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(early_z
, bool, false)
61 DRI_CONF_DESC(en
, "Enable early Z in classic mode (unstable, 945-only).")
64 DRI_CONF_OPT_BEGIN(fragment_shader
, bool, true)
65 DRI_CONF_DESC(en
, "Enable limited ARB_fragment_shader support on 915/945.")
69 DRI_CONF_SECTION_QUALITY
70 DRI_CONF_FORCE_S3TC_ENABLE(false)
71 DRI_CONF_ALLOW_LARGE_TEXTURES(2)
73 DRI_CONF_SECTION_DEBUG
74 DRI_CONF_NO_RAST(false)
75 DRI_CONF_ALWAYS_FLUSH_BATCH(false)
76 DRI_CONF_ALWAYS_FLUSH_CACHE(false)
77 DRI_CONF_FORCE_GLSL_EXTENSIONS_WARN(false)
79 DRI_CONF_OPT_BEGIN(stub_occlusion_query
, bool, false)
80 DRI_CONF_DESC(en
, "Enable stub ARB_occlusion_query support on 915/945.")
83 DRI_CONF_OPT_BEGIN(shader_precompile
, bool, false)
84 DRI_CONF_DESC(en
, "Perform code generation at shader link time.")
89 const GLuint __driNConfigOptions
= 13;
91 #include "intel_batchbuffer.h"
92 #include "intel_buffers.h"
93 #include "intel_bufmgr.h"
94 #include "intel_chipset.h"
95 #include "intel_fbo.h"
96 #include "intel_mipmap_tree.h"
97 #include "intel_screen.h"
98 #include "intel_tex.h"
99 #include "intel_regions.h"
101 #include "i915_drm.h"
103 #ifdef USE_NEW_INTERFACE
104 static PFNGLXCREATECONTEXTMODES create_context_modes
= NULL
;
105 #endif /*USE_NEW_INTERFACE */
107 static const __DRItexBufferExtension intelTexBufferExtension
= {
108 { __DRI_TEX_BUFFER
, __DRI_TEX_BUFFER_VERSION
},
114 intelDRI2Flush(__DRIdrawable
*drawable
)
116 GET_CURRENT_CONTEXT(ctx
);
117 struct intel_context
*intel
= intel_context(ctx
);
122 INTEL_FIREVERTICES(intel
);
124 intel
->need_throttle
= true;
126 if (intel
->batch
.used
)
127 intel_batchbuffer_flush(intel
);
130 static const struct __DRI2flushExtensionRec intelFlushExtension
= {
131 { __DRI2_FLUSH
, __DRI2_FLUSH_VERSION
},
133 dri2InvalidateDrawable
,
137 intel_create_image_from_name(__DRIscreen
*screen
,
138 int width
, int height
, int format
,
139 int name
, int pitch
, void *loaderPrivate
)
141 struct intel_screen
*intelScreen
= screen
->driverPrivate
;
145 image
= CALLOC(sizeof *image
);
150 case __DRI_IMAGE_FORMAT_RGB565
:
151 image
->format
= MESA_FORMAT_RGB565
;
152 image
->internal_format
= GL_RGB
;
153 image
->data_type
= GL_UNSIGNED_BYTE
;
155 case __DRI_IMAGE_FORMAT_XRGB8888
:
156 image
->format
= MESA_FORMAT_XRGB8888
;
157 image
->internal_format
= GL_RGB
;
158 image
->data_type
= GL_UNSIGNED_BYTE
;
160 case __DRI_IMAGE_FORMAT_ARGB8888
:
161 image
->format
= MESA_FORMAT_ARGB8888
;
162 image
->internal_format
= GL_RGBA
;
163 image
->data_type
= GL_UNSIGNED_BYTE
;
165 case __DRI_IMAGE_FORMAT_ABGR8888
:
166 image
->format
= MESA_FORMAT_RGBA8888_REV
;
167 image
->internal_format
= GL_RGBA
;
168 image
->data_type
= GL_UNSIGNED_BYTE
;
175 image
->data
= loaderPrivate
;
176 cpp
= _mesa_get_format_bytes(image
->format
);
178 image
->region
= intel_region_alloc_for_handle(intelScreen
,
180 pitch
, name
, "image");
181 if (image
->region
== NULL
) {
190 intel_create_image_from_renderbuffer(__DRIcontext
*context
,
191 int renderbuffer
, void *loaderPrivate
)
194 struct intel_context
*intel
= context
->driverPrivate
;
195 struct gl_renderbuffer
*rb
;
196 struct intel_renderbuffer
*irb
;
198 rb
= _mesa_lookup_renderbuffer(&intel
->ctx
, renderbuffer
);
200 _mesa_error(&intel
->ctx
,
201 GL_INVALID_OPERATION
, "glRenderbufferExternalMESA");
205 irb
= intel_renderbuffer(rb
);
206 image
= CALLOC(sizeof *image
);
210 image
->internal_format
= rb
->InternalFormat
;
211 image
->format
= rb
->Format
;
212 image
->data_type
= GL_UNSIGNED_BYTE
;
213 image
->data
= loaderPrivate
;
214 intel_region_reference(&image
->region
, irb
->mt
->region
);
220 intel_destroy_image(__DRIimage
*image
)
222 intel_region_release(&image
->region
);
227 intel_create_image(__DRIscreen
*screen
,
228 int width
, int height
, int format
,
233 struct intel_screen
*intelScreen
= screen
->driverPrivate
;
237 tiling
= I915_TILING_X
;
238 if (use
& __DRI_IMAGE_USE_CURSOR
) {
239 if (width
!= 64 || height
!= 64)
241 tiling
= I915_TILING_NONE
;
244 image
= CALLOC(sizeof *image
);
249 case __DRI_IMAGE_FORMAT_RGB565
:
250 image
->format
= MESA_FORMAT_RGB565
;
251 image
->internal_format
= GL_RGB
;
252 image
->data_type
= GL_UNSIGNED_BYTE
;
254 case __DRI_IMAGE_FORMAT_XRGB8888
:
255 image
->format
= MESA_FORMAT_XRGB8888
;
256 image
->internal_format
= GL_RGB
;
257 image
->data_type
= GL_UNSIGNED_BYTE
;
259 case __DRI_IMAGE_FORMAT_ARGB8888
:
260 image
->format
= MESA_FORMAT_ARGB8888
;
261 image
->internal_format
= GL_RGBA
;
262 image
->data_type
= GL_UNSIGNED_BYTE
;
264 case __DRI_IMAGE_FORMAT_ABGR8888
:
265 image
->format
= MESA_FORMAT_RGBA8888_REV
;
266 image
->internal_format
= GL_RGBA
;
267 image
->data_type
= GL_UNSIGNED_BYTE
;
274 image
->data
= loaderPrivate
;
275 cpp
= _mesa_get_format_bytes(image
->format
);
278 intel_region_alloc(intelScreen
, tiling
,
279 cpp
, width
, height
, true);
280 if (image
->region
== NULL
) {
289 intel_query_image(__DRIimage
*image
, int attrib
, int *value
)
292 case __DRI_IMAGE_ATTRIB_STRIDE
:
293 *value
= image
->region
->pitch
* image
->region
->cpp
;
295 case __DRI_IMAGE_ATTRIB_HANDLE
:
296 *value
= image
->region
->bo
->handle
;
298 case __DRI_IMAGE_ATTRIB_NAME
:
299 return intel_region_flink(image
->region
, (uint32_t *) value
);
306 intel_dup_image(__DRIimage
*orig_image
, void *loaderPrivate
)
310 image
= CALLOC(sizeof *image
);
314 intel_region_reference(&image
->region
, orig_image
->region
);
315 if (image
->region
== NULL
) {
320 image
->internal_format
= orig_image
->internal_format
;
321 image
->format
= orig_image
->format
;
322 image
->data_type
= orig_image
->data_type
;
323 image
->data
= loaderPrivate
;
329 intel_validate_usage(__DRIimage
*image
, unsigned int use
)
331 if (use
& __DRI_IMAGE_USE_CURSOR
) {
332 if (image
->region
->width
!= 64 || image
->region
->height
!= 64)
339 static struct __DRIimageExtensionRec intelImageExtension
= {
341 intel_create_image_from_name
,
342 intel_create_image_from_renderbuffer
,
350 static const __DRIextension
*intelScreenExtensions
[] = {
351 &intelTexBufferExtension
.base
,
352 &intelFlushExtension
.base
,
353 &intelImageExtension
.base
,
354 &dri2ConfigQueryExtension
.base
,
359 intel_get_param(__DRIscreen
*psp
, int param
, int *value
)
362 struct drm_i915_getparam gp
;
364 memset(&gp
, 0, sizeof(gp
));
368 ret
= drmCommandWriteRead(psp
->fd
, DRM_I915_GETPARAM
, &gp
, sizeof(gp
));
371 _mesa_warning(NULL
, "drm_i915_getparam: %d", ret
);
379 intel_get_boolean(__DRIscreen
*psp
, int param
)
382 return intel_get_param(psp
, param
, &value
) && value
;
386 nop_callback(GLuint key
, void *data
, void *userData
)
391 intelDestroyScreen(__DRIscreen
* sPriv
)
393 struct intel_screen
*intelScreen
= sPriv
->driverPrivate
;
395 dri_bufmgr_destroy(intelScreen
->bufmgr
);
396 driDestroyOptionInfo(&intelScreen
->optionCache
);
398 /* Some regions may still have references to them at this point, so
399 * flush the hash table to prevent _mesa_DeleteHashTable() from
400 * complaining about the hash not being empty; */
401 _mesa_HashDeleteAll(intelScreen
->named_regions
, nop_callback
, NULL
);
402 _mesa_DeleteHashTable(intelScreen
->named_regions
);
405 sPriv
->driverPrivate
= NULL
;
410 * This is called when we need to set up GL rendering to a new X window.
413 intelCreateBuffer(__DRIscreen
* driScrnPriv
,
414 __DRIdrawable
* driDrawPriv
,
415 const struct gl_config
* mesaVis
, GLboolean isPixmap
)
417 struct intel_renderbuffer
*rb
;
418 struct intel_screen
*screen
= (struct intel_screen
*) driScrnPriv
->driverPrivate
;
421 return false; /* not implemented */
426 struct gl_framebuffer
*fb
= CALLOC_STRUCT(gl_framebuffer
);
431 _mesa_initialize_window_framebuffer(fb
, mesaVis
);
433 if (mesaVis
->redBits
== 5)
434 rgbFormat
= MESA_FORMAT_RGB565
;
435 else if (mesaVis
->alphaBits
== 0)
436 rgbFormat
= MESA_FORMAT_XRGB8888
;
438 rgbFormat
= MESA_FORMAT_ARGB8888
;
440 /* setup the hardware-based renderbuffers */
441 rb
= intel_create_renderbuffer(rgbFormat
);
442 _mesa_add_renderbuffer(fb
, BUFFER_FRONT_LEFT
, &rb
->Base
.Base
);
444 if (mesaVis
->doubleBufferMode
) {
445 rb
= intel_create_renderbuffer(rgbFormat
);
446 _mesa_add_renderbuffer(fb
, BUFFER_BACK_LEFT
, &rb
->Base
.Base
);
450 * Assert here that the gl_config has an expected depth/stencil bit
451 * combination: one of d24/s8, d16/s0, d0/s0. (See intelInitScreen2(),
452 * which constructs the advertised configs.)
454 if (mesaVis
->depthBits
== 24) {
455 assert(mesaVis
->stencilBits
== 8);
457 if (screen
->hw_has_separate_stencil
458 && screen
->dri2_has_hiz
!= INTEL_DRI2_HAS_HIZ_FALSE
) {
460 * Request a separate stencil buffer even if we do not yet know if
461 * the screen supports it. (See comments for
462 * enum intel_dri2_has_hiz).
464 rb
= intel_create_renderbuffer(MESA_FORMAT_X8_Z24
);
465 _mesa_add_renderbuffer(fb
, BUFFER_DEPTH
, &rb
->Base
.Base
);
466 rb
= intel_create_renderbuffer(MESA_FORMAT_S8
);
467 _mesa_add_renderbuffer(fb
, BUFFER_STENCIL
, &rb
->Base
.Base
);
470 * Use combined depth/stencil. Note that the renderbuffer is
471 * attached to two attachment points.
473 rb
= intel_create_renderbuffer(MESA_FORMAT_S8_Z24
);
474 _mesa_add_renderbuffer(fb
, BUFFER_DEPTH
, &rb
->Base
.Base
);
475 _mesa_add_renderbuffer(fb
, BUFFER_STENCIL
, &rb
->Base
.Base
);
478 else if (mesaVis
->depthBits
== 16) {
479 assert(mesaVis
->stencilBits
== 0);
480 /* just 16-bit depth buffer, no hw stencil */
481 struct intel_renderbuffer
*depthRb
482 = intel_create_renderbuffer(MESA_FORMAT_Z16
);
483 _mesa_add_renderbuffer(fb
, BUFFER_DEPTH
, &depthRb
->Base
.Base
);
486 assert(mesaVis
->depthBits
== 0);
487 assert(mesaVis
->stencilBits
== 0);
490 /* now add any/all software-based renderbuffers we may need */
491 _swrast_add_soft_renderbuffers(fb
,
492 false, /* never sw color */
493 false, /* never sw depth */
494 false, /* never sw stencil */
495 mesaVis
->accumRedBits
> 0,
496 false, /* never sw alpha */
497 false /* never sw aux */ );
498 driDrawPriv
->driverPrivate
= fb
;
505 intelDestroyBuffer(__DRIdrawable
* driDrawPriv
)
507 struct gl_framebuffer
*fb
= driDrawPriv
->driverPrivate
;
509 _mesa_reference_framebuffer(&fb
, NULL
);
512 /* There are probably better ways to do this, such as an
513 * init-designated function to register chipids and createcontext
517 i830CreateContext(const struct gl_config
*mesaVis
,
518 __DRIcontext
*driContextPriv
,
519 void *sharedContextPrivate
);
522 i915CreateContext(int api
,
523 const struct gl_config
*mesaVis
,
524 __DRIcontext
*driContextPriv
,
525 void *sharedContextPrivate
);
527 brwCreateContext(int api
,
528 const struct gl_config
*mesaVis
,
529 __DRIcontext
*driContextPriv
,
530 void *sharedContextPrivate
);
533 intelCreateContext(gl_api api
,
534 const struct gl_config
* mesaVis
,
535 __DRIcontext
* driContextPriv
,
536 unsigned major_version
,
537 unsigned minor_version
,
540 void *sharedContextPrivate
)
542 __DRIscreen
*sPriv
= driContextPriv
->driScreenPriv
;
543 struct intel_screen
*intelScreen
= sPriv
->driverPrivate
;
544 bool success
= false;
547 if (IS_9XX(intelScreen
->deviceID
)) {
548 if (!IS_965(intelScreen
->deviceID
)) {
549 success
= i915CreateContext(api
, mesaVis
, driContextPriv
,
550 sharedContextPrivate
);
553 intelScreen
->no_vbo
= true;
554 success
= i830CreateContext(mesaVis
, driContextPriv
,
555 sharedContextPrivate
);
558 if (IS_965(intelScreen
->deviceID
))
559 success
= brwCreateContext(api
, mesaVis
,
561 sharedContextPrivate
);
565 struct gl_context
*ctx
=
566 (struct gl_context
*) driContextPriv
->driverPrivate
;
568 _mesa_compute_version(ctx
);
569 if (ctx
->VersionMajor
> major_version
570 || (ctx
->VersionMajor
== major_version
571 && ctx
->VersionMinor
>= minor_version
)) {
572 *error
= __DRI_CTX_ERROR_BAD_VERSION
;
576 intelDestroyContext(driContextPriv
);
578 *error
= __DRI_CTX_ERROR_NO_MEMORY
;
579 fprintf(stderr
, "Unrecognized deviceID 0x%x\n", intelScreen
->deviceID
);
586 intel_init_bufmgr(struct intel_screen
*intelScreen
)
588 __DRIscreen
*spriv
= intelScreen
->driScrnPriv
;
591 intelScreen
->no_hw
= (getenv("INTEL_NO_HW") != NULL
||
592 getenv("INTEL_DEVID_OVERRIDE") != NULL
);
594 intelScreen
->bufmgr
= intel_bufmgr_gem_init(spriv
->fd
, BATCH_SZ
);
595 if (intelScreen
->bufmgr
== NULL
) {
596 fprintf(stderr
, "[%s:%u] Error initializing buffer manager.\n",
601 if (!intel_get_param(spriv
, I915_PARAM_NUM_FENCES_AVAIL
, &num_fences
) ||
603 fprintf(stderr
, "[%s: %u] Kernel 2.6.29 required.\n", __func__
, __LINE__
);
607 drm_intel_bufmgr_gem_enable_fenced_relocs(intelScreen
->bufmgr
);
609 intelScreen
->named_regions
= _mesa_NewHashTable();
611 intelScreen
->relaxed_relocations
= 0;
612 intelScreen
->relaxed_relocations
|=
613 intel_get_boolean(spriv
, I915_PARAM_HAS_RELAXED_DELTA
) << 0;
619 * Override intel_screen.hw_has_hiz with environment variable INTEL_HIZ.
621 * Valid values for INTEL_HIZ are "0" and "1". If an invalid valid value is
622 * encountered, a warning is emitted and INTEL_HIZ is ignored.
625 intel_override_hiz(struct intel_screen
*intel
)
627 const char *s
= getenv("INTEL_HIZ");
630 } else if (!strncmp("0", s
, 2)) {
631 intel
->hw_has_hiz
= false;
632 } else if (!strncmp("1", s
, 2)) {
633 intel
->hw_has_hiz
= true;
636 "warning: env variable INTEL_HIZ=\"%s\" has invalid value "
637 "and is ignored", s
);
642 * Override intel_screen.hw_has_separate_stencil with environment variable
643 * INTEL_SEPARATE_STENCIL.
645 * Valid values for INTEL_SEPARATE_STENCIL are "0" and "1". If an invalid
646 * valid value is encountered, a warning is emitted and INTEL_SEPARATE_STENCIL
650 intel_override_separate_stencil(struct intel_screen
*screen
)
652 const char *s
= getenv("INTEL_SEPARATE_STENCIL");
655 } else if (!strncmp("0", s
, 2)) {
656 screen
->hw_has_separate_stencil
= false;
657 } else if (!strncmp("1", s
, 2)) {
658 screen
->hw_has_separate_stencil
= true;
661 "warning: env variable INTEL_SEPARATE_STENCIL=\"%s\" has "
662 "invalid value and is ignored", s
);
667 * This is the driver specific part of the createNewScreen entry point.
668 * Called when using DRI2.
670 * \return the struct gl_config supported by this driver
673 __DRIconfig
**intelInitScreen2(__DRIscreen
*psp
)
675 struct intel_screen
*intelScreen
;
678 unsigned int api_mask
;
679 char *devid_override
;
681 static const GLenum back_buffer_modes
[] = {
682 GLX_NONE
, GLX_SWAP_UNDEFINED_OML
, GLX_SWAP_COPY_OML
684 uint8_t depth_bits
[4], stencil_bits
[4], msaa_samples_array
[1];
686 __DRIconfig
**configs
= NULL
;
688 /* Allocate the private area */
689 intelScreen
= CALLOC(sizeof *intelScreen
);
691 fprintf(stderr
, "\nERROR! Allocating private area failed\n");
694 /* parse information in __driConfigOptions */
695 driParseOptionInfo(&intelScreen
->optionCache
,
696 __driConfigOptions
, __driNConfigOptions
);
698 intelScreen
->driScrnPriv
= psp
;
699 psp
->driverPrivate
= (void *) intelScreen
;
701 /* Determine chipset ID */
702 if (!intel_get_param(psp
, I915_PARAM_CHIPSET_ID
,
703 &intelScreen
->deviceID
))
706 /* Allow an override of the device ID for the purpose of making the
707 * driver produce dumps for debugging of new chipset enablement.
708 * This implies INTEL_NO_HW, to avoid programming your actual GPU
711 devid_override
= getenv("INTEL_DEVID_OVERRIDE");
712 if (devid_override
) {
713 intelScreen
->deviceID
= strtod(devid_override
, NULL
);
716 intelScreen
->kernel_has_gen7_sol_reset
=
717 intel_get_boolean(intelScreen
->driScrnPriv
,
718 I915_PARAM_HAS_GEN7_SOL_RESET
);
720 if (IS_GEN7(intelScreen
->deviceID
)) {
721 intelScreen
->gen
= 7;
722 } else if (IS_GEN6(intelScreen
->deviceID
)) {
723 intelScreen
->gen
= 6;
724 } else if (IS_GEN5(intelScreen
->deviceID
)) {
725 intelScreen
->gen
= 5;
726 } else if (IS_965(intelScreen
->deviceID
)) {
727 intelScreen
->gen
= 4;
728 } else if (IS_9XX(intelScreen
->deviceID
)) {
729 intelScreen
->gen
= 3;
731 intelScreen
->gen
= 2;
734 intelScreen
->hw_has_separate_stencil
= intelScreen
->gen
>= 6;
735 intelScreen
->hw_must_use_separate_stencil
= intelScreen
->gen
>= 7;
736 intelScreen
->hw_has_hiz
= intelScreen
->gen
>= 6;
737 intelScreen
->dri2_has_hiz
= INTEL_DRI2_HAS_HIZ_UNKNOWN
;
739 #if defined(I915_PARAM_HAS_LLC)
740 intelScreen
->hw_has_llc
=
741 intel_get_boolean(intelScreen
->driScrnPriv
,
744 intelScreen
->hw_has_llc
= intelScreen
->gen
>= 6;
747 intel_override_hiz(intelScreen
);
748 intel_override_separate_stencil(intelScreen
);
750 api_mask
= (1 << __DRI_API_OPENGL
);
752 api_mask
|= (1 << __DRI_API_GLES
);
755 api_mask
|= (1 << __DRI_API_GLES2
);
758 if (IS_9XX(intelScreen
->deviceID
) || IS_965(intelScreen
->deviceID
))
759 psp
->api_mask
= api_mask
;
761 if (!intel_init_bufmgr(intelScreen
))
764 psp
->extensions
= intelScreenExtensions
;
766 msaa_samples_array
[0] = 0;
768 fb_format
[0] = GL_RGB
;
769 fb_type
[0] = GL_UNSIGNED_SHORT_5_6_5
;
771 fb_format
[1] = GL_BGR
;
772 fb_type
[1] = GL_UNSIGNED_INT_8_8_8_8_REV
;
774 fb_format
[2] = GL_BGRA
;
775 fb_type
[2] = GL_UNSIGNED_INT_8_8_8_8_REV
;
780 /* Generate a rich set of useful configs that do not include an
781 * accumulation buffer.
783 for (color
= 0; color
< ARRAY_SIZE(fb_format
); color
++) {
784 __DRIconfig
**new_configs
;
787 /* Starting with DRI2 protocol version 1.1 we can request a depth/stencil
788 * buffer that has a diffferent number of bits per pixel than the color
789 * buffer. This isn't yet supported here.
791 if (fb_type
[color
] == GL_UNSIGNED_SHORT_5_6_5
) {
801 new_configs
= driCreateConfigs(fb_format
[color
], fb_type
[color
],
806 ARRAY_SIZE(back_buffer_modes
),
808 ARRAY_SIZE(msaa_samples_array
),
811 configs
= new_configs
;
813 configs
= driConcatConfigs(configs
, new_configs
);
816 /* Generate the minimum possible set of configs that include an
817 * accumulation buffer.
819 for (color
= 0; color
< ARRAY_SIZE(fb_format
); color
++) {
820 __DRIconfig
**new_configs
;
822 if (fb_type
[color
] == GL_UNSIGNED_SHORT_5_6_5
) {
830 new_configs
= driCreateConfigs(fb_format
[color
], fb_type
[color
],
831 depth_bits
, stencil_bits
, 1,
832 back_buffer_modes
+ 1, 1,
833 msaa_samples_array
, 1,
836 configs
= new_configs
;
838 configs
= driConcatConfigs(configs
, new_configs
);
841 if (configs
== NULL
) {
842 fprintf(stderr
, "[%s:%u] Error creating FBConfig!\n", __func__
,
847 return (const __DRIconfig
**)configs
;
850 struct intel_buffer
{
852 struct intel_region
*region
;
856 * \brief Get tiling format for a DRI buffer.
858 * \param attachment is the buffer's attachmet point, such as
859 * __DRI_BUFFER_DEPTH.
860 * \param out_tiling is the returned tiling format for buffer.
861 * \return false if attachment is unrecognized or is incompatible with screen.
864 intel_get_dri_buffer_tiling(struct intel_screen
*screen
,
866 uint32_t *out_tiling
)
868 if (screen
->gen
< 4) {
869 *out_tiling
= I915_TILING_X
;
873 switch (attachment
) {
874 case __DRI_BUFFER_DEPTH
:
875 case __DRI_BUFFER_DEPTH_STENCIL
:
876 case __DRI_BUFFER_HIZ
:
877 *out_tiling
= I915_TILING_Y
;
879 case __DRI_BUFFER_ACCUM
:
880 case __DRI_BUFFER_FRONT_LEFT
:
881 case __DRI_BUFFER_FRONT_RIGHT
:
882 case __DRI_BUFFER_BACK_LEFT
:
883 case __DRI_BUFFER_BACK_RIGHT
:
884 case __DRI_BUFFER_FAKE_FRONT_LEFT
:
885 case __DRI_BUFFER_FAKE_FRONT_RIGHT
:
886 *out_tiling
= I915_TILING_X
;
888 case __DRI_BUFFER_STENCIL
:
889 /* The stencil buffer is W tiled. However, we request from the kernel
890 * a non-tiled buffer because the GTT is incapable of W fencing.
892 *out_tiling
= I915_TILING_NONE
;
895 if(unlikely(INTEL_DEBUG
& DEBUG_DRI
)) {
896 fprintf(stderr
, "error: %s: unrecognized DRI buffer attachment 0x%x\n",
897 __FUNCTION__
, attachment
);
904 intelAllocateBuffer(__DRIscreen
*screen
,
905 unsigned attachment
, unsigned format
,
906 int width
, int height
)
908 struct intel_buffer
*intelBuffer
;
909 struct intel_screen
*intelScreen
= screen
->driverPrivate
;
912 uint32_t region_width
;
913 uint32_t region_height
;
918 ok
= intel_get_dri_buffer_tiling(intelScreen
, attachment
, &tiling
);
922 intelBuffer
= CALLOC(sizeof *intelBuffer
);
923 if (intelBuffer
== NULL
)
926 if (attachment
== __DRI_BUFFER_STENCIL
) {
927 /* The stencil buffer has quirky pitch requirements. From Vol 2a,
928 * 11.5.6.2.1 3DSTATE_STENCIL_BUFFER, field "Surface Pitch":
929 * The pitch must be set to 2x the value computed based on width, as
930 * the stencil buffer is stored with two rows interleaved.
931 * To accomplish this, we resort to the nasty hack of doubling the
932 * region's cpp and halving its height.
934 region_width
= ALIGN(width
, 64);
935 region_height
= ALIGN(ALIGN(height
, 2) / 2, 64);
936 region_cpp
= format
/ 4;
938 region_width
= width
;
939 region_height
= height
;
940 region_cpp
= format
/ 8;
943 intelBuffer
->region
= intel_region_alloc(intelScreen
,
950 if (intelBuffer
->region
== NULL
) {
955 intel_region_flink(intelBuffer
->region
, &intelBuffer
->base
.name
);
957 intelBuffer
->base
.attachment
= attachment
;
958 intelBuffer
->base
.cpp
= intelBuffer
->region
->cpp
;
959 intelBuffer
->base
.pitch
=
960 intelBuffer
->region
->pitch
* intelBuffer
->region
->cpp
;
962 return &intelBuffer
->base
;
966 intelReleaseBuffer(__DRIscreen
*screen
, __DRIbuffer
*buffer
)
968 struct intel_buffer
*intelBuffer
= (struct intel_buffer
*) buffer
;
970 intel_region_release(&intelBuffer
->region
);
975 const struct __DriverAPIRec driDriverAPI
= {
976 .InitScreen
= intelInitScreen2
,
977 .DestroyScreen
= intelDestroyScreen
,
978 .CreateContext
= intelCreateContext
,
979 .DestroyContext
= intelDestroyContext
,
980 .CreateBuffer
= intelCreateBuffer
,
981 .DestroyBuffer
= intelDestroyBuffer
,
982 .MakeCurrent
= intelMakeCurrent
,
983 .UnbindContext
= intelUnbindContext
,
984 .AllocateBuffer
= intelAllocateBuffer
,
985 .ReleaseBuffer
= intelReleaseBuffer
988 /* This is the table of extensions that the loader will dlsym() for. */
989 PUBLIC
const __DRIextension
*__driDriverExtensions
[] = {
990 &driCoreExtension
.base
,
991 &driDRI2Extension
.base
,