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;
553 struct gl_framebuffer *fb;
558 fb = CALLOC_STRUCT(gl_framebuffer);
562 _mesa_initialize_window_framebuffer(fb, mesaVis);
564 if (mesaVis->redBits == 5)
565 rgbFormat = MESA_FORMAT_RGB565;
566 else if (mesaVis->alphaBits == 0)
567 rgbFormat = MESA_FORMAT_XRGB8888;
569 rgbFormat = MESA_FORMAT_ARGB8888;
571 /* setup the hardware-based renderbuffers */
572 rb = intel_create_renderbuffer(rgbFormat);
573 _mesa_add_renderbuffer(fb, BUFFER_FRONT_LEFT, &rb->Base.Base);
575 if (mesaVis->doubleBufferMode) {
576 rb = intel_create_renderbuffer(rgbFormat);
577 _mesa_add_renderbuffer(fb, BUFFER_BACK_LEFT, &rb->Base.Base);
581 * Assert here that the gl_config has an expected depth/stencil bit
582 * combination: one of d24/s8, d16/s0, d0/s0. (See intelInitScreen2(),
583 * which constructs the advertised configs.)
585 if (mesaVis->depthBits == 24) {
586 assert(mesaVis->stencilBits == 8);
588 if (screen->hw_has_separate_stencil) {
589 rb = intel_create_private_renderbuffer(MESA_FORMAT_X8_Z24);
590 _mesa_add_renderbuffer(fb, BUFFER_DEPTH, &rb->Base.Base);
591 rb = intel_create_private_renderbuffer(MESA_FORMAT_S8);
592 _mesa_add_renderbuffer(fb, BUFFER_STENCIL, &rb->Base.Base);
595 * Use combined depth/stencil. Note that the renderbuffer is
596 * attached to two attachment points.
598 rb = intel_create_private_renderbuffer(MESA_FORMAT_S8_Z24);
599 _mesa_add_renderbuffer(fb, BUFFER_DEPTH, &rb->Base.Base);
600 _mesa_add_renderbuffer(fb, BUFFER_STENCIL, &rb->Base.Base);
603 else if (mesaVis->depthBits == 16) {
604 assert(mesaVis->stencilBits == 0);
605 rb = intel_create_private_renderbuffer(MESA_FORMAT_Z16);
606 _mesa_add_renderbuffer(fb, BUFFER_DEPTH, &rb->Base.Base);
609 assert(mesaVis->depthBits == 0);
610 assert(mesaVis->stencilBits == 0);
613 /* now add any/all software-based renderbuffers we may need */
614 _swrast_add_soft_renderbuffers(fb,
615 false, /* never sw color */
616 false, /* never sw depth */
617 false, /* never sw stencil */
618 mesaVis->accumRedBits > 0,
619 false, /* never sw alpha */
620 false /* never sw aux */ );
621 driDrawPriv->driverPrivate = fb;
627 intelDestroyBuffer(__DRIdrawable * driDrawPriv)
629 struct gl_framebuffer *fb = driDrawPriv->driverPrivate;
631 _mesa_reference_framebuffer(&fb, NULL);
634 /* There are probably better ways to do this, such as an
635 * init-designated function to register chipids and createcontext
639 i830CreateContext(const struct gl_config *mesaVis,
640 __DRIcontext *driContextPriv,
641 void *sharedContextPrivate);
644 i915CreateContext(int api,
645 const struct gl_config *mesaVis,
646 __DRIcontext *driContextPriv,
647 void *sharedContextPrivate);
649 brwCreateContext(int api,
650 const struct gl_config *mesaVis,
651 __DRIcontext *driContextPriv,
652 void *sharedContextPrivate);
655 intelCreateContext(gl_api api,
656 const struct gl_config * mesaVis,
657 __DRIcontext * driContextPriv,
658 unsigned major_version,
659 unsigned minor_version,
662 void *sharedContextPrivate)
664 __DRIscreen *sPriv = driContextPriv->driScreenPriv;
665 struct intel_screen *intelScreen = sPriv->driverPrivate;
666 bool success = false;
669 if (IS_9XX(intelScreen->deviceID)) {
670 if (!IS_965(intelScreen->deviceID)) {
671 success = i915CreateContext(api, mesaVis, driContextPriv,
672 sharedContextPrivate);
675 intelScreen->no_vbo = true;
676 success = i830CreateContext(mesaVis, driContextPriv,
677 sharedContextPrivate);
680 if (IS_965(intelScreen->deviceID))
681 success = brwCreateContext(api, mesaVis,
683 sharedContextPrivate);
687 struct gl_context *ctx =
688 (struct gl_context *) driContextPriv->driverPrivate;
690 _mesa_compute_version(ctx);
691 if (ctx->VersionMajor > major_version
692 || (ctx->VersionMajor == major_version
693 && ctx->VersionMinor >= minor_version)) {
697 *error = __DRI_CTX_ERROR_BAD_VERSION;
698 intelDestroyContext(driContextPriv);
700 *error = __DRI_CTX_ERROR_NO_MEMORY;
701 fprintf(stderr, "Unrecognized deviceID 0x%x\n", intelScreen->deviceID);
708 intel_init_bufmgr(struct intel_screen *intelScreen)
710 __DRIscreen *spriv = intelScreen->driScrnPriv;
713 intelScreen->no_hw = getenv("INTEL_NO_HW") != NULL;
715 intelScreen->bufmgr = intel_bufmgr_gem_init(spriv->fd, BATCH_SZ);
716 if (intelScreen->bufmgr == NULL) {
717 fprintf(stderr, "[%s:%u] Error initializing buffer manager.\n",
722 if (!intel_get_param(spriv, I915_PARAM_NUM_FENCES_AVAIL, &num_fences) ||
724 fprintf(stderr, "[%s: %u] Kernel 2.6.29 required.\n", __func__, __LINE__);
728 drm_intel_bufmgr_gem_enable_fenced_relocs(intelScreen->bufmgr);
730 intelScreen->named_regions = _mesa_NewHashTable();
732 intelScreen->relaxed_relocations = 0;
733 intelScreen->relaxed_relocations |=
734 intel_get_boolean(spriv, I915_PARAM_HAS_RELAXED_DELTA) << 0;
740 * Override intel_screen.hw_has_separate_stencil with environment variable
741 * INTEL_SEPARATE_STENCIL.
743 * Valid values for INTEL_SEPARATE_STENCIL are "0" and "1". If an invalid
744 * valid value is encountered, a warning is emitted and INTEL_SEPARATE_STENCIL
748 intel_override_separate_stencil(struct intel_screen *screen)
750 const char *s = getenv("INTEL_SEPARATE_STENCIL");
753 } else if (!strncmp("0", s, 2)) {
754 screen->hw_has_separate_stencil = false;
755 } else if (!strncmp("1", s, 2)) {
756 screen->hw_has_separate_stencil = true;
759 "warning: env variable INTEL_SEPARATE_STENCIL=\"%s\" has "
760 "invalid value and is ignored", s);
765 intel_detect_swizzling(struct intel_screen *screen)
767 drm_intel_bo *buffer;
768 unsigned long flags = 0;
769 unsigned long aligned_pitch;
770 uint32_t tiling = I915_TILING_X;
771 uint32_t swizzle_mode = 0;
773 buffer = drm_intel_bo_alloc_tiled(screen->bufmgr, "swizzle test",
775 &tiling, &aligned_pitch, flags);
779 drm_intel_bo_get_tiling(buffer, &tiling, &swizzle_mode);
780 drm_intel_bo_unreference(buffer);
782 if (swizzle_mode == I915_BIT_6_SWIZZLE_NONE)
789 * This is the driver specific part of the createNewScreen entry point.
790 * Called when using DRI2.
792 * \return the struct gl_config supported by this driver
795 __DRIconfig **intelInitScreen2(__DRIscreen *psp)
797 struct intel_screen *intelScreen;
800 unsigned int api_mask;
802 static const GLenum back_buffer_modes[] = {
803 GLX_NONE, GLX_SWAP_UNDEFINED_OML, GLX_SWAP_COPY_OML
805 uint8_t depth_bits[4], stencil_bits[4], msaa_samples_array[1];
807 __DRIconfig **configs = NULL;
809 if (psp->dri2.loader->base.version <= 2 ||
810 psp->dri2.loader->getBuffersWithFormat == NULL) {
812 "\nERROR! DRI2 loader with getBuffersWithFormat() "
813 "support required\n");
817 /* Allocate the private area */
818 intelScreen = CALLOC(sizeof *intelScreen);
820 fprintf(stderr, "\nERROR! Allocating private area failed\n");
823 /* parse information in __driConfigOptions */
824 driParseOptionInfo(&intelScreen->optionCache,
825 __driConfigOptions, __driNConfigOptions);
827 intelScreen->driScrnPriv = psp;
828 psp->driverPrivate = (void *) intelScreen;
830 if (!intel_init_bufmgr(intelScreen))
833 intelScreen->deviceID = drm_intel_bufmgr_gem_get_devid(intelScreen->bufmgr);
835 intelScreen->kernel_has_gen7_sol_reset =
836 intel_get_boolean(intelScreen->driScrnPriv,
837 I915_PARAM_HAS_GEN7_SOL_RESET);
839 if (IS_GEN7(intelScreen->deviceID)) {
840 intelScreen->gen = 7;
841 } else if (IS_GEN6(intelScreen->deviceID)) {
842 intelScreen->gen = 6;
843 } else if (IS_GEN5(intelScreen->deviceID)) {
844 intelScreen->gen = 5;
845 } else if (IS_965(intelScreen->deviceID)) {
846 intelScreen->gen = 4;
847 } else if (IS_9XX(intelScreen->deviceID)) {
848 intelScreen->gen = 3;
850 intelScreen->gen = 2;
853 intelScreen->hw_has_separate_stencil = intelScreen->gen >= 6;
854 intelScreen->hw_must_use_separate_stencil = intelScreen->gen >= 7;
857 bool success = intel_get_param(intelScreen->driScrnPriv, I915_PARAM_HAS_LLC,
859 if (success && has_llc)
860 intelScreen->hw_has_llc = true;
861 else if (!success && intelScreen->gen >= 6)
862 intelScreen->hw_has_llc = true;
864 intel_override_separate_stencil(intelScreen);
866 api_mask = (1 << __DRI_API_OPENGL);
868 api_mask |= (1 << __DRI_API_GLES);
871 api_mask |= (1 << __DRI_API_GLES2);
874 if (IS_9XX(intelScreen->deviceID) || IS_965(intelScreen->deviceID))
875 psp->api_mask = api_mask;
877 intelScreen->hw_has_swizzling = intel_detect_swizzling(intelScreen);
879 psp->extensions = intelScreenExtensions;
881 msaa_samples_array[0] = 0;
883 fb_format[0] = GL_RGB;
884 fb_type[0] = GL_UNSIGNED_SHORT_5_6_5;
886 fb_format[1] = GL_BGR;
887 fb_type[1] = GL_UNSIGNED_INT_8_8_8_8_REV;
889 fb_format[2] = GL_BGRA;
890 fb_type[2] = GL_UNSIGNED_INT_8_8_8_8_REV;
895 /* Generate a rich set of useful configs that do not include an
896 * accumulation buffer.
898 for (color = 0; color < ARRAY_SIZE(fb_format); color++) {
899 __DRIconfig **new_configs;
902 /* Starting with DRI2 protocol version 1.1 we can request a depth/stencil
903 * buffer that has a diffferent number of bits per pixel than the color
904 * buffer. This isn't yet supported here.
906 if (fb_type[color] == GL_UNSIGNED_SHORT_5_6_5) {
916 new_configs = driCreateConfigs(fb_format[color], fb_type[color],
921 ARRAY_SIZE(back_buffer_modes),
923 ARRAY_SIZE(msaa_samples_array),
926 configs = new_configs;
928 configs = driConcatConfigs(configs, new_configs);
931 /* Generate the minimum possible set of configs that include an
932 * accumulation buffer.
934 for (color = 0; color < ARRAY_SIZE(fb_format); color++) {
935 __DRIconfig **new_configs;
937 if (fb_type[color] == GL_UNSIGNED_SHORT_5_6_5) {
945 new_configs = driCreateConfigs(fb_format[color], fb_type[color],
946 depth_bits, stencil_bits, 1,
947 back_buffer_modes + 1, 1,
948 msaa_samples_array, 1,
951 configs = new_configs;
953 configs = driConcatConfigs(configs, new_configs);
956 if (configs == NULL) {
957 fprintf(stderr, "[%s:%u] Error creating FBConfig!\n", __func__,
962 return (const __DRIconfig **)configs;
965 struct intel_buffer {
967 struct intel_region *region;
971 intelAllocateBuffer(__DRIscreen *screen,
972 unsigned attachment, unsigned format,
973 int width, int height)
975 struct intel_buffer *intelBuffer;
976 struct intel_screen *intelScreen = screen->driverPrivate;
978 assert(attachment == __DRI_BUFFER_FRONT_LEFT ||
979 attachment == __DRI_BUFFER_BACK_LEFT);
981 intelBuffer = CALLOC(sizeof *intelBuffer);
982 if (intelBuffer == NULL)
985 /* The front and back buffers are color buffers, which are X tiled. */
986 intelBuffer->region = intel_region_alloc(intelScreen,
993 if (intelBuffer->region == NULL) {
998 intel_region_flink(intelBuffer->region, &intelBuffer->base.name);
1000 intelBuffer->base.attachment = attachment;
1001 intelBuffer->base.cpp = intelBuffer->region->cpp;
1002 intelBuffer->base.pitch =
1003 intelBuffer->region->pitch * intelBuffer->region->cpp;
1005 return &intelBuffer->base;
1009 intelReleaseBuffer(__DRIscreen *screen, __DRIbuffer *buffer)
1011 struct intel_buffer *intelBuffer = (struct intel_buffer *) buffer;
1013 intel_region_release(&intelBuffer->region);
1018 const struct __DriverAPIRec driDriverAPI = {
1019 .InitScreen = intelInitScreen2,
1020 .DestroyScreen = intelDestroyScreen,
1021 .CreateContext = intelCreateContext,
1022 .DestroyContext = intelDestroyContext,
1023 .CreateBuffer = intelCreateBuffer,
1024 .DestroyBuffer = intelDestroyBuffer,
1025 .MakeCurrent = intelMakeCurrent,
1026 .UnbindContext = intelUnbindContext,
1027 .AllocateBuffer = intelAllocateBuffer,
1028 .ReleaseBuffer = intelReleaseBuffer
1031 /* This is the table of extensions that the loader will dlsym() for. */
1032 PUBLIC const __DRIextension *__driDriverExtensions[] = {
1033 &driCoreExtension.base,
1034 &driDRI2Extension.base,