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 "main/version.h"
37 #include "swrast/s_renderbuffer.h"
42 PUBLIC
const char __driConfigOptions
[] =
44 DRI_CONF_SECTION_PERFORMANCE
45 DRI_CONF_VBLANK_MODE(DRI_CONF_VBLANK_ALWAYS_SYNC
)
46 /* Options correspond to DRI_CONF_BO_REUSE_DISABLED,
47 * DRI_CONF_BO_REUSE_ALL
49 DRI_CONF_OPT_BEGIN_V(bo_reuse
, enum, 1, "0:1")
50 DRI_CONF_DESC_BEGIN(en
, "Buffer object reuse")
51 DRI_CONF_ENUM(0, "Disable buffer object reuse")
52 DRI_CONF_ENUM(1, "Enable reuse of all sizes of buffer objects")
56 DRI_CONF_OPT_BEGIN(texture_tiling
, bool, true)
57 DRI_CONF_DESC(en
, "Enable texture tiling")
60 DRI_CONF_OPT_BEGIN(early_z
, bool, false)
61 DRI_CONF_DESC(en
, "Enable early Z in classic mode (unstable, 945-only).")
64 DRI_CONF_OPT_BEGIN(fragment_shader
, bool, true)
65 DRI_CONF_DESC(en
, "Enable limited ARB_fragment_shader support on 915/945.")
69 DRI_CONF_SECTION_QUALITY
70 DRI_CONF_FORCE_S3TC_ENABLE(false)
71 DRI_CONF_ALLOW_LARGE_TEXTURES(2)
73 DRI_CONF_SECTION_DEBUG
74 DRI_CONF_NO_RAST(false)
75 DRI_CONF_ALWAYS_FLUSH_BATCH(false)
76 DRI_CONF_ALWAYS_FLUSH_CACHE(false)
78 DRI_CONF_OPT_BEGIN(stub_occlusion_query
, bool, false)
79 DRI_CONF_DESC(en
, "Enable stub ARB_occlusion_query support on 915/945.")
82 DRI_CONF_OPT_BEGIN(shader_precompile
, bool, false)
83 DRI_CONF_DESC(en
, "Perform code generation at shader link time.")
88 const GLuint __driNConfigOptions
= 12;
90 #include "intel_batchbuffer.h"
91 #include "intel_buffers.h"
92 #include "intel_bufmgr.h"
93 #include "intel_chipset.h"
94 #include "intel_fbo.h"
95 #include "intel_mipmap_tree.h"
96 #include "intel_screen.h"
97 #include "intel_tex.h"
98 #include "intel_regions.h"
100 #include "i915_drm.h"
102 #ifdef USE_NEW_INTERFACE
103 static PFNGLXCREATECONTEXTMODES create_context_modes
= NULL
;
104 #endif /*USE_NEW_INTERFACE */
106 static const __DRItexBufferExtension intelTexBufferExtension
= {
107 { __DRI_TEX_BUFFER
, __DRI_TEX_BUFFER_VERSION
},
113 intelDRI2Flush(__DRIdrawable
*drawable
)
115 GET_CURRENT_CONTEXT(ctx
);
116 struct intel_context
*intel
= intel_context(ctx
);
119 INTEL_FIREVERTICES(intel
);
121 intel
->need_throttle
= true;
123 if (intel
->batch
.used
)
124 intel_batchbuffer_flush(intel
);
127 static const struct __DRI2flushExtensionRec intelFlushExtension
= {
128 { __DRI2_FLUSH
, __DRI2_FLUSH_VERSION
},
130 dri2InvalidateDrawable
,
134 intel_create_image_from_name(__DRIscreen
*screen
,
135 int width
, int height
, int format
,
136 int name
, int pitch
, void *loaderPrivate
)
138 struct intel_screen
*intelScreen
= screen
->driverPrivate
;
142 image
= CALLOC(sizeof *image
);
147 case __DRI_IMAGE_FORMAT_RGB565
:
148 image
->format
= MESA_FORMAT_RGB565
;
149 image
->internal_format
= GL_RGB
;
150 image
->data_type
= GL_UNSIGNED_BYTE
;
152 case __DRI_IMAGE_FORMAT_XRGB8888
:
153 image
->format
= MESA_FORMAT_XRGB8888
;
154 image
->internal_format
= GL_RGB
;
155 image
->data_type
= GL_UNSIGNED_BYTE
;
157 case __DRI_IMAGE_FORMAT_ARGB8888
:
158 image
->format
= MESA_FORMAT_ARGB8888
;
159 image
->internal_format
= GL_RGBA
;
160 image
->data_type
= GL_UNSIGNED_BYTE
;
162 case __DRI_IMAGE_FORMAT_ABGR8888
:
163 image
->format
= MESA_FORMAT_RGBA8888_REV
;
164 image
->internal_format
= GL_RGBA
;
165 image
->data_type
= GL_UNSIGNED_BYTE
;
172 image
->data
= loaderPrivate
;
173 cpp
= _mesa_get_format_bytes(image
->format
);
175 image
->region
= intel_region_alloc_for_handle(intelScreen
,
177 pitch
, name
, "image");
178 if (image
->region
== NULL
) {
187 intel_create_image_from_renderbuffer(__DRIcontext
*context
,
188 int renderbuffer
, void *loaderPrivate
)
191 struct intel_context
*intel
= context
->driverPrivate
;
192 struct gl_renderbuffer
*rb
;
193 struct intel_renderbuffer
*irb
;
195 rb
= _mesa_lookup_renderbuffer(&intel
->ctx
, renderbuffer
);
197 _mesa_error(&intel
->ctx
,
198 GL_INVALID_OPERATION
, "glRenderbufferExternalMESA");
202 irb
= intel_renderbuffer(rb
);
203 image
= CALLOC(sizeof *image
);
207 image
->internal_format
= rb
->InternalFormat
;
208 image
->format
= rb
->Format
;
209 image
->data_type
= rb
->DataType
;
210 image
->data
= loaderPrivate
;
211 intel_region_reference(&image
->region
, irb
->mt
->region
);
217 intel_destroy_image(__DRIimage
*image
)
219 intel_region_release(&image
->region
);
224 intel_create_image(__DRIscreen
*screen
,
225 int width
, int height
, int format
,
230 struct intel_screen
*intelScreen
= screen
->driverPrivate
;
234 tiling
= I915_TILING_X
;
235 if (use
& __DRI_IMAGE_USE_CURSOR
) {
236 if (width
!= 64 || height
!= 64)
238 tiling
= I915_TILING_NONE
;
241 image
= CALLOC(sizeof *image
);
246 case __DRI_IMAGE_FORMAT_RGB565
:
247 image
->format
= MESA_FORMAT_RGB565
;
248 image
->internal_format
= GL_RGB
;
249 image
->data_type
= GL_UNSIGNED_BYTE
;
251 case __DRI_IMAGE_FORMAT_XRGB8888
:
252 image
->format
= MESA_FORMAT_XRGB8888
;
253 image
->internal_format
= GL_RGB
;
254 image
->data_type
= GL_UNSIGNED_BYTE
;
256 case __DRI_IMAGE_FORMAT_ARGB8888
:
257 image
->format
= MESA_FORMAT_ARGB8888
;
258 image
->internal_format
= GL_RGBA
;
259 image
->data_type
= GL_UNSIGNED_BYTE
;
261 case __DRI_IMAGE_FORMAT_ABGR8888
:
262 image
->format
= MESA_FORMAT_RGBA8888_REV
;
263 image
->internal_format
= GL_RGBA
;
264 image
->data_type
= GL_UNSIGNED_BYTE
;
271 image
->data
= loaderPrivate
;
272 cpp
= _mesa_get_format_bytes(image
->format
);
275 intel_region_alloc(intelScreen
, tiling
,
276 cpp
, width
, height
, true);
277 if (image
->region
== NULL
) {
286 intel_query_image(__DRIimage
*image
, int attrib
, int *value
)
289 case __DRI_IMAGE_ATTRIB_STRIDE
:
290 *value
= image
->region
->pitch
* image
->region
->cpp
;
292 case __DRI_IMAGE_ATTRIB_HANDLE
:
293 *value
= image
->region
->bo
->handle
;
295 case __DRI_IMAGE_ATTRIB_NAME
:
296 return intel_region_flink(image
->region
, (uint32_t *) value
);
303 intel_dup_image(__DRIimage
*orig_image
, void *loaderPrivate
)
307 image
= CALLOC(sizeof *image
);
311 intel_region_reference(&image
->region
, orig_image
->region
);
312 if (image
->region
== NULL
) {
317 image
->internal_format
= orig_image
->internal_format
;
318 image
->format
= orig_image
->format
;
319 image
->data_type
= orig_image
->data_type
;
320 image
->data
= loaderPrivate
;
325 static struct __DRIimageExtensionRec intelImageExtension
= {
326 { __DRI_IMAGE
, __DRI_IMAGE_VERSION
},
327 intel_create_image_from_name
,
328 intel_create_image_from_renderbuffer
,
335 static const __DRIextension
*intelScreenExtensions
[] = {
336 &intelTexBufferExtension
.base
,
337 &intelFlushExtension
.base
,
338 &intelImageExtension
.base
,
339 &dri2ConfigQueryExtension
.base
,
344 intel_get_param(__DRIscreen
*psp
, int param
, int *value
)
347 struct drm_i915_getparam gp
;
352 ret
= drmCommandWriteRead(psp
->fd
, DRM_I915_GETPARAM
, &gp
, sizeof(gp
));
355 _mesa_warning(NULL
, "drm_i915_getparam: %d", ret
);
363 intel_get_boolean(__DRIscreen
*psp
, int param
)
366 return intel_get_param(psp
, param
, &value
) && value
;
370 nop_callback(GLuint key
, void *data
, void *userData
)
375 intelDestroyScreen(__DRIscreen
* sPriv
)
377 struct intel_screen
*intelScreen
= sPriv
->driverPrivate
;
379 dri_bufmgr_destroy(intelScreen
->bufmgr
);
380 driDestroyOptionInfo(&intelScreen
->optionCache
);
382 /* Some regions may still have references to them at this point, so
383 * flush the hash table to prevent _mesa_DeleteHashTable() from
384 * complaining about the hash not being empty; */
385 _mesa_HashDeleteAll(intelScreen
->named_regions
, nop_callback
, NULL
);
386 _mesa_DeleteHashTable(intelScreen
->named_regions
);
389 sPriv
->driverPrivate
= NULL
;
394 * This is called when we need to set up GL rendering to a new X window.
397 intelCreateBuffer(__DRIscreen
* driScrnPriv
,
398 __DRIdrawable
* driDrawPriv
,
399 const struct gl_config
* mesaVis
, GLboolean isPixmap
)
401 struct intel_renderbuffer
*rb
;
402 struct intel_screen
*screen
= (struct intel_screen
*) driScrnPriv
->driverPrivate
;
405 return false; /* not implemented */
410 struct gl_framebuffer
*fb
= CALLOC_STRUCT(gl_framebuffer
);
415 _mesa_initialize_window_framebuffer(fb
, mesaVis
);
417 if (mesaVis
->redBits
== 5)
418 rgbFormat
= MESA_FORMAT_RGB565
;
419 else if (mesaVis
->alphaBits
== 0)
420 rgbFormat
= MESA_FORMAT_XRGB8888
;
422 rgbFormat
= MESA_FORMAT_ARGB8888
;
424 /* setup the hardware-based renderbuffers */
425 rb
= intel_create_renderbuffer(rgbFormat
);
426 _mesa_add_renderbuffer(fb
, BUFFER_FRONT_LEFT
, &rb
->Base
);
428 if (mesaVis
->doubleBufferMode
) {
429 rb
= intel_create_renderbuffer(rgbFormat
);
430 _mesa_add_renderbuffer(fb
, BUFFER_BACK_LEFT
, &rb
->Base
);
434 * Assert here that the gl_config has an expected depth/stencil bit
435 * combination: one of d24/s8, d16/s0, d0/s0. (See intelInitScreen2(),
436 * which constructs the advertised configs.)
438 if (mesaVis
->depthBits
== 24) {
439 assert(mesaVis
->stencilBits
== 8);
441 if (screen
->hw_has_separate_stencil
442 && screen
->dri2_has_hiz
!= INTEL_DRI2_HAS_HIZ_FALSE
) {
444 * Request a separate stencil buffer even if we do not yet know if
445 * the screen supports it. (See comments for
446 * enum intel_dri2_has_hiz).
448 rb
= intel_create_renderbuffer(MESA_FORMAT_X8_Z24
);
449 _mesa_add_renderbuffer(fb
, BUFFER_DEPTH
, &rb
->Base
);
450 rb
= intel_create_renderbuffer(MESA_FORMAT_S8
);
451 _mesa_add_renderbuffer(fb
, BUFFER_STENCIL
, &rb
->Base
);
454 * Use combined depth/stencil. Note that the renderbuffer is
455 * attached to two attachment points.
457 rb
= intel_create_renderbuffer(MESA_FORMAT_S8_Z24
);
458 _mesa_add_renderbuffer(fb
, BUFFER_DEPTH
, &rb
->Base
);
459 _mesa_add_renderbuffer(fb
, BUFFER_STENCIL
, &rb
->Base
);
462 else if (mesaVis
->depthBits
== 16) {
463 assert(mesaVis
->stencilBits
== 0);
464 /* just 16-bit depth buffer, no hw stencil */
465 struct intel_renderbuffer
*depthRb
466 = intel_create_renderbuffer(MESA_FORMAT_Z16
);
467 _mesa_add_renderbuffer(fb
, BUFFER_DEPTH
, &depthRb
->Base
);
470 assert(mesaVis
->depthBits
== 0);
471 assert(mesaVis
->stencilBits
== 0);
474 /* now add any/all software-based renderbuffers we may need */
475 _swrast_add_soft_renderbuffers(fb
,
476 false, /* never sw color */
477 false, /* never sw depth */
478 false, /* never sw stencil */
479 mesaVis
->accumRedBits
> 0,
480 false, /* never sw alpha */
481 false /* never sw aux */ );
482 driDrawPriv
->driverPrivate
= fb
;
489 intelDestroyBuffer(__DRIdrawable
* driDrawPriv
)
491 struct gl_framebuffer
*fb
= driDrawPriv
->driverPrivate
;
493 _mesa_reference_framebuffer(&fb
, NULL
);
496 /* There are probably better ways to do this, such as an
497 * init-designated function to register chipids and createcontext
501 i830CreateContext(const struct gl_config
*mesaVis
,
502 __DRIcontext
*driContextPriv
,
503 void *sharedContextPrivate
);
506 i915CreateContext(int api
,
507 const struct gl_config
*mesaVis
,
508 __DRIcontext
*driContextPriv
,
509 void *sharedContextPrivate
);
511 brwCreateContext(int api
,
512 const struct gl_config
*mesaVis
,
513 __DRIcontext
*driContextPriv
,
514 void *sharedContextPrivate
);
517 intelCreateContext(gl_api api
,
518 const struct gl_config
* mesaVis
,
519 __DRIcontext
* driContextPriv
,
520 unsigned major_version
,
521 unsigned minor_version
,
524 void *sharedContextPrivate
)
526 __DRIscreen
*sPriv
= driContextPriv
->driScreenPriv
;
527 struct intel_screen
*intelScreen
= sPriv
->driverPrivate
;
531 if (IS_9XX(intelScreen
->deviceID
)) {
532 if (!IS_965(intelScreen
->deviceID
)) {
533 success
= i915CreateContext(api
, mesaVis
, driContextPriv
,
534 sharedContextPrivate
);
537 intelScreen
->no_vbo
= true;
538 success
= i830CreateContext(mesaVis
, driContextPriv
,
539 sharedContextPrivate
);
542 if (IS_965(intelScreen
->deviceID
))
543 success
= brwCreateContext(api
, mesaVis
,
545 sharedContextPrivate
);
549 struct gl_context
*ctx
=
550 (struct gl_context
*) driContextPriv
->driverPrivate
;
552 _mesa_compute_version(ctx
);
553 if (ctx
->VersionMajor
> major_version
554 || (ctx
->VersionMajor
== major_version
555 && ctx
->VersionMinor
>= minor_version
)) {
556 *error
= __DRI_CTX_ERROR_BAD_VERSION
;
560 intelDestroyContext(driContextPriv
);
562 *error
= __DRI_CTX_ERROR_NO_MEMORY
;
563 fprintf(stderr
, "Unrecognized deviceID 0x%x\n", intelScreen
->deviceID
);
570 intel_init_bufmgr(struct intel_screen
*intelScreen
)
572 __DRIscreen
*spriv
= intelScreen
->driScrnPriv
;
575 intelScreen
->no_hw
= (getenv("INTEL_NO_HW") != NULL
||
576 getenv("INTEL_DEVID_OVERRIDE") != NULL
);
578 intelScreen
->bufmgr
= intel_bufmgr_gem_init(spriv
->fd
, BATCH_SZ
);
579 if (intelScreen
->bufmgr
== NULL
) {
580 fprintf(stderr
, "[%s:%u] Error initializing buffer manager.\n",
585 if (!intel_get_param(spriv
, I915_PARAM_NUM_FENCES_AVAIL
, &num_fences
) ||
587 fprintf(stderr
, "[%s: %u] Kernel 2.6.29 required.\n", __func__
, __LINE__
);
591 drm_intel_bufmgr_gem_enable_fenced_relocs(intelScreen
->bufmgr
);
593 intelScreen
->named_regions
= _mesa_NewHashTable();
595 intelScreen
->relaxed_relocations
= 0;
596 intelScreen
->relaxed_relocations
|=
597 intel_get_boolean(spriv
, I915_PARAM_HAS_RELAXED_DELTA
) << 0;
603 * Override intel_screen.hw_has_hiz with environment variable INTEL_HIZ.
605 * Valid values for INTEL_HIZ are "0" and "1". If an invalid valid value is
606 * encountered, a warning is emitted and INTEL_HIZ is ignored.
609 intel_override_hiz(struct intel_screen
*intel
)
611 const char *s
= getenv("INTEL_HIZ");
614 } else if (!strncmp("0", s
, 2)) {
615 intel
->hw_has_hiz
= false;
616 } else if (!strncmp("1", s
, 2)) {
617 intel
->hw_has_hiz
= true;
620 "warning: env variable INTEL_HIZ=\"%s\" has invalid value "
621 "and is ignored", s
);
626 * Override intel_screen.hw_has_separate_stencil with environment variable
627 * INTEL_SEPARATE_STENCIL.
629 * Valid values for INTEL_SEPARATE_STENCIL are "0" and "1". If an invalid
630 * valid value is encountered, a warning is emitted and INTEL_SEPARATE_STENCIL
634 intel_override_separate_stencil(struct intel_screen
*screen
)
636 const char *s
= getenv("INTEL_SEPARATE_STENCIL");
639 } else if (!strncmp("0", s
, 2)) {
640 screen
->hw_has_separate_stencil
= false;
641 } else if (!strncmp("1", s
, 2)) {
642 screen
->hw_has_separate_stencil
= true;
645 "warning: env variable INTEL_SEPARATE_STENCIL=\"%s\" has "
646 "invalid value and is ignored", s
);
651 * This is the driver specific part of the createNewScreen entry point.
652 * Called when using DRI2.
654 * \return the struct gl_config supported by this driver
657 __DRIconfig
**intelInitScreen2(__DRIscreen
*psp
)
659 struct intel_screen
*intelScreen
;
662 unsigned int api_mask
;
663 char *devid_override
;
665 static const GLenum back_buffer_modes
[] = {
666 GLX_NONE
, GLX_SWAP_UNDEFINED_OML
, GLX_SWAP_COPY_OML
668 uint8_t depth_bits
[4], stencil_bits
[4], msaa_samples_array
[1];
670 __DRIconfig
**configs
= NULL
;
672 /* Allocate the private area */
673 intelScreen
= CALLOC(sizeof *intelScreen
);
675 fprintf(stderr
, "\nERROR! Allocating private area failed\n");
678 /* parse information in __driConfigOptions */
679 driParseOptionInfo(&intelScreen
->optionCache
,
680 __driConfigOptions
, __driNConfigOptions
);
682 intelScreen
->driScrnPriv
= psp
;
683 psp
->driverPrivate
= (void *) intelScreen
;
685 /* Determine chipset ID */
686 if (!intel_get_param(psp
, I915_PARAM_CHIPSET_ID
,
687 &intelScreen
->deviceID
))
690 /* Allow an override of the device ID for the purpose of making the
691 * driver produce dumps for debugging of new chipset enablement.
692 * This implies INTEL_NO_HW, to avoid programming your actual GPU
695 devid_override
= getenv("INTEL_DEVID_OVERRIDE");
696 if (devid_override
) {
697 intelScreen
->deviceID
= strtod(devid_override
, NULL
);
700 intelScreen
->kernel_has_gen7_sol_reset
=
701 intel_get_boolean(intelScreen
->driScrnPriv
,
702 I915_PARAM_HAS_GEN7_SOL_RESET
);
704 if (IS_GEN7(intelScreen
->deviceID
)) {
705 intelScreen
->gen
= 7;
706 } else if (IS_GEN6(intelScreen
->deviceID
)) {
707 intelScreen
->gen
= 6;
708 } else if (IS_GEN5(intelScreen
->deviceID
)) {
709 intelScreen
->gen
= 5;
710 } else if (IS_965(intelScreen
->deviceID
)) {
711 intelScreen
->gen
= 4;
712 } else if (IS_9XX(intelScreen
->deviceID
)) {
713 intelScreen
->gen
= 3;
715 intelScreen
->gen
= 2;
718 intelScreen
->hw_has_separate_stencil
= intelScreen
->gen
>= 6;
719 intelScreen
->hw_must_use_separate_stencil
= intelScreen
->gen
>= 7;
720 intelScreen
->hw_has_hiz
= intelScreen
->gen
== 6; /* Not yet for gen7. */
721 intelScreen
->dri2_has_hiz
= INTEL_DRI2_HAS_HIZ_UNKNOWN
;
723 intel_override_hiz(intelScreen
);
724 intel_override_separate_stencil(intelScreen
);
726 api_mask
= (1 << __DRI_API_OPENGL
);
728 api_mask
|= (1 << __DRI_API_GLES
);
731 api_mask
|= (1 << __DRI_API_GLES2
);
734 if (IS_9XX(intelScreen
->deviceID
) || IS_965(intelScreen
->deviceID
))
735 psp
->api_mask
= api_mask
;
737 if (!intel_init_bufmgr(intelScreen
))
740 psp
->extensions
= intelScreenExtensions
;
742 msaa_samples_array
[0] = 0;
744 fb_format
[0] = GL_RGB
;
745 fb_type
[0] = GL_UNSIGNED_SHORT_5_6_5
;
747 fb_format
[1] = GL_BGR
;
748 fb_type
[1] = GL_UNSIGNED_INT_8_8_8_8_REV
;
750 fb_format
[2] = GL_BGRA
;
751 fb_type
[2] = GL_UNSIGNED_INT_8_8_8_8_REV
;
756 /* Generate a rich set of useful configs that do not include an
757 * accumulation buffer.
759 for (color
= 0; color
< ARRAY_SIZE(fb_format
); color
++) {
760 __DRIconfig
**new_configs
;
763 /* Starting with DRI2 protocol version 1.1 we can request a depth/stencil
764 * buffer that has a diffferent number of bits per pixel than the color
765 * buffer. This isn't yet supported here.
767 if (fb_type
[color
] == GL_UNSIGNED_SHORT_5_6_5
) {
777 new_configs
= driCreateConfigs(fb_format
[color
], fb_type
[color
],
782 ARRAY_SIZE(back_buffer_modes
),
784 ARRAY_SIZE(msaa_samples_array
),
787 configs
= new_configs
;
789 configs
= driConcatConfigs(configs
, new_configs
);
792 /* Generate the minimum possible set of configs that include an
793 * accumulation buffer.
795 for (color
= 0; color
< ARRAY_SIZE(fb_format
); color
++) {
796 __DRIconfig
**new_configs
;
798 if (fb_type
[color
] == GL_UNSIGNED_SHORT_5_6_5
) {
806 new_configs
= driCreateConfigs(fb_format
[color
], fb_type
[color
],
807 depth_bits
, stencil_bits
, 1,
808 back_buffer_modes
+ 1, 1,
809 msaa_samples_array
, 1,
812 configs
= new_configs
;
814 configs
= driConcatConfigs(configs
, new_configs
);
817 if (configs
== NULL
) {
818 fprintf(stderr
, "[%s:%u] Error creating FBConfig!\n", __func__
,
823 return (const __DRIconfig
**)configs
;
826 struct intel_buffer
{
828 struct intel_region
*region
;
832 * \brief Get tiling format for a DRI buffer.
834 * \param attachment is the buffer's attachmet point, such as
835 * __DRI_BUFFER_DEPTH.
836 * \param out_tiling is the returned tiling format for buffer.
837 * \return false if attachment is unrecognized or is incompatible with screen.
840 intel_get_dri_buffer_tiling(struct intel_screen
*screen
,
842 uint32_t *out_tiling
)
844 if (screen
->gen
< 4) {
845 *out_tiling
= I915_TILING_X
;
849 switch (attachment
) {
850 case __DRI_BUFFER_DEPTH
:
851 case __DRI_BUFFER_DEPTH_STENCIL
:
852 case __DRI_BUFFER_HIZ
:
853 *out_tiling
= I915_TILING_Y
;
855 case __DRI_BUFFER_ACCUM
:
856 case __DRI_BUFFER_FRONT_LEFT
:
857 case __DRI_BUFFER_FRONT_RIGHT
:
858 case __DRI_BUFFER_BACK_LEFT
:
859 case __DRI_BUFFER_BACK_RIGHT
:
860 case __DRI_BUFFER_FAKE_FRONT_LEFT
:
861 case __DRI_BUFFER_FAKE_FRONT_RIGHT
:
862 *out_tiling
= I915_TILING_X
;
864 case __DRI_BUFFER_STENCIL
:
865 /* The stencil buffer is W tiled. However, we request from the kernel
866 * a non-tiled buffer because the GTT is incapable of W fencing.
868 *out_tiling
= I915_TILING_NONE
;
871 if(unlikely(INTEL_DEBUG
& DEBUG_DRI
)) {
872 fprintf(stderr
, "error: %s: unrecognized DRI buffer attachment 0x%x\n",
873 __FUNCTION__
, attachment
);
880 intelAllocateBuffer(__DRIscreen
*screen
,
881 unsigned attachment
, unsigned format
,
882 int width
, int height
)
884 struct intel_buffer
*intelBuffer
;
885 struct intel_screen
*intelScreen
= screen
->driverPrivate
;
888 uint32_t region_width
;
889 uint32_t region_height
;
894 ok
= intel_get_dri_buffer_tiling(intelScreen
, attachment
, &tiling
);
898 intelBuffer
= CALLOC(sizeof *intelBuffer
);
899 if (intelBuffer
== NULL
)
902 if (attachment
== __DRI_BUFFER_STENCIL
) {
903 /* The stencil buffer has quirky pitch requirements. From Vol 2a,
904 * 11.5.6.2.1 3DSTATE_STENCIL_BUFFER, field "Surface Pitch":
905 * The pitch must be set to 2x the value computed based on width, as
906 * the stencil buffer is stored with two rows interleaved.
907 * To accomplish this, we resort to the nasty hack of doubling the
908 * region's cpp and halving its height.
910 region_width
= ALIGN(width
, 64);
911 region_height
= ALIGN(ALIGN(height
, 2) / 2, 64);
912 region_cpp
= format
/ 4;
914 region_width
= width
;
915 region_height
= height
;
916 region_cpp
= format
/ 8;
919 intelBuffer
->region
= intel_region_alloc(intelScreen
,
926 if (intelBuffer
->region
== NULL
) {
931 intel_region_flink(intelBuffer
->region
, &intelBuffer
->base
.name
);
933 intelBuffer
->base
.attachment
= attachment
;
934 intelBuffer
->base
.cpp
= intelBuffer
->region
->cpp
;
935 intelBuffer
->base
.pitch
=
936 intelBuffer
->region
->pitch
* intelBuffer
->region
->cpp
;
938 return &intelBuffer
->base
;
942 intelReleaseBuffer(__DRIscreen
*screen
, __DRIbuffer
*buffer
)
944 struct intel_buffer
*intelBuffer
= (struct intel_buffer
*) buffer
;
946 intel_region_release(&intelBuffer
->region
);
951 const struct __DriverAPIRec driDriverAPI
= {
952 .InitScreen
= intelInitScreen2
,
953 .DestroyScreen
= intelDestroyScreen
,
954 .CreateContext
= intelCreateContext
,
955 .DestroyContext
= intelDestroyContext
,
956 .CreateBuffer
= intelCreateBuffer
,
957 .DestroyBuffer
= intelDestroyBuffer
,
958 .MakeCurrent
= intelMakeCurrent
,
959 .UnbindContext
= intelUnbindContext
,
960 .AllocateBuffer
= intelAllocateBuffer
,
961 .ReleaseBuffer
= intelReleaseBuffer
964 /* This is the table of extensions that the loader will dlsym() for. */
965 PUBLIC
const __DRIextension
*__driDriverExtensions
[] = {
966 &driCoreExtension
.base
,
967 &driDRI2Extension
.base
,