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
,
175 struct intel_region
*region
,
176 intelRegion
*region_desc
,
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
);
186 region
= intel_region_create_static(intelScreen
, mem_type
,
187 region_desc
->bo_handle
,
189 region_desc
->map
, intelScreen
->cpp
,
190 region_desc
->pitch
/ intelScreen
->cpp
,
191 intelScreen
->height
);
194 assert(region
->buffer
!= NULL
);
200 /* Create intel_region structs to describe the static front,back,depth
201 * buffers created by the xserver.
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 and rotated buffers will
208 * Note that these don't allocate video memory, just describe
209 * allocations alread made by the X server.
212 intel_recreate_static_regions(intelScreenPrivate
*intelScreen
)
214 intelScreen
->front_region
=
215 intel_recreate_static(intelScreen
,
216 intelScreen
->front_region
,
220 /* The rotated region is only used for old DDXes that didn't handle rotation
223 if (intelScreen
->driScrnPriv
->ddx_version
.minor
< 8) {
224 intelScreen
->rotated_region
=
225 intel_recreate_static(intelScreen
,
226 intelScreen
->rotated_region
,
227 &intelScreen
->rotated
,
231 intelScreen
->back_region
=
232 intel_recreate_static(intelScreen
,
233 intelScreen
->back_region
,
237 if (intelScreen
->third
.handle
) {
238 intelScreen
->third_region
=
239 intel_recreate_static(intelScreen
,
240 intelScreen
->third_region
,
245 /* Still assumes front.cpp == depth.cpp. We can kill this when we move to
248 intelScreen
->depth_region
=
249 intel_recreate_static(intelScreen
,
250 intelScreen
->depth_region
,
256 * Use the information in the sarea to update the screen parameters
257 * related to screen rotation. Needs to be called locked.
260 intelUpdateScreenRotation(__DRIscreenPrivate
* sPriv
, drmI830Sarea
* sarea
)
262 intelScreenPrivate
*intelScreen
= (intelScreenPrivate
*) sPriv
->private;
264 intelUnmapScreenRegions(intelScreen
);
265 intelUpdateScreenFromSAREA(intelScreen
, sarea
);
266 if (!intelMapScreenRegions(sPriv
)) {
267 fprintf(stderr
, "ERROR Remapping screen regions!!!\n");
269 intel_recreate_static_regions(intelScreen
);
274 intelUnmapScreenRegions(intelScreenPrivate
* intelScreen
)
276 #define REALLY_UNMAP 1
277 if (intelScreen
->front
.map
) {
279 if (drmUnmap(intelScreen
->front
.map
, intelScreen
->front
.size
) != 0)
280 printf("drmUnmap front failed!\n");
282 intelScreen
->front
.map
= NULL
;
284 if (intelScreen
->back
.map
) {
286 if (drmUnmap(intelScreen
->back
.map
, intelScreen
->back
.size
) != 0)
287 printf("drmUnmap back failed!\n");
289 intelScreen
->back
.map
= NULL
;
291 if (intelScreen
->third
.map
) {
293 if (drmUnmap(intelScreen
->third
.map
, intelScreen
->third
.size
) != 0)
294 printf("drmUnmap third failed!\n");
296 intelScreen
->third
.map
= NULL
;
298 if (intelScreen
->depth
.map
) {
300 drmUnmap(intelScreen
->depth
.map
, intelScreen
->depth
.size
);
301 intelScreen
->depth
.map
= NULL
;
304 if (intelScreen
->tex
.map
) {
306 drmUnmap(intelScreen
->tex
.map
, intelScreen
->tex
.size
);
307 intelScreen
->tex
.map
= NULL
;
314 intelPrintDRIInfo(intelScreenPrivate
* intelScreen
,
315 __DRIscreenPrivate
* sPriv
, I830DRIPtr gDRIPriv
)
317 fprintf(stderr
, "*** Front size: 0x%x offset: 0x%x pitch: %d\n",
318 intelScreen
->front
.size
, intelScreen
->front
.offset
,
319 intelScreen
->front
.pitch
);
320 fprintf(stderr
, "*** Back size: 0x%x offset: 0x%x pitch: %d\n",
321 intelScreen
->back
.size
, intelScreen
->back
.offset
,
322 intelScreen
->back
.pitch
);
323 fprintf(stderr
, "*** Depth size: 0x%x offset: 0x%x pitch: %d\n",
324 intelScreen
->depth
.size
, intelScreen
->depth
.offset
,
325 intelScreen
->depth
.pitch
);
326 fprintf(stderr
, "*** Rotated size: 0x%x offset: 0x%x pitch: %d\n",
327 intelScreen
->rotated
.size
, intelScreen
->rotated
.offset
,
328 intelScreen
->rotated
.pitch
);
329 fprintf(stderr
, "*** Texture size: 0x%x offset: 0x%x\n",
330 intelScreen
->tex
.size
, intelScreen
->tex
.offset
);
331 fprintf(stderr
, "*** Memory : 0x%x\n", gDRIPriv
->mem
);
336 intelPrintSAREA(const drmI830Sarea
* sarea
)
338 fprintf(stderr
, "SAREA: sarea width %d height %d\n", sarea
->width
,
340 fprintf(stderr
, "SAREA: pitch: %d\n", sarea
->pitch
);
342 "SAREA: front offset: 0x%08x size: 0x%x handle: 0x%x\n",
343 sarea
->front_offset
, sarea
->front_size
,
344 (unsigned) sarea
->front_handle
);
346 "SAREA: back offset: 0x%08x size: 0x%x handle: 0x%x\n",
347 sarea
->back_offset
, sarea
->back_size
,
348 (unsigned) sarea
->back_handle
);
349 fprintf(stderr
, "SAREA: depth offset: 0x%08x size: 0x%x handle: 0x%x\n",
350 sarea
->depth_offset
, sarea
->depth_size
,
351 (unsigned) sarea
->depth_handle
);
352 fprintf(stderr
, "SAREA: tex offset: 0x%08x size: 0x%x handle: 0x%x\n",
353 sarea
->tex_offset
, sarea
->tex_size
, (unsigned) sarea
->tex_handle
);
354 fprintf(stderr
, "SAREA: rotation: %d\n", sarea
->rotation
);
356 "SAREA: rotated offset: 0x%08x size: 0x%x\n",
357 sarea
->rotated_offset
, sarea
->rotated_size
);
358 fprintf(stderr
, "SAREA: rotated pitch: %d\n", sarea
->rotated_pitch
);
363 * A number of the screen parameters are obtained/computed from
364 * information in the SAREA. This function updates those parameters.
367 intelUpdateScreenFromSAREA(intelScreenPrivate
* intelScreen
,
368 drmI830Sarea
* sarea
)
370 intelScreen
->width
= sarea
->width
;
371 intelScreen
->height
= sarea
->height
;
373 intelScreen
->front
.offset
= sarea
->front_offset
;
374 intelScreen
->front
.pitch
= sarea
->pitch
* intelScreen
->cpp
;
375 intelScreen
->front
.handle
= sarea
->front_handle
;
376 intelScreen
->front
.size
= sarea
->front_size
;
378 intelScreen
->back
.offset
= sarea
->back_offset
;
379 intelScreen
->back
.pitch
= sarea
->pitch
* intelScreen
->cpp
;
380 intelScreen
->back
.handle
= sarea
->back_handle
;
381 intelScreen
->back
.size
= sarea
->back_size
;
383 if (intelScreen
->driScrnPriv
->ddx_version
.minor
>= 8) {
384 intelScreen
->third
.offset
= sarea
->third_offset
;
385 intelScreen
->third
.pitch
= sarea
->pitch
* intelScreen
->cpp
;
386 intelScreen
->third
.handle
= sarea
->third_handle
;
387 intelScreen
->third
.size
= sarea
->third_size
;
390 intelScreen
->depth
.offset
= sarea
->depth_offset
;
391 intelScreen
->depth
.pitch
= sarea
->pitch
* intelScreen
->cpp
;
392 intelScreen
->depth
.handle
= sarea
->depth_handle
;
393 intelScreen
->depth
.size
= sarea
->depth_size
;
395 if (intelScreen
->driScrnPriv
->ddx_version
.minor
>= 9) {
396 intelScreen
->front
.bo_handle
= sarea
->front_bo_handle
;
397 intelScreen
->back
.bo_handle
= sarea
->back_bo_handle
;
398 intelScreen
->third
.bo_handle
= sarea
->third_bo_handle
;
399 intelScreen
->depth
.bo_handle
= sarea
->depth_bo_handle
;
401 intelScreen
->front
.bo_handle
= -1;
402 intelScreen
->back
.bo_handle
= -1;
403 intelScreen
->third
.bo_handle
= -1;
404 intelScreen
->depth
.bo_handle
= -1;
407 intelScreen
->tex
.offset
= sarea
->tex_offset
;
408 intelScreen
->logTextureGranularity
= sarea
->log_tex_granularity
;
409 intelScreen
->tex
.handle
= sarea
->tex_handle
;
410 intelScreen
->tex
.size
= sarea
->tex_size
;
412 intelScreen
->rotated
.offset
= sarea
->rotated_offset
;
413 intelScreen
->rotated
.pitch
= sarea
->rotated_pitch
* intelScreen
->cpp
;
414 intelScreen
->rotated
.size
= sarea
->rotated_size
;
415 intelScreen
->current_rotation
= sarea
->rotation
;
416 matrix23Rotate(&intelScreen
->rotMatrix
,
417 sarea
->width
, sarea
->height
, sarea
->rotation
);
418 intelScreen
->rotatedWidth
= sarea
->virtualX
;
419 intelScreen
->rotatedHeight
= sarea
->virtualY
;
422 intelPrintSAREA(sarea
);
425 static const __DRItexOffsetExtension intelTexOffsetExtension
= {
426 { __DRI_TEX_OFFSET
},
430 static const __DRIextension
*intelExtensions
[] = {
431 &driReadDrawableExtension
,
432 &driCopySubBufferExtension
.base
,
433 &driSwapControlExtension
.base
,
434 &driFrameTrackingExtension
.base
,
435 &driMediaStreamCounterExtension
.base
,
436 &intelTexOffsetExtension
.base
,
441 static GLboolean
intelInitDriver(__DRIscreenPrivate
*sPriv
)
443 intelScreenPrivate
*intelScreen
;
444 I830DRIPtr gDRIPriv
= (I830DRIPtr
) sPriv
->pDevPriv
;
447 if (sPriv
->devPrivSize
!= sizeof(I830DRIRec
)) {
449 "\nERROR! sizeof(I830DRIRec) does not match passed size from device driver\n");
453 /* Allocate the private area */
454 intelScreen
= (intelScreenPrivate
*) CALLOC(sizeof(intelScreenPrivate
));
456 fprintf(stderr
, "\nERROR! Allocating private area failed\n");
459 /* parse information in __driConfigOptions */
460 driParseOptionInfo(&intelScreen
->optionCache
,
461 __driConfigOptions
, __driNConfigOptions
);
463 intelScreen
->driScrnPriv
= sPriv
;
464 sPriv
->private = (void *) intelScreen
;
465 intelScreen
->sarea_priv_offset
= gDRIPriv
->sarea_priv_offset
;
466 sarea
= (drmI830Sarea
*)
467 (((GLubyte
*) sPriv
->pSAREA
) + intelScreen
->sarea_priv_offset
);
469 intelScreen
->deviceID
= gDRIPriv
->deviceID
;
470 if (intelScreen
->deviceID
== PCI_CHIP_I865_G
)
471 intelScreen
->maxBatchSize
= 4096;
473 intelScreen
->maxBatchSize
= BATCH_SZ
;
475 intelScreen
->mem
= gDRIPriv
->mem
;
476 intelScreen
->cpp
= gDRIPriv
->cpp
;
478 switch (gDRIPriv
->bitsPerPixel
) {
480 intelScreen
->fbFormat
= DV_PF_565
;
483 intelScreen
->fbFormat
= DV_PF_8888
;
490 intelUpdateScreenFromSAREA(intelScreen
, sarea
);
492 if (!intelMapScreenRegions(sPriv
)) {
493 fprintf(stderr
, "\nERROR! mapping regions\n");
494 _mesa_free(intelScreen
);
495 sPriv
->private = NULL
;
499 intelScreen
->sarea_priv_offset
= gDRIPriv
->sarea_priv_offset
;
502 intelPrintDRIInfo(intelScreen
, sPriv
, gDRIPriv
);
504 intelScreen
->drmMinor
= sPriv
->drm_version
.minor
;
506 /* Determine if IRQs are active? */
511 gp
.param
= I830_PARAM_IRQ_ACTIVE
;
512 gp
.value
= &intelScreen
->irq_active
;
514 ret
= drmCommandWriteRead(sPriv
->fd
, DRM_I830_GETPARAM
,
517 fprintf(stderr
, "drmI830GetParam: %d\n", ret
);
522 /* Determine if batchbuffers are allowed */
527 gp
.param
= I830_PARAM_ALLOW_BATCHBUFFER
;
528 gp
.value
= &intelScreen
->allow_batchbuffer
;
530 ret
= drmCommandWriteRead(sPriv
->fd
, DRM_I830_GETPARAM
,
533 fprintf(stderr
, "drmI830GetParam: (%d) %d\n", gp
.param
, ret
);
538 sPriv
->extensions
= intelExtensions
;
540 /* If we've got a new enough DDX that's initializing TTM and giving us
541 * object handles for the shared buffers, use that.
543 intelScreen
->ttm
= GL_FALSE
;
544 if (getenv("INTEL_NO_TTM") == NULL
&&
545 intelScreen
->driScrnPriv
->ddx_version
.minor
>= 9 &&
546 intelScreen
->drmMinor
>= 11 &&
547 intelScreen
->front
.bo_handle
!= -1) {
548 intelScreen
->bufmgr
= intel_bufmgr_ttm_init(sPriv
->fd
,
551 DRM_I915_FENCE_TYPE_RW
,
553 if (intelScreen
->bufmgr
!= NULL
)
554 intelScreen
->ttm
= GL_TRUE
;
556 /* Otherwise, use the classic buffer manager. */
557 if (intelScreen
->bufmgr
== NULL
) {
558 if (intelScreen
->tex
.size
== 0) {
559 fprintf(stderr
, "[%s:%u] Error initializing buffer manager.\n",
563 fprintf(stderr
, "[%s:%u] Failed to init TTM buffer manager, falling back"
564 " to classic.\n", __func__
, __LINE__
);
565 intelScreen
->bufmgr
= dri_bufmgr_fake_init(intelScreen
->tex
.offset
,
566 intelScreen
->tex
.map
,
567 intelScreen
->tex
.size
,
573 intel_recreate_static_regions(intelScreen
);
580 intelDestroyScreen(__DRIscreenPrivate
* sPriv
)
582 intelScreenPrivate
*intelScreen
= (intelScreenPrivate
*) sPriv
->private;
584 intelUnmapScreenRegions(intelScreen
);
586 dri_bufmgr_destroy(intelScreen
->bufmgr
);
588 sPriv
->private = NULL
;
593 * This is called when we need to set up GL rendering to a new X window.
596 intelCreateBuffer(__DRIscreenPrivate
* driScrnPriv
,
597 __DRIdrawablePrivate
* driDrawPriv
,
598 const __GLcontextModes
* mesaVis
, GLboolean isPixmap
)
600 intelScreenPrivate
*screen
= (intelScreenPrivate
*) driScrnPriv
->private;
603 return GL_FALSE
; /* not implemented */
606 GLboolean swStencil
= (mesaVis
->stencilBits
> 0 &&
607 mesaVis
->depthBits
!= 24);
608 GLenum rgbFormat
= (mesaVis
->redBits
== 5 ? GL_RGB5
: GL_RGBA8
);
610 struct intel_framebuffer
*intel_fb
= CALLOC_STRUCT(intel_framebuffer
);
615 _mesa_initialize_framebuffer(&intel_fb
->Base
, mesaVis
);
617 /* setup the hardware-based renderbuffers */
619 intel_fb
->color_rb
[0]
620 = intel_create_renderbuffer(rgbFormat
,
621 screen
->width
, screen
->height
,
622 screen
->front
.offset
,
626 intel_set_span_functions(&intel_fb
->color_rb
[0]->Base
);
627 _mesa_add_renderbuffer(&intel_fb
->Base
, BUFFER_FRONT_LEFT
,
628 &intel_fb
->color_rb
[0]->Base
);
631 if (mesaVis
->doubleBufferMode
) {
632 intel_fb
->color_rb
[1]
633 = intel_create_renderbuffer(rgbFormat
,
634 screen
->width
, screen
->height
,
639 intel_set_span_functions(&intel_fb
->color_rb
[1]->Base
);
640 _mesa_add_renderbuffer(&intel_fb
->Base
, BUFFER_BACK_LEFT
,
641 &intel_fb
->color_rb
[1]->Base
);
643 if (screen
->third
.handle
) {
644 struct gl_renderbuffer
*tmp_rb
= NULL
;
646 intel_fb
->color_rb
[2]
647 = intel_create_renderbuffer(rgbFormat
,
648 screen
->width
, screen
->height
,
649 screen
->third
.offset
,
653 intel_set_span_functions(&intel_fb
->color_rb
[2]->Base
);
654 _mesa_reference_renderbuffer(&tmp_rb
, &intel_fb
->color_rb
[2]->Base
);
658 if (mesaVis
->depthBits
== 24) {
659 if (mesaVis
->stencilBits
== 8) {
660 /* combined depth/stencil buffer */
661 struct intel_renderbuffer
*depthStencilRb
662 = intel_create_renderbuffer(GL_DEPTH24_STENCIL8_EXT
,
663 screen
->width
, screen
->height
,
664 screen
->depth
.offset
,
666 screen
->cpp
, /* 4! */
668 intel_set_span_functions(&depthStencilRb
->Base
);
669 /* note: bind RB to two attachment points */
670 _mesa_add_renderbuffer(&intel_fb
->Base
, BUFFER_DEPTH
,
671 &depthStencilRb
->Base
);
672 _mesa_add_renderbuffer(&intel_fb
->Base
, BUFFER_STENCIL
,
673 &depthStencilRb
->Base
);
675 struct intel_renderbuffer
*depthRb
676 = intel_create_renderbuffer(GL_DEPTH_COMPONENT24
,
677 screen
->width
, screen
->height
,
678 screen
->depth
.offset
,
680 screen
->cpp
, /* 4! */
682 intel_set_span_functions(&depthRb
->Base
);
683 _mesa_add_renderbuffer(&intel_fb
->Base
, BUFFER_DEPTH
,
687 else if (mesaVis
->depthBits
== 16) {
688 /* just 16-bit depth buffer, no hw stencil */
689 struct intel_renderbuffer
*depthRb
690 = intel_create_renderbuffer(GL_DEPTH_COMPONENT16
,
691 screen
->width
, screen
->height
,
692 screen
->depth
.offset
,
694 screen
->cpp
, /* 2! */
696 intel_set_span_functions(&depthRb
->Base
);
697 _mesa_add_renderbuffer(&intel_fb
->Base
, BUFFER_DEPTH
, &depthRb
->Base
);
700 /* now add any/all software-based renderbuffers we may need */
701 _mesa_add_soft_renderbuffers(&intel_fb
->Base
,
702 GL_FALSE
, /* never sw color */
703 GL_FALSE
, /* never sw depth */
704 swStencil
, mesaVis
->accumRedBits
> 0,
705 GL_FALSE
, /* never sw alpha */
706 GL_FALSE
/* never sw aux */ );
707 driDrawPriv
->driverPrivate
= (void *) intel_fb
;
714 intelDestroyBuffer(__DRIdrawablePrivate
* driDrawPriv
)
716 _mesa_unreference_framebuffer((GLframebuffer
**)(&(driDrawPriv
->driverPrivate
)));
721 * Get information about previous buffer swaps.
724 intelGetSwapInfo(__DRIdrawablePrivate
* dPriv
, __DRIswapInfo
* sInfo
)
726 struct intel_framebuffer
*intel_fb
;
728 if ((dPriv
== NULL
) || (dPriv
->driverPrivate
== NULL
)
729 || (sInfo
== NULL
)) {
733 intel_fb
= dPriv
->driverPrivate
;
734 sInfo
->swap_count
= intel_fb
->swap_count
;
735 sInfo
->swap_ust
= intel_fb
->swap_ust
;
736 sInfo
->swap_missed_count
= intel_fb
->swap_missed_count
;
738 sInfo
->swap_missed_usage
= (sInfo
->swap_missed_count
!= 0)
739 ? driCalculateSwapUsage(dPriv
, 0, intel_fb
->swap_missed_ust
)
746 /* There are probably better ways to do this, such as an
747 * init-designated function to register chipids and createcontext
750 extern GLboolean
i830CreateContext(const __GLcontextModes
* mesaVis
,
751 __DRIcontextPrivate
* driContextPriv
,
752 void *sharedContextPrivate
);
754 extern GLboolean
i915CreateContext(const __GLcontextModes
* mesaVis
,
755 __DRIcontextPrivate
* driContextPriv
,
756 void *sharedContextPrivate
);
762 intelCreateContext(const __GLcontextModes
* mesaVis
,
763 __DRIcontextPrivate
* driContextPriv
,
764 void *sharedContextPrivate
)
766 __DRIscreenPrivate
*sPriv
= driContextPriv
->driScreenPriv
;
767 intelScreenPrivate
*intelScreen
= (intelScreenPrivate
*) sPriv
->private;
769 switch (intelScreen
->deviceID
) {
770 /* Don't deal with i830 until texture work complete:
773 case PCI_CHIP_I830_M
:
774 case PCI_CHIP_I855_GM
:
775 case PCI_CHIP_I865_G
:
776 return i830CreateContext(mesaVis
, driContextPriv
, sharedContextPrivate
);
778 case PCI_CHIP_I915_G
:
779 case PCI_CHIP_I915_GM
:
780 case PCI_CHIP_I945_G
:
781 case PCI_CHIP_I945_GM
:
782 case PCI_CHIP_I945_GME
:
786 return i915CreateContext(mesaVis
, driContextPriv
, sharedContextPrivate
);
789 fprintf(stderr
, "Unrecognized deviceID %x\n", intelScreen
->deviceID
);
795 static const struct __DriverAPIRec intelAPI
= {
796 .DestroyScreen
= intelDestroyScreen
,
797 .CreateContext
= intelCreateContext
,
798 .DestroyContext
= intelDestroyContext
,
799 .CreateBuffer
= intelCreateBuffer
,
800 .DestroyBuffer
= intelDestroyBuffer
,
801 .SwapBuffers
= intelSwapBuffers
,
802 .MakeCurrent
= intelMakeCurrent
,
803 .UnbindContext
= intelUnbindContext
,
804 .GetSwapInfo
= intelGetSwapInfo
,
805 .GetMSC
= driGetMSC32
,
806 .GetDrawableMSC
= driDrawableGetMSC32
,
807 .WaitForMSC
= driWaitForMSC32
,
809 .SwapBuffersMSC
= NULL
,
810 .CopySubBuffer
= intelCopySubBuffer
,
811 .setTexOffset
= intelSetTexOffset
,
815 static __GLcontextModes
*
816 intelFillInModes(unsigned pixel_bits
, unsigned depth_bits
,
817 unsigned stencil_bits
, GLboolean have_back_buffer
)
819 __GLcontextModes
*modes
;
822 unsigned depth_buffer_factor
;
823 unsigned back_buffer_factor
;
827 /* GLX_SWAP_COPY_OML is only supported because the Intel driver doesn't
828 * support pageflipping at all.
830 static const GLenum back_buffer_modes
[] = {
831 GLX_NONE
, GLX_SWAP_UNDEFINED_OML
, GLX_SWAP_COPY_OML
834 u_int8_t depth_bits_array
[3];
835 u_int8_t stencil_bits_array
[3];
838 depth_bits_array
[0] = 0;
839 depth_bits_array
[1] = depth_bits
;
840 depth_bits_array
[2] = depth_bits
;
842 /* Just like with the accumulation buffer, always provide some modes
843 * with a stencil buffer. It will be a sw fallback, but some apps won't
846 stencil_bits_array
[0] = 0;
847 stencil_bits_array
[1] = 0;
848 if (depth_bits
== 24)
849 stencil_bits_array
[1] = (stencil_bits
== 0) ? 8 : stencil_bits
;
851 stencil_bits_array
[2] = (stencil_bits
== 0) ? 8 : stencil_bits
;
853 depth_buffer_factor
= ((depth_bits
!= 0) || (stencil_bits
!= 0)) ? 3 : 1;
854 back_buffer_factor
= (have_back_buffer
) ? 3 : 1;
856 num_modes
= depth_buffer_factor
* back_buffer_factor
* 4;
858 if (pixel_bits
== 16) {
860 fb_type
= GL_UNSIGNED_SHORT_5_6_5
;
864 fb_type
= GL_UNSIGNED_INT_8_8_8_8_REV
;
868 (*dri_interface
->createContextModes
) (num_modes
,
869 sizeof(__GLcontextModes
));
871 if (!driFillInModes(&m
, fb_format
, fb_type
,
872 depth_bits_array
, stencil_bits_array
,
873 depth_buffer_factor
, back_buffer_modes
,
874 back_buffer_factor
, GLX_TRUE_COLOR
)) {
875 fprintf(stderr
, "[%s:%u] Error creating FBConfig!\n", __func__
,
879 if (!driFillInModes(&m
, fb_format
, fb_type
,
880 depth_bits_array
, stencil_bits_array
,
881 depth_buffer_factor
, back_buffer_modes
,
882 back_buffer_factor
, GLX_DIRECT_COLOR
)) {
883 fprintf(stderr
, "[%s:%u] Error creating FBConfig!\n", __func__
,
888 /* Mark the visual as slow if there are "fake" stencil bits.
890 for (m
= modes
; m
!= NULL
; m
= m
->next
) {
891 if ((m
->stencilBits
!= 0) && (m
->stencilBits
!= stencil_bits
)) {
892 m
->visualRating
= GLX_SLOW_CONFIG
;
901 * This is the driver specific part of the createNewScreen entry point.
903 * \todo maybe fold this into intelInitDriver
905 * \return the __GLcontextModes supported by this driver
907 PUBLIC __GLcontextModes
*__driDriverInitScreen(__DRIscreenPrivate
*psp
)
909 static const __DRIversion ddx_expected
= { 1, 5, 0 };
910 static const __DRIversion dri_expected
= { 4, 0, 0 };
911 static const __DRIversion drm_expected
= { 1, 5, 0 };
912 I830DRIPtr dri_priv
= (I830DRIPtr
) psp
->pDevPriv
;
914 psp
->DriverAPI
= intelAPI
;
916 if (!driCheckDriDdxDrmVersions2("i915",
917 &psp
->dri_version
, &dri_expected
,
918 &psp
->ddx_version
, &ddx_expected
,
919 &psp
->drm_version
, &drm_expected
)) {
923 /* Calling driInitExtensions here, with a NULL context pointer,
924 * does not actually enable the extensions. It just makes sure
925 * that all the dispatch offsets for all the extensions that
926 * *might* be enables are known. This is needed because the
927 * dispatch offsets need to be known when _mesa_context_create is
928 * called, but we can't enable the extensions until we have a
931 * Hello chicken. Hello egg. How are you two today?
933 driInitExtensions(NULL
, card_extensions
, GL_FALSE
);
934 driInitExtensions(NULL
, ttm_extensions
, GL_FALSE
);
936 if (!intelInitDriver(psp
))
939 return intelFillInModes(dri_priv
->cpp
* 8,
940 (dri_priv
->cpp
== 2) ? 16 : 24,
941 (dri_priv
->cpp
== 2) ? 0 : 8, 1);
944 struct intel_context
*intelScreenContext(intelScreenPrivate
*intelScreen
)
947 * This should probably change to have the screen allocate a dummy
948 * context at screen creation. For now just use the current context.
951 GET_CURRENT_CONTEXT(ctx
);
953 _mesa_problem(NULL
, "No current context in intelScreenContext\n");
956 return intel_context(ctx
);