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);
243 driDrawPriv
->driverPrivate
= (void *)
244 _mesa_create_framebuffer(mesaVis
,
245 GL_FALSE
, /* software depth buffer? */
247 mesaVis
->accumRedBits
> 0,
248 GL_FALSE
/* s/w alpha planes */);
250 struct gl_framebuffer
*fb
= _mesa_create_framebuffer(mesaVis
);
253 driRenderbuffer
*frontRb
254 = driNewRenderbuffer(GL_RGBA
, screen
->cpp
,
255 screen
->frontOffset
, screen
->frontPitch
);
256 intelSetSpanFunctions(frontRb
, mesaVis
);
257 _mesa_add_renderbuffer(fb
, BUFFER_FRONT_LEFT
, &frontRb
->Base
);
260 if (mesaVis
->doubleBufferMode
) {
261 driRenderbuffer
*backRb
262 = driNewRenderbuffer(GL_RGBA
, screen
->cpp
,
263 screen
->backOffset
, screen
->backPitch
);
264 intelSetSpanFunctions(backRb
, mesaVis
);
265 _mesa_add_renderbuffer(fb
, BUFFER_BACK_LEFT
, &backRb
->Base
);
268 if (mesaVis
->depthBits
== 16) {
269 driRenderbuffer
*depthRb
270 = driNewRenderbuffer(GL_DEPTH_COMPONENT16
, screen
->cpp
,
271 screen
->depthOffset
, screen
->depthPitch
);
272 intelSetSpanFunctions(depthRb
, mesaVis
);
273 _mesa_add_renderbuffer(fb
, BUFFER_DEPTH
, &depthRb
->Base
);
275 else if (mesaVis
->depthBits
== 24) {
276 driRenderbuffer
*depthRb
277 = driNewRenderbuffer(GL_DEPTH_COMPONENT24
, screen
->cpp
,
278 screen
->depthOffset
, screen
->depthPitch
);
279 intelSetSpanFunctions(depthRb
, mesaVis
);
280 _mesa_add_renderbuffer(fb
, BUFFER_DEPTH
, &depthRb
->Base
);
283 if (mesaVis
->stencilBits
> 0 && !swStencil
) {
284 driRenderbuffer
*stencilRb
285 = driNewRenderbuffer(GL_STENCIL_INDEX8_EXT
, screen
->cpp
,
286 screen
->depthOffset
, screen
->depthPitch
);
287 intelSetSpanFunctions(stencilRb
, mesaVis
);
288 _mesa_add_renderbuffer(fb
, BUFFER_STENCIL
, &stencilRb
->Base
);
291 _mesa_add_soft_renderbuffers(fb
,
292 GL_FALSE
, /* color */
293 GL_FALSE
, /* depth */
295 mesaVis
->accumRedBits
> 0,
296 GL_FALSE
, /* alpha */
298 driDrawPriv
->driverPrivate
= (void *) fb
;
300 return (driDrawPriv
->driverPrivate
!= NULL
);
304 static void intelDestroyBuffer(__DRIdrawablePrivate
*driDrawPriv
)
306 _mesa_destroy_framebuffer((GLframebuffer
*) (driDrawPriv
->driverPrivate
));
310 /* There are probably better ways to do this, such as an
311 * init-designated function to register chipids and createcontext
314 extern GLboolean
i830CreateContext( const __GLcontextModes
*mesaVis
,
315 __DRIcontextPrivate
*driContextPriv
,
316 void *sharedContextPrivate
);
318 extern GLboolean
i915CreateContext( const __GLcontextModes
*mesaVis
,
319 __DRIcontextPrivate
*driContextPriv
,
320 void *sharedContextPrivate
);
325 static GLboolean
intelCreateContext( const __GLcontextModes
*mesaVis
,
326 __DRIcontextPrivate
*driContextPriv
,
327 void *sharedContextPrivate
)
329 __DRIscreenPrivate
*sPriv
= driContextPriv
->driScreenPriv
;
330 intelScreenPrivate
*intelScreen
= (intelScreenPrivate
*)sPriv
->private;
332 switch (intelScreen
->deviceID
) {
334 case PCI_CHIP_I830_M
:
335 case PCI_CHIP_I855_GM
:
336 case PCI_CHIP_I865_G
:
337 return i830CreateContext( mesaVis
, driContextPriv
,
338 sharedContextPrivate
);
340 case PCI_CHIP_I915_G
:
341 case PCI_CHIP_I915_GM
:
342 case PCI_CHIP_I945_G
:
343 return i915CreateContext( mesaVis
, driContextPriv
,
344 sharedContextPrivate
);
347 fprintf(stderr
, "Unrecognized deviceID %x\n", intelScreen
->deviceID
);
353 static const struct __DriverAPIRec intelAPI
= {
354 .InitDriver
= intelInitDriver
,
355 .DestroyScreen
= intelDestroyScreen
,
356 .CreateContext
= intelCreateContext
,
357 .DestroyContext
= intelDestroyContext
,
358 .CreateBuffer
= intelCreateBuffer
,
359 .DestroyBuffer
= intelDestroyBuffer
,
360 .SwapBuffers
= intelSwapBuffers
,
361 .MakeCurrent
= intelMakeCurrent
,
362 .UnbindContext
= intelUnbindContext
,
367 .SwapBuffersMSC
= NULL
371 static __GLcontextModes
*
372 intelFillInModes( unsigned pixel_bits
, unsigned depth_bits
,
373 unsigned stencil_bits
, GLboolean have_back_buffer
)
375 __GLcontextModes
* modes
;
376 __GLcontextModes
* m
;
378 unsigned depth_buffer_factor
;
379 unsigned back_buffer_factor
;
383 /* GLX_SWAP_COPY_OML is only supported because the Intel driver doesn't
384 * support pageflipping at all.
386 static const GLenum back_buffer_modes
[] = {
387 GLX_NONE
, GLX_SWAP_UNDEFINED_OML
, GLX_SWAP_COPY_OML
390 u_int8_t depth_bits_array
[3];
391 u_int8_t stencil_bits_array
[3];
394 depth_bits_array
[0] = 0;
395 depth_bits_array
[1] = depth_bits
;
396 depth_bits_array
[2] = depth_bits
;
398 /* Just like with the accumulation buffer, always provide some modes
399 * with a stencil buffer. It will be a sw fallback, but some apps won't
402 stencil_bits_array
[0] = 0;
403 stencil_bits_array
[1] = 0;
404 stencil_bits_array
[2] = (stencil_bits
== 0) ? 8 : stencil_bits
;
406 depth_buffer_factor
= ((depth_bits
!= 0) || (stencil_bits
!= 0)) ? 3 : 1;
407 back_buffer_factor
= (have_back_buffer
) ? 3 : 1;
409 num_modes
= depth_buffer_factor
* back_buffer_factor
* 4;
411 if ( pixel_bits
== 16 ) {
413 fb_type
= GL_UNSIGNED_SHORT_5_6_5
;
417 fb_type
= GL_UNSIGNED_INT_8_8_8_8_REV
;
420 modes
= (*dri_interface
->createContextModes
)( num_modes
, sizeof( __GLcontextModes
) );
422 if ( ! driFillInModes( & m
, fb_format
, fb_type
,
423 depth_bits_array
, stencil_bits_array
, depth_buffer_factor
,
424 back_buffer_modes
, back_buffer_factor
,
426 fprintf( stderr
, "[%s:%u] Error creating FBConfig!\n",
427 __func__
, __LINE__
);
430 if ( ! driFillInModes( & m
, fb_format
, fb_type
,
431 depth_bits_array
, stencil_bits_array
, depth_buffer_factor
,
432 back_buffer_modes
, back_buffer_factor
,
433 GLX_DIRECT_COLOR
) ) {
434 fprintf( stderr
, "[%s:%u] Error creating FBConfig!\n",
435 __func__
, __LINE__
);
439 /* Mark the visual as slow if there are "fake" stencil bits.
441 for ( m
= modes
; m
!= NULL
; m
= m
->next
) {
442 if ( (m
->stencilBits
!= 0) && (m
->stencilBits
!= stencil_bits
) ) {
443 m
->visualRating
= GLX_SLOW_CONFIG
;
452 * This is the bootstrap function for the driver. libGL supplies all of the
453 * requisite information about the system, and the driver initializes itself.
454 * This routine also fills in the linked list pointed to by \c driver_modes
455 * with the \c __GLcontextModes that the driver can support for windows or
458 * \return A pointer to a \c __DRIscreenPrivate on success, or \c NULL on
462 void * __driCreateNewScreen_20050727( __DRInativeDisplay
*dpy
, int scrn
, __DRIscreen
*psc
,
463 const __GLcontextModes
* modes
,
464 const __DRIversion
* ddx_version
,
465 const __DRIversion
* dri_version
,
466 const __DRIversion
* drm_version
,
467 const __DRIframebuffer
* frame_buffer
,
468 drmAddress pSAREA
, int fd
,
469 int internal_api_version
,
470 const __DRIinterfaceMethods
* interface
,
471 __GLcontextModes
** driver_modes
)
474 __DRIscreenPrivate
*psp
;
475 static const __DRIversion ddx_expected
= { 1, 4, 0 };
476 static const __DRIversion dri_expected
= { 4, 0, 0 };
477 static const __DRIversion drm_expected
= { 1, 1, 0 };
479 dri_interface
= interface
;
481 if ( ! driCheckDriDdxDrmVersions2( "i915",
482 dri_version
, & dri_expected
,
483 ddx_version
, & ddx_expected
,
484 drm_version
, & drm_expected
) ) {
488 psp
= __driUtilCreateNewScreen(dpy
, scrn
, psc
, NULL
,
489 ddx_version
, dri_version
, drm_version
,
490 frame_buffer
, pSAREA
, fd
,
491 internal_api_version
, &intelAPI
);
493 I830DRIPtr dri_priv
= (I830DRIPtr
) psp
->pDevPriv
;
494 *driver_modes
= intelFillInModes( dri_priv
->cpp
* 8,
495 (dri_priv
->cpp
== 2) ? 16 : 24,
496 (dri_priv
->cpp
== 2) ? 0 : 8,
497 (dri_priv
->backOffset
!= dri_priv
->depthOffset
) );
499 /* Calling driInitExtensions here, with a NULL context pointer, does not actually
500 * enable the extensions. It just makes sure that all the dispatch offsets for all
501 * the extensions that *might* be enables are known. This is needed because the
502 * dispatch offsets need to be known when _mesa_context_create is called, but we can't
503 * enable the extensions until we have a context pointer.
505 * Hello chicken. Hello egg. How are you two today?
507 driInitExtensions( NULL
, card_extensions
, GL_FALSE
);