1 /**************************************************************************
3 * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
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:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
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.
26 **************************************************************************/
30 #include "framebuffer.h"
32 #include "renderbuffer.h"
33 #include "simple_list.h"
39 #include "intel_screen.h"
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"
49 #include "dri_bufmgr.h"
50 #include "intel_regions.h"
51 #include "intel_batchbuffer.h"
53 #include "intel_bufmgr_ttm.h"
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;
65 #ifdef USE_NEW_INTERFACE
66 static PFNGLXCREATECONTEXTMODES create_context_modes
= NULL
;
67 #endif /*USE_NEW_INTERFACE */
69 extern const struct dri_extension card_extensions
[];
70 extern const struct dri_extension ttm_extensions
[];
73 * Map all the memory regions described by the screen.
74 * \return GL_TRUE if success, GL_FALSE if error.
77 intelMapScreenRegions(__DRIscreenPrivate
* sPriv
)
79 intelScreenPrivate
*intelScreen
= (intelScreenPrivate
*) sPriv
->private;
81 if (intelScreen
->front
.handle
) {
83 intelScreen
->front
.handle
,
84 intelScreen
->front
.size
,
85 (drmAddress
*) & intelScreen
->front
.map
) != 0) {
86 _mesa_problem(NULL
, "drmMap(frontbuffer) failed!");
91 _mesa_warning(NULL
, "no front buffer handle in intelMapScreenRegions!");
95 _mesa_printf("Back 0x%08x ", intelScreen
->back
.handle
);
97 intelScreen
->back
.handle
,
98 intelScreen
->back
.size
,
99 (drmAddress
*) & intelScreen
->back
.map
) != 0) {
100 intelUnmapScreenRegions(intelScreen
);
104 if (intelScreen
->third
.handle
) {
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
);
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
);
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
);
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
);
146 /** Driver-specific fence emit implementation for the fake memory manager. */
148 intel_fence_emit(void *private)
150 intelScreenPrivate
*intelScreen
= (intelScreenPrivate
*)private;
153 /* XXX: Need to emit a flush, if we haven't already (at least with the
154 * current batchbuffer implementation, we have).
157 fence
= intelEmitIrqLocked(intelScreen
);
162 /** Driver-specific fence wait implementation for the fake memory manager. */
164 intel_fence_wait(void *private, unsigned int cookie
)
166 intelScreenPrivate
*intelScreen
= (intelScreenPrivate
*)private;
168 intelWaitIrq(intelScreen
, cookie
);
173 static struct intel_region
*
174 intel_recreate_static(intelScreenPrivate
*intelScreen
,
176 struct intel_region
*region
,
177 intelRegion
*region_desc
,
181 intel_region_update_static(intelScreen
, region
, name
, mem_type
,
182 region_desc
->bo_handle
, region_desc
->offset
,
183 region_desc
->map
, intelScreen
->cpp
,
184 region_desc
->pitch
/ intelScreen
->cpp
,
185 intelScreen
->height
, region_desc
->tiled
);
187 region
= intel_region_create_static(intelScreen
, name
, mem_type
,
188 region_desc
->bo_handle
,
190 region_desc
->map
, intelScreen
->cpp
,
191 region_desc
->pitch
/ intelScreen
->cpp
,
196 assert(region
->buffer
!= NULL
);
202 /* Create intel_region structs to describe the static front,back,depth
203 * buffers created by the xserver.
205 * Although FBO's mean we now no longer use these as render targets in
206 * all circumstances, they won't go away until the back and depth
207 * buffers become private, and the front buffer will remain even then.
209 * Note that these don't allocate video memory, just describe
210 * allocations alread made by the X server.
213 intel_recreate_static_regions(intelScreenPrivate
*intelScreen
)
215 intelScreen
->front_region
=
216 intel_recreate_static(intelScreen
, "front",
217 intelScreen
->front_region
,
221 intelScreen
->back_region
=
222 intel_recreate_static(intelScreen
, "back",
223 intelScreen
->back_region
,
227 if (intelScreen
->third
.handle
) {
228 intelScreen
->third_region
=
229 intel_recreate_static(intelScreen
, "third",
230 intelScreen
->third_region
,
235 /* Still assumes front.cpp == depth.cpp. We can kill this when we move to
238 intelScreen
->depth_region
=
239 intel_recreate_static(intelScreen
, "depth",
240 intelScreen
->depth_region
,
246 intelUnmapScreenRegions(intelScreenPrivate
* intelScreen
)
248 #define REALLY_UNMAP 1
249 if (intelScreen
->front
.map
) {
251 if (drmUnmap(intelScreen
->front
.map
, intelScreen
->front
.size
) != 0)
252 printf("drmUnmap front failed!\n");
254 intelScreen
->front
.map
= NULL
;
256 if (intelScreen
->back
.map
) {
258 if (drmUnmap(intelScreen
->back
.map
, intelScreen
->back
.size
) != 0)
259 printf("drmUnmap back failed!\n");
261 intelScreen
->back
.map
= NULL
;
263 if (intelScreen
->third
.map
) {
265 if (drmUnmap(intelScreen
->third
.map
, intelScreen
->third
.size
) != 0)
266 printf("drmUnmap third failed!\n");
268 intelScreen
->third
.map
= NULL
;
270 if (intelScreen
->depth
.map
) {
272 drmUnmap(intelScreen
->depth
.map
, intelScreen
->depth
.size
);
273 intelScreen
->depth
.map
= NULL
;
276 if (intelScreen
->tex
.map
) {
278 drmUnmap(intelScreen
->tex
.map
, intelScreen
->tex
.size
);
279 intelScreen
->tex
.map
= NULL
;
286 intelPrintDRIInfo(intelScreenPrivate
* intelScreen
,
287 __DRIscreenPrivate
* sPriv
, I830DRIPtr gDRIPriv
)
289 fprintf(stderr
, "*** Front size: 0x%x offset: 0x%x pitch: %d\n",
290 intelScreen
->front
.size
, intelScreen
->front
.offset
,
291 intelScreen
->front
.pitch
);
292 fprintf(stderr
, "*** Back size: 0x%x offset: 0x%x pitch: %d\n",
293 intelScreen
->back
.size
, intelScreen
->back
.offset
,
294 intelScreen
->back
.pitch
);
295 fprintf(stderr
, "*** Depth size: 0x%x offset: 0x%x pitch: %d\n",
296 intelScreen
->depth
.size
, intelScreen
->depth
.offset
,
297 intelScreen
->depth
.pitch
);
298 fprintf(stderr
, "*** Texture size: 0x%x offset: 0x%x\n",
299 intelScreen
->tex
.size
, intelScreen
->tex
.offset
);
300 fprintf(stderr
, "*** Memory : 0x%x\n", gDRIPriv
->mem
);
305 intelPrintSAREA(const drmI830Sarea
* sarea
)
307 fprintf(stderr
, "SAREA: sarea width %d height %d\n", sarea
->width
,
309 fprintf(stderr
, "SAREA: pitch: %d\n", sarea
->pitch
);
311 "SAREA: front offset: 0x%08x size: 0x%x handle: 0x%x\n",
312 sarea
->front_offset
, sarea
->front_size
,
313 (unsigned) sarea
->front_handle
);
315 "SAREA: back offset: 0x%08x size: 0x%x handle: 0x%x\n",
316 sarea
->back_offset
, sarea
->back_size
,
317 (unsigned) sarea
->back_handle
);
318 fprintf(stderr
, "SAREA: depth offset: 0x%08x size: 0x%x handle: 0x%x\n",
319 sarea
->depth_offset
, sarea
->depth_size
,
320 (unsigned) sarea
->depth_handle
);
321 fprintf(stderr
, "SAREA: tex offset: 0x%08x size: 0x%x handle: 0x%x\n",
322 sarea
->tex_offset
, sarea
->tex_size
, (unsigned) sarea
->tex_handle
);
327 * A number of the screen parameters are obtained/computed from
328 * information in the SAREA. This function updates those parameters.
331 intelUpdateScreenFromSAREA(intelScreenPrivate
* intelScreen
,
332 drmI830Sarea
* sarea
)
334 intelScreen
->width
= sarea
->width
;
335 intelScreen
->height
= sarea
->height
;
337 intelScreen
->front
.offset
= sarea
->front_offset
;
338 intelScreen
->front
.pitch
= sarea
->pitch
* intelScreen
->cpp
;
339 intelScreen
->front
.handle
= sarea
->front_handle
;
340 intelScreen
->front
.size
= sarea
->front_size
;
341 intelScreen
->front
.tiled
= sarea
->front_tiled
;
343 intelScreen
->back
.offset
= sarea
->back_offset
;
344 intelScreen
->back
.pitch
= sarea
->pitch
* intelScreen
->cpp
;
345 intelScreen
->back
.handle
= sarea
->back_handle
;
346 intelScreen
->back
.size
= sarea
->back_size
;
347 intelScreen
->back
.tiled
= sarea
->back_tiled
;
349 if (intelScreen
->driScrnPriv
->ddx_version
.minor
>= 8) {
350 intelScreen
->third
.offset
= sarea
->third_offset
;
351 intelScreen
->third
.pitch
= sarea
->pitch
* intelScreen
->cpp
;
352 intelScreen
->third
.handle
= sarea
->third_handle
;
353 intelScreen
->third
.size
= sarea
->third_size
;
354 intelScreen
->third
.tiled
= sarea
->third_tiled
;
357 intelScreen
->depth
.offset
= sarea
->depth_offset
;
358 intelScreen
->depth
.pitch
= sarea
->pitch
* intelScreen
->cpp
;
359 intelScreen
->depth
.handle
= sarea
->depth_handle
;
360 intelScreen
->depth
.size
= sarea
->depth_size
;
361 intelScreen
->depth
.tiled
= sarea
->depth_tiled
;
363 if (intelScreen
->driScrnPriv
->ddx_version
.minor
>= 9) {
364 intelScreen
->front
.bo_handle
= sarea
->front_bo_handle
;
365 intelScreen
->back
.bo_handle
= sarea
->back_bo_handle
;
366 intelScreen
->third
.bo_handle
= sarea
->third_bo_handle
;
367 intelScreen
->depth
.bo_handle
= sarea
->depth_bo_handle
;
369 intelScreen
->front
.bo_handle
= -1;
370 intelScreen
->back
.bo_handle
= -1;
371 intelScreen
->third
.bo_handle
= -1;
372 intelScreen
->depth
.bo_handle
= -1;
375 intelScreen
->tex
.offset
= sarea
->tex_offset
;
376 intelScreen
->logTextureGranularity
= sarea
->log_tex_granularity
;
377 intelScreen
->tex
.handle
= sarea
->tex_handle
;
378 intelScreen
->tex
.size
= sarea
->tex_size
;
381 intelPrintSAREA(sarea
);
384 static const __DRItexOffsetExtension intelTexOffsetExtension
= {
385 { __DRI_TEX_OFFSET
},
389 static const __DRIextension
*intelExtensions
[] = {
390 &driReadDrawableExtension
,
391 &driCopySubBufferExtension
.base
,
392 &driSwapControlExtension
.base
,
393 &driFrameTrackingExtension
.base
,
394 &driMediaStreamCounterExtension
.base
,
395 &intelTexOffsetExtension
.base
,
400 static GLboolean
intelInitDriver(__DRIscreenPrivate
*sPriv
)
402 intelScreenPrivate
*intelScreen
;
403 I830DRIPtr gDRIPriv
= (I830DRIPtr
) sPriv
->pDevPriv
;
406 if (sPriv
->devPrivSize
!= sizeof(I830DRIRec
)) {
408 "\nERROR! sizeof(I830DRIRec) does not match passed size from device driver\n");
412 /* Allocate the private area */
413 intelScreen
= (intelScreenPrivate
*) CALLOC(sizeof(intelScreenPrivate
));
415 fprintf(stderr
, "\nERROR! Allocating private area failed\n");
418 /* parse information in __driConfigOptions */
419 driParseOptionInfo(&intelScreen
->optionCache
,
420 __driConfigOptions
, __driNConfigOptions
);
422 intelScreen
->driScrnPriv
= sPriv
;
423 sPriv
->private = (void *) intelScreen
;
424 intelScreen
->sarea_priv_offset
= gDRIPriv
->sarea_priv_offset
;
425 sarea
= (drmI830Sarea
*)
426 (((GLubyte
*) sPriv
->pSAREA
) + intelScreen
->sarea_priv_offset
);
428 intelScreen
->deviceID
= gDRIPriv
->deviceID
;
429 if (intelScreen
->deviceID
== PCI_CHIP_I865_G
)
430 intelScreen
->maxBatchSize
= 4096;
432 intelScreen
->maxBatchSize
= BATCH_SZ
;
434 intelScreen
->mem
= gDRIPriv
->mem
;
435 intelScreen
->cpp
= gDRIPriv
->cpp
;
437 switch (gDRIPriv
->bitsPerPixel
) {
439 intelScreen
->fbFormat
= DV_PF_565
;
442 intelScreen
->fbFormat
= DV_PF_8888
;
449 intelUpdateScreenFromSAREA(intelScreen
, sarea
);
451 if (!intelMapScreenRegions(sPriv
)) {
452 fprintf(stderr
, "\nERROR! mapping regions\n");
453 _mesa_free(intelScreen
);
454 sPriv
->private = NULL
;
458 intelScreen
->sarea_priv_offset
= gDRIPriv
->sarea_priv_offset
;
461 intelPrintDRIInfo(intelScreen
, sPriv
, gDRIPriv
);
463 intelScreen
->drmMinor
= sPriv
->drm_version
.minor
;
465 /* Determine if IRQs are active? */
470 gp
.param
= I830_PARAM_IRQ_ACTIVE
;
471 gp
.value
= &intelScreen
->irq_active
;
473 ret
= drmCommandWriteRead(sPriv
->fd
, DRM_I830_GETPARAM
,
476 fprintf(stderr
, "drmI830GetParam: %d\n", ret
);
481 /* Determine if batchbuffers are allowed */
486 gp
.param
= I830_PARAM_ALLOW_BATCHBUFFER
;
487 gp
.value
= &intelScreen
->allow_batchbuffer
;
489 ret
= drmCommandWriteRead(sPriv
->fd
, DRM_I830_GETPARAM
,
492 fprintf(stderr
, "drmI830GetParam: (%d) %d\n", gp
.param
, ret
);
497 sPriv
->extensions
= intelExtensions
;
499 /* If we've got a new enough DDX that's initializing TTM and giving us
500 * object handles for the shared buffers, use that.
502 intelScreen
->ttm
= GL_FALSE
;
503 if (getenv("INTEL_NO_TTM") == NULL
&&
504 intelScreen
->driScrnPriv
->ddx_version
.minor
>= 9 &&
505 intelScreen
->drmMinor
>= 11 &&
506 intelScreen
->front
.bo_handle
!= -1) {
507 intelScreen
->bufmgr
= intel_bufmgr_ttm_init(sPriv
->fd
,
510 DRM_I915_FENCE_TYPE_RW
,
512 if (intelScreen
->bufmgr
!= NULL
)
513 intelScreen
->ttm
= GL_TRUE
;
515 /* Otherwise, use the classic buffer manager. */
516 if (intelScreen
->bufmgr
== NULL
) {
517 if (intelScreen
->tex
.size
== 0) {
518 fprintf(stderr
, "[%s:%u] Error initializing buffer manager.\n",
522 fprintf(stderr
, "[%s:%u] Failed to init TTM buffer manager, falling back"
523 " to classic.\n", __func__
, __LINE__
);
524 intelScreen
->bufmgr
= dri_bufmgr_fake_init(intelScreen
->tex
.offset
,
525 intelScreen
->tex
.map
,
526 intelScreen
->tex
.size
,
532 intel_recreate_static_regions(intelScreen
);
539 intelDestroyScreen(__DRIscreenPrivate
* sPriv
)
541 intelScreenPrivate
*intelScreen
= (intelScreenPrivate
*) sPriv
->private;
543 intelUnmapScreenRegions(intelScreen
);
545 dri_bufmgr_destroy(intelScreen
->bufmgr
);
547 sPriv
->private = NULL
;
552 * This is called when we need to set up GL rendering to a new X window.
555 intelCreateBuffer(__DRIscreenPrivate
* driScrnPriv
,
556 __DRIdrawablePrivate
* driDrawPriv
,
557 const __GLcontextModes
* mesaVis
, GLboolean isPixmap
)
559 intelScreenPrivate
*screen
= (intelScreenPrivate
*) driScrnPriv
->private;
562 return GL_FALSE
; /* not implemented */
565 GLboolean swStencil
= (mesaVis
->stencilBits
> 0 &&
566 mesaVis
->depthBits
!= 24);
567 GLenum rgbFormat
= (mesaVis
->redBits
== 5 ? GL_RGB5
: GL_RGBA8
);
569 struct intel_framebuffer
*intel_fb
= CALLOC_STRUCT(intel_framebuffer
);
574 _mesa_initialize_framebuffer(&intel_fb
->Base
, mesaVis
);
576 /* setup the hardware-based renderbuffers */
578 intel_fb
->color_rb
[0]
579 = intel_create_renderbuffer(rgbFormat
,
580 screen
->width
, screen
->height
,
581 screen
->front
.offset
,
585 intel_set_span_functions(&intel_fb
->color_rb
[0]->Base
);
586 _mesa_add_renderbuffer(&intel_fb
->Base
, BUFFER_FRONT_LEFT
,
587 &intel_fb
->color_rb
[0]->Base
);
590 if (mesaVis
->doubleBufferMode
) {
591 intel_fb
->color_rb
[1]
592 = intel_create_renderbuffer(rgbFormat
,
593 screen
->width
, screen
->height
,
598 intel_set_span_functions(&intel_fb
->color_rb
[1]->Base
);
599 _mesa_add_renderbuffer(&intel_fb
->Base
, BUFFER_BACK_LEFT
,
600 &intel_fb
->color_rb
[1]->Base
);
602 if (screen
->third
.handle
) {
603 struct gl_renderbuffer
*tmp_rb
= NULL
;
605 intel_fb
->color_rb
[2]
606 = intel_create_renderbuffer(rgbFormat
,
607 screen
->width
, screen
->height
,
608 screen
->third
.offset
,
612 intel_set_span_functions(&intel_fb
->color_rb
[2]->Base
);
613 _mesa_reference_renderbuffer(&tmp_rb
, &intel_fb
->color_rb
[2]->Base
);
617 if (mesaVis
->depthBits
== 24) {
618 if (mesaVis
->stencilBits
== 8) {
619 /* combined depth/stencil buffer */
620 struct intel_renderbuffer
*depthStencilRb
621 = intel_create_renderbuffer(GL_DEPTH24_STENCIL8_EXT
,
622 screen
->width
, screen
->height
,
623 screen
->depth
.offset
,
625 screen
->cpp
, /* 4! */
627 intel_set_span_functions(&depthStencilRb
->Base
);
628 /* note: bind RB to two attachment points */
629 _mesa_add_renderbuffer(&intel_fb
->Base
, BUFFER_DEPTH
,
630 &depthStencilRb
->Base
);
631 _mesa_add_renderbuffer(&intel_fb
->Base
, BUFFER_STENCIL
,
632 &depthStencilRb
->Base
);
634 struct intel_renderbuffer
*depthRb
635 = intel_create_renderbuffer(GL_DEPTH_COMPONENT24
,
636 screen
->width
, screen
->height
,
637 screen
->depth
.offset
,
639 screen
->cpp
, /* 4! */
641 intel_set_span_functions(&depthRb
->Base
);
642 _mesa_add_renderbuffer(&intel_fb
->Base
, BUFFER_DEPTH
,
646 else if (mesaVis
->depthBits
== 16) {
647 /* just 16-bit depth buffer, no hw stencil */
648 struct intel_renderbuffer
*depthRb
649 = intel_create_renderbuffer(GL_DEPTH_COMPONENT16
,
650 screen
->width
, screen
->height
,
651 screen
->depth
.offset
,
653 screen
->cpp
, /* 2! */
655 intel_set_span_functions(&depthRb
->Base
);
656 _mesa_add_renderbuffer(&intel_fb
->Base
, BUFFER_DEPTH
, &depthRb
->Base
);
659 /* now add any/all software-based renderbuffers we may need */
660 _mesa_add_soft_renderbuffers(&intel_fb
->Base
,
661 GL_FALSE
, /* never sw color */
662 GL_FALSE
, /* never sw depth */
663 swStencil
, mesaVis
->accumRedBits
> 0,
664 GL_FALSE
, /* never sw alpha */
665 GL_FALSE
/* never sw aux */ );
666 driDrawPriv
->driverPrivate
= (void *) intel_fb
;
673 intelDestroyBuffer(__DRIdrawablePrivate
* driDrawPriv
)
675 _mesa_unreference_framebuffer((GLframebuffer
**)(&(driDrawPriv
->driverPrivate
)));
680 * Get information about previous buffer swaps.
683 intelGetSwapInfo(__DRIdrawablePrivate
* dPriv
, __DRIswapInfo
* sInfo
)
685 struct intel_framebuffer
*intel_fb
;
687 if ((dPriv
== NULL
) || (dPriv
->driverPrivate
== NULL
)
688 || (sInfo
== NULL
)) {
692 intel_fb
= dPriv
->driverPrivate
;
693 sInfo
->swap_count
= intel_fb
->swap_count
;
694 sInfo
->swap_ust
= intel_fb
->swap_ust
;
695 sInfo
->swap_missed_count
= intel_fb
->swap_missed_count
;
697 sInfo
->swap_missed_usage
= (sInfo
->swap_missed_count
!= 0)
698 ? driCalculateSwapUsage(dPriv
, 0, intel_fb
->swap_missed_ust
)
705 /* There are probably better ways to do this, such as an
706 * init-designated function to register chipids and createcontext
709 extern GLboolean
i830CreateContext(const __GLcontextModes
* mesaVis
,
710 __DRIcontextPrivate
* driContextPriv
,
711 void *sharedContextPrivate
);
713 extern GLboolean
i915CreateContext(const __GLcontextModes
* mesaVis
,
714 __DRIcontextPrivate
* driContextPriv
,
715 void *sharedContextPrivate
);
721 intelCreateContext(const __GLcontextModes
* mesaVis
,
722 __DRIcontextPrivate
* driContextPriv
,
723 void *sharedContextPrivate
)
725 __DRIscreenPrivate
*sPriv
= driContextPriv
->driScreenPriv
;
726 intelScreenPrivate
*intelScreen
= (intelScreenPrivate
*) sPriv
->private;
728 switch (intelScreen
->deviceID
) {
729 /* Don't deal with i830 until texture work complete:
732 case PCI_CHIP_I830_M
:
733 case PCI_CHIP_I855_GM
:
734 case PCI_CHIP_I865_G
:
735 return i830CreateContext(mesaVis
, driContextPriv
, sharedContextPrivate
);
737 case PCI_CHIP_I915_G
:
738 case PCI_CHIP_I915_GM
:
739 case PCI_CHIP_I945_G
:
740 case PCI_CHIP_I945_GM
:
741 case PCI_CHIP_I945_GME
:
745 return i915CreateContext(mesaVis
, driContextPriv
, sharedContextPrivate
);
748 fprintf(stderr
, "Unrecognized deviceID %x\n", intelScreen
->deviceID
);
754 static const struct __DriverAPIRec intelAPI
= {
755 .DestroyScreen
= intelDestroyScreen
,
756 .CreateContext
= intelCreateContext
,
757 .DestroyContext
= intelDestroyContext
,
758 .CreateBuffer
= intelCreateBuffer
,
759 .DestroyBuffer
= intelDestroyBuffer
,
760 .SwapBuffers
= intelSwapBuffers
,
761 .MakeCurrent
= intelMakeCurrent
,
762 .UnbindContext
= intelUnbindContext
,
763 .GetSwapInfo
= intelGetSwapInfo
,
764 .GetMSC
= driGetMSC32
,
765 .GetDrawableMSC
= driDrawableGetMSC32
,
766 .WaitForMSC
= driWaitForMSC32
,
768 .SwapBuffersMSC
= NULL
,
769 .CopySubBuffer
= intelCopySubBuffer
,
770 .setTexOffset
= intelSetTexOffset
,
774 static __GLcontextModes
*
775 intelFillInModes(unsigned pixel_bits
, unsigned depth_bits
,
776 unsigned stencil_bits
, GLboolean have_back_buffer
)
778 __GLcontextModes
*modes
;
781 unsigned depth_buffer_factor
;
782 unsigned back_buffer_factor
;
786 /* GLX_SWAP_COPY_OML is only supported because the Intel driver doesn't
787 * support pageflipping at all.
789 static const GLenum back_buffer_modes
[] = {
790 GLX_NONE
, GLX_SWAP_UNDEFINED_OML
, GLX_SWAP_COPY_OML
793 u_int8_t depth_bits_array
[3];
794 u_int8_t stencil_bits_array
[3];
797 depth_bits_array
[0] = 0;
798 depth_bits_array
[1] = depth_bits
;
799 depth_bits_array
[2] = depth_bits
;
801 /* Just like with the accumulation buffer, always provide some modes
802 * with a stencil buffer. It will be a sw fallback, but some apps won't
805 stencil_bits_array
[0] = 0;
806 stencil_bits_array
[1] = 0;
807 if (depth_bits
== 24)
808 stencil_bits_array
[1] = (stencil_bits
== 0) ? 8 : stencil_bits
;
810 stencil_bits_array
[2] = (stencil_bits
== 0) ? 8 : stencil_bits
;
812 depth_buffer_factor
= ((depth_bits
!= 0) || (stencil_bits
!= 0)) ? 3 : 1;
813 back_buffer_factor
= (have_back_buffer
) ? 3 : 1;
815 num_modes
= depth_buffer_factor
* back_buffer_factor
* 4;
817 if (pixel_bits
== 16) {
819 fb_type
= GL_UNSIGNED_SHORT_5_6_5
;
823 fb_type
= GL_UNSIGNED_INT_8_8_8_8_REV
;
827 (*dri_interface
->createContextModes
) (num_modes
,
828 sizeof(__GLcontextModes
));
830 if (!driFillInModes(&m
, fb_format
, fb_type
,
831 depth_bits_array
, stencil_bits_array
,
832 depth_buffer_factor
, back_buffer_modes
,
833 back_buffer_factor
, GLX_TRUE_COLOR
)) {
834 fprintf(stderr
, "[%s:%u] Error creating FBConfig!\n", __func__
,
838 if (!driFillInModes(&m
, fb_format
, fb_type
,
839 depth_bits_array
, stencil_bits_array
,
840 depth_buffer_factor
, back_buffer_modes
,
841 back_buffer_factor
, GLX_DIRECT_COLOR
)) {
842 fprintf(stderr
, "[%s:%u] Error creating FBConfig!\n", __func__
,
847 /* Mark the visual as slow if there are "fake" stencil bits.
849 for (m
= modes
; m
!= NULL
; m
= m
->next
) {
850 if ((m
->stencilBits
!= 0) && (m
->stencilBits
!= stencil_bits
)) {
851 m
->visualRating
= GLX_SLOW_CONFIG
;
860 * This is the driver specific part of the createNewScreen entry point.
862 * \todo maybe fold this into intelInitDriver
864 * \return the __GLcontextModes supported by this driver
866 PUBLIC __GLcontextModes
*__driDriverInitScreen(__DRIscreenPrivate
*psp
)
868 static const __DRIversion ddx_expected
= { 1, 5, 0 };
869 static const __DRIversion dri_expected
= { 4, 0, 0 };
870 static const __DRIversion drm_expected
= { 1, 5, 0 };
871 I830DRIPtr dri_priv
= (I830DRIPtr
) psp
->pDevPriv
;
873 psp
->DriverAPI
= intelAPI
;
875 if (!driCheckDriDdxDrmVersions2("i915",
876 &psp
->dri_version
, &dri_expected
,
877 &psp
->ddx_version
, &ddx_expected
,
878 &psp
->drm_version
, &drm_expected
)) {
882 /* Calling driInitExtensions here, with a NULL context pointer,
883 * does not actually enable the extensions. It just makes sure
884 * that all the dispatch offsets for all the extensions that
885 * *might* be enables are known. This is needed because the
886 * dispatch offsets need to be known when _mesa_context_create is
887 * called, but we can't enable the extensions until we have a
890 * Hello chicken. Hello egg. How are you two today?
892 driInitExtensions(NULL
, card_extensions
, GL_FALSE
);
893 driInitExtensions(NULL
, ttm_extensions
, GL_FALSE
);
895 if (!intelInitDriver(psp
))
898 return intelFillInModes(dri_priv
->cpp
* 8,
899 (dri_priv
->cpp
== 2) ? 16 : 24,
900 (dri_priv
->cpp
== 2) ? 0 : 8, 1);
903 struct intel_context
*intelScreenContext(intelScreenPrivate
*intelScreen
)
906 * This should probably change to have the screen allocate a dummy
907 * context at screen creation. For now just use the current context.
910 GET_CURRENT_CONTEXT(ctx
);
912 _mesa_problem(NULL
, "No current context in intelScreenContext\n");
915 return intel_context(ctx
);