2355eafeca25976b0616dc7eecde573111426474
[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 "glheader.h"
29 #include "context.h"
30 #include "framebuffer.h"
31 #include "matrix.h"
32 #include "renderbuffer.h"
33 #include "simple_list.h"
34 #include "utils.h"
35 #include "vblank.h"
36 #include "xmlpool.h"
37
38
39 #include "intel_screen.h"
40
41 #include "intel_buffers.h"
42 #include "intel_tex.h"
43 #include "intel_span.h"
44 #include "intel_ioctl.h"
45 #include "intel_fbo.h"
46 #include "intel_chipset.h"
47
48 #include "i915_drm.h"
49 #include "i830_dri.h"
50 #include "intel_regions.h"
51 #include "intel_batchbuffer.h"
52 #include "intel_bufmgr.h"
53
54 PUBLIC const char __driConfigOptions[] =
55 DRI_CONF_BEGIN
56 DRI_CONF_SECTION_PERFORMANCE
57 DRI_CONF_FTHROTTLE_MODE(DRI_CONF_FTHROTTLE_IRQS)
58 DRI_CONF_VBLANK_MODE(DRI_CONF_VBLANK_ALWAYS_SYNC)
59 /* Options correspond to DRI_CONF_BO_REUSE_DISABLED,
60 * DRI_CONF_BO_REUSE_ALL
61 */
62 DRI_CONF_OPT_BEGIN_V(bo_reuse, enum, 1, "0:1")
63 DRI_CONF_DESC_BEGIN(en, "Buffer object reuse")
64 DRI_CONF_ENUM(0, "Disable buffer object reuse")
65 DRI_CONF_ENUM(1, "Enable reuse of all sizes of buffer objects")
66 DRI_CONF_DESC_END
67 DRI_CONF_OPT_END
68 DRI_CONF_SECTION_END
69 DRI_CONF_SECTION_QUALITY
70 DRI_CONF_FORCE_S3TC_ENABLE(false)
71 DRI_CONF_ALLOW_LARGE_TEXTURES(2)
72 DRI_CONF_SECTION_END
73 DRI_CONF_SECTION_DEBUG
74 DRI_CONF_NO_RAST(false)
75 DRI_CONF_SECTION_END
76 DRI_CONF_END;
77
78 const GLuint __driNConfigOptions = 6;
79
80 #ifdef USE_NEW_INTERFACE
81 static PFNGLXCREATECONTEXTMODES create_context_modes = NULL;
82 #endif /*USE_NEW_INTERFACE */
83
84 /**
85 * Map all the memory regions described by the screen.
86 * \return GL_TRUE if success, GL_FALSE if error.
87 */
88 GLboolean
89 intelMapScreenRegions(__DRIscreenPrivate * sPriv)
90 {
91 intelScreenPrivate *intelScreen = (intelScreenPrivate *) sPriv->private;
92
93 if (0)
94 _mesa_printf("TEX 0x%08x ", intelScreen->tex.handle);
95 if (intelScreen->tex.size != 0) {
96 if (drmMap(sPriv->fd,
97 intelScreen->tex.handle,
98 intelScreen->tex.size,
99 (drmAddress *) & intelScreen->tex.map) != 0) {
100 intelUnmapScreenRegions(intelScreen);
101 return GL_FALSE;
102 }
103 }
104
105 return GL_TRUE;
106 }
107
108 void
109 intelUnmapScreenRegions(intelScreenPrivate * intelScreen)
110 {
111 if (intelScreen->tex.map) {
112 drmUnmap(intelScreen->tex.map, intelScreen->tex.size);
113 intelScreen->tex.map = NULL;
114 }
115 }
116
117
118 static void
119 intelPrintDRIInfo(intelScreenPrivate * intelScreen,
120 __DRIscreenPrivate * sPriv, I830DRIPtr gDRIPriv)
121 {
122 fprintf(stderr, "*** Front size: 0x%x offset: 0x%x pitch: %d\n",
123 intelScreen->front.size, intelScreen->front.offset,
124 intelScreen->pitch);
125 fprintf(stderr, "*** Back size: 0x%x offset: 0x%x pitch: %d\n",
126 intelScreen->back.size, intelScreen->back.offset,
127 intelScreen->pitch);
128 fprintf(stderr, "*** Depth size: 0x%x offset: 0x%x pitch: %d\n",
129 intelScreen->depth.size, intelScreen->depth.offset,
130 intelScreen->pitch);
131 fprintf(stderr, "*** Texture size: 0x%x offset: 0x%x\n",
132 intelScreen->tex.size, intelScreen->tex.offset);
133 fprintf(stderr, "*** Memory : 0x%x\n", gDRIPriv->mem);
134 }
135
136
137 static void
138 intelPrintSAREA(const struct drm_i915_sarea * sarea)
139 {
140 fprintf(stderr, "SAREA: sarea width %d height %d\n", sarea->width,
141 sarea->height);
142 fprintf(stderr, "SAREA: pitch: %d\n", sarea->pitch);
143 fprintf(stderr,
144 "SAREA: front offset: 0x%08x size: 0x%x handle: 0x%x tiled: %d\n",
145 sarea->front_offset, sarea->front_size,
146 (unsigned) sarea->front_handle, sarea->front_tiled);
147 fprintf(stderr,
148 "SAREA: back offset: 0x%08x size: 0x%x handle: 0x%x tiled: %d\n",
149 sarea->back_offset, sarea->back_size,
150 (unsigned) sarea->back_handle, sarea->back_tiled);
151 fprintf(stderr, "SAREA: depth offset: 0x%08x size: 0x%x handle: 0x%x tiled: %d\n",
152 sarea->depth_offset, sarea->depth_size,
153 (unsigned) sarea->depth_handle, sarea->depth_tiled);
154 fprintf(stderr, "SAREA: tex offset: 0x%08x size: 0x%x handle: 0x%x\n",
155 sarea->tex_offset, sarea->tex_size, (unsigned) sarea->tex_handle);
156 }
157
158
159 /**
160 * A number of the screen parameters are obtained/computed from
161 * information in the SAREA. This function updates those parameters.
162 */
163 void
164 intelUpdateScreenFromSAREA(intelScreenPrivate * intelScreen,
165 struct drm_i915_sarea * sarea)
166 {
167 intelScreen->width = sarea->width;
168 intelScreen->height = sarea->height;
169 intelScreen->pitch = sarea->pitch;
170
171 intelScreen->front.offset = sarea->front_offset;
172 intelScreen->front.handle = sarea->front_handle;
173 intelScreen->front.size = sarea->front_size;
174 intelScreen->front.tiled = sarea->front_tiled;
175
176 intelScreen->back.offset = sarea->back_offset;
177 intelScreen->back.handle = sarea->back_handle;
178 intelScreen->back.size = sarea->back_size;
179 intelScreen->back.tiled = sarea->back_tiled;
180
181 if (intelScreen->driScrnPriv->ddx_version.minor >= 8) {
182 intelScreen->third.offset = sarea->third_offset;
183 intelScreen->third.handle = sarea->third_handle;
184 intelScreen->third.size = sarea->third_size;
185 intelScreen->third.tiled = sarea->third_tiled;
186 }
187
188 intelScreen->depth.offset = sarea->depth_offset;
189 intelScreen->depth.handle = sarea->depth_handle;
190 intelScreen->depth.size = sarea->depth_size;
191 intelScreen->depth.tiled = sarea->depth_tiled;
192
193 if (intelScreen->driScrnPriv->ddx_version.minor >= 9) {
194 intelScreen->front.bo_handle = sarea->front_bo_handle;
195 intelScreen->back.bo_handle = sarea->back_bo_handle;
196 intelScreen->third.bo_handle = sarea->third_bo_handle;
197 intelScreen->depth.bo_handle = sarea->depth_bo_handle;
198 } else {
199 intelScreen->front.bo_handle = -1;
200 intelScreen->back.bo_handle = -1;
201 intelScreen->third.bo_handle = -1;
202 intelScreen->depth.bo_handle = -1;
203 }
204
205 intelScreen->tex.offset = sarea->tex_offset;
206 intelScreen->logTextureGranularity = sarea->log_tex_granularity;
207 intelScreen->tex.handle = sarea->tex_handle;
208 intelScreen->tex.size = sarea->tex_size;
209
210 if (0)
211 intelPrintSAREA(sarea);
212 }
213
214 static const __DRItexOffsetExtension intelTexOffsetExtension = {
215 { __DRI_TEX_OFFSET },
216 intelSetTexOffset,
217 };
218
219 static const __DRItexBufferExtension intelTexBufferExtension = {
220 { __DRI_TEX_BUFFER, __DRI_TEX_BUFFER_VERSION },
221 intelSetTexBuffer,
222 };
223
224 static const __DRIextension *intelScreenExtensions[] = {
225 &driReadDrawableExtension,
226 &driCopySubBufferExtension.base,
227 &driSwapControlExtension.base,
228 &driFrameTrackingExtension.base,
229 &driMediaStreamCounterExtension.base,
230 &intelTexOffsetExtension.base,
231 &intelTexBufferExtension.base,
232 NULL
233 };
234
235 static GLboolean
236 intel_get_param(__DRIscreenPrivate *psp, int param, int *value)
237 {
238 int ret;
239 struct drm_i915_getparam gp;
240
241 gp.param = param;
242 gp.value = value;
243
244 ret = drmCommandWriteRead(psp->fd, DRM_I915_GETPARAM, &gp, sizeof(gp));
245 if (ret) {
246 fprintf(stderr, "drm_i915_getparam: %d\n", ret);
247 return GL_FALSE;
248 }
249
250 return GL_TRUE;
251 }
252
253 static GLboolean intelInitDriver(__DRIscreenPrivate *sPriv)
254 {
255 intelScreenPrivate *intelScreen;
256 I830DRIPtr gDRIPriv = (I830DRIPtr) sPriv->pDevPriv;
257 struct drm_i915_sarea *sarea;
258
259 if (sPriv->devPrivSize != sizeof(I830DRIRec)) {
260 fprintf(stderr,
261 "\nERROR! sizeof(I830DRIRec) does not match passed size from device driver\n");
262 return GL_FALSE;
263 }
264
265 /* Allocate the private area */
266 intelScreen = (intelScreenPrivate *) CALLOC(sizeof(intelScreenPrivate));
267 if (!intelScreen) {
268 fprintf(stderr, "\nERROR! Allocating private area failed\n");
269 return GL_FALSE;
270 }
271 /* parse information in __driConfigOptions */
272 driParseOptionInfo(&intelScreen->optionCache,
273 __driConfigOptions, __driNConfigOptions);
274
275 intelScreen->driScrnPriv = sPriv;
276 sPriv->private = (void *) intelScreen;
277 sarea = (struct drm_i915_sarea *)
278 (((GLubyte *) sPriv->pSAREA) + gDRIPriv->sarea_priv_offset);
279 intelScreen->sarea = sarea;
280
281 intelScreen->deviceID = gDRIPriv->deviceID;
282
283 intelUpdateScreenFromSAREA(intelScreen, sarea);
284
285 if (!intelMapScreenRegions(sPriv)) {
286 fprintf(stderr, "\nERROR! mapping regions\n");
287 _mesa_free(intelScreen);
288 sPriv->private = NULL;
289 return GL_FALSE;
290 }
291
292 if (0)
293 intelPrintDRIInfo(intelScreen, sPriv, gDRIPriv);
294
295 intelScreen->drmMinor = sPriv->drm_version.minor;
296
297 /* Determine if IRQs are active? */
298 if (!intel_get_param(sPriv, I915_PARAM_IRQ_ACTIVE,
299 &intelScreen->irq_active))
300 return GL_FALSE;
301
302 /* Determine if batchbuffers are allowed */
303 if (!intel_get_param(sPriv, I915_PARAM_ALLOW_BATCHBUFFER,
304 &intelScreen->allow_batchbuffer))
305 return GL_FALSE;
306
307 sPriv->extensions = intelScreenExtensions;
308
309 return GL_TRUE;
310 }
311
312
313 static void
314 intelDestroyScreen(__DRIscreenPrivate * sPriv)
315 {
316 intelScreenPrivate *intelScreen = (intelScreenPrivate *) sPriv->private;
317
318 intelUnmapScreenRegions(intelScreen);
319
320 FREE(intelScreen);
321 sPriv->private = NULL;
322 }
323
324
325 /**
326 * This is called when we need to set up GL rendering to a new X window.
327 */
328 static GLboolean
329 intelCreateBuffer(__DRIscreenPrivate * driScrnPriv,
330 __DRIdrawablePrivate * driDrawPriv,
331 const __GLcontextModes * mesaVis, GLboolean isPixmap)
332 {
333 intelScreenPrivate *screen = (intelScreenPrivate *) driScrnPriv->private;
334
335 if (isPixmap) {
336 return GL_FALSE; /* not implemented */
337 }
338 else {
339 GLboolean swStencil = (mesaVis->stencilBits > 0 &&
340 mesaVis->depthBits != 24);
341 GLenum rgbFormat = (mesaVis->redBits == 5 ? GL_RGB5 : GL_RGBA8);
342
343 struct intel_framebuffer *intel_fb = CALLOC_STRUCT(intel_framebuffer);
344
345 if (!intel_fb)
346 return GL_FALSE;
347
348 _mesa_initialize_framebuffer(&intel_fb->Base, mesaVis);
349
350 /* setup the hardware-based renderbuffers */
351 intel_fb->color_rb[0] = intel_create_renderbuffer(rgbFormat);
352 _mesa_add_renderbuffer(&intel_fb->Base, BUFFER_FRONT_LEFT,
353 &intel_fb->color_rb[0]->Base);
354
355 if (mesaVis->doubleBufferMode) {
356 intel_fb->color_rb[1] = intel_create_renderbuffer(rgbFormat);
357
358 _mesa_add_renderbuffer(&intel_fb->Base, BUFFER_BACK_LEFT,
359 &intel_fb->color_rb[1]->Base);
360
361 if (screen->third.handle) {
362 struct gl_renderbuffer *tmp_rb = NULL;
363
364 intel_fb->color_rb[2] = intel_create_renderbuffer(rgbFormat);
365 _mesa_reference_renderbuffer(&tmp_rb, &intel_fb->color_rb[2]->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_unreference_framebuffer((GLframebuffer **)(&(driDrawPriv->driverPrivate)));
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 return i830CreateContext(mesaVis, driContextPriv, sharedContextPrivate);
470 }
471 #else
472 if (IS_965(intelScreen->deviceID))
473 return brwCreateContext(mesaVis, driContextPriv, sharedContextPrivate);
474 #endif
475 fprintf(stderr, "Unrecognized deviceID %x\n", intelScreen->deviceID);
476 return GL_FALSE;
477 }
478
479
480 static __DRIconfig **
481 intelFillInModes(__DRIscreenPrivate *psp,
482 unsigned pixel_bits, unsigned depth_bits,
483 unsigned stencil_bits, GLboolean have_back_buffer)
484 {
485 __DRIconfig **configs;
486 __GLcontextModes *m;
487 unsigned depth_buffer_factor;
488 unsigned back_buffer_factor;
489 GLenum fb_format;
490 GLenum fb_type;
491 int i;
492
493 /* GLX_SWAP_COPY_OML is only supported because the Intel driver doesn't
494 * support pageflipping at all.
495 */
496 static const GLenum back_buffer_modes[] = {
497 GLX_NONE, GLX_SWAP_UNDEFINED_OML, GLX_SWAP_COPY_OML
498 };
499
500 u_int8_t depth_bits_array[3];
501 u_int8_t stencil_bits_array[3];
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 depth_buffer_factor = ((depth_bits != 0) || (stencil_bits != 0)) ? 3 : 1;
519 back_buffer_factor = (have_back_buffer) ? 3 : 1;
520
521 if (pixel_bits == 16) {
522 fb_format = GL_RGB;
523 fb_type = GL_UNSIGNED_SHORT_5_6_5;
524 }
525 else {
526 fb_format = GL_BGRA;
527 fb_type = GL_UNSIGNED_INT_8_8_8_8_REV;
528 }
529
530 configs = driCreateConfigs(fb_format, fb_type,
531 depth_bits_array, stencil_bits_array,
532 depth_buffer_factor, back_buffer_modes,
533 back_buffer_factor);
534 if (configs == NULL) {
535 fprintf(stderr, "[%s:%u] Error creating FBConfig!\n", __func__,
536 __LINE__);
537 return NULL;
538 }
539
540 /* Mark the visual as slow if there are "fake" stencil bits.
541 */
542 for (i = 0; configs[i]; i++) {
543 m = &configs[i]->modes;
544 if ((m->stencilBits != 0) && (m->stencilBits != stencil_bits)) {
545 m->visualRating = GLX_SLOW_CONFIG;
546 }
547 }
548
549 return configs;
550 }
551
552 static GLboolean
553 intel_init_bufmgr(intelScreenPrivate *intelScreen)
554 {
555 GLboolean gem_disable = getenv("INTEL_NO_GEM") != NULL;
556 int gem_kernel = 0;
557 GLboolean gem_supported;
558 struct drm_i915_getparam gp;
559 __DRIscreenPrivate *spriv = intelScreen->driScrnPriv;
560
561 intelScreen->no_hw = getenv("INTEL_NO_HW") != NULL;
562
563 gp.param = I915_PARAM_HAS_GEM;
564 gp.value = &gem_kernel;
565
566 (void) drmCommandWriteRead(spriv->fd, DRM_I915_GETPARAM, &gp, sizeof(gp));
567
568 /* If we've got a new enough DDX that's initializing GEM and giving us
569 * object handles for the shared buffers, use that.
570 */
571 intelScreen->ttm = GL_FALSE;
572 if (intelScreen->driScrnPriv->dri2.enabled)
573 gem_supported = GL_TRUE;
574 else if (intelScreen->driScrnPriv->ddx_version.minor >= 9 &&
575 gem_kernel &&
576 intelScreen->front.bo_handle != -1)
577 gem_supported = GL_TRUE;
578 else
579 gem_supported = GL_FALSE;
580
581 if (!gem_disable && gem_supported) {
582 intelScreen->bufmgr = intel_bufmgr_gem_init(spriv->fd, BATCH_SZ);
583 if (intelScreen->bufmgr != NULL)
584 intelScreen->ttm = GL_TRUE;
585 }
586 /* Otherwise, use the classic buffer manager. */
587 if (intelScreen->bufmgr == NULL) {
588 if (gem_disable) {
589 fprintf(stderr, "GEM disabled. Using classic.\n");
590 } else {
591 fprintf(stderr, "Failed to initialize GEM. "
592 "Falling back to classic.\n");
593 }
594
595 if (intelScreen->tex.size == 0) {
596 fprintf(stderr, "[%s:%u] Error initializing buffer manager.\n",
597 __func__, __LINE__);
598 return GL_FALSE;
599 }
600
601 intelScreen->bufmgr =
602 intel_bufmgr_fake_init(spriv->fd,
603 intelScreen->tex.offset,
604 intelScreen->tex.map,
605 intelScreen->tex.size,
606 (unsigned int * volatile)
607 &intelScreen->sarea->last_dispatch);
608 }
609
610 /* XXX bufmgr should be per-screen, not per-context */
611 intelScreen->ttm = intelScreen->ttm;
612
613 return GL_TRUE;
614 }
615
616 /**
617 * This is the driver specific part of the createNewScreen entry point.
618 * Called when using legacy DRI.
619 *
620 * \todo maybe fold this into intelInitDriver
621 *
622 * \return the __GLcontextModes supported by this driver
623 */
624 static const __DRIconfig **intelInitScreen(__DRIscreenPrivate *psp)
625 {
626 intelScreenPrivate *intelScreen;
627 #ifdef I915
628 static const __DRIversion ddx_expected = { 1, 5, 0 };
629 #else
630 static const __DRIversion ddx_expected = { 1, 6, 0 };
631 #endif
632 static const __DRIversion dri_expected = { 4, 0, 0 };
633 static const __DRIversion drm_expected = { 1, 5, 0 };
634 I830DRIPtr dri_priv = (I830DRIPtr) psp->pDevPriv;
635
636 if (!driCheckDriDdxDrmVersions2("i915",
637 &psp->dri_version, &dri_expected,
638 &psp->ddx_version, &ddx_expected,
639 &psp->drm_version, &drm_expected)) {
640 return NULL;
641 }
642
643 /* Calling driInitExtensions here, with a NULL context pointer,
644 * does not actually enable the extensions. It just makes sure
645 * that all the dispatch offsets for all the extensions that
646 * *might* be enables are known. This is needed because the
647 * dispatch offsets need to be known when _mesa_context_create is
648 * called, but we can't enable the extensions until we have a
649 * context pointer.
650 *
651 * Hello chicken. Hello egg. How are you two today?
652 */
653 intelInitExtensions(NULL, GL_TRUE);
654
655 if (!intelInitDriver(psp))
656 return NULL;
657
658 psp->extensions = intelScreenExtensions;
659
660 intelScreen = psp->private;
661 if (!intel_init_bufmgr(intelScreen))
662 return GL_FALSE;
663
664 return (const __DRIconfig **)
665 intelFillInModes(psp, dri_priv->cpp * 8,
666 (dri_priv->cpp == 2) ? 16 : 24,
667 (dri_priv->cpp == 2) ? 0 : 8, 1);
668 }
669
670 struct intel_context *intelScreenContext(intelScreenPrivate *intelScreen)
671 {
672 /*
673 * This should probably change to have the screen allocate a dummy
674 * context at screen creation. For now just use the current context.
675 */
676
677 GET_CURRENT_CONTEXT(ctx);
678 if (ctx == NULL) {
679 _mesa_problem(NULL, "No current context in intelScreenContext\n");
680 return NULL;
681 }
682 return intel_context(ctx);
683 }
684
685 /**
686 * This is the driver specific part of the createNewScreen entry point.
687 * Called when using DRI2.
688 *
689 * \return the __GLcontextModes supported by this driver
690 */
691 static const
692 __DRIconfig **intelInitScreen2(__DRIscreenPrivate *psp)
693 {
694 intelScreenPrivate *intelScreen;
695
696 /* Calling driInitExtensions here, with a NULL context pointer,
697 * does not actually enable the extensions. It just makes sure
698 * that all the dispatch offsets for all the extensions that
699 * *might* be enables are known. This is needed because the
700 * dispatch offsets need to be known when _mesa_context_create is
701 * called, but we can't enable the extensions until we have a
702 * context pointer.
703 *
704 * Hello chicken. Hello egg. How are you two today?
705 */
706 intelInitExtensions(NULL, GL_TRUE);
707
708 /* Allocate the private area */
709 intelScreen = (intelScreenPrivate *) CALLOC(sizeof(intelScreenPrivate));
710 if (!intelScreen) {
711 fprintf(stderr, "\nERROR! Allocating private area failed\n");
712 return GL_FALSE;
713 }
714 /* parse information in __driConfigOptions */
715 driParseOptionInfo(&intelScreen->optionCache,
716 __driConfigOptions, __driNConfigOptions);
717
718 intelScreen->driScrnPriv = psp;
719 psp->private = (void *) intelScreen;
720
721 intelScreen->drmMinor = psp->drm_version.minor;
722
723 /* Determine chipset ID */
724 if (!intel_get_param(psp, I915_PARAM_CHIPSET_ID,
725 &intelScreen->deviceID))
726 return GL_FALSE;
727
728 if (!intel_init_bufmgr(intelScreen))
729 return GL_FALSE;
730
731 intelScreen->irq_active = 1;
732 psp->extensions = intelScreenExtensions;
733
734 return driConcatConfigs(intelFillInModes(psp, 16, 16, 0, 1),
735 intelFillInModes(psp, 32, 24, 8, 1));
736 }
737
738 const struct __DriverAPIRec driDriverAPI = {
739 .InitScreen = intelInitScreen,
740 .DestroyScreen = intelDestroyScreen,
741 .CreateContext = intelCreateContext,
742 .DestroyContext = intelDestroyContext,
743 .CreateBuffer = intelCreateBuffer,
744 .DestroyBuffer = intelDestroyBuffer,
745 .SwapBuffers = intelSwapBuffers,
746 .MakeCurrent = intelMakeCurrent,
747 .UnbindContext = intelUnbindContext,
748 .GetSwapInfo = intelGetSwapInfo,
749 .GetDrawableMSC = driDrawableGetMSC32,
750 .WaitForMSC = driWaitForMSC32,
751 .CopySubBuffer = intelCopySubBuffer,
752
753 .InitScreen2 = intelInitScreen2,
754 };