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 aub_dump_bmp(struct gl_context
*ctx
)
115 struct gl_framebuffer
*fb
= ctx
->DrawBuffer
;
117 for (int i
= 0; i
< fb
->_NumColorDrawBuffers
; i
++) {
118 struct intel_renderbuffer
*irb
=
119 intel_renderbuffer(fb
->_ColorDrawBuffers
[i
]);
121 if (irb
&& irb
->mt
) {
122 enum aub_dump_bmp_format format
;
124 switch (irb
->Base
.Base
.Format
) {
125 case MESA_FORMAT_ARGB8888
:
126 case MESA_FORMAT_XRGB8888
:
127 format
= AUB_DUMP_BMP_FORMAT_ARGB_8888
;
133 drm_intel_gem_bo_aub_dump_bmp(irb
->mt
->region
->bo
,
136 irb
->Base
.Base
.Width
,
137 irb
->Base
.Base
.Height
,
139 irb
->mt
->region
->pitch
*
140 irb
->mt
->region
->cpp
,
146 static const __DRItexBufferExtension intelTexBufferExtension
= {
147 { __DRI_TEX_BUFFER
, __DRI_TEX_BUFFER_VERSION
},
153 intel_downsample_for_dri2_flush(struct intel_context
*intel
,
154 __DRIdrawable
*drawable
)
156 if (intel
->gen
< 6) {
157 /* MSAA is not supported, so don't waste time checking for
158 * a multisample buffer.
163 struct gl_framebuffer
*fb
= drawable
->driverPrivate
;
164 struct intel_renderbuffer
*rb
;
166 /* Usually, only the back buffer will need to be downsampled. However,
167 * the front buffer will also need it if the user has rendered into it.
169 static const gl_buffer_index buffers
[2] = {
174 for (int i
= 0; i
< 2; ++i
) {
175 rb
= intel_get_renderbuffer(fb
, buffers
[i
]);
176 if (rb
== NULL
|| rb
->mt
== NULL
)
178 intel_miptree_downsample(intel
, rb
->mt
);
183 intelDRI2Flush(__DRIdrawable
*drawable
)
185 GET_CURRENT_CONTEXT(ctx
);
186 struct intel_context
*intel
= intel_context(ctx
);
191 INTEL_FIREVERTICES(intel
);
193 intel_downsample_for_dri2_flush(intel
, drawable
);
194 intel
->need_throttle
= true;
196 if (intel
->batch
.used
)
197 intel_batchbuffer_flush(intel
);
199 if (INTEL_DEBUG
& DEBUG_AUB
) {
204 static const struct __DRI2flushExtensionRec intelFlushExtension
= {
205 { __DRI2_FLUSH
, __DRI2_FLUSH_VERSION
},
207 dri2InvalidateDrawable
,
211 intel_allocate_image(int dri_format
, void *loaderPrivate
)
215 image
= CALLOC(sizeof *image
);
219 image
->dri_format
= dri_format
;
222 switch (dri_format
) {
223 case __DRI_IMAGE_FORMAT_RGB565
:
224 image
->format
= MESA_FORMAT_RGB565
;
226 case __DRI_IMAGE_FORMAT_XRGB8888
:
227 image
->format
= MESA_FORMAT_XRGB8888
;
229 case __DRI_IMAGE_FORMAT_ARGB8888
:
230 image
->format
= MESA_FORMAT_ARGB8888
;
232 case __DRI_IMAGE_FORMAT_ABGR8888
:
233 image
->format
= MESA_FORMAT_RGBA8888_REV
;
235 case __DRI_IMAGE_FORMAT_XBGR8888
:
236 image
->format
= MESA_FORMAT_RGBX8888_REV
;
238 case __DRI_IMAGE_FORMAT_R8
:
239 image
->format
= MESA_FORMAT_R8
;
241 case __DRI_IMAGE_FORMAT_GR88
:
242 image
->format
= MESA_FORMAT_GR88
;
244 case __DRI_IMAGE_FORMAT_NONE
:
245 image
->format
= MESA_FORMAT_NONE
;
252 image
->internal_format
= _mesa_get_format_base_format(image
->format
);
253 image
->data
= loaderPrivate
;
259 intel_create_image_from_name(__DRIscreen
*screen
,
260 int width
, int height
, int format
,
261 int name
, int pitch
, void *loaderPrivate
)
263 struct intel_screen
*intelScreen
= screen
->driverPrivate
;
267 image
= intel_allocate_image(format
, loaderPrivate
);
268 if (image
->format
== MESA_FORMAT_NONE
)
271 cpp
= _mesa_get_format_bytes(image
->format
);
272 image
->region
= intel_region_alloc_for_handle(intelScreen
,
274 pitch
, name
, "image");
275 if (image
->region
== NULL
) {
284 intel_create_image_from_renderbuffer(__DRIcontext
*context
,
285 int renderbuffer
, void *loaderPrivate
)
288 struct intel_context
*intel
= context
->driverPrivate
;
289 struct gl_renderbuffer
*rb
;
290 struct intel_renderbuffer
*irb
;
292 rb
= _mesa_lookup_renderbuffer(&intel
->ctx
, renderbuffer
);
294 _mesa_error(&intel
->ctx
,
295 GL_INVALID_OPERATION
, "glRenderbufferExternalMESA");
299 irb
= intel_renderbuffer(rb
);
300 image
= CALLOC(sizeof *image
);
304 image
->internal_format
= rb
->InternalFormat
;
305 image
->format
= rb
->Format
;
307 image
->data
= loaderPrivate
;
308 intel_region_reference(&image
->region
, irb
->mt
->region
);
310 switch (image
->format
) {
311 case MESA_FORMAT_RGB565
:
312 image
->dri_format
= __DRI_IMAGE_FORMAT_RGB565
;
314 case MESA_FORMAT_XRGB8888
:
315 image
->dri_format
= __DRI_IMAGE_FORMAT_XRGB8888
;
317 case MESA_FORMAT_ARGB8888
:
318 image
->dri_format
= __DRI_IMAGE_FORMAT_ARGB8888
;
320 case MESA_FORMAT_RGBA8888_REV
:
321 image
->dri_format
= __DRI_IMAGE_FORMAT_ABGR8888
;
324 image
->dri_format
= __DRI_IMAGE_FORMAT_R8
;
326 case MESA_FORMAT_RG88
:
327 image
->dri_format
= __DRI_IMAGE_FORMAT_GR88
;
335 intel_destroy_image(__DRIimage
*image
)
337 intel_region_release(&image
->region
);
342 intel_create_image(__DRIscreen
*screen
,
343 int width
, int height
, int format
,
348 struct intel_screen
*intelScreen
= screen
->driverPrivate
;
352 tiling
= I915_TILING_X
;
353 if (use
& __DRI_IMAGE_USE_CURSOR
) {
354 if (width
!= 64 || height
!= 64)
356 tiling
= I915_TILING_NONE
;
359 /* We only support write for cursor drm images */
360 if ((use
& __DRI_IMAGE_USE_WRITE
) &&
361 use
!= (__DRI_IMAGE_USE_WRITE
| __DRI_IMAGE_USE_CURSOR
))
364 image
= intel_allocate_image(format
, loaderPrivate
);
366 cpp
= _mesa_get_format_bytes(image
->format
);
368 intel_region_alloc(intelScreen
, tiling
, cpp
, width
, height
, true);
369 if (image
->region
== NULL
) {
378 intel_query_image(__DRIimage
*image
, int attrib
, int *value
)
381 case __DRI_IMAGE_ATTRIB_STRIDE
:
382 *value
= image
->region
->pitch
* image
->region
->cpp
;
384 case __DRI_IMAGE_ATTRIB_HANDLE
:
385 *value
= image
->region
->bo
->handle
;
387 case __DRI_IMAGE_ATTRIB_NAME
:
388 return intel_region_flink(image
->region
, (uint32_t *) value
);
389 case __DRI_IMAGE_ATTRIB_FORMAT
:
390 *value
= image
->dri_format
;
392 case __DRI_IMAGE_ATTRIB_WIDTH
:
393 *value
= image
->region
->width
;
395 case __DRI_IMAGE_ATTRIB_HEIGHT
:
396 *value
= image
->region
->height
;
404 intel_dup_image(__DRIimage
*orig_image
, void *loaderPrivate
)
408 image
= CALLOC(sizeof *image
);
412 intel_region_reference(&image
->region
, orig_image
->region
);
413 if (image
->region
== NULL
) {
418 image
->internal_format
= orig_image
->internal_format
;
419 image
->usage
= orig_image
->usage
;
420 image
->dri_format
= orig_image
->dri_format
;
421 image
->format
= orig_image
->format
;
422 image
->offset
= orig_image
->offset
;
423 image
->data
= loaderPrivate
;
429 intel_validate_usage(__DRIimage
*image
, unsigned int use
)
431 if (use
& __DRI_IMAGE_USE_CURSOR
) {
432 if (image
->region
->width
!= 64 || image
->region
->height
!= 64)
436 /* We only support write for cursor drm images */
437 if ((use
& __DRI_IMAGE_USE_WRITE
) &&
438 use
!= (__DRI_IMAGE_USE_WRITE
| __DRI_IMAGE_USE_CURSOR
))
445 intel_image_write(__DRIimage
*image
, const void *buf
, size_t count
)
447 if (image
->region
->map_refcount
)
449 if (!(image
->usage
& __DRI_IMAGE_USE_WRITE
))
452 drm_intel_bo_map(image
->region
->bo
, true);
453 memcpy(image
->region
->bo
->virtual, buf
, count
);
454 drm_intel_bo_unmap(image
->region
->bo
);
460 intel_create_sub_image(__DRIimage
*parent
,
461 int width
, int height
, int dri_format
,
462 int offset
, int pitch
, void *loaderPrivate
)
466 uint32_t mask_x
, mask_y
;
468 image
= intel_allocate_image(dri_format
, loaderPrivate
);
469 cpp
= _mesa_get_format_bytes(image
->format
);
470 if (offset
+ height
* cpp
* pitch
> parent
->region
->bo
->size
) {
471 _mesa_warning(NULL
, "intel_create_sub_image: subimage out of bounds");
476 image
->region
= calloc(sizeof(*image
->region
), 1);
477 if (image
->region
== NULL
) {
482 image
->region
->cpp
= _mesa_get_format_bytes(image
->format
);
483 image
->region
->width
= width
;
484 image
->region
->height
= height
;
485 image
->region
->pitch
= pitch
;
486 image
->region
->refcount
= 1;
487 image
->region
->bo
= parent
->region
->bo
;
488 drm_intel_bo_reference(image
->region
->bo
);
489 image
->region
->tiling
= parent
->region
->tiling
;
490 image
->region
->screen
= parent
->region
->screen
;
491 image
->offset
= offset
;
493 intel_region_get_tile_masks(image
->region
, &mask_x
, &mask_y
);
496 "intel_create_sub_image: offset not on tile boundary");
501 static struct __DRIimageExtensionRec intelImageExtension
= {
503 intel_create_image_from_name
,
504 intel_create_image_from_renderbuffer
,
509 intel_validate_usage
,
511 intel_create_sub_image
514 static const __DRIextension
*intelScreenExtensions
[] = {
515 &intelTexBufferExtension
.base
,
516 &intelFlushExtension
.base
,
517 &intelImageExtension
.base
,
518 &dri2ConfigQueryExtension
.base
,
523 intel_get_param(__DRIscreen
*psp
, int param
, int *value
)
526 struct drm_i915_getparam gp
;
528 memset(&gp
, 0, sizeof(gp
));
532 ret
= drmCommandWriteRead(psp
->fd
, DRM_I915_GETPARAM
, &gp
, sizeof(gp
));
535 _mesa_warning(NULL
, "drm_i915_getparam: %d", ret
);
543 intel_get_boolean(__DRIscreen
*psp
, int param
)
546 return intel_get_param(psp
, param
, &value
) && value
;
550 nop_callback(GLuint key
, void *data
, void *userData
)
555 intelDestroyScreen(__DRIscreen
* sPriv
)
557 struct intel_screen
*intelScreen
= sPriv
->driverPrivate
;
559 dri_bufmgr_destroy(intelScreen
->bufmgr
);
560 driDestroyOptionInfo(&intelScreen
->optionCache
);
562 /* Some regions may still have references to them at this point, so
563 * flush the hash table to prevent _mesa_DeleteHashTable() from
564 * complaining about the hash not being empty; */
565 _mesa_HashDeleteAll(intelScreen
->named_regions
, nop_callback
, NULL
);
566 _mesa_DeleteHashTable(intelScreen
->named_regions
);
569 sPriv
->driverPrivate
= NULL
;
574 * This is called when we need to set up GL rendering to a new X window.
577 intelCreateBuffer(__DRIscreen
* driScrnPriv
,
578 __DRIdrawable
* driDrawPriv
,
579 const struct gl_config
* mesaVis
, GLboolean isPixmap
)
581 struct intel_renderbuffer
*rb
;
582 struct intel_screen
*screen
= (struct intel_screen
*) driScrnPriv
->driverPrivate
;
584 unsigned num_samples
= intel_quantize_num_samples(screen
, mesaVis
->samples
);
585 struct gl_framebuffer
*fb
;
590 fb
= CALLOC_STRUCT(gl_framebuffer
);
594 _mesa_initialize_window_framebuffer(fb
, mesaVis
);
596 if (mesaVis
->redBits
== 5)
597 rgbFormat
= MESA_FORMAT_RGB565
;
598 else if (mesaVis
->alphaBits
== 0)
599 rgbFormat
= MESA_FORMAT_XRGB8888
;
601 rgbFormat
= MESA_FORMAT_ARGB8888
;
603 /* setup the hardware-based renderbuffers */
604 rb
= intel_create_renderbuffer(rgbFormat
, num_samples
);
605 _mesa_add_renderbuffer(fb
, BUFFER_FRONT_LEFT
, &rb
->Base
.Base
);
607 if (mesaVis
->doubleBufferMode
) {
608 rb
= intel_create_renderbuffer(rgbFormat
, num_samples
);
609 _mesa_add_renderbuffer(fb
, BUFFER_BACK_LEFT
, &rb
->Base
.Base
);
613 * Assert here that the gl_config has an expected depth/stencil bit
614 * combination: one of d24/s8, d16/s0, d0/s0. (See intelInitScreen2(),
615 * which constructs the advertised configs.)
617 if (mesaVis
->depthBits
== 24) {
618 assert(mesaVis
->stencilBits
== 8);
620 if (screen
->hw_has_separate_stencil
) {
621 rb
= intel_create_private_renderbuffer(MESA_FORMAT_X8_Z24
,
623 _mesa_add_renderbuffer(fb
, BUFFER_DEPTH
, &rb
->Base
.Base
);
624 rb
= intel_create_private_renderbuffer(MESA_FORMAT_S8
,
626 _mesa_add_renderbuffer(fb
, BUFFER_STENCIL
, &rb
->Base
.Base
);
629 * Use combined depth/stencil. Note that the renderbuffer is
630 * attached to two attachment points.
632 rb
= intel_create_private_renderbuffer(MESA_FORMAT_S8_Z24
,
634 _mesa_add_renderbuffer(fb
, BUFFER_DEPTH
, &rb
->Base
.Base
);
635 _mesa_add_renderbuffer(fb
, BUFFER_STENCIL
, &rb
->Base
.Base
);
638 else if (mesaVis
->depthBits
== 16) {
639 assert(mesaVis
->stencilBits
== 0);
640 rb
= intel_create_private_renderbuffer(MESA_FORMAT_Z16
,
642 _mesa_add_renderbuffer(fb
, BUFFER_DEPTH
, &rb
->Base
.Base
);
645 assert(mesaVis
->depthBits
== 0);
646 assert(mesaVis
->stencilBits
== 0);
649 /* now add any/all software-based renderbuffers we may need */
650 _swrast_add_soft_renderbuffers(fb
,
651 false, /* never sw color */
652 false, /* never sw depth */
653 false, /* never sw stencil */
654 mesaVis
->accumRedBits
> 0,
655 false, /* never sw alpha */
656 false /* never sw aux */ );
657 driDrawPriv
->driverPrivate
= fb
;
663 intelDestroyBuffer(__DRIdrawable
* driDrawPriv
)
665 struct gl_framebuffer
*fb
= driDrawPriv
->driverPrivate
;
667 _mesa_reference_framebuffer(&fb
, NULL
);
670 /* There are probably better ways to do this, such as an
671 * init-designated function to register chipids and createcontext
675 i830CreateContext(const struct gl_config
*mesaVis
,
676 __DRIcontext
*driContextPriv
,
677 void *sharedContextPrivate
);
680 i915CreateContext(int api
,
681 const struct gl_config
*mesaVis
,
682 __DRIcontext
*driContextPriv
,
683 void *sharedContextPrivate
);
685 brwCreateContext(int api
,
686 const struct gl_config
*mesaVis
,
687 __DRIcontext
*driContextPriv
,
688 void *sharedContextPrivate
);
691 intelCreateContext(gl_api api
,
692 const struct gl_config
* mesaVis
,
693 __DRIcontext
* driContextPriv
,
694 unsigned major_version
,
695 unsigned minor_version
,
698 void *sharedContextPrivate
)
700 __DRIscreen
*sPriv
= driContextPriv
->driScreenPriv
;
701 struct intel_screen
*intelScreen
= sPriv
->driverPrivate
;
702 bool success
= false;
705 if (IS_9XX(intelScreen
->deviceID
)) {
706 if (!IS_965(intelScreen
->deviceID
)) {
707 success
= i915CreateContext(api
, mesaVis
, driContextPriv
,
708 sharedContextPrivate
);
711 intelScreen
->no_vbo
= true;
712 success
= i830CreateContext(mesaVis
, driContextPriv
,
713 sharedContextPrivate
);
716 if (IS_965(intelScreen
->deviceID
))
717 success
= brwCreateContext(api
, mesaVis
,
719 sharedContextPrivate
);
723 struct gl_context
*ctx
=
724 (struct gl_context
*) driContextPriv
->driverPrivate
;
726 _mesa_compute_version(ctx
);
727 if (ctx
->VersionMajor
> major_version
728 || (ctx
->VersionMajor
== major_version
729 && ctx
->VersionMinor
>= minor_version
)) {
733 *error
= __DRI_CTX_ERROR_BAD_VERSION
;
734 intelDestroyContext(driContextPriv
);
736 *error
= __DRI_CTX_ERROR_NO_MEMORY
;
737 fprintf(stderr
, "Unrecognized deviceID 0x%x\n", intelScreen
->deviceID
);
744 intel_init_bufmgr(struct intel_screen
*intelScreen
)
746 __DRIscreen
*spriv
= intelScreen
->driScrnPriv
;
749 intelScreen
->no_hw
= getenv("INTEL_NO_HW") != NULL
;
751 intelScreen
->bufmgr
= intel_bufmgr_gem_init(spriv
->fd
, BATCH_SZ
);
752 if (intelScreen
->bufmgr
== NULL
) {
753 fprintf(stderr
, "[%s:%u] Error initializing buffer manager.\n",
758 if (!intel_get_param(spriv
, I915_PARAM_NUM_FENCES_AVAIL
, &num_fences
) ||
760 fprintf(stderr
, "[%s: %u] Kernel 2.6.29 required.\n", __func__
, __LINE__
);
764 drm_intel_bufmgr_gem_enable_fenced_relocs(intelScreen
->bufmgr
);
766 intelScreen
->named_regions
= _mesa_NewHashTable();
768 intelScreen
->relaxed_relocations
= 0;
769 intelScreen
->relaxed_relocations
|=
770 intel_get_boolean(spriv
, I915_PARAM_HAS_RELAXED_DELTA
) << 0;
776 * Override intel_screen.hw_has_separate_stencil with environment variable
777 * INTEL_SEPARATE_STENCIL.
779 * Valid values for INTEL_SEPARATE_STENCIL are "0" and "1". If an invalid
780 * valid value is encountered, a warning is emitted and INTEL_SEPARATE_STENCIL
784 intel_override_separate_stencil(struct intel_screen
*screen
)
786 const char *s
= getenv("INTEL_SEPARATE_STENCIL");
789 } else if (!strncmp("0", s
, 2)) {
790 screen
->hw_has_separate_stencil
= false;
791 } else if (!strncmp("1", s
, 2)) {
792 screen
->hw_has_separate_stencil
= true;
795 "warning: env variable INTEL_SEPARATE_STENCIL=\"%s\" has "
796 "invalid value and is ignored", s
);
801 intel_detect_swizzling(struct intel_screen
*screen
)
803 drm_intel_bo
*buffer
;
804 unsigned long flags
= 0;
805 unsigned long aligned_pitch
;
806 uint32_t tiling
= I915_TILING_X
;
807 uint32_t swizzle_mode
= 0;
809 buffer
= drm_intel_bo_alloc_tiled(screen
->bufmgr
, "swizzle test",
811 &tiling
, &aligned_pitch
, flags
);
815 drm_intel_bo_get_tiling(buffer
, &tiling
, &swizzle_mode
);
816 drm_intel_bo_unreference(buffer
);
818 if (swizzle_mode
== I915_BIT_6_SWIZZLE_NONE
)
825 intel_screen_make_configs(__DRIscreen
*dri_screen
)
827 static const GLenum back_buffer_modes
[] = {
828 GLX_NONE
, GLX_SWAP_UNDEFINED_OML
, GLX_SWAP_COPY_OML
833 uint8_t depth_bits
[4], stencil_bits
[4], msaa_samples_array
[1];
835 __DRIconfig
**configs
= NULL
;
837 msaa_samples_array
[0] = 0;
839 fb_format
[0] = GL_RGB
;
840 fb_type
[0] = GL_UNSIGNED_SHORT_5_6_5
;
842 fb_format
[1] = GL_BGR
;
843 fb_type
[1] = GL_UNSIGNED_INT_8_8_8_8_REV
;
845 fb_format
[2] = GL_BGRA
;
846 fb_type
[2] = GL_UNSIGNED_INT_8_8_8_8_REV
;
851 /* Generate a rich set of useful configs that do not include an
852 * accumulation buffer.
854 for (color
= 0; color
< ARRAY_SIZE(fb_format
); color
++) {
855 __DRIconfig
**new_configs
;
858 /* Starting with DRI2 protocol version 1.1 we can request a depth/stencil
859 * buffer that has a different number of bits per pixel than the color
860 * buffer. This isn't yet supported here.
862 if (fb_type
[color
] == GL_UNSIGNED_SHORT_5_6_5
) {
872 new_configs
= driCreateConfigs(fb_format
[color
], fb_type
[color
],
877 ARRAY_SIZE(back_buffer_modes
),
879 ARRAY_SIZE(msaa_samples_array
),
882 configs
= new_configs
;
884 configs
= driConcatConfigs(configs
, new_configs
);
887 /* Generate the minimum possible set of configs that include an
888 * accumulation buffer.
890 for (color
= 0; color
< ARRAY_SIZE(fb_format
); color
++) {
891 __DRIconfig
**new_configs
;
893 if (fb_type
[color
] == GL_UNSIGNED_SHORT_5_6_5
) {
901 new_configs
= driCreateConfigs(fb_format
[color
], fb_type
[color
],
902 depth_bits
, stencil_bits
, 1,
903 back_buffer_modes
+ 1, 1,
904 msaa_samples_array
, 1,
907 configs
= new_configs
;
909 configs
= driConcatConfigs(configs
, new_configs
);
912 if (configs
== NULL
) {
913 fprintf(stderr
, "[%s:%u] Error creating FBConfig!\n", __func__
,
922 * This is the driver specific part of the createNewScreen entry point.
923 * Called when using DRI2.
925 * \return the struct gl_config supported by this driver
928 __DRIconfig
**intelInitScreen2(__DRIscreen
*psp
)
930 struct intel_screen
*intelScreen
;
931 unsigned int api_mask
;
933 if (psp
->dri2
.loader
->base
.version
<= 2 ||
934 psp
->dri2
.loader
->getBuffersWithFormat
== NULL
) {
936 "\nERROR! DRI2 loader with getBuffersWithFormat() "
937 "support required\n");
941 /* Allocate the private area */
942 intelScreen
= CALLOC(sizeof *intelScreen
);
944 fprintf(stderr
, "\nERROR! Allocating private area failed\n");
947 /* parse information in __driConfigOptions */
948 driParseOptionInfo(&intelScreen
->optionCache
,
949 __driConfigOptions
, __driNConfigOptions
);
951 intelScreen
->driScrnPriv
= psp
;
952 psp
->driverPrivate
= (void *) intelScreen
;
954 if (!intel_init_bufmgr(intelScreen
))
957 intelScreen
->deviceID
= drm_intel_bufmgr_gem_get_devid(intelScreen
->bufmgr
);
959 intelScreen
->kernel_has_gen7_sol_reset
=
960 intel_get_boolean(intelScreen
->driScrnPriv
,
961 I915_PARAM_HAS_GEN7_SOL_RESET
);
963 if (IS_GEN7(intelScreen
->deviceID
)) {
964 intelScreen
->gen
= 7;
965 } else if (IS_GEN6(intelScreen
->deviceID
)) {
966 intelScreen
->gen
= 6;
967 } else if (IS_GEN5(intelScreen
->deviceID
)) {
968 intelScreen
->gen
= 5;
969 } else if (IS_965(intelScreen
->deviceID
)) {
970 intelScreen
->gen
= 4;
971 } else if (IS_9XX(intelScreen
->deviceID
)) {
972 intelScreen
->gen
= 3;
974 intelScreen
->gen
= 2;
977 intelScreen
->hw_has_separate_stencil
= intelScreen
->gen
>= 6;
978 intelScreen
->hw_must_use_separate_stencil
= intelScreen
->gen
>= 7;
981 bool success
= intel_get_param(intelScreen
->driScrnPriv
, I915_PARAM_HAS_LLC
,
983 if (success
&& has_llc
)
984 intelScreen
->hw_has_llc
= true;
985 else if (!success
&& intelScreen
->gen
>= 6)
986 intelScreen
->hw_has_llc
= true;
988 intel_override_separate_stencil(intelScreen
);
990 api_mask
= (1 << __DRI_API_OPENGL
);
992 api_mask
|= (1 << __DRI_API_GLES
);
995 api_mask
|= (1 << __DRI_API_GLES2
);
998 if (IS_9XX(intelScreen
->deviceID
) || IS_965(intelScreen
->deviceID
))
999 psp
->api_mask
= api_mask
;
1001 intelScreen
->hw_has_swizzling
= intel_detect_swizzling(intelScreen
);
1003 psp
->extensions
= intelScreenExtensions
;
1005 return (const __DRIconfig
**) intel_screen_make_configs(psp
);
1008 struct intel_buffer
{
1010 struct intel_region
*region
;
1013 static __DRIbuffer
*
1014 intelAllocateBuffer(__DRIscreen
*screen
,
1015 unsigned attachment
, unsigned format
,
1016 int width
, int height
)
1018 struct intel_buffer
*intelBuffer
;
1019 struct intel_screen
*intelScreen
= screen
->driverPrivate
;
1021 assert(attachment
== __DRI_BUFFER_FRONT_LEFT
||
1022 attachment
== __DRI_BUFFER_BACK_LEFT
);
1024 intelBuffer
= CALLOC(sizeof *intelBuffer
);
1025 if (intelBuffer
== NULL
)
1028 /* The front and back buffers are color buffers, which are X tiled. */
1029 intelBuffer
->region
= intel_region_alloc(intelScreen
,
1036 if (intelBuffer
->region
== NULL
) {
1041 intel_region_flink(intelBuffer
->region
, &intelBuffer
->base
.name
);
1043 intelBuffer
->base
.attachment
= attachment
;
1044 intelBuffer
->base
.cpp
= intelBuffer
->region
->cpp
;
1045 intelBuffer
->base
.pitch
=
1046 intelBuffer
->region
->pitch
* intelBuffer
->region
->cpp
;
1048 return &intelBuffer
->base
;
1052 intelReleaseBuffer(__DRIscreen
*screen
, __DRIbuffer
*buffer
)
1054 struct intel_buffer
*intelBuffer
= (struct intel_buffer
*) buffer
;
1056 intel_region_release(&intelBuffer
->region
);
1061 const struct __DriverAPIRec driDriverAPI
= {
1062 .InitScreen
= intelInitScreen2
,
1063 .DestroyScreen
= intelDestroyScreen
,
1064 .CreateContext
= intelCreateContext
,
1065 .DestroyContext
= intelDestroyContext
,
1066 .CreateBuffer
= intelCreateBuffer
,
1067 .DestroyBuffer
= intelDestroyBuffer
,
1068 .MakeCurrent
= intelMakeCurrent
,
1069 .UnbindContext
= intelUnbindContext
,
1070 .AllocateBuffer
= intelAllocateBuffer
,
1071 .ReleaseBuffer
= intelReleaseBuffer
1074 /* This is the table of extensions that the loader will dlsym() for. */
1075 PUBLIC
const __DRIextension
*__driDriverExtensions
[] = {
1076 &driCoreExtension
.base
,
1077 &driDRI2Extension
.base
,