1 /**************************************************************************
3 * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 **************************************************************************/
29 #include "main/glheader.h"
30 #include "main/context.h"
31 #include "main/framebuffer.h"
32 #include "main/renderbuffer.h"
33 #include "main/hash.h"
34 #include "main/fbobject.h"
35 #include "main/mfeatures.h"
36 #include "swrast/s_renderbuffer.h"
41 PUBLIC
const char __driConfigOptions
[] =
43 DRI_CONF_SECTION_PERFORMANCE
44 DRI_CONF_VBLANK_MODE(DRI_CONF_VBLANK_ALWAYS_SYNC
)
45 /* Options correspond to DRI_CONF_BO_REUSE_DISABLED,
46 * DRI_CONF_BO_REUSE_ALL
48 DRI_CONF_OPT_BEGIN_V(bo_reuse
, enum, 1, "0:1")
49 DRI_CONF_DESC_BEGIN(en
, "Buffer object reuse")
50 DRI_CONF_ENUM(0, "Disable buffer object reuse")
51 DRI_CONF_ENUM(1, "Enable reuse of all sizes of buffer objects")
55 DRI_CONF_OPT_BEGIN(texture_tiling
, bool, true)
56 DRI_CONF_DESC(en
, "Enable texture tiling")
59 DRI_CONF_OPT_BEGIN(early_z
, bool, false)
60 DRI_CONF_DESC(en
, "Enable early Z in classic mode (unstable, 945-only).")
63 DRI_CONF_OPT_BEGIN(fragment_shader
, bool, true)
64 DRI_CONF_DESC(en
, "Enable limited ARB_fragment_shader support on 915/945.")
68 DRI_CONF_SECTION_QUALITY
69 DRI_CONF_FORCE_S3TC_ENABLE(false)
70 DRI_CONF_ALLOW_LARGE_TEXTURES(2)
72 DRI_CONF_SECTION_DEBUG
73 DRI_CONF_NO_RAST(false)
74 DRI_CONF_ALWAYS_FLUSH_BATCH(false)
75 DRI_CONF_ALWAYS_FLUSH_CACHE(false)
77 DRI_CONF_OPT_BEGIN(stub_occlusion_query
, bool, false)
78 DRI_CONF_DESC(en
, "Enable stub ARB_occlusion_query support on 915/945.")
81 DRI_CONF_OPT_BEGIN(shader_precompile
, bool, false)
82 DRI_CONF_DESC(en
, "Perform code generation at shader link time.")
87 const GLuint __driNConfigOptions
= 12;
89 #include "intel_batchbuffer.h"
90 #include "intel_buffers.h"
91 #include "intel_bufmgr.h"
92 #include "intel_chipset.h"
93 #include "intel_fbo.h"
94 #include "intel_mipmap_tree.h"
95 #include "intel_screen.h"
96 #include "intel_tex.h"
97 #include "intel_regions.h"
101 #ifdef USE_NEW_INTERFACE
102 static PFNGLXCREATECONTEXTMODES create_context_modes
= NULL
;
103 #endif /*USE_NEW_INTERFACE */
105 static const __DRItexBufferExtension intelTexBufferExtension
= {
106 { __DRI_TEX_BUFFER
, __DRI_TEX_BUFFER_VERSION
},
112 intelDRI2Flush(__DRIdrawable
*drawable
)
114 GET_CURRENT_CONTEXT(ctx
);
115 struct intel_context
*intel
= intel_context(ctx
);
118 INTEL_FIREVERTICES(intel
);
120 intel
->need_throttle
= true;
122 if (intel
->batch
.used
)
123 intel_batchbuffer_flush(intel
);
126 static const struct __DRI2flushExtensionRec intelFlushExtension
= {
127 { __DRI2_FLUSH
, __DRI2_FLUSH_VERSION
},
129 dri2InvalidateDrawable
,
133 intel_create_image_from_name(__DRIscreen
*screen
,
134 int width
, int height
, int format
,
135 int name
, int pitch
, void *loaderPrivate
)
137 struct intel_screen
*intelScreen
= screen
->driverPrivate
;
141 image
= CALLOC(sizeof *image
);
146 case __DRI_IMAGE_FORMAT_RGB565
:
147 image
->format
= MESA_FORMAT_RGB565
;
148 image
->internal_format
= GL_RGB
;
149 image
->data_type
= GL_UNSIGNED_BYTE
;
151 case __DRI_IMAGE_FORMAT_XRGB8888
:
152 image
->format
= MESA_FORMAT_XRGB8888
;
153 image
->internal_format
= GL_RGB
;
154 image
->data_type
= GL_UNSIGNED_BYTE
;
156 case __DRI_IMAGE_FORMAT_ARGB8888
:
157 image
->format
= MESA_FORMAT_ARGB8888
;
158 image
->internal_format
= GL_RGBA
;
159 image
->data_type
= GL_UNSIGNED_BYTE
;
161 case __DRI_IMAGE_FORMAT_ABGR8888
:
162 image
->format
= MESA_FORMAT_RGBA8888_REV
;
163 image
->internal_format
= GL_RGBA
;
164 image
->data_type
= GL_UNSIGNED_BYTE
;
171 image
->data
= loaderPrivate
;
172 cpp
= _mesa_get_format_bytes(image
->format
);
174 image
->region
= intel_region_alloc_for_handle(intelScreen
,
176 pitch
, name
, "image");
177 if (image
->region
== NULL
) {
186 intel_create_image_from_renderbuffer(__DRIcontext
*context
,
187 int renderbuffer
, void *loaderPrivate
)
190 struct intel_context
*intel
= context
->driverPrivate
;
191 struct gl_renderbuffer
*rb
;
192 struct intel_renderbuffer
*irb
;
194 rb
= _mesa_lookup_renderbuffer(&intel
->ctx
, renderbuffer
);
196 _mesa_error(&intel
->ctx
,
197 GL_INVALID_OPERATION
, "glRenderbufferExternalMESA");
201 irb
= intel_renderbuffer(rb
);
202 image
= CALLOC(sizeof *image
);
206 image
->internal_format
= rb
->InternalFormat
;
207 image
->format
= rb
->Format
;
208 image
->data_type
= rb
->DataType
;
209 image
->data
= loaderPrivate
;
210 intel_region_reference(&image
->region
, irb
->mt
->region
);
216 intel_destroy_image(__DRIimage
*image
)
218 intel_region_release(&image
->region
);
223 intel_create_image(__DRIscreen
*screen
,
224 int width
, int height
, int format
,
229 struct intel_screen
*intelScreen
= screen
->driverPrivate
;
233 tiling
= I915_TILING_X
;
234 if (use
& __DRI_IMAGE_USE_CURSOR
) {
235 if (width
!= 64 || height
!= 64)
237 tiling
= I915_TILING_NONE
;
240 image
= CALLOC(sizeof *image
);
245 case __DRI_IMAGE_FORMAT_RGB565
:
246 image
->format
= MESA_FORMAT_RGB565
;
247 image
->internal_format
= GL_RGB
;
248 image
->data_type
= GL_UNSIGNED_BYTE
;
250 case __DRI_IMAGE_FORMAT_XRGB8888
:
251 image
->format
= MESA_FORMAT_XRGB8888
;
252 image
->internal_format
= GL_RGB
;
253 image
->data_type
= GL_UNSIGNED_BYTE
;
255 case __DRI_IMAGE_FORMAT_ARGB8888
:
256 image
->format
= MESA_FORMAT_ARGB8888
;
257 image
->internal_format
= GL_RGBA
;
258 image
->data_type
= GL_UNSIGNED_BYTE
;
260 case __DRI_IMAGE_FORMAT_ABGR8888
:
261 image
->format
= MESA_FORMAT_RGBA8888_REV
;
262 image
->internal_format
= GL_RGBA
;
263 image
->data_type
= GL_UNSIGNED_BYTE
;
270 image
->data
= loaderPrivate
;
271 cpp
= _mesa_get_format_bytes(image
->format
);
274 intel_region_alloc(intelScreen
, tiling
,
275 cpp
, width
, height
, true);
276 if (image
->region
== NULL
) {
285 intel_query_image(__DRIimage
*image
, int attrib
, int *value
)
288 case __DRI_IMAGE_ATTRIB_STRIDE
:
289 *value
= image
->region
->pitch
* image
->region
->cpp
;
291 case __DRI_IMAGE_ATTRIB_HANDLE
:
292 *value
= image
->region
->bo
->handle
;
294 case __DRI_IMAGE_ATTRIB_NAME
:
295 return intel_region_flink(image
->region
, (uint32_t *) value
);
302 intel_dup_image(__DRIimage
*orig_image
, void *loaderPrivate
)
306 image
= CALLOC(sizeof *image
);
310 intel_region_reference(&image
->region
, orig_image
->region
);
311 if (image
->region
== NULL
) {
316 image
->internal_format
= orig_image
->internal_format
;
317 image
->format
= orig_image
->format
;
318 image
->data_type
= orig_image
->data_type
;
319 image
->data
= loaderPrivate
;
324 static struct __DRIimageExtensionRec intelImageExtension
= {
325 { __DRI_IMAGE
, __DRI_IMAGE_VERSION
},
326 intel_create_image_from_name
,
327 intel_create_image_from_renderbuffer
,
334 static const __DRIextension
*intelScreenExtensions
[] = {
335 &intelTexBufferExtension
.base
,
336 &intelFlushExtension
.base
,
337 &intelImageExtension
.base
,
338 &dri2ConfigQueryExtension
.base
,
343 intel_get_param(__DRIscreen
*psp
, int param
, int *value
)
346 struct drm_i915_getparam gp
;
351 ret
= drmCommandWriteRead(psp
->fd
, DRM_I915_GETPARAM
, &gp
, sizeof(gp
));
354 _mesa_warning(NULL
, "drm_i915_getparam: %d", ret
);
362 intel_get_boolean(__DRIscreen
*psp
, int param
)
365 return intel_get_param(psp
, param
, &value
) && value
;
369 nop_callback(GLuint key
, void *data
, void *userData
)
374 intelDestroyScreen(__DRIscreen
* sPriv
)
376 struct intel_screen
*intelScreen
= sPriv
->driverPrivate
;
378 dri_bufmgr_destroy(intelScreen
->bufmgr
);
379 driDestroyOptionInfo(&intelScreen
->optionCache
);
381 /* Some regions may still have references to them at this point, so
382 * flush the hash table to prevent _mesa_DeleteHashTable() from
383 * complaining about the hash not being empty; */
384 _mesa_HashDeleteAll(intelScreen
->named_regions
, nop_callback
, NULL
);
385 _mesa_DeleteHashTable(intelScreen
->named_regions
);
388 sPriv
->driverPrivate
= NULL
;
393 * This is called when we need to set up GL rendering to a new X window.
396 intelCreateBuffer(__DRIscreen
* driScrnPriv
,
397 __DRIdrawable
* driDrawPriv
,
398 const struct gl_config
* mesaVis
, GLboolean isPixmap
)
400 struct intel_renderbuffer
*rb
;
401 struct intel_screen
*screen
= (struct intel_screen
*) driScrnPriv
->driverPrivate
;
404 return false; /* not implemented */
409 struct gl_framebuffer
*fb
= CALLOC_STRUCT(gl_framebuffer
);
414 _mesa_initialize_window_framebuffer(fb
, mesaVis
);
416 if (mesaVis
->redBits
== 5)
417 rgbFormat
= MESA_FORMAT_RGB565
;
418 else if (mesaVis
->alphaBits
== 0)
419 rgbFormat
= MESA_FORMAT_XRGB8888
;
421 rgbFormat
= MESA_FORMAT_ARGB8888
;
423 /* setup the hardware-based renderbuffers */
424 rb
= intel_create_renderbuffer(rgbFormat
);
425 _mesa_add_renderbuffer(fb
, BUFFER_FRONT_LEFT
, &rb
->Base
);
427 if (mesaVis
->doubleBufferMode
) {
428 rb
= intel_create_renderbuffer(rgbFormat
);
429 _mesa_add_renderbuffer(fb
, BUFFER_BACK_LEFT
, &rb
->Base
);
433 * Assert here that the gl_config has an expected depth/stencil bit
434 * combination: one of d24/s8, d16/s0, d0/s0. (See intelInitScreen2(),
435 * which constructs the advertised configs.)
437 if (mesaVis
->depthBits
== 24) {
438 assert(mesaVis
->stencilBits
== 8);
440 if (screen
->hw_has_separate_stencil
441 && screen
->dri2_has_hiz
!= INTEL_DRI2_HAS_HIZ_FALSE
) {
443 * Request a separate stencil buffer even if we do not yet know if
444 * the screen supports it. (See comments for
445 * enum intel_dri2_has_hiz).
447 rb
= intel_create_renderbuffer(MESA_FORMAT_X8_Z24
);
448 _mesa_add_renderbuffer(fb
, BUFFER_DEPTH
, &rb
->Base
);
449 rb
= intel_create_renderbuffer(MESA_FORMAT_S8
);
450 _mesa_add_renderbuffer(fb
, BUFFER_STENCIL
, &rb
->Base
);
453 * Use combined depth/stencil. Note that the renderbuffer is
454 * attached to two attachment points.
456 rb
= intel_create_renderbuffer(MESA_FORMAT_S8_Z24
);
457 _mesa_add_renderbuffer(fb
, BUFFER_DEPTH
, &rb
->Base
);
458 _mesa_add_renderbuffer(fb
, BUFFER_STENCIL
, &rb
->Base
);
461 else if (mesaVis
->depthBits
== 16) {
462 assert(mesaVis
->stencilBits
== 0);
463 /* just 16-bit depth buffer, no hw stencil */
464 struct intel_renderbuffer
*depthRb
465 = intel_create_renderbuffer(MESA_FORMAT_Z16
);
466 _mesa_add_renderbuffer(fb
, BUFFER_DEPTH
, &depthRb
->Base
);
469 assert(mesaVis
->depthBits
== 0);
470 assert(mesaVis
->stencilBits
== 0);
473 /* now add any/all software-based renderbuffers we may need */
474 _swrast_add_soft_renderbuffers(fb
,
475 false, /* never sw color */
476 false, /* never sw depth */
477 false, /* never sw stencil */
478 mesaVis
->accumRedBits
> 0,
479 false, /* never sw alpha */
480 false /* never sw aux */ );
481 driDrawPriv
->driverPrivate
= fb
;
488 intelDestroyBuffer(__DRIdrawable
* driDrawPriv
)
490 struct gl_framebuffer
*fb
= driDrawPriv
->driverPrivate
;
492 _mesa_reference_framebuffer(&fb
, NULL
);
495 /* There are probably better ways to do this, such as an
496 * init-designated function to register chipids and createcontext
500 i830CreateContext(const struct gl_config
*mesaVis
,
501 __DRIcontext
*driContextPriv
,
502 void *sharedContextPrivate
);
505 i915CreateContext(int api
,
506 const struct gl_config
*mesaVis
,
507 __DRIcontext
*driContextPriv
,
508 void *sharedContextPrivate
);
510 brwCreateContext(int api
,
511 const struct gl_config
*mesaVis
,
512 __DRIcontext
*driContextPriv
,
513 void *sharedContextPrivate
);
516 intelCreateContext(gl_api api
,
517 const struct gl_config
* mesaVis
,
518 __DRIcontext
* driContextPriv
,
519 unsigned major_version
,
520 unsigned minor_version
,
523 void *sharedContextPrivate
)
525 __DRIscreen
*sPriv
= driContextPriv
->driScreenPriv
;
526 struct intel_screen
*intelScreen
= sPriv
->driverPrivate
;
530 if (IS_9XX(intelScreen
->deviceID
)) {
531 if (!IS_965(intelScreen
->deviceID
)) {
532 success
= i915CreateContext(api
, mesaVis
, driContextPriv
,
533 sharedContextPrivate
);
536 intelScreen
->no_vbo
= true;
537 success
= i830CreateContext(mesaVis
, driContextPriv
,
538 sharedContextPrivate
);
541 if (IS_965(intelScreen
->deviceID
))
542 success
= brwCreateContext(api
, mesaVis
,
544 sharedContextPrivate
);
548 struct gl_context
*ctx
=
549 (struct gl_context
*) driContextPriv
->driverPrivate
;
551 _mesa_compute_version(ctx
);
552 if (ctx
->VersionMajor
> major_version
553 || (ctx
->VersionMajor
== major_version
554 && ctx
->VersionMinor
>= minor_version
)) {
555 *error
= __DRI_CTX_ERROR_BAD_VERSION
;
559 intelDestroyContext(driContextPriv
);
561 *error
= __DRI_CTX_ERROR_NO_MEMORY
;
562 fprintf(stderr
, "Unrecognized deviceID 0x%x\n", intelScreen
->deviceID
);
569 intel_init_bufmgr(struct intel_screen
*intelScreen
)
571 __DRIscreen
*spriv
= intelScreen
->driScrnPriv
;
574 intelScreen
->no_hw
= (getenv("INTEL_NO_HW") != NULL
||
575 getenv("INTEL_DEVID_OVERRIDE") != NULL
);
577 intelScreen
->bufmgr
= intel_bufmgr_gem_init(spriv
->fd
, BATCH_SZ
);
578 if (intelScreen
->bufmgr
== NULL
) {
579 fprintf(stderr
, "[%s:%u] Error initializing buffer manager.\n",
584 if (!intel_get_param(spriv
, I915_PARAM_NUM_FENCES_AVAIL
, &num_fences
) ||
586 fprintf(stderr
, "[%s: %u] Kernel 2.6.29 required.\n", __func__
, __LINE__
);
590 drm_intel_bufmgr_gem_enable_fenced_relocs(intelScreen
->bufmgr
);
592 intelScreen
->named_regions
= _mesa_NewHashTable();
594 intelScreen
->relaxed_relocations
= 0;
595 intelScreen
->relaxed_relocations
|=
596 intel_get_boolean(spriv
, I915_PARAM_HAS_RELAXED_DELTA
) << 0;
602 * Override intel_screen.hw_has_hiz with environment variable INTEL_HIZ.
604 * Valid values for INTEL_HIZ are "0" and "1". If an invalid valid value is
605 * encountered, a warning is emitted and INTEL_HIZ is ignored.
608 intel_override_hiz(struct intel_screen
*intel
)
610 const char *s
= getenv("INTEL_HIZ");
613 } else if (!strncmp("0", s
, 2)) {
614 intel
->hw_has_hiz
= false;
615 } else if (!strncmp("1", s
, 2)) {
616 intel
->hw_has_hiz
= true;
619 "warning: env variable INTEL_HIZ=\"%s\" has invalid value "
620 "and is ignored", s
);
625 * Override intel_screen.hw_has_separate_stencil with environment variable
626 * INTEL_SEPARATE_STENCIL.
628 * Valid values for INTEL_SEPARATE_STENCIL are "0" and "1". If an invalid
629 * valid value is encountered, a warning is emitted and INTEL_SEPARATE_STENCIL
633 intel_override_separate_stencil(struct intel_screen
*screen
)
635 const char *s
= getenv("INTEL_SEPARATE_STENCIL");
638 } else if (!strncmp("0", s
, 2)) {
639 screen
->hw_has_separate_stencil
= false;
640 } else if (!strncmp("1", s
, 2)) {
641 screen
->hw_has_separate_stencil
= true;
644 "warning: env variable INTEL_SEPARATE_STENCIL=\"%s\" has "
645 "invalid value and is ignored", s
);
650 * This is the driver specific part of the createNewScreen entry point.
651 * Called when using DRI2.
653 * \return the struct gl_config supported by this driver
656 __DRIconfig
**intelInitScreen2(__DRIscreen
*psp
)
658 struct intel_screen
*intelScreen
;
661 unsigned int api_mask
;
662 char *devid_override
;
664 static const GLenum back_buffer_modes
[] = {
665 GLX_NONE
, GLX_SWAP_UNDEFINED_OML
, GLX_SWAP_COPY_OML
667 uint8_t depth_bits
[4], stencil_bits
[4], msaa_samples_array
[1];
669 __DRIconfig
**configs
= NULL
;
671 /* Allocate the private area */
672 intelScreen
= CALLOC(sizeof *intelScreen
);
674 fprintf(stderr
, "\nERROR! Allocating private area failed\n");
677 /* parse information in __driConfigOptions */
678 driParseOptionInfo(&intelScreen
->optionCache
,
679 __driConfigOptions
, __driNConfigOptions
);
681 intelScreen
->driScrnPriv
= psp
;
682 psp
->driverPrivate
= (void *) intelScreen
;
684 /* Determine chipset ID */
685 if (!intel_get_param(psp
, I915_PARAM_CHIPSET_ID
,
686 &intelScreen
->deviceID
))
689 /* Allow an override of the device ID for the purpose of making the
690 * driver produce dumps for debugging of new chipset enablement.
691 * This implies INTEL_NO_HW, to avoid programming your actual GPU
694 devid_override
= getenv("INTEL_DEVID_OVERRIDE");
695 if (devid_override
) {
696 intelScreen
->deviceID
= strtod(devid_override
, NULL
);
699 if (IS_GEN7(intelScreen
->deviceID
)) {
700 intelScreen
->gen
= 7;
701 } else if (IS_GEN6(intelScreen
->deviceID
)) {
702 intelScreen
->gen
= 6;
703 } else if (IS_GEN5(intelScreen
->deviceID
)) {
704 intelScreen
->gen
= 5;
705 } else if (IS_965(intelScreen
->deviceID
)) {
706 intelScreen
->gen
= 4;
707 } else if (IS_9XX(intelScreen
->deviceID
)) {
708 intelScreen
->gen
= 3;
710 intelScreen
->gen
= 2;
713 intelScreen
->hw_has_separate_stencil
= intelScreen
->gen
>= 6;
714 intelScreen
->hw_must_use_separate_stencil
= intelScreen
->gen
>= 7;
715 intelScreen
->hw_has_hiz
= intelScreen
->gen
== 6; /* Not yet for gen7. */
716 intelScreen
->dri2_has_hiz
= INTEL_DRI2_HAS_HIZ_UNKNOWN
;
718 intel_override_hiz(intelScreen
);
719 intel_override_separate_stencil(intelScreen
);
721 api_mask
= (1 << __DRI_API_OPENGL
);
723 api_mask
|= (1 << __DRI_API_GLES
);
726 api_mask
|= (1 << __DRI_API_GLES2
);
729 if (IS_9XX(intelScreen
->deviceID
) || IS_965(intelScreen
->deviceID
))
730 psp
->api_mask
= api_mask
;
732 if (!intel_init_bufmgr(intelScreen
))
735 psp
->extensions
= intelScreenExtensions
;
737 msaa_samples_array
[0] = 0;
739 fb_format
[0] = GL_RGB
;
740 fb_type
[0] = GL_UNSIGNED_SHORT_5_6_5
;
742 fb_format
[1] = GL_BGR
;
743 fb_type
[1] = GL_UNSIGNED_INT_8_8_8_8_REV
;
745 fb_format
[2] = GL_BGRA
;
746 fb_type
[2] = GL_UNSIGNED_INT_8_8_8_8_REV
;
751 /* Generate a rich set of useful configs that do not include an
752 * accumulation buffer.
754 for (color
= 0; color
< ARRAY_SIZE(fb_format
); color
++) {
755 __DRIconfig
**new_configs
;
758 /* Starting with DRI2 protocol version 1.1 we can request a depth/stencil
759 * buffer that has a diffferent number of bits per pixel than the color
760 * buffer. This isn't yet supported here.
762 if (fb_type
[color
] == GL_UNSIGNED_SHORT_5_6_5
) {
772 new_configs
= driCreateConfigs(fb_format
[color
], fb_type
[color
],
777 ARRAY_SIZE(back_buffer_modes
),
779 ARRAY_SIZE(msaa_samples_array
),
782 configs
= new_configs
;
784 configs
= driConcatConfigs(configs
, new_configs
);
787 /* Generate the minimum possible set of configs that include an
788 * accumulation buffer.
790 for (color
= 0; color
< ARRAY_SIZE(fb_format
); color
++) {
791 __DRIconfig
**new_configs
;
793 if (fb_type
[color
] == GL_UNSIGNED_SHORT_5_6_5
) {
801 new_configs
= driCreateConfigs(fb_format
[color
], fb_type
[color
],
802 depth_bits
, stencil_bits
, 1,
803 back_buffer_modes
+ 1, 1,
804 msaa_samples_array
, 1,
807 configs
= new_configs
;
809 configs
= driConcatConfigs(configs
, new_configs
);
812 if (configs
== NULL
) {
813 fprintf(stderr
, "[%s:%u] Error creating FBConfig!\n", __func__
,
818 return (const __DRIconfig
**)configs
;
821 struct intel_buffer
{
823 struct intel_region
*region
;
827 * \brief Get tiling format for a DRI buffer.
829 * \param attachment is the buffer's attachmet point, such as
830 * __DRI_BUFFER_DEPTH.
831 * \param out_tiling is the returned tiling format for buffer.
832 * \return false if attachment is unrecognized or is incompatible with screen.
835 intel_get_dri_buffer_tiling(struct intel_screen
*screen
,
837 uint32_t *out_tiling
)
839 if (screen
->gen
< 4) {
840 *out_tiling
= I915_TILING_X
;
844 switch (attachment
) {
845 case __DRI_BUFFER_DEPTH
:
846 case __DRI_BUFFER_DEPTH_STENCIL
:
847 case __DRI_BUFFER_HIZ
:
848 *out_tiling
= I915_TILING_Y
;
850 case __DRI_BUFFER_ACCUM
:
851 case __DRI_BUFFER_FRONT_LEFT
:
852 case __DRI_BUFFER_FRONT_RIGHT
:
853 case __DRI_BUFFER_BACK_LEFT
:
854 case __DRI_BUFFER_BACK_RIGHT
:
855 case __DRI_BUFFER_FAKE_FRONT_LEFT
:
856 case __DRI_BUFFER_FAKE_FRONT_RIGHT
:
857 *out_tiling
= I915_TILING_X
;
859 case __DRI_BUFFER_STENCIL
:
860 /* The stencil buffer is W tiled. However, we request from the kernel
861 * a non-tiled buffer because the GTT is incapable of W fencing.
863 *out_tiling
= I915_TILING_NONE
;
866 if(unlikely(INTEL_DEBUG
& DEBUG_DRI
)) {
867 fprintf(stderr
, "error: %s: unrecognized DRI buffer attachment 0x%x\n",
868 __FUNCTION__
, attachment
);
875 intelAllocateBuffer(__DRIscreen
*screen
,
876 unsigned attachment
, unsigned format
,
877 int width
, int height
)
879 struct intel_buffer
*intelBuffer
;
880 struct intel_screen
*intelScreen
= screen
->driverPrivate
;
883 uint32_t region_width
;
884 uint32_t region_height
;
889 ok
= intel_get_dri_buffer_tiling(intelScreen
, attachment
, &tiling
);
893 intelBuffer
= CALLOC(sizeof *intelBuffer
);
894 if (intelBuffer
== NULL
)
897 if (attachment
== __DRI_BUFFER_STENCIL
) {
898 /* The stencil buffer has quirky pitch requirements. From Vol 2a,
899 * 11.5.6.2.1 3DSTATE_STENCIL_BUFFER, field "Surface Pitch":
900 * The pitch must be set to 2x the value computed based on width, as
901 * the stencil buffer is stored with two rows interleaved.
902 * To accomplish this, we resort to the nasty hack of doubling the
903 * region's cpp and halving its height.
905 region_width
= ALIGN(width
, 64);
906 region_height
= ALIGN(ALIGN(height
, 2) / 2, 64);
907 region_cpp
= format
/ 4;
909 region_width
= width
;
910 region_height
= height
;
911 region_cpp
= format
/ 8;
914 intelBuffer
->region
= intel_region_alloc(intelScreen
,
921 if (intelBuffer
->region
== NULL
) {
926 intel_region_flink(intelBuffer
->region
, &intelBuffer
->base
.name
);
928 intelBuffer
->base
.attachment
= attachment
;
929 intelBuffer
->base
.cpp
= intelBuffer
->region
->cpp
;
930 intelBuffer
->base
.pitch
=
931 intelBuffer
->region
->pitch
* intelBuffer
->region
->cpp
;
933 return &intelBuffer
->base
;
937 intelReleaseBuffer(__DRIscreen
*screen
, __DRIbuffer
*buffer
)
939 struct intel_buffer
*intelBuffer
= (struct intel_buffer
*) buffer
;
941 intel_region_release(&intelBuffer
->region
);
946 const struct __DriverAPIRec driDriverAPI
= {
947 .InitScreen
= intelInitScreen2
,
948 .DestroyScreen
= intelDestroyScreen
,
949 .CreateContext
= intelCreateContext
,
950 .DestroyContext
= intelDestroyContext
,
951 .CreateBuffer
= intelCreateBuffer
,
952 .DestroyBuffer
= intelDestroyBuffer
,
953 .MakeCurrent
= intelMakeCurrent
,
954 .UnbindContext
= intelUnbindContext
,
955 .AllocateBuffer
= intelAllocateBuffer
,
956 .ReleaseBuffer
= intelReleaseBuffer
959 /* This is the table of extensions that the loader will dlsym() for. */
960 PUBLIC
const __DRIextension
*__driDriverExtensions
[] = {
961 &driCoreExtension
.base
,
962 &driDRI2Extension
.base
,