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
->ddxMinor
< 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
->ddxMinor
>= 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
->ddxMinor
>= 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
);
426 intelInitDriver(__DRIscreenPrivate
* sPriv
)
428 intelScreenPrivate
*intelScreen
;
429 I830DRIPtr gDRIPriv
= (I830DRIPtr
) sPriv
->pDevPriv
;
432 PFNGLXSCRENABLEEXTENSIONPROC glx_enable_extension
=
433 (PFNGLXSCRENABLEEXTENSIONPROC
) (*dri_interface
->
434 getProcAddress("glxEnableExtension"));
435 void *const psc
= sPriv
->psc
->screenConfigs
;
437 if (sPriv
->devPrivSize
!= sizeof(I830DRIRec
)) {
439 "\nERROR! sizeof(I830DRIRec) does not match passed size from device driver\n");
443 /* Allocate the private area */
444 intelScreen
= (intelScreenPrivate
*) CALLOC(sizeof(intelScreenPrivate
));
446 fprintf(stderr
, "\nERROR! Allocating private area failed\n");
449 /* parse information in __driConfigOptions */
450 driParseOptionInfo(&intelScreen
->optionCache
,
451 __driConfigOptions
, __driNConfigOptions
);
453 intelScreen
->driScrnPriv
= sPriv
;
454 sPriv
->private = (void *) intelScreen
;
455 intelScreen
->sarea_priv_offset
= gDRIPriv
->sarea_priv_offset
;
456 sarea
= (drmI830Sarea
*)
457 (((GLubyte
*) sPriv
->pSAREA
) + intelScreen
->sarea_priv_offset
);
459 intelScreen
->deviceID
= gDRIPriv
->deviceID
;
460 if (intelScreen
->deviceID
== PCI_CHIP_I865_G
)
461 intelScreen
->maxBatchSize
= 4096;
463 intelScreen
->maxBatchSize
= BATCH_SZ
;
465 intelScreen
->mem
= gDRIPriv
->mem
;
466 intelScreen
->cpp
= gDRIPriv
->cpp
;
468 switch (gDRIPriv
->bitsPerPixel
) {
470 intelScreen
->fbFormat
= DV_PF_565
;
473 intelScreen
->fbFormat
= DV_PF_8888
;
480 intelUpdateScreenFromSAREA(intelScreen
, sarea
);
482 if (!intelMapScreenRegions(sPriv
)) {
483 fprintf(stderr
, "\nERROR! mapping regions\n");
484 _mesa_free(intelScreen
);
485 sPriv
->private = NULL
;
489 intelScreen
->sarea_priv_offset
= gDRIPriv
->sarea_priv_offset
;
492 intelPrintDRIInfo(intelScreen
, sPriv
, gDRIPriv
);
494 intelScreen
->drmMinor
= sPriv
->drmMinor
;
496 /* Determine if IRQs are active? */
501 gp
.param
= I830_PARAM_IRQ_ACTIVE
;
502 gp
.value
= &intelScreen
->irq_active
;
504 ret
= drmCommandWriteRead(sPriv
->fd
, DRM_I830_GETPARAM
,
507 fprintf(stderr
, "drmI830GetParam: %d\n", ret
);
512 /* Determine if batchbuffers are allowed */
517 gp
.param
= I830_PARAM_ALLOW_BATCHBUFFER
;
518 gp
.value
= &intelScreen
->allow_batchbuffer
;
520 ret
= drmCommandWriteRead(sPriv
->fd
, DRM_I830_GETPARAM
,
523 fprintf(stderr
, "drmI830GetParam: (%d) %d\n", gp
.param
, ret
);
528 if (glx_enable_extension
!= NULL
) {
529 (*glx_enable_extension
) (psc
, "GLX_SGI_swap_control");
530 (*glx_enable_extension
) (psc
, "GLX_SGI_video_sync");
531 (*glx_enable_extension
) (psc
, "GLX_MESA_swap_control");
532 (*glx_enable_extension
) (psc
, "GLX_MESA_swap_frame_usage");
533 (*glx_enable_extension
) (psc
, "GLX_SGI_make_current_read");
536 /* If we've got a new enough DDX that's initializing TTM and giving us
537 * object handles for the shared buffers, use that.
539 intelScreen
->ttm
= GL_FALSE
;
540 if (getenv("INTEL_NO_TTM") == NULL
&&
541 intelScreen
->driScrnPriv
->ddxMinor
>= 9 &&
542 intelScreen
->drmMinor
>= 11 &&
543 intelScreen
->front
.bo_handle
!= -1) {
544 intelScreen
->bufmgr
= intel_bufmgr_ttm_init(sPriv
->fd
,
547 DRM_I915_FENCE_TYPE_RW
,
549 if (intelScreen
->bufmgr
!= NULL
)
550 intelScreen
->ttm
= GL_TRUE
;
552 /* Otherwise, use the classic buffer manager. */
553 if (intelScreen
->bufmgr
== NULL
) {
554 if (intelScreen
->tex
.size
== 0) {
555 fprintf(stderr
, "[%s:%u] Error initializing buffer manager.\n",
559 fprintf(stderr
, "[%s:%u] Failed to init TTM buffer manager, falling back"
560 " to classic.\n", __func__
, __LINE__
);
561 intelScreen
->bufmgr
= dri_bufmgr_fake_init(intelScreen
->tex
.offset
,
562 intelScreen
->tex
.map
,
563 intelScreen
->tex
.size
,
569 intel_recreate_static_regions(intelScreen
);
576 intelDestroyScreen(__DRIscreenPrivate
* sPriv
)
578 intelScreenPrivate
*intelScreen
= (intelScreenPrivate
*) sPriv
->private;
580 intelUnmapScreenRegions(intelScreen
);
582 dri_bufmgr_destroy(intelScreen
->bufmgr
);
584 sPriv
->private = NULL
;
589 * This is called when we need to set up GL rendering to a new X window.
592 intelCreateBuffer(__DRIscreenPrivate
* driScrnPriv
,
593 __DRIdrawablePrivate
* driDrawPriv
,
594 const __GLcontextModes
* mesaVis
, GLboolean isPixmap
)
596 intelScreenPrivate
*screen
= (intelScreenPrivate
*) driScrnPriv
->private;
599 return GL_FALSE
; /* not implemented */
602 GLboolean swStencil
= (mesaVis
->stencilBits
> 0 &&
603 mesaVis
->depthBits
!= 24);
604 GLenum rgbFormat
= (mesaVis
->redBits
== 5 ? GL_RGB5
: GL_RGBA8
);
606 struct intel_framebuffer
*intel_fb
= CALLOC_STRUCT(intel_framebuffer
);
611 _mesa_initialize_framebuffer(&intel_fb
->Base
, mesaVis
);
613 /* setup the hardware-based renderbuffers */
615 intel_fb
->color_rb
[0]
616 = intel_create_renderbuffer(rgbFormat
,
617 screen
->width
, screen
->height
,
618 screen
->front
.offset
,
622 intel_set_span_functions(&intel_fb
->color_rb
[0]->Base
);
623 _mesa_add_renderbuffer(&intel_fb
->Base
, BUFFER_FRONT_LEFT
,
624 &intel_fb
->color_rb
[0]->Base
);
627 if (mesaVis
->doubleBufferMode
) {
628 intel_fb
->color_rb
[1]
629 = intel_create_renderbuffer(rgbFormat
,
630 screen
->width
, screen
->height
,
635 intel_set_span_functions(&intel_fb
->color_rb
[1]->Base
);
636 _mesa_add_renderbuffer(&intel_fb
->Base
, BUFFER_BACK_LEFT
,
637 &intel_fb
->color_rb
[1]->Base
);
639 if (screen
->third
.handle
) {
640 struct gl_renderbuffer
*tmp_rb
= NULL
;
642 intel_fb
->color_rb
[2]
643 = intel_create_renderbuffer(rgbFormat
,
644 screen
->width
, screen
->height
,
645 screen
->third
.offset
,
649 intel_set_span_functions(&intel_fb
->color_rb
[2]->Base
);
650 _mesa_reference_renderbuffer(&tmp_rb
, &intel_fb
->color_rb
[2]->Base
);
654 if (mesaVis
->depthBits
== 24 && mesaVis
->stencilBits
== 8) {
655 /* combined depth/stencil buffer */
656 struct intel_renderbuffer
*depthStencilRb
657 = intel_create_renderbuffer(GL_DEPTH24_STENCIL8_EXT
,
658 screen
->width
, screen
->height
,
659 screen
->depth
.offset
,
661 screen
->cpp
, /* 4! */
663 intel_set_span_functions(&depthStencilRb
->Base
);
664 /* note: bind RB to two attachment points */
665 _mesa_add_renderbuffer(&intel_fb
->Base
, BUFFER_DEPTH
,
666 &depthStencilRb
->Base
);
667 _mesa_add_renderbuffer(&intel_fb
->Base
, BUFFER_STENCIL
,
668 &depthStencilRb
->Base
);
670 else if (mesaVis
->depthBits
== 16) {
671 /* just 16-bit depth buffer, no hw stencil */
672 struct intel_renderbuffer
*depthRb
673 = intel_create_renderbuffer(GL_DEPTH_COMPONENT16
,
674 screen
->width
, screen
->height
,
675 screen
->depth
.offset
,
677 screen
->cpp
, /* 2! */
679 intel_set_span_functions(&depthRb
->Base
);
680 _mesa_add_renderbuffer(&intel_fb
->Base
, BUFFER_DEPTH
, &depthRb
->Base
);
683 /* now add any/all software-based renderbuffers we may need */
684 _mesa_add_soft_renderbuffers(&intel_fb
->Base
,
685 GL_FALSE
, /* never sw color */
686 GL_FALSE
, /* never sw depth */
687 swStencil
, mesaVis
->accumRedBits
> 0,
688 GL_FALSE
, /* never sw alpha */
689 GL_FALSE
/* never sw aux */ );
690 driDrawPriv
->driverPrivate
= (void *) intel_fb
;
697 intelDestroyBuffer(__DRIdrawablePrivate
* driDrawPriv
)
699 _mesa_unreference_framebuffer((GLframebuffer
**)(&(driDrawPriv
->driverPrivate
)));
704 * Get information about previous buffer swaps.
707 intelGetSwapInfo(__DRIdrawablePrivate
* dPriv
, __DRIswapInfo
* sInfo
)
709 struct intel_framebuffer
*intel_fb
;
711 if ((dPriv
== NULL
) || (dPriv
->driverPrivate
== NULL
)
712 || (sInfo
== NULL
)) {
716 intel_fb
= dPriv
->driverPrivate
;
717 sInfo
->swap_count
= intel_fb
->swap_count
;
718 sInfo
->swap_ust
= intel_fb
->swap_ust
;
719 sInfo
->swap_missed_count
= intel_fb
->swap_missed_count
;
721 sInfo
->swap_missed_usage
= (sInfo
->swap_missed_count
!= 0)
722 ? driCalculateSwapUsage(dPriv
, 0, intel_fb
->swap_missed_ust
)
729 /* There are probably better ways to do this, such as an
730 * init-designated function to register chipids and createcontext
733 extern GLboolean
i830CreateContext(const __GLcontextModes
* mesaVis
,
734 __DRIcontextPrivate
* driContextPriv
,
735 void *sharedContextPrivate
);
737 extern GLboolean
i915CreateContext(const __GLcontextModes
* mesaVis
,
738 __DRIcontextPrivate
* driContextPriv
,
739 void *sharedContextPrivate
);
745 intelCreateContext(const __GLcontextModes
* mesaVis
,
746 __DRIcontextPrivate
* driContextPriv
,
747 void *sharedContextPrivate
)
749 __DRIscreenPrivate
*sPriv
= driContextPriv
->driScreenPriv
;
750 intelScreenPrivate
*intelScreen
= (intelScreenPrivate
*) sPriv
->private;
752 switch (intelScreen
->deviceID
) {
753 /* Don't deal with i830 until texture work complete:
756 case PCI_CHIP_I830_M
:
757 case PCI_CHIP_I855_GM
:
758 case PCI_CHIP_I865_G
:
759 return i830CreateContext(mesaVis
, driContextPriv
, sharedContextPrivate
);
761 case PCI_CHIP_I915_G
:
762 case PCI_CHIP_I915_GM
:
763 case PCI_CHIP_I945_G
:
764 case PCI_CHIP_I945_GM
:
765 case PCI_CHIP_I945_GME
:
769 return i915CreateContext(mesaVis
, driContextPriv
, sharedContextPrivate
);
772 fprintf(stderr
, "Unrecognized deviceID %x\n", intelScreen
->deviceID
);
778 static const struct __DriverAPIRec intelAPI
= {
779 .InitDriver
= intelInitDriver
,
780 .DestroyScreen
= intelDestroyScreen
,
781 .CreateContext
= intelCreateContext
,
782 .DestroyContext
= intelDestroyContext
,
783 .CreateBuffer
= intelCreateBuffer
,
784 .DestroyBuffer
= intelDestroyBuffer
,
785 .SwapBuffers
= intelSwapBuffers
,
786 .MakeCurrent
= intelMakeCurrent
,
787 .UnbindContext
= intelUnbindContext
,
788 .GetSwapInfo
= intelGetSwapInfo
,
789 .GetMSC
= driGetMSC32
,
790 .WaitForMSC
= driWaitForMSC32
,
792 .SwapBuffersMSC
= NULL
,
793 .CopySubBuffer
= intelCopySubBuffer
,
794 .setTexOffset
= intelSetTexOffset
,
798 static __GLcontextModes
*
799 intelFillInModes(unsigned pixel_bits
, unsigned depth_bits
,
800 unsigned stencil_bits
, GLboolean have_back_buffer
)
802 __GLcontextModes
*modes
;
805 unsigned depth_buffer_factor
;
806 unsigned back_buffer_factor
;
810 /* GLX_SWAP_COPY_OML is only supported because the Intel driver doesn't
811 * support pageflipping at all.
813 static const GLenum back_buffer_modes
[] = {
814 GLX_NONE
, GLX_SWAP_UNDEFINED_OML
, GLX_SWAP_COPY_OML
817 u_int8_t depth_bits_array
[3];
818 u_int8_t stencil_bits_array
[3];
821 depth_bits_array
[0] = 0;
822 depth_bits_array
[1] = depth_bits
;
823 depth_bits_array
[2] = depth_bits
;
825 /* Just like with the accumulation buffer, always provide some modes
826 * with a stencil buffer. It will be a sw fallback, but some apps won't
829 stencil_bits_array
[0] = 0;
830 stencil_bits_array
[1] = 0;
831 if (depth_bits
== 24)
832 stencil_bits_array
[1] = (stencil_bits
== 0) ? 8 : stencil_bits
;
834 stencil_bits_array
[2] = (stencil_bits
== 0) ? 8 : stencil_bits
;
836 depth_buffer_factor
= ((depth_bits
!= 0) || (stencil_bits
!= 0)) ? 3 : 1;
837 back_buffer_factor
= (have_back_buffer
) ? 3 : 1;
839 num_modes
= depth_buffer_factor
* back_buffer_factor
* 4;
841 if (pixel_bits
== 16) {
843 fb_type
= GL_UNSIGNED_SHORT_5_6_5
;
847 fb_type
= GL_UNSIGNED_INT_8_8_8_8_REV
;
851 (*dri_interface
->createContextModes
) (num_modes
,
852 sizeof(__GLcontextModes
));
854 if (!driFillInModes(&m
, fb_format
, fb_type
,
855 depth_bits_array
, stencil_bits_array
,
856 depth_buffer_factor
, back_buffer_modes
,
857 back_buffer_factor
, GLX_TRUE_COLOR
)) {
858 fprintf(stderr
, "[%s:%u] Error creating FBConfig!\n", __func__
,
862 if (!driFillInModes(&m
, fb_format
, fb_type
,
863 depth_bits_array
, stencil_bits_array
,
864 depth_buffer_factor
, back_buffer_modes
,
865 back_buffer_factor
, GLX_DIRECT_COLOR
)) {
866 fprintf(stderr
, "[%s:%u] Error creating FBConfig!\n", __func__
,
871 /* Mark the visual as slow if there are "fake" stencil bits.
873 for (m
= modes
; m
!= NULL
; m
= m
->next
) {
874 if ((m
->stencilBits
!= 0) && (m
->stencilBits
!= stencil_bits
)) {
875 m
->visualRating
= GLX_SLOW_CONFIG
;
884 * This is the bootstrap function for the driver. libGL supplies all of the
885 * requisite information about the system, and the driver initializes itself.
886 * This routine also fills in the linked list pointed to by \c driver_modes
887 * with the \c __GLcontextModes that the driver can support for windows or
890 * \return A pointer to a \c __DRIscreenPrivate on success, or \c NULL on
894 __driCreateNewScreen_20050727(__DRInativeDisplay
* dpy
, int scrn
,
896 const __GLcontextModes
* modes
,
897 const __DRIversion
* ddx_version
,
898 const __DRIversion
* dri_version
,
899 const __DRIversion
* drm_version
,
900 const __DRIframebuffer
* frame_buffer
,
901 drmAddress pSAREA
, int fd
,
902 int internal_api_version
,
903 const __DRIinterfaceMethods
* interface
,
904 __GLcontextModes
** driver_modes
)
906 __DRIscreenPrivate
*psp
;
907 static const __DRIversion ddx_expected
= { 1, 5, 0 };
908 static const __DRIversion dri_expected
= { 4, 0, 0 };
909 static const __DRIversion drm_expected
= { 1, 5, 0 };
911 dri_interface
= interface
;
913 if (!driCheckDriDdxDrmVersions2("i915",
914 dri_version
, &dri_expected
,
915 ddx_version
, &ddx_expected
,
916 drm_version
, &drm_expected
)) {
920 psp
= __driUtilCreateNewScreen(dpy
, scrn
, psc
, NULL
,
921 ddx_version
, dri_version
, drm_version
,
922 frame_buffer
, pSAREA
, fd
,
923 internal_api_version
, &intelAPI
);
926 I830DRIPtr dri_priv
= (I830DRIPtr
) psp
->pDevPriv
;
927 *driver_modes
= intelFillInModes(dri_priv
->cpp
* 8,
928 (dri_priv
->cpp
== 2) ? 16 : 24,
929 (dri_priv
->cpp
== 2) ? 0 : 8, 1);
931 /* Calling driInitExtensions here, with a NULL context pointer, does not actually
932 * enable the extensions. It just makes sure that all the dispatch offsets for all
933 * the extensions that *might* be enables are known. This is needed because the
934 * dispatch offsets need to be known when _mesa_context_create is called, but we can't
935 * enable the extensions until we have a context pointer.
937 * Hello chicken. Hello egg. How are you two today?
939 driInitExtensions(NULL
, card_extensions
, GL_FALSE
);
945 struct intel_context
*intelScreenContext(intelScreenPrivate
*intelScreen
)
948 * This should probably change to have the screen allocate a dummy
949 * context at screen creation. For now just use the current context.
952 GET_CURRENT_CONTEXT(ctx
);
954 _mesa_problem(NULL
, "No current context in intelScreenContext\n");
957 return intel_context(ctx
);