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 **************************************************************************/
28 #include "main/glheader.h"
29 #include "main/context.h"
30 #include "main/framebuffer.h"
31 #include "main/renderbuffer.h"
37 #include "intel_batchbuffer.h"
38 #include "intel_buffers.h"
39 #include "intel_bufmgr.h"
40 #include "intel_chipset.h"
41 #include "intel_extensions.h"
42 #include "intel_fbo.h"
43 #include "intel_regions.h"
44 #include "intel_swapbuffers.h"
45 #include "intel_screen.h"
46 #include "intel_span.h"
47 #include "intel_tex.h"
53 PUBLIC
const char __driConfigOptions
[] =
55 DRI_CONF_SECTION_PERFORMANCE
56 DRI_CONF_FTHROTTLE_MODE(DRI_CONF_FTHROTTLE_IRQS
)
57 DRI_CONF_VBLANK_MODE(DRI_CONF_VBLANK_ALWAYS_SYNC
)
58 /* Options correspond to DRI_CONF_BO_REUSE_DISABLED,
59 * DRI_CONF_BO_REUSE_ALL
61 DRI_CONF_OPT_BEGIN_V(bo_reuse
, enum, 1, "0:1")
62 DRI_CONF_DESC_BEGIN(en
, "Buffer object reuse")
63 DRI_CONF_ENUM(0, "Disable buffer object reuse")
64 DRI_CONF_ENUM(1, "Enable reuse of all sizes of buffer objects")
68 DRI_CONF_SECTION_QUALITY
69 DRI_CONF_FORCE_S3TC_ENABLE(false)
70 DRI_CONF_ALLOW_LARGE_TEXTURES(2)
72 DRI_CONF_SECTION_DEBUG
73 DRI_CONF_NO_RAST(false)
74 DRI_CONF_ALWAYS_FLUSH_BATCH(false)
75 DRI_CONF_ALWAYS_FLUSH_CACHE(false)
79 const GLuint __driNConfigOptions
= 8;
81 #ifdef USE_NEW_INTERFACE
82 static PFNGLXCREATECONTEXTMODES create_context_modes
= NULL
;
83 #endif /*USE_NEW_INTERFACE */
86 * Map all the memory regions described by the screen.
87 * \return GL_TRUE if success, GL_FALSE if error.
90 intelMapScreenRegions(__DRIscreenPrivate
* sPriv
)
92 intelScreenPrivate
*intelScreen
= (intelScreenPrivate
*) sPriv
->private;
95 _mesa_printf("TEX 0x%08x ", intelScreen
->tex
.handle
);
96 if (intelScreen
->tex
.size
!= 0) {
98 intelScreen
->tex
.handle
,
99 intelScreen
->tex
.size
,
100 (drmAddress
*) & intelScreen
->tex
.map
) != 0) {
101 intelUnmapScreenRegions(intelScreen
);
110 intelUnmapScreenRegions(intelScreenPrivate
* intelScreen
)
112 if (intelScreen
->tex
.map
) {
113 drmUnmap(intelScreen
->tex
.map
, intelScreen
->tex
.size
);
114 intelScreen
->tex
.map
= NULL
;
120 intelPrintDRIInfo(intelScreenPrivate
* intelScreen
,
121 __DRIscreenPrivate
* sPriv
, I830DRIPtr gDRIPriv
)
123 fprintf(stderr
, "*** Front size: 0x%x offset: 0x%x pitch: %d\n",
124 intelScreen
->front
.size
, intelScreen
->front
.offset
,
126 fprintf(stderr
, "*** Back size: 0x%x offset: 0x%x pitch: %d\n",
127 intelScreen
->back
.size
, intelScreen
->back
.offset
,
129 fprintf(stderr
, "*** Depth size: 0x%x offset: 0x%x pitch: %d\n",
130 intelScreen
->depth
.size
, intelScreen
->depth
.offset
,
132 fprintf(stderr
, "*** Texture size: 0x%x offset: 0x%x\n",
133 intelScreen
->tex
.size
, intelScreen
->tex
.offset
);
134 fprintf(stderr
, "*** Memory : 0x%x\n", gDRIPriv
->mem
);
139 intelPrintSAREA(const drm_i915_sarea_t
* sarea
)
141 fprintf(stderr
, "SAREA: sarea width %d height %d\n", sarea
->width
,
143 fprintf(stderr
, "SAREA: pitch: %d\n", sarea
->pitch
);
145 "SAREA: front offset: 0x%08x size: 0x%x handle: 0x%x tiled: %d\n",
146 sarea
->front_offset
, sarea
->front_size
,
147 (unsigned) sarea
->front_handle
, sarea
->front_tiled
);
149 "SAREA: back offset: 0x%08x size: 0x%x handle: 0x%x tiled: %d\n",
150 sarea
->back_offset
, sarea
->back_size
,
151 (unsigned) sarea
->back_handle
, sarea
->back_tiled
);
152 fprintf(stderr
, "SAREA: depth offset: 0x%08x size: 0x%x handle: 0x%x tiled: %d\n",
153 sarea
->depth_offset
, sarea
->depth_size
,
154 (unsigned) sarea
->depth_handle
, sarea
->depth_tiled
);
155 fprintf(stderr
, "SAREA: tex offset: 0x%08x size: 0x%x handle: 0x%x\n",
156 sarea
->tex_offset
, sarea
->tex_size
, (unsigned) sarea
->tex_handle
);
161 * A number of the screen parameters are obtained/computed from
162 * information in the SAREA. This function updates those parameters.
165 intelUpdateScreenFromSAREA(intelScreenPrivate
* intelScreen
,
166 drm_i915_sarea_t
* sarea
)
168 intelScreen
->width
= sarea
->width
;
169 intelScreen
->height
= sarea
->height
;
170 intelScreen
->pitch
= sarea
->pitch
;
172 intelScreen
->front
.offset
= sarea
->front_offset
;
173 intelScreen
->front
.handle
= sarea
->front_handle
;
174 intelScreen
->front
.size
= sarea
->front_size
;
175 intelScreen
->front
.tiled
= sarea
->front_tiled
;
177 intelScreen
->back
.offset
= sarea
->back_offset
;
178 intelScreen
->back
.handle
= sarea
->back_handle
;
179 intelScreen
->back
.size
= sarea
->back_size
;
180 intelScreen
->back
.tiled
= sarea
->back_tiled
;
182 intelScreen
->depth
.offset
= sarea
->depth_offset
;
183 intelScreen
->depth
.handle
= sarea
->depth_handle
;
184 intelScreen
->depth
.size
= sarea
->depth_size
;
185 intelScreen
->depth
.tiled
= sarea
->depth_tiled
;
187 if (intelScreen
->driScrnPriv
->ddx_version
.minor
>= 9) {
188 intelScreen
->front
.bo_handle
= sarea
->front_bo_handle
;
189 intelScreen
->back
.bo_handle
= sarea
->back_bo_handle
;
190 intelScreen
->depth
.bo_handle
= sarea
->depth_bo_handle
;
192 intelScreen
->front
.bo_handle
= -1;
193 intelScreen
->back
.bo_handle
= -1;
194 intelScreen
->depth
.bo_handle
= -1;
197 intelScreen
->tex
.offset
= sarea
->tex_offset
;
198 intelScreen
->logTextureGranularity
= sarea
->log_tex_granularity
;
199 intelScreen
->tex
.handle
= sarea
->tex_handle
;
200 intelScreen
->tex
.size
= sarea
->tex_size
;
203 intelPrintSAREA(sarea
);
206 static const __DRItexOffsetExtension intelTexOffsetExtension
= {
207 { __DRI_TEX_OFFSET
},
211 static const __DRItexBufferExtension intelTexBufferExtension
= {
212 { __DRI_TEX_BUFFER
, __DRI_TEX_BUFFER_VERSION
},
217 static const __DRIextension
*intelScreenExtensions
[] = {
218 &driReadDrawableExtension
,
219 &driCopySubBufferExtension
.base
,
220 &driSwapControlExtension
.base
,
221 &driFrameTrackingExtension
.base
,
222 &driMediaStreamCounterExtension
.base
,
223 &intelTexOffsetExtension
.base
,
224 &intelTexBufferExtension
.base
,
229 intel_get_param(__DRIscreenPrivate
*psp
, int param
, int *value
)
232 struct drm_i915_getparam gp
;
237 ret
= drmCommandWriteRead(psp
->fd
, DRM_I915_GETPARAM
, &gp
, sizeof(gp
));
239 fprintf(stderr
, "drm_i915_getparam: %d\n", ret
);
246 static GLboolean
intelInitDriver(__DRIscreenPrivate
*sPriv
)
248 intelScreenPrivate
*intelScreen
;
249 I830DRIPtr gDRIPriv
= (I830DRIPtr
) sPriv
->pDevPriv
;
250 drm_i915_sarea_t
*sarea
;
252 if (sPriv
->devPrivSize
!= sizeof(I830DRIRec
)) {
254 "\nERROR! sizeof(I830DRIRec) does not match passed size from device driver\n");
258 /* Allocate the private area */
259 intelScreen
= (intelScreenPrivate
*) CALLOC(sizeof(intelScreenPrivate
));
261 fprintf(stderr
, "\nERROR! Allocating private area failed\n");
264 /* parse information in __driConfigOptions */
265 driParseOptionInfo(&intelScreen
->optionCache
,
266 __driConfigOptions
, __driNConfigOptions
);
268 intelScreen
->driScrnPriv
= sPriv
;
269 sPriv
->private = (void *) intelScreen
;
270 sarea
= (drm_i915_sarea_t
*)
271 (((GLubyte
*) sPriv
->pSAREA
) + gDRIPriv
->sarea_priv_offset
);
272 intelScreen
->sarea
= sarea
;
274 intelScreen
->deviceID
= gDRIPriv
->deviceID
;
276 intelUpdateScreenFromSAREA(intelScreen
, sarea
);
278 if (!intelMapScreenRegions(sPriv
)) {
279 fprintf(stderr
, "\nERROR! mapping regions\n");
280 _mesa_free(intelScreen
);
281 sPriv
->private = NULL
;
286 intelPrintDRIInfo(intelScreen
, sPriv
, gDRIPriv
);
288 intelScreen
->drmMinor
= sPriv
->drm_version
.minor
;
290 /* Determine if IRQs are active? */
291 if (!intel_get_param(sPriv
, I915_PARAM_IRQ_ACTIVE
,
292 &intelScreen
->irq_active
))
295 sPriv
->extensions
= intelScreenExtensions
;
302 intelDestroyScreen(__DRIscreenPrivate
* sPriv
)
304 intelScreenPrivate
*intelScreen
= (intelScreenPrivate
*) sPriv
->private;
306 dri_bufmgr_destroy(intelScreen
->bufmgr
);
307 intelUnmapScreenRegions(intelScreen
);
308 driDestroyOptionCache(&intelScreen
->optionCache
);
311 sPriv
->private = NULL
;
316 * This is called when we need to set up GL rendering to a new X window.
319 intelCreateBuffer(__DRIscreenPrivate
* driScrnPriv
,
320 __DRIdrawablePrivate
* driDrawPriv
,
321 const __GLcontextModes
* mesaVis
, GLboolean isPixmap
)
324 return GL_FALSE
; /* not implemented */
327 GLboolean swStencil
= (mesaVis
->stencilBits
> 0 &&
328 mesaVis
->depthBits
!= 24);
331 struct intel_framebuffer
*intel_fb
= CALLOC_STRUCT(intel_framebuffer
);
336 _mesa_initialize_framebuffer(&intel_fb
->Base
, mesaVis
);
338 if (mesaVis
->redBits
== 5)
340 else if (mesaVis
->alphaBits
== 0)
343 rgbFormat
= GL_RGBA8
;
345 /* setup the hardware-based renderbuffers */
346 intel_fb
->color_rb
[0] = intel_create_renderbuffer(rgbFormat
);
347 _mesa_add_renderbuffer(&intel_fb
->Base
, BUFFER_FRONT_LEFT
,
348 &intel_fb
->color_rb
[0]->Base
);
350 if (mesaVis
->doubleBufferMode
) {
351 intel_fb
->color_rb
[1] = intel_create_renderbuffer(rgbFormat
);
353 _mesa_add_renderbuffer(&intel_fb
->Base
, BUFFER_BACK_LEFT
,
354 &intel_fb
->color_rb
[1]->Base
);
358 if (mesaVis
->depthBits
== 24) {
359 if (mesaVis
->stencilBits
== 8) {
360 /* combined depth/stencil buffer */
361 struct intel_renderbuffer
*depthStencilRb
362 = intel_create_renderbuffer(GL_DEPTH24_STENCIL8_EXT
);
363 /* note: bind RB to two attachment points */
364 _mesa_add_renderbuffer(&intel_fb
->Base
, BUFFER_DEPTH
,
365 &depthStencilRb
->Base
);
366 _mesa_add_renderbuffer(&intel_fb
->Base
, BUFFER_STENCIL
,
367 &depthStencilRb
->Base
);
369 struct intel_renderbuffer
*depthRb
370 = intel_create_renderbuffer(GL_DEPTH_COMPONENT24
);
371 _mesa_add_renderbuffer(&intel_fb
->Base
, BUFFER_DEPTH
,
375 else if (mesaVis
->depthBits
== 16) {
376 /* just 16-bit depth buffer, no hw stencil */
377 struct intel_renderbuffer
*depthRb
378 = intel_create_renderbuffer(GL_DEPTH_COMPONENT16
);
379 _mesa_add_renderbuffer(&intel_fb
->Base
, BUFFER_DEPTH
, &depthRb
->Base
);
382 /* now add any/all software-based renderbuffers we may need */
383 _mesa_add_soft_renderbuffers(&intel_fb
->Base
,
384 GL_FALSE
, /* never sw color */
385 GL_FALSE
, /* never sw depth */
386 swStencil
, mesaVis
->accumRedBits
> 0,
387 GL_FALSE
, /* never sw alpha */
388 GL_FALSE
/* never sw aux */ );
389 driDrawPriv
->driverPrivate
= (void *) intel_fb
;
396 intelDestroyBuffer(__DRIdrawablePrivate
* driDrawPriv
)
398 struct intel_framebuffer
*intel_fb
= driDrawPriv
->driverPrivate
;
399 struct intel_renderbuffer
*depth_rb
;
400 struct intel_renderbuffer
*stencil_rb
;
403 if (intel_fb
->color_rb
[0]) {
404 intel_renderbuffer_set_region(intel_fb
->color_rb
[0], NULL
);
407 if (intel_fb
->color_rb
[1]) {
408 intel_renderbuffer_set_region(intel_fb
->color_rb
[1], NULL
);
411 depth_rb
= intel_get_renderbuffer(&intel_fb
->Base
, BUFFER_DEPTH
);
413 intel_renderbuffer_set_region(depth_rb
, NULL
);
416 stencil_rb
= intel_get_renderbuffer(&intel_fb
->Base
, BUFFER_STENCIL
);
418 intel_renderbuffer_set_region(stencil_rb
, NULL
);
422 _mesa_reference_framebuffer((GLframebuffer
**)(&(driDrawPriv
->driverPrivate
)), NULL
);
427 * Get information about previous buffer swaps.
430 intelGetSwapInfo(__DRIdrawablePrivate
* dPriv
, __DRIswapInfo
* sInfo
)
432 struct intel_framebuffer
*intel_fb
;
434 if ((dPriv
== NULL
) || (dPriv
->driverPrivate
== NULL
)
435 || (sInfo
== NULL
)) {
439 intel_fb
= dPriv
->driverPrivate
;
440 sInfo
->swap_count
= intel_fb
->swap_count
;
441 sInfo
->swap_ust
= intel_fb
->swap_ust
;
442 sInfo
->swap_missed_count
= intel_fb
->swap_missed_count
;
444 sInfo
->swap_missed_usage
= (sInfo
->swap_missed_count
!= 0)
445 ? driCalculateSwapUsage(dPriv
, 0, intel_fb
->swap_missed_ust
)
452 /* There are probably better ways to do this, such as an
453 * init-designated function to register chipids and createcontext
456 extern GLboolean
i830CreateContext(const __GLcontextModes
* mesaVis
,
457 __DRIcontextPrivate
* driContextPriv
,
458 void *sharedContextPrivate
);
460 extern GLboolean
i915CreateContext(const __GLcontextModes
* mesaVis
,
461 __DRIcontextPrivate
* driContextPriv
,
462 void *sharedContextPrivate
);
463 extern GLboolean
brwCreateContext(const __GLcontextModes
* mesaVis
,
464 __DRIcontextPrivate
* driContextPriv
,
465 void *sharedContextPrivate
);
468 intelCreateContext(const __GLcontextModes
* mesaVis
,
469 __DRIcontextPrivate
* driContextPriv
,
470 void *sharedContextPrivate
)
472 __DRIscreenPrivate
*sPriv
= driContextPriv
->driScreenPriv
;
473 intelScreenPrivate
*intelScreen
= (intelScreenPrivate
*) sPriv
->private;
476 if (IS_9XX(intelScreen
->deviceID
)) {
477 if (!IS_965(intelScreen
->deviceID
)) {
478 return i915CreateContext(mesaVis
, driContextPriv
,
479 sharedContextPrivate
);
482 intelScreen
->no_vbo
= GL_TRUE
;
483 return i830CreateContext(mesaVis
, driContextPriv
, sharedContextPrivate
);
486 if (IS_965(intelScreen
->deviceID
))
487 return brwCreateContext(mesaVis
, driContextPriv
, sharedContextPrivate
);
489 fprintf(stderr
, "Unrecognized deviceID %x\n", intelScreen
->deviceID
);
494 static __DRIconfig
**
495 intelFillInModes(__DRIscreenPrivate
*psp
,
496 unsigned pixel_bits
, unsigned depth_bits
,
497 unsigned stencil_bits
, GLboolean have_back_buffer
)
499 __DRIconfig
**configs
;
501 unsigned depth_buffer_factor
;
502 unsigned back_buffer_factor
;
505 /* GLX_SWAP_COPY_OML is only supported because the Intel driver doesn't
506 * support pageflipping at all.
508 static const GLenum back_buffer_modes
[] = {
509 GLX_NONE
, GLX_SWAP_UNDEFINED_OML
, GLX_SWAP_COPY_OML
512 uint8_t depth_bits_array
[3];
513 uint8_t stencil_bits_array
[3];
514 uint8_t msaa_samples_array
[1];
516 depth_bits_array
[0] = 0;
517 depth_bits_array
[1] = depth_bits
;
518 depth_bits_array
[2] = depth_bits
;
520 /* Just like with the accumulation buffer, always provide some modes
521 * with a stencil buffer. It will be a sw fallback, but some apps won't
524 stencil_bits_array
[0] = 0;
525 stencil_bits_array
[1] = 0;
526 if (depth_bits
== 24)
527 stencil_bits_array
[1] = (stencil_bits
== 0) ? 8 : stencil_bits
;
529 stencil_bits_array
[2] = (stencil_bits
== 0) ? 8 : stencil_bits
;
531 msaa_samples_array
[0] = 0;
533 depth_buffer_factor
= ((depth_bits
!= 0) || (stencil_bits
!= 0)) ? 3 : 1;
534 back_buffer_factor
= (have_back_buffer
) ? 3 : 1;
536 if (pixel_bits
== 16) {
537 configs
= driCreateConfigs(GL_RGB
, GL_UNSIGNED_SHORT_5_6_5
,
538 depth_bits_array
, stencil_bits_array
,
539 depth_buffer_factor
, back_buffer_modes
,
541 msaa_samples_array
, 1);
544 __DRIconfig
**configs_a8r8g8b8
;
545 __DRIconfig
**configs_x8r8g8b8
;
547 configs_a8r8g8b8
= driCreateConfigs(GL_BGRA
, GL_UNSIGNED_INT_8_8_8_8_REV
,
553 msaa_samples_array
, 1);
554 configs_x8r8g8b8
= driCreateConfigs(GL_BGR
, GL_UNSIGNED_INT_8_8_8_8_REV
,
560 msaa_samples_array
, 1);
561 configs
= driConcatConfigs(configs_a8r8g8b8
, configs_x8r8g8b8
);
564 if (configs
== NULL
) {
565 fprintf(stderr
, "[%s:%u] Error creating FBConfig!\n", __func__
,
570 /* Mark the visual as slow if there are "fake" stencil bits.
572 for (i
= 0; configs
[i
]; i
++) {
573 m
= &configs
[i
]->modes
;
574 if ((m
->stencilBits
!= 0) && (m
->stencilBits
!= stencil_bits
)) {
575 m
->visualRating
= GLX_SLOW_CONFIG
;
583 intel_init_bufmgr(intelScreenPrivate
*intelScreen
)
585 GLboolean gem_disable
= getenv("INTEL_NO_GEM") != NULL
;
587 GLboolean gem_supported
;
588 struct drm_i915_getparam gp
;
589 __DRIscreenPrivate
*spriv
= intelScreen
->driScrnPriv
;
592 intelScreen
->no_hw
= getenv("INTEL_NO_HW") != NULL
;
594 gp
.param
= I915_PARAM_HAS_GEM
;
595 gp
.value
= &gem_kernel
;
597 (void) drmCommandWriteRead(spriv
->fd
, DRM_I915_GETPARAM
, &gp
, sizeof(gp
));
599 /* If we've got a new enough DDX that's initializing GEM and giving us
600 * object handles for the shared buffers, use that.
602 intelScreen
->ttm
= GL_FALSE
;
603 if (intelScreen
->driScrnPriv
->dri2
.enabled
)
604 gem_supported
= GL_TRUE
;
605 else if (intelScreen
->driScrnPriv
->ddx_version
.minor
>= 9 &&
607 intelScreen
->front
.bo_handle
!= -1)
608 gem_supported
= GL_TRUE
;
610 gem_supported
= GL_FALSE
;
612 if (!gem_disable
&& gem_supported
) {
613 intelScreen
->bufmgr
= intel_bufmgr_gem_init(spriv
->fd
, BATCH_SZ
);
614 if (intelScreen
->bufmgr
!= NULL
)
615 intelScreen
->ttm
= GL_TRUE
;
617 /* Otherwise, use the classic buffer manager. */
618 if (intelScreen
->bufmgr
== NULL
) {
620 fprintf(stderr
, "GEM disabled. Using classic.\n");
622 fprintf(stderr
, "Failed to initialize GEM. "
623 "Falling back to classic.\n");
626 if (intelScreen
->tex
.size
== 0) {
627 fprintf(stderr
, "[%s:%u] Error initializing buffer manager.\n",
632 intelScreen
->bufmgr
=
633 intel_bufmgr_fake_init(spriv
->fd
,
634 intelScreen
->tex
.offset
,
635 intelScreen
->tex
.map
,
636 intelScreen
->tex
.size
,
637 (unsigned int * volatile)
638 &intelScreen
->sarea
->last_dispatch
);
641 if (intel_get_param(spriv
, I915_PARAM_NUM_FENCES_AVAIL
, &num_fences
))
642 intelScreen
->kernel_exec_fencing
= !!num_fences
;
644 intelScreen
->kernel_exec_fencing
= GL_FALSE
;
650 * This is the driver specific part of the createNewScreen entry point.
651 * Called when using legacy DRI.
653 * \todo maybe fold this into intelInitDriver
655 * \return the __GLcontextModes supported by this driver
657 static const __DRIconfig
**intelInitScreen(__DRIscreenPrivate
*psp
)
659 intelScreenPrivate
*intelScreen
;
661 static const __DRIversion ddx_expected
= { 1, 5, 0 };
663 static const __DRIversion ddx_expected
= { 1, 6, 0 };
665 static const __DRIversion dri_expected
= { 4, 0, 0 };
666 static const __DRIversion drm_expected
= { 1, 5, 0 };
667 I830DRIPtr dri_priv
= (I830DRIPtr
) psp
->pDevPriv
;
669 if (!driCheckDriDdxDrmVersions2("i915",
670 &psp
->dri_version
, &dri_expected
,
671 &psp
->ddx_version
, &ddx_expected
,
672 &psp
->drm_version
, &drm_expected
)) {
676 /* Calling driInitExtensions here, with a NULL context pointer,
677 * does not actually enable the extensions. It just makes sure
678 * that all the dispatch offsets for all the extensions that
679 * *might* be enables are known. This is needed because the
680 * dispatch offsets need to be known when _mesa_context_create is
681 * called, but we can't enable the extensions until we have a
684 * Hello chicken. Hello egg. How are you two today?
686 intelInitExtensions(NULL
, GL_TRUE
);
688 if (!intelInitDriver(psp
))
691 psp
->extensions
= intelScreenExtensions
;
693 intelScreen
= psp
->private;
694 if (!intel_init_bufmgr(intelScreen
))
697 return (const __DRIconfig
**)
698 intelFillInModes(psp
, dri_priv
->cpp
* 8,
699 (dri_priv
->cpp
== 2) ? 16 : 24,
700 (dri_priv
->cpp
== 2) ? 0 : 8, 1);
703 struct intel_context
*intelScreenContext(intelScreenPrivate
*intelScreen
)
706 * This should probably change to have the screen allocate a dummy
707 * context at screen creation. For now just use the current context.
710 GET_CURRENT_CONTEXT(ctx
);
712 _mesa_problem(NULL
, "No current context in intelScreenContext\n");
715 return intel_context(ctx
);
719 * This is the driver specific part of the createNewScreen entry point.
720 * Called when using DRI2.
722 * \return the __GLcontextModes supported by this driver
725 __DRIconfig
**intelInitScreen2(__DRIscreenPrivate
*psp
)
727 intelScreenPrivate
*intelScreen
;
730 /* GLX_SWAP_COPY_OML is only supported because the Intel driver doesn't
731 * support pageflipping at all.
733 static const GLenum back_buffer_modes
[] = {
734 GLX_NONE
, GLX_SWAP_UNDEFINED_OML
, GLX_SWAP_COPY_OML
736 uint8_t depth_bits
[4], stencil_bits
[4], msaa_samples_array
[1];
738 __DRIconfig
**configs
= NULL
;
740 /* Calling driInitExtensions here, with a NULL context pointer,
741 * does not actually enable the extensions. It just makes sure
742 * that all the dispatch offsets for all the extensions that
743 * *might* be enables are known. This is needed because the
744 * dispatch offsets need to be known when _mesa_context_create is
745 * called, but we can't enable the extensions until we have a
748 * Hello chicken. Hello egg. How are you two today?
750 intelInitExtensions(NULL
, GL_TRUE
);
752 /* Allocate the private area */
753 intelScreen
= (intelScreenPrivate
*) CALLOC(sizeof(intelScreenPrivate
));
755 fprintf(stderr
, "\nERROR! Allocating private area failed\n");
758 /* parse information in __driConfigOptions */
759 driParseOptionInfo(&intelScreen
->optionCache
,
760 __driConfigOptions
, __driNConfigOptions
);
762 intelScreen
->driScrnPriv
= psp
;
763 psp
->private = (void *) intelScreen
;
765 intelScreen
->drmMinor
= psp
->drm_version
.minor
;
767 /* Determine chipset ID */
768 if (!intel_get_param(psp
, I915_PARAM_CHIPSET_ID
,
769 &intelScreen
->deviceID
))
772 if (!intel_init_bufmgr(intelScreen
))
775 intelScreen
->irq_active
= 1;
776 psp
->extensions
= intelScreenExtensions
;
787 msaa_samples_array
[0] = 0;
789 fb_format
[0] = GL_RGB
;
790 fb_type
[0] = GL_UNSIGNED_SHORT_5_6_5
;
792 fb_format
[1] = GL_BGR
;
793 fb_type
[1] = GL_UNSIGNED_INT_8_8_8_8_REV
;
795 fb_format
[2] = GL_BGRA
;
796 fb_type
[2] = GL_UNSIGNED_INT_8_8_8_8_REV
;
801 for (color
= 0; color
< ARRAY_SIZE(fb_format
); color
++) {
802 __DRIconfig
**new_configs
;
805 /* With DRI2 right now, GetBuffers always returns a depth/stencil buffer
806 * with the same cpp as the drawable. So we can't support depth cpp !=
807 * color cpp currently.
809 if (fb_type
[color
] == GL_UNSIGNED_SHORT_5_6_5
) {
822 new_configs
= driCreateConfigs(fb_format
[color
], fb_type
[color
],
827 ARRAY_SIZE(back_buffer_modes
),
829 ARRAY_SIZE(msaa_samples_array
));
831 configs
= new_configs
;
833 configs
= driConcatConfigs(configs
, new_configs
);
836 if (configs
== NULL
) {
837 fprintf(stderr
, "[%s:%u] Error creating FBConfig!\n", __func__
,
842 return (const __DRIconfig
**)configs
;
845 const struct __DriverAPIRec driDriverAPI
= {
846 .InitScreen
= intelInitScreen
,
847 .DestroyScreen
= intelDestroyScreen
,
848 .CreateContext
= intelCreateContext
,
849 .DestroyContext
= intelDestroyContext
,
850 .CreateBuffer
= intelCreateBuffer
,
851 .DestroyBuffer
= intelDestroyBuffer
,
852 .SwapBuffers
= intelSwapBuffers
,
853 .MakeCurrent
= intelMakeCurrent
,
854 .UnbindContext
= intelUnbindContext
,
855 .GetSwapInfo
= intelGetSwapInfo
,
856 .GetDrawableMSC
= driDrawableGetMSC32
,
857 .WaitForMSC
= driWaitForMSC32
,
858 .CopySubBuffer
= intelCopySubBuffer
,
860 .InitScreen2
= intelInitScreen2
,