Merge branch 'mesa_7_5_branch'
[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 "main/glheader.h"
29 #include "main/context.h"
30 #include "main/framebuffer.h"
31 #include "main/renderbuffer.h"
32
33 #include "utils.h"
34 #include "vblank.h"
35 #include "xmlpool.h"
36
37 #include "intel_batchbuffer.h"
38 #include "intel_buffers.h"
39 #include "intel_bufmgr.h"
40 #include "intel_chipset.h"
41 #include "intel_extensions.h"
42 #include "intel_fbo.h"
43 #include "intel_regions.h"
44 #include "intel_swapbuffers.h"
45 #include "intel_screen.h"
46 #include "intel_span.h"
47 #include "intel_tex.h"
48
49 #include "i915_drm.h"
50 #include "i830_dri.h"
51
52 #define DRI_CONF_TEXTURE_TILING(def) \
53 DRI_CONF_OPT_BEGIN(texture_tiling, bool, def) \
54 DRI_CONF_DESC(en, "Enable texture tiling") \
55 DRI_CONF_OPT_END \
56
57 PUBLIC const char __driConfigOptions[] =
58 DRI_CONF_BEGIN
59 DRI_CONF_SECTION_PERFORMANCE
60 DRI_CONF_FTHROTTLE_MODE(DRI_CONF_FTHROTTLE_IRQS)
61 DRI_CONF_VBLANK_MODE(DRI_CONF_VBLANK_ALWAYS_SYNC)
62 /* Options correspond to DRI_CONF_BO_REUSE_DISABLED,
63 * DRI_CONF_BO_REUSE_ALL
64 */
65 DRI_CONF_OPT_BEGIN_V(bo_reuse, enum, 1, "0:1")
66 DRI_CONF_DESC_BEGIN(en, "Buffer object reuse")
67 DRI_CONF_ENUM(0, "Disable buffer object reuse")
68 DRI_CONF_ENUM(1, "Enable reuse of all sizes of buffer objects")
69 DRI_CONF_DESC_END
70 DRI_CONF_OPT_END
71
72 #ifdef I915
73 DRI_CONF_TEXTURE_TILING(false)
74 #else
75 DRI_CONF_TEXTURE_TILING(true)
76 #endif
77
78 DRI_CONF_SECTION_END
79 DRI_CONF_SECTION_QUALITY
80 DRI_CONF_FORCE_S3TC_ENABLE(false)
81 DRI_CONF_ALLOW_LARGE_TEXTURES(2)
82 DRI_CONF_SECTION_END
83 DRI_CONF_SECTION_DEBUG
84 DRI_CONF_NO_RAST(false)
85 DRI_CONF_ALWAYS_FLUSH_BATCH(false)
86 DRI_CONF_ALWAYS_FLUSH_CACHE(false)
87 DRI_CONF_SECTION_END
88 DRI_CONF_END;
89
90 const GLuint __driNConfigOptions = 9;
91
92 #ifdef USE_NEW_INTERFACE
93 static PFNGLXCREATECONTEXTMODES create_context_modes = NULL;
94 #endif /*USE_NEW_INTERFACE */
95
96 /**
97 * Map all the memory regions described by the screen.
98 * \return GL_TRUE if success, GL_FALSE if error.
99 */
100 GLboolean
101 intelMapScreenRegions(__DRIscreenPrivate * sPriv)
102 {
103 intelScreenPrivate *intelScreen = (intelScreenPrivate *) sPriv->private;
104
105 if (0)
106 _mesa_printf("TEX 0x%08x ", intelScreen->tex.handle);
107 if (intelScreen->tex.size != 0) {
108 if (drmMap(sPriv->fd,
109 intelScreen->tex.handle,
110 intelScreen->tex.size,
111 (drmAddress *) & intelScreen->tex.map) != 0) {
112 intelUnmapScreenRegions(intelScreen);
113 return GL_FALSE;
114 }
115 }
116
117 return GL_TRUE;
118 }
119
120 void
121 intelUnmapScreenRegions(intelScreenPrivate * intelScreen)
122 {
123 if (intelScreen->tex.map) {
124 drmUnmap(intelScreen->tex.map, intelScreen->tex.size);
125 intelScreen->tex.map = NULL;
126 }
127 }
128
129
130 static void
131 intelPrintDRIInfo(intelScreenPrivate * intelScreen,
132 __DRIscreenPrivate * sPriv, I830DRIPtr gDRIPriv)
133 {
134 fprintf(stderr, "*** Front size: 0x%x offset: 0x%x pitch: %d\n",
135 intelScreen->front.size, intelScreen->front.offset,
136 intelScreen->pitch);
137 fprintf(stderr, "*** Back size: 0x%x offset: 0x%x pitch: %d\n",
138 intelScreen->back.size, intelScreen->back.offset,
139 intelScreen->pitch);
140 fprintf(stderr, "*** Depth size: 0x%x offset: 0x%x pitch: %d\n",
141 intelScreen->depth.size, intelScreen->depth.offset,
142 intelScreen->pitch);
143 fprintf(stderr, "*** Texture size: 0x%x offset: 0x%x\n",
144 intelScreen->tex.size, intelScreen->tex.offset);
145 fprintf(stderr, "*** Memory : 0x%x\n", gDRIPriv->mem);
146 }
147
148
149 static void
150 intelPrintSAREA(const drm_i915_sarea_t * sarea)
151 {
152 fprintf(stderr, "SAREA: sarea width %d height %d\n", sarea->width,
153 sarea->height);
154 fprintf(stderr, "SAREA: pitch: %d\n", sarea->pitch);
155 fprintf(stderr,
156 "SAREA: front offset: 0x%08x size: 0x%x handle: 0x%x tiled: %d\n",
157 sarea->front_offset, sarea->front_size,
158 (unsigned) sarea->front_handle, sarea->front_tiled);
159 fprintf(stderr,
160 "SAREA: back offset: 0x%08x size: 0x%x handle: 0x%x tiled: %d\n",
161 sarea->back_offset, sarea->back_size,
162 (unsigned) sarea->back_handle, sarea->back_tiled);
163 fprintf(stderr, "SAREA: depth offset: 0x%08x size: 0x%x handle: 0x%x tiled: %d\n",
164 sarea->depth_offset, sarea->depth_size,
165 (unsigned) sarea->depth_handle, sarea->depth_tiled);
166 fprintf(stderr, "SAREA: tex offset: 0x%08x size: 0x%x handle: 0x%x\n",
167 sarea->tex_offset, sarea->tex_size, (unsigned) sarea->tex_handle);
168 }
169
170
171 /**
172 * A number of the screen parameters are obtained/computed from
173 * information in the SAREA. This function updates those parameters.
174 */
175 static void
176 intelUpdateScreenFromSAREA(intelScreenPrivate * intelScreen,
177 drm_i915_sarea_t * sarea)
178 {
179 intelScreen->width = sarea->width;
180 intelScreen->height = sarea->height;
181 intelScreen->pitch = sarea->pitch;
182
183 intelScreen->front.offset = sarea->front_offset;
184 intelScreen->front.handle = sarea->front_handle;
185 intelScreen->front.size = sarea->front_size;
186 intelScreen->front.tiled = sarea->front_tiled;
187
188 intelScreen->back.offset = sarea->back_offset;
189 intelScreen->back.handle = sarea->back_handle;
190 intelScreen->back.size = sarea->back_size;
191 intelScreen->back.tiled = sarea->back_tiled;
192
193 intelScreen->depth.offset = sarea->depth_offset;
194 intelScreen->depth.handle = sarea->depth_handle;
195 intelScreen->depth.size = sarea->depth_size;
196 intelScreen->depth.tiled = sarea->depth_tiled;
197
198 if (intelScreen->driScrnPriv->ddx_version.minor >= 9) {
199 intelScreen->front.bo_handle = sarea->front_bo_handle;
200 intelScreen->back.bo_handle = sarea->back_bo_handle;
201 intelScreen->depth.bo_handle = sarea->depth_bo_handle;
202 } else {
203 intelScreen->front.bo_handle = -1;
204 intelScreen->back.bo_handle = -1;
205 intelScreen->depth.bo_handle = -1;
206 }
207
208 intelScreen->tex.offset = sarea->tex_offset;
209 intelScreen->logTextureGranularity = sarea->log_tex_granularity;
210 intelScreen->tex.handle = sarea->tex_handle;
211 intelScreen->tex.size = sarea->tex_size;
212
213 if (0)
214 intelPrintSAREA(sarea);
215 }
216
217 static const __DRItexOffsetExtension intelTexOffsetExtension = {
218 { __DRI_TEX_OFFSET },
219 intelSetTexOffset,
220 };
221
222 static const __DRItexBufferExtension intelTexBufferExtension = {
223 { __DRI_TEX_BUFFER, __DRI_TEX_BUFFER_VERSION },
224 intelSetTexBuffer,
225 intelSetTexBuffer2,
226 };
227
228 static const __DRIextension *intelScreenExtensions[] = {
229 &driReadDrawableExtension,
230 &driCopySubBufferExtension.base,
231 &driSwapControlExtension.base,
232 &driFrameTrackingExtension.base,
233 &driMediaStreamCounterExtension.base,
234 &intelTexOffsetExtension.base,
235 &intelTexBufferExtension.base,
236 NULL
237 };
238
239 static GLboolean
240 intel_get_param(__DRIscreenPrivate *psp, int param, int *value)
241 {
242 int ret;
243 struct drm_i915_getparam gp;
244
245 gp.param = param;
246 gp.value = value;
247
248 ret = drmCommandWriteRead(psp->fd, DRM_I915_GETPARAM, &gp, sizeof(gp));
249 if (ret) {
250 _mesa_warning(NULL, "drm_i915_getparam: %d\n", ret);
251 return GL_FALSE;
252 }
253
254 return GL_TRUE;
255 }
256
257 static GLboolean intelInitDriver(__DRIscreenPrivate *sPriv)
258 {
259 intelScreenPrivate *intelScreen;
260 I830DRIPtr gDRIPriv = (I830DRIPtr) sPriv->pDevPriv;
261 drm_i915_sarea_t *sarea;
262
263 if (sPriv->devPrivSize != sizeof(I830DRIRec)) {
264 fprintf(stderr,
265 "\nERROR! sizeof(I830DRIRec) does not match passed size from device driver\n");
266 return GL_FALSE;
267 }
268
269 /* Allocate the private area */
270 intelScreen = (intelScreenPrivate *) CALLOC(sizeof(intelScreenPrivate));
271 if (!intelScreen) {
272 fprintf(stderr, "\nERROR! Allocating private area failed\n");
273 return GL_FALSE;
274 }
275 /* parse information in __driConfigOptions */
276 driParseOptionInfo(&intelScreen->optionCache,
277 __driConfigOptions, __driNConfigOptions);
278
279 intelScreen->driScrnPriv = sPriv;
280 sPriv->private = (void *) intelScreen;
281 sarea = (drm_i915_sarea_t *)
282 (((GLubyte *) sPriv->pSAREA) + gDRIPriv->sarea_priv_offset);
283 intelScreen->sarea = sarea;
284
285 intelScreen->deviceID = gDRIPriv->deviceID;
286
287 intelUpdateScreenFromSAREA(intelScreen, sarea);
288
289 if (!intelMapScreenRegions(sPriv)) {
290 fprintf(stderr, "\nERROR! mapping regions\n");
291 _mesa_free(intelScreen);
292 sPriv->private = NULL;
293 return GL_FALSE;
294 }
295
296 if (0)
297 intelPrintDRIInfo(intelScreen, sPriv, gDRIPriv);
298
299 intelScreen->drmMinor = sPriv->drm_version.minor;
300
301 /* Determine if IRQs are active? */
302 if (!intel_get_param(sPriv, I915_PARAM_IRQ_ACTIVE,
303 &intelScreen->irq_active))
304 return GL_FALSE;
305
306 sPriv->extensions = intelScreenExtensions;
307
308 return GL_TRUE;
309 }
310
311
312 static void
313 intelDestroyScreen(__DRIscreenPrivate * sPriv)
314 {
315 intelScreenPrivate *intelScreen = (intelScreenPrivate *) sPriv->private;
316
317 dri_bufmgr_destroy(intelScreen->bufmgr);
318 intelUnmapScreenRegions(intelScreen);
319 driDestroyOptionCache(&intelScreen->optionCache);
320
321 FREE(intelScreen);
322 sPriv->private = NULL;
323 }
324
325
326 /**
327 * This is called when we need to set up GL rendering to a new X window.
328 */
329 static GLboolean
330 intelCreateBuffer(__DRIscreenPrivate * driScrnPriv,
331 __DRIdrawablePrivate * driDrawPriv,
332 const __GLcontextModes * mesaVis, GLboolean isPixmap)
333 {
334 if (isPixmap) {
335 return GL_FALSE; /* not implemented */
336 }
337 else {
338 GLboolean swStencil = (mesaVis->stencilBits > 0 &&
339 mesaVis->depthBits != 24);
340 GLenum rgbFormat;
341
342 struct intel_framebuffer *intel_fb = CALLOC_STRUCT(intel_framebuffer);
343
344 if (!intel_fb)
345 return GL_FALSE;
346
347 _mesa_initialize_framebuffer(&intel_fb->Base, mesaVis);
348
349 if (mesaVis->redBits == 5)
350 rgbFormat = GL_RGB5;
351 else if (mesaVis->alphaBits == 0)
352 rgbFormat = GL_RGB8;
353 else
354 rgbFormat = GL_RGBA8;
355
356 /* setup the hardware-based renderbuffers */
357 intel_fb->color_rb[0] = intel_create_renderbuffer(rgbFormat);
358 _mesa_add_renderbuffer(&intel_fb->Base, BUFFER_FRONT_LEFT,
359 &intel_fb->color_rb[0]->Base);
360
361 if (mesaVis->doubleBufferMode) {
362 intel_fb->color_rb[1] = intel_create_renderbuffer(rgbFormat);
363
364 _mesa_add_renderbuffer(&intel_fb->Base, BUFFER_BACK_LEFT,
365 &intel_fb->color_rb[1]->Base);
366
367 }
368
369 if (mesaVis->depthBits == 24) {
370 if (mesaVis->stencilBits == 8) {
371 /* combined depth/stencil buffer */
372 struct intel_renderbuffer *depthStencilRb
373 = intel_create_renderbuffer(GL_DEPTH24_STENCIL8_EXT);
374 /* note: bind RB to two attachment points */
375 _mesa_add_renderbuffer(&intel_fb->Base, BUFFER_DEPTH,
376 &depthStencilRb->Base);
377 _mesa_add_renderbuffer(&intel_fb->Base, BUFFER_STENCIL,
378 &depthStencilRb->Base);
379 } else {
380 struct intel_renderbuffer *depthRb
381 = intel_create_renderbuffer(GL_DEPTH_COMPONENT24);
382 _mesa_add_renderbuffer(&intel_fb->Base, BUFFER_DEPTH,
383 &depthRb->Base);
384 }
385 }
386 else if (mesaVis->depthBits == 16) {
387 /* just 16-bit depth buffer, no hw stencil */
388 struct intel_renderbuffer *depthRb
389 = intel_create_renderbuffer(GL_DEPTH_COMPONENT16);
390 _mesa_add_renderbuffer(&intel_fb->Base, BUFFER_DEPTH, &depthRb->Base);
391 }
392
393 /* now add any/all software-based renderbuffers we may need */
394 _mesa_add_soft_renderbuffers(&intel_fb->Base,
395 GL_FALSE, /* never sw color */
396 GL_FALSE, /* never sw depth */
397 swStencil, mesaVis->accumRedBits > 0,
398 GL_FALSE, /* never sw alpha */
399 GL_FALSE /* never sw aux */ );
400 driDrawPriv->driverPrivate = (void *) intel_fb;
401
402 return GL_TRUE;
403 }
404 }
405
406 static void
407 intelDestroyBuffer(__DRIdrawablePrivate * driDrawPriv)
408 {
409 _mesa_reference_framebuffer((GLframebuffer **)(&(driDrawPriv->driverPrivate)), NULL);
410 }
411
412
413 /**
414 * Get information about previous buffer swaps.
415 */
416 static int
417 intelGetSwapInfo(__DRIdrawablePrivate * dPriv, __DRIswapInfo * sInfo)
418 {
419 struct intel_framebuffer *intel_fb;
420
421 if ((dPriv == NULL) || (dPriv->driverPrivate == NULL)
422 || (sInfo == NULL)) {
423 return -1;
424 }
425
426 intel_fb = dPriv->driverPrivate;
427 sInfo->swap_count = intel_fb->swap_count;
428 sInfo->swap_ust = intel_fb->swap_ust;
429 sInfo->swap_missed_count = intel_fb->swap_missed_count;
430
431 sInfo->swap_missed_usage = (sInfo->swap_missed_count != 0)
432 ? driCalculateSwapUsage(dPriv, 0, intel_fb->swap_missed_ust)
433 : 0.0;
434
435 return 0;
436 }
437
438
439 /* There are probably better ways to do this, such as an
440 * init-designated function to register chipids and createcontext
441 * functions.
442 */
443 extern GLboolean i830CreateContext(const __GLcontextModes * mesaVis,
444 __DRIcontextPrivate * driContextPriv,
445 void *sharedContextPrivate);
446
447 extern GLboolean i915CreateContext(const __GLcontextModes * mesaVis,
448 __DRIcontextPrivate * driContextPriv,
449 void *sharedContextPrivate);
450 extern GLboolean brwCreateContext(const __GLcontextModes * mesaVis,
451 __DRIcontextPrivate * driContextPriv,
452 void *sharedContextPrivate);
453
454 static GLboolean
455 intelCreateContext(const __GLcontextModes * mesaVis,
456 __DRIcontextPrivate * driContextPriv,
457 void *sharedContextPrivate)
458 {
459 __DRIscreenPrivate *sPriv = driContextPriv->driScreenPriv;
460 intelScreenPrivate *intelScreen = (intelScreenPrivate *) sPriv->private;
461
462 #ifdef I915
463 if (IS_9XX(intelScreen->deviceID)) {
464 if (!IS_965(intelScreen->deviceID)) {
465 return i915CreateContext(mesaVis, driContextPriv,
466 sharedContextPrivate);
467 }
468 } else {
469 intelScreen->no_vbo = GL_TRUE;
470 return i830CreateContext(mesaVis, driContextPriv, sharedContextPrivate);
471 }
472 #else
473 if (IS_965(intelScreen->deviceID))
474 return brwCreateContext(mesaVis, driContextPriv, sharedContextPrivate);
475 #endif
476 fprintf(stderr, "Unrecognized deviceID %x\n", intelScreen->deviceID);
477 return GL_FALSE;
478 }
479
480
481 static __DRIconfig **
482 intelFillInModes(__DRIscreenPrivate *psp,
483 unsigned pixel_bits, unsigned depth_bits,
484 unsigned stencil_bits, GLboolean have_back_buffer)
485 {
486 __DRIconfig **configs;
487 __GLcontextModes *m;
488 unsigned depth_buffer_factor;
489 unsigned back_buffer_factor;
490 int i;
491
492 /* GLX_SWAP_COPY_OML is only supported because the Intel driver doesn't
493 * support pageflipping at all.
494 */
495 static const GLenum back_buffer_modes[] = {
496 GLX_NONE, GLX_SWAP_UNDEFINED_OML, GLX_SWAP_COPY_OML
497 };
498
499 uint8_t depth_bits_array[3];
500 uint8_t stencil_bits_array[3];
501 uint8_t msaa_samples_array[1];
502
503 depth_bits_array[0] = 0;
504 depth_bits_array[1] = depth_bits;
505 depth_bits_array[2] = depth_bits;
506
507 /* Just like with the accumulation buffer, always provide some modes
508 * with a stencil buffer. It will be a sw fallback, but some apps won't
509 * care about that.
510 */
511 stencil_bits_array[0] = 0;
512 stencil_bits_array[1] = 0;
513 if (depth_bits == 24)
514 stencil_bits_array[1] = (stencil_bits == 0) ? 8 : stencil_bits;
515
516 stencil_bits_array[2] = (stencil_bits == 0) ? 8 : stencil_bits;
517
518 msaa_samples_array[0] = 0;
519
520 depth_buffer_factor = ((depth_bits != 0) || (stencil_bits != 0)) ? 3 : 1;
521 back_buffer_factor = (have_back_buffer) ? 3 : 1;
522
523 if (pixel_bits == 16) {
524 configs = driCreateConfigs(GL_RGB, GL_UNSIGNED_SHORT_5_6_5,
525 depth_bits_array, stencil_bits_array,
526 depth_buffer_factor, back_buffer_modes,
527 back_buffer_factor,
528 msaa_samples_array, 1);
529 }
530 else {
531 __DRIconfig **configs_a8r8g8b8;
532 __DRIconfig **configs_x8r8g8b8;
533
534 configs_a8r8g8b8 = driCreateConfigs(GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV,
535 depth_bits_array,
536 stencil_bits_array,
537 depth_buffer_factor,
538 back_buffer_modes,
539 back_buffer_factor,
540 msaa_samples_array, 1);
541 configs_x8r8g8b8 = driCreateConfigs(GL_BGR, GL_UNSIGNED_INT_8_8_8_8_REV,
542 depth_bits_array,
543 stencil_bits_array,
544 depth_buffer_factor,
545 back_buffer_modes,
546 back_buffer_factor,
547 msaa_samples_array, 1);
548 configs = driConcatConfigs(configs_a8r8g8b8, configs_x8r8g8b8);
549 }
550
551 if (configs == NULL) {
552 fprintf(stderr, "[%s:%u] Error creating FBConfig!\n", __func__,
553 __LINE__);
554 return NULL;
555 }
556
557 /* Mark the visual as slow if there are "fake" stencil bits.
558 */
559 for (i = 0; configs[i]; i++) {
560 m = &configs[i]->modes;
561 if ((m->stencilBits != 0) && (m->stencilBits != stencil_bits)) {
562 m->visualRating = GLX_SLOW_CONFIG;
563 }
564 }
565
566 return configs;
567 }
568
569 static GLboolean
570 intel_init_bufmgr(intelScreenPrivate *intelScreen)
571 {
572 GLboolean gem_disable = getenv("INTEL_NO_GEM") != NULL;
573 int gem_kernel = 0;
574 GLboolean gem_supported;
575 struct drm_i915_getparam gp;
576 __DRIscreenPrivate *spriv = intelScreen->driScrnPriv;
577 int num_fences;
578
579 intelScreen->no_hw = getenv("INTEL_NO_HW") != NULL;
580
581 gp.param = I915_PARAM_HAS_GEM;
582 gp.value = &gem_kernel;
583
584 (void) drmCommandWriteRead(spriv->fd, DRM_I915_GETPARAM, &gp, sizeof(gp));
585
586 /* If we've got a new enough DDX that's initializing GEM and giving us
587 * object handles for the shared buffers, use that.
588 */
589 intelScreen->ttm = GL_FALSE;
590 if (intelScreen->driScrnPriv->dri2.enabled)
591 gem_supported = GL_TRUE;
592 else if (intelScreen->driScrnPriv->ddx_version.minor >= 9 &&
593 gem_kernel &&
594 intelScreen->front.bo_handle != -1)
595 gem_supported = GL_TRUE;
596 else
597 gem_supported = GL_FALSE;
598
599 if (!gem_disable && gem_supported) {
600 intelScreen->bufmgr = intel_bufmgr_gem_init(spriv->fd, BATCH_SZ);
601 if (intelScreen->bufmgr != NULL)
602 intelScreen->ttm = GL_TRUE;
603 }
604 /* Otherwise, use the classic buffer manager. */
605 if (intelScreen->bufmgr == NULL) {
606 if (gem_disable) {
607 fprintf(stderr, "GEM disabled. Using classic.\n");
608 } else {
609 fprintf(stderr, "Failed to initialize GEM. "
610 "Falling back to classic.\n");
611 }
612
613 if (intelScreen->tex.size == 0) {
614 fprintf(stderr, "[%s:%u] Error initializing buffer manager.\n",
615 __func__, __LINE__);
616 return GL_FALSE;
617 }
618
619 intelScreen->bufmgr =
620 intel_bufmgr_fake_init(spriv->fd,
621 intelScreen->tex.offset,
622 intelScreen->tex.map,
623 intelScreen->tex.size,
624 (unsigned int * volatile)
625 &intelScreen->sarea->last_dispatch);
626 }
627
628 if (intel_get_param(spriv, I915_PARAM_NUM_FENCES_AVAIL, &num_fences))
629 intelScreen->kernel_exec_fencing = !!num_fences;
630 else
631 intelScreen->kernel_exec_fencing = GL_FALSE;
632
633 return GL_TRUE;
634 }
635
636 /**
637 * This is the driver specific part of the createNewScreen entry point.
638 * Called when using legacy DRI.
639 *
640 * \todo maybe fold this into intelInitDriver
641 *
642 * \return the __GLcontextModes supported by this driver
643 */
644 static const __DRIconfig **intelInitScreen(__DRIscreenPrivate *psp)
645 {
646 intelScreenPrivate *intelScreen;
647 #ifdef I915
648 static const __DRIversion ddx_expected = { 1, 5, 0 };
649 #else
650 static const __DRIversion ddx_expected = { 1, 6, 0 };
651 #endif
652 static const __DRIversion dri_expected = { 4, 0, 0 };
653 static const __DRIversion drm_expected = { 1, 5, 0 };
654 I830DRIPtr dri_priv = (I830DRIPtr) psp->pDevPriv;
655
656 if (!driCheckDriDdxDrmVersions2("i915",
657 &psp->dri_version, &dri_expected,
658 &psp->ddx_version, &ddx_expected,
659 &psp->drm_version, &drm_expected)) {
660 return NULL;
661 }
662
663 /* Calling driInitExtensions here, with a NULL context pointer,
664 * does not actually enable the extensions. It just makes sure
665 * that all the dispatch offsets for all the extensions that
666 * *might* be enables are known. This is needed because the
667 * dispatch offsets need to be known when _mesa_context_create is
668 * called, but we can't enable the extensions until we have a
669 * context pointer.
670 *
671 * Hello chicken. Hello egg. How are you two today?
672 */
673 intelInitExtensions(NULL, GL_TRUE);
674
675 if (!intelInitDriver(psp))
676 return NULL;
677
678 psp->extensions = intelScreenExtensions;
679
680 intelScreen = psp->private;
681 if (!intel_init_bufmgr(intelScreen))
682 return GL_FALSE;
683
684 return (const __DRIconfig **)
685 intelFillInModes(psp, dri_priv->cpp * 8,
686 (dri_priv->cpp == 2) ? 16 : 24,
687 (dri_priv->cpp == 2) ? 0 : 8, 1);
688 }
689
690 struct intel_context *intelScreenContext(intelScreenPrivate *intelScreen)
691 {
692 /*
693 * This should probably change to have the screen allocate a dummy
694 * context at screen creation. For now just use the current context.
695 */
696
697 GET_CURRENT_CONTEXT(ctx);
698 if (ctx == NULL) {
699 _mesa_problem(NULL, "No current context in intelScreenContext\n");
700 return NULL;
701 }
702 return intel_context(ctx);
703 }
704
705 /**
706 * This is the driver specific part of the createNewScreen entry point.
707 * Called when using DRI2.
708 *
709 * \return the __GLcontextModes supported by this driver
710 */
711 static const
712 __DRIconfig **intelInitScreen2(__DRIscreenPrivate *psp)
713 {
714 intelScreenPrivate *intelScreen;
715 GLenum fb_format[3];
716 GLenum fb_type[3];
717 /* GLX_SWAP_COPY_OML is only supported because the Intel driver doesn't
718 * support pageflipping at all.
719 */
720 static const GLenum back_buffer_modes[] = {
721 GLX_NONE, GLX_SWAP_UNDEFINED_OML, GLX_SWAP_COPY_OML
722 };
723 uint8_t depth_bits[4], stencil_bits[4], msaa_samples_array[1];
724 int color;
725 __DRIconfig **configs = NULL;
726
727 /* Calling driInitExtensions here, with a NULL context pointer,
728 * does not actually enable the extensions. It just makes sure
729 * that all the dispatch offsets for all the extensions that
730 * *might* be enables are known. This is needed because the
731 * dispatch offsets need to be known when _mesa_context_create is
732 * called, but we can't enable the extensions until we have a
733 * context pointer.
734 *
735 * Hello chicken. Hello egg. How are you two today?
736 */
737 intelInitExtensions(NULL, GL_TRUE);
738
739 /* Allocate the private area */
740 intelScreen = (intelScreenPrivate *) CALLOC(sizeof(intelScreenPrivate));
741 if (!intelScreen) {
742 fprintf(stderr, "\nERROR! Allocating private area failed\n");
743 return GL_FALSE;
744 }
745 /* parse information in __driConfigOptions */
746 driParseOptionInfo(&intelScreen->optionCache,
747 __driConfigOptions, __driNConfigOptions);
748
749 intelScreen->driScrnPriv = psp;
750 psp->private = (void *) intelScreen;
751
752 intelScreen->drmMinor = psp->drm_version.minor;
753
754 /* Determine chipset ID */
755 if (!intel_get_param(psp, I915_PARAM_CHIPSET_ID,
756 &intelScreen->deviceID))
757 return GL_FALSE;
758
759 if (!intel_init_bufmgr(intelScreen))
760 return GL_FALSE;
761
762 intelScreen->irq_active = 1;
763 psp->extensions = intelScreenExtensions;
764
765 depth_bits[0] = 0;
766 stencil_bits[0] = 0;
767 depth_bits[1] = 16;
768 stencil_bits[1] = 0;
769 depth_bits[2] = 24;
770 stencil_bits[2] = 0;
771 depth_bits[3] = 24;
772 stencil_bits[3] = 8;
773
774 msaa_samples_array[0] = 0;
775
776 fb_format[0] = GL_RGB;
777 fb_type[0] = GL_UNSIGNED_SHORT_5_6_5;
778
779 fb_format[1] = GL_BGR;
780 fb_type[1] = GL_UNSIGNED_INT_8_8_8_8_REV;
781
782 fb_format[2] = GL_BGRA;
783 fb_type[2] = GL_UNSIGNED_INT_8_8_8_8_REV;
784
785 depth_bits[0] = 0;
786 stencil_bits[0] = 0;
787
788 for (color = 0; color < ARRAY_SIZE(fb_format); color++) {
789 __DRIconfig **new_configs;
790 int depth_factor;
791
792 /* With DRI2 right now, GetBuffers always returns a depth/stencil buffer
793 * with the same cpp as the drawable. So we can't support depth cpp !=
794 * color cpp currently.
795 */
796 if (fb_type[color] == GL_UNSIGNED_SHORT_5_6_5) {
797 depth_bits[1] = 16;
798 stencil_bits[1] = 0;
799
800 depth_factor = 2;
801 } else {
802 depth_bits[1] = 24;
803 stencil_bits[1] = 0;
804 depth_bits[2] = 24;
805 stencil_bits[2] = 8;
806
807 depth_factor = 3;
808 }
809 new_configs = driCreateConfigs(fb_format[color], fb_type[color],
810 depth_bits,
811 stencil_bits,
812 depth_factor,
813 back_buffer_modes,
814 ARRAY_SIZE(back_buffer_modes),
815 msaa_samples_array,
816 ARRAY_SIZE(msaa_samples_array));
817 if (configs == NULL)
818 configs = new_configs;
819 else
820 configs = driConcatConfigs(configs, new_configs);
821 }
822
823 if (configs == NULL) {
824 fprintf(stderr, "[%s:%u] Error creating FBConfig!\n", __func__,
825 __LINE__);
826 return NULL;
827 }
828
829 return (const __DRIconfig **)configs;
830 }
831
832 const struct __DriverAPIRec driDriverAPI = {
833 .InitScreen = intelInitScreen,
834 .DestroyScreen = intelDestroyScreen,
835 .CreateContext = intelCreateContext,
836 .DestroyContext = intelDestroyContext,
837 .CreateBuffer = intelCreateBuffer,
838 .DestroyBuffer = intelDestroyBuffer,
839 .SwapBuffers = intelSwapBuffers,
840 .MakeCurrent = intelMakeCurrent,
841 .UnbindContext = intelUnbindContext,
842 .GetSwapInfo = intelGetSwapInfo,
843 .GetDrawableMSC = driDrawableGetMSC32,
844 .WaitForMSC = driWaitForMSC32,
845 .CopySubBuffer = intelCopySubBuffer,
846
847 .InitScreen2 = intelInitScreen2,
848 };