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