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
);
121 INTEL_FIREVERTICES(intel
);
123 intel
->need_throttle
= true;
125 if (intel
->batch
.used
)
126 intel_batchbuffer_flush(intel
);
129 static const struct __DRI2flushExtensionRec intelFlushExtension
= {
130 { __DRI2_FLUSH
, __DRI2_FLUSH_VERSION
},
132 dri2InvalidateDrawable
,
136 intel_create_image_from_name(__DRIscreen
*screen
,
137 int width
, int height
, int format
,
138 int name
, int pitch
, void *loaderPrivate
)
140 struct intel_screen
*intelScreen
= screen
->driverPrivate
;
144 image
= CALLOC(sizeof *image
);
149 case __DRI_IMAGE_FORMAT_RGB565
:
150 image
->format
= MESA_FORMAT_RGB565
;
151 image
->internal_format
= GL_RGB
;
152 image
->data_type
= GL_UNSIGNED_BYTE
;
154 case __DRI_IMAGE_FORMAT_XRGB8888
:
155 image
->format
= MESA_FORMAT_XRGB8888
;
156 image
->internal_format
= GL_RGB
;
157 image
->data_type
= GL_UNSIGNED_BYTE
;
159 case __DRI_IMAGE_FORMAT_ARGB8888
:
160 image
->format
= MESA_FORMAT_ARGB8888
;
161 image
->internal_format
= GL_RGBA
;
162 image
->data_type
= GL_UNSIGNED_BYTE
;
164 case __DRI_IMAGE_FORMAT_ABGR8888
:
165 image
->format
= MESA_FORMAT_RGBA8888_REV
;
166 image
->internal_format
= GL_RGBA
;
167 image
->data_type
= GL_UNSIGNED_BYTE
;
174 image
->data
= loaderPrivate
;
175 cpp
= _mesa_get_format_bytes(image
->format
);
177 image
->region
= intel_region_alloc_for_handle(intelScreen
,
179 pitch
, name
, "image");
180 if (image
->region
== NULL
) {
189 intel_create_image_from_renderbuffer(__DRIcontext
*context
,
190 int renderbuffer
, void *loaderPrivate
)
193 struct intel_context
*intel
= context
->driverPrivate
;
194 struct gl_renderbuffer
*rb
;
195 struct intel_renderbuffer
*irb
;
197 rb
= _mesa_lookup_renderbuffer(&intel
->ctx
, renderbuffer
);
199 _mesa_error(&intel
->ctx
,
200 GL_INVALID_OPERATION
, "glRenderbufferExternalMESA");
204 irb
= intel_renderbuffer(rb
);
205 image
= CALLOC(sizeof *image
);
209 image
->internal_format
= rb
->InternalFormat
;
210 image
->format
= rb
->Format
;
211 image
->data_type
= rb
->DataType
;
212 image
->data
= loaderPrivate
;
213 intel_region_reference(&image
->region
, irb
->mt
->region
);
219 intel_destroy_image(__DRIimage
*image
)
221 intel_region_release(&image
->region
);
226 intel_create_image(__DRIscreen
*screen
,
227 int width
, int height
, int format
,
232 struct intel_screen
*intelScreen
= screen
->driverPrivate
;
236 tiling
= I915_TILING_X
;
237 if (use
& __DRI_IMAGE_USE_CURSOR
) {
238 if (width
!= 64 || height
!= 64)
240 tiling
= I915_TILING_NONE
;
243 image
= CALLOC(sizeof *image
);
248 case __DRI_IMAGE_FORMAT_RGB565
:
249 image
->format
= MESA_FORMAT_RGB565
;
250 image
->internal_format
= GL_RGB
;
251 image
->data_type
= GL_UNSIGNED_BYTE
;
253 case __DRI_IMAGE_FORMAT_XRGB8888
:
254 image
->format
= MESA_FORMAT_XRGB8888
;
255 image
->internal_format
= GL_RGB
;
256 image
->data_type
= GL_UNSIGNED_BYTE
;
258 case __DRI_IMAGE_FORMAT_ARGB8888
:
259 image
->format
= MESA_FORMAT_ARGB8888
;
260 image
->internal_format
= GL_RGBA
;
261 image
->data_type
= GL_UNSIGNED_BYTE
;
263 case __DRI_IMAGE_FORMAT_ABGR8888
:
264 image
->format
= MESA_FORMAT_RGBA8888_REV
;
265 image
->internal_format
= GL_RGBA
;
266 image
->data_type
= GL_UNSIGNED_BYTE
;
273 image
->data
= loaderPrivate
;
274 cpp
= _mesa_get_format_bytes(image
->format
);
277 intel_region_alloc(intelScreen
, tiling
,
278 cpp
, width
, height
, true);
279 if (image
->region
== NULL
) {
288 intel_query_image(__DRIimage
*image
, int attrib
, int *value
)
291 case __DRI_IMAGE_ATTRIB_STRIDE
:
292 *value
= image
->region
->pitch
* image
->region
->cpp
;
294 case __DRI_IMAGE_ATTRIB_HANDLE
:
295 *value
= image
->region
->bo
->handle
;
297 case __DRI_IMAGE_ATTRIB_NAME
:
298 return intel_region_flink(image
->region
, (uint32_t *) value
);
305 intel_dup_image(__DRIimage
*orig_image
, void *loaderPrivate
)
309 image
= CALLOC(sizeof *image
);
313 intel_region_reference(&image
->region
, orig_image
->region
);
314 if (image
->region
== NULL
) {
319 image
->internal_format
= orig_image
->internal_format
;
320 image
->format
= orig_image
->format
;
321 image
->data_type
= orig_image
->data_type
;
322 image
->data
= loaderPrivate
;
327 static struct __DRIimageExtensionRec intelImageExtension
= {
328 { __DRI_IMAGE
, __DRI_IMAGE_VERSION
},
329 intel_create_image_from_name
,
330 intel_create_image_from_renderbuffer
,
337 static const __DRIextension
*intelScreenExtensions
[] = {
338 &intelTexBufferExtension
.base
,
339 &intelFlushExtension
.base
,
340 &intelImageExtension
.base
,
341 &dri2ConfigQueryExtension
.base
,
346 intel_get_param(__DRIscreen
*psp
, int param
, int *value
)
349 struct drm_i915_getparam gp
;
354 ret
= drmCommandWriteRead(psp
->fd
, DRM_I915_GETPARAM
, &gp
, sizeof(gp
));
357 _mesa_warning(NULL
, "drm_i915_getparam: %d", ret
);
365 intel_get_boolean(__DRIscreen
*psp
, int param
)
368 return intel_get_param(psp
, param
, &value
) && value
;
372 nop_callback(GLuint key
, void *data
, void *userData
)
377 intelDestroyScreen(__DRIscreen
* sPriv
)
379 struct intel_screen
*intelScreen
= sPriv
->driverPrivate
;
381 dri_bufmgr_destroy(intelScreen
->bufmgr
);
382 driDestroyOptionInfo(&intelScreen
->optionCache
);
384 /* Some regions may still have references to them at this point, so
385 * flush the hash table to prevent _mesa_DeleteHashTable() from
386 * complaining about the hash not being empty; */
387 _mesa_HashDeleteAll(intelScreen
->named_regions
, nop_callback
, NULL
);
388 _mesa_DeleteHashTable(intelScreen
->named_regions
);
391 sPriv
->driverPrivate
= NULL
;
396 * This is called when we need to set up GL rendering to a new X window.
399 intelCreateBuffer(__DRIscreen
* driScrnPriv
,
400 __DRIdrawable
* driDrawPriv
,
401 const struct gl_config
* mesaVis
, GLboolean isPixmap
)
403 struct intel_renderbuffer
*rb
;
404 struct intel_screen
*screen
= (struct intel_screen
*) driScrnPriv
->driverPrivate
;
407 return false; /* not implemented */
412 struct gl_framebuffer
*fb
= CALLOC_STRUCT(gl_framebuffer
);
417 _mesa_initialize_window_framebuffer(fb
, mesaVis
);
419 if (mesaVis
->redBits
== 5)
420 rgbFormat
= MESA_FORMAT_RGB565
;
421 else if (mesaVis
->alphaBits
== 0)
422 rgbFormat
= MESA_FORMAT_XRGB8888
;
424 rgbFormat
= MESA_FORMAT_ARGB8888
;
426 /* setup the hardware-based renderbuffers */
427 rb
= intel_create_renderbuffer(rgbFormat
);
428 _mesa_add_renderbuffer(fb
, BUFFER_FRONT_LEFT
, &rb
->Base
);
430 if (mesaVis
->doubleBufferMode
) {
431 rb
= intel_create_renderbuffer(rgbFormat
);
432 _mesa_add_renderbuffer(fb
, BUFFER_BACK_LEFT
, &rb
->Base
);
436 * Assert here that the gl_config has an expected depth/stencil bit
437 * combination: one of d24/s8, d16/s0, d0/s0. (See intelInitScreen2(),
438 * which constructs the advertised configs.)
440 if (mesaVis
->depthBits
== 24) {
441 assert(mesaVis
->stencilBits
== 8);
443 if (screen
->hw_has_separate_stencil
444 && screen
->dri2_has_hiz
!= INTEL_DRI2_HAS_HIZ_FALSE
) {
446 * Request a separate stencil buffer even if we do not yet know if
447 * the screen supports it. (See comments for
448 * enum intel_dri2_has_hiz).
450 rb
= intel_create_renderbuffer(MESA_FORMAT_X8_Z24
);
451 _mesa_add_renderbuffer(fb
, BUFFER_DEPTH
, &rb
->Base
);
452 rb
= intel_create_renderbuffer(MESA_FORMAT_S8
);
453 _mesa_add_renderbuffer(fb
, BUFFER_STENCIL
, &rb
->Base
);
456 * Use combined depth/stencil. Note that the renderbuffer is
457 * attached to two attachment points.
459 rb
= intel_create_renderbuffer(MESA_FORMAT_S8_Z24
);
460 _mesa_add_renderbuffer(fb
, BUFFER_DEPTH
, &rb
->Base
);
461 _mesa_add_renderbuffer(fb
, BUFFER_STENCIL
, &rb
->Base
);
464 else if (mesaVis
->depthBits
== 16) {
465 assert(mesaVis
->stencilBits
== 0);
466 /* just 16-bit depth buffer, no hw stencil */
467 struct intel_renderbuffer
*depthRb
468 = intel_create_renderbuffer(MESA_FORMAT_Z16
);
469 _mesa_add_renderbuffer(fb
, BUFFER_DEPTH
, &depthRb
->Base
);
472 assert(mesaVis
->depthBits
== 0);
473 assert(mesaVis
->stencilBits
== 0);
476 /* now add any/all software-based renderbuffers we may need */
477 _swrast_add_soft_renderbuffers(fb
,
478 false, /* never sw color */
479 false, /* never sw depth */
480 false, /* never sw stencil */
481 mesaVis
->accumRedBits
> 0,
482 false, /* never sw alpha */
483 false /* never sw aux */ );
484 driDrawPriv
->driverPrivate
= fb
;
491 intelDestroyBuffer(__DRIdrawable
* driDrawPriv
)
493 struct gl_framebuffer
*fb
= driDrawPriv
->driverPrivate
;
495 _mesa_reference_framebuffer(&fb
, NULL
);
498 /* There are probably better ways to do this, such as an
499 * init-designated function to register chipids and createcontext
503 i830CreateContext(const struct gl_config
*mesaVis
,
504 __DRIcontext
*driContextPriv
,
505 void *sharedContextPrivate
);
508 i915CreateContext(int api
,
509 const struct gl_config
*mesaVis
,
510 __DRIcontext
*driContextPriv
,
511 void *sharedContextPrivate
);
513 brwCreateContext(int api
,
514 const struct gl_config
*mesaVis
,
515 __DRIcontext
*driContextPriv
,
516 void *sharedContextPrivate
);
519 intelCreateContext(gl_api api
,
520 const struct gl_config
* mesaVis
,
521 __DRIcontext
* driContextPriv
,
522 unsigned major_version
,
523 unsigned minor_version
,
526 void *sharedContextPrivate
)
528 __DRIscreen
*sPriv
= driContextPriv
->driScreenPriv
;
529 struct intel_screen
*intelScreen
= sPriv
->driverPrivate
;
530 bool success
= false;
533 if (IS_9XX(intelScreen
->deviceID
)) {
534 if (!IS_965(intelScreen
->deviceID
)) {
535 success
= i915CreateContext(api
, mesaVis
, driContextPriv
,
536 sharedContextPrivate
);
539 intelScreen
->no_vbo
= true;
540 success
= i830CreateContext(mesaVis
, driContextPriv
,
541 sharedContextPrivate
);
544 if (IS_965(intelScreen
->deviceID
))
545 success
= brwCreateContext(api
, mesaVis
,
547 sharedContextPrivate
);
551 struct gl_context
*ctx
=
552 (struct gl_context
*) driContextPriv
->driverPrivate
;
554 _mesa_compute_version(ctx
);
555 if (ctx
->VersionMajor
> major_version
556 || (ctx
->VersionMajor
== major_version
557 && ctx
->VersionMinor
>= minor_version
)) {
558 *error
= __DRI_CTX_ERROR_BAD_VERSION
;
562 intelDestroyContext(driContextPriv
);
564 *error
= __DRI_CTX_ERROR_NO_MEMORY
;
565 fprintf(stderr
, "Unrecognized deviceID 0x%x\n", intelScreen
->deviceID
);
572 intel_init_bufmgr(struct intel_screen
*intelScreen
)
574 __DRIscreen
*spriv
= intelScreen
->driScrnPriv
;
577 intelScreen
->no_hw
= (getenv("INTEL_NO_HW") != NULL
||
578 getenv("INTEL_DEVID_OVERRIDE") != NULL
);
580 intelScreen
->bufmgr
= intel_bufmgr_gem_init(spriv
->fd
, BATCH_SZ
);
581 if (intelScreen
->bufmgr
== NULL
) {
582 fprintf(stderr
, "[%s:%u] Error initializing buffer manager.\n",
587 if (!intel_get_param(spriv
, I915_PARAM_NUM_FENCES_AVAIL
, &num_fences
) ||
589 fprintf(stderr
, "[%s: %u] Kernel 2.6.29 required.\n", __func__
, __LINE__
);
593 drm_intel_bufmgr_gem_enable_fenced_relocs(intelScreen
->bufmgr
);
595 intelScreen
->named_regions
= _mesa_NewHashTable();
597 intelScreen
->relaxed_relocations
= 0;
598 intelScreen
->relaxed_relocations
|=
599 intel_get_boolean(spriv
, I915_PARAM_HAS_RELAXED_DELTA
) << 0;
605 * Override intel_screen.hw_has_hiz with environment variable INTEL_HIZ.
607 * Valid values for INTEL_HIZ are "0" and "1". If an invalid valid value is
608 * encountered, a warning is emitted and INTEL_HIZ is ignored.
611 intel_override_hiz(struct intel_screen
*intel
)
613 const char *s
= getenv("INTEL_HIZ");
616 } else if (!strncmp("0", s
, 2)) {
617 intel
->hw_has_hiz
= false;
618 } else if (!strncmp("1", s
, 2)) {
619 intel
->hw_has_hiz
= true;
622 "warning: env variable INTEL_HIZ=\"%s\" has invalid value "
623 "and is ignored", s
);
628 * Override intel_screen.hw_has_separate_stencil with environment variable
629 * INTEL_SEPARATE_STENCIL.
631 * Valid values for INTEL_SEPARATE_STENCIL are "0" and "1". If an invalid
632 * valid value is encountered, a warning is emitted and INTEL_SEPARATE_STENCIL
636 intel_override_separate_stencil(struct intel_screen
*screen
)
638 const char *s
= getenv("INTEL_SEPARATE_STENCIL");
641 } else if (!strncmp("0", s
, 2)) {
642 screen
->hw_has_separate_stencil
= false;
643 } else if (!strncmp("1", s
, 2)) {
644 screen
->hw_has_separate_stencil
= true;
647 "warning: env variable INTEL_SEPARATE_STENCIL=\"%s\" has "
648 "invalid value and is ignored", s
);
653 * This is the driver specific part of the createNewScreen entry point.
654 * Called when using DRI2.
656 * \return the struct gl_config supported by this driver
659 __DRIconfig
**intelInitScreen2(__DRIscreen
*psp
)
661 struct intel_screen
*intelScreen
;
664 unsigned int api_mask
;
665 char *devid_override
;
667 static const GLenum back_buffer_modes
[] = {
668 GLX_NONE
, GLX_SWAP_UNDEFINED_OML
, GLX_SWAP_COPY_OML
670 uint8_t depth_bits
[4], stencil_bits
[4], msaa_samples_array
[1];
672 __DRIconfig
**configs
= NULL
;
674 /* Allocate the private area */
675 intelScreen
= CALLOC(sizeof *intelScreen
);
677 fprintf(stderr
, "\nERROR! Allocating private area failed\n");
680 /* parse information in __driConfigOptions */
681 driParseOptionInfo(&intelScreen
->optionCache
,
682 __driConfigOptions
, __driNConfigOptions
);
684 intelScreen
->driScrnPriv
= psp
;
685 psp
->driverPrivate
= (void *) intelScreen
;
687 /* Determine chipset ID */
688 if (!intel_get_param(psp
, I915_PARAM_CHIPSET_ID
,
689 &intelScreen
->deviceID
))
692 /* Allow an override of the device ID for the purpose of making the
693 * driver produce dumps for debugging of new chipset enablement.
694 * This implies INTEL_NO_HW, to avoid programming your actual GPU
697 devid_override
= getenv("INTEL_DEVID_OVERRIDE");
698 if (devid_override
) {
699 intelScreen
->deviceID
= strtod(devid_override
, NULL
);
702 intelScreen
->kernel_has_gen7_sol_reset
=
703 intel_get_boolean(intelScreen
->driScrnPriv
,
704 I915_PARAM_HAS_GEN7_SOL_RESET
);
706 if (IS_GEN7(intelScreen
->deviceID
)) {
707 intelScreen
->gen
= 7;
708 } else if (IS_GEN6(intelScreen
->deviceID
)) {
709 intelScreen
->gen
= 6;
710 } else if (IS_GEN5(intelScreen
->deviceID
)) {
711 intelScreen
->gen
= 5;
712 } else if (IS_965(intelScreen
->deviceID
)) {
713 intelScreen
->gen
= 4;
714 } else if (IS_9XX(intelScreen
->deviceID
)) {
715 intelScreen
->gen
= 3;
717 intelScreen
->gen
= 2;
720 intelScreen
->hw_has_separate_stencil
= intelScreen
->gen
>= 6;
721 intelScreen
->hw_must_use_separate_stencil
= intelScreen
->gen
>= 7;
722 intelScreen
->hw_has_hiz
= intelScreen
->gen
>= 6;
723 intelScreen
->dri2_has_hiz
= INTEL_DRI2_HAS_HIZ_UNKNOWN
;
725 intel_override_hiz(intelScreen
);
726 intel_override_separate_stencil(intelScreen
);
728 api_mask
= (1 << __DRI_API_OPENGL
);
730 api_mask
|= (1 << __DRI_API_GLES
);
733 api_mask
|= (1 << __DRI_API_GLES2
);
736 if (IS_9XX(intelScreen
->deviceID
) || IS_965(intelScreen
->deviceID
))
737 psp
->api_mask
= api_mask
;
739 if (!intel_init_bufmgr(intelScreen
))
742 psp
->extensions
= intelScreenExtensions
;
744 msaa_samples_array
[0] = 0;
746 fb_format
[0] = GL_RGB
;
747 fb_type
[0] = GL_UNSIGNED_SHORT_5_6_5
;
749 fb_format
[1] = GL_BGR
;
750 fb_type
[1] = GL_UNSIGNED_INT_8_8_8_8_REV
;
752 fb_format
[2] = GL_BGRA
;
753 fb_type
[2] = GL_UNSIGNED_INT_8_8_8_8_REV
;
758 /* Generate a rich set of useful configs that do not include an
759 * accumulation buffer.
761 for (color
= 0; color
< ARRAY_SIZE(fb_format
); color
++) {
762 __DRIconfig
**new_configs
;
765 /* Starting with DRI2 protocol version 1.1 we can request a depth/stencil
766 * buffer that has a diffferent number of bits per pixel than the color
767 * buffer. This isn't yet supported here.
769 if (fb_type
[color
] == GL_UNSIGNED_SHORT_5_6_5
) {
779 new_configs
= driCreateConfigs(fb_format
[color
], fb_type
[color
],
784 ARRAY_SIZE(back_buffer_modes
),
786 ARRAY_SIZE(msaa_samples_array
),
789 configs
= new_configs
;
791 configs
= driConcatConfigs(configs
, new_configs
);
794 /* Generate the minimum possible set of configs that include an
795 * accumulation buffer.
797 for (color
= 0; color
< ARRAY_SIZE(fb_format
); color
++) {
798 __DRIconfig
**new_configs
;
800 if (fb_type
[color
] == GL_UNSIGNED_SHORT_5_6_5
) {
808 new_configs
= driCreateConfigs(fb_format
[color
], fb_type
[color
],
809 depth_bits
, stencil_bits
, 1,
810 back_buffer_modes
+ 1, 1,
811 msaa_samples_array
, 1,
814 configs
= new_configs
;
816 configs
= driConcatConfigs(configs
, new_configs
);
819 if (configs
== NULL
) {
820 fprintf(stderr
, "[%s:%u] Error creating FBConfig!\n", __func__
,
825 return (const __DRIconfig
**)configs
;
828 struct intel_buffer
{
830 struct intel_region
*region
;
834 * \brief Get tiling format for a DRI buffer.
836 * \param attachment is the buffer's attachmet point, such as
837 * __DRI_BUFFER_DEPTH.
838 * \param out_tiling is the returned tiling format for buffer.
839 * \return false if attachment is unrecognized or is incompatible with screen.
842 intel_get_dri_buffer_tiling(struct intel_screen
*screen
,
844 uint32_t *out_tiling
)
846 if (screen
->gen
< 4) {
847 *out_tiling
= I915_TILING_X
;
851 switch (attachment
) {
852 case __DRI_BUFFER_DEPTH
:
853 case __DRI_BUFFER_DEPTH_STENCIL
:
854 case __DRI_BUFFER_HIZ
:
855 *out_tiling
= I915_TILING_Y
;
857 case __DRI_BUFFER_ACCUM
:
858 case __DRI_BUFFER_FRONT_LEFT
:
859 case __DRI_BUFFER_FRONT_RIGHT
:
860 case __DRI_BUFFER_BACK_LEFT
:
861 case __DRI_BUFFER_BACK_RIGHT
:
862 case __DRI_BUFFER_FAKE_FRONT_LEFT
:
863 case __DRI_BUFFER_FAKE_FRONT_RIGHT
:
864 *out_tiling
= I915_TILING_X
;
866 case __DRI_BUFFER_STENCIL
:
867 /* The stencil buffer is W tiled. However, we request from the kernel
868 * a non-tiled buffer because the GTT is incapable of W fencing.
870 *out_tiling
= I915_TILING_NONE
;
873 if(unlikely(INTEL_DEBUG
& DEBUG_DRI
)) {
874 fprintf(stderr
, "error: %s: unrecognized DRI buffer attachment 0x%x\n",
875 __FUNCTION__
, attachment
);
882 intelAllocateBuffer(__DRIscreen
*screen
,
883 unsigned attachment
, unsigned format
,
884 int width
, int height
)
886 struct intel_buffer
*intelBuffer
;
887 struct intel_screen
*intelScreen
= screen
->driverPrivate
;
890 uint32_t region_width
;
891 uint32_t region_height
;
896 ok
= intel_get_dri_buffer_tiling(intelScreen
, attachment
, &tiling
);
900 intelBuffer
= CALLOC(sizeof *intelBuffer
);
901 if (intelBuffer
== NULL
)
904 if (attachment
== __DRI_BUFFER_STENCIL
) {
905 /* The stencil buffer has quirky pitch requirements. From Vol 2a,
906 * 11.5.6.2.1 3DSTATE_STENCIL_BUFFER, field "Surface Pitch":
907 * The pitch must be set to 2x the value computed based on width, as
908 * the stencil buffer is stored with two rows interleaved.
909 * To accomplish this, we resort to the nasty hack of doubling the
910 * region's cpp and halving its height.
912 region_width
= ALIGN(width
, 64);
913 region_height
= ALIGN(ALIGN(height
, 2) / 2, 64);
914 region_cpp
= format
/ 4;
916 region_width
= width
;
917 region_height
= height
;
918 region_cpp
= format
/ 8;
921 intelBuffer
->region
= intel_region_alloc(intelScreen
,
928 if (intelBuffer
->region
== NULL
) {
933 intel_region_flink(intelBuffer
->region
, &intelBuffer
->base
.name
);
935 intelBuffer
->base
.attachment
= attachment
;
936 intelBuffer
->base
.cpp
= intelBuffer
->region
->cpp
;
937 intelBuffer
->base
.pitch
=
938 intelBuffer
->region
->pitch
* intelBuffer
->region
->cpp
;
940 return &intelBuffer
->base
;
944 intelReleaseBuffer(__DRIscreen
*screen
, __DRIbuffer
*buffer
)
946 struct intel_buffer
*intelBuffer
= (struct intel_buffer
*) buffer
;
948 intel_region_release(&intelBuffer
->region
);
953 const struct __DriverAPIRec driDriverAPI
= {
954 .InitScreen
= intelInitScreen2
,
955 .DestroyScreen
= intelDestroyScreen
,
956 .CreateContext
= intelCreateContext
,
957 .DestroyContext
= intelDestroyContext
,
958 .CreateBuffer
= intelCreateBuffer
,
959 .DestroyBuffer
= intelDestroyBuffer
,
960 .MakeCurrent
= intelMakeCurrent
,
961 .UnbindContext
= intelUnbindContext
,
962 .AllocateBuffer
= intelAllocateBuffer
,
963 .ReleaseBuffer
= intelReleaseBuffer
966 /* This is the table of extensions that the loader will dlsym() for. */
967 PUBLIC
const __DRIextension
*__driDriverExtensions
[] = {
968 &driCoreExtension
.base
,
969 &driDRI2Extension
.base
,