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(hiz
, bool, true)
61 DRI_CONF_DESC(en
, "Enable Hierarchical Z on gen6+")
64 DRI_CONF_OPT_BEGIN(early_z
, bool, false)
65 DRI_CONF_DESC(en
, "Enable early Z in classic mode (unstable, 945-only).")
68 DRI_CONF_OPT_BEGIN(fragment_shader
, bool, true)
69 DRI_CONF_DESC(en
, "Enable limited ARB_fragment_shader support on 915/945.")
73 DRI_CONF_SECTION_QUALITY
74 DRI_CONF_FORCE_S3TC_ENABLE(false)
75 DRI_CONF_ALLOW_LARGE_TEXTURES(2)
77 DRI_CONF_SECTION_DEBUG
78 DRI_CONF_NO_RAST(false)
79 DRI_CONF_ALWAYS_FLUSH_BATCH(false)
80 DRI_CONF_ALWAYS_FLUSH_CACHE(false)
81 DRI_CONF_FORCE_GLSL_EXTENSIONS_WARN(false)
83 DRI_CONF_OPT_BEGIN(stub_occlusion_query
, bool, false)
84 DRI_CONF_DESC(en
, "Enable stub ARB_occlusion_query support on 915/945.")
87 DRI_CONF_OPT_BEGIN(shader_precompile
, bool, false)
88 DRI_CONF_DESC(en
, "Perform code generation at shader link time.")
93 const GLuint __driNConfigOptions
= 14;
95 #include "intel_batchbuffer.h"
96 #include "intel_buffers.h"
97 #include "intel_bufmgr.h"
98 #include "intel_chipset.h"
99 #include "intel_fbo.h"
100 #include "intel_mipmap_tree.h"
101 #include "intel_screen.h"
102 #include "intel_tex.h"
103 #include "intel_regions.h"
105 #include "i915_drm.h"
107 #ifdef USE_NEW_INTERFACE
108 static PFNGLXCREATECONTEXTMODES create_context_modes
= NULL
;
109 #endif /*USE_NEW_INTERFACE */
111 static const __DRItexBufferExtension intelTexBufferExtension
= {
112 { __DRI_TEX_BUFFER
, __DRI_TEX_BUFFER_VERSION
},
118 intelDRI2Flush(__DRIdrawable
*drawable
)
120 GET_CURRENT_CONTEXT(ctx
);
121 struct intel_context
*intel
= intel_context(ctx
);
126 INTEL_FIREVERTICES(intel
);
128 intel
->need_throttle
= true;
130 if (intel
->batch
.used
)
131 intel_batchbuffer_flush(intel
);
133 if (INTEL_DEBUG
& DEBUG_AUB
) {
134 struct gl_framebuffer
*fb
= ctx
->DrawBuffer
;
136 for (int i
= 0; i
< fb
->_NumColorDrawBuffers
; i
++) {
137 struct intel_renderbuffer
*irb
=
138 intel_renderbuffer(fb
->_ColorDrawBuffers
[i
]);
140 if (irb
&& irb
->mt
) {
141 enum aub_dump_bmp_format format
;
143 switch (irb
->Base
.Base
.Format
) {
144 case MESA_FORMAT_ARGB8888
:
145 case MESA_FORMAT_XRGB8888
:
146 format
= AUB_DUMP_BMP_FORMAT_ARGB_8888
;
152 drm_intel_gem_bo_aub_dump_bmp(irb
->mt
->region
->bo
,
155 irb
->Base
.Base
.Width
,
156 irb
->Base
.Base
.Height
,
158 irb
->mt
->region
->pitch
*
159 irb
->mt
->region
->cpp
,
166 static const struct __DRI2flushExtensionRec intelFlushExtension
= {
167 { __DRI2_FLUSH
, __DRI2_FLUSH_VERSION
},
169 dri2InvalidateDrawable
,
173 intel_create_image_from_name(__DRIscreen
*screen
,
174 int width
, int height
, int format
,
175 int name
, int pitch
, void *loaderPrivate
)
177 struct intel_screen
*intelScreen
= screen
->driverPrivate
;
181 image
= CALLOC(sizeof *image
);
186 case __DRI_IMAGE_FORMAT_RGB565
:
187 image
->format
= MESA_FORMAT_RGB565
;
188 image
->internal_format
= GL_RGB
;
189 image
->data_type
= GL_UNSIGNED_BYTE
;
191 case __DRI_IMAGE_FORMAT_XRGB8888
:
192 image
->format
= MESA_FORMAT_XRGB8888
;
193 image
->internal_format
= GL_RGB
;
194 image
->data_type
= GL_UNSIGNED_BYTE
;
196 case __DRI_IMAGE_FORMAT_ARGB8888
:
197 image
->format
= MESA_FORMAT_ARGB8888
;
198 image
->internal_format
= GL_RGBA
;
199 image
->data_type
= GL_UNSIGNED_BYTE
;
201 case __DRI_IMAGE_FORMAT_ABGR8888
:
202 image
->format
= MESA_FORMAT_RGBA8888_REV
;
203 image
->internal_format
= GL_RGBA
;
204 image
->data_type
= GL_UNSIGNED_BYTE
;
211 image
->data
= loaderPrivate
;
212 cpp
= _mesa_get_format_bytes(image
->format
);
214 image
->region
= intel_region_alloc_for_handle(intelScreen
,
216 pitch
, name
, "image");
217 if (image
->region
== NULL
) {
226 intel_create_image_from_renderbuffer(__DRIcontext
*context
,
227 int renderbuffer
, void *loaderPrivate
)
230 struct intel_context
*intel
= context
->driverPrivate
;
231 struct gl_renderbuffer
*rb
;
232 struct intel_renderbuffer
*irb
;
234 rb
= _mesa_lookup_renderbuffer(&intel
->ctx
, renderbuffer
);
236 _mesa_error(&intel
->ctx
,
237 GL_INVALID_OPERATION
, "glRenderbufferExternalMESA");
241 irb
= intel_renderbuffer(rb
);
242 image
= CALLOC(sizeof *image
);
246 image
->internal_format
= rb
->InternalFormat
;
247 image
->format
= rb
->Format
;
248 image
->data_type
= GL_UNSIGNED_BYTE
;
249 image
->data
= loaderPrivate
;
250 intel_region_reference(&image
->region
, irb
->mt
->region
);
256 intel_destroy_image(__DRIimage
*image
)
258 intel_region_release(&image
->region
);
263 intel_create_image(__DRIscreen
*screen
,
264 int width
, int height
, int format
,
269 struct intel_screen
*intelScreen
= screen
->driverPrivate
;
273 tiling
= I915_TILING_X
;
274 if (use
& __DRI_IMAGE_USE_CURSOR
) {
275 if (width
!= 64 || height
!= 64)
277 tiling
= I915_TILING_NONE
;
280 image
= CALLOC(sizeof *image
);
284 image
->dri_format
= format
;
287 case __DRI_IMAGE_FORMAT_RGB565
:
288 image
->format
= MESA_FORMAT_RGB565
;
289 image
->internal_format
= GL_RGB
;
290 image
->data_type
= GL_UNSIGNED_BYTE
;
292 case __DRI_IMAGE_FORMAT_XRGB8888
:
293 image
->format
= MESA_FORMAT_XRGB8888
;
294 image
->internal_format
= GL_RGB
;
295 image
->data_type
= GL_UNSIGNED_BYTE
;
297 case __DRI_IMAGE_FORMAT_ARGB8888
:
298 image
->format
= MESA_FORMAT_ARGB8888
;
299 image
->internal_format
= GL_RGBA
;
300 image
->data_type
= GL_UNSIGNED_BYTE
;
302 case __DRI_IMAGE_FORMAT_ABGR8888
:
303 image
->format
= MESA_FORMAT_RGBA8888_REV
;
304 image
->internal_format
= GL_RGBA
;
305 image
->data_type
= GL_UNSIGNED_BYTE
;
312 image
->data
= loaderPrivate
;
313 cpp
= _mesa_get_format_bytes(image
->format
);
316 intel_region_alloc(intelScreen
, tiling
,
317 cpp
, width
, height
, true);
318 if (image
->region
== NULL
) {
327 intel_query_image(__DRIimage
*image
, int attrib
, int *value
)
330 case __DRI_IMAGE_ATTRIB_STRIDE
:
331 *value
= image
->region
->pitch
* image
->region
->cpp
;
333 case __DRI_IMAGE_ATTRIB_HANDLE
:
334 *value
= image
->region
->bo
->handle
;
336 case __DRI_IMAGE_ATTRIB_NAME
:
337 return intel_region_flink(image
->region
, (uint32_t *) value
);
338 case __DRI_IMAGE_ATTRIB_FORMAT
:
339 return image
->dri_format
;
346 intel_dup_image(__DRIimage
*orig_image
, void *loaderPrivate
)
350 image
= CALLOC(sizeof *image
);
354 intel_region_reference(&image
->region
, orig_image
->region
);
355 if (image
->region
== NULL
) {
360 image
->internal_format
= orig_image
->internal_format
;
361 image
->format
= orig_image
->format
;
362 image
->data_type
= orig_image
->data_type
;
363 image
->data
= loaderPrivate
;
369 intel_validate_usage(__DRIimage
*image
, unsigned int use
)
371 if (use
& __DRI_IMAGE_USE_CURSOR
) {
372 if (image
->region
->width
!= 64 || image
->region
->height
!= 64)
379 static struct __DRIimageExtensionRec intelImageExtension
= {
381 intel_create_image_from_name
,
382 intel_create_image_from_renderbuffer
,
390 static const __DRIextension
*intelScreenExtensions
[] = {
391 &intelTexBufferExtension
.base
,
392 &intelFlushExtension
.base
,
393 &intelImageExtension
.base
,
394 &dri2ConfigQueryExtension
.base
,
399 intel_get_param(__DRIscreen
*psp
, int param
, int *value
)
402 struct drm_i915_getparam gp
;
404 memset(&gp
, 0, sizeof(gp
));
408 ret
= drmCommandWriteRead(psp
->fd
, DRM_I915_GETPARAM
, &gp
, sizeof(gp
));
411 _mesa_warning(NULL
, "drm_i915_getparam: %d", ret
);
419 intel_get_boolean(__DRIscreen
*psp
, int param
)
422 return intel_get_param(psp
, param
, &value
) && value
;
426 nop_callback(GLuint key
, void *data
, void *userData
)
431 intelDestroyScreen(__DRIscreen
* sPriv
)
433 struct intel_screen
*intelScreen
= sPriv
->driverPrivate
;
435 dri_bufmgr_destroy(intelScreen
->bufmgr
);
436 driDestroyOptionInfo(&intelScreen
->optionCache
);
438 /* Some regions may still have references to them at this point, so
439 * flush the hash table to prevent _mesa_DeleteHashTable() from
440 * complaining about the hash not being empty; */
441 _mesa_HashDeleteAll(intelScreen
->named_regions
, nop_callback
, NULL
);
442 _mesa_DeleteHashTable(intelScreen
->named_regions
);
445 sPriv
->driverPrivate
= NULL
;
450 * This is called when we need to set up GL rendering to a new X window.
453 intelCreateBuffer(__DRIscreen
* driScrnPriv
,
454 __DRIdrawable
* driDrawPriv
,
455 const struct gl_config
* mesaVis
, GLboolean isPixmap
)
457 struct intel_renderbuffer
*rb
;
458 struct intel_screen
*screen
= (struct intel_screen
*) driScrnPriv
->driverPrivate
;
461 return false; /* not implemented */
466 struct gl_framebuffer
*fb
= CALLOC_STRUCT(gl_framebuffer
);
471 _mesa_initialize_window_framebuffer(fb
, mesaVis
);
473 if (mesaVis
->redBits
== 5)
474 rgbFormat
= MESA_FORMAT_RGB565
;
475 else if (mesaVis
->alphaBits
== 0)
476 rgbFormat
= MESA_FORMAT_XRGB8888
;
478 rgbFormat
= MESA_FORMAT_ARGB8888
;
480 /* setup the hardware-based renderbuffers */
481 rb
= intel_create_renderbuffer(rgbFormat
);
482 _mesa_add_renderbuffer(fb
, BUFFER_FRONT_LEFT
, &rb
->Base
.Base
);
484 if (mesaVis
->doubleBufferMode
) {
485 rb
= intel_create_renderbuffer(rgbFormat
);
486 _mesa_add_renderbuffer(fb
, BUFFER_BACK_LEFT
, &rb
->Base
.Base
);
490 * Assert here that the gl_config has an expected depth/stencil bit
491 * combination: one of d24/s8, d16/s0, d0/s0. (See intelInitScreen2(),
492 * which constructs the advertised configs.)
494 if (mesaVis
->depthBits
== 24) {
495 assert(mesaVis
->stencilBits
== 8);
497 if (screen
->hw_has_separate_stencil
498 && screen
->dri2_has_hiz
!= INTEL_DRI2_HAS_HIZ_FALSE
) {
500 * Request a separate stencil buffer even if we do not yet know if
501 * the screen supports it. (See comments for
502 * enum intel_dri2_has_hiz).
504 rb
= intel_create_renderbuffer(MESA_FORMAT_X8_Z24
);
505 _mesa_add_renderbuffer(fb
, BUFFER_DEPTH
, &rb
->Base
.Base
);
506 rb
= intel_create_renderbuffer(MESA_FORMAT_S8
);
507 _mesa_add_renderbuffer(fb
, BUFFER_STENCIL
, &rb
->Base
.Base
);
510 * Use combined depth/stencil. Note that the renderbuffer is
511 * attached to two attachment points.
513 rb
= intel_create_renderbuffer(MESA_FORMAT_S8_Z24
);
514 _mesa_add_renderbuffer(fb
, BUFFER_DEPTH
, &rb
->Base
.Base
);
515 _mesa_add_renderbuffer(fb
, BUFFER_STENCIL
, &rb
->Base
.Base
);
518 else if (mesaVis
->depthBits
== 16) {
519 assert(mesaVis
->stencilBits
== 0);
520 /* just 16-bit depth buffer, no hw stencil */
521 struct intel_renderbuffer
*depthRb
522 = intel_create_renderbuffer(MESA_FORMAT_Z16
);
523 _mesa_add_renderbuffer(fb
, BUFFER_DEPTH
, &depthRb
->Base
.Base
);
526 assert(mesaVis
->depthBits
== 0);
527 assert(mesaVis
->stencilBits
== 0);
530 /* now add any/all software-based renderbuffers we may need */
531 _swrast_add_soft_renderbuffers(fb
,
532 false, /* never sw color */
533 false, /* never sw depth */
534 false, /* never sw stencil */
535 mesaVis
->accumRedBits
> 0,
536 false, /* never sw alpha */
537 false /* never sw aux */ );
538 driDrawPriv
->driverPrivate
= fb
;
545 intelDestroyBuffer(__DRIdrawable
* driDrawPriv
)
547 struct gl_framebuffer
*fb
= driDrawPriv
->driverPrivate
;
549 _mesa_reference_framebuffer(&fb
, NULL
);
552 /* There are probably better ways to do this, such as an
553 * init-designated function to register chipids and createcontext
557 i830CreateContext(const struct gl_config
*mesaVis
,
558 __DRIcontext
*driContextPriv
,
559 void *sharedContextPrivate
);
562 i915CreateContext(int api
,
563 const struct gl_config
*mesaVis
,
564 __DRIcontext
*driContextPriv
,
565 void *sharedContextPrivate
);
567 brwCreateContext(int api
,
568 const struct gl_config
*mesaVis
,
569 __DRIcontext
*driContextPriv
,
570 void *sharedContextPrivate
);
573 intelCreateContext(gl_api api
,
574 const struct gl_config
* mesaVis
,
575 __DRIcontext
* driContextPriv
,
576 unsigned major_version
,
577 unsigned minor_version
,
580 void *sharedContextPrivate
)
582 __DRIscreen
*sPriv
= driContextPriv
->driScreenPriv
;
583 struct intel_screen
*intelScreen
= sPriv
->driverPrivate
;
584 bool success
= false;
587 if (IS_9XX(intelScreen
->deviceID
)) {
588 if (!IS_965(intelScreen
->deviceID
)) {
589 success
= i915CreateContext(api
, mesaVis
, driContextPriv
,
590 sharedContextPrivate
);
593 intelScreen
->no_vbo
= true;
594 success
= i830CreateContext(mesaVis
, driContextPriv
,
595 sharedContextPrivate
);
598 if (IS_965(intelScreen
->deviceID
))
599 success
= brwCreateContext(api
, mesaVis
,
601 sharedContextPrivate
);
605 struct gl_context
*ctx
=
606 (struct gl_context
*) driContextPriv
->driverPrivate
;
608 _mesa_compute_version(ctx
);
609 if (ctx
->VersionMajor
> major_version
610 || (ctx
->VersionMajor
== major_version
611 && ctx
->VersionMinor
>= minor_version
)) {
612 *error
= __DRI_CTX_ERROR_BAD_VERSION
;
616 intelDestroyContext(driContextPriv
);
618 *error
= __DRI_CTX_ERROR_NO_MEMORY
;
619 fprintf(stderr
, "Unrecognized deviceID 0x%x\n", intelScreen
->deviceID
);
626 intel_init_bufmgr(struct intel_screen
*intelScreen
)
628 __DRIscreen
*spriv
= intelScreen
->driScrnPriv
;
631 intelScreen
->no_hw
= getenv("INTEL_NO_HW") != NULL
;
633 intelScreen
->bufmgr
= intel_bufmgr_gem_init(spriv
->fd
, BATCH_SZ
);
634 if (intelScreen
->bufmgr
== NULL
) {
635 fprintf(stderr
, "[%s:%u] Error initializing buffer manager.\n",
640 if (!intel_get_param(spriv
, I915_PARAM_NUM_FENCES_AVAIL
, &num_fences
) ||
642 fprintf(stderr
, "[%s: %u] Kernel 2.6.29 required.\n", __func__
, __LINE__
);
646 drm_intel_bufmgr_gem_enable_fenced_relocs(intelScreen
->bufmgr
);
648 intelScreen
->named_regions
= _mesa_NewHashTable();
650 intelScreen
->relaxed_relocations
= 0;
651 intelScreen
->relaxed_relocations
|=
652 intel_get_boolean(spriv
, I915_PARAM_HAS_RELAXED_DELTA
) << 0;
658 * Override intel_screen.hw_has_separate_stencil with environment variable
659 * INTEL_SEPARATE_STENCIL.
661 * Valid values for INTEL_SEPARATE_STENCIL are "0" and "1". If an invalid
662 * valid value is encountered, a warning is emitted and INTEL_SEPARATE_STENCIL
666 intel_override_separate_stencil(struct intel_screen
*screen
)
668 const char *s
= getenv("INTEL_SEPARATE_STENCIL");
671 } else if (!strncmp("0", s
, 2)) {
672 screen
->hw_has_separate_stencil
= false;
673 } else if (!strncmp("1", s
, 2)) {
674 screen
->hw_has_separate_stencil
= true;
677 "warning: env variable INTEL_SEPARATE_STENCIL=\"%s\" has "
678 "invalid value and is ignored", s
);
683 intel_detect_swizzling(struct intel_screen
*screen
)
685 drm_intel_bo
*buffer
;
686 unsigned long flags
= 0;
687 unsigned long aligned_pitch
;
688 uint32_t tiling
= I915_TILING_X
;
689 uint32_t swizzle_mode
= 0;
691 buffer
= drm_intel_bo_alloc_tiled(screen
->bufmgr
, "swizzle test",
693 &tiling
, &aligned_pitch
, flags
);
697 drm_intel_bo_get_tiling(buffer
, &tiling
, &swizzle_mode
);
698 drm_intel_bo_unreference(buffer
);
700 if (swizzle_mode
== I915_BIT_6_SWIZZLE_NONE
)
707 * This is the driver specific part of the createNewScreen entry point.
708 * Called when using DRI2.
710 * \return the struct gl_config supported by this driver
713 __DRIconfig
**intelInitScreen2(__DRIscreen
*psp
)
715 struct intel_screen
*intelScreen
;
718 unsigned int api_mask
;
720 static const GLenum back_buffer_modes
[] = {
721 GLX_NONE
, GLX_SWAP_UNDEFINED_OML
, GLX_SWAP_COPY_OML
723 uint8_t depth_bits
[4], stencil_bits
[4], msaa_samples_array
[1];
725 __DRIconfig
**configs
= NULL
;
727 /* Allocate the private area */
728 intelScreen
= CALLOC(sizeof *intelScreen
);
730 fprintf(stderr
, "\nERROR! Allocating private area failed\n");
733 /* parse information in __driConfigOptions */
734 driParseOptionInfo(&intelScreen
->optionCache
,
735 __driConfigOptions
, __driNConfigOptions
);
737 intelScreen
->driScrnPriv
= psp
;
738 psp
->driverPrivate
= (void *) intelScreen
;
740 if (!intel_init_bufmgr(intelScreen
))
743 intelScreen
->deviceID
= drm_intel_bufmgr_gem_get_devid(intelScreen
->bufmgr
);
745 intelScreen
->kernel_has_gen7_sol_reset
=
746 intel_get_boolean(intelScreen
->driScrnPriv
,
747 I915_PARAM_HAS_GEN7_SOL_RESET
);
749 if (IS_GEN7(intelScreen
->deviceID
)) {
750 intelScreen
->gen
= 7;
751 } else if (IS_GEN6(intelScreen
->deviceID
)) {
752 intelScreen
->gen
= 6;
753 } else if (IS_GEN5(intelScreen
->deviceID
)) {
754 intelScreen
->gen
= 5;
755 } else if (IS_965(intelScreen
->deviceID
)) {
756 intelScreen
->gen
= 4;
757 } else if (IS_9XX(intelScreen
->deviceID
)) {
758 intelScreen
->gen
= 3;
760 intelScreen
->gen
= 2;
763 intelScreen
->hw_has_separate_stencil
= intelScreen
->gen
>= 6;
764 intelScreen
->hw_must_use_separate_stencil
= intelScreen
->gen
>= 7;
765 intelScreen
->dri2_has_hiz
= INTEL_DRI2_HAS_HIZ_UNKNOWN
;
767 #if defined(I915_PARAM_HAS_LLC)
768 intelScreen
->hw_has_llc
=
769 intel_get_boolean(intelScreen
->driScrnPriv
,
772 intelScreen
->hw_has_llc
= intelScreen
->gen
>= 6;
775 intel_override_separate_stencil(intelScreen
);
777 api_mask
= (1 << __DRI_API_OPENGL
);
779 api_mask
|= (1 << __DRI_API_GLES
);
782 api_mask
|= (1 << __DRI_API_GLES2
);
785 if (IS_9XX(intelScreen
->deviceID
) || IS_965(intelScreen
->deviceID
))
786 psp
->api_mask
= api_mask
;
788 intelScreen
->hw_has_swizzling
= intel_detect_swizzling(intelScreen
);
790 psp
->extensions
= intelScreenExtensions
;
792 msaa_samples_array
[0] = 0;
794 fb_format
[0] = GL_RGB
;
795 fb_type
[0] = GL_UNSIGNED_SHORT_5_6_5
;
797 fb_format
[1] = GL_BGR
;
798 fb_type
[1] = GL_UNSIGNED_INT_8_8_8_8_REV
;
800 fb_format
[2] = GL_BGRA
;
801 fb_type
[2] = GL_UNSIGNED_INT_8_8_8_8_REV
;
806 /* Generate a rich set of useful configs that do not include an
807 * accumulation buffer.
809 for (color
= 0; color
< ARRAY_SIZE(fb_format
); color
++) {
810 __DRIconfig
**new_configs
;
813 /* Starting with DRI2 protocol version 1.1 we can request a depth/stencil
814 * buffer that has a diffferent number of bits per pixel than the color
815 * buffer. This isn't yet supported here.
817 if (fb_type
[color
] == GL_UNSIGNED_SHORT_5_6_5
) {
827 new_configs
= driCreateConfigs(fb_format
[color
], fb_type
[color
],
832 ARRAY_SIZE(back_buffer_modes
),
834 ARRAY_SIZE(msaa_samples_array
),
837 configs
= new_configs
;
839 configs
= driConcatConfigs(configs
, new_configs
);
842 /* Generate the minimum possible set of configs that include an
843 * accumulation buffer.
845 for (color
= 0; color
< ARRAY_SIZE(fb_format
); color
++) {
846 __DRIconfig
**new_configs
;
848 if (fb_type
[color
] == GL_UNSIGNED_SHORT_5_6_5
) {
856 new_configs
= driCreateConfigs(fb_format
[color
], fb_type
[color
],
857 depth_bits
, stencil_bits
, 1,
858 back_buffer_modes
+ 1, 1,
859 msaa_samples_array
, 1,
862 configs
= new_configs
;
864 configs
= driConcatConfigs(configs
, new_configs
);
867 if (configs
== NULL
) {
868 fprintf(stderr
, "[%s:%u] Error creating FBConfig!\n", __func__
,
873 return (const __DRIconfig
**)configs
;
876 struct intel_buffer
{
878 struct intel_region
*region
;
882 * \brief Get tiling format for a DRI buffer.
884 * \param attachment is the buffer's attachmet point, such as
885 * __DRI_BUFFER_DEPTH.
886 * \param out_tiling is the returned tiling format for buffer.
887 * \return false if attachment is unrecognized or is incompatible with screen.
890 intel_get_dri_buffer_tiling(struct intel_screen
*screen
,
892 uint32_t *out_tiling
)
894 if (screen
->gen
< 4) {
895 *out_tiling
= I915_TILING_X
;
899 switch (attachment
) {
900 case __DRI_BUFFER_DEPTH
:
901 case __DRI_BUFFER_DEPTH_STENCIL
:
902 case __DRI_BUFFER_HIZ
:
903 *out_tiling
= I915_TILING_Y
;
905 case __DRI_BUFFER_ACCUM
:
906 case __DRI_BUFFER_FRONT_LEFT
:
907 case __DRI_BUFFER_FRONT_RIGHT
:
908 case __DRI_BUFFER_BACK_LEFT
:
909 case __DRI_BUFFER_BACK_RIGHT
:
910 case __DRI_BUFFER_FAKE_FRONT_LEFT
:
911 case __DRI_BUFFER_FAKE_FRONT_RIGHT
:
912 *out_tiling
= I915_TILING_X
;
914 case __DRI_BUFFER_STENCIL
:
915 /* The stencil buffer is W tiled. However, we request from the kernel
916 * a non-tiled buffer because the GTT is incapable of W fencing.
918 *out_tiling
= I915_TILING_NONE
;
921 if(unlikely(INTEL_DEBUG
& DEBUG_DRI
)) {
922 fprintf(stderr
, "error: %s: unrecognized DRI buffer attachment 0x%x\n",
923 __FUNCTION__
, attachment
);
930 intelAllocateBuffer(__DRIscreen
*screen
,
931 unsigned attachment
, unsigned format
,
932 int width
, int height
)
934 struct intel_buffer
*intelBuffer
;
935 struct intel_screen
*intelScreen
= screen
->driverPrivate
;
938 uint32_t region_width
;
939 uint32_t region_height
;
944 ok
= intel_get_dri_buffer_tiling(intelScreen
, attachment
, &tiling
);
948 intelBuffer
= CALLOC(sizeof *intelBuffer
);
949 if (intelBuffer
== NULL
)
952 if (attachment
== __DRI_BUFFER_STENCIL
) {
953 /* The stencil buffer has quirky pitch requirements. From Vol 2a,
954 * 11.5.6.2.1 3DSTATE_STENCIL_BUFFER, field "Surface Pitch":
955 * The pitch must be set to 2x the value computed based on width, as
956 * the stencil buffer is stored with two rows interleaved.
957 * To accomplish this, we resort to the nasty hack of doubling the
958 * region's cpp and halving its height.
960 region_width
= ALIGN(width
, 64);
961 region_height
= ALIGN(ALIGN(height
, 2) / 2, 64);
962 region_cpp
= format
/ 4;
964 region_width
= width
;
965 region_height
= height
;
966 region_cpp
= format
/ 8;
969 intelBuffer
->region
= intel_region_alloc(intelScreen
,
976 if (intelBuffer
->region
== NULL
) {
981 intel_region_flink(intelBuffer
->region
, &intelBuffer
->base
.name
);
983 intelBuffer
->base
.attachment
= attachment
;
984 intelBuffer
->base
.cpp
= intelBuffer
->region
->cpp
;
985 intelBuffer
->base
.pitch
=
986 intelBuffer
->region
->pitch
* intelBuffer
->region
->cpp
;
988 return &intelBuffer
->base
;
992 intelReleaseBuffer(__DRIscreen
*screen
, __DRIbuffer
*buffer
)
994 struct intel_buffer
*intelBuffer
= (struct intel_buffer
*) buffer
;
996 intel_region_release(&intelBuffer
->region
);
1001 const struct __DriverAPIRec driDriverAPI
= {
1002 .InitScreen
= intelInitScreen2
,
1003 .DestroyScreen
= intelDestroyScreen
,
1004 .CreateContext
= intelCreateContext
,
1005 .DestroyContext
= intelDestroyContext
,
1006 .CreateBuffer
= intelCreateBuffer
,
1007 .DestroyBuffer
= intelDestroyBuffer
,
1008 .MakeCurrent
= intelMakeCurrent
,
1009 .UnbindContext
= intelUnbindContext
,
1010 .AllocateBuffer
= intelAllocateBuffer
,
1011 .ReleaseBuffer
= intelReleaseBuffer
1014 /* This is the table of extensions that the loader will dlsym() for. */
1015 PUBLIC
const __DRIextension
*__driDriverExtensions
[] = {
1016 &driCoreExtension
.base
,
1017 &driDRI2Extension
.base
,