1 /**************************************************************************
3 Copyright 1998-1999 Precision Insight, 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 PRECISION INSIGHT 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 **************************************************************************/
27 /* $XFree86: xc/lib/GL/mesa/src/drv/i810/i810context.c,v 1.3 2002/10/30 12:51:33 alanh Exp $ */
31 * Keith Whitwell <keith@tungstengraphics.com>
39 #include "simple_list.h"
40 #include "extensions.h"
41 #include "framebuffer.h"
44 #include "swrast/swrast.h"
45 #include "swrast_setup/swrast_setup.h"
47 #include "array_cache/acache.h"
49 #include "tnl/t_pipeline.h"
51 #include "drivers/common/driverfuncs.h"
53 #include "i810screen.h"
56 #include "i810state.h"
61 #include "i810ioctl.h"
63 #include "drirenderbuffer.h"
66 #define need_GL_ARB_multisample
67 #define need_GL_ARB_texture_compression
68 #include "extension_helper.h"
74 PUBLIC
const char __driConfigOptions
[] = { 0 };
75 const GLuint __driNConfigOptions
= 0;
77 #define DRIVER_DATE "20050821"
79 static const GLubyte
*i810GetString( GLcontext
*ctx
, GLenum name
)
81 static char buffer
[128];
85 return (GLubyte
*)"Keith Whitwell";
87 i810ContextPtr imesa
= I810_CONTEXT(ctx
);
90 switch (imesa
->i810Screen
->deviceID
) {
91 case PCI_CHIP_I810
: chipset
= "i810"; break;
92 case PCI_CHIP_I810_DC100
: chipset
= "i810 DC-100"; break;
93 case PCI_CHIP_I810_E
: chipset
= "i810E"; break;
94 case PCI_CHIP_I815
: chipset
= "i815"; break;
95 default: chipset
= "Unknown i810-class Chipset"; break;
98 (void) driGetRendererString( buffer
, chipset
, DRIVER_DATE
, 0 );
99 return (GLubyte
*) buffer
;
106 static void i810BufferSize(GLframebuffer
*buffer
, GLuint
*width
, GLuint
*height
)
108 GET_CURRENT_CONTEXT(ctx
);
109 i810ContextPtr imesa
= I810_CONTEXT(ctx
);
111 /* Need to lock to make sure the driDrawable is uptodate. This
112 * information is used to resize Mesa's software buffers, so it has
115 LOCK_HARDWARE(imesa
);
116 *width
= imesa
->driDrawable
->w
;
117 *height
= imesa
->driDrawable
->h
;
118 UNLOCK_HARDWARE(imesa
);
121 /* Extension strings exported by the i810 driver.
123 const struct dri_extension card_extensions
[] =
125 { "GL_ARB_multisample", GL_ARB_multisample_functions
},
126 { "GL_ARB_multitexture", NULL
},
127 { "GL_ARB_texture_compression", GL_ARB_texture_compression_functions
},
128 { "GL_ARB_texture_env_add", NULL
},
129 { "GL_ARB_texture_env_combine", NULL
},
130 { "GL_ARB_texture_env_crossbar", NULL
},
131 { "GL_ARB_texture_mirrored_repeat", NULL
},
132 { "GL_EXT_stencil_wrap", NULL
},
133 { "GL_EXT_texture_edge_clamp", NULL
},
134 { "GL_EXT_texture_env_combine", NULL
},
135 { "GL_EXT_texture_lod_bias", NULL
},
136 { "GL_EXT_texture_rectangle", NULL
},
137 { "GL_MESA_ycbcr_texture", NULL
},
138 { "GL_NV_blend_square", NULL
},
139 { "GL_SGIS_generate_mipmap", NULL
},
143 extern const struct tnl_pipeline_stage _i810_render_stage
;
145 static const struct tnl_pipeline_stage
*i810_pipeline
[] = {
146 &_tnl_vertex_transform_stage
,
147 &_tnl_normal_transform_stage
,
148 &_tnl_lighting_stage
,
149 &_tnl_fog_coordinate_stage
,
151 &_tnl_texture_transform_stage
,
152 /* REMOVE: point attenuation stage */
154 &_i810_render_stage
, /* ADD: unclipped rastersetup-to-dma */
160 static const struct dri_debug_control debug_control
[] =
162 { "fall", DEBUG_FALLBACKS
},
163 { "tex", DEBUG_TEXTURE
},
164 { "ioctl", DEBUG_IOCTL
},
165 { "prim", DEBUG_PRIMS
},
166 { "vert", DEBUG_VERTS
},
167 { "state", DEBUG_STATE
},
168 { "verb", DEBUG_VERBOSE
},
169 { "dri", DEBUG_DRI
},
170 { "dma", DEBUG_DMA
},
171 { "san", DEBUG_SANITY
},
172 { "sync", DEBUG_SYNC
},
173 { "sleep", DEBUG_SLEEP
},
178 i810CreateContext( const __GLcontextModes
*mesaVis
,
179 __DRIcontextPrivate
*driContextPriv
,
180 void *sharedContextPrivate
)
182 GLcontext
*ctx
, *shareCtx
;
183 i810ContextPtr imesa
;
184 __DRIscreenPrivate
*sPriv
= driContextPriv
->driScreenPriv
;
185 i810ScreenPrivate
*i810Screen
= (i810ScreenPrivate
*)sPriv
->private;
186 I810SAREAPtr saPriv
= (I810SAREAPtr
)
187 (((GLubyte
*)sPriv
->pSAREA
) + i810Screen
->sarea_priv_offset
);
188 struct dd_function_table functions
;
190 /* Allocate i810 context */
191 imesa
= (i810ContextPtr
) CALLOC_STRUCT(i810_context_t
);
196 driContextPriv
->driverPrivate
= imesa
;
198 imesa
->i810Screen
= i810Screen
;
199 imesa
->driScreen
= sPriv
;
200 imesa
->sarea
= saPriv
;
201 imesa
->glBuffer
= NULL
;
203 /* Init default driver functions then plug in our I810-specific functions
204 * (the texture functions are especially important)
206 _mesa_init_driver_functions( &functions
);
207 i810InitIoctlFuncs( &functions
);
208 i810InitTextureFuncs( &functions
);
211 /* Allocate the Mesa context */
212 if (sharedContextPrivate
)
213 shareCtx
= ((i810ContextPtr
) sharedContextPrivate
)->glCtx
;
216 imesa
->glCtx
= _mesa_create_context(mesaVis
, shareCtx
,
217 &functions
, (void*) imesa
);
223 (void) memset( imesa
->texture_heaps
, 0, sizeof( imesa
->texture_heaps
) );
224 make_empty_list( & imesa
->swapped
);
227 imesa
->texture_heaps
[0] = driCreateTextureHeap( 0, imesa
,
228 i810Screen
->textureSize
,
231 imesa
->sarea
->texList
,
232 (unsigned *) & imesa
->sarea
->texAge
, /* XXX we shouldn't cast! */
234 sizeof( struct i810_texture_object_t
),
235 (destroy_texture_object_t
*) i810DestroyTexObj
);
239 /* Set the maximum texture size small enough that we can guarentee
240 * that both texture units can bind a maximal texture and have them
247 ctx
->Const
.MaxTextureUnits
= 2;
248 ctx
->Const
.MaxTextureImageUnits
= 2;
249 ctx
->Const
.MaxTextureCoordUnits
= 2;
252 /* FIXME: driCalcualteMaxTextureLevels assumes that mipmaps are tightly
253 * FIXME: packed, but they're not in Intel graphics hardware.
255 driCalculateMaxTextureLevels( imesa
->texture_heaps
,
259 11, /* max 2D texture size is 2048x2048 */
260 0, /* 3D textures unsupported */
261 0, /* cube textures unsupported. */
262 0, /* texture rectangles unsupported. */
267 ctx
->Const
.MinLineWidth
= 1.0;
268 ctx
->Const
.MinLineWidthAA
= 1.0;
269 ctx
->Const
.MaxLineWidth
= 3.0;
270 ctx
->Const
.MaxLineWidthAA
= 3.0;
271 ctx
->Const
.LineWidthGranularity
= 1.0;
273 ctx
->Const
.MinPointSize
= 1.0;
274 ctx
->Const
.MinPointSizeAA
= 1.0;
275 ctx
->Const
.MaxPointSize
= 3.0;
276 ctx
->Const
.MaxPointSizeAA
= 3.0;
277 ctx
->Const
.PointSizeGranularity
= 1.0;
279 ctx
->Driver
.GetBufferSize
= i810BufferSize
;
280 ctx
->Driver
.ResizeBuffers
= _mesa_resize_framebuffer
;
281 ctx
->Driver
.GetString
= i810GetString
;
285 ctx
->DriverCtx
= (void *) imesa
;
288 /* Initialize the software rasterizer and helper modules.
290 _swrast_CreateContext( ctx
);
291 _ac_CreateContext( ctx
);
292 _tnl_CreateContext( ctx
);
293 _swsetup_CreateContext( ctx
);
295 /* Install the customized pipeline:
297 _tnl_destroy_pipeline( ctx
);
298 _tnl_install_pipeline( ctx
, i810_pipeline
);
300 /* Configure swrast and T&L to match hardware characteristics:
302 _swrast_allow_pixel_fog( ctx
, GL_FALSE
);
303 _swrast_allow_vertex_fog( ctx
, GL_TRUE
);
304 _tnl_allow_pixel_fog( ctx
, GL_FALSE
);
305 _tnl_allow_vertex_fog( ctx
, GL_TRUE
);
309 imesa
->hHWContext
= driContextPriv
->hHWContext
;
310 imesa
->driFd
= sPriv
->fd
;
311 imesa
->driHwLock
= &sPriv
->pSAREA
->lock
;
313 imesa
->stipple_in_hw
= 1;
314 imesa
->RenderIndex
= ~0;
315 imesa
->dirty
= I810_UPLOAD_CTX
|I810_UPLOAD_BUFFERS
;
316 imesa
->upload_cliprects
= GL_TRUE
;
318 imesa
->CurrentTexObj
[0] = 0;
319 imesa
->CurrentTexObj
[1] = 0;
321 _math_matrix_ctr( &imesa
->ViewportMatrix
);
323 driInitExtensions( ctx
, card_extensions
, GL_TRUE
);
324 /* XXX these should really go right after _mesa_init_driver_functions() */
325 i810InitStateFuncs( ctx
);
326 i810InitTriFuncs( ctx
);
327 i810InitSpanFuncs( ctx
);
329 i810InitState( ctx
);
332 I810_DEBUG
= driParseDebugString( getenv( "I810_DEBUG" ),
334 I810_DEBUG
|= driParseDebugString( getenv( "INTEL_DEBUG" ),
342 i810DestroyContext(__DRIcontextPrivate
*driContextPriv
)
344 i810ContextPtr imesa
= (i810ContextPtr
) driContextPriv
->driverPrivate
;
346 assert(imesa
); /* should never be null */
348 GLboolean release_texture_heaps
;
351 release_texture_heaps
= (imesa
->glCtx
->Shared
->RefCount
== 1);
352 _swsetup_DestroyContext( imesa
->glCtx
);
353 _tnl_DestroyContext( imesa
->glCtx
);
354 _ac_DestroyContext( imesa
->glCtx
);
355 _swrast_DestroyContext( imesa
->glCtx
);
357 i810FreeVB( imesa
->glCtx
);
359 /* free the Mesa context */
360 imesa
->glCtx
->DriverCtx
= NULL
;
361 _mesa_destroy_context(imesa
->glCtx
);
362 if ( release_texture_heaps
) {
363 /* This share group is about to go away, free our private
364 * texture object data.
368 for ( i
= 0 ; i
< imesa
->nr_heaps
; i
++ ) {
369 driDestroyTextureHeap( imesa
->texture_heaps
[ i
] );
370 imesa
->texture_heaps
[ i
] = NULL
;
373 assert( is_empty_list( & imesa
->swapped
) );
381 void i810XMesaSetFrontClipRects( i810ContextPtr imesa
)
383 __DRIdrawablePrivate
*dPriv
= imesa
->driDrawable
;
385 imesa
->numClipRects
= dPriv
->numClipRects
;
386 imesa
->pClipRects
= dPriv
->pClipRects
;
387 imesa
->drawX
= dPriv
->x
;
388 imesa
->drawY
= dPriv
->y
;
390 i810EmitDrawingRectangle( imesa
);
391 imesa
->upload_cliprects
= GL_TRUE
;
395 void i810XMesaSetBackClipRects( i810ContextPtr imesa
)
397 __DRIdrawablePrivate
*dPriv
= imesa
->driDrawable
;
399 if (imesa
->sarea
->pf_enabled
== 0 && dPriv
->numBackClipRects
== 0)
401 imesa
->numClipRects
= dPriv
->numClipRects
;
402 imesa
->pClipRects
= dPriv
->pClipRects
;
403 imesa
->drawX
= dPriv
->x
;
404 imesa
->drawY
= dPriv
->y
;
406 imesa
->numClipRects
= dPriv
->numBackClipRects
;
407 imesa
->pClipRects
= dPriv
->pBackClipRects
;
408 imesa
->drawX
= dPriv
->backX
;
409 imesa
->drawY
= dPriv
->backY
;
412 i810EmitDrawingRectangle( imesa
);
413 imesa
->upload_cliprects
= GL_TRUE
;
417 static void i810XMesaWindowMoved( i810ContextPtr imesa
)
419 /* Determine current color drawing buffer */
420 switch (imesa
->glCtx
->DrawBuffer
->_ColorDrawBufferMask
[0]) {
421 case BUFFER_BIT_FRONT_LEFT
:
422 i810XMesaSetFrontClipRects( imesa
);
424 case BUFFER_BIT_BACK_LEFT
:
425 i810XMesaSetBackClipRects( imesa
);
428 /* glDrawBuffer(GL_NONE or GL_FRONT_AND_BACK): software fallback */
429 i810XMesaSetFrontClipRects( imesa
);
435 i810UnbindContext(__DRIcontextPrivate
*driContextPriv
)
437 i810ContextPtr imesa
= (i810ContextPtr
) driContextPriv
->driverPrivate
;
439 imesa
->dirty
= I810_UPLOAD_CTX
|I810_UPLOAD_BUFFERS
;
440 if (imesa
->CurrentTexObj
[0]) imesa
->dirty
|= I810_UPLOAD_TEX0
;
441 if (imesa
->CurrentTexObj
[1]) imesa
->dirty
|= I810_UPLOAD_TEX1
;
449 i810MakeCurrent(__DRIcontextPrivate
*driContextPriv
,
450 __DRIdrawablePrivate
*driDrawPriv
,
451 __DRIdrawablePrivate
*driReadPriv
)
453 if (driContextPriv
) {
454 i810ContextPtr imesa
= (i810ContextPtr
) driContextPriv
->driverPrivate
;
456 /* Shouldn't the readbuffer be stored also?
458 imesa
->driDrawable
= driDrawPriv
;
460 _mesa_make_current(imesa
->glCtx
,
461 (GLframebuffer
*) driDrawPriv
->driverPrivate
,
462 (GLframebuffer
*) driReadPriv
->driverPrivate
);
464 /* Are these necessary?
466 i810XMesaWindowMoved( imesa
);
469 _mesa_make_current(NULL
, NULL
, NULL
);
476 i810UpdatePageFlipping( i810ContextPtr imesa
)
478 GLcontext
*ctx
= imesa
->glCtx
;
481 /* Determine current color drawing buffer */
482 switch (ctx
->DrawBuffer
->_ColorDrawBufferMask
[0]) {
483 case BUFFER_BIT_FRONT_LEFT
:
486 case BUFFER_BIT_BACK_LEFT
:
493 if ( imesa
->sarea
->pf_current_page
== 1 )
496 driFlipRenderbuffers(ctx
->WinSysDrawBuffer
, front
);
499 imesa
->BufferSetup
[I810_DESTREG_DI1
] = imesa
->i810Screen
->fbOffset
| imesa
->i810Screen
->backPitchBits
;
501 imesa
->BufferSetup
[I810_DESTREG_DI1
] = imesa
->i810Screen
->backOffset
| imesa
->i810Screen
->backPitchBits
;
504 imesa
->dirty
|= I810_UPLOAD_BUFFERS
;
507 void i810GetLock( i810ContextPtr imesa
, GLuint flags
)
509 __DRIdrawablePrivate
*dPriv
= imesa
->driDrawable
;
510 __DRIscreenPrivate
*sPriv
= imesa
->driScreen
;
511 I810SAREAPtr sarea
= imesa
->sarea
;
512 int me
= imesa
->hHWContext
;
515 drmGetLock(imesa
->driFd
, imesa
->hHWContext
, flags
);
517 /* If the window moved, may need to set a new cliprect now.
519 * NOTE: This releases and regains the hw lock, so all state
520 * checking must be done *after* this call:
522 DRI_VALIDATE_DRAWABLE_INFO(sPriv
, dPriv
);
525 /* If we lost context, need to dump all registers to hardware.
526 * Note that we don't care about 2d contexts, even if they perform
527 * accelerated commands, so the DRI locking in the X server is even
528 * more broken than usual.
530 if (sarea
->ctxOwner
!= me
) {
531 driUpdateFramebufferSize(imesa
->glCtx
, dPriv
);
532 imesa
->upload_cliprects
= GL_TRUE
;
533 imesa
->dirty
= I810_UPLOAD_CTX
|I810_UPLOAD_BUFFERS
;
534 if (imesa
->CurrentTexObj
[0]) imesa
->dirty
|= I810_UPLOAD_TEX0
;
535 if (imesa
->CurrentTexObj
[1]) imesa
->dirty
|= I810_UPLOAD_TEX1
;
536 sarea
->ctxOwner
= me
;
539 /* Shared texture managment - if another client has played with
540 * texture space, figure out which if any of our textures have been
541 * ejected, and update our global LRU.
543 for ( i
= 0 ; i
< imesa
->nr_heaps
; i
++ ) {
544 DRI_AGE_TEXTURES( imesa
->texture_heaps
[ i
] );
547 if (imesa
->lastStamp
!= dPriv
->lastStamp
) {
548 i810UpdatePageFlipping( imesa
);
549 i810XMesaWindowMoved( imesa
);
550 imesa
->lastStamp
= dPriv
->lastStamp
;
556 i810SwapBuffers( __DRIdrawablePrivate
*dPriv
)
558 if (dPriv
->driContextPriv
&& dPriv
->driContextPriv
->driverPrivate
) {
559 i810ContextPtr imesa
;
561 imesa
= (i810ContextPtr
) dPriv
->driContextPriv
->driverPrivate
;
563 if (ctx
->Visual
.doubleBufferMode
) {
564 _mesa_notifySwapBuffers( ctx
); /* flush pending rendering comands */
565 if ( imesa
->sarea
->pf_active
) {
566 i810PageFlip( dPriv
);
568 i810CopyBuffer( dPriv
);
573 /* XXX this shouldn't be an error but we can't handle it for now */
574 _mesa_problem(NULL
, "i810SwapBuffers: drawable has no context!\n");