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
[];
72 * Map all the memory regions described by the screen.
73 * \return GL_TRUE if success, GL_FALSE if error.
76 intelMapScreenRegions(__DRIscreenPrivate
* sPriv
)
78 intelScreenPrivate
*intelScreen
= (intelScreenPrivate
*) sPriv
->private;
80 if (intelScreen
->front
.handle
) {
82 intelScreen
->front
.handle
,
83 intelScreen
->front
.size
,
84 (drmAddress
*) & intelScreen
->front
.map
) != 0) {
85 _mesa_problem(NULL
, "drmMap(frontbuffer) failed!");
90 _mesa_warning(NULL
, "no front buffer handle in intelMapScreenRegions!");
94 _mesa_printf("Back 0x%08x ", intelScreen
->back
.handle
);
96 intelScreen
->back
.handle
,
97 intelScreen
->back
.size
,
98 (drmAddress
*) & intelScreen
->back
.map
) != 0) {
99 intelUnmapScreenRegions(intelScreen
);
103 if (intelScreen
->third
.handle
) {
105 _mesa_printf("Third 0x%08x ", intelScreen
->third
.handle
);
106 if (drmMap(sPriv
->fd
,
107 intelScreen
->third
.handle
,
108 intelScreen
->third
.size
,
109 (drmAddress
*) & intelScreen
->third
.map
) != 0) {
110 intelUnmapScreenRegions(intelScreen
);
116 _mesa_printf("Depth 0x%08x ", intelScreen
->depth
.handle
);
117 if (drmMap(sPriv
->fd
,
118 intelScreen
->depth
.handle
,
119 intelScreen
->depth
.size
,
120 (drmAddress
*) & intelScreen
->depth
.map
) != 0) {
121 intelUnmapScreenRegions(intelScreen
);
126 _mesa_printf("TEX 0x%08x ", intelScreen
->tex
.handle
);
127 if (intelScreen
->tex
.size
!= 0) {
128 if (drmMap(sPriv
->fd
,
129 intelScreen
->tex
.handle
,
130 intelScreen
->tex
.size
,
131 (drmAddress
*) & intelScreen
->tex
.map
) != 0) {
132 intelUnmapScreenRegions(intelScreen
);
138 printf("Mappings: front: %p back: %p third: %p depth: %p tex: %p\n",
139 intelScreen
->front
.map
,
140 intelScreen
->back
.map
, intelScreen
->third
.map
,
141 intelScreen
->depth
.map
, intelScreen
->tex
.map
);
145 /** Driver-specific fence emit implementation for the fake memory manager. */
147 intel_fence_emit(void *private)
149 intelScreenPrivate
*intelScreen
= (intelScreenPrivate
*)private;
152 /* XXX: Need to emit a flush, if we haven't already (at least with the
153 * current batchbuffer implementation, we have).
156 fence
= intelEmitIrqLocked(intelScreen
);
161 /** Driver-specific fence wait implementation for the fake memory manager. */
163 intel_fence_wait(void *private, unsigned int cookie
)
165 intelScreenPrivate
*intelScreen
= (intelScreenPrivate
*)private;
167 intelWaitIrq(intelScreen
, cookie
);
172 static struct intel_region
*
173 intel_recreate_static(intelScreenPrivate
*intelScreen
,
174 struct intel_region
*region
,
175 intelRegion
*region_desc
,
179 intel_region_update_static(intelScreen
, region
, mem_type
,
180 region_desc
->bo_handle
, region_desc
->offset
,
181 region_desc
->map
, intelScreen
->cpp
,
182 region_desc
->pitch
/ intelScreen
->cpp
,
183 intelScreen
->height
);
185 region
= intel_region_create_static(intelScreen
, mem_type
,
186 region_desc
->bo_handle
,
188 region_desc
->map
, intelScreen
->cpp
,
189 region_desc
->pitch
/ intelScreen
->cpp
,
190 intelScreen
->height
);
193 assert(region
->buffer
!= NULL
);
199 /* Create intel_region structs to describe the static front,back,depth
200 * buffers created by the xserver.
202 * Although FBO's mean we now no longer use these as render targets in
203 * all circumstances, they won't go away until the back and depth
204 * buffers become private, and the front and rotated buffers will
207 * Note that these don't allocate video memory, just describe
208 * allocations alread made by the X server.
211 intel_recreate_static_regions(intelScreenPrivate
*intelScreen
)
213 intelScreen
->front_region
=
214 intel_recreate_static(intelScreen
,
215 intelScreen
->front_region
,
219 /* The rotated region is only used for old DDXes that didn't handle rotation
222 if (intelScreen
->driScrnPriv
->ddx_version
.minor
< 8) {
223 intelScreen
->rotated_region
=
224 intel_recreate_static(intelScreen
,
225 intelScreen
->rotated_region
,
226 &intelScreen
->rotated
,
230 intelScreen
->back_region
=
231 intel_recreate_static(intelScreen
,
232 intelScreen
->back_region
,
236 if (intelScreen
->third
.handle
) {
237 intelScreen
->third_region
=
238 intel_recreate_static(intelScreen
,
239 intelScreen
->third_region
,
244 /* Still assumes front.cpp == depth.cpp. We can kill this when we move to
247 intelScreen
->depth_region
=
248 intel_recreate_static(intelScreen
,
249 intelScreen
->depth_region
,
255 * Use the information in the sarea to update the screen parameters
256 * related to screen rotation. Needs to be called locked.
259 intelUpdateScreenRotation(__DRIscreenPrivate
* sPriv
, drmI830Sarea
* sarea
)
261 intelScreenPrivate
*intelScreen
= (intelScreenPrivate
*) sPriv
->private;
263 intelUnmapScreenRegions(intelScreen
);
264 intelUpdateScreenFromSAREA(intelScreen
, sarea
);
265 if (!intelMapScreenRegions(sPriv
)) {
266 fprintf(stderr
, "ERROR Remapping screen regions!!!\n");
268 intel_recreate_static_regions(intelScreen
);
273 intelUnmapScreenRegions(intelScreenPrivate
* intelScreen
)
275 #define REALLY_UNMAP 1
276 if (intelScreen
->front
.map
) {
278 if (drmUnmap(intelScreen
->front
.map
, intelScreen
->front
.size
) != 0)
279 printf("drmUnmap front failed!\n");
281 intelScreen
->front
.map
= NULL
;
283 if (intelScreen
->back
.map
) {
285 if (drmUnmap(intelScreen
->back
.map
, intelScreen
->back
.size
) != 0)
286 printf("drmUnmap back failed!\n");
288 intelScreen
->back
.map
= NULL
;
290 if (intelScreen
->third
.map
) {
292 if (drmUnmap(intelScreen
->third
.map
, intelScreen
->third
.size
) != 0)
293 printf("drmUnmap third failed!\n");
295 intelScreen
->third
.map
= NULL
;
297 if (intelScreen
->depth
.map
) {
299 drmUnmap(intelScreen
->depth
.map
, intelScreen
->depth
.size
);
300 intelScreen
->depth
.map
= NULL
;
303 if (intelScreen
->tex
.map
) {
305 drmUnmap(intelScreen
->tex
.map
, intelScreen
->tex
.size
);
306 intelScreen
->tex
.map
= NULL
;
313 intelPrintDRIInfo(intelScreenPrivate
* intelScreen
,
314 __DRIscreenPrivate
* sPriv
, I830DRIPtr gDRIPriv
)
316 fprintf(stderr
, "*** Front size: 0x%x offset: 0x%x pitch: %d\n",
317 intelScreen
->front
.size
, intelScreen
->front
.offset
,
318 intelScreen
->front
.pitch
);
319 fprintf(stderr
, "*** Back size: 0x%x offset: 0x%x pitch: %d\n",
320 intelScreen
->back
.size
, intelScreen
->back
.offset
,
321 intelScreen
->back
.pitch
);
322 fprintf(stderr
, "*** Depth size: 0x%x offset: 0x%x pitch: %d\n",
323 intelScreen
->depth
.size
, intelScreen
->depth
.offset
,
324 intelScreen
->depth
.pitch
);
325 fprintf(stderr
, "*** Rotated size: 0x%x offset: 0x%x pitch: %d\n",
326 intelScreen
->rotated
.size
, intelScreen
->rotated
.offset
,
327 intelScreen
->rotated
.pitch
);
328 fprintf(stderr
, "*** Texture size: 0x%x offset: 0x%x\n",
329 intelScreen
->tex
.size
, intelScreen
->tex
.offset
);
330 fprintf(stderr
, "*** Memory : 0x%x\n", gDRIPriv
->mem
);
335 intelPrintSAREA(const drmI830Sarea
* sarea
)
337 fprintf(stderr
, "SAREA: sarea width %d height %d\n", sarea
->width
,
339 fprintf(stderr
, "SAREA: pitch: %d\n", sarea
->pitch
);
341 "SAREA: front offset: 0x%08x size: 0x%x handle: 0x%x\n",
342 sarea
->front_offset
, sarea
->front_size
,
343 (unsigned) sarea
->front_handle
);
345 "SAREA: back offset: 0x%08x size: 0x%x handle: 0x%x\n",
346 sarea
->back_offset
, sarea
->back_size
,
347 (unsigned) sarea
->back_handle
);
348 fprintf(stderr
, "SAREA: depth offset: 0x%08x size: 0x%x handle: 0x%x\n",
349 sarea
->depth_offset
, sarea
->depth_size
,
350 (unsigned) sarea
->depth_handle
);
351 fprintf(stderr
, "SAREA: tex offset: 0x%08x size: 0x%x handle: 0x%x\n",
352 sarea
->tex_offset
, sarea
->tex_size
, (unsigned) sarea
->tex_handle
);
353 fprintf(stderr
, "SAREA: rotation: %d\n", sarea
->rotation
);
355 "SAREA: rotated offset: 0x%08x size: 0x%x\n",
356 sarea
->rotated_offset
, sarea
->rotated_size
);
357 fprintf(stderr
, "SAREA: rotated pitch: %d\n", sarea
->rotated_pitch
);
362 * A number of the screen parameters are obtained/computed from
363 * information in the SAREA. This function updates those parameters.
366 intelUpdateScreenFromSAREA(intelScreenPrivate
* intelScreen
,
367 drmI830Sarea
* sarea
)
369 intelScreen
->width
= sarea
->width
;
370 intelScreen
->height
= sarea
->height
;
372 intelScreen
->front
.offset
= sarea
->front_offset
;
373 intelScreen
->front
.pitch
= sarea
->pitch
* intelScreen
->cpp
;
374 intelScreen
->front
.handle
= sarea
->front_handle
;
375 intelScreen
->front
.size
= sarea
->front_size
;
377 intelScreen
->back
.offset
= sarea
->back_offset
;
378 intelScreen
->back
.pitch
= sarea
->pitch
* intelScreen
->cpp
;
379 intelScreen
->back
.handle
= sarea
->back_handle
;
380 intelScreen
->back
.size
= sarea
->back_size
;
382 if (intelScreen
->driScrnPriv
->ddx_version
.minor
>= 8) {
383 intelScreen
->third
.offset
= sarea
->third_offset
;
384 intelScreen
->third
.pitch
= sarea
->pitch
* intelScreen
->cpp
;
385 intelScreen
->third
.handle
= sarea
->third_handle
;
386 intelScreen
->third
.size
= sarea
->third_size
;
389 intelScreen
->depth
.offset
= sarea
->depth_offset
;
390 intelScreen
->depth
.pitch
= sarea
->pitch
* intelScreen
->cpp
;
391 intelScreen
->depth
.handle
= sarea
->depth_handle
;
392 intelScreen
->depth
.size
= sarea
->depth_size
;
394 if (intelScreen
->driScrnPriv
->ddx_version
.minor
>= 9) {
395 intelScreen
->front
.bo_handle
= sarea
->front_bo_handle
;
396 intelScreen
->back
.bo_handle
= sarea
->back_bo_handle
;
397 intelScreen
->third
.bo_handle
= sarea
->third_bo_handle
;
398 intelScreen
->depth
.bo_handle
= sarea
->depth_bo_handle
;
400 intelScreen
->front
.bo_handle
= -1;
401 intelScreen
->back
.bo_handle
= -1;
402 intelScreen
->third
.bo_handle
= -1;
403 intelScreen
->depth
.bo_handle
= -1;
406 intelScreen
->tex
.offset
= sarea
->tex_offset
;
407 intelScreen
->logTextureGranularity
= sarea
->log_tex_granularity
;
408 intelScreen
->tex
.handle
= sarea
->tex_handle
;
409 intelScreen
->tex
.size
= sarea
->tex_size
;
411 intelScreen
->rotated
.offset
= sarea
->rotated_offset
;
412 intelScreen
->rotated
.pitch
= sarea
->rotated_pitch
* intelScreen
->cpp
;
413 intelScreen
->rotated
.size
= sarea
->rotated_size
;
414 intelScreen
->current_rotation
= sarea
->rotation
;
415 matrix23Rotate(&intelScreen
->rotMatrix
,
416 sarea
->width
, sarea
->height
, sarea
->rotation
);
417 intelScreen
->rotatedWidth
= sarea
->virtualX
;
418 intelScreen
->rotatedHeight
= sarea
->virtualY
;
421 intelPrintSAREA(sarea
);
424 static const __DRIextension
*intelExtensions
[] = {
425 &driReadDrawableExtension
,
426 &driCopySubBufferExtension
.base
,
427 &driSwapControlExtension
.base
,
428 &driFrameTrackingExtension
.base
,
429 &driMediaStreamCounterExtension
.base
,
434 static GLboolean
intelInitDriver(__DRIscreenPrivate
*sPriv
)
436 intelScreenPrivate
*intelScreen
;
437 I830DRIPtr gDRIPriv
= (I830DRIPtr
) sPriv
->pDevPriv
;
440 if (sPriv
->devPrivSize
!= sizeof(I830DRIRec
)) {
442 "\nERROR! sizeof(I830DRIRec) does not match passed size from device driver\n");
446 /* Allocate the private area */
447 intelScreen
= (intelScreenPrivate
*) CALLOC(sizeof(intelScreenPrivate
));
449 fprintf(stderr
, "\nERROR! Allocating private area failed\n");
452 /* parse information in __driConfigOptions */
453 driParseOptionInfo(&intelScreen
->optionCache
,
454 __driConfigOptions
, __driNConfigOptions
);
456 intelScreen
->driScrnPriv
= sPriv
;
457 sPriv
->private = (void *) intelScreen
;
458 intelScreen
->sarea_priv_offset
= gDRIPriv
->sarea_priv_offset
;
459 sarea
= (drmI830Sarea
*)
460 (((GLubyte
*) sPriv
->pSAREA
) + intelScreen
->sarea_priv_offset
);
462 intelScreen
->deviceID
= gDRIPriv
->deviceID
;
463 if (intelScreen
->deviceID
== PCI_CHIP_I865_G
)
464 intelScreen
->maxBatchSize
= 4096;
466 intelScreen
->maxBatchSize
= BATCH_SZ
;
468 intelScreen
->mem
= gDRIPriv
->mem
;
469 intelScreen
->cpp
= gDRIPriv
->cpp
;
471 switch (gDRIPriv
->bitsPerPixel
) {
473 intelScreen
->fbFormat
= DV_PF_565
;
476 intelScreen
->fbFormat
= DV_PF_8888
;
483 intelUpdateScreenFromSAREA(intelScreen
, sarea
);
485 if (!intelMapScreenRegions(sPriv
)) {
486 fprintf(stderr
, "\nERROR! mapping regions\n");
487 _mesa_free(intelScreen
);
488 sPriv
->private = NULL
;
492 intelScreen
->sarea_priv_offset
= gDRIPriv
->sarea_priv_offset
;
495 intelPrintDRIInfo(intelScreen
, sPriv
, gDRIPriv
);
497 intelScreen
->drmMinor
= sPriv
->drm_version
.minor
;
499 /* Determine if IRQs are active? */
504 gp
.param
= I830_PARAM_IRQ_ACTIVE
;
505 gp
.value
= &intelScreen
->irq_active
;
507 ret
= drmCommandWriteRead(sPriv
->fd
, DRM_I830_GETPARAM
,
510 fprintf(stderr
, "drmI830GetParam: %d\n", ret
);
515 /* Determine if batchbuffers are allowed */
520 gp
.param
= I830_PARAM_ALLOW_BATCHBUFFER
;
521 gp
.value
= &intelScreen
->allow_batchbuffer
;
523 ret
= drmCommandWriteRead(sPriv
->fd
, DRM_I830_GETPARAM
,
526 fprintf(stderr
, "drmI830GetParam: (%d) %d\n", gp
.param
, ret
);
531 sPriv
->extensions
= intelExtensions
;
533 /* If we've got a new enough DDX that's initializing TTM and giving us
534 * object handles for the shared buffers, use that.
536 intelScreen
->ttm
= GL_FALSE
;
537 if (getenv("INTEL_NO_TTM") == NULL
&&
538 intelScreen
->driScrnPriv
->ddx_version
.minor
>= 9 &&
539 intelScreen
->drmMinor
>= 11 &&
540 intelScreen
->front
.bo_handle
!= -1) {
541 intelScreen
->bufmgr
= intel_bufmgr_ttm_init(sPriv
->fd
,
544 DRM_I915_FENCE_TYPE_RW
,
546 if (intelScreen
->bufmgr
!= NULL
)
547 intelScreen
->ttm
= GL_TRUE
;
549 /* Otherwise, use the classic buffer manager. */
550 if (intelScreen
->bufmgr
== NULL
) {
551 if (intelScreen
->tex
.size
== 0) {
552 fprintf(stderr
, "[%s:%u] Error initializing buffer manager.\n",
556 fprintf(stderr
, "[%s:%u] Failed to init TTM buffer manager, falling back"
557 " to classic.\n", __func__
, __LINE__
);
558 intelScreen
->bufmgr
= dri_bufmgr_fake_init(intelScreen
->tex
.offset
,
559 intelScreen
->tex
.map
,
560 intelScreen
->tex
.size
,
566 intel_recreate_static_regions(intelScreen
);
573 intelDestroyScreen(__DRIscreenPrivate
* sPriv
)
575 intelScreenPrivate
*intelScreen
= (intelScreenPrivate
*) sPriv
->private;
577 intelUnmapScreenRegions(intelScreen
);
579 dri_bufmgr_destroy(intelScreen
->bufmgr
);
581 sPriv
->private = NULL
;
586 * This is called when we need to set up GL rendering to a new X window.
589 intelCreateBuffer(__DRIscreenPrivate
* driScrnPriv
,
590 __DRIdrawablePrivate
* driDrawPriv
,
591 const __GLcontextModes
* mesaVis
, GLboolean isPixmap
)
593 intelScreenPrivate
*screen
= (intelScreenPrivate
*) driScrnPriv
->private;
596 return GL_FALSE
; /* not implemented */
599 GLboolean swStencil
= (mesaVis
->stencilBits
> 0 &&
600 mesaVis
->depthBits
!= 24);
601 GLenum rgbFormat
= (mesaVis
->redBits
== 5 ? GL_RGB5
: GL_RGBA8
);
603 struct intel_framebuffer
*intel_fb
= CALLOC_STRUCT(intel_framebuffer
);
608 _mesa_initialize_framebuffer(&intel_fb
->Base
, mesaVis
);
610 /* setup the hardware-based renderbuffers */
612 intel_fb
->color_rb
[0]
613 = intel_create_renderbuffer(rgbFormat
,
614 screen
->width
, screen
->height
,
615 screen
->front
.offset
,
619 intel_set_span_functions(&intel_fb
->color_rb
[0]->Base
);
620 _mesa_add_renderbuffer(&intel_fb
->Base
, BUFFER_FRONT_LEFT
,
621 &intel_fb
->color_rb
[0]->Base
);
624 if (mesaVis
->doubleBufferMode
) {
625 intel_fb
->color_rb
[1]
626 = intel_create_renderbuffer(rgbFormat
,
627 screen
->width
, screen
->height
,
632 intel_set_span_functions(&intel_fb
->color_rb
[1]->Base
);
633 _mesa_add_renderbuffer(&intel_fb
->Base
, BUFFER_BACK_LEFT
,
634 &intel_fb
->color_rb
[1]->Base
);
636 if (screen
->third
.handle
) {
637 struct gl_renderbuffer
*tmp_rb
= NULL
;
639 intel_fb
->color_rb
[2]
640 = intel_create_renderbuffer(rgbFormat
,
641 screen
->width
, screen
->height
,
642 screen
->third
.offset
,
646 intel_set_span_functions(&intel_fb
->color_rb
[2]->Base
);
647 _mesa_reference_renderbuffer(&tmp_rb
, &intel_fb
->color_rb
[2]->Base
);
651 if (mesaVis
->depthBits
== 24 && mesaVis
->stencilBits
== 8) {
652 /* combined depth/stencil buffer */
653 struct intel_renderbuffer
*depthStencilRb
654 = intel_create_renderbuffer(GL_DEPTH24_STENCIL8_EXT
,
655 screen
->width
, screen
->height
,
656 screen
->depth
.offset
,
658 screen
->cpp
, /* 4! */
660 intel_set_span_functions(&depthStencilRb
->Base
);
661 /* note: bind RB to two attachment points */
662 _mesa_add_renderbuffer(&intel_fb
->Base
, BUFFER_DEPTH
,
663 &depthStencilRb
->Base
);
664 _mesa_add_renderbuffer(&intel_fb
->Base
, BUFFER_STENCIL
,
665 &depthStencilRb
->Base
);
667 else if (mesaVis
->depthBits
== 16) {
668 /* just 16-bit depth buffer, no hw stencil */
669 struct intel_renderbuffer
*depthRb
670 = intel_create_renderbuffer(GL_DEPTH_COMPONENT16
,
671 screen
->width
, screen
->height
,
672 screen
->depth
.offset
,
674 screen
->cpp
, /* 2! */
676 intel_set_span_functions(&depthRb
->Base
);
677 _mesa_add_renderbuffer(&intel_fb
->Base
, BUFFER_DEPTH
, &depthRb
->Base
);
680 /* now add any/all software-based renderbuffers we may need */
681 _mesa_add_soft_renderbuffers(&intel_fb
->Base
,
682 GL_FALSE
, /* never sw color */
683 GL_FALSE
, /* never sw depth */
684 swStencil
, mesaVis
->accumRedBits
> 0,
685 GL_FALSE
, /* never sw alpha */
686 GL_FALSE
/* never sw aux */ );
687 driDrawPriv
->driverPrivate
= (void *) intel_fb
;
694 intelDestroyBuffer(__DRIdrawablePrivate
* driDrawPriv
)
696 _mesa_unreference_framebuffer((GLframebuffer
**)(&(driDrawPriv
->driverPrivate
)));
701 * Get information about previous buffer swaps.
704 intelGetSwapInfo(__DRIdrawablePrivate
* dPriv
, __DRIswapInfo
* sInfo
)
706 struct intel_framebuffer
*intel_fb
;
708 if ((dPriv
== NULL
) || (dPriv
->driverPrivate
== NULL
)
709 || (sInfo
== NULL
)) {
713 intel_fb
= dPriv
->driverPrivate
;
714 sInfo
->swap_count
= intel_fb
->swap_count
;
715 sInfo
->swap_ust
= intel_fb
->swap_ust
;
716 sInfo
->swap_missed_count
= intel_fb
->swap_missed_count
;
718 sInfo
->swap_missed_usage
= (sInfo
->swap_missed_count
!= 0)
719 ? driCalculateSwapUsage(dPriv
, 0, intel_fb
->swap_missed_ust
)
726 /* There are probably better ways to do this, such as an
727 * init-designated function to register chipids and createcontext
730 extern GLboolean
i830CreateContext(const __GLcontextModes
* mesaVis
,
731 __DRIcontextPrivate
* driContextPriv
,
732 void *sharedContextPrivate
);
734 extern GLboolean
i915CreateContext(const __GLcontextModes
* mesaVis
,
735 __DRIcontextPrivate
* driContextPriv
,
736 void *sharedContextPrivate
);
742 intelCreateContext(const __GLcontextModes
* mesaVis
,
743 __DRIcontextPrivate
* driContextPriv
,
744 void *sharedContextPrivate
)
746 __DRIscreenPrivate
*sPriv
= driContextPriv
->driScreenPriv
;
747 intelScreenPrivate
*intelScreen
= (intelScreenPrivate
*) sPriv
->private;
749 switch (intelScreen
->deviceID
) {
750 /* Don't deal with i830 until texture work complete:
753 case PCI_CHIP_I830_M
:
754 case PCI_CHIP_I855_GM
:
755 case PCI_CHIP_I865_G
:
756 return i830CreateContext(mesaVis
, driContextPriv
, sharedContextPrivate
);
758 case PCI_CHIP_I915_G
:
759 case PCI_CHIP_I915_GM
:
760 case PCI_CHIP_I945_G
:
761 case PCI_CHIP_I945_GM
:
762 case PCI_CHIP_I945_GME
:
766 return i915CreateContext(mesaVis
, driContextPriv
, sharedContextPrivate
);
769 fprintf(stderr
, "Unrecognized deviceID %x\n", intelScreen
->deviceID
);
775 static const struct __DriverAPIRec intelAPI
= {
776 .DestroyScreen
= intelDestroyScreen
,
777 .CreateContext
= intelCreateContext
,
778 .DestroyContext
= intelDestroyContext
,
779 .CreateBuffer
= intelCreateBuffer
,
780 .DestroyBuffer
= intelDestroyBuffer
,
781 .SwapBuffers
= intelSwapBuffers
,
782 .MakeCurrent
= intelMakeCurrent
,
783 .UnbindContext
= intelUnbindContext
,
784 .GetSwapInfo
= intelGetSwapInfo
,
785 .GetMSC
= driGetMSC32
,
786 .WaitForMSC
= driWaitForMSC32
,
788 .SwapBuffersMSC
= NULL
,
789 .CopySubBuffer
= intelCopySubBuffer
,
790 .setTexOffset
= intelSetTexOffset
,
794 static __GLcontextModes
*
795 intelFillInModes(unsigned pixel_bits
, unsigned depth_bits
,
796 unsigned stencil_bits
, GLboolean have_back_buffer
)
798 __GLcontextModes
*modes
;
801 unsigned depth_buffer_factor
;
802 unsigned back_buffer_factor
;
806 /* GLX_SWAP_COPY_OML is only supported because the Intel driver doesn't
807 * support pageflipping at all.
809 static const GLenum back_buffer_modes
[] = {
810 GLX_NONE
, GLX_SWAP_UNDEFINED_OML
, GLX_SWAP_COPY_OML
813 u_int8_t depth_bits_array
[3];
814 u_int8_t stencil_bits_array
[3];
817 depth_bits_array
[0] = 0;
818 depth_bits_array
[1] = depth_bits
;
819 depth_bits_array
[2] = depth_bits
;
821 /* Just like with the accumulation buffer, always provide some modes
822 * with a stencil buffer. It will be a sw fallback, but some apps won't
825 stencil_bits_array
[0] = 0;
826 stencil_bits_array
[1] = 0;
827 if (depth_bits
== 24)
828 stencil_bits_array
[1] = (stencil_bits
== 0) ? 8 : stencil_bits
;
830 stencil_bits_array
[2] = (stencil_bits
== 0) ? 8 : stencil_bits
;
832 depth_buffer_factor
= ((depth_bits
!= 0) || (stencil_bits
!= 0)) ? 3 : 1;
833 back_buffer_factor
= (have_back_buffer
) ? 3 : 1;
835 num_modes
= depth_buffer_factor
* back_buffer_factor
* 4;
837 if (pixel_bits
== 16) {
839 fb_type
= GL_UNSIGNED_SHORT_5_6_5
;
843 fb_type
= GL_UNSIGNED_INT_8_8_8_8_REV
;
847 (*dri_interface
->createContextModes
) (num_modes
,
848 sizeof(__GLcontextModes
));
850 if (!driFillInModes(&m
, fb_format
, fb_type
,
851 depth_bits_array
, stencil_bits_array
,
852 depth_buffer_factor
, back_buffer_modes
,
853 back_buffer_factor
, GLX_TRUE_COLOR
)) {
854 fprintf(stderr
, "[%s:%u] Error creating FBConfig!\n", __func__
,
858 if (!driFillInModes(&m
, fb_format
, fb_type
,
859 depth_bits_array
, stencil_bits_array
,
860 depth_buffer_factor
, back_buffer_modes
,
861 back_buffer_factor
, GLX_DIRECT_COLOR
)) {
862 fprintf(stderr
, "[%s:%u] Error creating FBConfig!\n", __func__
,
867 /* Mark the visual as slow if there are "fake" stencil bits.
869 for (m
= modes
; m
!= NULL
; m
= m
->next
) {
870 if ((m
->stencilBits
!= 0) && (m
->stencilBits
!= stencil_bits
)) {
871 m
->visualRating
= GLX_SLOW_CONFIG
;
880 * This is the driver specific part of the createNewScreen entry point.
882 * \todo maybe fold this into intelInitDriver
884 * \return the __GLcontextModes supported by this driver
886 PUBLIC __GLcontextModes
*__driDriverInitScreen(__DRIscreenPrivate
*psp
)
888 static const __DRIversion ddx_expected
= { 1, 5, 0 };
889 static const __DRIversion dri_expected
= { 4, 0, 0 };
890 static const __DRIversion drm_expected
= { 1, 5, 0 };
891 I830DRIPtr dri_priv
= (I830DRIPtr
) psp
->pDevPriv
;
893 psp
->DriverAPI
= intelAPI
;
895 if (!driCheckDriDdxDrmVersions2("i915",
896 &psp
->dri_version
, &dri_expected
,
897 &psp
->ddx_version
, &ddx_expected
,
898 &psp
->drm_version
, &drm_expected
)) {
902 /* Calling driInitExtensions here, with a NULL context pointer,
903 * does not actually enable the extensions. It just makes sure
904 * that all the dispatch offsets for all the extensions that
905 * *might* be enables are known. This is needed because the
906 * dispatch offsets need to be known when _mesa_context_create is
907 * called, but we can't enable the extensions until we have a
910 * Hello chicken. Hello egg. How are you two today?
912 driInitExtensions(NULL
, card_extensions
, GL_FALSE
);
914 if (!intelInitDriver(psp
))
917 return intelFillInModes(dri_priv
->cpp
* 8,
918 (dri_priv
->cpp
== 2) ? 16 : 24,
919 (dri_priv
->cpp
== 2) ? 0 : 8, 1);
922 struct intel_context
*intelScreenContext(intelScreenPrivate
*intelScreen
)
925 * This should probably change to have the screen allocate a dummy
926 * context at screen creation. For now just use the current context.
929 GET_CURRENT_CONTEXT(ctx
);
931 _mesa_problem(NULL
, "No current context in intelScreenContext\n");
934 return intel_context(ctx
);