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 #ifdef USE_NEW_INTERFACE
58 static PFNGLXCREATECONTEXTMODES create_context_modes
= NULL
;
59 #endif /*USE_NEW_INTERFACE*/
62 static void intelPrintDRIInfo(intelScreenPrivate
*intelScreen
,
63 __DRIscreenPrivate
*sPriv
,
66 fprintf(stderr
, "Front size : 0x%x\n", sPriv
->fbSize
);
67 fprintf(stderr
, "Front offset : 0x%x\n", intelScreen
->frontOffset
);
68 fprintf(stderr
, "Back size : 0x%x\n", intelScreen
->back
.size
);
69 fprintf(stderr
, "Back offset : 0x%x\n", intelScreen
->backOffset
);
70 fprintf(stderr
, "Depth size : 0x%x\n", intelScreen
->depth
.size
);
71 fprintf(stderr
, "Depth offset : 0x%x\n", intelScreen
->depthOffset
);
72 fprintf(stderr
, "Texture size : 0x%x\n", intelScreen
->textureSize
);
73 fprintf(stderr
, "Texture offset : 0x%x\n", intelScreen
->textureOffset
);
74 fprintf(stderr
, "Memory : 0x%x\n", gDRIPriv
->mem
);
77 static GLboolean
intelInitDriver(__DRIscreenPrivate
*sPriv
)
79 intelScreenPrivate
*intelScreen
;
80 I830DRIPtr gDRIPriv
= (I830DRIPtr
)sPriv
->pDevPriv
;
83 /* Allocate the private area */
84 intelScreen
= (intelScreenPrivate
*)MALLOC(sizeof(intelScreenPrivate
));
86 fprintf(stderr
,"\nERROR! Allocating private area failed\n");
89 /* parse information in __driConfigOptions */
90 driParseOptionInfo (&intelScreen
->optionCache
,
91 __driConfigOptions
, __driNConfigOptions
);
93 intelScreen
->driScrnPriv
= sPriv
;
94 sPriv
->private = (void *)intelScreen
;
96 intelScreen
->deviceID
= gDRIPriv
->deviceID
;
97 intelScreen
->width
= gDRIPriv
->width
;
98 intelScreen
->height
= gDRIPriv
->height
;
99 intelScreen
->mem
= gDRIPriv
->mem
;
100 intelScreen
->cpp
= gDRIPriv
->cpp
;
101 intelScreen
->frontPitch
= gDRIPriv
->fbStride
;
102 intelScreen
->frontOffset
= gDRIPriv
->fbOffset
;
104 switch (gDRIPriv
->bitsPerPixel
) {
105 case 15: intelScreen
->fbFormat
= DV_PF_555
; break;
106 case 16: intelScreen
->fbFormat
= DV_PF_565
; break;
107 case 32: intelScreen
->fbFormat
= DV_PF_8888
; break;
110 intelScreen
->backOffset
= gDRIPriv
->backOffset
;
111 intelScreen
->backPitch
= gDRIPriv
->backPitch
;
112 intelScreen
->depthOffset
= gDRIPriv
->depthOffset
;
113 intelScreen
->depthPitch
= gDRIPriv
->depthPitch
;
114 intelScreen
->textureOffset
= gDRIPriv
->textureOffset
;
115 intelScreen
->textureSize
= gDRIPriv
->textureSize
;
116 intelScreen
->logTextureGranularity
= gDRIPriv
->logTextureGranularity
;
117 intelScreen
->back
.handle
= gDRIPriv
->backbuffer
;
118 intelScreen
->back
.size
= gDRIPriv
->backbufferSize
;
120 if (drmMap(sPriv
->fd
,
121 intelScreen
->back
.handle
,
122 intelScreen
->back
.size
,
123 (drmAddress
*)&intelScreen
->back
.map
) != 0) {
124 fprintf(stderr
, "\nERROR: line %d, Function %s, File %s\n",
125 __LINE__
, __FUNCTION__
, __FILE__
);
127 sPriv
->private = NULL
;
131 intelScreen
->depth
.handle
= gDRIPriv
->depthbuffer
;
132 intelScreen
->depth
.size
= gDRIPriv
->depthbufferSize
;
134 if (drmMap(sPriv
->fd
,
135 intelScreen
->depth
.handle
,
136 intelScreen
->depth
.size
,
137 (drmAddress
*)&intelScreen
->depth
.map
) != 0) {
138 fprintf(stderr
, "\nERROR: line %d, Function %s, File %s\n",
139 __LINE__
, __FUNCTION__
, __FILE__
);
141 drmUnmap(intelScreen
->back
.map
, intelScreen
->back
.size
);
142 sPriv
->private = NULL
;
146 intelScreen
->tex
.handle
= gDRIPriv
->textures
;
147 intelScreen
->tex
.size
= gDRIPriv
->textureSize
;
149 if (drmMap(sPriv
->fd
,
150 intelScreen
->tex
.handle
,
151 intelScreen
->tex
.size
,
152 (drmAddress
*)&intelScreen
->tex
.map
) != 0) {
153 fprintf(stderr
, "\nERROR: line %d, Function %s, File %s\n",
154 __LINE__
, __FUNCTION__
, __FILE__
);
156 drmUnmap(intelScreen
->back
.map
, intelScreen
->back
.size
);
157 drmUnmap(intelScreen
->depth
.map
, intelScreen
->depth
.size
);
158 sPriv
->private = NULL
;
162 intelScreen
->sarea_priv_offset
= gDRIPriv
->sarea_priv_offset
;
164 if (0) intelPrintDRIInfo(intelScreen
, sPriv
, gDRIPriv
);
166 intelScreen
->drmMinor
= sPriv
->drmMinor
;
172 gp
.param
= I830_PARAM_IRQ_ACTIVE
;
173 gp
.value
= &intelScreen
->irq_active
;
175 ret
= drmCommandWriteRead( sPriv
->fd
, DRM_I830_GETPARAM
,
178 fprintf(stderr
, "drmI830GetParam: %d\n", ret
);
187 gp
.param
= I830_PARAM_ALLOW_BATCHBUFFER
;
188 gp
.value
= &intelScreen
->allow_batchbuffer
;
190 ret
= drmCommandWriteRead( sPriv
->fd
, DRM_I830_GETPARAM
,
193 fprintf(stderr
, "drmI830GetParam: (%d) %d\n", gp
.param
, ret
);
198 if ( driCompareGLXAPIVersion( 20030813 ) >= 0 ) {
199 PFNGLXSCRENABLEEXTENSIONPROC glx_enable_extension
=
200 (PFNGLXSCRENABLEEXTENSIONPROC
) glXGetProcAddress( (const GLubyte
*) "__glXScrEnableExtension" );
201 void * const psc
= sPriv
->psc
->screenConfigs
;
203 if (glx_enable_extension
!= NULL
) {
204 (*glx_enable_extension
)( psc
, "GLX_SGI_make_current_read" );
206 if ( driCompareGLXAPIVersion( 20030915 ) >= 0 ) {
207 (*glx_enable_extension
)( psc
, "GLX_SGIX_fbconfig" );
208 (*glx_enable_extension
)( psc
, "GLX_OML_swap_method" );
211 if ( driCompareGLXAPIVersion( 20030818 ) >= 0 ) {
212 sPriv
->psc
->allocateMemory
= (void *) intelAllocateMemoryMESA
;
213 sPriv
->psc
->freeMemory
= (void *) intelFreeMemoryMESA
;
214 sPriv
->psc
->memoryOffset
= (void *) intelGetMemoryOffsetMESA
;
216 (*glx_enable_extension
)( psc
, "GLX_MESA_allocate_memory" );
225 static void intelDestroyScreen(__DRIscreenPrivate
*sPriv
)
227 intelScreenPrivate
*intelScreen
= (intelScreenPrivate
*)sPriv
->private;
229 /* Need to unmap all the bufs and maps here:
231 drmUnmap(intelScreen
->back
.map
, intelScreen
->back
.size
);
232 drmUnmap(intelScreen
->depth
.map
, intelScreen
->depth
.size
);
233 drmUnmap(intelScreen
->tex
.map
, intelScreen
->tex
.size
);
235 sPriv
->private = NULL
;
239 static GLboolean
intelCreateBuffer( __DRIscreenPrivate
*driScrnPriv
,
240 __DRIdrawablePrivate
*driDrawPriv
,
241 const __GLcontextModes
*mesaVis
,
244 intelScreenPrivate
*screen
= (intelScreenPrivate
*) driScrnPriv
->private;
247 return GL_FALSE
; /* not implemented */
249 GLboolean swStencil
= (mesaVis
->stencilBits
> 0 &&
250 mesaVis
->depthBits
!= 24);
253 driDrawPriv
->driverPrivate
= (void *)
254 _mesa_create_framebuffer(mesaVis
,
255 GL_FALSE
, /* software depth buffer? */
257 mesaVis
->accumRedBits
> 0,
258 GL_FALSE
/* s/w alpha planes */);
260 struct gl_framebuffer
*fb
= _mesa_create_framebuffer(mesaVis
);
263 driRenderbuffer
*frontRb
264 = driNewRenderbuffer(GL_RGBA
, screen
->cpp
,
265 screen
->frontOffset
, screen
->frontPitch
);
266 intelSetSpanFunctions(frontRb
, mesaVis
);
267 _mesa_add_renderbuffer(fb
, BUFFER_FRONT_LEFT
, &frontRb
->Base
);
270 if (mesaVis
->doubleBufferMode
) {
271 driRenderbuffer
*backRb
272 = driNewRenderbuffer(GL_RGBA
, screen
->cpp
,
273 screen
->backOffset
, screen
->backPitch
);
274 intelSetSpanFunctions(backRb
, mesaVis
);
275 _mesa_add_renderbuffer(fb
, BUFFER_BACK_LEFT
, &backRb
->Base
);
278 if (mesaVis
->depthBits
== 16) {
279 driRenderbuffer
*depthRb
280 = driNewRenderbuffer(GL_DEPTH_COMPONENT16
, screen
->cpp
,
281 screen
->depthOffset
, screen
->depthPitch
);
282 intelSetSpanFunctions(depthRb
, mesaVis
);
283 _mesa_add_renderbuffer(fb
, BUFFER_DEPTH
, &depthRb
->Base
);
285 else if (mesaVis
->depthBits
== 24) {
286 driRenderbuffer
*depthRb
287 = driNewRenderbuffer(GL_DEPTH_COMPONENT24
, screen
->cpp
,
288 screen
->depthOffset
, screen
->depthPitch
);
289 intelSetSpanFunctions(depthRb
, mesaVis
);
290 _mesa_add_renderbuffer(fb
, BUFFER_DEPTH
, &depthRb
->Base
);
293 if (mesaVis
->stencilBits
> 0 && !swStencil
) {
294 driRenderbuffer
*stencilRb
295 = driNewRenderbuffer(GL_STENCIL_INDEX8_EXT
, screen
->cpp
,
296 screen
->depthOffset
, screen
->depthPitch
);
297 intelSetSpanFunctions(stencilRb
, mesaVis
);
298 _mesa_add_renderbuffer(fb
, BUFFER_STENCIL
, &stencilRb
->Base
);
301 _mesa_add_soft_renderbuffers(fb
,
302 GL_FALSE
, /* color */
303 GL_FALSE
, /* depth */
305 mesaVis
->accumRedBits
> 0,
306 GL_FALSE
, /* alpha */
308 driDrawPriv
->driverPrivate
= (void *) fb
;
310 return (driDrawPriv
->driverPrivate
!= NULL
);
314 static void intelDestroyBuffer(__DRIdrawablePrivate
*driDrawPriv
)
316 _mesa_destroy_framebuffer((GLframebuffer
*) (driDrawPriv
->driverPrivate
));
320 /* There are probably better ways to do this, such as an
321 * init-designated function to register chipids and createcontext
324 extern GLboolean
i830CreateContext( const __GLcontextModes
*mesaVis
,
325 __DRIcontextPrivate
*driContextPriv
,
326 void *sharedContextPrivate
);
328 extern GLboolean
i915CreateContext( const __GLcontextModes
*mesaVis
,
329 __DRIcontextPrivate
*driContextPriv
,
330 void *sharedContextPrivate
);
335 static GLboolean
intelCreateContext( const __GLcontextModes
*mesaVis
,
336 __DRIcontextPrivate
*driContextPriv
,
337 void *sharedContextPrivate
)
339 __DRIscreenPrivate
*sPriv
= driContextPriv
->driScreenPriv
;
340 intelScreenPrivate
*intelScreen
= (intelScreenPrivate
*)sPriv
->private;
342 switch (intelScreen
->deviceID
) {
344 case PCI_CHIP_I830_M
:
345 case PCI_CHIP_I855_GM
:
346 case PCI_CHIP_I865_G
:
347 return i830CreateContext( mesaVis
, driContextPriv
,
348 sharedContextPrivate
);
350 case PCI_CHIP_I915_G
:
351 case PCI_CHIP_I915_GM
:
352 return i915CreateContext( mesaVis
, driContextPriv
,
353 sharedContextPrivate
);
356 fprintf(stderr
, "Unrecognized deviceID %x\n", intelScreen
->deviceID
);
362 static const struct __DriverAPIRec intelAPI
= {
363 .InitDriver
= intelInitDriver
,
364 .DestroyScreen
= intelDestroyScreen
,
365 .CreateContext
= intelCreateContext
,
366 .DestroyContext
= intelDestroyContext
,
367 .CreateBuffer
= intelCreateBuffer
,
368 .DestroyBuffer
= intelDestroyBuffer
,
369 .SwapBuffers
= intelSwapBuffers
,
370 .MakeCurrent
= intelMakeCurrent
,
371 .UnbindContext
= intelUnbindContext
,
376 .SwapBuffersMSC
= NULL
380 * This is the bootstrap function for the driver.
381 * The __driCreateScreen name is the symbol that libGL.so fetches.
382 * Return: pointer to a __DRIscreenPrivate.
384 #if !defined(DRI_NEW_INTERFACE_ONLY)
385 void *__driCreateScreen(Display
*dpy
, int scrn
, __DRIscreen
*psc
,
386 int numConfigs
, __GLXvisualConfig
*config
)
388 __DRIscreenPrivate
*psp
;
389 psp
= __driUtilCreateScreen(dpy
, scrn
, psc
, numConfigs
, config
, &intelAPI
);
392 #endif /* !defined(DRI_NEW_INTERFACE_ONLY) */
395 #ifdef USE_NEW_INTERFACE
396 static __GLcontextModes
*
397 intelFillInModes( unsigned pixel_bits
, unsigned depth_bits
,
398 unsigned stencil_bits
, GLboolean have_back_buffer
)
400 __GLcontextModes
* modes
;
401 __GLcontextModes
* m
;
403 unsigned depth_buffer_factor
;
404 unsigned back_buffer_factor
;
408 /* GLX_SWAP_COPY_OML is only supported because the MGA driver doesn't
409 * support pageflipping at all.
411 static const GLenum back_buffer_modes
[] = {
412 GLX_NONE
, GLX_SWAP_UNDEFINED_OML
, GLX_SWAP_COPY_OML
415 u_int8_t depth_bits_array
[2];
416 u_int8_t stencil_bits_array
[2];
419 depth_bits_array
[0] = 0;
420 depth_bits_array
[1] = depth_bits
;
422 /* Just like with the accumulation buffer, always provide some modes
423 * with a stencil buffer. It will be a sw fallback, but some apps won't
426 stencil_bits_array
[0] = 0;
427 stencil_bits_array
[1] = (stencil_bits
== 0) ? 8 : stencil_bits
;
429 depth_buffer_factor
= ((depth_bits
!= 0) || (stencil_bits
!= 0)) ? 2 : 1;
430 back_buffer_factor
= (have_back_buffer
) ? 3 : 1;
432 num_modes
= depth_buffer_factor
* back_buffer_factor
* 4;
434 if ( pixel_bits
== 16 ) {
436 fb_type
= GL_UNSIGNED_SHORT_5_6_5
;
440 fb_type
= GL_UNSIGNED_INT_8_8_8_8_REV
;
443 modes
= (*create_context_modes
)( num_modes
, sizeof( __GLcontextModes
) );
445 if ( ! driFillInModes( & m
, fb_format
, fb_type
,
446 depth_bits_array
, stencil_bits_array
, depth_buffer_factor
,
447 back_buffer_modes
, back_buffer_factor
,
449 fprintf( stderr
, "[%s:%u] Error creating FBConfig!\n",
450 __func__
, __LINE__
);
454 /* There's no direct color modes on intel? */
456 /* Mark the visual as slow if there are "fake" stencil bits.
458 for ( m
= modes
; m
!= NULL
; m
= m
->next
) {
459 if ( (m
->stencilBits
!= 0) && (m
->stencilBits
!= stencil_bits
) ) {
460 m
->visualRating
= GLX_SLOW_CONFIG
;
466 #endif /* USE_NEW_INTERFACE */
470 * This is the bootstrap function for the driver. libGL supplies all of the
471 * requisite information about the system, and the driver initializes itself.
472 * This routine also fills in the linked list pointed to by \c driver_modes
473 * with the \c __GLcontextModes that the driver can support for windows or
476 * \return A pointer to a \c __DRIscreenPrivate on success, or \c NULL on
479 #ifdef USE_NEW_INTERFACE
481 void * __driCreateNewScreen( __DRInativeDisplay
*dpy
, int scrn
, __DRIscreen
*psc
,
482 const __GLcontextModes
* modes
,
483 const __DRIversion
* ddx_version
,
484 const __DRIversion
* dri_version
,
485 const __DRIversion
* drm_version
,
486 const __DRIframebuffer
* frame_buffer
,
487 drmAddress pSAREA
, int fd
,
488 int internal_api_version
,
489 __GLcontextModes
** driver_modes
)
492 __DRIscreenPrivate
*psp
;
493 static const __DRIversion ddx_expected
= { 1, 0, 0 };
494 static const __DRIversion dri_expected
= { 4, 0, 0 };
495 static const __DRIversion drm_expected
= { 1, 1, 0 };
497 if ( ! driCheckDriDdxDrmVersions2( "i915",
498 dri_version
, & dri_expected
,
499 ddx_version
, & ddx_expected
,
500 drm_version
, & drm_expected
) ) {
504 psp
= __driUtilCreateNewScreen(dpy
, scrn
, psc
, NULL
,
505 ddx_version
, dri_version
, drm_version
,
506 frame_buffer
, pSAREA
, fd
,
507 internal_api_version
, &intelAPI
);
509 create_context_modes
= (PFNGLXCREATECONTEXTMODES
)
510 glXGetProcAddress( (const GLubyte
*) "__glXCreateContextModes" );
511 if ( create_context_modes
!= NULL
) {
512 I830DRIPtr dri_priv
= (I830DRIPtr
) psp
->pDevPriv
;
513 *driver_modes
= intelFillInModes( dri_priv
->cpp
* 8,
514 (dri_priv
->cpp
== 2) ? 16 : 24,
515 (dri_priv
->cpp
== 2) ? 0 : 8,
516 (dri_priv
->backOffset
!= dri_priv
->depthOffset
) );
522 #endif /* USE_NEW_INTERFACE */