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_bufpool.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 (drmMap(sPriv
->fd
,
126 intelScreen
->tex
.handle
,
127 intelScreen
->tex
.size
,
128 (drmAddress
*) & intelScreen
->tex
.map
) != 0) {
129 intelUnmapScreenRegions(intelScreen
);
134 printf("Mappings: front: %p back: %p third: %p depth: %p tex: %p\n",
135 intelScreen
->front
.map
,
136 intelScreen
->back
.map
, intelScreen
->third
.map
,
137 intelScreen
->depth
.map
, intelScreen
->tex
.map
);
142 static struct intel_region
*
143 intel_recreate_static(intelScreenPrivate
*intelScreen
,
144 struct intel_region
*region
,
148 GLuint cpp
, GLuint pitch
, GLuint height
)
151 intel_region_update_static(intelScreen
, region
, mem_type
, offset
,
152 virtual, cpp
, pitch
, height
);
154 region
= intel_region_create_static(intelScreen
, mem_type
, offset
,
155 virtual, cpp
, pitch
, height
);
161 /* Create intel_region structs to describe the static front,back,depth
162 * buffers created by the xserver.
164 * Although FBO's mean we now no longer use these as render targets in
165 * all circumstances, they won't go away until the back and depth
166 * buffers become private, and the front and rotated buffers will
169 * Note that these don't allocate video memory, just describe
170 * allocations alread made by the X server.
173 intel_recreate_static_regions(intelScreenPrivate
*intelScreen
)
175 intelScreen
->front_region
=
176 intel_recreate_static(intelScreen
,
177 intelScreen
->front_region
,
179 intelScreen
->front
.offset
,
180 intelScreen
->front
.map
,
182 intelScreen
->front
.pitch
/ intelScreen
->cpp
,
183 intelScreen
->height
);
185 intelScreen
->rotated_region
=
186 intel_recreate_static(intelScreen
,
187 intelScreen
->rotated_region
,
189 intelScreen
->rotated
.offset
,
190 intelScreen
->rotated
.map
,
192 intelScreen
->rotated
.pitch
/
193 intelScreen
->cpp
, intelScreen
->height
);
196 intelScreen
->back_region
=
197 intel_recreate_static(intelScreen
,
198 intelScreen
->back_region
,
200 intelScreen
->back
.offset
,
201 intelScreen
->back
.map
,
203 intelScreen
->back
.pitch
/ intelScreen
->cpp
,
204 intelScreen
->height
);
206 if (intelScreen
->third
.handle
) {
207 intelScreen
->third_region
=
208 intel_recreate_static(intelScreen
,
209 intelScreen
->third_region
,
211 intelScreen
->third
.offset
,
212 intelScreen
->third
.map
,
214 intelScreen
->third
.pitch
/ intelScreen
->cpp
,
215 intelScreen
->height
);
218 /* Still assuming front.cpp == depth.cpp
220 intelScreen
->depth_region
=
221 intel_recreate_static(intelScreen
,
222 intelScreen
->depth_region
,
224 intelScreen
->depth
.offset
,
225 intelScreen
->depth
.map
,
227 intelScreen
->depth
.pitch
/ intelScreen
->cpp
,
228 intelScreen
->height
);
232 * Use the information in the sarea to update the screen parameters
233 * related to screen rotation. Needs to be called locked.
236 intelUpdateScreenRotation(__DRIscreenPrivate
* sPriv
, drmI830Sarea
* sarea
)
238 intelScreenPrivate
*intelScreen
= (intelScreenPrivate
*) sPriv
->private;
240 intelUnmapScreenRegions(intelScreen
);
241 intelUpdateScreenFromSAREA(intelScreen
, sarea
);
242 if (!intelMapScreenRegions(sPriv
)) {
243 fprintf(stderr
, "ERROR Remapping screen regions!!!\n");
245 intel_recreate_static_regions(intelScreen
);
250 intelUnmapScreenRegions(intelScreenPrivate
* intelScreen
)
252 #define REALLY_UNMAP 1
253 if (intelScreen
->front
.map
) {
255 if (drmUnmap(intelScreen
->front
.map
, intelScreen
->front
.size
) != 0)
256 printf("drmUnmap front failed!\n");
258 intelScreen
->front
.map
= NULL
;
260 if (intelScreen
->back
.map
) {
262 if (drmUnmap(intelScreen
->back
.map
, intelScreen
->back
.size
) != 0)
263 printf("drmUnmap back failed!\n");
265 intelScreen
->back
.map
= NULL
;
267 if (intelScreen
->third
.map
) {
269 if (drmUnmap(intelScreen
->third
.map
, intelScreen
->third
.size
) != 0)
270 printf("drmUnmap third failed!\n");
272 intelScreen
->third
.map
= NULL
;
274 if (intelScreen
->depth
.map
) {
276 drmUnmap(intelScreen
->depth
.map
, intelScreen
->depth
.size
);
277 intelScreen
->depth
.map
= NULL
;
280 if (intelScreen
->tex
.map
) {
282 drmUnmap(intelScreen
->tex
.map
, intelScreen
->tex
.size
);
283 intelScreen
->tex
.map
= NULL
;
290 intelPrintDRIInfo(intelScreenPrivate
* intelScreen
,
291 __DRIscreenPrivate
* sPriv
, I830DRIPtr gDRIPriv
)
293 fprintf(stderr
, "*** Front size: 0x%x offset: 0x%x pitch: %d\n",
294 intelScreen
->front
.size
, intelScreen
->front
.offset
,
295 intelScreen
->front
.pitch
);
296 fprintf(stderr
, "*** Back size: 0x%x offset: 0x%x pitch: %d\n",
297 intelScreen
->back
.size
, intelScreen
->back
.offset
,
298 intelScreen
->back
.pitch
);
299 fprintf(stderr
, "*** Depth size: 0x%x offset: 0x%x pitch: %d\n",
300 intelScreen
->depth
.size
, intelScreen
->depth
.offset
,
301 intelScreen
->depth
.pitch
);
302 fprintf(stderr
, "*** Rotated size: 0x%x offset: 0x%x pitch: %d\n",
303 intelScreen
->rotated
.size
, intelScreen
->rotated
.offset
,
304 intelScreen
->rotated
.pitch
);
305 fprintf(stderr
, "*** Texture size: 0x%x offset: 0x%x\n",
306 intelScreen
->tex
.size
, intelScreen
->tex
.offset
);
307 fprintf(stderr
, "*** Memory : 0x%x\n", gDRIPriv
->mem
);
312 intelPrintSAREA(const drmI830Sarea
* sarea
)
314 fprintf(stderr
, "SAREA: sarea width %d height %d\n", sarea
->width
,
316 fprintf(stderr
, "SAREA: pitch: %d\n", sarea
->pitch
);
318 "SAREA: front offset: 0x%08x size: 0x%x handle: 0x%x\n",
319 sarea
->front_offset
, sarea
->front_size
,
320 (unsigned) sarea
->front_handle
);
322 "SAREA: back offset: 0x%08x size: 0x%x handle: 0x%x\n",
323 sarea
->back_offset
, sarea
->back_size
,
324 (unsigned) sarea
->back_handle
);
325 fprintf(stderr
, "SAREA: depth offset: 0x%08x size: 0x%x handle: 0x%x\n",
326 sarea
->depth_offset
, sarea
->depth_size
,
327 (unsigned) sarea
->depth_handle
);
328 fprintf(stderr
, "SAREA: tex offset: 0x%08x size: 0x%x handle: 0x%x\n",
329 sarea
->tex_offset
, sarea
->tex_size
, (unsigned) sarea
->tex_handle
);
330 fprintf(stderr
, "SAREA: rotation: %d\n", sarea
->rotation
);
332 "SAREA: rotated offset: 0x%08x size: 0x%x\n",
333 sarea
->rotated_offset
, sarea
->rotated_size
);
334 fprintf(stderr
, "SAREA: rotated pitch: %d\n", sarea
->rotated_pitch
);
339 * A number of the screen parameters are obtained/computed from
340 * information in the SAREA. This function updates those parameters.
343 intelUpdateScreenFromSAREA(intelScreenPrivate
* intelScreen
,
344 drmI830Sarea
* sarea
)
346 intelScreen
->width
= sarea
->width
;
347 intelScreen
->height
= sarea
->height
;
349 intelScreen
->front
.offset
= sarea
->front_offset
;
350 intelScreen
->front
.pitch
= sarea
->pitch
* intelScreen
->cpp
;
351 intelScreen
->front
.handle
= sarea
->front_handle
;
352 intelScreen
->front
.size
= sarea
->front_size
;
354 intelScreen
->back
.offset
= sarea
->back_offset
;
355 intelScreen
->back
.pitch
= sarea
->pitch
* intelScreen
->cpp
;
356 intelScreen
->back
.handle
= sarea
->back_handle
;
357 intelScreen
->back
.size
= sarea
->back_size
;
359 if (intelScreen
->driScrnPriv
->ddxMinor
>= 8) {
360 intelScreen
->third
.offset
= sarea
->third_offset
;
361 intelScreen
->third
.pitch
= sarea
->pitch
* intelScreen
->cpp
;
362 intelScreen
->third
.handle
= sarea
->third_handle
;
363 intelScreen
->third
.size
= sarea
->third_size
;
366 intelScreen
->depth
.offset
= sarea
->depth_offset
;
367 intelScreen
->depth
.pitch
= sarea
->pitch
* intelScreen
->cpp
;
368 intelScreen
->depth
.handle
= sarea
->depth_handle
;
369 intelScreen
->depth
.size
= sarea
->depth_size
;
371 intelScreen
->tex
.offset
= sarea
->tex_offset
;
372 intelScreen
->logTextureGranularity
= sarea
->log_tex_granularity
;
373 intelScreen
->tex
.handle
= sarea
->tex_handle
;
374 intelScreen
->tex
.size
= sarea
->tex_size
;
376 intelScreen
->rotated
.offset
= sarea
->rotated_offset
;
377 intelScreen
->rotated
.pitch
= sarea
->rotated_pitch
* intelScreen
->cpp
;
378 intelScreen
->rotated
.size
= sarea
->rotated_size
;
379 intelScreen
->current_rotation
= sarea
->rotation
;
380 matrix23Rotate(&intelScreen
->rotMatrix
,
381 sarea
->width
, sarea
->height
, sarea
->rotation
);
382 intelScreen
->rotatedWidth
= sarea
->virtualX
;
383 intelScreen
->rotatedHeight
= sarea
->virtualY
;
386 intelPrintSAREA(sarea
);
391 intelInitDriver(__DRIscreenPrivate
* sPriv
)
393 intelScreenPrivate
*intelScreen
;
394 I830DRIPtr gDRIPriv
= (I830DRIPtr
) sPriv
->pDevPriv
;
396 unsigned batchPoolSize
= 1024*1024;
398 PFNGLXSCRENABLEEXTENSIONPROC glx_enable_extension
=
399 (PFNGLXSCRENABLEEXTENSIONPROC
) (*dri_interface
->
400 getProcAddress("glxEnableExtension"));
401 void *const psc
= sPriv
->psc
->screenConfigs
;
403 if (sPriv
->devPrivSize
!= sizeof(I830DRIRec
)) {
405 "\nERROR! sizeof(I830DRIRec) does not match passed size from device driver\n");
409 /* Allocate the private area */
410 intelScreen
= (intelScreenPrivate
*) CALLOC(sizeof(intelScreenPrivate
));
412 fprintf(stderr
, "\nERROR! Allocating private area failed\n");
415 /* parse information in __driConfigOptions */
416 driParseOptionInfo(&intelScreen
->optionCache
,
417 __driConfigOptions
, __driNConfigOptions
);
419 intelScreen
->driScrnPriv
= sPriv
;
420 sPriv
->private = (void *) intelScreen
;
421 intelScreen
->sarea_priv_offset
= gDRIPriv
->sarea_priv_offset
;
422 sarea
= (drmI830Sarea
*)
423 (((GLubyte
*) sPriv
->pSAREA
) + intelScreen
->sarea_priv_offset
);
425 intelScreen
->maxBatchSize
= BATCH_SZ
;
426 intelScreen
->deviceID
= gDRIPriv
->deviceID
;
427 if (intelScreen
->deviceID
== PCI_CHIP_I865_G
)
428 intelScreen
->maxBatchSize
= 4096;
429 batchPoolSize
/= intelScreen
->maxBatchSize
;
431 intelScreen
->mem
= gDRIPriv
->mem
;
432 intelScreen
->cpp
= gDRIPriv
->cpp
;
434 switch (gDRIPriv
->bitsPerPixel
) {
436 intelScreen
->fbFormat
= DV_PF_565
;
439 intelScreen
->fbFormat
= DV_PF_8888
;
446 intelUpdateScreenFromSAREA(intelScreen
, sarea
);
448 if (!intelMapScreenRegions(sPriv
)) {
449 fprintf(stderr
, "\nERROR! mapping regions\n");
450 _mesa_free(intelScreen
);
451 sPriv
->private = NULL
;
458 * FIXME: Remove this code and its references.
461 intelScreen
->tex
.offset
= gDRIPriv
->textureOffset
;
462 intelScreen
->logTextureGranularity
= gDRIPriv
->logTextureGranularity
;
463 intelScreen
->tex
.handle
= gDRIPriv
->textures
;
464 intelScreen
->tex
.size
= gDRIPriv
->textureSize
;
467 intelScreen
->tex
.offset
= 0;
468 intelScreen
->logTextureGranularity
= 0;
469 intelScreen
->tex
.handle
= 0;
470 intelScreen
->tex
.size
= 0;
473 intelScreen
->sarea_priv_offset
= gDRIPriv
->sarea_priv_offset
;
476 intelPrintDRIInfo(intelScreen
, sPriv
, gDRIPriv
);
478 intelScreen
->drmMinor
= sPriv
->drmMinor
;
480 /* Determine if IRQs are active? */
485 gp
.param
= I830_PARAM_IRQ_ACTIVE
;
486 gp
.value
= &intelScreen
->irq_active
;
488 ret
= drmCommandWriteRead(sPriv
->fd
, DRM_I830_GETPARAM
,
491 fprintf(stderr
, "drmI830GetParam: %d\n", ret
);
496 /* Determine if batchbuffers are allowed */
501 gp
.param
= I830_PARAM_ALLOW_BATCHBUFFER
;
502 gp
.value
= &intelScreen
->allow_batchbuffer
;
504 ret
= drmCommandWriteRead(sPriv
->fd
, DRM_I830_GETPARAM
,
507 fprintf(stderr
, "drmI830GetParam: (%d) %d\n", gp
.param
, ret
);
512 if (glx_enable_extension
!= NULL
) {
513 (*glx_enable_extension
) (psc
, "GLX_SGI_swap_control");
514 (*glx_enable_extension
) (psc
, "GLX_SGI_video_sync");
515 (*glx_enable_extension
) (psc
, "GLX_MESA_swap_control");
516 (*glx_enable_extension
) (psc
, "GLX_MESA_swap_frame_usage");
517 (*glx_enable_extension
) (psc
, "GLX_SGI_make_current_read");
520 intelScreen
->regionPool
= driDRMPoolInit(sPriv
->fd
);
522 if (!intelScreen
->regionPool
)
525 intelScreen
->staticPool
= driDRMStaticPoolInit(sPriv
->fd
);
527 if (!intelScreen
->staticPool
)
530 intelScreen
->texPool
= intelScreen
->regionPool
;
532 intelScreen
->batchPool
= driBatchPoolInit(sPriv
->fd
,
535 DRM_BO_FLAG_MEM_LOCAL
,
536 intelScreen
->maxBatchSize
,
538 if (!intelScreen
->batchPool
) {
539 fprintf(stderr
, "Failed to initialize batch pool - possible incorrect agpgart installed\n");
543 intel_recreate_static_regions(intelScreen
);
550 intelDestroyScreen(__DRIscreenPrivate
* sPriv
)
552 intelScreenPrivate
*intelScreen
= (intelScreenPrivate
*) sPriv
->private;
554 intelUnmapScreenRegions(intelScreen
);
556 driPoolTakeDown(intelScreen
->regionPool
);
557 driPoolTakeDown(intelScreen
->staticPool
);
558 driPoolTakeDown(intelScreen
->batchPool
);
560 sPriv
->private = NULL
;
565 * This is called when we need to set up GL rendering to a new X window.
568 intelCreateBuffer(__DRIscreenPrivate
* driScrnPriv
,
569 __DRIdrawablePrivate
* driDrawPriv
,
570 const __GLcontextModes
* mesaVis
, GLboolean isPixmap
)
572 intelScreenPrivate
*screen
= (intelScreenPrivate
*) driScrnPriv
->private;
575 return GL_FALSE
; /* not implemented */
578 GLboolean swStencil
= (mesaVis
->stencilBits
> 0 &&
579 mesaVis
->depthBits
!= 24);
580 GLenum rgbFormat
= (mesaVis
->redBits
== 5 ? GL_RGB5
: GL_RGBA8
);
582 struct intel_framebuffer
*intel_fb
= CALLOC_STRUCT(intel_framebuffer
);
587 _mesa_initialize_framebuffer(&intel_fb
->Base
, mesaVis
);
589 /* setup the hardware-based renderbuffers */
591 intel_fb
->color_rb
[0]
592 = intel_create_renderbuffer(rgbFormat
,
593 screen
->width
, screen
->height
,
594 screen
->front
.offset
,
598 intel_set_span_functions(&intel_fb
->color_rb
[0]->Base
);
599 _mesa_add_renderbuffer(&intel_fb
->Base
, BUFFER_FRONT_LEFT
,
600 &intel_fb
->color_rb
[0]->Base
);
603 if (mesaVis
->doubleBufferMode
) {
604 intel_fb
->color_rb
[1]
605 = intel_create_renderbuffer(rgbFormat
,
606 screen
->width
, screen
->height
,
611 intel_set_span_functions(&intel_fb
->color_rb
[1]->Base
);
612 _mesa_add_renderbuffer(&intel_fb
->Base
, BUFFER_BACK_LEFT
,
613 &intel_fb
->color_rb
[1]->Base
);
615 if (screen
->third
.handle
) {
616 struct gl_renderbuffer
*tmp_rb
= NULL
;
618 intel_fb
->color_rb
[2]
619 = intel_create_renderbuffer(rgbFormat
,
620 screen
->width
, screen
->height
,
621 screen
->third
.offset
,
625 intel_set_span_functions(&intel_fb
->color_rb
[2]->Base
);
626 _mesa_reference_renderbuffer(&tmp_rb
, &intel_fb
->color_rb
[2]->Base
);
630 if (mesaVis
->depthBits
== 24 && mesaVis
->stencilBits
== 8) {
631 /* combined depth/stencil buffer */
632 struct intel_renderbuffer
*depthStencilRb
633 = intel_create_renderbuffer(GL_DEPTH24_STENCIL8_EXT
,
634 screen
->width
, screen
->height
,
635 screen
->depth
.offset
,
637 screen
->cpp
, /* 4! */
639 intel_set_span_functions(&depthStencilRb
->Base
);
640 /* note: bind RB to two attachment points */
641 _mesa_add_renderbuffer(&intel_fb
->Base
, BUFFER_DEPTH
,
642 &depthStencilRb
->Base
);
643 _mesa_add_renderbuffer(&intel_fb
->Base
, BUFFER_STENCIL
,
644 &depthStencilRb
->Base
);
646 else if (mesaVis
->depthBits
== 16) {
647 /* just 16-bit depth buffer, no hw stencil */
648 struct intel_renderbuffer
*depthRb
649 = intel_create_renderbuffer(GL_DEPTH_COMPONENT16
,
650 screen
->width
, screen
->height
,
651 screen
->depth
.offset
,
653 screen
->cpp
, /* 2! */
655 intel_set_span_functions(&depthRb
->Base
);
656 _mesa_add_renderbuffer(&intel_fb
->Base
, BUFFER_DEPTH
, &depthRb
->Base
);
659 /* now add any/all software-based renderbuffers we may need */
660 _mesa_add_soft_renderbuffers(&intel_fb
->Base
,
661 GL_FALSE
, /* never sw color */
662 GL_FALSE
, /* never sw depth */
663 swStencil
, mesaVis
->accumRedBits
> 0,
664 GL_FALSE
, /* never sw alpha */
665 GL_FALSE
/* never sw aux */ );
666 driDrawPriv
->driverPrivate
= (void *) intel_fb
;
673 intelDestroyBuffer(__DRIdrawablePrivate
* driDrawPriv
)
675 _mesa_unreference_framebuffer((GLframebuffer
**)(&(driDrawPriv
->driverPrivate
)));
680 * Get information about previous buffer swaps.
683 intelGetSwapInfo(__DRIdrawablePrivate
* dPriv
, __DRIswapInfo
* sInfo
)
685 struct intel_framebuffer
*intel_fb
;
687 if ((dPriv
== NULL
) || (dPriv
->driverPrivate
== NULL
)
688 || (sInfo
== NULL
)) {
692 intel_fb
= dPriv
->driverPrivate
;
693 sInfo
->swap_count
= intel_fb
->swap_count
;
694 sInfo
->swap_ust
= intel_fb
->swap_ust
;
695 sInfo
->swap_missed_count
= intel_fb
->swap_missed_count
;
697 sInfo
->swap_missed_usage
= (sInfo
->swap_missed_count
!= 0)
698 ? driCalculateSwapUsage(dPriv
, 0, intel_fb
->swap_missed_ust
)
705 /* There are probably better ways to do this, such as an
706 * init-designated function to register chipids and createcontext
709 extern GLboolean
i830CreateContext(const __GLcontextModes
* mesaVis
,
710 __DRIcontextPrivate
* driContextPriv
,
711 void *sharedContextPrivate
);
713 extern GLboolean
i915CreateContext(const __GLcontextModes
* mesaVis
,
714 __DRIcontextPrivate
* driContextPriv
,
715 void *sharedContextPrivate
);
721 intelCreateContext(const __GLcontextModes
* mesaVis
,
722 __DRIcontextPrivate
* driContextPriv
,
723 void *sharedContextPrivate
)
725 __DRIscreenPrivate
*sPriv
= driContextPriv
->driScreenPriv
;
726 intelScreenPrivate
*intelScreen
= (intelScreenPrivate
*) sPriv
->private;
728 switch (intelScreen
->deviceID
) {
729 /* Don't deal with i830 until texture work complete:
732 case PCI_CHIP_I830_M
:
733 case PCI_CHIP_I855_GM
:
734 case PCI_CHIP_I865_G
:
735 return i830CreateContext(mesaVis
, driContextPriv
, sharedContextPrivate
);
737 case PCI_CHIP_I915_G
:
738 case PCI_CHIP_I915_GM
:
739 case PCI_CHIP_I945_G
:
740 case PCI_CHIP_I945_GM
:
741 return i915CreateContext(mesaVis
, driContextPriv
, sharedContextPrivate
);
744 fprintf(stderr
, "Unrecognized deviceID %x\n", intelScreen
->deviceID
);
750 static const struct __DriverAPIRec intelAPI
= {
751 .InitDriver
= intelInitDriver
,
752 .DestroyScreen
= intelDestroyScreen
,
753 .CreateContext
= intelCreateContext
,
754 .DestroyContext
= intelDestroyContext
,
755 .CreateBuffer
= intelCreateBuffer
,
756 .DestroyBuffer
= intelDestroyBuffer
,
757 .SwapBuffers
= intelSwapBuffers
,
758 .MakeCurrent
= intelMakeCurrent
,
759 .UnbindContext
= intelUnbindContext
,
760 .GetSwapInfo
= intelGetSwapInfo
,
761 .GetMSC
= driGetMSC32
,
762 .WaitForMSC
= driWaitForMSC32
,
764 .SwapBuffersMSC
= NULL
,
765 .CopySubBuffer
= intelCopySubBuffer
769 static __GLcontextModes
*
770 intelFillInModes(unsigned pixel_bits
, unsigned depth_bits
,
771 unsigned stencil_bits
, GLboolean have_back_buffer
)
773 __GLcontextModes
*modes
;
776 unsigned depth_buffer_factor
;
777 unsigned back_buffer_factor
;
781 /* GLX_SWAP_COPY_OML is only supported because the Intel driver doesn't
782 * support pageflipping at all.
784 static const GLenum back_buffer_modes
[] = {
785 GLX_NONE
, GLX_SWAP_UNDEFINED_OML
, GLX_SWAP_COPY_OML
788 u_int8_t depth_bits_array
[3];
789 u_int8_t stencil_bits_array
[3];
792 depth_bits_array
[0] = 0;
793 depth_bits_array
[1] = depth_bits
;
794 depth_bits_array
[2] = depth_bits
;
796 /* Just like with the accumulation buffer, always provide some modes
797 * with a stencil buffer. It will be a sw fallback, but some apps won't
800 stencil_bits_array
[0] = 0;
801 stencil_bits_array
[1] = 0;
802 if (depth_bits
== 24)
803 stencil_bits_array
[1] = (stencil_bits
== 0) ? 8 : stencil_bits
;
805 stencil_bits_array
[2] = (stencil_bits
== 0) ? 8 : stencil_bits
;
807 depth_buffer_factor
= ((depth_bits
!= 0) || (stencil_bits
!= 0)) ? 3 : 1;
808 back_buffer_factor
= (have_back_buffer
) ? 3 : 1;
810 num_modes
= depth_buffer_factor
* back_buffer_factor
* 4;
812 if (pixel_bits
== 16) {
814 fb_type
= GL_UNSIGNED_SHORT_5_6_5
;
818 fb_type
= GL_UNSIGNED_INT_8_8_8_8_REV
;
822 (*dri_interface
->createContextModes
) (num_modes
,
823 sizeof(__GLcontextModes
));
825 if (!driFillInModes(&m
, fb_format
, fb_type
,
826 depth_bits_array
, stencil_bits_array
,
827 depth_buffer_factor
, back_buffer_modes
,
828 back_buffer_factor
, GLX_TRUE_COLOR
)) {
829 fprintf(stderr
, "[%s:%u] Error creating FBConfig!\n", __func__
,
833 if (!driFillInModes(&m
, fb_format
, fb_type
,
834 depth_bits_array
, stencil_bits_array
,
835 depth_buffer_factor
, back_buffer_modes
,
836 back_buffer_factor
, GLX_DIRECT_COLOR
)) {
837 fprintf(stderr
, "[%s:%u] Error creating FBConfig!\n", __func__
,
842 /* Mark the visual as slow if there are "fake" stencil bits.
844 for (m
= modes
; m
!= NULL
; m
= m
->next
) {
845 if ((m
->stencilBits
!= 0) && (m
->stencilBits
!= stencil_bits
)) {
846 m
->visualRating
= GLX_SLOW_CONFIG
;
855 * This is the bootstrap function for the driver. libGL supplies all of the
856 * requisite information about the system, and the driver initializes itself.
857 * This routine also fills in the linked list pointed to by \c driver_modes
858 * with the \c __GLcontextModes that the driver can support for windows or
861 * \return A pointer to a \c __DRIscreenPrivate on success, or \c NULL on
865 __driCreateNewScreen_20050727(__DRInativeDisplay
* dpy
, int scrn
,
867 const __GLcontextModes
* modes
,
868 const __DRIversion
* ddx_version
,
869 const __DRIversion
* dri_version
,
870 const __DRIversion
* drm_version
,
871 const __DRIframebuffer
* frame_buffer
,
872 drmAddress pSAREA
, int fd
,
873 int internal_api_version
,
874 const __DRIinterfaceMethods
* interface
,
875 __GLcontextModes
** driver_modes
)
877 __DRIscreenPrivate
*psp
;
878 static const __DRIversion ddx_expected
= { 1, 5, 0 };
879 static const __DRIversion dri_expected
= { 4, 0, 0 };
880 static const __DRIversion drm_expected
= { 1, 7, 0 };
882 dri_interface
= interface
;
884 if (!driCheckDriDdxDrmVersions2("i915",
885 dri_version
, &dri_expected
,
886 ddx_version
, &ddx_expected
,
887 drm_version
, &drm_expected
)) {
891 psp
= __driUtilCreateNewScreen(dpy
, scrn
, psc
, NULL
,
892 ddx_version
, dri_version
, drm_version
,
893 frame_buffer
, pSAREA
, fd
,
894 internal_api_version
, &intelAPI
);
896 I830DRIPtr dri_priv
= (I830DRIPtr
) psp
->pDevPriv
;
897 *driver_modes
= intelFillInModes(dri_priv
->cpp
* 8,
898 (dri_priv
->cpp
== 2) ? 16 : 24,
899 (dri_priv
->cpp
== 2) ? 0 : 8, 1);
901 /* Calling driInitExtensions here, with a NULL context pointer, does not actually
902 * enable the extensions. It just makes sure that all the dispatch offsets for all
903 * the extensions that *might* be enables are known. This is needed because the
904 * dispatch offsets need to be known when _mesa_context_create is called, but we can't
905 * enable the extensions until we have a context pointer.
907 * Hello chicken. Hello egg. How are you two today?
909 driInitExtensions(NULL
, card_extensions
, GL_FALSE
);
915 struct intel_context
*intelScreenContext(intelScreenPrivate
*intelScreen
)
918 * This should probably change to have the screen allocate a dummy
919 * context at screen creation. For now just use the current context.
922 GET_CURRENT_CONTEXT(ctx
);
924 _mesa_problem(NULL
, "No current context in intelScreenContext\n");
927 return intel_context(ctx
);