[i915] Remove old frontbuffer rotation hack.
[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_tris.h"
45 #include "intel_ioctl.h"
46 #include "intel_fbo.h"
47
48 #include "i830_dri.h"
49 #include "dri_bufmgr.h"
50 #include "intel_regions.h"
51 #include "intel_batchbuffer.h"
52
53 #include "intel_bufmgr_ttm.h"
54
55 PUBLIC const char __driConfigOptions[] =
56 DRI_CONF_BEGIN DRI_CONF_SECTION_PERFORMANCE
57 DRI_CONF_FTHROTTLE_MODE(DRI_CONF_FTHROTTLE_IRQS)
58 DRI_CONF_VBLANK_MODE(DRI_CONF_VBLANK_DEF_INTERVAL_0)
59 DRI_CONF_SECTION_END DRI_CONF_SECTION_QUALITY
60 DRI_CONF_FORCE_S3TC_ENABLE(false)
61 DRI_CONF_ALLOW_LARGE_TEXTURES(1)
62 DRI_CONF_SECTION_END DRI_CONF_END;
63 const GLuint __driNConfigOptions = 4;
64
65 #ifdef USE_NEW_INTERFACE
66 static PFNGLXCREATECONTEXTMODES create_context_modes = NULL;
67 #endif /*USE_NEW_INTERFACE */
68
69 extern const struct dri_extension card_extensions[];
70 extern const struct dri_extension ttm_extensions[];
71
72 /**
73 * Map all the memory regions described by the screen.
74 * \return GL_TRUE if success, GL_FALSE if error.
75 */
76 GLboolean
77 intelMapScreenRegions(__DRIscreenPrivate * sPriv)
78 {
79 intelScreenPrivate *intelScreen = (intelScreenPrivate *) sPriv->private;
80
81 if (intelScreen->front.handle) {
82 if (drmMap(sPriv->fd,
83 intelScreen->front.handle,
84 intelScreen->front.size,
85 (drmAddress *) & intelScreen->front.map) != 0) {
86 _mesa_problem(NULL, "drmMap(frontbuffer) failed!");
87 return GL_FALSE;
88 }
89 }
90 else {
91 _mesa_warning(NULL, "no front buffer handle in intelMapScreenRegions!");
92 }
93
94 if (0)
95 _mesa_printf("Back 0x%08x ", intelScreen->back.handle);
96 if (drmMap(sPriv->fd,
97 intelScreen->back.handle,
98 intelScreen->back.size,
99 (drmAddress *) & intelScreen->back.map) != 0) {
100 intelUnmapScreenRegions(intelScreen);
101 return GL_FALSE;
102 }
103
104 if (intelScreen->third.handle) {
105 if (0)
106 _mesa_printf("Third 0x%08x ", intelScreen->third.handle);
107 if (drmMap(sPriv->fd,
108 intelScreen->third.handle,
109 intelScreen->third.size,
110 (drmAddress *) & intelScreen->third.map) != 0) {
111 intelUnmapScreenRegions(intelScreen);
112 return GL_FALSE;
113 }
114 }
115
116 if (0)
117 _mesa_printf("Depth 0x%08x ", intelScreen->depth.handle);
118 if (drmMap(sPriv->fd,
119 intelScreen->depth.handle,
120 intelScreen->depth.size,
121 (drmAddress *) & intelScreen->depth.map) != 0) {
122 intelUnmapScreenRegions(intelScreen);
123 return GL_FALSE;
124 }
125
126 if (0)
127 _mesa_printf("TEX 0x%08x ", intelScreen->tex.handle);
128 if (intelScreen->tex.size != 0) {
129 if (drmMap(sPriv->fd,
130 intelScreen->tex.handle,
131 intelScreen->tex.size,
132 (drmAddress *) & intelScreen->tex.map) != 0) {
133 intelUnmapScreenRegions(intelScreen);
134 return GL_FALSE;
135 }
136 }
137
138 if (0)
139 printf("Mappings: front: %p back: %p third: %p depth: %p tex: %p\n",
140 intelScreen->front.map,
141 intelScreen->back.map, intelScreen->third.map,
142 intelScreen->depth.map, intelScreen->tex.map);
143 return GL_TRUE;
144 }
145
146 /** Driver-specific fence emit implementation for the fake memory manager. */
147 static unsigned int
148 intel_fence_emit(void *private)
149 {
150 intelScreenPrivate *intelScreen = (intelScreenPrivate *)private;
151 unsigned int fence;
152
153 /* XXX: Need to emit a flush, if we haven't already (at least with the
154 * current batchbuffer implementation, we have).
155 */
156
157 fence = intelEmitIrqLocked(intelScreen);
158
159 return fence;
160 }
161
162 /** Driver-specific fence wait implementation for the fake memory manager. */
163 static int
164 intel_fence_wait(void *private, unsigned int cookie)
165 {
166 intelScreenPrivate *intelScreen = (intelScreenPrivate *)private;
167
168 intelWaitIrq(intelScreen, cookie);
169
170 return 0;
171 }
172
173 static struct intel_region *
174 intel_recreate_static(intelScreenPrivate *intelScreen,
175 struct intel_region *region,
176 intelRegion *region_desc,
177 GLuint mem_type)
178 {
179 if (region) {
180 intel_region_update_static(intelScreen, region, mem_type,
181 region_desc->bo_handle, region_desc->offset,
182 region_desc->map, intelScreen->cpp,
183 region_desc->pitch / intelScreen->cpp,
184 intelScreen->height);
185 } else {
186 region = intel_region_create_static(intelScreen, mem_type,
187 region_desc->bo_handle,
188 region_desc->offset,
189 region_desc->map, intelScreen->cpp,
190 region_desc->pitch / intelScreen->cpp,
191 intelScreen->height);
192 }
193
194 assert(region->buffer != NULL);
195
196 return region;
197 }
198
199
200 /* Create intel_region structs to describe the static front,back,depth
201 * buffers created by the xserver.
202 *
203 * Although FBO's mean we now no longer use these as render targets in
204 * all circumstances, they won't go away until the back and depth
205 * buffers become private, and the front buffer will remain even then.
206 *
207 * Note that these don't allocate video memory, just describe
208 * allocations alread made by the X server.
209 */
210 static void
211 intel_recreate_static_regions(intelScreenPrivate *intelScreen)
212 {
213 intelScreen->front_region =
214 intel_recreate_static(intelScreen,
215 intelScreen->front_region,
216 &intelScreen->front,
217 DRM_BO_FLAG_MEM_TT);
218
219 intelScreen->back_region =
220 intel_recreate_static(intelScreen,
221 intelScreen->back_region,
222 &intelScreen->back,
223 DRM_BO_FLAG_MEM_TT);
224
225 if (intelScreen->third.handle) {
226 intelScreen->third_region =
227 intel_recreate_static(intelScreen,
228 intelScreen->third_region,
229 &intelScreen->third,
230 DRM_BO_FLAG_MEM_TT);
231 }
232
233 /* Still assumes front.cpp == depth.cpp. We can kill this when we move to
234 * private buffers.
235 */
236 intelScreen->depth_region =
237 intel_recreate_static(intelScreen,
238 intelScreen->depth_region,
239 &intelScreen->depth,
240 DRM_BO_FLAG_MEM_TT);
241 }
242
243 void
244 intelUnmapScreenRegions(intelScreenPrivate * intelScreen)
245 {
246 #define REALLY_UNMAP 1
247 if (intelScreen->front.map) {
248 #if REALLY_UNMAP
249 if (drmUnmap(intelScreen->front.map, intelScreen->front.size) != 0)
250 printf("drmUnmap front failed!\n");
251 #endif
252 intelScreen->front.map = NULL;
253 }
254 if (intelScreen->back.map) {
255 #if REALLY_UNMAP
256 if (drmUnmap(intelScreen->back.map, intelScreen->back.size) != 0)
257 printf("drmUnmap back failed!\n");
258 #endif
259 intelScreen->back.map = NULL;
260 }
261 if (intelScreen->third.map) {
262 #if REALLY_UNMAP
263 if (drmUnmap(intelScreen->third.map, intelScreen->third.size) != 0)
264 printf("drmUnmap third failed!\n");
265 #endif
266 intelScreen->third.map = NULL;
267 }
268 if (intelScreen->depth.map) {
269 #if REALLY_UNMAP
270 drmUnmap(intelScreen->depth.map, intelScreen->depth.size);
271 intelScreen->depth.map = NULL;
272 #endif
273 }
274 if (intelScreen->tex.map) {
275 #if REALLY_UNMAP
276 drmUnmap(intelScreen->tex.map, intelScreen->tex.size);
277 intelScreen->tex.map = NULL;
278 #endif
279 }
280 }
281
282
283 static void
284 intelPrintDRIInfo(intelScreenPrivate * intelScreen,
285 __DRIscreenPrivate * sPriv, I830DRIPtr gDRIPriv)
286 {
287 fprintf(stderr, "*** Front size: 0x%x offset: 0x%x pitch: %d\n",
288 intelScreen->front.size, intelScreen->front.offset,
289 intelScreen->front.pitch);
290 fprintf(stderr, "*** Back size: 0x%x offset: 0x%x pitch: %d\n",
291 intelScreen->back.size, intelScreen->back.offset,
292 intelScreen->back.pitch);
293 fprintf(stderr, "*** Depth size: 0x%x offset: 0x%x pitch: %d\n",
294 intelScreen->depth.size, intelScreen->depth.offset,
295 intelScreen->depth.pitch);
296 fprintf(stderr, "*** Texture size: 0x%x offset: 0x%x\n",
297 intelScreen->tex.size, intelScreen->tex.offset);
298 fprintf(stderr, "*** Memory : 0x%x\n", gDRIPriv->mem);
299 }
300
301
302 static void
303 intelPrintSAREA(const drmI830Sarea * sarea)
304 {
305 fprintf(stderr, "SAREA: sarea width %d height %d\n", sarea->width,
306 sarea->height);
307 fprintf(stderr, "SAREA: pitch: %d\n", sarea->pitch);
308 fprintf(stderr,
309 "SAREA: front offset: 0x%08x size: 0x%x handle: 0x%x\n",
310 sarea->front_offset, sarea->front_size,
311 (unsigned) sarea->front_handle);
312 fprintf(stderr,
313 "SAREA: back offset: 0x%08x size: 0x%x handle: 0x%x\n",
314 sarea->back_offset, sarea->back_size,
315 (unsigned) sarea->back_handle);
316 fprintf(stderr, "SAREA: depth offset: 0x%08x size: 0x%x handle: 0x%x\n",
317 sarea->depth_offset, sarea->depth_size,
318 (unsigned) sarea->depth_handle);
319 fprintf(stderr, "SAREA: tex offset: 0x%08x size: 0x%x handle: 0x%x\n",
320 sarea->tex_offset, sarea->tex_size, (unsigned) sarea->tex_handle);
321 }
322
323
324 /**
325 * A number of the screen parameters are obtained/computed from
326 * information in the SAREA. This function updates those parameters.
327 */
328 void
329 intelUpdateScreenFromSAREA(intelScreenPrivate * intelScreen,
330 drmI830Sarea * sarea)
331 {
332 intelScreen->width = sarea->width;
333 intelScreen->height = sarea->height;
334
335 intelScreen->front.offset = sarea->front_offset;
336 intelScreen->front.pitch = sarea->pitch * intelScreen->cpp;
337 intelScreen->front.handle = sarea->front_handle;
338 intelScreen->front.size = sarea->front_size;
339
340 intelScreen->back.offset = sarea->back_offset;
341 intelScreen->back.pitch = sarea->pitch * intelScreen->cpp;
342 intelScreen->back.handle = sarea->back_handle;
343 intelScreen->back.size = sarea->back_size;
344
345 if (intelScreen->driScrnPriv->ddx_version.minor >= 8) {
346 intelScreen->third.offset = sarea->third_offset;
347 intelScreen->third.pitch = sarea->pitch * intelScreen->cpp;
348 intelScreen->third.handle = sarea->third_handle;
349 intelScreen->third.size = sarea->third_size;
350 }
351
352 intelScreen->depth.offset = sarea->depth_offset;
353 intelScreen->depth.pitch = sarea->pitch * intelScreen->cpp;
354 intelScreen->depth.handle = sarea->depth_handle;
355 intelScreen->depth.size = sarea->depth_size;
356
357 if (intelScreen->driScrnPriv->ddx_version.minor >= 9) {
358 intelScreen->front.bo_handle = sarea->front_bo_handle;
359 intelScreen->back.bo_handle = sarea->back_bo_handle;
360 intelScreen->third.bo_handle = sarea->third_bo_handle;
361 intelScreen->depth.bo_handle = sarea->depth_bo_handle;
362 } else {
363 intelScreen->front.bo_handle = -1;
364 intelScreen->back.bo_handle = -1;
365 intelScreen->third.bo_handle = -1;
366 intelScreen->depth.bo_handle = -1;
367 }
368
369 intelScreen->tex.offset = sarea->tex_offset;
370 intelScreen->logTextureGranularity = sarea->log_tex_granularity;
371 intelScreen->tex.handle = sarea->tex_handle;
372 intelScreen->tex.size = sarea->tex_size;
373
374 if (0)
375 intelPrintSAREA(sarea);
376 }
377
378 static const __DRItexOffsetExtension intelTexOffsetExtension = {
379 { __DRI_TEX_OFFSET },
380 intelSetTexOffset,
381 };
382
383 static const __DRIextension *intelExtensions[] = {
384 &driReadDrawableExtension,
385 &driCopySubBufferExtension.base,
386 &driSwapControlExtension.base,
387 &driFrameTrackingExtension.base,
388 &driMediaStreamCounterExtension.base,
389 &intelTexOffsetExtension.base,
390 NULL
391 };
392
393
394 static GLboolean intelInitDriver(__DRIscreenPrivate *sPriv)
395 {
396 intelScreenPrivate *intelScreen;
397 I830DRIPtr gDRIPriv = (I830DRIPtr) sPriv->pDevPriv;
398 drmI830Sarea *sarea;
399
400 if (sPriv->devPrivSize != sizeof(I830DRIRec)) {
401 fprintf(stderr,
402 "\nERROR! sizeof(I830DRIRec) does not match passed size from device driver\n");
403 return GL_FALSE;
404 }
405
406 /* Allocate the private area */
407 intelScreen = (intelScreenPrivate *) CALLOC(sizeof(intelScreenPrivate));
408 if (!intelScreen) {
409 fprintf(stderr, "\nERROR! Allocating private area failed\n");
410 return GL_FALSE;
411 }
412 /* parse information in __driConfigOptions */
413 driParseOptionInfo(&intelScreen->optionCache,
414 __driConfigOptions, __driNConfigOptions);
415
416 intelScreen->driScrnPriv = sPriv;
417 sPriv->private = (void *) intelScreen;
418 intelScreen->sarea_priv_offset = gDRIPriv->sarea_priv_offset;
419 sarea = (drmI830Sarea *)
420 (((GLubyte *) sPriv->pSAREA) + intelScreen->sarea_priv_offset);
421
422 intelScreen->deviceID = gDRIPriv->deviceID;
423 if (intelScreen->deviceID == PCI_CHIP_I865_G)
424 intelScreen->maxBatchSize = 4096;
425 else
426 intelScreen->maxBatchSize = BATCH_SZ;
427
428 intelScreen->mem = gDRIPriv->mem;
429 intelScreen->cpp = gDRIPriv->cpp;
430
431 switch (gDRIPriv->bitsPerPixel) {
432 case 16:
433 intelScreen->fbFormat = DV_PF_565;
434 break;
435 case 32:
436 intelScreen->fbFormat = DV_PF_8888;
437 break;
438 default:
439 exit(1);
440 break;
441 }
442
443 intelUpdateScreenFromSAREA(intelScreen, sarea);
444
445 if (!intelMapScreenRegions(sPriv)) {
446 fprintf(stderr, "\nERROR! mapping regions\n");
447 _mesa_free(intelScreen);
448 sPriv->private = NULL;
449 return GL_FALSE;
450 }
451
452 intelScreen->sarea_priv_offset = gDRIPriv->sarea_priv_offset;
453
454 if (0)
455 intelPrintDRIInfo(intelScreen, sPriv, gDRIPriv);
456
457 intelScreen->drmMinor = sPriv->drm_version.minor;
458
459 /* Determine if IRQs are active? */
460 {
461 int ret;
462 drmI830GetParam gp;
463
464 gp.param = I830_PARAM_IRQ_ACTIVE;
465 gp.value = &intelScreen->irq_active;
466
467 ret = drmCommandWriteRead(sPriv->fd, DRM_I830_GETPARAM,
468 &gp, sizeof(gp));
469 if (ret) {
470 fprintf(stderr, "drmI830GetParam: %d\n", ret);
471 return GL_FALSE;
472 }
473 }
474
475 /* Determine if batchbuffers are allowed */
476 {
477 int ret;
478 drmI830GetParam gp;
479
480 gp.param = I830_PARAM_ALLOW_BATCHBUFFER;
481 gp.value = &intelScreen->allow_batchbuffer;
482
483 ret = drmCommandWriteRead(sPriv->fd, DRM_I830_GETPARAM,
484 &gp, sizeof(gp));
485 if (ret) {
486 fprintf(stderr, "drmI830GetParam: (%d) %d\n", gp.param, ret);
487 return GL_FALSE;
488 }
489 }
490
491 sPriv->extensions = intelExtensions;
492
493 /* If we've got a new enough DDX that's initializing TTM and giving us
494 * object handles for the shared buffers, use that.
495 */
496 intelScreen->ttm = GL_FALSE;
497 if (getenv("INTEL_NO_TTM") == NULL &&
498 intelScreen->driScrnPriv->ddx_version.minor >= 9 &&
499 intelScreen->drmMinor >= 11 &&
500 intelScreen->front.bo_handle != -1) {
501 intelScreen->bufmgr = intel_bufmgr_ttm_init(sPriv->fd,
502 DRM_FENCE_TYPE_EXE,
503 DRM_FENCE_TYPE_EXE |
504 DRM_I915_FENCE_TYPE_RW,
505 BATCH_SZ);
506 if (intelScreen->bufmgr != NULL)
507 intelScreen->ttm = GL_TRUE;
508 }
509 /* Otherwise, use the classic buffer manager. */
510 if (intelScreen->bufmgr == NULL) {
511 if (intelScreen->tex.size == 0) {
512 fprintf(stderr, "[%s:%u] Error initializing buffer manager.\n",
513 __func__, __LINE__);
514 return GL_FALSE;
515 }
516 fprintf(stderr, "[%s:%u] Failed to init TTM buffer manager, falling back"
517 " to classic.\n", __func__, __LINE__);
518 intelScreen->bufmgr = dri_bufmgr_fake_init(intelScreen->tex.offset,
519 intelScreen->tex.map,
520 intelScreen->tex.size,
521 intel_fence_emit,
522 intel_fence_wait,
523 intelScreen);
524 }
525
526 intel_recreate_static_regions(intelScreen);
527
528 return GL_TRUE;
529 }
530
531
532 static void
533 intelDestroyScreen(__DRIscreenPrivate * sPriv)
534 {
535 intelScreenPrivate *intelScreen = (intelScreenPrivate *) sPriv->private;
536
537 intelUnmapScreenRegions(intelScreen);
538
539 dri_bufmgr_destroy(intelScreen->bufmgr);
540 FREE(intelScreen);
541 sPriv->private = NULL;
542 }
543
544
545 /**
546 * This is called when we need to set up GL rendering to a new X window.
547 */
548 static GLboolean
549 intelCreateBuffer(__DRIscreenPrivate * driScrnPriv,
550 __DRIdrawablePrivate * driDrawPriv,
551 const __GLcontextModes * mesaVis, GLboolean isPixmap)
552 {
553 intelScreenPrivate *screen = (intelScreenPrivate *) driScrnPriv->private;
554
555 if (isPixmap) {
556 return GL_FALSE; /* not implemented */
557 }
558 else {
559 GLboolean swStencil = (mesaVis->stencilBits > 0 &&
560 mesaVis->depthBits != 24);
561 GLenum rgbFormat = (mesaVis->redBits == 5 ? GL_RGB5 : GL_RGBA8);
562
563 struct intel_framebuffer *intel_fb = CALLOC_STRUCT(intel_framebuffer);
564
565 if (!intel_fb)
566 return GL_FALSE;
567
568 _mesa_initialize_framebuffer(&intel_fb->Base, mesaVis);
569
570 /* setup the hardware-based renderbuffers */
571 {
572 intel_fb->color_rb[0]
573 = intel_create_renderbuffer(rgbFormat,
574 screen->width, screen->height,
575 screen->front.offset,
576 screen->front.pitch,
577 screen->cpp,
578 screen->front.map);
579 intel_set_span_functions(&intel_fb->color_rb[0]->Base);
580 _mesa_add_renderbuffer(&intel_fb->Base, BUFFER_FRONT_LEFT,
581 &intel_fb->color_rb[0]->Base);
582 }
583
584 if (mesaVis->doubleBufferMode) {
585 intel_fb->color_rb[1]
586 = intel_create_renderbuffer(rgbFormat,
587 screen->width, screen->height,
588 screen->back.offset,
589 screen->back.pitch,
590 screen->cpp,
591 screen->back.map);
592 intel_set_span_functions(&intel_fb->color_rb[1]->Base);
593 _mesa_add_renderbuffer(&intel_fb->Base, BUFFER_BACK_LEFT,
594 &intel_fb->color_rb[1]->Base);
595
596 if (screen->third.handle) {
597 struct gl_renderbuffer *tmp_rb = NULL;
598
599 intel_fb->color_rb[2]
600 = intel_create_renderbuffer(rgbFormat,
601 screen->width, screen->height,
602 screen->third.offset,
603 screen->third.pitch,
604 screen->cpp,
605 screen->third.map);
606 intel_set_span_functions(&intel_fb->color_rb[2]->Base);
607 _mesa_reference_renderbuffer(&tmp_rb, &intel_fb->color_rb[2]->Base);
608 }
609 }
610
611 if (mesaVis->depthBits == 24) {
612 if (mesaVis->stencilBits == 8) {
613 /* combined depth/stencil buffer */
614 struct intel_renderbuffer *depthStencilRb
615 = intel_create_renderbuffer(GL_DEPTH24_STENCIL8_EXT,
616 screen->width, screen->height,
617 screen->depth.offset,
618 screen->depth.pitch,
619 screen->cpp, /* 4! */
620 screen->depth.map);
621 intel_set_span_functions(&depthStencilRb->Base);
622 /* note: bind RB to two attachment points */
623 _mesa_add_renderbuffer(&intel_fb->Base, BUFFER_DEPTH,
624 &depthStencilRb->Base);
625 _mesa_add_renderbuffer(&intel_fb->Base, BUFFER_STENCIL,
626 &depthStencilRb->Base);
627 } else {
628 struct intel_renderbuffer *depthRb
629 = intel_create_renderbuffer(GL_DEPTH_COMPONENT24,
630 screen->width, screen->height,
631 screen->depth.offset,
632 screen->depth.pitch,
633 screen->cpp, /* 4! */
634 screen->depth.map);
635 intel_set_span_functions(&depthRb->Base);
636 _mesa_add_renderbuffer(&intel_fb->Base, BUFFER_DEPTH,
637 &depthRb->Base);
638 }
639 }
640 else if (mesaVis->depthBits == 16) {
641 /* just 16-bit depth buffer, no hw stencil */
642 struct intel_renderbuffer *depthRb
643 = intel_create_renderbuffer(GL_DEPTH_COMPONENT16,
644 screen->width, screen->height,
645 screen->depth.offset,
646 screen->depth.pitch,
647 screen->cpp, /* 2! */
648 screen->depth.map);
649 intel_set_span_functions(&depthRb->Base);
650 _mesa_add_renderbuffer(&intel_fb->Base, BUFFER_DEPTH, &depthRb->Base);
651 }
652
653 /* now add any/all software-based renderbuffers we may need */
654 _mesa_add_soft_renderbuffers(&intel_fb->Base,
655 GL_FALSE, /* never sw color */
656 GL_FALSE, /* never sw depth */
657 swStencil, mesaVis->accumRedBits > 0,
658 GL_FALSE, /* never sw alpha */
659 GL_FALSE /* never sw aux */ );
660 driDrawPriv->driverPrivate = (void *) intel_fb;
661
662 return GL_TRUE;
663 }
664 }
665
666 static void
667 intelDestroyBuffer(__DRIdrawablePrivate * driDrawPriv)
668 {
669 _mesa_unreference_framebuffer((GLframebuffer **)(&(driDrawPriv->driverPrivate)));
670 }
671
672
673 /**
674 * Get information about previous buffer swaps.
675 */
676 static int
677 intelGetSwapInfo(__DRIdrawablePrivate * dPriv, __DRIswapInfo * sInfo)
678 {
679 struct intel_framebuffer *intel_fb;
680
681 if ((dPriv == NULL) || (dPriv->driverPrivate == NULL)
682 || (sInfo == NULL)) {
683 return -1;
684 }
685
686 intel_fb = dPriv->driverPrivate;
687 sInfo->swap_count = intel_fb->swap_count;
688 sInfo->swap_ust = intel_fb->swap_ust;
689 sInfo->swap_missed_count = intel_fb->swap_missed_count;
690
691 sInfo->swap_missed_usage = (sInfo->swap_missed_count != 0)
692 ? driCalculateSwapUsage(dPriv, 0, intel_fb->swap_missed_ust)
693 : 0.0;
694
695 return 0;
696 }
697
698
699 /* There are probably better ways to do this, such as an
700 * init-designated function to register chipids and createcontext
701 * functions.
702 */
703 extern GLboolean i830CreateContext(const __GLcontextModes * mesaVis,
704 __DRIcontextPrivate * driContextPriv,
705 void *sharedContextPrivate);
706
707 extern GLboolean i915CreateContext(const __GLcontextModes * mesaVis,
708 __DRIcontextPrivate * driContextPriv,
709 void *sharedContextPrivate);
710
711
712
713
714 static GLboolean
715 intelCreateContext(const __GLcontextModes * mesaVis,
716 __DRIcontextPrivate * driContextPriv,
717 void *sharedContextPrivate)
718 {
719 __DRIscreenPrivate *sPriv = driContextPriv->driScreenPriv;
720 intelScreenPrivate *intelScreen = (intelScreenPrivate *) sPriv->private;
721
722 switch (intelScreen->deviceID) {
723 /* Don't deal with i830 until texture work complete:
724 */
725 case PCI_CHIP_845_G:
726 case PCI_CHIP_I830_M:
727 case PCI_CHIP_I855_GM:
728 case PCI_CHIP_I865_G:
729 return i830CreateContext(mesaVis, driContextPriv, sharedContextPrivate);
730
731 case PCI_CHIP_I915_G:
732 case PCI_CHIP_I915_GM:
733 case PCI_CHIP_I945_G:
734 case PCI_CHIP_I945_GM:
735 case PCI_CHIP_I945_GME:
736 case PCI_CHIP_G33_G:
737 case PCI_CHIP_Q35_G:
738 case PCI_CHIP_Q33_G:
739 return i915CreateContext(mesaVis, driContextPriv, sharedContextPrivate);
740
741 default:
742 fprintf(stderr, "Unrecognized deviceID %x\n", intelScreen->deviceID);
743 return GL_FALSE;
744 }
745 }
746
747
748 static const struct __DriverAPIRec intelAPI = {
749 .DestroyScreen = intelDestroyScreen,
750 .CreateContext = intelCreateContext,
751 .DestroyContext = intelDestroyContext,
752 .CreateBuffer = intelCreateBuffer,
753 .DestroyBuffer = intelDestroyBuffer,
754 .SwapBuffers = intelSwapBuffers,
755 .MakeCurrent = intelMakeCurrent,
756 .UnbindContext = intelUnbindContext,
757 .GetSwapInfo = intelGetSwapInfo,
758 .GetMSC = driGetMSC32,
759 .GetDrawableMSC = driDrawableGetMSC32,
760 .WaitForMSC = driWaitForMSC32,
761 .WaitForSBC = NULL,
762 .SwapBuffersMSC = NULL,
763 .CopySubBuffer = intelCopySubBuffer,
764 .setTexOffset = intelSetTexOffset,
765 };
766
767
768 static __GLcontextModes *
769 intelFillInModes(unsigned pixel_bits, unsigned depth_bits,
770 unsigned stencil_bits, GLboolean have_back_buffer)
771 {
772 __GLcontextModes *modes;
773 __GLcontextModes *m;
774 unsigned num_modes;
775 unsigned depth_buffer_factor;
776 unsigned back_buffer_factor;
777 GLenum fb_format;
778 GLenum fb_type;
779
780 /* GLX_SWAP_COPY_OML is only supported because the Intel driver doesn't
781 * support pageflipping at all.
782 */
783 static const GLenum back_buffer_modes[] = {
784 GLX_NONE, GLX_SWAP_UNDEFINED_OML, GLX_SWAP_COPY_OML
785 };
786
787 u_int8_t depth_bits_array[3];
788 u_int8_t stencil_bits_array[3];
789
790
791 depth_bits_array[0] = 0;
792 depth_bits_array[1] = depth_bits;
793 depth_bits_array[2] = depth_bits;
794
795 /* Just like with the accumulation buffer, always provide some modes
796 * with a stencil buffer. It will be a sw fallback, but some apps won't
797 * care about that.
798 */
799 stencil_bits_array[0] = 0;
800 stencil_bits_array[1] = 0;
801 if (depth_bits == 24)
802 stencil_bits_array[1] = (stencil_bits == 0) ? 8 : stencil_bits;
803
804 stencil_bits_array[2] = (stencil_bits == 0) ? 8 : stencil_bits;
805
806 depth_buffer_factor = ((depth_bits != 0) || (stencil_bits != 0)) ? 3 : 1;
807 back_buffer_factor = (have_back_buffer) ? 3 : 1;
808
809 num_modes = depth_buffer_factor * back_buffer_factor * 4;
810
811 if (pixel_bits == 16) {
812 fb_format = GL_RGB;
813 fb_type = GL_UNSIGNED_SHORT_5_6_5;
814 }
815 else {
816 fb_format = GL_BGRA;
817 fb_type = GL_UNSIGNED_INT_8_8_8_8_REV;
818 }
819
820 modes =
821 (*dri_interface->createContextModes) (num_modes,
822 sizeof(__GLcontextModes));
823 m = modes;
824 if (!driFillInModes(&m, fb_format, fb_type,
825 depth_bits_array, stencil_bits_array,
826 depth_buffer_factor, back_buffer_modes,
827 back_buffer_factor, GLX_TRUE_COLOR)) {
828 fprintf(stderr, "[%s:%u] Error creating FBConfig!\n", __func__,
829 __LINE__);
830 return NULL;
831 }
832 if (!driFillInModes(&m, fb_format, fb_type,
833 depth_bits_array, stencil_bits_array,
834 depth_buffer_factor, back_buffer_modes,
835 back_buffer_factor, GLX_DIRECT_COLOR)) {
836 fprintf(stderr, "[%s:%u] Error creating FBConfig!\n", __func__,
837 __LINE__);
838 return NULL;
839 }
840
841 /* Mark the visual as slow if there are "fake" stencil bits.
842 */
843 for (m = modes; m != NULL; m = m->next) {
844 if ((m->stencilBits != 0) && (m->stencilBits != stencil_bits)) {
845 m->visualRating = GLX_SLOW_CONFIG;
846 }
847 }
848
849 return modes;
850 }
851
852
853 /**
854 * This is the driver specific part of the createNewScreen entry point.
855 *
856 * \todo maybe fold this into intelInitDriver
857 *
858 * \return the __GLcontextModes supported by this driver
859 */
860 PUBLIC __GLcontextModes *__driDriverInitScreen(__DRIscreenPrivate *psp)
861 {
862 static const __DRIversion ddx_expected = { 1, 5, 0 };
863 static const __DRIversion dri_expected = { 4, 0, 0 };
864 static const __DRIversion drm_expected = { 1, 5, 0 };
865 I830DRIPtr dri_priv = (I830DRIPtr) psp->pDevPriv;
866
867 psp->DriverAPI = intelAPI;
868
869 if (!driCheckDriDdxDrmVersions2("i915",
870 &psp->dri_version, &dri_expected,
871 &psp->ddx_version, &ddx_expected,
872 &psp->drm_version, &drm_expected)) {
873 return NULL;
874 }
875
876 /* Calling driInitExtensions here, with a NULL context pointer,
877 * does not actually enable the extensions. It just makes sure
878 * that all the dispatch offsets for all the extensions that
879 * *might* be enables are known. This is needed because the
880 * dispatch offsets need to be known when _mesa_context_create is
881 * called, but we can't enable the extensions until we have a
882 * context pointer.
883 *
884 * Hello chicken. Hello egg. How are you two today?
885 */
886 driInitExtensions(NULL, card_extensions, GL_FALSE);
887 driInitExtensions(NULL, ttm_extensions, GL_FALSE);
888
889 if (!intelInitDriver(psp))
890 return NULL;
891
892 return intelFillInModes(dri_priv->cpp * 8,
893 (dri_priv->cpp == 2) ? 16 : 24,
894 (dri_priv->cpp == 2) ? 0 : 8, 1);
895 }
896
897 struct intel_context *intelScreenContext(intelScreenPrivate *intelScreen)
898 {
899 /*
900 * This should probably change to have the screen allocate a dummy
901 * context at screen creation. For now just use the current context.
902 */
903
904 GET_CURRENT_CONTEXT(ctx);
905 if (ctx == NULL) {
906 _mesa_problem(NULL, "No current context in intelScreenContext\n");
907 return NULL;
908 }
909 return intel_context(ctx);
910 }
911