Merge remote-tracking branch 'origin/master' into pipe-video
[mesa.git] / src / mesa / drivers / dri / intel / intel_screen.c
1 /**************************************************************************
2 *
3 * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
4 * All Rights Reserved.
5 *
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:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
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.
25 *
26 **************************************************************************/
27
28 #include <errno.h>
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
37 #include "utils.h"
38 #include "xmlpool.h"
39
40 PUBLIC const char __driConfigOptions[] =
41 DRI_CONF_BEGIN
42 DRI_CONF_SECTION_PERFORMANCE
43 DRI_CONF_VBLANK_MODE(DRI_CONF_VBLANK_ALWAYS_SYNC)
44 /* Options correspond to DRI_CONF_BO_REUSE_DISABLED,
45 * DRI_CONF_BO_REUSE_ALL
46 */
47 DRI_CONF_OPT_BEGIN_V(bo_reuse, enum, 1, "0:1")
48 DRI_CONF_DESC_BEGIN(en, "Buffer object reuse")
49 DRI_CONF_ENUM(0, "Disable buffer object reuse")
50 DRI_CONF_ENUM(1, "Enable reuse of all sizes of buffer objects")
51 DRI_CONF_DESC_END
52 DRI_CONF_OPT_END
53
54 DRI_CONF_OPT_BEGIN(texture_tiling, bool, true)
55 DRI_CONF_DESC(en, "Enable texture tiling")
56 DRI_CONF_OPT_END
57
58 DRI_CONF_OPT_BEGIN(early_z, bool, false)
59 DRI_CONF_DESC(en, "Enable early Z in classic mode (unstable, 945-only).")
60 DRI_CONF_OPT_END
61
62 DRI_CONF_OPT_BEGIN(fragment_shader, bool, true)
63 DRI_CONF_DESC(en, "Enable limited ARB_fragment_shader support on 915/945.")
64 DRI_CONF_OPT_END
65
66 DRI_CONF_SECTION_END
67 DRI_CONF_SECTION_QUALITY
68 DRI_CONF_FORCE_S3TC_ENABLE(false)
69 DRI_CONF_ALLOW_LARGE_TEXTURES(2)
70 DRI_CONF_SECTION_END
71 DRI_CONF_SECTION_DEBUG
72 DRI_CONF_NO_RAST(false)
73 DRI_CONF_ALWAYS_FLUSH_BATCH(false)
74 DRI_CONF_ALWAYS_FLUSH_CACHE(false)
75
76 DRI_CONF_OPT_BEGIN(stub_occlusion_query, bool, false)
77 DRI_CONF_DESC(en, "Enable stub ARB_occlusion_query support on 915/945.")
78 DRI_CONF_OPT_END
79 DRI_CONF_SECTION_END
80 DRI_CONF_END;
81
82 const GLuint __driNConfigOptions = 11;
83
84 #include "intel_batchbuffer.h"
85 #include "intel_buffers.h"
86 #include "intel_bufmgr.h"
87 #include "intel_chipset.h"
88 #include "intel_fbo.h"
89 #include "intel_screen.h"
90 #include "intel_tex.h"
91 #include "intel_regions.h"
92
93 #include "i915_drm.h"
94
95 #ifdef USE_NEW_INTERFACE
96 static PFNGLXCREATECONTEXTMODES create_context_modes = NULL;
97 #endif /*USE_NEW_INTERFACE */
98
99 static const __DRItexBufferExtension intelTexBufferExtension = {
100 { __DRI_TEX_BUFFER, __DRI_TEX_BUFFER_VERSION },
101 intelSetTexBuffer,
102 intelSetTexBuffer2,
103 };
104
105 static void
106 intelDRI2Flush(__DRIdrawable *drawable)
107 {
108 GET_CURRENT_CONTEXT(ctx);
109 struct intel_context *intel = intel_context(ctx);
110
111 if (intel->gen < 4)
112 INTEL_FIREVERTICES(intel);
113
114 intel->need_throttle = GL_TRUE;
115
116 if (intel->batch.used)
117 intel_batchbuffer_flush(intel);
118 }
119
120 static const struct __DRI2flushExtensionRec intelFlushExtension = {
121 { __DRI2_FLUSH, __DRI2_FLUSH_VERSION },
122 intelDRI2Flush,
123 dri2InvalidateDrawable,
124 };
125
126 static __DRIimage *
127 intel_create_image_from_name(__DRIscreen *screen,
128 int width, int height, int format,
129 int name, int pitch, void *loaderPrivate)
130 {
131 struct intel_screen *intelScreen = screen->private;
132 __DRIimage *image;
133 int cpp;
134
135 image = CALLOC(sizeof *image);
136 if (image == NULL)
137 return NULL;
138
139 switch (format) {
140 case __DRI_IMAGE_FORMAT_RGB565:
141 image->format = MESA_FORMAT_RGB565;
142 image->internal_format = GL_RGB;
143 image->data_type = GL_UNSIGNED_BYTE;
144 break;
145 case __DRI_IMAGE_FORMAT_XRGB8888:
146 image->format = MESA_FORMAT_XRGB8888;
147 image->internal_format = GL_RGB;
148 image->data_type = GL_UNSIGNED_BYTE;
149 break;
150 case __DRI_IMAGE_FORMAT_ARGB8888:
151 image->format = MESA_FORMAT_ARGB8888;
152 image->internal_format = GL_RGBA;
153 image->data_type = GL_UNSIGNED_BYTE;
154 break;
155 default:
156 free(image);
157 return NULL;
158 }
159
160 image->data = loaderPrivate;
161 cpp = _mesa_get_format_bytes(image->format);
162
163 image->region = intel_region_alloc_for_handle(intelScreen,
164 cpp, width, height,
165 pitch, name, "image");
166 if (image->region == NULL) {
167 FREE(image);
168 return NULL;
169 }
170
171 return image;
172 }
173
174 static __DRIimage *
175 intel_create_image_from_renderbuffer(__DRIcontext *context,
176 int renderbuffer, void *loaderPrivate)
177 {
178 __DRIimage *image;
179 struct intel_context *intel = context->driverPrivate;
180 struct gl_renderbuffer *rb;
181 struct intel_renderbuffer *irb;
182
183 rb = _mesa_lookup_renderbuffer(&intel->ctx, renderbuffer);
184 if (!rb) {
185 _mesa_error(&intel->ctx,
186 GL_INVALID_OPERATION, "glRenderbufferExternalMESA");
187 return NULL;
188 }
189
190 irb = intel_renderbuffer(rb);
191 image = CALLOC(sizeof *image);
192 if (image == NULL)
193 return NULL;
194
195 image->internal_format = rb->InternalFormat;
196 image->format = rb->Format;
197 image->data_type = rb->DataType;
198 image->data = loaderPrivate;
199 intel_region_reference(&image->region, irb->region);
200
201 return image;
202 }
203
204 static void
205 intel_destroy_image(__DRIimage *image)
206 {
207 intel_region_release(&image->region);
208 FREE(image);
209 }
210
211 static __DRIimage *
212 intel_create_image(__DRIscreen *screen,
213 int width, int height, int format,
214 unsigned int use,
215 void *loaderPrivate)
216 {
217 __DRIimage *image;
218 struct intel_screen *intelScreen = screen->private;
219 uint32_t tiling;
220 int cpp;
221
222 tiling = I915_TILING_X;
223 if (use & __DRI_IMAGE_USE_CURSOR) {
224 if (width != 64 || height != 64)
225 return NULL;
226 tiling = I915_TILING_NONE;
227 }
228
229 image = CALLOC(sizeof *image);
230 if (image == NULL)
231 return NULL;
232
233 switch (format) {
234 case __DRI_IMAGE_FORMAT_RGB565:
235 image->format = MESA_FORMAT_RGB565;
236 image->internal_format = GL_RGB;
237 image->data_type = GL_UNSIGNED_BYTE;
238 break;
239 case __DRI_IMAGE_FORMAT_XRGB8888:
240 image->format = MESA_FORMAT_XRGB8888;
241 image->internal_format = GL_RGB;
242 image->data_type = GL_UNSIGNED_BYTE;
243 break;
244 case __DRI_IMAGE_FORMAT_ARGB8888:
245 image->format = MESA_FORMAT_ARGB8888;
246 image->internal_format = GL_RGBA;
247 image->data_type = GL_UNSIGNED_BYTE;
248 break;
249 default:
250 free(image);
251 return NULL;
252 }
253
254 image->data = loaderPrivate;
255 cpp = _mesa_get_format_bytes(image->format);
256
257 image->region =
258 intel_region_alloc(intelScreen, tiling,
259 cpp, width, height, GL_TRUE);
260 if (image->region == NULL) {
261 FREE(image);
262 return NULL;
263 }
264
265 return image;
266 }
267
268 static GLboolean
269 intel_query_image(__DRIimage *image, int attrib, int *value)
270 {
271 switch (attrib) {
272 case __DRI_IMAGE_ATTRIB_STRIDE:
273 *value = image->region->pitch * image->region->cpp;
274 return GL_TRUE;
275 case __DRI_IMAGE_ATTRIB_HANDLE:
276 *value = image->region->buffer->handle;
277 return GL_TRUE;
278 case __DRI_IMAGE_ATTRIB_NAME:
279 return intel_region_flink(image->region, (uint32_t *) value);
280 default:
281 return GL_FALSE;
282 }
283 }
284
285 static struct __DRIimageExtensionRec intelImageExtension = {
286 { __DRI_IMAGE, __DRI_IMAGE_VERSION },
287 intel_create_image_from_name,
288 intel_create_image_from_renderbuffer,
289 intel_destroy_image,
290 intel_create_image,
291 intel_query_image
292 };
293
294 static const __DRIextension *intelScreenExtensions[] = {
295 &driReadDrawableExtension,
296 &intelTexBufferExtension.base,
297 &intelFlushExtension.base,
298 &intelImageExtension.base,
299 &dri2ConfigQueryExtension.base,
300 NULL
301 };
302
303 static GLboolean
304 intel_get_param(__DRIscreen *psp, int param, int *value)
305 {
306 int ret;
307 struct drm_i915_getparam gp;
308
309 gp.param = param;
310 gp.value = value;
311
312 ret = drmCommandWriteRead(psp->fd, DRM_I915_GETPARAM, &gp, sizeof(gp));
313 if (ret) {
314 if (ret != -EINVAL)
315 _mesa_warning(NULL, "drm_i915_getparam: %d", ret);
316 return GL_FALSE;
317 }
318
319 return GL_TRUE;
320 }
321
322 static GLboolean
323 intel_get_boolean(__DRIscreen *psp, int param)
324 {
325 int value = 0;
326 return intel_get_param(psp, param, &value) && value;
327 }
328
329 static void
330 nop_callback(GLuint key, void *data, void *userData)
331 {
332 }
333
334 static void
335 intelDestroyScreen(__DRIscreen * sPriv)
336 {
337 struct intel_screen *intelScreen = sPriv->private;
338
339 dri_bufmgr_destroy(intelScreen->bufmgr);
340 driDestroyOptionInfo(&intelScreen->optionCache);
341
342 /* Some regions may still have references to them at this point, so
343 * flush the hash table to prevent _mesa_DeleteHashTable() from
344 * complaining about the hash not being empty; */
345 _mesa_HashDeleteAll(intelScreen->named_regions, nop_callback, NULL);
346 _mesa_DeleteHashTable(intelScreen->named_regions);
347
348 FREE(intelScreen);
349 sPriv->private = NULL;
350 }
351
352
353 /**
354 * This is called when we need to set up GL rendering to a new X window.
355 */
356 static GLboolean
357 intelCreateBuffer(__DRIscreen * driScrnPriv,
358 __DRIdrawable * driDrawPriv,
359 const struct gl_config * mesaVis, GLboolean isPixmap)
360 {
361 struct intel_renderbuffer *rb;
362 struct intel_screen *screen = (struct intel_screen*) driScrnPriv->private;
363
364 if (isPixmap) {
365 return GL_FALSE; /* not implemented */
366 }
367 else {
368 gl_format rgbFormat;
369
370 struct gl_framebuffer *fb = CALLOC_STRUCT(gl_framebuffer);
371
372 if (!fb)
373 return GL_FALSE;
374
375 _mesa_initialize_window_framebuffer(fb, mesaVis);
376
377 if (mesaVis->redBits == 5)
378 rgbFormat = MESA_FORMAT_RGB565;
379 else if (mesaVis->alphaBits == 0)
380 rgbFormat = MESA_FORMAT_XRGB8888;
381 else
382 rgbFormat = MESA_FORMAT_ARGB8888;
383
384 /* setup the hardware-based renderbuffers */
385 rb = intel_create_renderbuffer(rgbFormat);
386 _mesa_add_renderbuffer(fb, BUFFER_FRONT_LEFT, &rb->Base);
387
388 if (mesaVis->doubleBufferMode) {
389 rb = intel_create_renderbuffer(rgbFormat);
390 _mesa_add_renderbuffer(fb, BUFFER_BACK_LEFT, &rb->Base);
391 }
392
393 /*
394 * Assert here that the gl_config has an expected depth/stencil bit
395 * combination: one of d24/s8, d16/s0, d0/s0. (See intelInitScreen2(),
396 * which constructs the advertised configs.)
397 */
398 if (mesaVis->depthBits == 24) {
399 assert(mesaVis->stencilBits == 8);
400
401 if (screen->hw_has_separate_stencil
402 && screen->dri2_has_hiz != INTEL_DRI2_HAS_HIZ_FALSE) {
403 /*
404 * Request a separate stencil buffer even if we do not yet know if
405 * the screen supports it. (See comments for
406 * enum intel_dri2_has_hiz).
407 */
408 rb = intel_create_renderbuffer(MESA_FORMAT_X8_Z24);
409 _mesa_add_renderbuffer(fb, BUFFER_DEPTH, &rb->Base);
410 rb = intel_create_renderbuffer(MESA_FORMAT_S8);
411 _mesa_add_renderbuffer(fb, BUFFER_STENCIL, &rb->Base);
412 } else {
413 /*
414 * Use combined depth/stencil. Note that the renderbuffer is
415 * attached to two attachment points.
416 */
417 rb = intel_create_renderbuffer(MESA_FORMAT_S8_Z24);
418 _mesa_add_renderbuffer(fb, BUFFER_DEPTH, &rb->Base);
419 _mesa_add_renderbuffer(fb, BUFFER_STENCIL, &rb->Base);
420 }
421 }
422 else if (mesaVis->depthBits == 16) {
423 assert(mesaVis->stencilBits == 0);
424 /* just 16-bit depth buffer, no hw stencil */
425 struct intel_renderbuffer *depthRb
426 = intel_create_renderbuffer(MESA_FORMAT_Z16);
427 _mesa_add_renderbuffer(fb, BUFFER_DEPTH, &depthRb->Base);
428 }
429 else {
430 assert(mesaVis->depthBits == 0);
431 assert(mesaVis->stencilBits == 0);
432 }
433
434 /* now add any/all software-based renderbuffers we may need */
435 _mesa_add_soft_renderbuffers(fb,
436 GL_FALSE, /* never sw color */
437 GL_FALSE, /* never sw depth */
438 GL_FALSE, /* never sw stencil */
439 mesaVis->accumRedBits > 0,
440 GL_FALSE, /* never sw alpha */
441 GL_FALSE /* never sw aux */ );
442 driDrawPriv->driverPrivate = fb;
443
444 return GL_TRUE;
445 }
446 }
447
448 static void
449 intelDestroyBuffer(__DRIdrawable * driDrawPriv)
450 {
451 struct gl_framebuffer *fb = driDrawPriv->driverPrivate;
452
453 _mesa_reference_framebuffer(&fb, NULL);
454 }
455
456 /* There are probably better ways to do this, such as an
457 * init-designated function to register chipids and createcontext
458 * functions.
459 */
460 extern GLboolean i830CreateContext(const struct gl_config * mesaVis,
461 __DRIcontext * driContextPriv,
462 void *sharedContextPrivate);
463
464 extern GLboolean i915CreateContext(int api,
465 const struct gl_config * mesaVis,
466 __DRIcontext * driContextPriv,
467 void *sharedContextPrivate);
468 extern GLboolean brwCreateContext(int api,
469 const struct gl_config * mesaVis,
470 __DRIcontext * driContextPriv,
471 void *sharedContextPrivate);
472
473 static GLboolean
474 intelCreateContext(gl_api api,
475 const struct gl_config * mesaVis,
476 __DRIcontext * driContextPriv,
477 void *sharedContextPrivate)
478 {
479 __DRIscreen *sPriv = driContextPriv->driScreenPriv;
480 struct intel_screen *intelScreen = sPriv->private;
481
482 #ifdef I915
483 if (IS_9XX(intelScreen->deviceID)) {
484 if (!IS_965(intelScreen->deviceID)) {
485 return i915CreateContext(api, mesaVis, driContextPriv,
486 sharedContextPrivate);
487 }
488 } else {
489 intelScreen->no_vbo = GL_TRUE;
490 return i830CreateContext(mesaVis, driContextPriv, sharedContextPrivate);
491 }
492 #else
493 if (IS_965(intelScreen->deviceID))
494 return brwCreateContext(api, mesaVis,
495 driContextPriv, sharedContextPrivate);
496 #endif
497 fprintf(stderr, "Unrecognized deviceID 0x%x\n", intelScreen->deviceID);
498 return GL_FALSE;
499 }
500
501 static GLboolean
502 intel_init_bufmgr(struct intel_screen *intelScreen)
503 {
504 __DRIscreen *spriv = intelScreen->driScrnPriv;
505 int num_fences = 0;
506
507 intelScreen->no_hw = (getenv("INTEL_NO_HW") != NULL ||
508 getenv("INTEL_DEVID_OVERRIDE") != NULL);
509
510 intelScreen->bufmgr = intel_bufmgr_gem_init(spriv->fd, BATCH_SZ);
511 if (intelScreen->bufmgr == NULL) {
512 fprintf(stderr, "[%s:%u] Error initializing buffer manager.\n",
513 __func__, __LINE__);
514 return GL_FALSE;
515 }
516
517 if (!intel_get_param(spriv, I915_PARAM_NUM_FENCES_AVAIL, &num_fences) ||
518 num_fences == 0) {
519 fprintf(stderr, "[%s: %u] Kernel 2.6.29 required.\n", __func__, __LINE__);
520 return GL_FALSE;
521 }
522
523 drm_intel_bufmgr_gem_enable_fenced_relocs(intelScreen->bufmgr);
524
525 intelScreen->named_regions = _mesa_NewHashTable();
526
527 intelScreen->relaxed_relocations = 0;
528 intelScreen->relaxed_relocations |=
529 intel_get_boolean(spriv, I915_PARAM_HAS_RELAXED_DELTA) << 0;
530
531 return GL_TRUE;
532 }
533
534 /**
535 * Override intel_screen.hw_has_hiz with environment variable INTEL_HIZ.
536 *
537 * Valid values for INTEL_HIZ are "0" and "1". If an invalid valid value is
538 * encountered, a warning is emitted and INTEL_HIZ is ignored.
539 */
540 static void
541 intel_override_hiz(struct intel_screen *intel)
542 {
543 const char *s = getenv("INTEL_HIZ");
544 if (!s) {
545 return;
546 } else if (!strncmp("0", s, 2)) {
547 intel->hw_has_hiz = false;
548 } else if (!strncmp("1", s, 2)) {
549 intel->hw_has_hiz = true;
550 } else {
551 fprintf(stderr,
552 "warning: env variable INTEL_HIZ=\"%s\" has invalid value "
553 "and is ignored", s);
554 }
555 }
556
557 /**
558 * Override intel_screen.hw_has_separate_stencil with environment variable
559 * INTEL_SEPARATE_STENCIL.
560 *
561 * Valid values for INTEL_SEPARATE_STENCIL are "0" and "1". If an invalid
562 * valid value is encountered, a warning is emitted and INTEL_SEPARATE_STENCIL
563 * is ignored.
564 */
565 static void
566 intel_override_separate_stencil(struct intel_screen *screen)
567 {
568 const char *s = getenv("INTEL_SEPARATE_STENCIL");
569 if (!s) {
570 return;
571 } else if (!strncmp("0", s, 2)) {
572 screen->hw_has_separate_stencil = false;
573 } else if (!strncmp("1", s, 2)) {
574 screen->hw_has_separate_stencil = true;
575 } else {
576 fprintf(stderr,
577 "warning: env variable INTEL_SEPARATE_STENCIL=\"%s\" has "
578 "invalid value and is ignored", s);
579 }
580 }
581
582 /**
583 * This is the driver specific part of the createNewScreen entry point.
584 * Called when using DRI2.
585 *
586 * \return the struct gl_config supported by this driver
587 */
588 static const
589 __DRIconfig **intelInitScreen2(__DRIscreen *psp)
590 {
591 struct intel_screen *intelScreen;
592 GLenum fb_format[3];
593 GLenum fb_type[3];
594 unsigned int api_mask;
595 char *devid_override;
596
597 static const GLenum back_buffer_modes[] = {
598 GLX_NONE, GLX_SWAP_UNDEFINED_OML, GLX_SWAP_COPY_OML
599 };
600 uint8_t depth_bits[4], stencil_bits[4], msaa_samples_array[1];
601 int color;
602 __DRIconfig **configs = NULL;
603
604 /* Allocate the private area */
605 intelScreen = CALLOC(sizeof *intelScreen);
606 if (!intelScreen) {
607 fprintf(stderr, "\nERROR! Allocating private area failed\n");
608 return GL_FALSE;
609 }
610 /* parse information in __driConfigOptions */
611 driParseOptionInfo(&intelScreen->optionCache,
612 __driConfigOptions, __driNConfigOptions);
613
614 intelScreen->driScrnPriv = psp;
615 psp->private = (void *) intelScreen;
616
617 /* Determine chipset ID */
618 if (!intel_get_param(psp, I915_PARAM_CHIPSET_ID,
619 &intelScreen->deviceID))
620 return GL_FALSE;
621
622 /* Allow an override of the device ID for the purpose of making the
623 * driver produce dumps for debugging of new chipset enablement.
624 * This implies INTEL_NO_HW, to avoid programming your actual GPU
625 * incorrectly.
626 */
627 devid_override = getenv("INTEL_DEVID_OVERRIDE");
628 if (devid_override) {
629 intelScreen->deviceID = strtod(devid_override, NULL);
630 }
631
632 if (IS_GEN7(intelScreen->deviceID)) {
633 intelScreen->gen = 7;
634 } else if (IS_GEN6(intelScreen->deviceID)) {
635 intelScreen->gen = 6;
636 } else if (IS_GEN5(intelScreen->deviceID)) {
637 intelScreen->gen = 5;
638 } else if (IS_965(intelScreen->deviceID)) {
639 intelScreen->gen = 4;
640 } else if (IS_9XX(intelScreen->deviceID)) {
641 intelScreen->gen = 3;
642 } else {
643 intelScreen->gen = 2;
644 }
645
646 /*
647 * FIXME: The hiz and separate stencil fields need updating once the
648 * FIXME: features are completely implemented for a given chipset.
649 */
650 intelScreen->hw_has_separate_stencil = intelScreen->gen >= 7;
651 intelScreen->hw_must_use_separate_stencil = intelScreen->gen >= 7;
652 intelScreen->hw_has_hiz = false;
653 intelScreen->dri2_has_hiz = INTEL_DRI2_HAS_HIZ_UNKNOWN;
654
655 intel_override_hiz(intelScreen);
656 intel_override_separate_stencil(intelScreen);
657
658 api_mask = (1 << __DRI_API_OPENGL);
659 #if FEATURE_ES1
660 api_mask |= (1 << __DRI_API_GLES);
661 #endif
662 #if FEATURE_ES2
663 api_mask |= (1 << __DRI_API_GLES2);
664 #endif
665
666 if (IS_9XX(intelScreen->deviceID) || IS_965(intelScreen->deviceID))
667 psp->api_mask = api_mask;
668
669 if (!intel_init_bufmgr(intelScreen))
670 return GL_FALSE;
671
672 psp->extensions = intelScreenExtensions;
673
674 msaa_samples_array[0] = 0;
675
676 fb_format[0] = GL_RGB;
677 fb_type[0] = GL_UNSIGNED_SHORT_5_6_5;
678
679 fb_format[1] = GL_BGR;
680 fb_type[1] = GL_UNSIGNED_INT_8_8_8_8_REV;
681
682 fb_format[2] = GL_BGRA;
683 fb_type[2] = GL_UNSIGNED_INT_8_8_8_8_REV;
684
685 depth_bits[0] = 0;
686 stencil_bits[0] = 0;
687
688 /* Generate a rich set of useful configs that do not include an
689 * accumulation buffer.
690 */
691 for (color = 0; color < ARRAY_SIZE(fb_format); color++) {
692 __DRIconfig **new_configs;
693 int depth_factor;
694
695 /* Starting with DRI2 protocol version 1.1 we can request a depth/stencil
696 * buffer that has a diffferent number of bits per pixel than the color
697 * buffer. This isn't yet supported here.
698 */
699 if (fb_type[color] == GL_UNSIGNED_SHORT_5_6_5) {
700 depth_bits[1] = 16;
701 stencil_bits[1] = 0;
702 } else {
703 depth_bits[1] = 24;
704 stencil_bits[1] = 8;
705 }
706
707 depth_factor = 2;
708
709 new_configs = driCreateConfigs(fb_format[color], fb_type[color],
710 depth_bits,
711 stencil_bits,
712 depth_factor,
713 back_buffer_modes,
714 ARRAY_SIZE(back_buffer_modes),
715 msaa_samples_array,
716 ARRAY_SIZE(msaa_samples_array),
717 GL_FALSE);
718 if (configs == NULL)
719 configs = new_configs;
720 else
721 configs = driConcatConfigs(configs, new_configs);
722 }
723
724 /* Generate the minimum possible set of configs that include an
725 * accumulation buffer.
726 */
727 for (color = 0; color < ARRAY_SIZE(fb_format); color++) {
728 __DRIconfig **new_configs;
729
730 if (fb_type[color] == GL_UNSIGNED_SHORT_5_6_5) {
731 depth_bits[0] = 16;
732 stencil_bits[0] = 0;
733 } else {
734 depth_bits[0] = 24;
735 stencil_bits[0] = 8;
736 }
737
738 new_configs = driCreateConfigs(fb_format[color], fb_type[color],
739 depth_bits, stencil_bits, 1,
740 back_buffer_modes + 1, 1,
741 msaa_samples_array, 1,
742 GL_TRUE);
743 if (configs == NULL)
744 configs = new_configs;
745 else
746 configs = driConcatConfigs(configs, new_configs);
747 }
748
749 if (configs == NULL) {
750 fprintf(stderr, "[%s:%u] Error creating FBConfig!\n", __func__,
751 __LINE__);
752 return NULL;
753 }
754
755 return (const __DRIconfig **)configs;
756 }
757
758 struct intel_buffer {
759 __DRIbuffer base;
760 struct intel_region *region;
761 };
762
763 static __DRIbuffer *
764 intelAllocateBuffer(__DRIscreen *screen,
765 unsigned attachment, unsigned format,
766 int width, int height)
767 {
768 struct intel_buffer *intelBuffer;
769 struct intel_screen *intelScreen = screen->private;
770 uint32_t tiling;
771
772 intelBuffer = CALLOC(sizeof *intelBuffer);
773 if (intelBuffer == NULL)
774 return NULL;
775
776 if ((attachment == __DRI_BUFFER_DEPTH ||
777 attachment == __DRI_BUFFER_STENCIL ||
778 attachment == __DRI_BUFFER_DEPTH_STENCIL) &&
779 intelScreen->gen >= 4)
780 tiling = I915_TILING_Y;
781 else
782 tiling = I915_TILING_X;
783
784 intelBuffer->region = intel_region_alloc(intelScreen, tiling,
785 format / 8, width, height, GL_TRUE);
786
787 if (intelBuffer->region == NULL) {
788 FREE(intelBuffer);
789 return NULL;
790 }
791
792 intel_region_flink(intelBuffer->region, &intelBuffer->base.name);
793
794 intelBuffer->base.attachment = attachment;
795 intelBuffer->base.cpp = intelBuffer->region->cpp;
796 intelBuffer->base.pitch =
797 intelBuffer->region->pitch * intelBuffer->region->cpp;
798
799 return &intelBuffer->base;
800 }
801
802 static void
803 intelReleaseBuffer(__DRIscreen *screen, __DRIbuffer *buffer)
804 {
805 struct intel_buffer *intelBuffer = (struct intel_buffer *) buffer;
806
807 intel_region_release(&intelBuffer->region);
808 free(intelBuffer);
809 }
810
811
812 const struct __DriverAPIRec driDriverAPI = {
813 .DestroyScreen = intelDestroyScreen,
814 .CreateContext = intelCreateContext,
815 .DestroyContext = intelDestroyContext,
816 .CreateBuffer = intelCreateBuffer,
817 .DestroyBuffer = intelDestroyBuffer,
818 .MakeCurrent = intelMakeCurrent,
819 .UnbindContext = intelUnbindContext,
820 .InitScreen2 = intelInitScreen2,
821 .AllocateBuffer = intelAllocateBuffer,
822 .ReleaseBuffer = intelReleaseBuffer
823 };
824
825 /* This is the table of extensions that the loader will dlsym() for. */
826 PUBLIC const __DRIextension *__driDriverExtensions[] = {
827 &driCoreExtension.base,
828 &driDRI2Extension.base,
829 NULL
830 };