09eba13aab50c7e0dedf9161d5bda9f5cf74c9cc
[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_SECTION_END
75 DRI_CONF_END;
76
77 const GLuint __driNConfigOptions = 6;
78
79 #ifdef USE_NEW_INTERFACE
80 static PFNGLXCREATECONTEXTMODES create_context_modes = NULL;
81 #endif /*USE_NEW_INTERFACE */
82
83 /**
84 * Map all the memory regions described by the screen.
85 * \return GL_TRUE if success, GL_FALSE if error.
86 */
87 GLboolean
88 intelMapScreenRegions(__DRIscreenPrivate * sPriv)
89 {
90 intelScreenPrivate *intelScreen = (intelScreenPrivate *) sPriv->private;
91
92 if (0)
93 _mesa_printf("TEX 0x%08x ", intelScreen->tex.handle);
94 if (intelScreen->tex.size != 0) {
95 if (drmMap(sPriv->fd,
96 intelScreen->tex.handle,
97 intelScreen->tex.size,
98 (drmAddress *) & intelScreen->tex.map) != 0) {
99 intelUnmapScreenRegions(intelScreen);
100 return GL_FALSE;
101 }
102 }
103
104 return GL_TRUE;
105 }
106
107 void
108 intelUnmapScreenRegions(intelScreenPrivate * intelScreen)
109 {
110 if (intelScreen->tex.map) {
111 drmUnmap(intelScreen->tex.map, intelScreen->tex.size);
112 intelScreen->tex.map = NULL;
113 }
114 }
115
116
117 static void
118 intelPrintDRIInfo(intelScreenPrivate * intelScreen,
119 __DRIscreenPrivate * sPriv, I830DRIPtr gDRIPriv)
120 {
121 fprintf(stderr, "*** Front size: 0x%x offset: 0x%x pitch: %d\n",
122 intelScreen->front.size, intelScreen->front.offset,
123 intelScreen->pitch);
124 fprintf(stderr, "*** Back size: 0x%x offset: 0x%x pitch: %d\n",
125 intelScreen->back.size, intelScreen->back.offset,
126 intelScreen->pitch);
127 fprintf(stderr, "*** Depth size: 0x%x offset: 0x%x pitch: %d\n",
128 intelScreen->depth.size, intelScreen->depth.offset,
129 intelScreen->pitch);
130 fprintf(stderr, "*** Texture size: 0x%x offset: 0x%x\n",
131 intelScreen->tex.size, intelScreen->tex.offset);
132 fprintf(stderr, "*** Memory : 0x%x\n", gDRIPriv->mem);
133 }
134
135
136 static void
137 intelPrintSAREA(const drm_i915_sarea_t * sarea)
138 {
139 fprintf(stderr, "SAREA: sarea width %d height %d\n", sarea->width,
140 sarea->height);
141 fprintf(stderr, "SAREA: pitch: %d\n", sarea->pitch);
142 fprintf(stderr,
143 "SAREA: front offset: 0x%08x size: 0x%x handle: 0x%x tiled: %d\n",
144 sarea->front_offset, sarea->front_size,
145 (unsigned) sarea->front_handle, sarea->front_tiled);
146 fprintf(stderr,
147 "SAREA: back offset: 0x%08x size: 0x%x handle: 0x%x tiled: %d\n",
148 sarea->back_offset, sarea->back_size,
149 (unsigned) sarea->back_handle, sarea->back_tiled);
150 fprintf(stderr, "SAREA: depth offset: 0x%08x size: 0x%x handle: 0x%x tiled: %d\n",
151 sarea->depth_offset, sarea->depth_size,
152 (unsigned) sarea->depth_handle, sarea->depth_tiled);
153 fprintf(stderr, "SAREA: tex offset: 0x%08x size: 0x%x handle: 0x%x\n",
154 sarea->tex_offset, sarea->tex_size, (unsigned) sarea->tex_handle);
155 }
156
157
158 /**
159 * A number of the screen parameters are obtained/computed from
160 * information in the SAREA. This function updates those parameters.
161 */
162 static void
163 intelUpdateScreenFromSAREA(intelScreenPrivate * intelScreen,
164 drm_i915_sarea_t * sarea)
165 {
166 intelScreen->width = sarea->width;
167 intelScreen->height = sarea->height;
168 intelScreen->pitch = sarea->pitch;
169
170 intelScreen->front.offset = sarea->front_offset;
171 intelScreen->front.handle = sarea->front_handle;
172 intelScreen->front.size = sarea->front_size;
173 intelScreen->front.tiled = sarea->front_tiled;
174
175 intelScreen->back.offset = sarea->back_offset;
176 intelScreen->back.handle = sarea->back_handle;
177 intelScreen->back.size = sarea->back_size;
178 intelScreen->back.tiled = sarea->back_tiled;
179
180 intelScreen->depth.offset = sarea->depth_offset;
181 intelScreen->depth.handle = sarea->depth_handle;
182 intelScreen->depth.size = sarea->depth_size;
183 intelScreen->depth.tiled = sarea->depth_tiled;
184
185 if (intelScreen->driScrnPriv->ddx_version.minor >= 9) {
186 intelScreen->front.bo_handle = sarea->front_bo_handle;
187 intelScreen->back.bo_handle = sarea->back_bo_handle;
188 intelScreen->depth.bo_handle = sarea->depth_bo_handle;
189 } else {
190 intelScreen->front.bo_handle = -1;
191 intelScreen->back.bo_handle = -1;
192 intelScreen->depth.bo_handle = -1;
193 }
194
195 intelScreen->tex.offset = sarea->tex_offset;
196 intelScreen->logTextureGranularity = sarea->log_tex_granularity;
197 intelScreen->tex.handle = sarea->tex_handle;
198 intelScreen->tex.size = sarea->tex_size;
199
200 if (0)
201 intelPrintSAREA(sarea);
202 }
203
204 static const __DRItexOffsetExtension intelTexOffsetExtension = {
205 { __DRI_TEX_OFFSET },
206 intelSetTexOffset,
207 };
208
209 static const __DRItexBufferExtension intelTexBufferExtension = {
210 { __DRI_TEX_BUFFER, __DRI_TEX_BUFFER_VERSION },
211 intelSetTexBuffer,
212 };
213
214 static const __DRIextension *intelScreenExtensions[] = {
215 &driReadDrawableExtension,
216 &driCopySubBufferExtension.base,
217 &driSwapControlExtension.base,
218 &driFrameTrackingExtension.base,
219 &driMediaStreamCounterExtension.base,
220 &intelTexOffsetExtension.base,
221 &intelTexBufferExtension.base,
222 NULL
223 };
224
225 static GLboolean
226 intel_get_param(__DRIscreenPrivate *psp, int param, int *value)
227 {
228 int ret;
229 struct drm_i915_getparam gp;
230
231 gp.param = param;
232 gp.value = value;
233
234 ret = drmCommandWriteRead(psp->fd, DRM_I915_GETPARAM, &gp, sizeof(gp));
235 if (ret) {
236 fprintf(stderr, "drm_i915_getparam: %d\n", ret);
237 return GL_FALSE;
238 }
239
240 return GL_TRUE;
241 }
242
243 static GLboolean intelInitDriver(__DRIscreenPrivate *sPriv)
244 {
245 intelScreenPrivate *intelScreen;
246 I830DRIPtr gDRIPriv = (I830DRIPtr) sPriv->pDevPriv;
247 drm_i915_sarea_t *sarea;
248
249 if (sPriv->devPrivSize != sizeof(I830DRIRec)) {
250 fprintf(stderr,
251 "\nERROR! sizeof(I830DRIRec) does not match passed size from device driver\n");
252 return GL_FALSE;
253 }
254
255 /* Allocate the private area */
256 intelScreen = (intelScreenPrivate *) CALLOC(sizeof(intelScreenPrivate));
257 if (!intelScreen) {
258 fprintf(stderr, "\nERROR! Allocating private area failed\n");
259 return GL_FALSE;
260 }
261 /* parse information in __driConfigOptions */
262 driParseOptionInfo(&intelScreen->optionCache,
263 __driConfigOptions, __driNConfigOptions);
264
265 intelScreen->driScrnPriv = sPriv;
266 sPriv->private = (void *) intelScreen;
267 sarea = (drm_i915_sarea_t *)
268 (((GLubyte *) sPriv->pSAREA) + gDRIPriv->sarea_priv_offset);
269 intelScreen->sarea = sarea;
270
271 intelScreen->deviceID = gDRIPriv->deviceID;
272
273 intelUpdateScreenFromSAREA(intelScreen, sarea);
274
275 if (!intelMapScreenRegions(sPriv)) {
276 fprintf(stderr, "\nERROR! mapping regions\n");
277 _mesa_free(intelScreen);
278 sPriv->private = NULL;
279 return GL_FALSE;
280 }
281
282 if (0)
283 intelPrintDRIInfo(intelScreen, sPriv, gDRIPriv);
284
285 intelScreen->drmMinor = sPriv->drm_version.minor;
286
287 /* Determine if IRQs are active? */
288 if (!intel_get_param(sPriv, I915_PARAM_IRQ_ACTIVE,
289 &intelScreen->irq_active))
290 return GL_FALSE;
291
292 sPriv->extensions = intelScreenExtensions;
293
294 return GL_TRUE;
295 }
296
297
298 static void
299 intelDestroyScreen(__DRIscreenPrivate * sPriv)
300 {
301 intelScreenPrivate *intelScreen = (intelScreenPrivate *) sPriv->private;
302
303 dri_bufmgr_destroy(intelScreen->bufmgr);
304 intelUnmapScreenRegions(intelScreen);
305 driDestroyOptionCache(&intelScreen->optionCache);
306
307 FREE(intelScreen);
308 sPriv->private = NULL;
309 }
310
311
312 /**
313 * This is called when we need to set up GL rendering to a new X window.
314 */
315 static GLboolean
316 intelCreateBuffer(__DRIscreenPrivate * driScrnPriv,
317 __DRIdrawablePrivate * driDrawPriv,
318 const __GLcontextModes * mesaVis, GLboolean isPixmap)
319 {
320 if (isPixmap) {
321 return GL_FALSE; /* not implemented */
322 }
323 else {
324 GLboolean swStencil = (mesaVis->stencilBits > 0 &&
325 mesaVis->depthBits != 24);
326 GLenum rgbFormat;
327
328 struct intel_framebuffer *intel_fb = CALLOC_STRUCT(intel_framebuffer);
329
330 if (!intel_fb)
331 return GL_FALSE;
332
333 _mesa_initialize_framebuffer(&intel_fb->Base, mesaVis);
334
335 if (mesaVis->redBits == 5)
336 rgbFormat = GL_RGB5;
337 else if (mesaVis->alphaBits == 0)
338 rgbFormat = GL_RGB8;
339 else
340 rgbFormat = GL_RGBA8;
341
342 /* setup the hardware-based renderbuffers */
343 intel_fb->color_rb[0] = intel_create_renderbuffer(rgbFormat);
344 _mesa_add_renderbuffer(&intel_fb->Base, BUFFER_FRONT_LEFT,
345 &intel_fb->color_rb[0]->Base);
346
347 if (mesaVis->doubleBufferMode) {
348 intel_fb->color_rb[1] = intel_create_renderbuffer(rgbFormat);
349
350 _mesa_add_renderbuffer(&intel_fb->Base, BUFFER_BACK_LEFT,
351 &intel_fb->color_rb[1]->Base);
352
353 }
354
355 if (mesaVis->depthBits == 24) {
356 if (mesaVis->stencilBits == 8) {
357 /* combined depth/stencil buffer */
358 struct intel_renderbuffer *depthStencilRb
359 = intel_create_renderbuffer(GL_DEPTH24_STENCIL8_EXT);
360 /* note: bind RB to two attachment points */
361 _mesa_add_renderbuffer(&intel_fb->Base, BUFFER_DEPTH,
362 &depthStencilRb->Base);
363 _mesa_add_renderbuffer(&intel_fb->Base, BUFFER_STENCIL,
364 &depthStencilRb->Base);
365 } else {
366 struct intel_renderbuffer *depthRb
367 = intel_create_renderbuffer(GL_DEPTH_COMPONENT24);
368 _mesa_add_renderbuffer(&intel_fb->Base, BUFFER_DEPTH,
369 &depthRb->Base);
370 }
371 }
372 else if (mesaVis->depthBits == 16) {
373 /* just 16-bit depth buffer, no hw stencil */
374 struct intel_renderbuffer *depthRb
375 = intel_create_renderbuffer(GL_DEPTH_COMPONENT16);
376 _mesa_add_renderbuffer(&intel_fb->Base, BUFFER_DEPTH, &depthRb->Base);
377 }
378
379 /* now add any/all software-based renderbuffers we may need */
380 _mesa_add_soft_renderbuffers(&intel_fb->Base,
381 GL_FALSE, /* never sw color */
382 GL_FALSE, /* never sw depth */
383 swStencil, mesaVis->accumRedBits > 0,
384 GL_FALSE, /* never sw alpha */
385 GL_FALSE /* never sw aux */ );
386 driDrawPriv->driverPrivate = (void *) intel_fb;
387
388 return GL_TRUE;
389 }
390 }
391
392 static void
393 intelDestroyBuffer(__DRIdrawablePrivate * driDrawPriv)
394 {
395 _mesa_unreference_framebuffer((GLframebuffer **)(&(driDrawPriv->driverPrivate)));
396 }
397
398
399 /**
400 * Get information about previous buffer swaps.
401 */
402 static int
403 intelGetSwapInfo(__DRIdrawablePrivate * dPriv, __DRIswapInfo * sInfo)
404 {
405 struct intel_framebuffer *intel_fb;
406
407 if ((dPriv == NULL) || (dPriv->driverPrivate == NULL)
408 || (sInfo == NULL)) {
409 return -1;
410 }
411
412 intel_fb = dPriv->driverPrivate;
413 sInfo->swap_count = intel_fb->swap_count;
414 sInfo->swap_ust = intel_fb->swap_ust;
415 sInfo->swap_missed_count = intel_fb->swap_missed_count;
416
417 sInfo->swap_missed_usage = (sInfo->swap_missed_count != 0)
418 ? driCalculateSwapUsage(dPriv, 0, intel_fb->swap_missed_ust)
419 : 0.0;
420
421 return 0;
422 }
423
424
425 /* There are probably better ways to do this, such as an
426 * init-designated function to register chipids and createcontext
427 * functions.
428 */
429 extern GLboolean i830CreateContext(const __GLcontextModes * mesaVis,
430 __DRIcontextPrivate * driContextPriv,
431 void *sharedContextPrivate);
432
433 extern GLboolean i915CreateContext(const __GLcontextModes * mesaVis,
434 __DRIcontextPrivate * driContextPriv,
435 void *sharedContextPrivate);
436 extern GLboolean brwCreateContext(const __GLcontextModes * mesaVis,
437 __DRIcontextPrivate * driContextPriv,
438 void *sharedContextPrivate);
439
440 static GLboolean
441 intelCreateContext(const __GLcontextModes * mesaVis,
442 __DRIcontextPrivate * driContextPriv,
443 void *sharedContextPrivate)
444 {
445 __DRIscreenPrivate *sPriv = driContextPriv->driScreenPriv;
446 intelScreenPrivate *intelScreen = (intelScreenPrivate *) sPriv->private;
447
448 #ifdef I915
449 if (IS_9XX(intelScreen->deviceID)) {
450 if (!IS_965(intelScreen->deviceID)) {
451 return i915CreateContext(mesaVis, driContextPriv,
452 sharedContextPrivate);
453 }
454 } else {
455 intelScreen->no_vbo = GL_TRUE;
456 return i830CreateContext(mesaVis, driContextPriv, sharedContextPrivate);
457 }
458 #else
459 if (IS_965(intelScreen->deviceID))
460 return brwCreateContext(mesaVis, driContextPriv, sharedContextPrivate);
461 #endif
462 fprintf(stderr, "Unrecognized deviceID %x\n", intelScreen->deviceID);
463 return GL_FALSE;
464 }
465
466
467 static __DRIconfig **
468 intelFillInModes(__DRIscreenPrivate *psp,
469 unsigned pixel_bits, unsigned depth_bits,
470 unsigned stencil_bits, GLboolean have_back_buffer)
471 {
472 __DRIconfig **configs;
473 __GLcontextModes *m;
474 unsigned depth_buffer_factor;
475 unsigned back_buffer_factor;
476 int i;
477
478 /* GLX_SWAP_COPY_OML is only supported because the Intel driver doesn't
479 * support pageflipping at all.
480 */
481 static const GLenum back_buffer_modes[] = {
482 GLX_NONE, GLX_SWAP_UNDEFINED_OML, GLX_SWAP_COPY_OML
483 };
484
485 uint8_t depth_bits_array[3];
486 uint8_t stencil_bits_array[3];
487 uint8_t msaa_samples_array[1];
488
489 depth_bits_array[0] = 0;
490 depth_bits_array[1] = depth_bits;
491 depth_bits_array[2] = depth_bits;
492
493 /* Just like with the accumulation buffer, always provide some modes
494 * with a stencil buffer. It will be a sw fallback, but some apps won't
495 * care about that.
496 */
497 stencil_bits_array[0] = 0;
498 stencil_bits_array[1] = 0;
499 if (depth_bits == 24)
500 stencil_bits_array[1] = (stencil_bits == 0) ? 8 : stencil_bits;
501
502 stencil_bits_array[2] = (stencil_bits == 0) ? 8 : stencil_bits;
503
504 msaa_samples_array[0] = 0;
505
506 depth_buffer_factor = ((depth_bits != 0) || (stencil_bits != 0)) ? 3 : 1;
507 back_buffer_factor = (have_back_buffer) ? 3 : 1;
508
509 if (pixel_bits == 16) {
510 configs = driCreateConfigs(GL_RGB, GL_UNSIGNED_SHORT_5_6_5,
511 depth_bits_array, stencil_bits_array,
512 depth_buffer_factor, back_buffer_modes,
513 back_buffer_factor,
514 msaa_samples_array, 1);
515 }
516 else {
517 __DRIconfig **configs_a8r8g8b8;
518 __DRIconfig **configs_x8r8g8b8;
519
520 configs_a8r8g8b8 = driCreateConfigs(GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV,
521 depth_bits_array,
522 stencil_bits_array,
523 depth_buffer_factor,
524 back_buffer_modes,
525 back_buffer_factor,
526 msaa_samples_array, 1);
527 configs_x8r8g8b8 = driCreateConfigs(GL_BGR, GL_UNSIGNED_INT_8_8_8_8_REV,
528 depth_bits_array,
529 stencil_bits_array,
530 depth_buffer_factor,
531 back_buffer_modes,
532 back_buffer_factor,
533 msaa_samples_array, 1);
534 configs = driConcatConfigs(configs_a8r8g8b8, configs_x8r8g8b8);
535 }
536
537 if (configs == NULL) {
538 fprintf(stderr, "[%s:%u] Error creating FBConfig!\n", __func__,
539 __LINE__);
540 return NULL;
541 }
542
543 /* Mark the visual as slow if there are "fake" stencil bits.
544 */
545 for (i = 0; configs[i]; i++) {
546 m = &configs[i]->modes;
547 if ((m->stencilBits != 0) && (m->stencilBits != stencil_bits)) {
548 m->visualRating = GLX_SLOW_CONFIG;
549 }
550 }
551
552 return configs;
553 }
554
555 static GLboolean
556 intel_init_bufmgr(intelScreenPrivate *intelScreen)
557 {
558 GLboolean gem_disable = getenv("INTEL_NO_GEM") != NULL;
559 int gem_kernel = 0;
560 GLboolean gem_supported;
561 struct drm_i915_getparam gp;
562 __DRIscreenPrivate *spriv = intelScreen->driScrnPriv;
563
564 intelScreen->no_hw = getenv("INTEL_NO_HW") != NULL;
565
566 gp.param = I915_PARAM_HAS_GEM;
567 gp.value = &gem_kernel;
568
569 (void) drmCommandWriteRead(spriv->fd, DRM_I915_GETPARAM, &gp, sizeof(gp));
570
571 /* If we've got a new enough DDX that's initializing GEM and giving us
572 * object handles for the shared buffers, use that.
573 */
574 intelScreen->ttm = GL_FALSE;
575 if (intelScreen->driScrnPriv->dri2.enabled)
576 gem_supported = GL_TRUE;
577 else if (intelScreen->driScrnPriv->ddx_version.minor >= 9 &&
578 gem_kernel &&
579 intelScreen->front.bo_handle != -1)
580 gem_supported = GL_TRUE;
581 else
582 gem_supported = GL_FALSE;
583
584 if (!gem_disable && gem_supported) {
585 intelScreen->bufmgr = intel_bufmgr_gem_init(spriv->fd, BATCH_SZ);
586 if (intelScreen->bufmgr != NULL)
587 intelScreen->ttm = GL_TRUE;
588 }
589 /* Otherwise, use the classic buffer manager. */
590 if (intelScreen->bufmgr == NULL) {
591 if (gem_disable) {
592 fprintf(stderr, "GEM disabled. Using classic.\n");
593 } else {
594 fprintf(stderr, "Failed to initialize GEM. "
595 "Falling back to classic.\n");
596 }
597
598 if (intelScreen->tex.size == 0) {
599 fprintf(stderr, "[%s:%u] Error initializing buffer manager.\n",
600 __func__, __LINE__);
601 return GL_FALSE;
602 }
603
604 intelScreen->bufmgr =
605 intel_bufmgr_fake_init(spriv->fd,
606 intelScreen->tex.offset,
607 intelScreen->tex.map,
608 intelScreen->tex.size,
609 (unsigned int * volatile)
610 &intelScreen->sarea->last_dispatch);
611 }
612
613 /* XXX bufmgr should be per-screen, not per-context */
614 intelScreen->ttm = intelScreen->ttm;
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 };