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)
82 DRI_CONF_DISABLE_BLEND_FUNC_EXTENDED(false)
84 DRI_CONF_OPT_BEGIN(stub_occlusion_query
, bool, false)
85 DRI_CONF_DESC(en
, "Enable stub ARB_occlusion_query support on 915/945.")
88 DRI_CONF_OPT_BEGIN(shader_precompile
, bool, true)
89 DRI_CONF_DESC(en
, "Perform code generation at shader link time.")
94 const GLuint __driNConfigOptions
= 15;
96 #include "intel_batchbuffer.h"
97 #include "intel_buffers.h"
98 #include "intel_bufmgr.h"
99 #include "intel_chipset.h"
100 #include "intel_fbo.h"
101 #include "intel_mipmap_tree.h"
102 #include "intel_screen.h"
103 #include "intel_tex.h"
104 #include "intel_regions.h"
106 #include "i915_drm.h"
108 #ifdef USE_NEW_INTERFACE
109 static PFNGLXCREATECONTEXTMODES create_context_modes
= NULL
;
110 #endif /*USE_NEW_INTERFACE */
113 * For debugging purposes, this returns a time in seconds.
120 clock_gettime(CLOCK_MONOTONIC
, &tp
);
122 return tp
.tv_sec
+ tp
.tv_nsec
/ 1000000000.0;
126 aub_dump_bmp(struct gl_context
*ctx
)
128 struct gl_framebuffer
*fb
= ctx
->DrawBuffer
;
130 for (int i
= 0; i
< fb
->_NumColorDrawBuffers
; i
++) {
131 struct intel_renderbuffer
*irb
=
132 intel_renderbuffer(fb
->_ColorDrawBuffers
[i
]);
134 if (irb
&& irb
->mt
) {
135 enum aub_dump_bmp_format format
;
137 switch (irb
->Base
.Base
.Format
) {
138 case MESA_FORMAT_ARGB8888
:
139 case MESA_FORMAT_XRGB8888
:
140 format
= AUB_DUMP_BMP_FORMAT_ARGB_8888
;
146 drm_intel_gem_bo_aub_dump_bmp(irb
->mt
->region
->bo
,
149 irb
->Base
.Base
.Width
,
150 irb
->Base
.Base
.Height
,
152 irb
->mt
->region
->pitch
*
153 irb
->mt
->region
->cpp
,
159 static const __DRItexBufferExtension intelTexBufferExtension
= {
160 { __DRI_TEX_BUFFER
, __DRI_TEX_BUFFER_VERSION
},
166 intelDRI2Flush(__DRIdrawable
*drawable
)
168 GET_CURRENT_CONTEXT(ctx
);
169 struct intel_context
*intel
= intel_context(ctx
);
174 INTEL_FIREVERTICES(intel
);
176 intel_downsample_for_dri2_flush(intel
, drawable
);
177 intel
->need_throttle
= true;
179 if (intel
->batch
.used
)
180 intel_batchbuffer_flush(intel
);
182 if (INTEL_DEBUG
& DEBUG_AUB
) {
187 static const struct __DRI2flushExtensionRec intelFlushExtension
= {
188 { __DRI2_FLUSH
, __DRI2_FLUSH_VERSION
},
190 dri2InvalidateDrawable
,
194 intel_allocate_image(int dri_format
, void *loaderPrivate
)
198 image
= CALLOC(sizeof *image
);
202 image
->dri_format
= dri_format
;
205 switch (dri_format
) {
206 case __DRI_IMAGE_FORMAT_RGB565
:
207 image
->format
= MESA_FORMAT_RGB565
;
209 case __DRI_IMAGE_FORMAT_XRGB8888
:
210 image
->format
= MESA_FORMAT_XRGB8888
;
212 case __DRI_IMAGE_FORMAT_ARGB8888
:
213 image
->format
= MESA_FORMAT_ARGB8888
;
215 case __DRI_IMAGE_FORMAT_ABGR8888
:
216 image
->format
= MESA_FORMAT_RGBA8888_REV
;
218 case __DRI_IMAGE_FORMAT_XBGR8888
:
219 image
->format
= MESA_FORMAT_RGBX8888_REV
;
221 case __DRI_IMAGE_FORMAT_R8
:
222 image
->format
= MESA_FORMAT_R8
;
224 case __DRI_IMAGE_FORMAT_GR88
:
225 image
->format
= MESA_FORMAT_GR88
;
227 case __DRI_IMAGE_FORMAT_NONE
:
228 image
->format
= MESA_FORMAT_NONE
;
235 image
->internal_format
= _mesa_get_format_base_format(image
->format
);
236 image
->data
= loaderPrivate
;
242 intel_create_image_from_name(__DRIscreen
*screen
,
243 int width
, int height
, int format
,
244 int name
, int pitch
, void *loaderPrivate
)
246 struct intel_screen
*intelScreen
= screen
->driverPrivate
;
250 image
= intel_allocate_image(format
, loaderPrivate
);
251 if (image
->format
== MESA_FORMAT_NONE
)
254 cpp
= _mesa_get_format_bytes(image
->format
);
255 image
->region
= intel_region_alloc_for_handle(intelScreen
,
257 pitch
, name
, "image");
258 if (image
->region
== NULL
) {
267 intel_create_image_from_renderbuffer(__DRIcontext
*context
,
268 int renderbuffer
, void *loaderPrivate
)
271 struct intel_context
*intel
= context
->driverPrivate
;
272 struct gl_renderbuffer
*rb
;
273 struct intel_renderbuffer
*irb
;
275 rb
= _mesa_lookup_renderbuffer(&intel
->ctx
, renderbuffer
);
277 _mesa_error(&intel
->ctx
,
278 GL_INVALID_OPERATION
, "glRenderbufferExternalMESA");
282 irb
= intel_renderbuffer(rb
);
283 image
= CALLOC(sizeof *image
);
287 image
->internal_format
= rb
->InternalFormat
;
288 image
->format
= rb
->Format
;
290 image
->data
= loaderPrivate
;
291 intel_region_reference(&image
->region
, irb
->mt
->region
);
293 switch (image
->format
) {
294 case MESA_FORMAT_RGB565
:
295 image
->dri_format
= __DRI_IMAGE_FORMAT_RGB565
;
297 case MESA_FORMAT_XRGB8888
:
298 image
->dri_format
= __DRI_IMAGE_FORMAT_XRGB8888
;
300 case MESA_FORMAT_ARGB8888
:
301 image
->dri_format
= __DRI_IMAGE_FORMAT_ARGB8888
;
303 case MESA_FORMAT_RGBA8888_REV
:
304 image
->dri_format
= __DRI_IMAGE_FORMAT_ABGR8888
;
307 image
->dri_format
= __DRI_IMAGE_FORMAT_R8
;
309 case MESA_FORMAT_RG88
:
310 image
->dri_format
= __DRI_IMAGE_FORMAT_GR88
;
318 intel_destroy_image(__DRIimage
*image
)
320 intel_region_release(&image
->region
);
325 intel_create_image(__DRIscreen
*screen
,
326 int width
, int height
, int format
,
331 struct intel_screen
*intelScreen
= screen
->driverPrivate
;
335 tiling
= I915_TILING_X
;
336 if (use
& __DRI_IMAGE_USE_CURSOR
) {
337 if (width
!= 64 || height
!= 64)
339 tiling
= I915_TILING_NONE
;
342 image
= intel_allocate_image(format
, loaderPrivate
);
343 cpp
= _mesa_get_format_bytes(image
->format
);
345 intel_region_alloc(intelScreen
, tiling
, cpp
, width
, height
, true);
346 if (image
->region
== NULL
) {
355 intel_query_image(__DRIimage
*image
, int attrib
, int *value
)
358 case __DRI_IMAGE_ATTRIB_STRIDE
:
359 *value
= image
->region
->pitch
* image
->region
->cpp
;
361 case __DRI_IMAGE_ATTRIB_HANDLE
:
362 *value
= image
->region
->bo
->handle
;
364 case __DRI_IMAGE_ATTRIB_NAME
:
365 return intel_region_flink(image
->region
, (uint32_t *) value
);
366 case __DRI_IMAGE_ATTRIB_FORMAT
:
367 *value
= image
->dri_format
;
369 case __DRI_IMAGE_ATTRIB_WIDTH
:
370 *value
= image
->region
->width
;
372 case __DRI_IMAGE_ATTRIB_HEIGHT
:
373 *value
= image
->region
->height
;
381 intel_dup_image(__DRIimage
*orig_image
, void *loaderPrivate
)
385 image
= CALLOC(sizeof *image
);
389 intel_region_reference(&image
->region
, orig_image
->region
);
390 if (image
->region
== NULL
) {
395 image
->internal_format
= orig_image
->internal_format
;
396 image
->dri_format
= orig_image
->dri_format
;
397 image
->format
= orig_image
->format
;
398 image
->offset
= orig_image
->offset
;
399 image
->data
= loaderPrivate
;
405 intel_validate_usage(__DRIimage
*image
, unsigned int use
)
407 if (use
& __DRI_IMAGE_USE_CURSOR
) {
408 if (image
->region
->width
!= 64 || image
->region
->height
!= 64)
416 intel_create_sub_image(__DRIimage
*parent
,
417 int width
, int height
, int dri_format
,
418 int offset
, int pitch
, void *loaderPrivate
)
422 uint32_t mask_x
, mask_y
;
424 image
= intel_allocate_image(dri_format
, loaderPrivate
);
425 cpp
= _mesa_get_format_bytes(image
->format
);
426 if (offset
+ height
* cpp
* pitch
> parent
->region
->bo
->size
) {
427 _mesa_warning(NULL
, "intel_create_sub_image: subimage out of bounds");
432 image
->region
= calloc(sizeof(*image
->region
), 1);
433 if (image
->region
== NULL
) {
438 image
->region
->cpp
= _mesa_get_format_bytes(image
->format
);
439 image
->region
->width
= width
;
440 image
->region
->height
= height
;
441 image
->region
->pitch
= pitch
;
442 image
->region
->refcount
= 1;
443 image
->region
->bo
= parent
->region
->bo
;
444 drm_intel_bo_reference(image
->region
->bo
);
445 image
->region
->tiling
= parent
->region
->tiling
;
446 image
->region
->screen
= parent
->region
->screen
;
447 image
->offset
= offset
;
449 intel_region_get_tile_masks(image
->region
, &mask_x
, &mask_y
);
452 "intel_create_sub_image: offset not on tile boundary");
457 static struct __DRIimageExtensionRec intelImageExtension
= {
459 intel_create_image_from_name
,
460 intel_create_image_from_renderbuffer
,
465 intel_validate_usage
,
466 intel_create_sub_image
469 static const __DRIextension
*intelScreenExtensions
[] = {
470 &intelTexBufferExtension
.base
,
471 &intelFlushExtension
.base
,
472 &intelImageExtension
.base
,
473 &dri2ConfigQueryExtension
.base
,
478 intel_get_param(__DRIscreen
*psp
, int param
, int *value
)
481 struct drm_i915_getparam gp
;
483 memset(&gp
, 0, sizeof(gp
));
487 ret
= drmCommandWriteRead(psp
->fd
, DRM_I915_GETPARAM
, &gp
, sizeof(gp
));
490 _mesa_warning(NULL
, "drm_i915_getparam: %d", ret
);
498 intel_get_boolean(__DRIscreen
*psp
, int param
)
501 return intel_get_param(psp
, param
, &value
) && value
;
505 nop_callback(GLuint key
, void *data
, void *userData
)
510 intelDestroyScreen(__DRIscreen
* sPriv
)
512 struct intel_screen
*intelScreen
= sPriv
->driverPrivate
;
514 dri_bufmgr_destroy(intelScreen
->bufmgr
);
515 driDestroyOptionInfo(&intelScreen
->optionCache
);
517 /* Some regions may still have references to them at this point, so
518 * flush the hash table to prevent _mesa_DeleteHashTable() from
519 * complaining about the hash not being empty; */
520 _mesa_HashDeleteAll(intelScreen
->named_regions
, nop_callback
, NULL
);
521 _mesa_DeleteHashTable(intelScreen
->named_regions
);
524 sPriv
->driverPrivate
= NULL
;
529 * This is called when we need to set up GL rendering to a new X window.
532 intelCreateBuffer(__DRIscreen
* driScrnPriv
,
533 __DRIdrawable
* driDrawPriv
,
534 const struct gl_config
* mesaVis
, GLboolean isPixmap
)
536 struct intel_renderbuffer
*rb
;
537 struct intel_screen
*screen
= (struct intel_screen
*) driScrnPriv
->driverPrivate
;
539 unsigned num_samples
= intel_quantize_num_samples(screen
, mesaVis
->samples
);
540 struct gl_framebuffer
*fb
;
545 fb
= CALLOC_STRUCT(gl_framebuffer
);
549 _mesa_initialize_window_framebuffer(fb
, mesaVis
);
551 if (mesaVis
->redBits
== 5)
552 rgbFormat
= MESA_FORMAT_RGB565
;
553 else if (mesaVis
->alphaBits
== 0)
554 rgbFormat
= MESA_FORMAT_XRGB8888
;
556 rgbFormat
= MESA_FORMAT_ARGB8888
;
558 /* setup the hardware-based renderbuffers */
559 rb
= intel_create_renderbuffer(rgbFormat
, num_samples
);
560 _mesa_add_renderbuffer(fb
, BUFFER_FRONT_LEFT
, &rb
->Base
.Base
);
562 if (mesaVis
->doubleBufferMode
) {
563 rb
= intel_create_renderbuffer(rgbFormat
, num_samples
);
564 _mesa_add_renderbuffer(fb
, BUFFER_BACK_LEFT
, &rb
->Base
.Base
);
568 * Assert here that the gl_config has an expected depth/stencil bit
569 * combination: one of d24/s8, d16/s0, d0/s0. (See intelInitScreen2(),
570 * which constructs the advertised configs.)
572 if (mesaVis
->depthBits
== 24) {
573 assert(mesaVis
->stencilBits
== 8);
575 if (screen
->hw_has_separate_stencil
) {
576 rb
= intel_create_private_renderbuffer(MESA_FORMAT_X8_Z24
,
578 _mesa_add_renderbuffer(fb
, BUFFER_DEPTH
, &rb
->Base
.Base
);
579 rb
= intel_create_private_renderbuffer(MESA_FORMAT_S8
,
581 _mesa_add_renderbuffer(fb
, BUFFER_STENCIL
, &rb
->Base
.Base
);
584 * Use combined depth/stencil. Note that the renderbuffer is
585 * attached to two attachment points.
587 rb
= intel_create_private_renderbuffer(MESA_FORMAT_S8_Z24
,
589 _mesa_add_renderbuffer(fb
, BUFFER_DEPTH
, &rb
->Base
.Base
);
590 _mesa_add_renderbuffer(fb
, BUFFER_STENCIL
, &rb
->Base
.Base
);
593 else if (mesaVis
->depthBits
== 16) {
594 assert(mesaVis
->stencilBits
== 0);
595 rb
= intel_create_private_renderbuffer(MESA_FORMAT_Z16
,
597 _mesa_add_renderbuffer(fb
, BUFFER_DEPTH
, &rb
->Base
.Base
);
600 assert(mesaVis
->depthBits
== 0);
601 assert(mesaVis
->stencilBits
== 0);
604 /* now add any/all software-based renderbuffers we may need */
605 _swrast_add_soft_renderbuffers(fb
,
606 false, /* never sw color */
607 false, /* never sw depth */
608 false, /* never sw stencil */
609 mesaVis
->accumRedBits
> 0,
610 false, /* never sw alpha */
611 false /* never sw aux */ );
612 driDrawPriv
->driverPrivate
= fb
;
618 intelDestroyBuffer(__DRIdrawable
* driDrawPriv
)
620 struct gl_framebuffer
*fb
= driDrawPriv
->driverPrivate
;
622 _mesa_reference_framebuffer(&fb
, NULL
);
625 /* There are probably better ways to do this, such as an
626 * init-designated function to register chipids and createcontext
630 i830CreateContext(const struct gl_config
*mesaVis
,
631 __DRIcontext
*driContextPriv
,
632 void *sharedContextPrivate
);
635 i915CreateContext(int api
,
636 const struct gl_config
*mesaVis
,
637 __DRIcontext
*driContextPriv
,
638 unsigned major_version
,
639 unsigned minor_version
,
641 void *sharedContextPrivate
);
643 brwCreateContext(int api
,
644 const struct gl_config
*mesaVis
,
645 __DRIcontext
*driContextPriv
,
646 unsigned major_version
,
647 unsigned minor_version
,
650 void *sharedContextPrivate
);
653 intelCreateContext(gl_api api
,
654 const struct gl_config
* mesaVis
,
655 __DRIcontext
* driContextPriv
,
656 unsigned major_version
,
657 unsigned minor_version
,
660 void *sharedContextPrivate
)
662 __DRIscreen
*sPriv
= driContextPriv
->driScreenPriv
;
663 struct intel_screen
*intelScreen
= sPriv
->driverPrivate
;
664 bool success
= false;
667 if (IS_9XX(intelScreen
->deviceID
)) {
668 success
= i915CreateContext(api
, mesaVis
, driContextPriv
,
669 major_version
, minor_version
, error
,
670 sharedContextPrivate
);
674 if (major_version
> 1 || minor_version
> 3) {
675 *error
= __DRI_CTX_ERROR_BAD_VERSION
;
682 *error
= __DRI_CTX_ERROR_BAD_API
;
687 intelScreen
->no_vbo
= true;
688 success
= i830CreateContext(mesaVis
, driContextPriv
,
689 sharedContextPrivate
);
691 *error
= __DRI_CTX_ERROR_NO_MEMORY
;
695 success
= brwCreateContext(api
, mesaVis
,
697 major_version
, minor_version
, flags
,
698 error
, sharedContextPrivate
);
704 intelDestroyContext(driContextPriv
);
709 intel_init_bufmgr(struct intel_screen
*intelScreen
)
711 __DRIscreen
*spriv
= intelScreen
->driScrnPriv
;
714 intelScreen
->no_hw
= getenv("INTEL_NO_HW") != NULL
;
716 intelScreen
->bufmgr
= intel_bufmgr_gem_init(spriv
->fd
, BATCH_SZ
);
717 if (intelScreen
->bufmgr
== NULL
) {
718 fprintf(stderr
, "[%s:%u] Error initializing buffer manager.\n",
723 if (!intel_get_param(spriv
, I915_PARAM_NUM_FENCES_AVAIL
, &num_fences
) ||
725 fprintf(stderr
, "[%s: %u] Kernel 2.6.29 required.\n", __func__
, __LINE__
);
729 drm_intel_bufmgr_gem_enable_fenced_relocs(intelScreen
->bufmgr
);
731 intelScreen
->named_regions
= _mesa_NewHashTable();
733 intelScreen
->relaxed_relocations
= 0;
734 intelScreen
->relaxed_relocations
|=
735 intel_get_boolean(spriv
, I915_PARAM_HAS_RELAXED_DELTA
) << 0;
741 * Override intel_screen.hw_has_separate_stencil with environment variable
742 * INTEL_SEPARATE_STENCIL.
744 * Valid values for INTEL_SEPARATE_STENCIL are "0" and "1". If an invalid
745 * valid value is encountered, a warning is emitted and INTEL_SEPARATE_STENCIL
749 intel_override_separate_stencil(struct intel_screen
*screen
)
751 const char *s
= getenv("INTEL_SEPARATE_STENCIL");
754 } else if (!strncmp("0", s
, 2)) {
755 screen
->hw_has_separate_stencil
= false;
756 } else if (!strncmp("1", s
, 2)) {
757 screen
->hw_has_separate_stencil
= true;
760 "warning: env variable INTEL_SEPARATE_STENCIL=\"%s\" has "
761 "invalid value and is ignored", s
);
766 intel_detect_swizzling(struct intel_screen
*screen
)
768 drm_intel_bo
*buffer
;
769 unsigned long flags
= 0;
770 unsigned long aligned_pitch
;
771 uint32_t tiling
= I915_TILING_X
;
772 uint32_t swizzle_mode
= 0;
774 buffer
= drm_intel_bo_alloc_tiled(screen
->bufmgr
, "swizzle test",
776 &tiling
, &aligned_pitch
, flags
);
780 drm_intel_bo_get_tiling(buffer
, &tiling
, &swizzle_mode
);
781 drm_intel_bo_unreference(buffer
);
783 if (swizzle_mode
== I915_BIT_6_SWIZZLE_NONE
)
790 intel_screen_make_configs(__DRIscreen
*dri_screen
)
792 static const GLenum back_buffer_modes
[] = {
793 GLX_NONE
, GLX_SWAP_UNDEFINED_OML
, GLX_SWAP_COPY_OML
796 static const uint8_t singlesample_samples
[1] = {0};
797 static const uint8_t multisample_samples
[2] = {4, 8};
799 struct intel_screen
*screen
= dri_screen
->driverPrivate
;
802 uint8_t depth_bits
[4], stencil_bits
[4];
803 __DRIconfig
**configs
= NULL
;
805 fb_format
[0] = GL_RGB
;
806 fb_type
[0] = GL_UNSIGNED_SHORT_5_6_5
;
808 fb_format
[1] = GL_BGR
;
809 fb_type
[1] = GL_UNSIGNED_INT_8_8_8_8_REV
;
811 fb_format
[2] = GL_BGRA
;
812 fb_type
[2] = GL_UNSIGNED_INT_8_8_8_8_REV
;
814 /* Generate singlesample configs without accumulation buffer. */
815 for (int i
= 0; i
< ARRAY_SIZE(fb_format
); i
++) {
816 __DRIconfig
**new_configs
;
817 const int num_depth_stencil_bits
= 2;
819 /* Starting with DRI2 protocol version 1.1 we can request a depth/stencil
820 * buffer that has a different number of bits per pixel than the color
821 * buffer. This isn't yet supported here.
826 if (fb_type
[i
] == GL_UNSIGNED_SHORT_5_6_5
) {
834 new_configs
= driCreateConfigs(fb_format
[i
], fb_type
[i
],
837 num_depth_stencil_bits
,
839 ARRAY_SIZE(back_buffer_modes
),
840 singlesample_samples
, 1,
842 configs
= driConcatConfigs(configs
, new_configs
);
845 /* Generate the minimum possible set of configs that include an
846 * accumulation buffer.
848 for (int i
= 0; i
< ARRAY_SIZE(fb_format
); i
++) {
849 __DRIconfig
**new_configs
;
851 if (fb_type
[i
] == GL_UNSIGNED_SHORT_5_6_5
) {
859 new_configs
= driCreateConfigs(fb_format
[i
], fb_type
[i
],
860 depth_bits
, stencil_bits
, 1,
861 back_buffer_modes
+ 1, 1,
862 singlesample_samples
, 1,
864 configs
= driConcatConfigs(configs
, new_configs
);
867 /* Generate multisample configs.
869 * This loop breaks early, and hence is a no-op, on gen < 6.
871 * Multisample configs must follow the singlesample configs in order to
872 * work around an X server bug present in 1.12. The X server chooses to
873 * associate the first listed RGBA888-Z24S8 config, regardless of its
874 * sample count, with the 32-bit depth visual used for compositing.
876 * Only doublebuffer configs with GLX_SWAP_UNDEFINED_OML behavior are
877 * supported. Singlebuffer configs are not supported because no one wants
878 * them. GLX_SWAP_COPY_OML is not supported due to page flipping.
880 for (int i
= 0; i
< ARRAY_SIZE(fb_format
); i
++) {
884 __DRIconfig
**new_configs
;
885 const int num_depth_stencil_bits
= 2;
886 int num_msaa_modes
= 0;
891 if (fb_type
[i
] == GL_UNSIGNED_SHORT_5_6_5
) {
899 if (screen
->gen
>= 7)
901 else if (screen
->gen
== 6)
904 new_configs
= driCreateConfigs(fb_format
[i
], fb_type
[i
],
907 num_depth_stencil_bits
,
908 back_buffer_modes
+ 1, 1,
912 configs
= driConcatConfigs(configs
, new_configs
);
915 if (configs
== NULL
) {
916 fprintf(stderr
, "[%s:%u] Error creating FBConfig!\n", __func__
,
925 * This is the driver specific part of the createNewScreen entry point.
926 * Called when using DRI2.
928 * \return the struct gl_config supported by this driver
931 __DRIconfig
**intelInitScreen2(__DRIscreen
*psp
)
933 struct intel_screen
*intelScreen
;
934 unsigned int api_mask
;
936 if (psp
->dri2
.loader
->base
.version
<= 2 ||
937 psp
->dri2
.loader
->getBuffersWithFormat
== NULL
) {
939 "\nERROR! DRI2 loader with getBuffersWithFormat() "
940 "support required\n");
944 /* Allocate the private area */
945 intelScreen
= CALLOC(sizeof *intelScreen
);
947 fprintf(stderr
, "\nERROR! Allocating private area failed\n");
950 /* parse information in __driConfigOptions */
951 driParseOptionInfo(&intelScreen
->optionCache
,
952 __driConfigOptions
, __driNConfigOptions
);
954 intelScreen
->driScrnPriv
= psp
;
955 psp
->driverPrivate
= (void *) intelScreen
;
957 if (!intel_init_bufmgr(intelScreen
))
960 intelScreen
->deviceID
= drm_intel_bufmgr_gem_get_devid(intelScreen
->bufmgr
);
962 intelScreen
->kernel_has_gen7_sol_reset
=
963 intel_get_boolean(intelScreen
->driScrnPriv
,
964 I915_PARAM_HAS_GEN7_SOL_RESET
);
966 if (IS_GEN7(intelScreen
->deviceID
)) {
967 intelScreen
->gen
= 7;
968 } else if (IS_GEN6(intelScreen
->deviceID
)) {
969 intelScreen
->gen
= 6;
970 } else if (IS_GEN5(intelScreen
->deviceID
)) {
971 intelScreen
->gen
= 5;
972 } else if (IS_965(intelScreen
->deviceID
)) {
973 intelScreen
->gen
= 4;
974 } else if (IS_9XX(intelScreen
->deviceID
)) {
975 intelScreen
->gen
= 3;
977 intelScreen
->gen
= 2;
980 intelScreen
->hw_has_separate_stencil
= intelScreen
->gen
>= 6;
981 intelScreen
->hw_must_use_separate_stencil
= intelScreen
->gen
>= 7;
984 bool success
= intel_get_param(intelScreen
->driScrnPriv
, I915_PARAM_HAS_LLC
,
986 if (success
&& has_llc
)
987 intelScreen
->hw_has_llc
= true;
988 else if (!success
&& intelScreen
->gen
>= 6)
989 intelScreen
->hw_has_llc
= true;
991 intel_override_separate_stencil(intelScreen
);
993 api_mask
= (1 << __DRI_API_OPENGL
);
995 api_mask
|= (1 << __DRI_API_GLES
);
998 api_mask
|= (1 << __DRI_API_GLES2
);
1001 if (IS_9XX(intelScreen
->deviceID
) || IS_965(intelScreen
->deviceID
))
1002 psp
->api_mask
= api_mask
;
1004 intelScreen
->hw_has_swizzling
= intel_detect_swizzling(intelScreen
);
1006 psp
->extensions
= intelScreenExtensions
;
1008 return (const __DRIconfig
**) intel_screen_make_configs(psp
);
1011 struct intel_buffer
{
1013 struct intel_region
*region
;
1016 static __DRIbuffer
*
1017 intelAllocateBuffer(__DRIscreen
*screen
,
1018 unsigned attachment
, unsigned format
,
1019 int width
, int height
)
1021 struct intel_buffer
*intelBuffer
;
1022 struct intel_screen
*intelScreen
= screen
->driverPrivate
;
1024 assert(attachment
== __DRI_BUFFER_FRONT_LEFT
||
1025 attachment
== __DRI_BUFFER_BACK_LEFT
);
1027 intelBuffer
= CALLOC(sizeof *intelBuffer
);
1028 if (intelBuffer
== NULL
)
1031 /* The front and back buffers are color buffers, which are X tiled. */
1032 intelBuffer
->region
= intel_region_alloc(intelScreen
,
1039 if (intelBuffer
->region
== NULL
) {
1044 intel_region_flink(intelBuffer
->region
, &intelBuffer
->base
.name
);
1046 intelBuffer
->base
.attachment
= attachment
;
1047 intelBuffer
->base
.cpp
= intelBuffer
->region
->cpp
;
1048 intelBuffer
->base
.pitch
=
1049 intelBuffer
->region
->pitch
* intelBuffer
->region
->cpp
;
1051 return &intelBuffer
->base
;
1055 intelReleaseBuffer(__DRIscreen
*screen
, __DRIbuffer
*buffer
)
1057 struct intel_buffer
*intelBuffer
= (struct intel_buffer
*) buffer
;
1059 intel_region_release(&intelBuffer
->region
);
1064 const struct __DriverAPIRec driDriverAPI
= {
1065 .InitScreen
= intelInitScreen2
,
1066 .DestroyScreen
= intelDestroyScreen
,
1067 .CreateContext
= intelCreateContext
,
1068 .DestroyContext
= intelDestroyContext
,
1069 .CreateBuffer
= intelCreateBuffer
,
1070 .DestroyBuffer
= intelDestroyBuffer
,
1071 .MakeCurrent
= intelMakeCurrent
,
1072 .UnbindContext
= intelUnbindContext
,
1073 .AllocateBuffer
= intelAllocateBuffer
,
1074 .ReleaseBuffer
= intelReleaseBuffer
1077 /* This is the table of extensions that the loader will dlsym() for. */
1078 PUBLIC
const __DRIextension
*__driDriverExtensions
[] = {
1079 &driCoreExtension
.base
,
1080 &driDRI2Extension
.base
,