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);
248 image->dri_format = format;
251 case __DRI_IMAGE_FORMAT_RGB565:
252 image->format = MESA_FORMAT_RGB565;
253 image->internal_format = GL_RGB;
254 image->data_type = GL_UNSIGNED_BYTE;
256 case __DRI_IMAGE_FORMAT_XRGB8888:
257 image->format = MESA_FORMAT_XRGB8888;
258 image->internal_format = GL_RGB;
259 image->data_type = GL_UNSIGNED_BYTE;
261 case __DRI_IMAGE_FORMAT_ARGB8888:
262 image->format = MESA_FORMAT_ARGB8888;
263 image->internal_format = GL_RGBA;
264 image->data_type = GL_UNSIGNED_BYTE;
266 case __DRI_IMAGE_FORMAT_ABGR8888:
267 image->format = MESA_FORMAT_RGBA8888_REV;
268 image->internal_format = GL_RGBA;
269 image->data_type = GL_UNSIGNED_BYTE;
276 image->data = loaderPrivate;
277 cpp = _mesa_get_format_bytes(image->format);
280 intel_region_alloc(intelScreen, tiling,
281 cpp, width, height, true);
282 if (image->region == NULL) {
291 intel_query_image(__DRIimage *image, int attrib, int *value)
294 case __DRI_IMAGE_ATTRIB_STRIDE:
295 *value = image->region->pitch * image->region->cpp;
297 case __DRI_IMAGE_ATTRIB_HANDLE:
298 *value = image->region->bo->handle;
300 case __DRI_IMAGE_ATTRIB_NAME:
301 return intel_region_flink(image->region, (uint32_t *) value);
302 case __DRI_IMAGE_ATTRIB_FORMAT:
303 return image->dri_format;
310 intel_dup_image(__DRIimage *orig_image, void *loaderPrivate)
314 image = CALLOC(sizeof *image);
318 intel_region_reference(&image->region, orig_image->region);
319 if (image->region == NULL) {
324 image->internal_format = orig_image->internal_format;
325 image->format = orig_image->format;
326 image->data_type = orig_image->data_type;
327 image->data = loaderPrivate;
333 intel_validate_usage(__DRIimage *image, unsigned int use)
335 if (use & __DRI_IMAGE_USE_CURSOR) {
336 if (image->region->width != 64 || image->region->height != 64)
343 static struct __DRIimageExtensionRec intelImageExtension = {
345 intel_create_image_from_name,
346 intel_create_image_from_renderbuffer,
354 static const __DRIextension *intelScreenExtensions[] = {
355 &intelTexBufferExtension.base,
356 &intelFlushExtension.base,
357 &intelImageExtension.base,
358 &dri2ConfigQueryExtension.base,
363 intel_get_param(__DRIscreen *psp, int param, int *value)
366 struct drm_i915_getparam gp;
368 memset(&gp, 0, sizeof(gp));
372 ret = drmCommandWriteRead(psp->fd, DRM_I915_GETPARAM, &gp, sizeof(gp));
375 _mesa_warning(NULL, "drm_i915_getparam: %d", ret);
383 intel_get_boolean(__DRIscreen *psp, int param)
386 return intel_get_param(psp, param, &value) && value;
390 nop_callback(GLuint key, void *data, void *userData)
395 intelDestroyScreen(__DRIscreen * sPriv)
397 struct intel_screen *intelScreen = sPriv->driverPrivate;
399 dri_bufmgr_destroy(intelScreen->bufmgr);
400 driDestroyOptionInfo(&intelScreen->optionCache);
402 /* Some regions may still have references to them at this point, so
403 * flush the hash table to prevent _mesa_DeleteHashTable() from
404 * complaining about the hash not being empty; */
405 _mesa_HashDeleteAll(intelScreen->named_regions, nop_callback, NULL);
406 _mesa_DeleteHashTable(intelScreen->named_regions);
409 sPriv->driverPrivate = NULL;
414 * This is called when we need to set up GL rendering to a new X window.
417 intelCreateBuffer(__DRIscreen * driScrnPriv,
418 __DRIdrawable * driDrawPriv,
419 const struct gl_config * mesaVis, GLboolean isPixmap)
421 struct intel_renderbuffer *rb;
422 struct intel_screen *screen = (struct intel_screen*) driScrnPriv->driverPrivate;
425 return false; /* not implemented */
430 struct gl_framebuffer *fb = CALLOC_STRUCT(gl_framebuffer);
435 _mesa_initialize_window_framebuffer(fb, mesaVis);
437 if (mesaVis->redBits == 5)
438 rgbFormat = MESA_FORMAT_RGB565;
439 else if (mesaVis->alphaBits == 0)
440 rgbFormat = MESA_FORMAT_XRGB8888;
442 rgbFormat = MESA_FORMAT_ARGB8888;
444 /* setup the hardware-based renderbuffers */
445 rb = intel_create_renderbuffer(rgbFormat);
446 _mesa_add_renderbuffer(fb, BUFFER_FRONT_LEFT, &rb->Base.Base);
448 if (mesaVis->doubleBufferMode) {
449 rb = intel_create_renderbuffer(rgbFormat);
450 _mesa_add_renderbuffer(fb, BUFFER_BACK_LEFT, &rb->Base.Base);
454 * Assert here that the gl_config has an expected depth/stencil bit
455 * combination: one of d24/s8, d16/s0, d0/s0. (See intelInitScreen2(),
456 * which constructs the advertised configs.)
458 if (mesaVis->depthBits == 24) {
459 assert(mesaVis->stencilBits == 8);
461 if (screen->hw_has_separate_stencil
462 && screen->dri2_has_hiz != INTEL_DRI2_HAS_HIZ_FALSE) {
464 * Request a separate stencil buffer even if we do not yet know if
465 * the screen supports it. (See comments for
466 * enum intel_dri2_has_hiz).
468 rb = intel_create_renderbuffer(MESA_FORMAT_X8_Z24);
469 _mesa_add_renderbuffer(fb, BUFFER_DEPTH, &rb->Base.Base);
470 rb = intel_create_renderbuffer(MESA_FORMAT_S8);
471 _mesa_add_renderbuffer(fb, BUFFER_STENCIL, &rb->Base.Base);
474 * Use combined depth/stencil. Note that the renderbuffer is
475 * attached to two attachment points.
477 rb = intel_create_renderbuffer(MESA_FORMAT_S8_Z24);
478 _mesa_add_renderbuffer(fb, BUFFER_DEPTH, &rb->Base.Base);
479 _mesa_add_renderbuffer(fb, BUFFER_STENCIL, &rb->Base.Base);
482 else if (mesaVis->depthBits == 16) {
483 assert(mesaVis->stencilBits == 0);
484 /* just 16-bit depth buffer, no hw stencil */
485 struct intel_renderbuffer *depthRb
486 = intel_create_renderbuffer(MESA_FORMAT_Z16);
487 _mesa_add_renderbuffer(fb, BUFFER_DEPTH, &depthRb->Base.Base);
490 assert(mesaVis->depthBits == 0);
491 assert(mesaVis->stencilBits == 0);
494 /* now add any/all software-based renderbuffers we may need */
495 _swrast_add_soft_renderbuffers(fb,
496 false, /* never sw color */
497 false, /* never sw depth */
498 false, /* never sw stencil */
499 mesaVis->accumRedBits > 0,
500 false, /* never sw alpha */
501 false /* never sw aux */ );
502 driDrawPriv->driverPrivate = fb;
509 intelDestroyBuffer(__DRIdrawable * driDrawPriv)
511 struct gl_framebuffer *fb = driDrawPriv->driverPrivate;
513 _mesa_reference_framebuffer(&fb, NULL);
516 /* There are probably better ways to do this, such as an
517 * init-designated function to register chipids and createcontext
521 i830CreateContext(const struct gl_config *mesaVis,
522 __DRIcontext *driContextPriv,
523 void *sharedContextPrivate);
526 i915CreateContext(int api,
527 const struct gl_config *mesaVis,
528 __DRIcontext *driContextPriv,
529 void *sharedContextPrivate);
531 brwCreateContext(int api,
532 const struct gl_config *mesaVis,
533 __DRIcontext *driContextPriv,
534 void *sharedContextPrivate);
537 intelCreateContext(gl_api api,
538 const struct gl_config * mesaVis,
539 __DRIcontext * driContextPriv,
540 unsigned major_version,
541 unsigned minor_version,
544 void *sharedContextPrivate)
546 __DRIscreen *sPriv = driContextPriv->driScreenPriv;
547 struct intel_screen *intelScreen = sPriv->driverPrivate;
548 bool success = false;
551 if (IS_9XX(intelScreen->deviceID)) {
552 if (!IS_965(intelScreen->deviceID)) {
553 success = i915CreateContext(api, mesaVis, driContextPriv,
554 sharedContextPrivate);
557 intelScreen->no_vbo = true;
558 success = i830CreateContext(mesaVis, driContextPriv,
559 sharedContextPrivate);
562 if (IS_965(intelScreen->deviceID))
563 success = brwCreateContext(api, mesaVis,
565 sharedContextPrivate);
569 struct gl_context *ctx =
570 (struct gl_context *) driContextPriv->driverPrivate;
572 _mesa_compute_version(ctx);
573 if (ctx->VersionMajor > major_version
574 || (ctx->VersionMajor == major_version
575 && ctx->VersionMinor >= minor_version)) {
576 *error = __DRI_CTX_ERROR_BAD_VERSION;
580 intelDestroyContext(driContextPriv);
582 *error = __DRI_CTX_ERROR_NO_MEMORY;
583 fprintf(stderr, "Unrecognized deviceID 0x%x\n", intelScreen->deviceID);
590 intel_init_bufmgr(struct intel_screen *intelScreen)
592 __DRIscreen *spriv = intelScreen->driScrnPriv;
595 intelScreen->no_hw = (getenv("INTEL_NO_HW") != NULL ||
596 getenv("INTEL_DEVID_OVERRIDE") != NULL);
598 intelScreen->bufmgr = intel_bufmgr_gem_init(spriv->fd, BATCH_SZ);
599 if (intelScreen->bufmgr == NULL) {
600 fprintf(stderr, "[%s:%u] Error initializing buffer manager.\n",
605 if (!intel_get_param(spriv, I915_PARAM_NUM_FENCES_AVAIL, &num_fences) ||
607 fprintf(stderr, "[%s: %u] Kernel 2.6.29 required.\n", __func__, __LINE__);
611 drm_intel_bufmgr_gem_enable_fenced_relocs(intelScreen->bufmgr);
613 intelScreen->named_regions = _mesa_NewHashTable();
615 intelScreen->relaxed_relocations = 0;
616 intelScreen->relaxed_relocations |=
617 intel_get_boolean(spriv, I915_PARAM_HAS_RELAXED_DELTA) << 0;
623 * Override intel_screen.hw_has_hiz with environment variable INTEL_HIZ.
625 * Valid values for INTEL_HIZ are "0" and "1". If an invalid valid value is
626 * encountered, a warning is emitted and INTEL_HIZ is ignored.
629 intel_override_hiz(struct intel_screen *intel)
631 const char *s = getenv("INTEL_HIZ");
634 } else if (!strncmp("0", s, 2)) {
635 intel->hw_has_hiz = false;
636 } else if (!strncmp("1", s, 2)) {
637 intel->hw_has_hiz = true;
640 "warning: env variable INTEL_HIZ=\"%s\" has invalid value "
641 "and is ignored", s);
646 * Override intel_screen.hw_has_separate_stencil with environment variable
647 * INTEL_SEPARATE_STENCIL.
649 * Valid values for INTEL_SEPARATE_STENCIL are "0" and "1". If an invalid
650 * valid value is encountered, a warning is emitted and INTEL_SEPARATE_STENCIL
654 intel_override_separate_stencil(struct intel_screen *screen)
656 const char *s = getenv("INTEL_SEPARATE_STENCIL");
659 } else if (!strncmp("0", s, 2)) {
660 screen->hw_has_separate_stencil = false;
661 } else if (!strncmp("1", s, 2)) {
662 screen->hw_has_separate_stencil = true;
665 "warning: env variable INTEL_SEPARATE_STENCIL=\"%s\" has "
666 "invalid value and is ignored", s);
671 * This is the driver specific part of the createNewScreen entry point.
672 * Called when using DRI2.
674 * \return the struct gl_config supported by this driver
677 __DRIconfig **intelInitScreen2(__DRIscreen *psp)
679 struct intel_screen *intelScreen;
682 unsigned int api_mask;
683 char *devid_override;
685 static const GLenum back_buffer_modes[] = {
686 GLX_NONE, GLX_SWAP_UNDEFINED_OML, GLX_SWAP_COPY_OML
688 uint8_t depth_bits[4], stencil_bits[4], msaa_samples_array[1];
690 __DRIconfig **configs = NULL;
692 /* Allocate the private area */
693 intelScreen = CALLOC(sizeof *intelScreen);
695 fprintf(stderr, "\nERROR! Allocating private area failed\n");
698 /* parse information in __driConfigOptions */
699 driParseOptionInfo(&intelScreen->optionCache,
700 __driConfigOptions, __driNConfigOptions);
702 intelScreen->driScrnPriv = psp;
703 psp->driverPrivate = (void *) intelScreen;
705 /* Determine chipset ID */
706 if (!intel_get_param(psp, I915_PARAM_CHIPSET_ID,
707 &intelScreen->deviceID))
710 /* Allow an override of the device ID for the purpose of making the
711 * driver produce dumps for debugging of new chipset enablement.
712 * This implies INTEL_NO_HW, to avoid programming your actual GPU
715 devid_override = getenv("INTEL_DEVID_OVERRIDE");
716 if (devid_override) {
717 intelScreen->deviceID = strtod(devid_override, NULL);
720 intelScreen->kernel_has_gen7_sol_reset =
721 intel_get_boolean(intelScreen->driScrnPriv,
722 I915_PARAM_HAS_GEN7_SOL_RESET);
724 if (IS_GEN7(intelScreen->deviceID)) {
725 intelScreen->gen = 7;
726 } else if (IS_GEN6(intelScreen->deviceID)) {
727 intelScreen->gen = 6;
728 } else if (IS_GEN5(intelScreen->deviceID)) {
729 intelScreen->gen = 5;
730 } else if (IS_965(intelScreen->deviceID)) {
731 intelScreen->gen = 4;
732 } else if (IS_9XX(intelScreen->deviceID)) {
733 intelScreen->gen = 3;
735 intelScreen->gen = 2;
738 intelScreen->hw_has_separate_stencil = intelScreen->gen >= 6;
739 intelScreen->hw_must_use_separate_stencil = intelScreen->gen >= 7;
740 intelScreen->hw_has_hiz = intelScreen->gen >= 6;
741 intelScreen->dri2_has_hiz = INTEL_DRI2_HAS_HIZ_UNKNOWN;
743 #if defined(I915_PARAM_HAS_LLC)
744 intelScreen->hw_has_llc =
745 intel_get_boolean(intelScreen->driScrnPriv,
748 intelScreen->hw_has_llc = intelScreen->gen >= 6;
751 intel_override_hiz(intelScreen);
752 intel_override_separate_stencil(intelScreen);
754 api_mask = (1 << __DRI_API_OPENGL);
756 api_mask |= (1 << __DRI_API_GLES);
759 api_mask |= (1 << __DRI_API_GLES2);
762 if (IS_9XX(intelScreen->deviceID) || IS_965(intelScreen->deviceID))
763 psp->api_mask = api_mask;
765 if (!intel_init_bufmgr(intelScreen))
768 psp->extensions = intelScreenExtensions;
770 msaa_samples_array[0] = 0;
772 fb_format[0] = GL_RGB;
773 fb_type[0] = GL_UNSIGNED_SHORT_5_6_5;
775 fb_format[1] = GL_BGR;
776 fb_type[1] = GL_UNSIGNED_INT_8_8_8_8_REV;
778 fb_format[2] = GL_BGRA;
779 fb_type[2] = GL_UNSIGNED_INT_8_8_8_8_REV;
784 /* Generate a rich set of useful configs that do not include an
785 * accumulation buffer.
787 for (color = 0; color < ARRAY_SIZE(fb_format); color++) {
788 __DRIconfig **new_configs;
791 /* Starting with DRI2 protocol version 1.1 we can request a depth/stencil
792 * buffer that has a diffferent number of bits per pixel than the color
793 * buffer. This isn't yet supported here.
795 if (fb_type[color] == GL_UNSIGNED_SHORT_5_6_5) {
805 new_configs = driCreateConfigs(fb_format[color], fb_type[color],
810 ARRAY_SIZE(back_buffer_modes),
812 ARRAY_SIZE(msaa_samples_array),
815 configs = new_configs;
817 configs = driConcatConfigs(configs, new_configs);
820 /* Generate the minimum possible set of configs that include an
821 * accumulation buffer.
823 for (color = 0; color < ARRAY_SIZE(fb_format); color++) {
824 __DRIconfig **new_configs;
826 if (fb_type[color] == GL_UNSIGNED_SHORT_5_6_5) {
834 new_configs = driCreateConfigs(fb_format[color], fb_type[color],
835 depth_bits, stencil_bits, 1,
836 back_buffer_modes + 1, 1,
837 msaa_samples_array, 1,
840 configs = new_configs;
842 configs = driConcatConfigs(configs, new_configs);
845 if (configs == NULL) {
846 fprintf(stderr, "[%s:%u] Error creating FBConfig!\n", __func__,
851 return (const __DRIconfig **)configs;
854 struct intel_buffer {
856 struct intel_region *region;
860 * \brief Get tiling format for a DRI buffer.
862 * \param attachment is the buffer's attachmet point, such as
863 * __DRI_BUFFER_DEPTH.
864 * \param out_tiling is the returned tiling format for buffer.
865 * \return false if attachment is unrecognized or is incompatible with screen.
868 intel_get_dri_buffer_tiling(struct intel_screen *screen,
870 uint32_t *out_tiling)
872 if (screen->gen < 4) {
873 *out_tiling = I915_TILING_X;
877 switch (attachment) {
878 case __DRI_BUFFER_DEPTH:
879 case __DRI_BUFFER_DEPTH_STENCIL:
880 case __DRI_BUFFER_HIZ:
881 *out_tiling = I915_TILING_Y;
883 case __DRI_BUFFER_ACCUM:
884 case __DRI_BUFFER_FRONT_LEFT:
885 case __DRI_BUFFER_FRONT_RIGHT:
886 case __DRI_BUFFER_BACK_LEFT:
887 case __DRI_BUFFER_BACK_RIGHT:
888 case __DRI_BUFFER_FAKE_FRONT_LEFT:
889 case __DRI_BUFFER_FAKE_FRONT_RIGHT:
890 *out_tiling = I915_TILING_X;
892 case __DRI_BUFFER_STENCIL:
893 /* The stencil buffer is W tiled. However, we request from the kernel
894 * a non-tiled buffer because the GTT is incapable of W fencing.
896 *out_tiling = I915_TILING_NONE;
899 if(unlikely(INTEL_DEBUG & DEBUG_DRI)) {
900 fprintf(stderr, "error: %s: unrecognized DRI buffer attachment 0x%x\n",
901 __FUNCTION__, attachment);
908 intelAllocateBuffer(__DRIscreen *screen,
909 unsigned attachment, unsigned format,
910 int width, int height)
912 struct intel_buffer *intelBuffer;
913 struct intel_screen *intelScreen = screen->driverPrivate;
916 uint32_t region_width;
917 uint32_t region_height;
922 ok = intel_get_dri_buffer_tiling(intelScreen, attachment, &tiling);
926 intelBuffer = CALLOC(sizeof *intelBuffer);
927 if (intelBuffer == NULL)
930 if (attachment == __DRI_BUFFER_STENCIL) {
931 /* The stencil buffer has quirky pitch requirements. From Vol 2a,
932 * 11.5.6.2.1 3DSTATE_STENCIL_BUFFER, field "Surface Pitch":
933 * The pitch must be set to 2x the value computed based on width, as
934 * the stencil buffer is stored with two rows interleaved.
935 * To accomplish this, we resort to the nasty hack of doubling the
936 * region's cpp and halving its height.
938 region_width = ALIGN(width, 64);
939 region_height = ALIGN(ALIGN(height, 2) / 2, 64);
940 region_cpp = format / 4;
942 region_width = width;
943 region_height = height;
944 region_cpp = format / 8;
947 intelBuffer->region = intel_region_alloc(intelScreen,
954 if (intelBuffer->region == NULL) {
959 intel_region_flink(intelBuffer->region, &intelBuffer->base.name);
961 intelBuffer->base.attachment = attachment;
962 intelBuffer->base.cpp = intelBuffer->region->cpp;
963 intelBuffer->base.pitch =
964 intelBuffer->region->pitch * intelBuffer->region->cpp;
966 return &intelBuffer->base;
970 intelReleaseBuffer(__DRIscreen *screen, __DRIbuffer *buffer)
972 struct intel_buffer *intelBuffer = (struct intel_buffer *) buffer;
974 intel_region_release(&intelBuffer->region);
979 const struct __DriverAPIRec driDriverAPI = {
980 .InitScreen = intelInitScreen2,
981 .DestroyScreen = intelDestroyScreen,
982 .CreateContext = intelCreateContext,
983 .DestroyContext = intelDestroyContext,
984 .CreateBuffer = intelCreateBuffer,
985 .DestroyBuffer = intelDestroyBuffer,
986 .MakeCurrent = intelMakeCurrent,
987 .UnbindContext = intelUnbindContext,
988 .AllocateBuffer = intelAllocateBuffer,
989 .ReleaseBuffer = intelReleaseBuffer
992 /* This is the table of extensions that the loader will dlsym() for. */
993 PUBLIC const __DRIextension *__driDriverExtensions[] = {
994 &driCoreExtension.base,
995 &driDRI2Extension.base,