1 /**************************************************************************
3 * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 **************************************************************************/
29 #include "main/glheader.h"
30 #include "main/context.h"
31 #include "main/framebuffer.h"
32 #include "main/renderbuffer.h"
33 #include "main/hash.h"
34 #include "main/fbobject.h"
35 #include "main/mfeatures.h"
36 #include "main/version.h"
37 #include "swrast/s_renderbuffer.h"
42 PUBLIC
const char __driConfigOptions
[] =
44 DRI_CONF_SECTION_PERFORMANCE
45 DRI_CONF_VBLANK_MODE(DRI_CONF_VBLANK_ALWAYS_SYNC
)
46 /* Options correspond to DRI_CONF_BO_REUSE_DISABLED,
47 * DRI_CONF_BO_REUSE_ALL
49 DRI_CONF_OPT_BEGIN_V(bo_reuse
, enum, 1, "0:1")
50 DRI_CONF_DESC_BEGIN(en
, "Buffer object reuse")
51 DRI_CONF_ENUM(0, "Disable buffer object reuse")
52 DRI_CONF_ENUM(1, "Enable reuse of all sizes of buffer objects")
56 DRI_CONF_OPT_BEGIN(texture_tiling
, bool, true)
57 DRI_CONF_DESC(en
, "Enable texture tiling")
60 DRI_CONF_OPT_BEGIN(hiz
, bool, true)
61 DRI_CONF_DESC(en
, "Enable Hierarchical Z on gen6+")
64 DRI_CONF_OPT_BEGIN(early_z
, bool, false)
65 DRI_CONF_DESC(en
, "Enable early Z in classic mode (unstable, 945-only).")
68 DRI_CONF_OPT_BEGIN(fragment_shader
, bool, true)
69 DRI_CONF_DESC(en
, "Enable limited ARB_fragment_shader support on 915/945.")
73 DRI_CONF_SECTION_QUALITY
74 DRI_CONF_FORCE_S3TC_ENABLE(false)
75 DRI_CONF_ALLOW_LARGE_TEXTURES(2)
77 DRI_CONF_SECTION_DEBUG
78 DRI_CONF_NO_RAST(false)
79 DRI_CONF_ALWAYS_FLUSH_BATCH(false)
80 DRI_CONF_ALWAYS_FLUSH_CACHE(false)
81 DRI_CONF_FORCE_GLSL_EXTENSIONS_WARN(false)
83 DRI_CONF_OPT_BEGIN(stub_occlusion_query
, bool, false)
84 DRI_CONF_DESC(en
, "Enable stub ARB_occlusion_query support on 915/945.")
87 DRI_CONF_OPT_BEGIN(shader_precompile
, bool, false)
88 DRI_CONF_DESC(en
, "Perform code generation at shader link time.")
93 const GLuint __driNConfigOptions
= 14;
95 #include "intel_batchbuffer.h"
96 #include "intel_buffers.h"
97 #include "intel_bufmgr.h"
98 #include "intel_chipset.h"
99 #include "intel_fbo.h"
100 #include "intel_mipmap_tree.h"
101 #include "intel_screen.h"
102 #include "intel_tex.h"
103 #include "intel_regions.h"
105 #include "i915_drm.h"
107 #ifdef USE_NEW_INTERFACE
108 static PFNGLXCREATECONTEXTMODES create_context_modes
= NULL
;
109 #endif /*USE_NEW_INTERFACE */
112 aub_dump_bmp(struct gl_context
*ctx
)
114 struct gl_framebuffer
*fb
= ctx
->DrawBuffer
;
116 for (int i
= 0; i
< fb
->_NumColorDrawBuffers
; i
++) {
117 struct intel_renderbuffer
*irb
=
118 intel_renderbuffer(fb
->_ColorDrawBuffers
[i
]);
120 if (irb
&& irb
->mt
) {
121 enum aub_dump_bmp_format format
;
123 switch (irb
->Base
.Base
.Format
) {
124 case MESA_FORMAT_ARGB8888
:
125 case MESA_FORMAT_XRGB8888
:
126 format
= AUB_DUMP_BMP_FORMAT_ARGB_8888
;
132 drm_intel_gem_bo_aub_dump_bmp(irb
->mt
->region
->bo
,
135 irb
->Base
.Base
.Width
,
136 irb
->Base
.Base
.Height
,
138 irb
->mt
->region
->pitch
*
139 irb
->mt
->region
->cpp
,
145 static const __DRItexBufferExtension intelTexBufferExtension
= {
146 { __DRI_TEX_BUFFER
, __DRI_TEX_BUFFER_VERSION
},
152 intelDRI2Flush(__DRIdrawable
*drawable
)
154 GET_CURRENT_CONTEXT(ctx
);
155 struct intel_context
*intel
= intel_context(ctx
);
160 INTEL_FIREVERTICES(intel
);
162 intel
->need_throttle
= true;
164 if (intel
->batch
.used
)
165 intel_batchbuffer_flush(intel
);
167 if (INTEL_DEBUG
& DEBUG_AUB
) {
172 static const struct __DRI2flushExtensionRec intelFlushExtension
= {
173 { __DRI2_FLUSH
, __DRI2_FLUSH_VERSION
},
175 dri2InvalidateDrawable
,
179 intel_create_image_from_name(__DRIscreen
*screen
,
180 int width
, int height
, int format
,
181 int name
, int pitch
, void *loaderPrivate
)
183 struct intel_screen
*intelScreen
= screen
->driverPrivate
;
187 image
= CALLOC(sizeof *image
);
191 image
->dri_format
= format
;
194 case __DRI_IMAGE_FORMAT_RGB565
:
195 image
->format
= MESA_FORMAT_RGB565
;
196 image
->internal_format
= GL_RGB
;
197 image
->data_type
= GL_UNSIGNED_BYTE
;
199 case __DRI_IMAGE_FORMAT_XRGB8888
:
200 image
->format
= MESA_FORMAT_XRGB8888
;
201 image
->internal_format
= GL_RGB
;
202 image
->data_type
= GL_UNSIGNED_BYTE
;
204 case __DRI_IMAGE_FORMAT_ARGB8888
:
205 image
->format
= MESA_FORMAT_ARGB8888
;
206 image
->internal_format
= GL_RGBA
;
207 image
->data_type
= GL_UNSIGNED_BYTE
;
209 case __DRI_IMAGE_FORMAT_ABGR8888
:
210 image
->format
= MESA_FORMAT_RGBA8888_REV
;
211 image
->internal_format
= GL_RGBA
;
212 image
->data_type
= GL_UNSIGNED_BYTE
;
214 case __DRI_IMAGE_FORMAT_XBGR8888
:
215 image
->format
= MESA_FORMAT_RGBX8888_REV
;
216 image
->internal_format
= GL_RGB
;
217 image
->data_type
= GL_UNSIGNED_BYTE
;
224 image
->data
= loaderPrivate
;
225 cpp
= _mesa_get_format_bytes(image
->format
);
227 image
->region
= intel_region_alloc_for_handle(intelScreen
,
229 pitch
, name
, "image");
230 if (image
->region
== NULL
) {
239 intel_create_image_from_renderbuffer(__DRIcontext
*context
,
240 int renderbuffer
, void *loaderPrivate
)
243 struct intel_context
*intel
= context
->driverPrivate
;
244 struct gl_renderbuffer
*rb
;
245 struct intel_renderbuffer
*irb
;
247 rb
= _mesa_lookup_renderbuffer(&intel
->ctx
, renderbuffer
);
249 _mesa_error(&intel
->ctx
,
250 GL_INVALID_OPERATION
, "glRenderbufferExternalMESA");
254 irb
= intel_renderbuffer(rb
);
255 image
= CALLOC(sizeof *image
);
259 image
->internal_format
= rb
->InternalFormat
;
260 image
->format
= rb
->Format
;
261 image
->data_type
= GL_UNSIGNED_BYTE
;
262 image
->data
= loaderPrivate
;
263 intel_region_reference(&image
->region
, irb
->mt
->region
);
265 switch (image
->format
) {
266 case MESA_FORMAT_RGB565
:
267 image
->dri_format
= __DRI_IMAGE_FORMAT_RGB565
;
269 case MESA_FORMAT_XRGB8888
:
270 image
->dri_format
= __DRI_IMAGE_FORMAT_XRGB8888
;
272 case MESA_FORMAT_ARGB8888
:
273 image
->dri_format
= __DRI_IMAGE_FORMAT_ARGB8888
;
275 case MESA_FORMAT_RGBA8888_REV
:
276 image
->dri_format
= __DRI_IMAGE_FORMAT_ABGR8888
;
284 intel_destroy_image(__DRIimage
*image
)
286 intel_region_release(&image
->region
);
291 intel_create_image(__DRIscreen
*screen
,
292 int width
, int height
, int format
,
297 struct intel_screen
*intelScreen
= screen
->driverPrivate
;
301 tiling
= I915_TILING_X
;
302 if (use
& __DRI_IMAGE_USE_CURSOR
) {
303 if (width
!= 64 || height
!= 64)
305 tiling
= I915_TILING_NONE
;
308 image
= CALLOC(sizeof *image
);
312 image
->dri_format
= format
;
315 case __DRI_IMAGE_FORMAT_RGB565
:
316 image
->format
= MESA_FORMAT_RGB565
;
317 image
->internal_format
= GL_RGB
;
318 image
->data_type
= GL_UNSIGNED_BYTE
;
320 case __DRI_IMAGE_FORMAT_XRGB8888
:
321 image
->format
= MESA_FORMAT_XRGB8888
;
322 image
->internal_format
= GL_RGB
;
323 image
->data_type
= GL_UNSIGNED_BYTE
;
325 case __DRI_IMAGE_FORMAT_ARGB8888
:
326 image
->format
= MESA_FORMAT_ARGB8888
;
327 image
->internal_format
= GL_RGBA
;
328 image
->data_type
= GL_UNSIGNED_BYTE
;
330 case __DRI_IMAGE_FORMAT_ABGR8888
:
331 image
->format
= MESA_FORMAT_RGBA8888_REV
;
332 image
->internal_format
= GL_RGBA
;
333 image
->data_type
= GL_UNSIGNED_BYTE
;
335 case __DRI_IMAGE_FORMAT_XBGR8888
:
336 image
->format
= MESA_FORMAT_RGBX8888_REV
;
337 image
->internal_format
= GL_RGB
;
338 image
->data_type
= GL_UNSIGNED_BYTE
;
345 image
->data
= loaderPrivate
;
346 cpp
= _mesa_get_format_bytes(image
->format
);
349 intel_region_alloc(intelScreen
, tiling
,
350 cpp
, width
, height
, true);
351 if (image
->region
== NULL
) {
360 intel_query_image(__DRIimage
*image
, int attrib
, int *value
)
363 case __DRI_IMAGE_ATTRIB_STRIDE
:
364 *value
= image
->region
->pitch
* image
->region
->cpp
;
366 case __DRI_IMAGE_ATTRIB_HANDLE
:
367 *value
= image
->region
->bo
->handle
;
369 case __DRI_IMAGE_ATTRIB_NAME
:
370 return intel_region_flink(image
->region
, (uint32_t *) value
);
371 case __DRI_IMAGE_ATTRIB_FORMAT
:
372 *value
= image
->dri_format
;
380 intel_dup_image(__DRIimage
*orig_image
, void *loaderPrivate
)
384 image
= CALLOC(sizeof *image
);
388 intel_region_reference(&image
->region
, orig_image
->region
);
389 if (image
->region
== NULL
) {
394 image
->internal_format
= orig_image
->internal_format
;
395 image
->dri_format
= orig_image
->dri_format
;
396 image
->format
= orig_image
->format
;
397 image
->data_type
= orig_image
->data_type
;
398 image
->data
= loaderPrivate
;
404 intel_validate_usage(__DRIimage
*image
, unsigned int use
)
406 if (use
& __DRI_IMAGE_USE_CURSOR
) {
407 if (image
->region
->width
!= 64 || image
->region
->height
!= 64)
414 static struct __DRIimageExtensionRec intelImageExtension
= {
416 intel_create_image_from_name
,
417 intel_create_image_from_renderbuffer
,
425 static const __DRIextension
*intelScreenExtensions
[] = {
426 &intelTexBufferExtension
.base
,
427 &intelFlushExtension
.base
,
428 &intelImageExtension
.base
,
429 &dri2ConfigQueryExtension
.base
,
434 intel_get_param(__DRIscreen
*psp
, int param
, int *value
)
437 struct drm_i915_getparam gp
;
439 memset(&gp
, 0, sizeof(gp
));
443 ret
= drmCommandWriteRead(psp
->fd
, DRM_I915_GETPARAM
, &gp
, sizeof(gp
));
446 _mesa_warning(NULL
, "drm_i915_getparam: %d", ret
);
454 intel_get_boolean(__DRIscreen
*psp
, int param
)
457 return intel_get_param(psp
, param
, &value
) && value
;
461 nop_callback(GLuint key
, void *data
, void *userData
)
466 intelDestroyScreen(__DRIscreen
* sPriv
)
468 struct intel_screen
*intelScreen
= sPriv
->driverPrivate
;
470 dri_bufmgr_destroy(intelScreen
->bufmgr
);
471 driDestroyOptionInfo(&intelScreen
->optionCache
);
473 /* Some regions may still have references to them at this point, so
474 * flush the hash table to prevent _mesa_DeleteHashTable() from
475 * complaining about the hash not being empty; */
476 _mesa_HashDeleteAll(intelScreen
->named_regions
, nop_callback
, NULL
);
477 _mesa_DeleteHashTable(intelScreen
->named_regions
);
480 sPriv
->driverPrivate
= NULL
;
485 * This is called when we need to set up GL rendering to a new X window.
488 intelCreateBuffer(__DRIscreen
* driScrnPriv
,
489 __DRIdrawable
* driDrawPriv
,
490 const struct gl_config
* mesaVis
, GLboolean isPixmap
)
492 struct intel_renderbuffer
*rb
;
493 struct intel_screen
*screen
= (struct intel_screen
*) driScrnPriv
->driverPrivate
;
496 return false; /* not implemented */
501 struct gl_framebuffer
*fb
= CALLOC_STRUCT(gl_framebuffer
);
506 _mesa_initialize_window_framebuffer(fb
, mesaVis
);
508 if (mesaVis
->redBits
== 5)
509 rgbFormat
= MESA_FORMAT_RGB565
;
510 else if (mesaVis
->alphaBits
== 0)
511 rgbFormat
= MESA_FORMAT_XRGB8888
;
513 rgbFormat
= MESA_FORMAT_ARGB8888
;
515 /* setup the hardware-based renderbuffers */
516 rb
= intel_create_renderbuffer(rgbFormat
);
517 _mesa_add_renderbuffer(fb
, BUFFER_FRONT_LEFT
, &rb
->Base
.Base
);
519 if (mesaVis
->doubleBufferMode
) {
520 rb
= intel_create_renderbuffer(rgbFormat
);
521 _mesa_add_renderbuffer(fb
, BUFFER_BACK_LEFT
, &rb
->Base
.Base
);
525 * Assert here that the gl_config has an expected depth/stencil bit
526 * combination: one of d24/s8, d16/s0, d0/s0. (See intelInitScreen2(),
527 * which constructs the advertised configs.)
529 if (mesaVis
->depthBits
== 24) {
530 assert(mesaVis
->stencilBits
== 8);
532 if (screen
->hw_has_separate_stencil
533 && screen
->dri2_has_hiz
!= INTEL_DRI2_HAS_HIZ_FALSE
) {
535 * Request a separate stencil buffer even if we do not yet know if
536 * the screen supports it. (See comments for
537 * enum intel_dri2_has_hiz).
539 rb
= intel_create_renderbuffer(MESA_FORMAT_X8_Z24
);
540 _mesa_add_renderbuffer(fb
, BUFFER_DEPTH
, &rb
->Base
.Base
);
541 rb
= intel_create_renderbuffer(MESA_FORMAT_S8
);
542 _mesa_add_renderbuffer(fb
, BUFFER_STENCIL
, &rb
->Base
.Base
);
545 * Use combined depth/stencil. Note that the renderbuffer is
546 * attached to two attachment points.
548 rb
= intel_create_renderbuffer(MESA_FORMAT_S8_Z24
);
549 _mesa_add_renderbuffer(fb
, BUFFER_DEPTH
, &rb
->Base
.Base
);
550 _mesa_add_renderbuffer(fb
, BUFFER_STENCIL
, &rb
->Base
.Base
);
553 else if (mesaVis
->depthBits
== 16) {
554 assert(mesaVis
->stencilBits
== 0);
555 /* just 16-bit depth buffer, no hw stencil */
556 struct intel_renderbuffer
*depthRb
557 = intel_create_renderbuffer(MESA_FORMAT_Z16
);
558 _mesa_add_renderbuffer(fb
, BUFFER_DEPTH
, &depthRb
->Base
.Base
);
561 assert(mesaVis
->depthBits
== 0);
562 assert(mesaVis
->stencilBits
== 0);
565 /* now add any/all software-based renderbuffers we may need */
566 _swrast_add_soft_renderbuffers(fb
,
567 false, /* never sw color */
568 false, /* never sw depth */
569 false, /* never sw stencil */
570 mesaVis
->accumRedBits
> 0,
571 false, /* never sw alpha */
572 false /* never sw aux */ );
573 driDrawPriv
->driverPrivate
= fb
;
580 intelDestroyBuffer(__DRIdrawable
* driDrawPriv
)
582 struct gl_framebuffer
*fb
= driDrawPriv
->driverPrivate
;
584 _mesa_reference_framebuffer(&fb
, NULL
);
587 /* There are probably better ways to do this, such as an
588 * init-designated function to register chipids and createcontext
592 i830CreateContext(const struct gl_config
*mesaVis
,
593 __DRIcontext
*driContextPriv
,
594 void *sharedContextPrivate
);
597 i915CreateContext(int api
,
598 const struct gl_config
*mesaVis
,
599 __DRIcontext
*driContextPriv
,
600 void *sharedContextPrivate
);
602 brwCreateContext(int api
,
603 const struct gl_config
*mesaVis
,
604 __DRIcontext
*driContextPriv
,
605 void *sharedContextPrivate
);
608 intelCreateContext(gl_api api
,
609 const struct gl_config
* mesaVis
,
610 __DRIcontext
* driContextPriv
,
611 unsigned major_version
,
612 unsigned minor_version
,
615 void *sharedContextPrivate
)
617 __DRIscreen
*sPriv
= driContextPriv
->driScreenPriv
;
618 struct intel_screen
*intelScreen
= sPriv
->driverPrivate
;
619 bool success
= false;
622 if (IS_9XX(intelScreen
->deviceID
)) {
623 if (!IS_965(intelScreen
->deviceID
)) {
624 success
= i915CreateContext(api
, mesaVis
, driContextPriv
,
625 sharedContextPrivate
);
628 intelScreen
->no_vbo
= true;
629 success
= i830CreateContext(mesaVis
, driContextPriv
,
630 sharedContextPrivate
);
633 if (IS_965(intelScreen
->deviceID
))
634 success
= brwCreateContext(api
, mesaVis
,
636 sharedContextPrivate
);
640 struct gl_context
*ctx
=
641 (struct gl_context
*) driContextPriv
->driverPrivate
;
643 _mesa_compute_version(ctx
);
644 if (ctx
->VersionMajor
> major_version
645 || (ctx
->VersionMajor
== major_version
646 && ctx
->VersionMinor
>= minor_version
)) {
647 *error
= __DRI_CTX_ERROR_BAD_VERSION
;
651 intelDestroyContext(driContextPriv
);
653 *error
= __DRI_CTX_ERROR_NO_MEMORY
;
654 fprintf(stderr
, "Unrecognized deviceID 0x%x\n", intelScreen
->deviceID
);
661 intel_init_bufmgr(struct intel_screen
*intelScreen
)
663 __DRIscreen
*spriv
= intelScreen
->driScrnPriv
;
666 intelScreen
->no_hw
= getenv("INTEL_NO_HW") != NULL
;
668 intelScreen
->bufmgr
= intel_bufmgr_gem_init(spriv
->fd
, BATCH_SZ
);
669 if (intelScreen
->bufmgr
== NULL
) {
670 fprintf(stderr
, "[%s:%u] Error initializing buffer manager.\n",
675 if (!intel_get_param(spriv
, I915_PARAM_NUM_FENCES_AVAIL
, &num_fences
) ||
677 fprintf(stderr
, "[%s: %u] Kernel 2.6.29 required.\n", __func__
, __LINE__
);
681 drm_intel_bufmgr_gem_enable_fenced_relocs(intelScreen
->bufmgr
);
683 intelScreen
->named_regions
= _mesa_NewHashTable();
685 intelScreen
->relaxed_relocations
= 0;
686 intelScreen
->relaxed_relocations
|=
687 intel_get_boolean(spriv
, I915_PARAM_HAS_RELAXED_DELTA
) << 0;
693 * Override intel_screen.hw_has_separate_stencil with environment variable
694 * INTEL_SEPARATE_STENCIL.
696 * Valid values for INTEL_SEPARATE_STENCIL are "0" and "1". If an invalid
697 * valid value is encountered, a warning is emitted and INTEL_SEPARATE_STENCIL
701 intel_override_separate_stencil(struct intel_screen
*screen
)
703 const char *s
= getenv("INTEL_SEPARATE_STENCIL");
706 } else if (!strncmp("0", s
, 2)) {
707 screen
->hw_has_separate_stencil
= false;
708 } else if (!strncmp("1", s
, 2)) {
709 screen
->hw_has_separate_stencil
= true;
712 "warning: env variable INTEL_SEPARATE_STENCIL=\"%s\" has "
713 "invalid value and is ignored", s
);
718 intel_detect_swizzling(struct intel_screen
*screen
)
720 drm_intel_bo
*buffer
;
721 unsigned long flags
= 0;
722 unsigned long aligned_pitch
;
723 uint32_t tiling
= I915_TILING_X
;
724 uint32_t swizzle_mode
= 0;
726 buffer
= drm_intel_bo_alloc_tiled(screen
->bufmgr
, "swizzle test",
728 &tiling
, &aligned_pitch
, flags
);
732 drm_intel_bo_get_tiling(buffer
, &tiling
, &swizzle_mode
);
733 drm_intel_bo_unreference(buffer
);
735 if (swizzle_mode
== I915_BIT_6_SWIZZLE_NONE
)
742 * This is the driver specific part of the createNewScreen entry point.
743 * Called when using DRI2.
745 * \return the struct gl_config supported by this driver
748 __DRIconfig
**intelInitScreen2(__DRIscreen
*psp
)
750 struct intel_screen
*intelScreen
;
753 unsigned int api_mask
;
755 static const GLenum back_buffer_modes
[] = {
756 GLX_NONE
, GLX_SWAP_UNDEFINED_OML
, GLX_SWAP_COPY_OML
758 uint8_t depth_bits
[4], stencil_bits
[4], msaa_samples_array
[1];
760 __DRIconfig
**configs
= NULL
;
762 /* Allocate the private area */
763 intelScreen
= CALLOC(sizeof *intelScreen
);
765 fprintf(stderr
, "\nERROR! Allocating private area failed\n");
768 /* parse information in __driConfigOptions */
769 driParseOptionInfo(&intelScreen
->optionCache
,
770 __driConfigOptions
, __driNConfigOptions
);
772 intelScreen
->driScrnPriv
= psp
;
773 psp
->driverPrivate
= (void *) intelScreen
;
775 if (!intel_init_bufmgr(intelScreen
))
778 intelScreen
->deviceID
= drm_intel_bufmgr_gem_get_devid(intelScreen
->bufmgr
);
780 intelScreen
->kernel_has_gen7_sol_reset
=
781 intel_get_boolean(intelScreen
->driScrnPriv
,
782 I915_PARAM_HAS_GEN7_SOL_RESET
);
784 if (IS_GEN7(intelScreen
->deviceID
)) {
785 intelScreen
->gen
= 7;
786 } else if (IS_GEN6(intelScreen
->deviceID
)) {
787 intelScreen
->gen
= 6;
788 } else if (IS_GEN5(intelScreen
->deviceID
)) {
789 intelScreen
->gen
= 5;
790 } else if (IS_965(intelScreen
->deviceID
)) {
791 intelScreen
->gen
= 4;
792 } else if (IS_9XX(intelScreen
->deviceID
)) {
793 intelScreen
->gen
= 3;
795 intelScreen
->gen
= 2;
798 intelScreen
->hw_has_separate_stencil
= intelScreen
->gen
>= 6;
799 intelScreen
->hw_must_use_separate_stencil
= intelScreen
->gen
>= 7;
800 intelScreen
->dri2_has_hiz
= INTEL_DRI2_HAS_HIZ_UNKNOWN
;
803 bool success
= intel_get_param(intelScreen
->driScrnPriv
, I915_PARAM_HAS_LLC
,
805 if (success
&& has_llc
)
806 intelScreen
->hw_has_llc
= true;
807 else if (!success
&& intelScreen
->gen
>= 6)
808 intelScreen
->hw_has_llc
= true;
810 intel_override_separate_stencil(intelScreen
);
812 api_mask
= (1 << __DRI_API_OPENGL
);
814 api_mask
|= (1 << __DRI_API_GLES
);
817 api_mask
|= (1 << __DRI_API_GLES2
);
820 if (IS_9XX(intelScreen
->deviceID
) || IS_965(intelScreen
->deviceID
))
821 psp
->api_mask
= api_mask
;
823 intelScreen
->hw_has_swizzling
= intel_detect_swizzling(intelScreen
);
825 psp
->extensions
= intelScreenExtensions
;
827 msaa_samples_array
[0] = 0;
829 fb_format
[0] = GL_RGB
;
830 fb_type
[0] = GL_UNSIGNED_SHORT_5_6_5
;
832 fb_format
[1] = GL_BGR
;
833 fb_type
[1] = GL_UNSIGNED_INT_8_8_8_8_REV
;
835 fb_format
[2] = GL_BGRA
;
836 fb_type
[2] = GL_UNSIGNED_INT_8_8_8_8_REV
;
841 /* Generate a rich set of useful configs that do not include an
842 * accumulation buffer.
844 for (color
= 0; color
< ARRAY_SIZE(fb_format
); color
++) {
845 __DRIconfig
**new_configs
;
848 /* Starting with DRI2 protocol version 1.1 we can request a depth/stencil
849 * buffer that has a diffferent number of bits per pixel than the color
850 * buffer. This isn't yet supported here.
852 if (fb_type
[color
] == GL_UNSIGNED_SHORT_5_6_5
) {
862 new_configs
= driCreateConfigs(fb_format
[color
], fb_type
[color
],
867 ARRAY_SIZE(back_buffer_modes
),
869 ARRAY_SIZE(msaa_samples_array
),
872 configs
= new_configs
;
874 configs
= driConcatConfigs(configs
, new_configs
);
877 /* Generate the minimum possible set of configs that include an
878 * accumulation buffer.
880 for (color
= 0; color
< ARRAY_SIZE(fb_format
); color
++) {
881 __DRIconfig
**new_configs
;
883 if (fb_type
[color
] == GL_UNSIGNED_SHORT_5_6_5
) {
891 new_configs
= driCreateConfigs(fb_format
[color
], fb_type
[color
],
892 depth_bits
, stencil_bits
, 1,
893 back_buffer_modes
+ 1, 1,
894 msaa_samples_array
, 1,
897 configs
= new_configs
;
899 configs
= driConcatConfigs(configs
, new_configs
);
902 if (configs
== NULL
) {
903 fprintf(stderr
, "[%s:%u] Error creating FBConfig!\n", __func__
,
908 return (const __DRIconfig
**)configs
;
911 struct intel_buffer
{
913 struct intel_region
*region
;
917 * \brief Get tiling format for a DRI buffer.
919 * \param attachment is the buffer's attachmet point, such as
920 * __DRI_BUFFER_DEPTH.
921 * \param out_tiling is the returned tiling format for buffer.
922 * \return false if attachment is unrecognized or is incompatible with screen.
925 intel_get_dri_buffer_tiling(struct intel_screen
*screen
,
927 uint32_t *out_tiling
)
929 if (screen
->gen
< 4) {
930 *out_tiling
= I915_TILING_X
;
934 switch (attachment
) {
935 case __DRI_BUFFER_DEPTH
:
936 case __DRI_BUFFER_DEPTH_STENCIL
:
937 case __DRI_BUFFER_HIZ
:
938 *out_tiling
= I915_TILING_Y
;
940 case __DRI_BUFFER_ACCUM
:
941 case __DRI_BUFFER_FRONT_LEFT
:
942 case __DRI_BUFFER_FRONT_RIGHT
:
943 case __DRI_BUFFER_BACK_LEFT
:
944 case __DRI_BUFFER_BACK_RIGHT
:
945 case __DRI_BUFFER_FAKE_FRONT_LEFT
:
946 case __DRI_BUFFER_FAKE_FRONT_RIGHT
:
947 *out_tiling
= I915_TILING_X
;
949 case __DRI_BUFFER_STENCIL
:
950 /* The stencil buffer is W tiled. However, we request from the kernel
951 * a non-tiled buffer because the GTT is incapable of W fencing.
953 *out_tiling
= I915_TILING_NONE
;
956 if(unlikely(INTEL_DEBUG
& DEBUG_DRI
)) {
957 fprintf(stderr
, "error: %s: unrecognized DRI buffer attachment 0x%x\n",
958 __FUNCTION__
, attachment
);
965 intelAllocateBuffer(__DRIscreen
*screen
,
966 unsigned attachment
, unsigned format
,
967 int width
, int height
)
969 struct intel_buffer
*intelBuffer
;
970 struct intel_screen
*intelScreen
= screen
->driverPrivate
;
973 uint32_t region_width
;
974 uint32_t region_height
;
979 ok
= intel_get_dri_buffer_tiling(intelScreen
, attachment
, &tiling
);
983 intelBuffer
= CALLOC(sizeof *intelBuffer
);
984 if (intelBuffer
== NULL
)
987 if (attachment
== __DRI_BUFFER_STENCIL
) {
988 /* Stencil buffers use W tiling, a tiling format that the DRM functions
989 * don't properly account for. Therefore, when we allocate a stencil
990 * buffer that is private to Mesa (see intel_miptree_create), we round
991 * the height and width up to the next multiple of the tile size (64x64)
992 * and then ask DRM to allocate an untiled buffer. Consequently, the
993 * height and the width stored in the stencil buffer's region structure
994 * are always multiples of 64, even if the stencil buffer itself is
997 * To avoid inconsistencies between how we represent private buffers and
998 * buffers shared with the window system, round up the height and width
999 * for window system buffers too.
1001 region_width
= ALIGN(width
, 64);
1002 region_height
= ALIGN(height
, 64);
1004 region_width
= width
;
1005 region_height
= height
;
1008 region_cpp
= format
/ 8;
1010 intelBuffer
->region
= intel_region_alloc(intelScreen
,
1017 if (intelBuffer
->region
== NULL
) {
1022 intel_region_flink(intelBuffer
->region
, &intelBuffer
->base
.name
);
1024 intelBuffer
->base
.attachment
= attachment
;
1025 intelBuffer
->base
.cpp
= intelBuffer
->region
->cpp
;
1026 intelBuffer
->base
.pitch
=
1027 intelBuffer
->region
->pitch
* intelBuffer
->region
->cpp
;
1029 return &intelBuffer
->base
;
1033 intelReleaseBuffer(__DRIscreen
*screen
, __DRIbuffer
*buffer
)
1035 struct intel_buffer
*intelBuffer
= (struct intel_buffer
*) buffer
;
1037 intel_region_release(&intelBuffer
->region
);
1042 const struct __DriverAPIRec driDriverAPI
= {
1043 .InitScreen
= intelInitScreen2
,
1044 .DestroyScreen
= intelDestroyScreen
,
1045 .CreateContext
= intelCreateContext
,
1046 .DestroyContext
= intelDestroyContext
,
1047 .CreateBuffer
= intelCreateBuffer
,
1048 .DestroyBuffer
= intelDestroyBuffer
,
1049 .MakeCurrent
= intelMakeCurrent
,
1050 .UnbindContext
= intelUnbindContext
,
1051 .AllocateBuffer
= intelAllocateBuffer
,
1052 .ReleaseBuffer
= intelReleaseBuffer
1055 /* This is the table of extensions that the loader will dlsym() for. */
1056 PUBLIC
const __DRIextension
*__driDriverExtensions
[] = {
1057 &driCoreExtension
.base
,
1058 &driDRI2Extension
.base
,