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 buffer will remain even then.
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 intelScreen
->back_region
=
220 intel_recreate_static(intelScreen
,
221 intelScreen
->back_region
,
225 if (intelScreen
->third
.handle
) {
226 intelScreen
->third_region
=
227 intel_recreate_static(intelScreen
,
228 intelScreen
->third_region
,
233 /* Still assumes front.cpp == depth.cpp. We can kill this when we move to
236 intelScreen
->depth_region
=
237 intel_recreate_static(intelScreen
,
238 intelScreen
->depth_region
,
244 intelUnmapScreenRegions(intelScreenPrivate
* intelScreen
)
246 #define REALLY_UNMAP 1
247 if (intelScreen
->front
.map
) {
249 if (drmUnmap(intelScreen
->front
.map
, intelScreen
->front
.size
) != 0)
250 printf("drmUnmap front failed!\n");
252 intelScreen
->front
.map
= NULL
;
254 if (intelScreen
->back
.map
) {
256 if (drmUnmap(intelScreen
->back
.map
, intelScreen
->back
.size
) != 0)
257 printf("drmUnmap back failed!\n");
259 intelScreen
->back
.map
= NULL
;
261 if (intelScreen
->third
.map
) {
263 if (drmUnmap(intelScreen
->third
.map
, intelScreen
->third
.size
) != 0)
264 printf("drmUnmap third failed!\n");
266 intelScreen
->third
.map
= NULL
;
268 if (intelScreen
->depth
.map
) {
270 drmUnmap(intelScreen
->depth
.map
, intelScreen
->depth
.size
);
271 intelScreen
->depth
.map
= NULL
;
274 if (intelScreen
->tex
.map
) {
276 drmUnmap(intelScreen
->tex
.map
, intelScreen
->tex
.size
);
277 intelScreen
->tex
.map
= NULL
;
284 intelPrintDRIInfo(intelScreenPrivate
* intelScreen
,
285 __DRIscreenPrivate
* sPriv
, I830DRIPtr gDRIPriv
)
287 fprintf(stderr
, "*** Front size: 0x%x offset: 0x%x pitch: %d\n",
288 intelScreen
->front
.size
, intelScreen
->front
.offset
,
289 intelScreen
->front
.pitch
);
290 fprintf(stderr
, "*** Back size: 0x%x offset: 0x%x pitch: %d\n",
291 intelScreen
->back
.size
, intelScreen
->back
.offset
,
292 intelScreen
->back
.pitch
);
293 fprintf(stderr
, "*** Depth size: 0x%x offset: 0x%x pitch: %d\n",
294 intelScreen
->depth
.size
, intelScreen
->depth
.offset
,
295 intelScreen
->depth
.pitch
);
296 fprintf(stderr
, "*** Texture size: 0x%x offset: 0x%x\n",
297 intelScreen
->tex
.size
, intelScreen
->tex
.offset
);
298 fprintf(stderr
, "*** Memory : 0x%x\n", gDRIPriv
->mem
);
303 intelPrintSAREA(const drmI830Sarea
* sarea
)
305 fprintf(stderr
, "SAREA: sarea width %d height %d\n", sarea
->width
,
307 fprintf(stderr
, "SAREA: pitch: %d\n", sarea
->pitch
);
309 "SAREA: front offset: 0x%08x size: 0x%x handle: 0x%x\n",
310 sarea
->front_offset
, sarea
->front_size
,
311 (unsigned) sarea
->front_handle
);
313 "SAREA: back offset: 0x%08x size: 0x%x handle: 0x%x\n",
314 sarea
->back_offset
, sarea
->back_size
,
315 (unsigned) sarea
->back_handle
);
316 fprintf(stderr
, "SAREA: depth offset: 0x%08x size: 0x%x handle: 0x%x\n",
317 sarea
->depth_offset
, sarea
->depth_size
,
318 (unsigned) sarea
->depth_handle
);
319 fprintf(stderr
, "SAREA: tex offset: 0x%08x size: 0x%x handle: 0x%x\n",
320 sarea
->tex_offset
, sarea
->tex_size
, (unsigned) sarea
->tex_handle
);
325 * A number of the screen parameters are obtained/computed from
326 * information in the SAREA. This function updates those parameters.
329 intelUpdateScreenFromSAREA(intelScreenPrivate
* intelScreen
,
330 drmI830Sarea
* sarea
)
332 intelScreen
->width
= sarea
->width
;
333 intelScreen
->height
= sarea
->height
;
335 intelScreen
->front
.offset
= sarea
->front_offset
;
336 intelScreen
->front
.pitch
= sarea
->pitch
* intelScreen
->cpp
;
337 intelScreen
->front
.handle
= sarea
->front_handle
;
338 intelScreen
->front
.size
= sarea
->front_size
;
340 intelScreen
->back
.offset
= sarea
->back_offset
;
341 intelScreen
->back
.pitch
= sarea
->pitch
* intelScreen
->cpp
;
342 intelScreen
->back
.handle
= sarea
->back_handle
;
343 intelScreen
->back
.size
= sarea
->back_size
;
345 if (intelScreen
->driScrnPriv
->ddx_version
.minor
>= 8) {
346 intelScreen
->third
.offset
= sarea
->third_offset
;
347 intelScreen
->third
.pitch
= sarea
->pitch
* intelScreen
->cpp
;
348 intelScreen
->third
.handle
= sarea
->third_handle
;
349 intelScreen
->third
.size
= sarea
->third_size
;
352 intelScreen
->depth
.offset
= sarea
->depth_offset
;
353 intelScreen
->depth
.pitch
= sarea
->pitch
* intelScreen
->cpp
;
354 intelScreen
->depth
.handle
= sarea
->depth_handle
;
355 intelScreen
->depth
.size
= sarea
->depth_size
;
357 if (intelScreen
->driScrnPriv
->ddx_version
.minor
>= 9) {
358 intelScreen
->front
.bo_handle
= sarea
->front_bo_handle
;
359 intelScreen
->back
.bo_handle
= sarea
->back_bo_handle
;
360 intelScreen
->third
.bo_handle
= sarea
->third_bo_handle
;
361 intelScreen
->depth
.bo_handle
= sarea
->depth_bo_handle
;
363 intelScreen
->front
.bo_handle
= -1;
364 intelScreen
->back
.bo_handle
= -1;
365 intelScreen
->third
.bo_handle
= -1;
366 intelScreen
->depth
.bo_handle
= -1;
369 intelScreen
->tex
.offset
= sarea
->tex_offset
;
370 intelScreen
->logTextureGranularity
= sarea
->log_tex_granularity
;
371 intelScreen
->tex
.handle
= sarea
->tex_handle
;
372 intelScreen
->tex
.size
= sarea
->tex_size
;
375 intelPrintSAREA(sarea
);
378 static const __DRItexOffsetExtension intelTexOffsetExtension
= {
379 { __DRI_TEX_OFFSET
},
383 static const __DRIextension
*intelExtensions
[] = {
384 &driReadDrawableExtension
,
385 &driCopySubBufferExtension
.base
,
386 &driSwapControlExtension
.base
,
387 &driFrameTrackingExtension
.base
,
388 &driMediaStreamCounterExtension
.base
,
389 &intelTexOffsetExtension
.base
,
394 static GLboolean
intelInitDriver(__DRIscreenPrivate
*sPriv
)
396 intelScreenPrivate
*intelScreen
;
397 I830DRIPtr gDRIPriv
= (I830DRIPtr
) sPriv
->pDevPriv
;
400 if (sPriv
->devPrivSize
!= sizeof(I830DRIRec
)) {
402 "\nERROR! sizeof(I830DRIRec) does not match passed size from device driver\n");
406 /* Allocate the private area */
407 intelScreen
= (intelScreenPrivate
*) CALLOC(sizeof(intelScreenPrivate
));
409 fprintf(stderr
, "\nERROR! Allocating private area failed\n");
412 /* parse information in __driConfigOptions */
413 driParseOptionInfo(&intelScreen
->optionCache
,
414 __driConfigOptions
, __driNConfigOptions
);
416 intelScreen
->driScrnPriv
= sPriv
;
417 sPriv
->private = (void *) intelScreen
;
418 intelScreen
->sarea_priv_offset
= gDRIPriv
->sarea_priv_offset
;
419 sarea
= (drmI830Sarea
*)
420 (((GLubyte
*) sPriv
->pSAREA
) + intelScreen
->sarea_priv_offset
);
422 intelScreen
->deviceID
= gDRIPriv
->deviceID
;
423 if (intelScreen
->deviceID
== PCI_CHIP_I865_G
)
424 intelScreen
->maxBatchSize
= 4096;
426 intelScreen
->maxBatchSize
= BATCH_SZ
;
428 intelScreen
->mem
= gDRIPriv
->mem
;
429 intelScreen
->cpp
= gDRIPriv
->cpp
;
431 switch (gDRIPriv
->bitsPerPixel
) {
433 intelScreen
->fbFormat
= DV_PF_565
;
436 intelScreen
->fbFormat
= DV_PF_8888
;
443 intelUpdateScreenFromSAREA(intelScreen
, sarea
);
445 if (!intelMapScreenRegions(sPriv
)) {
446 fprintf(stderr
, "\nERROR! mapping regions\n");
447 _mesa_free(intelScreen
);
448 sPriv
->private = NULL
;
452 intelScreen
->sarea_priv_offset
= gDRIPriv
->sarea_priv_offset
;
455 intelPrintDRIInfo(intelScreen
, sPriv
, gDRIPriv
);
457 intelScreen
->drmMinor
= sPriv
->drm_version
.minor
;
459 /* Determine if IRQs are active? */
464 gp
.param
= I830_PARAM_IRQ_ACTIVE
;
465 gp
.value
= &intelScreen
->irq_active
;
467 ret
= drmCommandWriteRead(sPriv
->fd
, DRM_I830_GETPARAM
,
470 fprintf(stderr
, "drmI830GetParam: %d\n", ret
);
475 /* Determine if batchbuffers are allowed */
480 gp
.param
= I830_PARAM_ALLOW_BATCHBUFFER
;
481 gp
.value
= &intelScreen
->allow_batchbuffer
;
483 ret
= drmCommandWriteRead(sPriv
->fd
, DRM_I830_GETPARAM
,
486 fprintf(stderr
, "drmI830GetParam: (%d) %d\n", gp
.param
, ret
);
491 sPriv
->extensions
= intelExtensions
;
493 /* If we've got a new enough DDX that's initializing TTM and giving us
494 * object handles for the shared buffers, use that.
496 intelScreen
->ttm
= GL_FALSE
;
497 if (getenv("INTEL_NO_TTM") == NULL
&&
498 intelScreen
->driScrnPriv
->ddx_version
.minor
>= 9 &&
499 intelScreen
->drmMinor
>= 11 &&
500 intelScreen
->front
.bo_handle
!= -1) {
501 intelScreen
->bufmgr
= intel_bufmgr_ttm_init(sPriv
->fd
,
504 DRM_I915_FENCE_TYPE_RW
,
506 if (intelScreen
->bufmgr
!= NULL
)
507 intelScreen
->ttm
= GL_TRUE
;
509 /* Otherwise, use the classic buffer manager. */
510 if (intelScreen
->bufmgr
== NULL
) {
511 if (intelScreen
->tex
.size
== 0) {
512 fprintf(stderr
, "[%s:%u] Error initializing buffer manager.\n",
516 fprintf(stderr
, "[%s:%u] Failed to init TTM buffer manager, falling back"
517 " to classic.\n", __func__
, __LINE__
);
518 intelScreen
->bufmgr
= dri_bufmgr_fake_init(intelScreen
->tex
.offset
,
519 intelScreen
->tex
.map
,
520 intelScreen
->tex
.size
,
526 intel_recreate_static_regions(intelScreen
);
533 intelDestroyScreen(__DRIscreenPrivate
* sPriv
)
535 intelScreenPrivate
*intelScreen
= (intelScreenPrivate
*) sPriv
->private;
537 intelUnmapScreenRegions(intelScreen
);
539 dri_bufmgr_destroy(intelScreen
->bufmgr
);
541 sPriv
->private = NULL
;
546 * This is called when we need to set up GL rendering to a new X window.
549 intelCreateBuffer(__DRIscreenPrivate
* driScrnPriv
,
550 __DRIdrawablePrivate
* driDrawPriv
,
551 const __GLcontextModes
* mesaVis
, GLboolean isPixmap
)
553 intelScreenPrivate
*screen
= (intelScreenPrivate
*) driScrnPriv
->private;
556 return GL_FALSE
; /* not implemented */
559 GLboolean swStencil
= (mesaVis
->stencilBits
> 0 &&
560 mesaVis
->depthBits
!= 24);
561 GLenum rgbFormat
= (mesaVis
->redBits
== 5 ? GL_RGB5
: GL_RGBA8
);
563 struct intel_framebuffer
*intel_fb
= CALLOC_STRUCT(intel_framebuffer
);
568 _mesa_initialize_framebuffer(&intel_fb
->Base
, mesaVis
);
570 /* setup the hardware-based renderbuffers */
572 intel_fb
->color_rb
[0]
573 = intel_create_renderbuffer(rgbFormat
,
574 screen
->width
, screen
->height
,
575 screen
->front
.offset
,
579 intel_set_span_functions(&intel_fb
->color_rb
[0]->Base
);
580 _mesa_add_renderbuffer(&intel_fb
->Base
, BUFFER_FRONT_LEFT
,
581 &intel_fb
->color_rb
[0]->Base
);
584 if (mesaVis
->doubleBufferMode
) {
585 intel_fb
->color_rb
[1]
586 = intel_create_renderbuffer(rgbFormat
,
587 screen
->width
, screen
->height
,
592 intel_set_span_functions(&intel_fb
->color_rb
[1]->Base
);
593 _mesa_add_renderbuffer(&intel_fb
->Base
, BUFFER_BACK_LEFT
,
594 &intel_fb
->color_rb
[1]->Base
);
596 if (screen
->third
.handle
) {
597 struct gl_renderbuffer
*tmp_rb
= NULL
;
599 intel_fb
->color_rb
[2]
600 = intel_create_renderbuffer(rgbFormat
,
601 screen
->width
, screen
->height
,
602 screen
->third
.offset
,
606 intel_set_span_functions(&intel_fb
->color_rb
[2]->Base
);
607 _mesa_reference_renderbuffer(&tmp_rb
, &intel_fb
->color_rb
[2]->Base
);
611 if (mesaVis
->depthBits
== 24) {
612 if (mesaVis
->stencilBits
== 8) {
613 /* combined depth/stencil buffer */
614 struct intel_renderbuffer
*depthStencilRb
615 = intel_create_renderbuffer(GL_DEPTH24_STENCIL8_EXT
,
616 screen
->width
, screen
->height
,
617 screen
->depth
.offset
,
619 screen
->cpp
, /* 4! */
621 intel_set_span_functions(&depthStencilRb
->Base
);
622 /* note: bind RB to two attachment points */
623 _mesa_add_renderbuffer(&intel_fb
->Base
, BUFFER_DEPTH
,
624 &depthStencilRb
->Base
);
625 _mesa_add_renderbuffer(&intel_fb
->Base
, BUFFER_STENCIL
,
626 &depthStencilRb
->Base
);
628 struct intel_renderbuffer
*depthRb
629 = intel_create_renderbuffer(GL_DEPTH_COMPONENT24
,
630 screen
->width
, screen
->height
,
631 screen
->depth
.offset
,
633 screen
->cpp
, /* 4! */
635 intel_set_span_functions(&depthRb
->Base
);
636 _mesa_add_renderbuffer(&intel_fb
->Base
, BUFFER_DEPTH
,
640 else if (mesaVis
->depthBits
== 16) {
641 /* just 16-bit depth buffer, no hw stencil */
642 struct intel_renderbuffer
*depthRb
643 = intel_create_renderbuffer(GL_DEPTH_COMPONENT16
,
644 screen
->width
, screen
->height
,
645 screen
->depth
.offset
,
647 screen
->cpp
, /* 2! */
649 intel_set_span_functions(&depthRb
->Base
);
650 _mesa_add_renderbuffer(&intel_fb
->Base
, BUFFER_DEPTH
, &depthRb
->Base
);
653 /* now add any/all software-based renderbuffers we may need */
654 _mesa_add_soft_renderbuffers(&intel_fb
->Base
,
655 GL_FALSE
, /* never sw color */
656 GL_FALSE
, /* never sw depth */
657 swStencil
, mesaVis
->accumRedBits
> 0,
658 GL_FALSE
, /* never sw alpha */
659 GL_FALSE
/* never sw aux */ );
660 driDrawPriv
->driverPrivate
= (void *) intel_fb
;
667 intelDestroyBuffer(__DRIdrawablePrivate
* driDrawPriv
)
669 _mesa_unreference_framebuffer((GLframebuffer
**)(&(driDrawPriv
->driverPrivate
)));
674 * Get information about previous buffer swaps.
677 intelGetSwapInfo(__DRIdrawablePrivate
* dPriv
, __DRIswapInfo
* sInfo
)
679 struct intel_framebuffer
*intel_fb
;
681 if ((dPriv
== NULL
) || (dPriv
->driverPrivate
== NULL
)
682 || (sInfo
== NULL
)) {
686 intel_fb
= dPriv
->driverPrivate
;
687 sInfo
->swap_count
= intel_fb
->swap_count
;
688 sInfo
->swap_ust
= intel_fb
->swap_ust
;
689 sInfo
->swap_missed_count
= intel_fb
->swap_missed_count
;
691 sInfo
->swap_missed_usage
= (sInfo
->swap_missed_count
!= 0)
692 ? driCalculateSwapUsage(dPriv
, 0, intel_fb
->swap_missed_ust
)
699 /* There are probably better ways to do this, such as an
700 * init-designated function to register chipids and createcontext
703 extern GLboolean
i830CreateContext(const __GLcontextModes
* mesaVis
,
704 __DRIcontextPrivate
* driContextPriv
,
705 void *sharedContextPrivate
);
707 extern GLboolean
i915CreateContext(const __GLcontextModes
* mesaVis
,
708 __DRIcontextPrivate
* driContextPriv
,
709 void *sharedContextPrivate
);
715 intelCreateContext(const __GLcontextModes
* mesaVis
,
716 __DRIcontextPrivate
* driContextPriv
,
717 void *sharedContextPrivate
)
719 __DRIscreenPrivate
*sPriv
= driContextPriv
->driScreenPriv
;
720 intelScreenPrivate
*intelScreen
= (intelScreenPrivate
*) sPriv
->private;
722 switch (intelScreen
->deviceID
) {
723 /* Don't deal with i830 until texture work complete:
726 case PCI_CHIP_I830_M
:
727 case PCI_CHIP_I855_GM
:
728 case PCI_CHIP_I865_G
:
729 return i830CreateContext(mesaVis
, driContextPriv
, sharedContextPrivate
);
731 case PCI_CHIP_I915_G
:
732 case PCI_CHIP_I915_GM
:
733 case PCI_CHIP_I945_G
:
734 case PCI_CHIP_I945_GM
:
735 case PCI_CHIP_I945_GME
:
739 return i915CreateContext(mesaVis
, driContextPriv
, sharedContextPrivate
);
742 fprintf(stderr
, "Unrecognized deviceID %x\n", intelScreen
->deviceID
);
748 static const struct __DriverAPIRec intelAPI
= {
749 .DestroyScreen
= intelDestroyScreen
,
750 .CreateContext
= intelCreateContext
,
751 .DestroyContext
= intelDestroyContext
,
752 .CreateBuffer
= intelCreateBuffer
,
753 .DestroyBuffer
= intelDestroyBuffer
,
754 .SwapBuffers
= intelSwapBuffers
,
755 .MakeCurrent
= intelMakeCurrent
,
756 .UnbindContext
= intelUnbindContext
,
757 .GetSwapInfo
= intelGetSwapInfo
,
758 .GetMSC
= driGetMSC32
,
759 .GetDrawableMSC
= driDrawableGetMSC32
,
760 .WaitForMSC
= driWaitForMSC32
,
762 .SwapBuffersMSC
= NULL
,
763 .CopySubBuffer
= intelCopySubBuffer
,
764 .setTexOffset
= intelSetTexOffset
,
768 static __GLcontextModes
*
769 intelFillInModes(unsigned pixel_bits
, unsigned depth_bits
,
770 unsigned stencil_bits
, GLboolean have_back_buffer
)
772 __GLcontextModes
*modes
;
775 unsigned depth_buffer_factor
;
776 unsigned back_buffer_factor
;
780 /* GLX_SWAP_COPY_OML is only supported because the Intel driver doesn't
781 * support pageflipping at all.
783 static const GLenum back_buffer_modes
[] = {
784 GLX_NONE
, GLX_SWAP_UNDEFINED_OML
, GLX_SWAP_COPY_OML
787 u_int8_t depth_bits_array
[3];
788 u_int8_t stencil_bits_array
[3];
791 depth_bits_array
[0] = 0;
792 depth_bits_array
[1] = depth_bits
;
793 depth_bits_array
[2] = depth_bits
;
795 /* Just like with the accumulation buffer, always provide some modes
796 * with a stencil buffer. It will be a sw fallback, but some apps won't
799 stencil_bits_array
[0] = 0;
800 stencil_bits_array
[1] = 0;
801 if (depth_bits
== 24)
802 stencil_bits_array
[1] = (stencil_bits
== 0) ? 8 : stencil_bits
;
804 stencil_bits_array
[2] = (stencil_bits
== 0) ? 8 : stencil_bits
;
806 depth_buffer_factor
= ((depth_bits
!= 0) || (stencil_bits
!= 0)) ? 3 : 1;
807 back_buffer_factor
= (have_back_buffer
) ? 3 : 1;
809 num_modes
= depth_buffer_factor
* back_buffer_factor
* 4;
811 if (pixel_bits
== 16) {
813 fb_type
= GL_UNSIGNED_SHORT_5_6_5
;
817 fb_type
= GL_UNSIGNED_INT_8_8_8_8_REV
;
821 (*dri_interface
->createContextModes
) (num_modes
,
822 sizeof(__GLcontextModes
));
824 if (!driFillInModes(&m
, fb_format
, fb_type
,
825 depth_bits_array
, stencil_bits_array
,
826 depth_buffer_factor
, back_buffer_modes
,
827 back_buffer_factor
, GLX_TRUE_COLOR
)) {
828 fprintf(stderr
, "[%s:%u] Error creating FBConfig!\n", __func__
,
832 if (!driFillInModes(&m
, fb_format
, fb_type
,
833 depth_bits_array
, stencil_bits_array
,
834 depth_buffer_factor
, back_buffer_modes
,
835 back_buffer_factor
, GLX_DIRECT_COLOR
)) {
836 fprintf(stderr
, "[%s:%u] Error creating FBConfig!\n", __func__
,
841 /* Mark the visual as slow if there are "fake" stencil bits.
843 for (m
= modes
; m
!= NULL
; m
= m
->next
) {
844 if ((m
->stencilBits
!= 0) && (m
->stencilBits
!= stencil_bits
)) {
845 m
->visualRating
= GLX_SLOW_CONFIG
;
854 * This is the driver specific part of the createNewScreen entry point.
856 * \todo maybe fold this into intelInitDriver
858 * \return the __GLcontextModes supported by this driver
860 PUBLIC __GLcontextModes
*__driDriverInitScreen(__DRIscreenPrivate
*psp
)
862 static const __DRIversion ddx_expected
= { 1, 5, 0 };
863 static const __DRIversion dri_expected
= { 4, 0, 0 };
864 static const __DRIversion drm_expected
= { 1, 5, 0 };
865 I830DRIPtr dri_priv
= (I830DRIPtr
) psp
->pDevPriv
;
867 psp
->DriverAPI
= intelAPI
;
869 if (!driCheckDriDdxDrmVersions2("i915",
870 &psp
->dri_version
, &dri_expected
,
871 &psp
->ddx_version
, &ddx_expected
,
872 &psp
->drm_version
, &drm_expected
)) {
876 /* Calling driInitExtensions here, with a NULL context pointer,
877 * does not actually enable the extensions. It just makes sure
878 * that all the dispatch offsets for all the extensions that
879 * *might* be enables are known. This is needed because the
880 * dispatch offsets need to be known when _mesa_context_create is
881 * called, but we can't enable the extensions until we have a
884 * Hello chicken. Hello egg. How are you two today?
886 driInitExtensions(NULL
, card_extensions
, GL_FALSE
);
887 driInitExtensions(NULL
, ttm_extensions
, GL_FALSE
);
889 if (!intelInitDriver(psp
))
892 return intelFillInModes(dri_priv
->cpp
* 8,
893 (dri_priv
->cpp
== 2) ? 16 : 24,
894 (dri_priv
->cpp
== 2) ? 0 : 8, 1);
897 struct intel_context
*intelScreenContext(intelScreenPrivate
*intelScreen
)
900 * This should probably change to have the screen allocate a dummy
901 * context at screen creation. For now just use the current context.
904 GET_CURRENT_CONTEXT(ctx
);
906 _mesa_problem(NULL
, "No current context in intelScreenContext\n");
909 return intel_context(ctx
);