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 intelDRI2Flush(__DRIdrawable
*drawable
)
155 GET_CURRENT_CONTEXT(ctx
);
156 struct intel_context
*intel
= intel_context(ctx
);
161 INTEL_FIREVERTICES(intel
);
163 intel
->need_throttle
= true;
165 if (intel
->batch
.used
)
166 intel_batchbuffer_flush(intel
);
168 if (INTEL_DEBUG
& DEBUG_AUB
) {
173 static const struct __DRI2flushExtensionRec intelFlushExtension
= {
174 { __DRI2_FLUSH
, __DRI2_FLUSH_VERSION
},
176 dri2InvalidateDrawable
,
180 intel_allocate_image(int dri_format
, void *loaderPrivate
)
184 image
= CALLOC(sizeof *image
);
188 image
->dri_format
= dri_format
;
191 switch (dri_format
) {
192 case __DRI_IMAGE_FORMAT_RGB565
:
193 image
->format
= MESA_FORMAT_RGB565
;
195 case __DRI_IMAGE_FORMAT_XRGB8888
:
196 image
->format
= MESA_FORMAT_XRGB8888
;
198 case __DRI_IMAGE_FORMAT_ARGB8888
:
199 image
->format
= MESA_FORMAT_ARGB8888
;
201 case __DRI_IMAGE_FORMAT_ABGR8888
:
202 image
->format
= MESA_FORMAT_RGBA8888_REV
;
204 case __DRI_IMAGE_FORMAT_XBGR8888
:
205 image
->format
= MESA_FORMAT_RGBX8888_REV
;
207 case __DRI_IMAGE_FORMAT_R8
:
208 image
->format
= MESA_FORMAT_R8
;
210 case __DRI_IMAGE_FORMAT_GR88
:
211 image
->format
= MESA_FORMAT_GR88
;
213 case __DRI_IMAGE_FORMAT_NONE
:
214 image
->format
= MESA_FORMAT_NONE
;
221 image
->internal_format
= _mesa_get_format_base_format(image
->format
);
222 image
->data
= loaderPrivate
;
228 intel_create_image_from_name(__DRIscreen
*screen
,
229 int width
, int height
, int format
,
230 int name
, int pitch
, void *loaderPrivate
)
232 struct intel_screen
*intelScreen
= screen
->driverPrivate
;
236 image
= intel_allocate_image(format
, loaderPrivate
);
237 if (image
->format
== MESA_FORMAT_NONE
)
240 cpp
= _mesa_get_format_bytes(image
->format
);
241 image
->region
= intel_region_alloc_for_handle(intelScreen
,
243 pitch
, name
, "image");
244 if (image
->region
== NULL
) {
253 intel_create_image_from_renderbuffer(__DRIcontext
*context
,
254 int renderbuffer
, void *loaderPrivate
)
257 struct intel_context
*intel
= context
->driverPrivate
;
258 struct gl_renderbuffer
*rb
;
259 struct intel_renderbuffer
*irb
;
261 rb
= _mesa_lookup_renderbuffer(&intel
->ctx
, renderbuffer
);
263 _mesa_error(&intel
->ctx
,
264 GL_INVALID_OPERATION
, "glRenderbufferExternalMESA");
268 irb
= intel_renderbuffer(rb
);
269 image
= CALLOC(sizeof *image
);
273 image
->internal_format
= rb
->InternalFormat
;
274 image
->format
= rb
->Format
;
276 image
->data
= loaderPrivate
;
277 intel_region_reference(&image
->region
, irb
->mt
->region
);
279 switch (image
->format
) {
280 case MESA_FORMAT_RGB565
:
281 image
->dri_format
= __DRI_IMAGE_FORMAT_RGB565
;
283 case MESA_FORMAT_XRGB8888
:
284 image
->dri_format
= __DRI_IMAGE_FORMAT_XRGB8888
;
286 case MESA_FORMAT_ARGB8888
:
287 image
->dri_format
= __DRI_IMAGE_FORMAT_ARGB8888
;
289 case MESA_FORMAT_RGBA8888_REV
:
290 image
->dri_format
= __DRI_IMAGE_FORMAT_ABGR8888
;
293 image
->dri_format
= __DRI_IMAGE_FORMAT_R8
;
295 case MESA_FORMAT_RG88
:
296 image
->dri_format
= __DRI_IMAGE_FORMAT_GR88
;
304 intel_destroy_image(__DRIimage
*image
)
306 intel_region_release(&image
->region
);
311 intel_create_image(__DRIscreen
*screen
,
312 int width
, int height
, int format
,
317 struct intel_screen
*intelScreen
= screen
->driverPrivate
;
321 tiling
= I915_TILING_X
;
322 if (use
& __DRI_IMAGE_USE_CURSOR
) {
323 if (width
!= 64 || height
!= 64)
325 tiling
= I915_TILING_NONE
;
328 /* We only support write for cursor drm images */
329 if ((use
& __DRI_IMAGE_USE_WRITE
) &&
330 use
!= (__DRI_IMAGE_USE_WRITE
| __DRI_IMAGE_USE_CURSOR
))
333 image
= intel_allocate_image(format
, loaderPrivate
);
335 cpp
= _mesa_get_format_bytes(image
->format
);
337 intel_region_alloc(intelScreen
, tiling
, cpp
, width
, height
, true);
338 if (image
->region
== NULL
) {
347 intel_query_image(__DRIimage
*image
, int attrib
, int *value
)
350 case __DRI_IMAGE_ATTRIB_STRIDE
:
351 *value
= image
->region
->pitch
* image
->region
->cpp
;
353 case __DRI_IMAGE_ATTRIB_HANDLE
:
354 *value
= image
->region
->bo
->handle
;
356 case __DRI_IMAGE_ATTRIB_NAME
:
357 return intel_region_flink(image
->region
, (uint32_t *) value
);
358 case __DRI_IMAGE_ATTRIB_FORMAT
:
359 *value
= image
->dri_format
;
361 case __DRI_IMAGE_ATTRIB_WIDTH
:
362 *value
= image
->region
->width
;
364 case __DRI_IMAGE_ATTRIB_HEIGHT
:
365 *value
= image
->region
->height
;
373 intel_dup_image(__DRIimage
*orig_image
, void *loaderPrivate
)
377 image
= CALLOC(sizeof *image
);
381 intel_region_reference(&image
->region
, orig_image
->region
);
382 if (image
->region
== NULL
) {
387 image
->internal_format
= orig_image
->internal_format
;
388 image
->usage
= orig_image
->usage
;
389 image
->dri_format
= orig_image
->dri_format
;
390 image
->format
= orig_image
->format
;
391 image
->offset
= orig_image
->offset
;
392 image
->data
= loaderPrivate
;
398 intel_validate_usage(__DRIimage
*image
, unsigned int use
)
400 if (use
& __DRI_IMAGE_USE_CURSOR
) {
401 if (image
->region
->width
!= 64 || image
->region
->height
!= 64)
405 /* We only support write for cursor drm images */
406 if ((use
& __DRI_IMAGE_USE_WRITE
) &&
407 use
!= (__DRI_IMAGE_USE_WRITE
| __DRI_IMAGE_USE_CURSOR
))
414 intel_image_write(__DRIimage
*image
, const void *buf
, size_t count
)
416 if (image
->region
->map_refcount
)
418 if (!(image
->usage
& __DRI_IMAGE_USE_WRITE
))
421 drm_intel_bo_map(image
->region
->bo
, true);
422 memcpy(image
->region
->bo
->virtual, buf
, count
);
423 drm_intel_bo_unmap(image
->region
->bo
);
429 intel_create_sub_image(__DRIimage
*parent
,
430 int width
, int height
, int dri_format
,
431 int offset
, int pitch
, void *loaderPrivate
)
435 uint32_t mask_x
, mask_y
;
437 image
= intel_allocate_image(dri_format
, loaderPrivate
);
438 cpp
= _mesa_get_format_bytes(image
->format
);
439 if (offset
+ height
* cpp
* pitch
> parent
->region
->bo
->size
) {
440 _mesa_warning(NULL
, "intel_create_sub_image: subimage out of bounds");
445 image
->region
= calloc(sizeof(*image
->region
), 1);
446 if (image
->region
== NULL
) {
451 image
->region
->cpp
= _mesa_get_format_bytes(image
->format
);
452 image
->region
->width
= width
;
453 image
->region
->height
= height
;
454 image
->region
->pitch
= pitch
;
455 image
->region
->refcount
= 1;
456 image
->region
->bo
= parent
->region
->bo
;
457 drm_intel_bo_reference(image
->region
->bo
);
458 image
->region
->tiling
= parent
->region
->tiling
;
459 image
->region
->screen
= parent
->region
->screen
;
460 image
->offset
= offset
;
462 intel_region_get_tile_masks(image
->region
, &mask_x
, &mask_y
);
465 "intel_create_sub_image: offset not on tile boundary");
470 static struct __DRIimageExtensionRec intelImageExtension
= {
472 intel_create_image_from_name
,
473 intel_create_image_from_renderbuffer
,
478 intel_validate_usage
,
480 intel_create_sub_image
483 static const __DRIextension
*intelScreenExtensions
[] = {
484 &intelTexBufferExtension
.base
,
485 &intelFlushExtension
.base
,
486 &intelImageExtension
.base
,
487 &dri2ConfigQueryExtension
.base
,
492 intel_get_param(__DRIscreen
*psp
, int param
, int *value
)
495 struct drm_i915_getparam gp
;
497 memset(&gp
, 0, sizeof(gp
));
501 ret
= drmCommandWriteRead(psp
->fd
, DRM_I915_GETPARAM
, &gp
, sizeof(gp
));
504 _mesa_warning(NULL
, "drm_i915_getparam: %d", ret
);
512 intel_get_boolean(__DRIscreen
*psp
, int param
)
515 return intel_get_param(psp
, param
, &value
) && value
;
519 nop_callback(GLuint key
, void *data
, void *userData
)
524 intelDestroyScreen(__DRIscreen
* sPriv
)
526 struct intel_screen
*intelScreen
= sPriv
->driverPrivate
;
528 dri_bufmgr_destroy(intelScreen
->bufmgr
);
529 driDestroyOptionInfo(&intelScreen
->optionCache
);
531 /* Some regions may still have references to them at this point, so
532 * flush the hash table to prevent _mesa_DeleteHashTable() from
533 * complaining about the hash not being empty; */
534 _mesa_HashDeleteAll(intelScreen
->named_regions
, nop_callback
, NULL
);
535 _mesa_DeleteHashTable(intelScreen
->named_regions
);
538 sPriv
->driverPrivate
= NULL
;
543 * This is called when we need to set up GL rendering to a new X window.
546 intelCreateBuffer(__DRIscreen
* driScrnPriv
,
547 __DRIdrawable
* driDrawPriv
,
548 const struct gl_config
* mesaVis
, GLboolean isPixmap
)
550 struct intel_renderbuffer
*rb
;
551 struct intel_screen
*screen
= (struct intel_screen
*) driScrnPriv
->driverPrivate
;
554 return false; /* not implemented */
559 struct gl_framebuffer
*fb
= CALLOC_STRUCT(gl_framebuffer
);
564 _mesa_initialize_window_framebuffer(fb
, mesaVis
);
566 if (mesaVis
->redBits
== 5)
567 rgbFormat
= MESA_FORMAT_RGB565
;
568 else if (mesaVis
->alphaBits
== 0)
569 rgbFormat
= MESA_FORMAT_XRGB8888
;
571 rgbFormat
= MESA_FORMAT_ARGB8888
;
573 /* setup the hardware-based renderbuffers */
574 rb
= intel_create_renderbuffer(rgbFormat
);
575 _mesa_add_renderbuffer(fb
, BUFFER_FRONT_LEFT
, &rb
->Base
.Base
);
577 if (mesaVis
->doubleBufferMode
) {
578 rb
= intel_create_renderbuffer(rgbFormat
);
579 _mesa_add_renderbuffer(fb
, BUFFER_BACK_LEFT
, &rb
->Base
.Base
);
583 * Assert here that the gl_config has an expected depth/stencil bit
584 * combination: one of d24/s8, d16/s0, d0/s0. (See intelInitScreen2(),
585 * which constructs the advertised configs.)
587 if (mesaVis
->depthBits
== 24) {
588 assert(mesaVis
->stencilBits
== 8);
590 if (screen
->hw_has_separate_stencil
) {
591 rb
= intel_create_private_renderbuffer(MESA_FORMAT_X8_Z24
);
592 _mesa_add_renderbuffer(fb
, BUFFER_DEPTH
, &rb
->Base
.Base
);
593 rb
= intel_create_private_renderbuffer(MESA_FORMAT_S8
);
594 _mesa_add_renderbuffer(fb
, BUFFER_STENCIL
, &rb
->Base
.Base
);
597 * Use combined depth/stencil. Note that the renderbuffer is
598 * attached to two attachment points.
600 rb
= intel_create_private_renderbuffer(MESA_FORMAT_S8_Z24
);
601 _mesa_add_renderbuffer(fb
, BUFFER_DEPTH
, &rb
->Base
.Base
);
602 _mesa_add_renderbuffer(fb
, BUFFER_STENCIL
, &rb
->Base
.Base
);
605 else if (mesaVis
->depthBits
== 16) {
606 assert(mesaVis
->stencilBits
== 0);
607 /* just 16-bit depth buffer, no hw stencil */
608 struct intel_renderbuffer
*depthRb
609 = intel_create_private_renderbuffer(MESA_FORMAT_Z16
);
610 _mesa_add_renderbuffer(fb
, BUFFER_DEPTH
, &depthRb
->Base
.Base
);
613 assert(mesaVis
->depthBits
== 0);
614 assert(mesaVis
->stencilBits
== 0);
617 /* now add any/all software-based renderbuffers we may need */
618 _swrast_add_soft_renderbuffers(fb
,
619 false, /* never sw color */
620 false, /* never sw depth */
621 false, /* never sw stencil */
622 mesaVis
->accumRedBits
> 0,
623 false, /* never sw alpha */
624 false /* never sw aux */ );
625 driDrawPriv
->driverPrivate
= fb
;
632 intelDestroyBuffer(__DRIdrawable
* driDrawPriv
)
634 struct gl_framebuffer
*fb
= driDrawPriv
->driverPrivate
;
636 _mesa_reference_framebuffer(&fb
, NULL
);
639 /* There are probably better ways to do this, such as an
640 * init-designated function to register chipids and createcontext
644 i830CreateContext(const struct gl_config
*mesaVis
,
645 __DRIcontext
*driContextPriv
,
646 void *sharedContextPrivate
);
649 i915CreateContext(int api
,
650 const struct gl_config
*mesaVis
,
651 __DRIcontext
*driContextPriv
,
652 void *sharedContextPrivate
);
654 brwCreateContext(int api
,
655 const struct gl_config
*mesaVis
,
656 __DRIcontext
*driContextPriv
,
657 void *sharedContextPrivate
);
660 intelCreateContext(gl_api api
,
661 const struct gl_config
* mesaVis
,
662 __DRIcontext
* driContextPriv
,
663 unsigned major_version
,
664 unsigned minor_version
,
667 void *sharedContextPrivate
)
669 __DRIscreen
*sPriv
= driContextPriv
->driScreenPriv
;
670 struct intel_screen
*intelScreen
= sPriv
->driverPrivate
;
671 bool success
= false;
674 if (IS_9XX(intelScreen
->deviceID
)) {
675 if (!IS_965(intelScreen
->deviceID
)) {
676 success
= i915CreateContext(api
, mesaVis
, driContextPriv
,
677 sharedContextPrivate
);
680 intelScreen
->no_vbo
= true;
681 success
= i830CreateContext(mesaVis
, driContextPriv
,
682 sharedContextPrivate
);
685 if (IS_965(intelScreen
->deviceID
))
686 success
= brwCreateContext(api
, mesaVis
,
688 sharedContextPrivate
);
692 struct gl_context
*ctx
=
693 (struct gl_context
*) driContextPriv
->driverPrivate
;
695 _mesa_compute_version(ctx
);
696 if (ctx
->VersionMajor
> major_version
697 || (ctx
->VersionMajor
== major_version
698 && ctx
->VersionMinor
>= minor_version
)) {
702 *error
= __DRI_CTX_ERROR_BAD_VERSION
;
703 intelDestroyContext(driContextPriv
);
705 *error
= __DRI_CTX_ERROR_NO_MEMORY
;
706 fprintf(stderr
, "Unrecognized deviceID 0x%x\n", intelScreen
->deviceID
);
713 intel_init_bufmgr(struct intel_screen
*intelScreen
)
715 __DRIscreen
*spriv
= intelScreen
->driScrnPriv
;
718 intelScreen
->no_hw
= getenv("INTEL_NO_HW") != NULL
;
720 intelScreen
->bufmgr
= intel_bufmgr_gem_init(spriv
->fd
, BATCH_SZ
);
721 if (intelScreen
->bufmgr
== NULL
) {
722 fprintf(stderr
, "[%s:%u] Error initializing buffer manager.\n",
727 if (!intel_get_param(spriv
, I915_PARAM_NUM_FENCES_AVAIL
, &num_fences
) ||
729 fprintf(stderr
, "[%s: %u] Kernel 2.6.29 required.\n", __func__
, __LINE__
);
733 drm_intel_bufmgr_gem_enable_fenced_relocs(intelScreen
->bufmgr
);
735 intelScreen
->named_regions
= _mesa_NewHashTable();
737 intelScreen
->relaxed_relocations
= 0;
738 intelScreen
->relaxed_relocations
|=
739 intel_get_boolean(spriv
, I915_PARAM_HAS_RELAXED_DELTA
) << 0;
745 * Override intel_screen.hw_has_separate_stencil with environment variable
746 * INTEL_SEPARATE_STENCIL.
748 * Valid values for INTEL_SEPARATE_STENCIL are "0" and "1". If an invalid
749 * valid value is encountered, a warning is emitted and INTEL_SEPARATE_STENCIL
753 intel_override_separate_stencil(struct intel_screen
*screen
)
755 const char *s
= getenv("INTEL_SEPARATE_STENCIL");
758 } else if (!strncmp("0", s
, 2)) {
759 screen
->hw_has_separate_stencil
= false;
760 } else if (!strncmp("1", s
, 2)) {
761 screen
->hw_has_separate_stencil
= true;
764 "warning: env variable INTEL_SEPARATE_STENCIL=\"%s\" has "
765 "invalid value and is ignored", s
);
770 intel_detect_swizzling(struct intel_screen
*screen
)
772 drm_intel_bo
*buffer
;
773 unsigned long flags
= 0;
774 unsigned long aligned_pitch
;
775 uint32_t tiling
= I915_TILING_X
;
776 uint32_t swizzle_mode
= 0;
778 buffer
= drm_intel_bo_alloc_tiled(screen
->bufmgr
, "swizzle test",
780 &tiling
, &aligned_pitch
, flags
);
784 drm_intel_bo_get_tiling(buffer
, &tiling
, &swizzle_mode
);
785 drm_intel_bo_unreference(buffer
);
787 if (swizzle_mode
== I915_BIT_6_SWIZZLE_NONE
)
794 * This is the driver specific part of the createNewScreen entry point.
795 * Called when using DRI2.
797 * \return the struct gl_config supported by this driver
800 __DRIconfig
**intelInitScreen2(__DRIscreen
*psp
)
802 struct intel_screen
*intelScreen
;
805 unsigned int api_mask
;
807 static const GLenum back_buffer_modes
[] = {
808 GLX_NONE
, GLX_SWAP_UNDEFINED_OML
, GLX_SWAP_COPY_OML
810 uint8_t depth_bits
[4], stencil_bits
[4], msaa_samples_array
[1];
812 __DRIconfig
**configs
= NULL
;
814 if (psp
->dri2
.loader
->base
.version
<= 2 ||
815 psp
->dri2
.loader
->getBuffersWithFormat
== NULL
) {
817 "\nERROR! DRI2 loader with getBuffersWithFormat() "
818 "support required\n");
822 /* Allocate the private area */
823 intelScreen
= CALLOC(sizeof *intelScreen
);
825 fprintf(stderr
, "\nERROR! Allocating private area failed\n");
828 /* parse information in __driConfigOptions */
829 driParseOptionInfo(&intelScreen
->optionCache
,
830 __driConfigOptions
, __driNConfigOptions
);
832 intelScreen
->driScrnPriv
= psp
;
833 psp
->driverPrivate
= (void *) intelScreen
;
835 if (!intel_init_bufmgr(intelScreen
))
838 intelScreen
->deviceID
= drm_intel_bufmgr_gem_get_devid(intelScreen
->bufmgr
);
840 intelScreen
->kernel_has_gen7_sol_reset
=
841 intel_get_boolean(intelScreen
->driScrnPriv
,
842 I915_PARAM_HAS_GEN7_SOL_RESET
);
844 if (IS_GEN7(intelScreen
->deviceID
)) {
845 intelScreen
->gen
= 7;
846 } else if (IS_GEN6(intelScreen
->deviceID
)) {
847 intelScreen
->gen
= 6;
848 } else if (IS_GEN5(intelScreen
->deviceID
)) {
849 intelScreen
->gen
= 5;
850 } else if (IS_965(intelScreen
->deviceID
)) {
851 intelScreen
->gen
= 4;
852 } else if (IS_9XX(intelScreen
->deviceID
)) {
853 intelScreen
->gen
= 3;
855 intelScreen
->gen
= 2;
858 intelScreen
->hw_has_separate_stencil
= intelScreen
->gen
>= 6;
859 intelScreen
->hw_must_use_separate_stencil
= intelScreen
->gen
>= 7;
862 bool success
= intel_get_param(intelScreen
->driScrnPriv
, I915_PARAM_HAS_LLC
,
864 if (success
&& has_llc
)
865 intelScreen
->hw_has_llc
= true;
866 else if (!success
&& intelScreen
->gen
>= 6)
867 intelScreen
->hw_has_llc
= true;
869 intel_override_separate_stencil(intelScreen
);
871 api_mask
= (1 << __DRI_API_OPENGL
);
873 api_mask
|= (1 << __DRI_API_GLES
);
876 api_mask
|= (1 << __DRI_API_GLES2
);
879 if (IS_9XX(intelScreen
->deviceID
) || IS_965(intelScreen
->deviceID
))
880 psp
->api_mask
= api_mask
;
882 intelScreen
->hw_has_swizzling
= intel_detect_swizzling(intelScreen
);
884 psp
->extensions
= intelScreenExtensions
;
886 msaa_samples_array
[0] = 0;
888 fb_format
[0] = GL_RGB
;
889 fb_type
[0] = GL_UNSIGNED_SHORT_5_6_5
;
891 fb_format
[1] = GL_BGR
;
892 fb_type
[1] = GL_UNSIGNED_INT_8_8_8_8_REV
;
894 fb_format
[2] = GL_BGRA
;
895 fb_type
[2] = GL_UNSIGNED_INT_8_8_8_8_REV
;
900 /* Generate a rich set of useful configs that do not include an
901 * accumulation buffer.
903 for (color
= 0; color
< ARRAY_SIZE(fb_format
); color
++) {
904 __DRIconfig
**new_configs
;
907 /* Starting with DRI2 protocol version 1.1 we can request a depth/stencil
908 * buffer that has a diffferent number of bits per pixel than the color
909 * buffer. This isn't yet supported here.
911 if (fb_type
[color
] == GL_UNSIGNED_SHORT_5_6_5
) {
921 new_configs
= driCreateConfigs(fb_format
[color
], fb_type
[color
],
926 ARRAY_SIZE(back_buffer_modes
),
928 ARRAY_SIZE(msaa_samples_array
),
931 configs
= new_configs
;
933 configs
= driConcatConfigs(configs
, new_configs
);
936 /* Generate the minimum possible set of configs that include an
937 * accumulation buffer.
939 for (color
= 0; color
< ARRAY_SIZE(fb_format
); color
++) {
940 __DRIconfig
**new_configs
;
942 if (fb_type
[color
] == GL_UNSIGNED_SHORT_5_6_5
) {
950 new_configs
= driCreateConfigs(fb_format
[color
], fb_type
[color
],
951 depth_bits
, stencil_bits
, 1,
952 back_buffer_modes
+ 1, 1,
953 msaa_samples_array
, 1,
956 configs
= new_configs
;
958 configs
= driConcatConfigs(configs
, new_configs
);
961 if (configs
== NULL
) {
962 fprintf(stderr
, "[%s:%u] Error creating FBConfig!\n", __func__
,
967 return (const __DRIconfig
**)configs
;
970 struct intel_buffer
{
972 struct intel_region
*region
;
976 * \brief Get tiling format for a DRI buffer.
978 * \param attachment is the buffer's attachmet point, such as
979 * __DRI_BUFFER_DEPTH.
980 * \param out_tiling is the returned tiling format for buffer.
981 * \return false if attachment is unrecognized or is incompatible with screen.
984 intel_get_dri_buffer_tiling(struct intel_screen
*screen
,
986 uint32_t *out_tiling
)
988 if (screen
->gen
< 4) {
989 *out_tiling
= I915_TILING_X
;
993 switch (attachment
) {
994 case __DRI_BUFFER_DEPTH
:
995 case __DRI_BUFFER_DEPTH_STENCIL
:
996 case __DRI_BUFFER_HIZ
:
997 *out_tiling
= I915_TILING_Y
;
999 case __DRI_BUFFER_ACCUM
:
1000 case __DRI_BUFFER_FRONT_LEFT
:
1001 case __DRI_BUFFER_FRONT_RIGHT
:
1002 case __DRI_BUFFER_BACK_LEFT
:
1003 case __DRI_BUFFER_BACK_RIGHT
:
1004 case __DRI_BUFFER_FAKE_FRONT_LEFT
:
1005 case __DRI_BUFFER_FAKE_FRONT_RIGHT
:
1006 *out_tiling
= I915_TILING_X
;
1008 case __DRI_BUFFER_STENCIL
:
1009 /* The stencil buffer is W tiled. However, we request from the kernel
1010 * a non-tiled buffer because the GTT is incapable of W fencing.
1012 *out_tiling
= I915_TILING_NONE
;
1015 if(unlikely(INTEL_DEBUG
& DEBUG_DRI
)) {
1016 fprintf(stderr
, "error: %s: unrecognized DRI buffer attachment 0x%x\n",
1017 __FUNCTION__
, attachment
);
1023 static __DRIbuffer
*
1024 intelAllocateBuffer(__DRIscreen
*screen
,
1025 unsigned attachment
, unsigned format
,
1026 int width
, int height
)
1028 struct intel_buffer
*intelBuffer
;
1029 struct intel_screen
*intelScreen
= screen
->driverPrivate
;
1032 uint32_t region_width
;
1033 uint32_t region_height
;
1034 uint32_t region_cpp
;
1038 ok
= intel_get_dri_buffer_tiling(intelScreen
, attachment
, &tiling
);
1042 intelBuffer
= CALLOC(sizeof *intelBuffer
);
1043 if (intelBuffer
== NULL
)
1046 if (attachment
== __DRI_BUFFER_STENCIL
) {
1047 /* Stencil buffers use W tiling, a tiling format that the DRM functions
1048 * don't properly account for. Therefore, when we allocate a stencil
1049 * buffer that is private to Mesa (see intel_miptree_create), we round
1050 * the height and width up to the next multiple of the tile size (64x64)
1051 * and then ask DRM to allocate an untiled buffer. Consequently, the
1052 * height and the width stored in the stencil buffer's region structure
1053 * are always multiples of 64, even if the stencil buffer itself is
1056 * To avoid inconsistencies between how we represent private buffers and
1057 * buffers shared with the window system, round up the height and width
1058 * for window system buffers too.
1060 region_width
= ALIGN(width
, 64);
1061 region_height
= ALIGN(height
, 64);
1063 region_width
= width
;
1064 region_height
= height
;
1067 region_cpp
= format
/ 8;
1069 intelBuffer
->region
= intel_region_alloc(intelScreen
,
1076 if (intelBuffer
->region
== NULL
) {
1081 intel_region_flink(intelBuffer
->region
, &intelBuffer
->base
.name
);
1083 intelBuffer
->base
.attachment
= attachment
;
1084 intelBuffer
->base
.cpp
= intelBuffer
->region
->cpp
;
1085 intelBuffer
->base
.pitch
=
1086 intelBuffer
->region
->pitch
* intelBuffer
->region
->cpp
;
1088 return &intelBuffer
->base
;
1092 intelReleaseBuffer(__DRIscreen
*screen
, __DRIbuffer
*buffer
)
1094 struct intel_buffer
*intelBuffer
= (struct intel_buffer
*) buffer
;
1096 intel_region_release(&intelBuffer
->region
);
1101 const struct __DriverAPIRec driDriverAPI
= {
1102 .InitScreen
= intelInitScreen2
,
1103 .DestroyScreen
= intelDestroyScreen
,
1104 .CreateContext
= intelCreateContext
,
1105 .DestroyContext
= intelDestroyContext
,
1106 .CreateBuffer
= intelCreateBuffer
,
1107 .DestroyBuffer
= intelDestroyBuffer
,
1108 .MakeCurrent
= intelMakeCurrent
,
1109 .UnbindContext
= intelUnbindContext
,
1110 .AllocateBuffer
= intelAllocateBuffer
,
1111 .ReleaseBuffer
= intelReleaseBuffer
1114 /* This is the table of extensions that the loader will dlsym() for. */
1115 PUBLIC
const __DRIextension
*__driDriverExtensions
[] = {
1116 &driCoreExtension
.base
,
1117 &driDRI2Extension
.base
,