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, false)
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 intel_downsample_for_dri2_flush(struct intel_context
*intel
,
167 __DRIdrawable
*drawable
)
169 if (intel
->gen
< 6) {
170 /* MSAA is not supported, so don't waste time checking for
171 * a multisample buffer.
176 struct gl_framebuffer
*fb
= drawable
->driverPrivate
;
177 struct intel_renderbuffer
*rb
;
179 /* Usually, only the back buffer will need to be downsampled. However,
180 * the front buffer will also need it if the user has rendered into it.
182 static const gl_buffer_index buffers
[2] = {
187 for (int i
= 0; i
< 2; ++i
) {
188 rb
= intel_get_renderbuffer(fb
, buffers
[i
]);
189 if (rb
== NULL
|| rb
->mt
== NULL
)
191 intel_miptree_downsample(intel
, rb
->mt
);
196 intelDRI2Flush(__DRIdrawable
*drawable
)
198 GET_CURRENT_CONTEXT(ctx
);
199 struct intel_context
*intel
= intel_context(ctx
);
204 INTEL_FIREVERTICES(intel
);
206 intel_downsample_for_dri2_flush(intel
, drawable
);
207 intel
->need_throttle
= true;
209 if (intel
->batch
.used
)
210 intel_batchbuffer_flush(intel
);
212 if (INTEL_DEBUG
& DEBUG_AUB
) {
217 static const struct __DRI2flushExtensionRec intelFlushExtension
= {
218 { __DRI2_FLUSH
, __DRI2_FLUSH_VERSION
},
220 dri2InvalidateDrawable
,
224 intel_allocate_image(int dri_format
, void *loaderPrivate
)
228 image
= CALLOC(sizeof *image
);
232 image
->dri_format
= dri_format
;
235 switch (dri_format
) {
236 case __DRI_IMAGE_FORMAT_RGB565
:
237 image
->format
= MESA_FORMAT_RGB565
;
239 case __DRI_IMAGE_FORMAT_XRGB8888
:
240 image
->format
= MESA_FORMAT_XRGB8888
;
242 case __DRI_IMAGE_FORMAT_ARGB8888
:
243 image
->format
= MESA_FORMAT_ARGB8888
;
245 case __DRI_IMAGE_FORMAT_ABGR8888
:
246 image
->format
= MESA_FORMAT_RGBA8888_REV
;
248 case __DRI_IMAGE_FORMAT_XBGR8888
:
249 image
->format
= MESA_FORMAT_RGBX8888_REV
;
251 case __DRI_IMAGE_FORMAT_R8
:
252 image
->format
= MESA_FORMAT_R8
;
254 case __DRI_IMAGE_FORMAT_GR88
:
255 image
->format
= MESA_FORMAT_GR88
;
257 case __DRI_IMAGE_FORMAT_NONE
:
258 image
->format
= MESA_FORMAT_NONE
;
265 image
->internal_format
= _mesa_get_format_base_format(image
->format
);
266 image
->data
= loaderPrivate
;
272 intel_create_image_from_name(__DRIscreen
*screen
,
273 int width
, int height
, int format
,
274 int name
, int pitch
, void *loaderPrivate
)
276 struct intel_screen
*intelScreen
= screen
->driverPrivate
;
280 image
= intel_allocate_image(format
, loaderPrivate
);
281 if (image
->format
== MESA_FORMAT_NONE
)
284 cpp
= _mesa_get_format_bytes(image
->format
);
285 image
->region
= intel_region_alloc_for_handle(intelScreen
,
287 pitch
, name
, "image");
288 if (image
->region
== NULL
) {
297 intel_create_image_from_renderbuffer(__DRIcontext
*context
,
298 int renderbuffer
, void *loaderPrivate
)
301 struct intel_context
*intel
= context
->driverPrivate
;
302 struct gl_renderbuffer
*rb
;
303 struct intel_renderbuffer
*irb
;
305 rb
= _mesa_lookup_renderbuffer(&intel
->ctx
, renderbuffer
);
307 _mesa_error(&intel
->ctx
,
308 GL_INVALID_OPERATION
, "glRenderbufferExternalMESA");
312 irb
= intel_renderbuffer(rb
);
313 image
= CALLOC(sizeof *image
);
317 image
->internal_format
= rb
->InternalFormat
;
318 image
->format
= rb
->Format
;
320 image
->data
= loaderPrivate
;
321 intel_region_reference(&image
->region
, irb
->mt
->region
);
323 switch (image
->format
) {
324 case MESA_FORMAT_RGB565
:
325 image
->dri_format
= __DRI_IMAGE_FORMAT_RGB565
;
327 case MESA_FORMAT_XRGB8888
:
328 image
->dri_format
= __DRI_IMAGE_FORMAT_XRGB8888
;
330 case MESA_FORMAT_ARGB8888
:
331 image
->dri_format
= __DRI_IMAGE_FORMAT_ARGB8888
;
333 case MESA_FORMAT_RGBA8888_REV
:
334 image
->dri_format
= __DRI_IMAGE_FORMAT_ABGR8888
;
337 image
->dri_format
= __DRI_IMAGE_FORMAT_R8
;
339 case MESA_FORMAT_RG88
:
340 image
->dri_format
= __DRI_IMAGE_FORMAT_GR88
;
348 intel_destroy_image(__DRIimage
*image
)
350 intel_region_release(&image
->region
);
355 intel_create_image(__DRIscreen
*screen
,
356 int width
, int height
, int format
,
361 struct intel_screen
*intelScreen
= screen
->driverPrivate
;
365 tiling
= I915_TILING_X
;
366 if (use
& __DRI_IMAGE_USE_CURSOR
) {
367 if (width
!= 64 || height
!= 64)
369 tiling
= I915_TILING_NONE
;
372 /* We only support write for cursor drm images */
373 if ((use
& __DRI_IMAGE_USE_WRITE
) &&
374 use
!= (__DRI_IMAGE_USE_WRITE
| __DRI_IMAGE_USE_CURSOR
))
377 image
= intel_allocate_image(format
, loaderPrivate
);
379 cpp
= _mesa_get_format_bytes(image
->format
);
381 intel_region_alloc(intelScreen
, tiling
, cpp
, width
, height
, true);
382 if (image
->region
== NULL
) {
391 intel_query_image(__DRIimage
*image
, int attrib
, int *value
)
394 case __DRI_IMAGE_ATTRIB_STRIDE
:
395 *value
= image
->region
->pitch
* image
->region
->cpp
;
397 case __DRI_IMAGE_ATTRIB_HANDLE
:
398 *value
= image
->region
->bo
->handle
;
400 case __DRI_IMAGE_ATTRIB_NAME
:
401 return intel_region_flink(image
->region
, (uint32_t *) value
);
402 case __DRI_IMAGE_ATTRIB_FORMAT
:
403 *value
= image
->dri_format
;
405 case __DRI_IMAGE_ATTRIB_WIDTH
:
406 *value
= image
->region
->width
;
408 case __DRI_IMAGE_ATTRIB_HEIGHT
:
409 *value
= image
->region
->height
;
417 intel_dup_image(__DRIimage
*orig_image
, void *loaderPrivate
)
421 image
= CALLOC(sizeof *image
);
425 intel_region_reference(&image
->region
, orig_image
->region
);
426 if (image
->region
== NULL
) {
431 image
->internal_format
= orig_image
->internal_format
;
432 image
->usage
= orig_image
->usage
;
433 image
->dri_format
= orig_image
->dri_format
;
434 image
->format
= orig_image
->format
;
435 image
->offset
= orig_image
->offset
;
436 image
->data
= loaderPrivate
;
442 intel_validate_usage(__DRIimage
*image
, unsigned int use
)
444 if (use
& __DRI_IMAGE_USE_CURSOR
) {
445 if (image
->region
->width
!= 64 || image
->region
->height
!= 64)
449 /* We only support write for cursor drm images */
450 if ((use
& __DRI_IMAGE_USE_WRITE
) &&
451 use
!= (__DRI_IMAGE_USE_WRITE
| __DRI_IMAGE_USE_CURSOR
))
458 intel_image_write(__DRIimage
*image
, const void *buf
, size_t count
)
460 if (image
->region
->map_refcount
)
462 if (!(image
->usage
& __DRI_IMAGE_USE_WRITE
))
465 drm_intel_bo_map(image
->region
->bo
, true);
466 memcpy(image
->region
->bo
->virtual, buf
, count
);
467 drm_intel_bo_unmap(image
->region
->bo
);
473 intel_create_sub_image(__DRIimage
*parent
,
474 int width
, int height
, int dri_format
,
475 int offset
, int pitch
, void *loaderPrivate
)
479 uint32_t mask_x
, mask_y
;
481 image
= intel_allocate_image(dri_format
, loaderPrivate
);
482 cpp
= _mesa_get_format_bytes(image
->format
);
483 if (offset
+ height
* cpp
* pitch
> parent
->region
->bo
->size
) {
484 _mesa_warning(NULL
, "intel_create_sub_image: subimage out of bounds");
489 image
->region
= calloc(sizeof(*image
->region
), 1);
490 if (image
->region
== NULL
) {
495 image
->region
->cpp
= _mesa_get_format_bytes(image
->format
);
496 image
->region
->width
= width
;
497 image
->region
->height
= height
;
498 image
->region
->pitch
= pitch
;
499 image
->region
->refcount
= 1;
500 image
->region
->bo
= parent
->region
->bo
;
501 drm_intel_bo_reference(image
->region
->bo
);
502 image
->region
->tiling
= parent
->region
->tiling
;
503 image
->region
->screen
= parent
->region
->screen
;
504 image
->offset
= offset
;
506 intel_region_get_tile_masks(image
->region
, &mask_x
, &mask_y
);
509 "intel_create_sub_image: offset not on tile boundary");
514 static struct __DRIimageExtensionRec intelImageExtension
= {
516 intel_create_image_from_name
,
517 intel_create_image_from_renderbuffer
,
522 intel_validate_usage
,
524 intel_create_sub_image
527 static const __DRIextension
*intelScreenExtensions
[] = {
528 &intelTexBufferExtension
.base
,
529 &intelFlushExtension
.base
,
530 &intelImageExtension
.base
,
531 &dri2ConfigQueryExtension
.base
,
536 intel_get_param(__DRIscreen
*psp
, int param
, int *value
)
539 struct drm_i915_getparam gp
;
541 memset(&gp
, 0, sizeof(gp
));
545 ret
= drmCommandWriteRead(psp
->fd
, DRM_I915_GETPARAM
, &gp
, sizeof(gp
));
548 _mesa_warning(NULL
, "drm_i915_getparam: %d", ret
);
556 intel_get_boolean(__DRIscreen
*psp
, int param
)
559 return intel_get_param(psp
, param
, &value
) && value
;
563 nop_callback(GLuint key
, void *data
, void *userData
)
568 intelDestroyScreen(__DRIscreen
* sPriv
)
570 struct intel_screen
*intelScreen
= sPriv
->driverPrivate
;
572 dri_bufmgr_destroy(intelScreen
->bufmgr
);
573 driDestroyOptionInfo(&intelScreen
->optionCache
);
575 /* Some regions may still have references to them at this point, so
576 * flush the hash table to prevent _mesa_DeleteHashTable() from
577 * complaining about the hash not being empty; */
578 _mesa_HashDeleteAll(intelScreen
->named_regions
, nop_callback
, NULL
);
579 _mesa_DeleteHashTable(intelScreen
->named_regions
);
582 sPriv
->driverPrivate
= NULL
;
587 * This is called when we need to set up GL rendering to a new X window.
590 intelCreateBuffer(__DRIscreen
* driScrnPriv
,
591 __DRIdrawable
* driDrawPriv
,
592 const struct gl_config
* mesaVis
, GLboolean isPixmap
)
594 struct intel_renderbuffer
*rb
;
595 struct intel_screen
*screen
= (struct intel_screen
*) driScrnPriv
->driverPrivate
;
597 unsigned num_samples
= intel_quantize_num_samples(screen
, mesaVis
->samples
);
598 struct gl_framebuffer
*fb
;
603 fb
= CALLOC_STRUCT(gl_framebuffer
);
607 _mesa_initialize_window_framebuffer(fb
, mesaVis
);
609 if (mesaVis
->redBits
== 5)
610 rgbFormat
= MESA_FORMAT_RGB565
;
611 else if (mesaVis
->alphaBits
== 0)
612 rgbFormat
= MESA_FORMAT_XRGB8888
;
614 rgbFormat
= MESA_FORMAT_ARGB8888
;
616 /* setup the hardware-based renderbuffers */
617 rb
= intel_create_renderbuffer(rgbFormat
, num_samples
);
618 _mesa_add_renderbuffer(fb
, BUFFER_FRONT_LEFT
, &rb
->Base
.Base
);
620 if (mesaVis
->doubleBufferMode
) {
621 rb
= intel_create_renderbuffer(rgbFormat
, num_samples
);
622 _mesa_add_renderbuffer(fb
, BUFFER_BACK_LEFT
, &rb
->Base
.Base
);
626 * Assert here that the gl_config has an expected depth/stencil bit
627 * combination: one of d24/s8, d16/s0, d0/s0. (See intelInitScreen2(),
628 * which constructs the advertised configs.)
630 if (mesaVis
->depthBits
== 24) {
631 assert(mesaVis
->stencilBits
== 8);
633 if (screen
->hw_has_separate_stencil
) {
634 rb
= intel_create_private_renderbuffer(MESA_FORMAT_X8_Z24
,
636 _mesa_add_renderbuffer(fb
, BUFFER_DEPTH
, &rb
->Base
.Base
);
637 rb
= intel_create_private_renderbuffer(MESA_FORMAT_S8
,
639 _mesa_add_renderbuffer(fb
, BUFFER_STENCIL
, &rb
->Base
.Base
);
642 * Use combined depth/stencil. Note that the renderbuffer is
643 * attached to two attachment points.
645 rb
= intel_create_private_renderbuffer(MESA_FORMAT_S8_Z24
,
647 _mesa_add_renderbuffer(fb
, BUFFER_DEPTH
, &rb
->Base
.Base
);
648 _mesa_add_renderbuffer(fb
, BUFFER_STENCIL
, &rb
->Base
.Base
);
651 else if (mesaVis
->depthBits
== 16) {
652 assert(mesaVis
->stencilBits
== 0);
653 rb
= intel_create_private_renderbuffer(MESA_FORMAT_Z16
,
655 _mesa_add_renderbuffer(fb
, BUFFER_DEPTH
, &rb
->Base
.Base
);
658 assert(mesaVis
->depthBits
== 0);
659 assert(mesaVis
->stencilBits
== 0);
662 /* now add any/all software-based renderbuffers we may need */
663 _swrast_add_soft_renderbuffers(fb
,
664 false, /* never sw color */
665 false, /* never sw depth */
666 false, /* never sw stencil */
667 mesaVis
->accumRedBits
> 0,
668 false, /* never sw alpha */
669 false /* never sw aux */ );
670 driDrawPriv
->driverPrivate
= fb
;
676 intelDestroyBuffer(__DRIdrawable
* driDrawPriv
)
678 struct gl_framebuffer
*fb
= driDrawPriv
->driverPrivate
;
680 _mesa_reference_framebuffer(&fb
, NULL
);
683 /* There are probably better ways to do this, such as an
684 * init-designated function to register chipids and createcontext
688 i830CreateContext(const struct gl_config
*mesaVis
,
689 __DRIcontext
*driContextPriv
,
690 void *sharedContextPrivate
);
693 i915CreateContext(int api
,
694 const struct gl_config
*mesaVis
,
695 __DRIcontext
*driContextPriv
,
696 void *sharedContextPrivate
);
698 brwCreateContext(int api
,
699 const struct gl_config
*mesaVis
,
700 __DRIcontext
*driContextPriv
,
701 void *sharedContextPrivate
);
704 intelCreateContext(gl_api api
,
705 const struct gl_config
* mesaVis
,
706 __DRIcontext
* driContextPriv
,
707 unsigned major_version
,
708 unsigned minor_version
,
711 void *sharedContextPrivate
)
713 __DRIscreen
*sPriv
= driContextPriv
->driScreenPriv
;
714 struct intel_screen
*intelScreen
= sPriv
->driverPrivate
;
715 bool success
= false;
718 if (IS_9XX(intelScreen
->deviceID
)) {
719 if (!IS_965(intelScreen
->deviceID
)) {
720 success
= i915CreateContext(api
, mesaVis
, driContextPriv
,
721 sharedContextPrivate
);
724 intelScreen
->no_vbo
= true;
725 success
= i830CreateContext(mesaVis
, driContextPriv
,
726 sharedContextPrivate
);
729 if (IS_965(intelScreen
->deviceID
))
730 success
= brwCreateContext(api
, mesaVis
,
732 sharedContextPrivate
);
736 struct gl_context
*ctx
=
737 (struct gl_context
*) driContextPriv
->driverPrivate
;
739 _mesa_compute_version(ctx
);
740 if (ctx
->Version
>= major_version
* 10 + minor_version
) {
744 *error
= __DRI_CTX_ERROR_BAD_VERSION
;
745 intelDestroyContext(driContextPriv
);
747 *error
= __DRI_CTX_ERROR_NO_MEMORY
;
748 fprintf(stderr
, "Unrecognized deviceID 0x%x\n", intelScreen
->deviceID
);
755 intel_init_bufmgr(struct intel_screen
*intelScreen
)
757 __DRIscreen
*spriv
= intelScreen
->driScrnPriv
;
760 intelScreen
->no_hw
= getenv("INTEL_NO_HW") != NULL
;
762 intelScreen
->bufmgr
= intel_bufmgr_gem_init(spriv
->fd
, BATCH_SZ
);
763 if (intelScreen
->bufmgr
== NULL
) {
764 fprintf(stderr
, "[%s:%u] Error initializing buffer manager.\n",
769 if (!intel_get_param(spriv
, I915_PARAM_NUM_FENCES_AVAIL
, &num_fences
) ||
771 fprintf(stderr
, "[%s: %u] Kernel 2.6.29 required.\n", __func__
, __LINE__
);
775 drm_intel_bufmgr_gem_enable_fenced_relocs(intelScreen
->bufmgr
);
777 intelScreen
->named_regions
= _mesa_NewHashTable();
779 intelScreen
->relaxed_relocations
= 0;
780 intelScreen
->relaxed_relocations
|=
781 intel_get_boolean(spriv
, I915_PARAM_HAS_RELAXED_DELTA
) << 0;
787 * Override intel_screen.hw_has_separate_stencil with environment variable
788 * INTEL_SEPARATE_STENCIL.
790 * Valid values for INTEL_SEPARATE_STENCIL are "0" and "1". If an invalid
791 * valid value is encountered, a warning is emitted and INTEL_SEPARATE_STENCIL
795 intel_override_separate_stencil(struct intel_screen
*screen
)
797 const char *s
= getenv("INTEL_SEPARATE_STENCIL");
800 } else if (!strncmp("0", s
, 2)) {
801 screen
->hw_has_separate_stencil
= false;
802 } else if (!strncmp("1", s
, 2)) {
803 screen
->hw_has_separate_stencil
= true;
806 "warning: env variable INTEL_SEPARATE_STENCIL=\"%s\" has "
807 "invalid value and is ignored", s
);
812 intel_detect_swizzling(struct intel_screen
*screen
)
814 drm_intel_bo
*buffer
;
815 unsigned long flags
= 0;
816 unsigned long aligned_pitch
;
817 uint32_t tiling
= I915_TILING_X
;
818 uint32_t swizzle_mode
= 0;
820 buffer
= drm_intel_bo_alloc_tiled(screen
->bufmgr
, "swizzle test",
822 &tiling
, &aligned_pitch
, flags
);
826 drm_intel_bo_get_tiling(buffer
, &tiling
, &swizzle_mode
);
827 drm_intel_bo_unreference(buffer
);
829 if (swizzle_mode
== I915_BIT_6_SWIZZLE_NONE
)
836 intel_screen_make_configs(__DRIscreen
*dri_screen
)
838 static const GLenum back_buffer_modes
[] = {
839 GLX_NONE
, GLX_SWAP_UNDEFINED_OML
, GLX_SWAP_COPY_OML
842 static const uint8_t singlesample_samples
[1] = {0};
843 static const uint8_t multisample_samples
[2] = {4, 8};
845 struct intel_screen
*screen
= dri_screen
->driverPrivate
;
848 uint8_t depth_bits
[4], stencil_bits
[4];
849 __DRIconfig
**configs
= NULL
;
851 fb_format
[0] = GL_RGB
;
852 fb_type
[0] = GL_UNSIGNED_SHORT_5_6_5
;
854 fb_format
[1] = GL_BGR
;
855 fb_type
[1] = GL_UNSIGNED_INT_8_8_8_8_REV
;
857 fb_format
[2] = GL_BGRA
;
858 fb_type
[2] = GL_UNSIGNED_INT_8_8_8_8_REV
;
860 /* Generate singlesample configs without accumulation buffer. */
861 for (int i
= 0; i
< ARRAY_SIZE(fb_format
); i
++) {
862 __DRIconfig
**new_configs
;
863 const int num_depth_stencil_bits
= 2;
865 /* Starting with DRI2 protocol version 1.1 we can request a depth/stencil
866 * buffer that has a different number of bits per pixel than the color
867 * buffer. This isn't yet supported here.
872 if (fb_type
[i
] == GL_UNSIGNED_SHORT_5_6_5
) {
880 new_configs
= driCreateConfigs(fb_format
[i
], fb_type
[i
],
883 num_depth_stencil_bits
,
885 ARRAY_SIZE(back_buffer_modes
),
886 singlesample_samples
, 1,
888 configs
= driConcatConfigs(configs
, new_configs
);
891 /* Generate the minimum possible set of configs that include an
892 * accumulation buffer.
894 for (int i
= 0; i
< ARRAY_SIZE(fb_format
); i
++) {
895 __DRIconfig
**new_configs
;
897 if (fb_type
[i
] == GL_UNSIGNED_SHORT_5_6_5
) {
905 new_configs
= driCreateConfigs(fb_format
[i
], fb_type
[i
],
906 depth_bits
, stencil_bits
, 1,
907 back_buffer_modes
+ 1, 1,
908 singlesample_samples
, 1,
910 configs
= driConcatConfigs(configs
, new_configs
);
913 /* Generate multisample configs.
915 * This loop breaks early, and hence is a no-op, on gen < 6.
917 * Multisample configs must follow the singlesample configs in order to
918 * work around an X server bug present in 1.12. The X server chooses to
919 * associate the first listed RGBA888-Z24S8 config, regardless of its
920 * sample count, with the 32-bit depth visual used for compositing.
922 * Only doublebuffer configs with GLX_SWAP_UNDEFINED_OML behavior are
923 * supported. Singlebuffer configs are not supported because no one wants
924 * them. GLX_SWAP_COPY_OML is not supported due to page flipping.
926 for (int i
= 0; i
< ARRAY_SIZE(fb_format
); i
++) {
930 __DRIconfig
**new_configs
;
931 const int num_depth_stencil_bits
= 2;
932 int num_msaa_modes
= 0;
937 if (fb_type
[i
] == GL_UNSIGNED_SHORT_5_6_5
) {
945 if (screen
->gen
>= 7)
947 else if (screen
->gen
== 6)
950 new_configs
= driCreateConfigs(fb_format
[i
], fb_type
[i
],
953 num_depth_stencil_bits
,
954 back_buffer_modes
+ 1, 1,
958 configs
= driConcatConfigs(configs
, new_configs
);
961 if (configs
== NULL
) {
962 fprintf(stderr
, "[%s:%u] Error creating FBConfig!\n", __func__
,
971 * This is the driver specific part of the createNewScreen entry point.
972 * Called when using DRI2.
974 * \return the struct gl_config supported by this driver
977 __DRIconfig
**intelInitScreen2(__DRIscreen
*psp
)
979 struct intel_screen
*intelScreen
;
980 unsigned int api_mask
;
982 if (psp
->dri2
.loader
->base
.version
<= 2 ||
983 psp
->dri2
.loader
->getBuffersWithFormat
== NULL
) {
985 "\nERROR! DRI2 loader with getBuffersWithFormat() "
986 "support required\n");
990 /* Allocate the private area */
991 intelScreen
= CALLOC(sizeof *intelScreen
);
993 fprintf(stderr
, "\nERROR! Allocating private area failed\n");
996 /* parse information in __driConfigOptions */
997 driParseOptionInfo(&intelScreen
->optionCache
,
998 __driConfigOptions
, __driNConfigOptions
);
1000 intelScreen
->driScrnPriv
= psp
;
1001 psp
->driverPrivate
= (void *) intelScreen
;
1003 if (!intel_init_bufmgr(intelScreen
))
1006 intelScreen
->deviceID
= drm_intel_bufmgr_gem_get_devid(intelScreen
->bufmgr
);
1008 intelScreen
->kernel_has_gen7_sol_reset
=
1009 intel_get_boolean(intelScreen
->driScrnPriv
,
1010 I915_PARAM_HAS_GEN7_SOL_RESET
);
1012 if (IS_GEN7(intelScreen
->deviceID
)) {
1013 intelScreen
->gen
= 7;
1014 } else if (IS_GEN6(intelScreen
->deviceID
)) {
1015 intelScreen
->gen
= 6;
1016 } else if (IS_GEN5(intelScreen
->deviceID
)) {
1017 intelScreen
->gen
= 5;
1018 } else if (IS_965(intelScreen
->deviceID
)) {
1019 intelScreen
->gen
= 4;
1020 } else if (IS_9XX(intelScreen
->deviceID
)) {
1021 intelScreen
->gen
= 3;
1023 intelScreen
->gen
= 2;
1026 intelScreen
->hw_has_separate_stencil
= intelScreen
->gen
>= 6;
1027 intelScreen
->hw_must_use_separate_stencil
= intelScreen
->gen
>= 7;
1030 bool success
= intel_get_param(intelScreen
->driScrnPriv
, I915_PARAM_HAS_LLC
,
1032 if (success
&& has_llc
)
1033 intelScreen
->hw_has_llc
= true;
1034 else if (!success
&& intelScreen
->gen
>= 6)
1035 intelScreen
->hw_has_llc
= true;
1037 intel_override_separate_stencil(intelScreen
);
1039 api_mask
= (1 << __DRI_API_OPENGL
);
1041 api_mask
|= (1 << __DRI_API_GLES
);
1044 api_mask
|= (1 << __DRI_API_GLES2
);
1047 if (IS_9XX(intelScreen
->deviceID
) || IS_965(intelScreen
->deviceID
))
1048 psp
->api_mask
= api_mask
;
1050 intelScreen
->hw_has_swizzling
= intel_detect_swizzling(intelScreen
);
1052 psp
->extensions
= intelScreenExtensions
;
1054 return (const __DRIconfig
**) intel_screen_make_configs(psp
);
1057 struct intel_buffer
{
1059 struct intel_region
*region
;
1062 static __DRIbuffer
*
1063 intelAllocateBuffer(__DRIscreen
*screen
,
1064 unsigned attachment
, unsigned format
,
1065 int width
, int height
)
1067 struct intel_buffer
*intelBuffer
;
1068 struct intel_screen
*intelScreen
= screen
->driverPrivate
;
1070 assert(attachment
== __DRI_BUFFER_FRONT_LEFT
||
1071 attachment
== __DRI_BUFFER_BACK_LEFT
);
1073 intelBuffer
= CALLOC(sizeof *intelBuffer
);
1074 if (intelBuffer
== NULL
)
1077 /* The front and back buffers are color buffers, which are X tiled. */
1078 intelBuffer
->region
= intel_region_alloc(intelScreen
,
1085 if (intelBuffer
->region
== NULL
) {
1090 intel_region_flink(intelBuffer
->region
, &intelBuffer
->base
.name
);
1092 intelBuffer
->base
.attachment
= attachment
;
1093 intelBuffer
->base
.cpp
= intelBuffer
->region
->cpp
;
1094 intelBuffer
->base
.pitch
=
1095 intelBuffer
->region
->pitch
* intelBuffer
->region
->cpp
;
1097 return &intelBuffer
->base
;
1101 intelReleaseBuffer(__DRIscreen
*screen
, __DRIbuffer
*buffer
)
1103 struct intel_buffer
*intelBuffer
= (struct intel_buffer
*) buffer
;
1105 intel_region_release(&intelBuffer
->region
);
1110 const struct __DriverAPIRec driDriverAPI
= {
1111 .InitScreen
= intelInitScreen2
,
1112 .DestroyScreen
= intelDestroyScreen
,
1113 .CreateContext
= intelCreateContext
,
1114 .DestroyContext
= intelDestroyContext
,
1115 .CreateBuffer
= intelCreateBuffer
,
1116 .DestroyBuffer
= intelDestroyBuffer
,
1117 .MakeCurrent
= intelMakeCurrent
,
1118 .UnbindContext
= intelUnbindContext
,
1119 .AllocateBuffer
= intelAllocateBuffer
,
1120 .ReleaseBuffer
= intelReleaseBuffer
1123 /* This is the table of extensions that the loader will dlsym() for. */
1124 PUBLIC
const __DRIextension
*__driDriverExtensions
[] = {
1125 &driCoreExtension
.base
,
1126 &driDRI2Extension
.base
,