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 PUBLIC
const char __driConfigOptions
[] =
54 DRI_CONF_BEGIN DRI_CONF_SECTION_PERFORMANCE
55 DRI_CONF_FTHROTTLE_MODE(DRI_CONF_FTHROTTLE_IRQS
)
56 DRI_CONF_VBLANK_MODE(DRI_CONF_VBLANK_DEF_INTERVAL_0
)
57 DRI_CONF_SECTION_END DRI_CONF_SECTION_QUALITY
58 DRI_CONF_FORCE_S3TC_ENABLE(false)
59 DRI_CONF_ALLOW_LARGE_TEXTURES(1)
60 DRI_CONF_SECTION_END DRI_CONF_END
;
61 const GLuint __driNConfigOptions
= 4;
63 #ifdef USE_NEW_INTERFACE
64 static PFNGLXCREATECONTEXTMODES create_context_modes
= NULL
;
65 #endif /*USE_NEW_INTERFACE */
67 extern const struct dri_extension card_extensions
[];
70 * Map all the memory regions described by the screen.
71 * \return GL_TRUE if success, GL_FALSE if error.
74 intelMapScreenRegions(__DRIscreenPrivate
* sPriv
)
76 intelScreenPrivate
*intelScreen
= (intelScreenPrivate
*) sPriv
->private;
78 if (intelScreen
->front
.handle
) {
80 intelScreen
->front
.handle
,
81 intelScreen
->front
.size
,
82 (drmAddress
*) & intelScreen
->front
.map
) != 0) {
83 _mesa_problem(NULL
, "drmMap(frontbuffer) failed!");
88 _mesa_warning(NULL
, "no front buffer handle in intelMapScreenRegions!");
92 _mesa_printf("Back 0x%08x ", intelScreen
->back
.handle
);
94 intelScreen
->back
.handle
,
95 intelScreen
->back
.size
,
96 (drmAddress
*) & intelScreen
->back
.map
) != 0) {
97 intelUnmapScreenRegions(intelScreen
);
101 if (intelScreen
->third
.handle
) {
103 _mesa_printf("Third 0x%08x ", intelScreen
->third
.handle
);
104 if (drmMap(sPriv
->fd
,
105 intelScreen
->third
.handle
,
106 intelScreen
->third
.size
,
107 (drmAddress
*) & intelScreen
->third
.map
) != 0) {
108 intelUnmapScreenRegions(intelScreen
);
114 _mesa_printf("Depth 0x%08x ", intelScreen
->depth
.handle
);
115 if (drmMap(sPriv
->fd
,
116 intelScreen
->depth
.handle
,
117 intelScreen
->depth
.size
,
118 (drmAddress
*) & intelScreen
->depth
.map
) != 0) {
119 intelUnmapScreenRegions(intelScreen
);
124 _mesa_printf("TEX 0x%08x ", intelScreen
->tex
.handle
);
125 if (intelScreen
->tex
.size
!= 0) {
126 if (drmMap(sPriv
->fd
,
127 intelScreen
->tex
.handle
,
128 intelScreen
->tex
.size
,
129 (drmAddress
*) & intelScreen
->tex
.map
) != 0) {
130 intelUnmapScreenRegions(intelScreen
);
136 printf("Mappings: front: %p back: %p third: %p depth: %p tex: %p\n",
137 intelScreen
->front
.map
,
138 intelScreen
->back
.map
, intelScreen
->third
.map
,
139 intelScreen
->depth
.map
, intelScreen
->tex
.map
);
143 /** Driver-specific fence emit implementation for the fake memory manager. */
145 intel_fence_emit(void *private)
147 intelScreenPrivate
*intelScreen
= (intelScreenPrivate
*)private;
150 /* XXX: Need to emit a flush, if we haven't already (at least with the
151 * current batchbuffer implementation, we have).
154 fence
= intelEmitIrqLocked(intelScreen
);
159 /** Driver-specific fence wait implementation for the fake memory manager. */
161 intel_fence_wait(void *private, unsigned int cookie
)
163 intelScreenPrivate
*intelScreen
= (intelScreenPrivate
*)private;
165 intelWaitIrq(intelScreen
, cookie
);
170 static struct intel_region
*
171 intel_recreate_static(intelScreenPrivate
*intelScreen
,
172 struct intel_region
*region
,
173 intelRegion
*region_desc
,
177 intel_region_update_static(intelScreen
, region
, mem_type
,
178 region_desc
->bo_handle
, region_desc
->offset
,
179 region_desc
->map
, intelScreen
->cpp
,
180 region_desc
->pitch
/ intelScreen
->cpp
,
181 intelScreen
->height
);
183 region
= intel_region_create_static(intelScreen
, mem_type
,
184 region_desc
->bo_handle
,
186 region_desc
->map
, intelScreen
->cpp
,
187 region_desc
->pitch
/ intelScreen
->cpp
,
188 intelScreen
->height
);
191 assert(region
->buffer
!= NULL
);
197 /* Create intel_region structs to describe the static front,back,depth
198 * buffers created by the xserver.
200 * Although FBO's mean we now no longer use these as render targets in
201 * all circumstances, they won't go away until the back and depth
202 * buffers become private, and the front and rotated buffers will
205 * Note that these don't allocate video memory, just describe
206 * allocations alread made by the X server.
209 intel_recreate_static_regions(intelScreenPrivate
*intelScreen
)
211 intelScreen
->front_region
=
212 intel_recreate_static(intelScreen
,
213 intelScreen
->front_region
,
217 /* The rotated region is only used for old DDXes that didn't handle rotation
220 if (intelScreen
->driScrnPriv
->ddxMinor
< 8) {
221 intelScreen
->rotated_region
=
222 intel_recreate_static(intelScreen
,
223 intelScreen
->rotated_region
,
224 &intelScreen
->rotated
,
228 intelScreen
->back_region
=
229 intel_recreate_static(intelScreen
,
230 intelScreen
->back_region
,
234 if (intelScreen
->third
.handle
) {
235 intelScreen
->third_region
=
236 intel_recreate_static(intelScreen
,
237 intelScreen
->third_region
,
242 /* Still assumes front.cpp == depth.cpp. We can kill this when we move to
245 intelScreen
->depth_region
=
246 intel_recreate_static(intelScreen
,
247 intelScreen
->depth_region
,
253 * Use the information in the sarea to update the screen parameters
254 * related to screen rotation. Needs to be called locked.
257 intelUpdateScreenRotation(__DRIscreenPrivate
* sPriv
, drmI830Sarea
* sarea
)
259 intelScreenPrivate
*intelScreen
= (intelScreenPrivate
*) sPriv
->private;
261 intelUnmapScreenRegions(intelScreen
);
262 intelUpdateScreenFromSAREA(intelScreen
, sarea
);
263 if (!intelMapScreenRegions(sPriv
)) {
264 fprintf(stderr
, "ERROR Remapping screen regions!!!\n");
266 intel_recreate_static_regions(intelScreen
);
271 intelUnmapScreenRegions(intelScreenPrivate
* intelScreen
)
273 #define REALLY_UNMAP 1
274 if (intelScreen
->front
.map
) {
276 if (drmUnmap(intelScreen
->front
.map
, intelScreen
->front
.size
) != 0)
277 printf("drmUnmap front failed!\n");
279 intelScreen
->front
.map
= NULL
;
281 if (intelScreen
->back
.map
) {
283 if (drmUnmap(intelScreen
->back
.map
, intelScreen
->back
.size
) != 0)
284 printf("drmUnmap back failed!\n");
286 intelScreen
->back
.map
= NULL
;
288 if (intelScreen
->third
.map
) {
290 if (drmUnmap(intelScreen
->third
.map
, intelScreen
->third
.size
) != 0)
291 printf("drmUnmap third failed!\n");
293 intelScreen
->third
.map
= NULL
;
295 if (intelScreen
->depth
.map
) {
297 drmUnmap(intelScreen
->depth
.map
, intelScreen
->depth
.size
);
298 intelScreen
->depth
.map
= NULL
;
301 if (intelScreen
->tex
.map
) {
303 drmUnmap(intelScreen
->tex
.map
, intelScreen
->tex
.size
);
304 intelScreen
->tex
.map
= NULL
;
311 intelPrintDRIInfo(intelScreenPrivate
* intelScreen
,
312 __DRIscreenPrivate
* sPriv
, I830DRIPtr gDRIPriv
)
314 fprintf(stderr
, "*** Front size: 0x%x offset: 0x%x pitch: %d\n",
315 intelScreen
->front
.size
, intelScreen
->front
.offset
,
316 intelScreen
->front
.pitch
);
317 fprintf(stderr
, "*** Back size: 0x%x offset: 0x%x pitch: %d\n",
318 intelScreen
->back
.size
, intelScreen
->back
.offset
,
319 intelScreen
->back
.pitch
);
320 fprintf(stderr
, "*** Depth size: 0x%x offset: 0x%x pitch: %d\n",
321 intelScreen
->depth
.size
, intelScreen
->depth
.offset
,
322 intelScreen
->depth
.pitch
);
323 fprintf(stderr
, "*** Rotated size: 0x%x offset: 0x%x pitch: %d\n",
324 intelScreen
->rotated
.size
, intelScreen
->rotated
.offset
,
325 intelScreen
->rotated
.pitch
);
326 fprintf(stderr
, "*** Texture size: 0x%x offset: 0x%x\n",
327 intelScreen
->tex
.size
, intelScreen
->tex
.offset
);
328 fprintf(stderr
, "*** Memory : 0x%x\n", gDRIPriv
->mem
);
333 intelPrintSAREA(const drmI830Sarea
* sarea
)
335 fprintf(stderr
, "SAREA: sarea width %d height %d\n", sarea
->width
,
337 fprintf(stderr
, "SAREA: pitch: %d\n", sarea
->pitch
);
339 "SAREA: front offset: 0x%08x size: 0x%x handle: 0x%x\n",
340 sarea
->front_offset
, sarea
->front_size
,
341 (unsigned) sarea
->front_handle
);
343 "SAREA: back offset: 0x%08x size: 0x%x handle: 0x%x\n",
344 sarea
->back_offset
, sarea
->back_size
,
345 (unsigned) sarea
->back_handle
);
346 fprintf(stderr
, "SAREA: depth offset: 0x%08x size: 0x%x handle: 0x%x\n",
347 sarea
->depth_offset
, sarea
->depth_size
,
348 (unsigned) sarea
->depth_handle
);
349 fprintf(stderr
, "SAREA: tex offset: 0x%08x size: 0x%x handle: 0x%x\n",
350 sarea
->tex_offset
, sarea
->tex_size
, (unsigned) sarea
->tex_handle
);
351 fprintf(stderr
, "SAREA: rotation: %d\n", sarea
->rotation
);
353 "SAREA: rotated offset: 0x%08x size: 0x%x\n",
354 sarea
->rotated_offset
, sarea
->rotated_size
);
355 fprintf(stderr
, "SAREA: rotated pitch: %d\n", sarea
->rotated_pitch
);
360 * A number of the screen parameters are obtained/computed from
361 * information in the SAREA. This function updates those parameters.
364 intelUpdateScreenFromSAREA(intelScreenPrivate
* intelScreen
,
365 drmI830Sarea
* sarea
)
367 intelScreen
->width
= sarea
->width
;
368 intelScreen
->height
= sarea
->height
;
370 intelScreen
->front
.offset
= sarea
->front_offset
;
371 intelScreen
->front
.pitch
= sarea
->pitch
* intelScreen
->cpp
;
372 intelScreen
->front
.handle
= sarea
->front_handle
;
373 intelScreen
->front
.size
= sarea
->front_size
;
375 intelScreen
->back
.offset
= sarea
->back_offset
;
376 intelScreen
->back
.pitch
= sarea
->pitch
* intelScreen
->cpp
;
377 intelScreen
->back
.handle
= sarea
->back_handle
;
378 intelScreen
->back
.size
= sarea
->back_size
;
380 if (intelScreen
->driScrnPriv
->ddxMinor
>= 8) {
381 intelScreen
->third
.offset
= sarea
->third_offset
;
382 intelScreen
->third
.pitch
= sarea
->pitch
* intelScreen
->cpp
;
383 intelScreen
->third
.handle
= sarea
->third_handle
;
384 intelScreen
->third
.size
= sarea
->third_size
;
387 intelScreen
->depth
.offset
= sarea
->depth_offset
;
388 intelScreen
->depth
.pitch
= sarea
->pitch
* intelScreen
->cpp
;
389 intelScreen
->depth
.handle
= sarea
->depth_handle
;
390 intelScreen
->depth
.size
= sarea
->depth_size
;
392 if (intelScreen
->driScrnPriv
->ddxMinor
>= 9) {
393 intelScreen
->front
.bo_handle
= sarea
->front_bo_handle
;
394 intelScreen
->back
.bo_handle
= sarea
->back_bo_handle
;
395 intelScreen
->third
.bo_handle
= sarea
->third_bo_handle
;
396 intelScreen
->depth
.bo_handle
= sarea
->depth_bo_handle
;
398 intelScreen
->front
.bo_handle
= -1;
399 intelScreen
->back
.bo_handle
= -1;
400 intelScreen
->third
.bo_handle
= -1;
401 intelScreen
->depth
.bo_handle
= -1;
404 intelScreen
->tex
.offset
= sarea
->tex_offset
;
405 intelScreen
->logTextureGranularity
= sarea
->log_tex_granularity
;
406 intelScreen
->tex
.handle
= sarea
->tex_handle
;
407 intelScreen
->tex
.size
= sarea
->tex_size
;
409 intelScreen
->rotated
.offset
= sarea
->rotated_offset
;
410 intelScreen
->rotated
.pitch
= sarea
->rotated_pitch
* intelScreen
->cpp
;
411 intelScreen
->rotated
.size
= sarea
->rotated_size
;
412 intelScreen
->current_rotation
= sarea
->rotation
;
413 matrix23Rotate(&intelScreen
->rotMatrix
,
414 sarea
->width
, sarea
->height
, sarea
->rotation
);
415 intelScreen
->rotatedWidth
= sarea
->virtualX
;
416 intelScreen
->rotatedHeight
= sarea
->virtualY
;
419 intelPrintSAREA(sarea
);
424 intelInitDriver(__DRIscreenPrivate
* sPriv
)
426 intelScreenPrivate
*intelScreen
;
427 I830DRIPtr gDRIPriv
= (I830DRIPtr
) sPriv
->pDevPriv
;
430 PFNGLXSCRENABLEEXTENSIONPROC glx_enable_extension
=
431 (PFNGLXSCRENABLEEXTENSIONPROC
) (*dri_interface
->
432 getProcAddress("glxEnableExtension"));
433 void *const psc
= sPriv
->psc
->screenConfigs
;
435 if (sPriv
->devPrivSize
!= sizeof(I830DRIRec
)) {
437 "\nERROR! sizeof(I830DRIRec) does not match passed size from device driver\n");
441 /* Allocate the private area */
442 intelScreen
= (intelScreenPrivate
*) CALLOC(sizeof(intelScreenPrivate
));
444 fprintf(stderr
, "\nERROR! Allocating private area failed\n");
447 /* parse information in __driConfigOptions */
448 driParseOptionInfo(&intelScreen
->optionCache
,
449 __driConfigOptions
, __driNConfigOptions
);
451 intelScreen
->driScrnPriv
= sPriv
;
452 sPriv
->private = (void *) intelScreen
;
453 intelScreen
->sarea_priv_offset
= gDRIPriv
->sarea_priv_offset
;
454 sarea
= (drmI830Sarea
*)
455 (((GLubyte
*) sPriv
->pSAREA
) + intelScreen
->sarea_priv_offset
);
457 intelScreen
->deviceID
= gDRIPriv
->deviceID
;
458 if (intelScreen
->deviceID
== PCI_CHIP_I865_G
)
459 intelScreen
->maxBatchSize
= 4096;
461 intelScreen
->maxBatchSize
= BATCH_SZ
;
463 intelScreen
->mem
= gDRIPriv
->mem
;
464 intelScreen
->cpp
= gDRIPriv
->cpp
;
466 switch (gDRIPriv
->bitsPerPixel
) {
468 intelScreen
->fbFormat
= DV_PF_565
;
471 intelScreen
->fbFormat
= DV_PF_8888
;
478 intelUpdateScreenFromSAREA(intelScreen
, sarea
);
480 if (!intelMapScreenRegions(sPriv
)) {
481 fprintf(stderr
, "\nERROR! mapping regions\n");
482 _mesa_free(intelScreen
);
483 sPriv
->private = NULL
;
487 intelScreen
->sarea_priv_offset
= gDRIPriv
->sarea_priv_offset
;
490 intelPrintDRIInfo(intelScreen
, sPriv
, gDRIPriv
);
492 intelScreen
->drmMinor
= sPriv
->drmMinor
;
494 /* Determine if IRQs are active? */
499 gp
.param
= I830_PARAM_IRQ_ACTIVE
;
500 gp
.value
= &intelScreen
->irq_active
;
502 ret
= drmCommandWriteRead(sPriv
->fd
, DRM_I830_GETPARAM
,
505 fprintf(stderr
, "drmI830GetParam: %d\n", ret
);
510 /* Determine if batchbuffers are allowed */
515 gp
.param
= I830_PARAM_ALLOW_BATCHBUFFER
;
516 gp
.value
= &intelScreen
->allow_batchbuffer
;
518 ret
= drmCommandWriteRead(sPriv
->fd
, DRM_I830_GETPARAM
,
521 fprintf(stderr
, "drmI830GetParam: (%d) %d\n", gp
.param
, ret
);
526 if (glx_enable_extension
!= NULL
) {
527 (*glx_enable_extension
) (psc
, "GLX_SGI_swap_control");
528 (*glx_enable_extension
) (psc
, "GLX_SGI_video_sync");
529 (*glx_enable_extension
) (psc
, "GLX_MESA_swap_control");
530 (*glx_enable_extension
) (psc
, "GLX_MESA_swap_frame_usage");
531 (*glx_enable_extension
) (psc
, "GLX_SGI_make_current_read");
534 /* If we've got a new enough DDX that's initializing TTM and giving us
535 * object handles for the shared buffers, use that.
537 intelScreen
->ttm
= GL_FALSE
;
538 if (getenv("INTEL_NO_TTM") == NULL
&&
539 intelScreen
->driScrnPriv
->ddxMinor
>= 9 &&
540 intelScreen
->front
.bo_handle
!= -1) {
541 intelScreen
->bufmgr
= intel_bufmgr_ttm_init(sPriv
->fd
,
544 DRM_I915_FENCE_TYPE_RW
);
545 if (intelScreen
->bufmgr
!= NULL
)
546 intelScreen
->ttm
= GL_TRUE
;
548 /* Otherwise, use the classic buffer manager. */
549 if (intelScreen
->bufmgr
== NULL
) {
550 if (intelScreen
->tex
.size
== 0) {
551 fprintf(stderr
, "[%s:%u] Error initializing buffer manager.\n",
555 fprintf(stderr
, "[%s:%u] Failed to init TTM buffer manager, falling back"
556 " to classic.\n", __func__
, __LINE__
);
557 intelScreen
->bufmgr
= dri_bufmgr_fake_init(intelScreen
->tex
.offset
,
558 intelScreen
->tex
.map
,
559 intelScreen
->tex
.size
,
565 intel_recreate_static_regions(intelScreen
);
572 intelDestroyScreen(__DRIscreenPrivate
* sPriv
)
574 intelScreenPrivate
*intelScreen
= (intelScreenPrivate
*) sPriv
->private;
576 intelUnmapScreenRegions(intelScreen
);
578 dri_bufmgr_destroy(intelScreen
->bufmgr
);
580 sPriv
->private = NULL
;
585 * This is called when we need to set up GL rendering to a new X window.
588 intelCreateBuffer(__DRIscreenPrivate
* driScrnPriv
,
589 __DRIdrawablePrivate
* driDrawPriv
,
590 const __GLcontextModes
* mesaVis
, GLboolean isPixmap
)
592 intelScreenPrivate
*screen
= (intelScreenPrivate
*) driScrnPriv
->private;
595 return GL_FALSE
; /* not implemented */
598 GLboolean swStencil
= (mesaVis
->stencilBits
> 0 &&
599 mesaVis
->depthBits
!= 24);
600 GLenum rgbFormat
= (mesaVis
->redBits
== 5 ? GL_RGB5
: GL_RGBA8
);
602 struct intel_framebuffer
*intel_fb
= CALLOC_STRUCT(intel_framebuffer
);
607 _mesa_initialize_framebuffer(&intel_fb
->Base
, mesaVis
);
609 /* setup the hardware-based renderbuffers */
611 intel_fb
->color_rb
[0]
612 = intel_create_renderbuffer(rgbFormat
,
613 screen
->width
, screen
->height
,
614 screen
->front
.offset
,
618 intel_set_span_functions(&intel_fb
->color_rb
[0]->Base
);
619 _mesa_add_renderbuffer(&intel_fb
->Base
, BUFFER_FRONT_LEFT
,
620 &intel_fb
->color_rb
[0]->Base
);
623 if (mesaVis
->doubleBufferMode
) {
624 intel_fb
->color_rb
[1]
625 = intel_create_renderbuffer(rgbFormat
,
626 screen
->width
, screen
->height
,
631 intel_set_span_functions(&intel_fb
->color_rb
[1]->Base
);
632 _mesa_add_renderbuffer(&intel_fb
->Base
, BUFFER_BACK_LEFT
,
633 &intel_fb
->color_rb
[1]->Base
);
635 if (screen
->third
.handle
) {
636 struct gl_renderbuffer
*tmp_rb
= NULL
;
638 intel_fb
->color_rb
[2]
639 = intel_create_renderbuffer(rgbFormat
,
640 screen
->width
, screen
->height
,
641 screen
->third
.offset
,
645 intel_set_span_functions(&intel_fb
->color_rb
[2]->Base
);
646 _mesa_reference_renderbuffer(&tmp_rb
, &intel_fb
->color_rb
[2]->Base
);
650 if (mesaVis
->depthBits
== 24 && mesaVis
->stencilBits
== 8) {
651 /* combined depth/stencil buffer */
652 struct intel_renderbuffer
*depthStencilRb
653 = intel_create_renderbuffer(GL_DEPTH24_STENCIL8_EXT
,
654 screen
->width
, screen
->height
,
655 screen
->depth
.offset
,
657 screen
->cpp
, /* 4! */
659 intel_set_span_functions(&depthStencilRb
->Base
);
660 /* note: bind RB to two attachment points */
661 _mesa_add_renderbuffer(&intel_fb
->Base
, BUFFER_DEPTH
,
662 &depthStencilRb
->Base
);
663 _mesa_add_renderbuffer(&intel_fb
->Base
, BUFFER_STENCIL
,
664 &depthStencilRb
->Base
);
666 else if (mesaVis
->depthBits
== 16) {
667 /* just 16-bit depth buffer, no hw stencil */
668 struct intel_renderbuffer
*depthRb
669 = intel_create_renderbuffer(GL_DEPTH_COMPONENT16
,
670 screen
->width
, screen
->height
,
671 screen
->depth
.offset
,
673 screen
->cpp
, /* 2! */
675 intel_set_span_functions(&depthRb
->Base
);
676 _mesa_add_renderbuffer(&intel_fb
->Base
, BUFFER_DEPTH
, &depthRb
->Base
);
679 /* now add any/all software-based renderbuffers we may need */
680 _mesa_add_soft_renderbuffers(&intel_fb
->Base
,
681 GL_FALSE
, /* never sw color */
682 GL_FALSE
, /* never sw depth */
683 swStencil
, mesaVis
->accumRedBits
> 0,
684 GL_FALSE
, /* never sw alpha */
685 GL_FALSE
/* never sw aux */ );
686 driDrawPriv
->driverPrivate
= (void *) intel_fb
;
693 intelDestroyBuffer(__DRIdrawablePrivate
* driDrawPriv
)
695 _mesa_unreference_framebuffer((GLframebuffer
**)(&(driDrawPriv
->driverPrivate
)));
700 * Get information about previous buffer swaps.
703 intelGetSwapInfo(__DRIdrawablePrivate
* dPriv
, __DRIswapInfo
* sInfo
)
705 struct intel_framebuffer
*intel_fb
;
707 if ((dPriv
== NULL
) || (dPriv
->driverPrivate
== NULL
)
708 || (sInfo
== NULL
)) {
712 intel_fb
= dPriv
->driverPrivate
;
713 sInfo
->swap_count
= intel_fb
->swap_count
;
714 sInfo
->swap_ust
= intel_fb
->swap_ust
;
715 sInfo
->swap_missed_count
= intel_fb
->swap_missed_count
;
717 sInfo
->swap_missed_usage
= (sInfo
->swap_missed_count
!= 0)
718 ? driCalculateSwapUsage(dPriv
, 0, intel_fb
->swap_missed_ust
)
725 /* There are probably better ways to do this, such as an
726 * init-designated function to register chipids and createcontext
729 extern GLboolean
i830CreateContext(const __GLcontextModes
* mesaVis
,
730 __DRIcontextPrivate
* driContextPriv
,
731 void *sharedContextPrivate
);
733 extern GLboolean
i915CreateContext(const __GLcontextModes
* mesaVis
,
734 __DRIcontextPrivate
* driContextPriv
,
735 void *sharedContextPrivate
);
741 intelCreateContext(const __GLcontextModes
* mesaVis
,
742 __DRIcontextPrivate
* driContextPriv
,
743 void *sharedContextPrivate
)
745 __DRIscreenPrivate
*sPriv
= driContextPriv
->driScreenPriv
;
746 intelScreenPrivate
*intelScreen
= (intelScreenPrivate
*) sPriv
->private;
748 switch (intelScreen
->deviceID
) {
749 /* Don't deal with i830 until texture work complete:
752 case PCI_CHIP_I830_M
:
753 case PCI_CHIP_I855_GM
:
754 case PCI_CHIP_I865_G
:
755 return i830CreateContext(mesaVis
, driContextPriv
, sharedContextPrivate
);
757 case PCI_CHIP_I915_G
:
758 case PCI_CHIP_I915_GM
:
759 case PCI_CHIP_I945_G
:
760 case PCI_CHIP_I945_GM
:
761 case PCI_CHIP_I945_GME
:
765 return i915CreateContext(mesaVis
, driContextPriv
, sharedContextPrivate
);
768 fprintf(stderr
, "Unrecognized deviceID %x\n", intelScreen
->deviceID
);
774 static const struct __DriverAPIRec intelAPI
= {
775 .InitDriver
= intelInitDriver
,
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 bootstrap function for the driver. libGL supplies all of the
881 * requisite information about the system, and the driver initializes itself.
882 * This routine also fills in the linked list pointed to by \c driver_modes
883 * with the \c __GLcontextModes that the driver can support for windows or
886 * \return A pointer to a \c __DRIscreenPrivate on success, or \c NULL on
890 __driCreateNewScreen_20050727(__DRInativeDisplay
* dpy
, int scrn
,
892 const __GLcontextModes
* modes
,
893 const __DRIversion
* ddx_version
,
894 const __DRIversion
* dri_version
,
895 const __DRIversion
* drm_version
,
896 const __DRIframebuffer
* frame_buffer
,
897 drmAddress pSAREA
, int fd
,
898 int internal_api_version
,
899 const __DRIinterfaceMethods
* interface
,
900 __GLcontextModes
** driver_modes
)
902 __DRIscreenPrivate
*psp
;
903 static const __DRIversion ddx_expected
= { 1, 5, 0 };
904 static const __DRIversion dri_expected
= { 4, 0, 0 };
905 static const __DRIversion drm_expected
= { 1, 5, 0 };
907 dri_interface
= interface
;
909 if (!driCheckDriDdxDrmVersions2("i915",
910 dri_version
, &dri_expected
,
911 ddx_version
, &ddx_expected
,
912 drm_version
, &drm_expected
)) {
916 psp
= __driUtilCreateNewScreen(dpy
, scrn
, psc
, NULL
,
917 ddx_version
, dri_version
, drm_version
,
918 frame_buffer
, pSAREA
, fd
,
919 internal_api_version
, &intelAPI
);
922 I830DRIPtr dri_priv
= (I830DRIPtr
) psp
->pDevPriv
;
923 *driver_modes
= intelFillInModes(dri_priv
->cpp
* 8,
924 (dri_priv
->cpp
== 2) ? 16 : 24,
925 (dri_priv
->cpp
== 2) ? 0 : 8, 1);
927 /* Calling driInitExtensions here, with a NULL context pointer, does not actually
928 * enable the extensions. It just makes sure that all the dispatch offsets for all
929 * the extensions that *might* be enables are known. This is needed because the
930 * dispatch offsets need to be known when _mesa_context_create is called, but we can't
931 * enable the extensions until we have a context pointer.
933 * Hello chicken. Hello egg. How are you two today?
935 driInitExtensions(NULL
, card_extensions
, GL_FALSE
);
941 struct intel_context
*intelScreenContext(intelScreenPrivate
*intelScreen
)
944 * This should probably change to have the screen allocate a dummy
945 * context at screen creation. For now just use the current context.
948 GET_CURRENT_CONTEXT(ctx
);
950 _mesa_problem(NULL
, "No current context in intelScreenContext\n");
953 return intel_context(ctx
);