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"
38 #include "intel_screen.h"
40 #include "intel_tex.h"
41 #include "intel_span.h"
42 #include "intel_tris.h"
43 #include "intel_ioctl.h"
49 PUBLIC
const char __driConfigOptions
[] =
51 DRI_CONF_SECTION_PERFORMANCE
52 DRI_CONF_FORCE_S3TC_ENABLE(false)
55 const GLuint __driNConfigOptions
= 1;
57 extern const struct dri_extension card_extensions
[];
59 static void intelPrintDRIInfo(intelScreenPrivate
*intelScreen
,
60 __DRIscreenPrivate
*sPriv
,
63 fprintf(stderr
, "Front size : 0x%x\n", sPriv
->fbSize
);
64 fprintf(stderr
, "Front offset : 0x%x\n", intelScreen
->frontOffset
);
65 fprintf(stderr
, "Back size : 0x%x\n", intelScreen
->back
.size
);
66 fprintf(stderr
, "Back offset : 0x%x\n", intelScreen
->backOffset
);
67 fprintf(stderr
, "Depth size : 0x%x\n", intelScreen
->depth
.size
);
68 fprintf(stderr
, "Depth offset : 0x%x\n", intelScreen
->depthOffset
);
69 fprintf(stderr
, "Texture size : 0x%x\n", intelScreen
->textureSize
);
70 fprintf(stderr
, "Texture offset : 0x%x\n", intelScreen
->textureOffset
);
71 fprintf(stderr
, "Memory : 0x%x\n", gDRIPriv
->mem
);
74 static GLboolean
intelInitDriver(__DRIscreenPrivate
*sPriv
)
76 intelScreenPrivate
*intelScreen
;
77 I830DRIPtr gDRIPriv
= (I830DRIPtr
)sPriv
->pDevPriv
;
78 PFNGLXSCRENABLEEXTENSIONPROC glx_enable_extension
=
79 (PFNGLXSCRENABLEEXTENSIONPROC
) (*dri_interface
->getProcAddress("glxEnableExtension"));
80 void * const psc
= sPriv
->psc
->screenConfigs
;
82 if (sPriv
->devPrivSize
!= sizeof(I830DRIRec
)) {
83 fprintf(stderr
,"\nERROR! sizeof(I830DRIRec) does not match passed size from device driver\n");
87 /* Allocate the private area */
88 intelScreen
= (intelScreenPrivate
*)CALLOC(sizeof(intelScreenPrivate
));
90 fprintf(stderr
,"\nERROR! Allocating private area failed\n");
93 /* parse information in __driConfigOptions */
94 driParseOptionInfo (&intelScreen
->optionCache
,
95 __driConfigOptions
, __driNConfigOptions
);
97 intelScreen
->driScrnPriv
= sPriv
;
98 sPriv
->private = (void *)intelScreen
;
100 intelScreen
->deviceID
= gDRIPriv
->deviceID
;
101 intelScreen
->width
= gDRIPriv
->width
;
102 intelScreen
->height
= gDRIPriv
->height
;
103 intelScreen
->mem
= gDRIPriv
->mem
;
104 intelScreen
->cpp
= gDRIPriv
->cpp
;
105 intelScreen
->frontPitch
= gDRIPriv
->fbStride
;
106 intelScreen
->frontOffset
= gDRIPriv
->fbOffset
;
108 switch (gDRIPriv
->bitsPerPixel
) {
109 case 15: intelScreen
->fbFormat
= DV_PF_555
; break;
110 case 16: intelScreen
->fbFormat
= DV_PF_565
; break;
111 case 32: intelScreen
->fbFormat
= DV_PF_8888
; break;
114 intelScreen
->backOffset
= gDRIPriv
->backOffset
;
115 intelScreen
->backPitch
= gDRIPriv
->backPitch
;
116 intelScreen
->depthOffset
= gDRIPriv
->depthOffset
;
117 intelScreen
->depthPitch
= gDRIPriv
->depthPitch
;
118 intelScreen
->textureOffset
= gDRIPriv
->textureOffset
;
119 intelScreen
->textureSize
= gDRIPriv
->textureSize
;
120 intelScreen
->logTextureGranularity
= gDRIPriv
->logTextureGranularity
;
121 intelScreen
->back
.handle
= gDRIPriv
->backbuffer
;
122 intelScreen
->back
.size
= gDRIPriv
->backbufferSize
;
124 if (drmMap(sPriv
->fd
,
125 intelScreen
->back
.handle
,
126 intelScreen
->back
.size
,
127 (drmAddress
*)&intelScreen
->back
.map
) != 0) {
128 fprintf(stderr
, "\nERROR: line %d, Function %s, File %s\n",
129 __LINE__
, __FUNCTION__
, __FILE__
);
131 sPriv
->private = NULL
;
135 intelScreen
->depth
.handle
= gDRIPriv
->depthbuffer
;
136 intelScreen
->depth
.size
= gDRIPriv
->depthbufferSize
;
138 if (drmMap(sPriv
->fd
,
139 intelScreen
->depth
.handle
,
140 intelScreen
->depth
.size
,
141 (drmAddress
*)&intelScreen
->depth
.map
) != 0) {
142 fprintf(stderr
, "\nERROR: line %d, Function %s, File %s\n",
143 __LINE__
, __FUNCTION__
, __FILE__
);
145 drmUnmap(intelScreen
->back
.map
, intelScreen
->back
.size
);
146 sPriv
->private = NULL
;
150 intelScreen
->tex
.handle
= gDRIPriv
->textures
;
151 intelScreen
->tex
.size
= gDRIPriv
->textureSize
;
153 if (drmMap(sPriv
->fd
,
154 intelScreen
->tex
.handle
,
155 intelScreen
->tex
.size
,
156 (drmAddress
*)&intelScreen
->tex
.map
) != 0) {
157 fprintf(stderr
, "\nERROR: line %d, Function %s, File %s\n",
158 __LINE__
, __FUNCTION__
, __FILE__
);
160 drmUnmap(intelScreen
->back
.map
, intelScreen
->back
.size
);
161 drmUnmap(intelScreen
->depth
.map
, intelScreen
->depth
.size
);
162 sPriv
->private = NULL
;
166 intelScreen
->sarea_priv_offset
= gDRIPriv
->sarea_priv_offset
;
168 if (0) intelPrintDRIInfo(intelScreen
, sPriv
, gDRIPriv
);
170 intelScreen
->drmMinor
= sPriv
->drmMinor
;
176 gp
.param
= I830_PARAM_IRQ_ACTIVE
;
177 gp
.value
= &intelScreen
->irq_active
;
179 ret
= drmCommandWriteRead( sPriv
->fd
, DRM_I830_GETPARAM
,
182 fprintf(stderr
, "drmI830GetParam: %d\n", ret
);
191 gp
.param
= I830_PARAM_ALLOW_BATCHBUFFER
;
192 gp
.value
= &intelScreen
->allow_batchbuffer
;
194 ret
= drmCommandWriteRead( sPriv
->fd
, DRM_I830_GETPARAM
,
197 fprintf(stderr
, "drmI830GetParam: (%d) %d\n", gp
.param
, ret
);
202 if (glx_enable_extension
!= NULL
) {
203 (*glx_enable_extension
)( psc
, "GLX_SGI_make_current_read" );
204 (*glx_enable_extension
)( psc
, "GLX_MESA_allocate_memory" );
207 sPriv
->psc
->allocateMemory
= (void *) intelAllocateMemoryMESA
;
208 sPriv
->psc
->freeMemory
= (void *) intelFreeMemoryMESA
;
209 sPriv
->psc
->memoryOffset
= (void *) intelGetMemoryOffsetMESA
;
215 static void intelDestroyScreen(__DRIscreenPrivate
*sPriv
)
217 intelScreenPrivate
*intelScreen
= (intelScreenPrivate
*)sPriv
->private;
219 /* Need to unmap all the bufs and maps here:
221 drmUnmap(intelScreen
->back
.map
, intelScreen
->back
.size
);
222 drmUnmap(intelScreen
->depth
.map
, intelScreen
->depth
.size
);
223 drmUnmap(intelScreen
->tex
.map
, intelScreen
->tex
.size
);
225 sPriv
->private = NULL
;
229 static GLboolean
intelCreateBuffer( __DRIscreenPrivate
*driScrnPriv
,
230 __DRIdrawablePrivate
*driDrawPriv
,
231 const __GLcontextModes
*mesaVis
,
234 intelScreenPrivate
*screen
= (intelScreenPrivate
*) driScrnPriv
->private;
237 return GL_FALSE
; /* not implemented */
239 GLboolean swStencil
= (mesaVis
->stencilBits
> 0 &&
240 mesaVis
->depthBits
!= 24);
242 struct gl_framebuffer
*fb
= _mesa_create_framebuffer(mesaVis
);
245 driRenderbuffer
*frontRb
246 = driNewRenderbuffer(GL_RGBA
,
249 screen
->frontOffset
, screen
->frontPitch
,
251 intelSetSpanFunctions(frontRb
, mesaVis
);
252 _mesa_add_renderbuffer(fb
, BUFFER_FRONT_LEFT
, &frontRb
->Base
);
255 if (mesaVis
->doubleBufferMode
) {
256 driRenderbuffer
*backRb
257 = driNewRenderbuffer(GL_RGBA
,
260 screen
->backOffset
, screen
->backPitch
,
262 intelSetSpanFunctions(backRb
, mesaVis
);
263 _mesa_add_renderbuffer(fb
, BUFFER_BACK_LEFT
, &backRb
->Base
);
266 if (mesaVis
->depthBits
== 16) {
267 driRenderbuffer
*depthRb
268 = driNewRenderbuffer(GL_DEPTH_COMPONENT16
,
271 screen
->depthOffset
, screen
->depthPitch
,
273 intelSetSpanFunctions(depthRb
, mesaVis
);
274 _mesa_add_renderbuffer(fb
, BUFFER_DEPTH
, &depthRb
->Base
);
276 else if (mesaVis
->depthBits
== 24) {
277 driRenderbuffer
*depthRb
278 = driNewRenderbuffer(GL_DEPTH_COMPONENT24
,
281 screen
->depthOffset
, screen
->depthPitch
,
283 intelSetSpanFunctions(depthRb
, mesaVis
);
284 _mesa_add_renderbuffer(fb
, BUFFER_DEPTH
, &depthRb
->Base
);
287 if (mesaVis
->stencilBits
> 0 && !swStencil
) {
288 driRenderbuffer
*stencilRb
289 = driNewRenderbuffer(GL_STENCIL_INDEX8_EXT
,
292 screen
->depthOffset
, screen
->depthPitch
,
294 intelSetSpanFunctions(stencilRb
, mesaVis
);
295 _mesa_add_renderbuffer(fb
, BUFFER_STENCIL
, &stencilRb
->Base
);
298 _mesa_add_soft_renderbuffers(fb
,
299 GL_FALSE
, /* color */
300 GL_FALSE
, /* depth */
302 mesaVis
->accumRedBits
> 0,
303 GL_FALSE
, /* alpha */
305 driDrawPriv
->driverPrivate
= (void *) fb
;
307 return (driDrawPriv
->driverPrivate
!= NULL
);
311 static void intelDestroyBuffer(__DRIdrawablePrivate
*driDrawPriv
)
313 _mesa_destroy_framebuffer((GLframebuffer
*) (driDrawPriv
->driverPrivate
));
317 /* There are probably better ways to do this, such as an
318 * init-designated function to register chipids and createcontext
321 extern GLboolean
i830CreateContext( const __GLcontextModes
*mesaVis
,
322 __DRIcontextPrivate
*driContextPriv
,
323 void *sharedContextPrivate
);
325 extern GLboolean
i915CreateContext( const __GLcontextModes
*mesaVis
,
326 __DRIcontextPrivate
*driContextPriv
,
327 void *sharedContextPrivate
);
332 static GLboolean
intelCreateContext( const __GLcontextModes
*mesaVis
,
333 __DRIcontextPrivate
*driContextPriv
,
334 void *sharedContextPrivate
)
336 __DRIscreenPrivate
*sPriv
= driContextPriv
->driScreenPriv
;
337 intelScreenPrivate
*intelScreen
= (intelScreenPrivate
*)sPriv
->private;
339 switch (intelScreen
->deviceID
) {
341 case PCI_CHIP_I830_M
:
342 case PCI_CHIP_I855_GM
:
343 case PCI_CHIP_I865_G
:
344 return i830CreateContext( mesaVis
, driContextPriv
,
345 sharedContextPrivate
);
347 case PCI_CHIP_I915_G
:
348 case PCI_CHIP_I915_GM
:
349 case PCI_CHIP_I945_G
:
350 return i915CreateContext( mesaVis
, driContextPriv
,
351 sharedContextPrivate
);
354 fprintf(stderr
, "Unrecognized deviceID %x\n", intelScreen
->deviceID
);
360 static const struct __DriverAPIRec intelAPI
= {
361 .InitDriver
= intelInitDriver
,
362 .DestroyScreen
= intelDestroyScreen
,
363 .CreateContext
= intelCreateContext
,
364 .DestroyContext
= intelDestroyContext
,
365 .CreateBuffer
= intelCreateBuffer
,
366 .DestroyBuffer
= intelDestroyBuffer
,
367 .SwapBuffers
= intelSwapBuffers
,
368 .MakeCurrent
= intelMakeCurrent
,
369 .UnbindContext
= intelUnbindContext
,
374 .SwapBuffersMSC
= NULL
378 static __GLcontextModes
*
379 intelFillInModes( unsigned pixel_bits
, unsigned depth_bits
,
380 unsigned stencil_bits
, GLboolean have_back_buffer
)
382 __GLcontextModes
* modes
;
383 __GLcontextModes
* m
;
385 unsigned depth_buffer_factor
;
386 unsigned back_buffer_factor
;
390 /* GLX_SWAP_COPY_OML is only supported because the Intel driver doesn't
391 * support pageflipping at all.
393 static const GLenum back_buffer_modes
[] = {
394 GLX_NONE
, GLX_SWAP_UNDEFINED_OML
, GLX_SWAP_COPY_OML
397 u_int8_t depth_bits_array
[3];
398 u_int8_t stencil_bits_array
[3];
401 depth_bits_array
[0] = 0;
402 depth_bits_array
[1] = depth_bits
;
403 depth_bits_array
[2] = depth_bits
;
405 /* Just like with the accumulation buffer, always provide some modes
406 * with a stencil buffer. It will be a sw fallback, but some apps won't
409 stencil_bits_array
[0] = 0;
410 stencil_bits_array
[1] = 0;
411 stencil_bits_array
[2] = (stencil_bits
== 0) ? 8 : stencil_bits
;
413 depth_buffer_factor
= ((depth_bits
!= 0) || (stencil_bits
!= 0)) ? 3 : 1;
414 back_buffer_factor
= (have_back_buffer
) ? 3 : 1;
416 num_modes
= depth_buffer_factor
* back_buffer_factor
* 4;
418 if ( pixel_bits
== 16 ) {
420 fb_type
= GL_UNSIGNED_SHORT_5_6_5
;
424 fb_type
= GL_UNSIGNED_INT_8_8_8_8_REV
;
427 modes
= (*dri_interface
->createContextModes
)( num_modes
, sizeof( __GLcontextModes
) );
429 if ( ! driFillInModes( & m
, fb_format
, fb_type
,
430 depth_bits_array
, stencil_bits_array
, depth_buffer_factor
,
431 back_buffer_modes
, back_buffer_factor
,
433 fprintf( stderr
, "[%s:%u] Error creating FBConfig!\n",
434 __func__
, __LINE__
);
437 if ( ! driFillInModes( & m
, fb_format
, fb_type
,
438 depth_bits_array
, stencil_bits_array
, depth_buffer_factor
,
439 back_buffer_modes
, back_buffer_factor
,
440 GLX_DIRECT_COLOR
) ) {
441 fprintf( stderr
, "[%s:%u] Error creating FBConfig!\n",
442 __func__
, __LINE__
);
446 /* Mark the visual as slow if there are "fake" stencil bits.
448 for ( m
= modes
; m
!= NULL
; m
= m
->next
) {
449 if ( (m
->stencilBits
!= 0) && (m
->stencilBits
!= stencil_bits
) ) {
450 m
->visualRating
= GLX_SLOW_CONFIG
;
459 * This is the bootstrap function for the driver. libGL supplies all of the
460 * requisite information about the system, and the driver initializes itself.
461 * This routine also fills in the linked list pointed to by \c driver_modes
462 * with the \c __GLcontextModes that the driver can support for windows or
465 * \return A pointer to a \c __DRIscreenPrivate on success, or \c NULL on
469 void * __driCreateNewScreen_20050727( __DRInativeDisplay
*dpy
, int scrn
, __DRIscreen
*psc
,
470 const __GLcontextModes
* modes
,
471 const __DRIversion
* ddx_version
,
472 const __DRIversion
* dri_version
,
473 const __DRIversion
* drm_version
,
474 const __DRIframebuffer
* frame_buffer
,
475 drmAddress pSAREA
, int fd
,
476 int internal_api_version
,
477 const __DRIinterfaceMethods
* interface
,
478 __GLcontextModes
** driver_modes
)
481 __DRIscreenPrivate
*psp
;
482 static const __DRIversion ddx_expected
= { 1, 4, 0 };
483 static const __DRIversion dri_expected
= { 4, 0, 0 };
484 static const __DRIversion drm_expected
= { 1, 1, 0 };
486 dri_interface
= interface
;
488 if ( ! driCheckDriDdxDrmVersions2( "i915",
489 dri_version
, & dri_expected
,
490 ddx_version
, & ddx_expected
,
491 drm_version
, & drm_expected
) ) {
495 psp
= __driUtilCreateNewScreen(dpy
, scrn
, psc
, NULL
,
496 ddx_version
, dri_version
, drm_version
,
497 frame_buffer
, pSAREA
, fd
,
498 internal_api_version
, &intelAPI
);
500 I830DRIPtr dri_priv
= (I830DRIPtr
) psp
->pDevPriv
;
501 *driver_modes
= intelFillInModes( dri_priv
->cpp
* 8,
502 (dri_priv
->cpp
== 2) ? 16 : 24,
503 (dri_priv
->cpp
== 2) ? 0 : 8,
504 (dri_priv
->backOffset
!= dri_priv
->depthOffset
) );
506 /* Calling driInitExtensions here, with a NULL context pointer, does not actually
507 * enable the extensions. It just makes sure that all the dispatch offsets for all
508 * the extensions that *might* be enables are known. This is needed because the
509 * dispatch offsets need to be known when _mesa_context_create is called, but we can't
510 * enable the extensions until we have a context pointer.
512 * Hello chicken. Hello egg. How are you two today?
514 driInitExtensions( NULL
, card_extensions
, GL_FALSE
);