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 **************************************************************************/
30 * Keith Whitwell <keith@tungstengraphics.com>
35 #include "main/glheader.h"
36 #include "main/context.h"
37 #include "main/simple_list.h"
38 #include "main/imports.h"
39 #include "main/points.h"
41 #include "swrast/swrast.h"
42 #include "swrast_setup/swrast_setup.h"
46 #include "tnl/t_pipeline.h"
48 #include "drivers/common/driverfuncs.h"
50 #include "i810screen.h"
53 #include "i810state.h"
58 #include "i810ioctl.h"
60 #include "drirenderbuffer.h"
67 PUBLIC
const char __driConfigOptions
[] = { 0 };
68 const GLuint __driNConfigOptions
= 0;
70 #define DRIVER_DATE "20050821"
72 static const GLubyte
*i810GetString( struct gl_context
*ctx
, GLenum name
)
74 static char buffer
[128];
78 return (GLubyte
*)"Keith Whitwell";
80 i810ContextPtr imesa
= I810_CONTEXT(ctx
);
83 switch (imesa
->i810Screen
->deviceID
) {
84 case PCI_CHIP_I810
: chipset
= "i810"; break;
85 case PCI_CHIP_I810_DC100
: chipset
= "i810 DC-100"; break;
86 case PCI_CHIP_I810_E
: chipset
= "i810E"; break;
87 case PCI_CHIP_I815
: chipset
= "i815"; break;
88 default: chipset
= "Unknown i810-class Chipset"; break;
91 (void) driGetRendererString( buffer
, chipset
, DRIVER_DATE
, 0 );
92 return (GLubyte
*) buffer
;
99 static void i810BufferSize(struct gl_framebuffer
*buffer
, GLuint
*width
, GLuint
*height
)
101 GET_CURRENT_CONTEXT(ctx
);
102 i810ContextPtr imesa
= I810_CONTEXT(ctx
);
104 /* Need to lock to make sure the driDrawable is uptodate. This
105 * information is used to resize Mesa's software buffers, so it has
108 LOCK_HARDWARE(imesa
);
109 *width
= imesa
->driDrawable
->w
;
110 *height
= imesa
->driDrawable
->h
;
111 UNLOCK_HARDWARE(imesa
);
114 /* Extension strings exported by the i810 driver.
116 static const struct dri_extension card_extensions
[] =
118 { "GL_ARB_multitexture", NULL
},
119 { "GL_ARB_texture_env_add", NULL
},
120 { "GL_ARB_texture_env_combine", NULL
},
121 { "GL_ARB_texture_env_crossbar", NULL
},
122 { "GL_ARB_texture_mirrored_repeat", NULL
},
123 { "GL_EXT_stencil_wrap", NULL
},
124 { "GL_EXT_texture_edge_clamp", NULL
},
125 { "GL_EXT_texture_env_combine", NULL
},
126 { "GL_EXT_texture_lod_bias", NULL
},
127 { "GL_EXT_texture_rectangle", NULL
},
128 { "GL_MESA_ycbcr_texture", NULL
},
129 { "GL_NV_blend_square", NULL
},
133 extern const struct tnl_pipeline_stage _i810_render_stage
;
135 static const struct tnl_pipeline_stage
*i810_pipeline
[] = {
136 &_tnl_vertex_transform_stage
,
137 &_tnl_normal_transform_stage
,
138 &_tnl_lighting_stage
,
139 &_tnl_fog_coordinate_stage
,
141 &_tnl_texture_transform_stage
,
142 /* REMOVE: point attenuation stage */
144 &_i810_render_stage
, /* ADD: unclipped rastersetup-to-dma */
150 static const struct dri_debug_control debug_control
[] =
152 { "fall", DEBUG_FALLBACKS
},
153 { "tex", DEBUG_TEXTURE
},
154 { "ioctl", DEBUG_IOCTL
},
155 { "prim", DEBUG_PRIMS
},
156 { "vert", DEBUG_VERTS
},
157 { "state", DEBUG_STATE
},
158 { "verb", DEBUG_VERBOSE
},
159 { "dri", DEBUG_DRI
},
160 { "dma", DEBUG_DMA
},
161 { "san", DEBUG_SANITY
},
162 { "sync", DEBUG_SYNC
},
163 { "sleep", DEBUG_SLEEP
},
168 i810CreateContext( gl_api api
,
169 const struct gl_config
*mesaVis
,
170 __DRIcontext
*driContextPriv
,
171 void *sharedContextPrivate
)
173 struct gl_context
*ctx
, *shareCtx
;
174 i810ContextPtr imesa
;
175 __DRIscreen
*sPriv
= driContextPriv
->driScreenPriv
;
176 i810ScreenPrivate
*i810Screen
= (i810ScreenPrivate
*)sPriv
->private;
177 I810SAREAPtr saPriv
= (I810SAREAPtr
)
178 (((GLubyte
*)sPriv
->pSAREA
) + i810Screen
->sarea_priv_offset
);
179 struct dd_function_table functions
;
181 /* Allocate i810 context */
182 imesa
= (i810ContextPtr
) CALLOC_STRUCT(i810_context_t
);
187 driContextPriv
->driverPrivate
= imesa
;
189 imesa
->i810Screen
= i810Screen
;
190 imesa
->driScreen
= sPriv
;
191 imesa
->sarea
= saPriv
;
192 imesa
->glBuffer
= NULL
;
194 /* Init default driver functions then plug in our I810-specific functions
195 * (the texture functions are especially important)
197 _mesa_init_driver_functions( &functions
);
198 i810InitIoctlFuncs( &functions
);
199 i810InitTextureFuncs( &functions
);
202 /* Allocate the Mesa context */
203 if (sharedContextPrivate
)
204 shareCtx
= ((i810ContextPtr
) sharedContextPrivate
)->glCtx
;
207 imesa
->glCtx
= _mesa_create_context(API_OPENGL
, mesaVis
, shareCtx
,
208 &functions
, (void*) imesa
);
214 (void) memset( imesa
->texture_heaps
, 0, sizeof( imesa
->texture_heaps
) );
215 make_empty_list( & imesa
->swapped
);
218 imesa
->texture_heaps
[0] = driCreateTextureHeap( 0, imesa
,
219 i810Screen
->textureSize
,
222 imesa
->sarea
->texList
,
223 (unsigned *) & imesa
->sarea
->texAge
, /* XXX we shouldn't cast! */
225 sizeof( struct i810_texture_object_t
),
226 (destroy_texture_object_t
*) i810DestroyTexObj
);
230 /* Set the maximum texture size small enough that we can guarentee
231 * that both texture units can bind a maximal texture and have them
238 ctx
->Const
.MaxTextureUnits
= 2;
239 ctx
->Const
.MaxTextureImageUnits
= 2;
240 ctx
->Const
.MaxTextureCoordUnits
= 2;
243 /* FIXME: driCalcualteMaxTextureLevels assumes that mipmaps are tightly
244 * FIXME: packed, but they're not in Intel graphics hardware.
246 driCalculateMaxTextureLevels( imesa
->texture_heaps
,
250 11, /* max 2D texture size is 2048x2048 */
251 0, /* 3D textures unsupported */
252 0, /* cube textures unsupported. */
253 0, /* texture rectangles unsupported. */
258 ctx
->Const
.MinLineWidth
= 1.0;
259 ctx
->Const
.MinLineWidthAA
= 1.0;
260 ctx
->Const
.MaxLineWidth
= 3.0;
261 ctx
->Const
.MaxLineWidthAA
= 3.0;
262 ctx
->Const
.LineWidthGranularity
= 1.0;
264 ctx
->Const
.MinPointSize
= 1.0;
265 ctx
->Const
.MinPointSizeAA
= 1.0;
266 ctx
->Const
.MaxPointSize
= 3.0;
267 ctx
->Const
.MaxPointSizeAA
= 3.0;
268 ctx
->Const
.PointSizeGranularity
= 1.0;
270 /* reinitialize the context point state.
271 * It depend on constants in __struct gl_contextRec::Const
273 _mesa_init_point(ctx
);
275 ctx
->Driver
.GetBufferSize
= i810BufferSize
;
276 ctx
->Driver
.GetString
= i810GetString
;
280 ctx
->DriverCtx
= (void *) imesa
;
283 /* Initialize the software rasterizer and helper modules.
285 _swrast_CreateContext( ctx
);
286 _vbo_CreateContext( ctx
);
287 _tnl_CreateContext( ctx
);
288 _swsetup_CreateContext( ctx
);
290 /* Install the customized pipeline:
292 _tnl_destroy_pipeline( ctx
);
293 _tnl_install_pipeline( ctx
, i810_pipeline
);
295 /* Configure swrast and T&L to match hardware characteristics:
297 _swrast_allow_pixel_fog( ctx
, GL_FALSE
);
298 _swrast_allow_vertex_fog( ctx
, GL_TRUE
);
299 _tnl_allow_pixel_fog( ctx
, GL_FALSE
);
300 _tnl_allow_vertex_fog( ctx
, GL_TRUE
);
304 imesa
->hHWContext
= driContextPriv
->hHWContext
;
305 imesa
->driFd
= sPriv
->fd
;
306 imesa
->driHwLock
= &sPriv
->pSAREA
->lock
;
308 imesa
->stipple_in_hw
= 1;
309 imesa
->RenderIndex
= ~0;
310 imesa
->dirty
= I810_UPLOAD_CTX
|I810_UPLOAD_BUFFERS
;
311 imesa
->upload_cliprects
= GL_TRUE
;
313 imesa
->CurrentTexObj
[0] = 0;
314 imesa
->CurrentTexObj
[1] = 0;
316 _math_matrix_ctr( &imesa
->ViewportMatrix
);
318 driInitExtensions( ctx
, card_extensions
, GL_TRUE
);
319 /* XXX these should really go right after _mesa_init_driver_functions() */
320 i810InitStateFuncs( ctx
);
321 i810InitTriFuncs( ctx
);
322 i810InitSpanFuncs( ctx
);
324 i810InitState( ctx
);
327 I810_DEBUG
= driParseDebugString( getenv( "I810_DEBUG" ),
329 I810_DEBUG
|= driParseDebugString( getenv( "INTEL_DEBUG" ),
337 i810DestroyContext(__DRIcontext
*driContextPriv
)
339 i810ContextPtr imesa
= (i810ContextPtr
) driContextPriv
->driverPrivate
;
341 assert(imesa
); /* should never be null */
343 GLboolean release_texture_heaps
;
346 release_texture_heaps
= (imesa
->glCtx
->Shared
->RefCount
== 1);
347 _swsetup_DestroyContext( imesa
->glCtx
);
348 _tnl_DestroyContext( imesa
->glCtx
);
349 _vbo_DestroyContext( imesa
->glCtx
);
350 _swrast_DestroyContext( imesa
->glCtx
);
352 i810FreeVB( imesa
->glCtx
);
354 /* free the Mesa context */
355 imesa
->glCtx
->DriverCtx
= NULL
;
356 _mesa_destroy_context(imesa
->glCtx
);
357 if ( release_texture_heaps
) {
358 /* This share group is about to go away, free our private
359 * texture object data.
363 for ( i
= 0 ; i
< imesa
->nr_heaps
; i
++ ) {
364 driDestroyTextureHeap( imesa
->texture_heaps
[ i
] );
365 imesa
->texture_heaps
[ i
] = NULL
;
368 assert( is_empty_list( & imesa
->swapped
) );
376 void i810XMesaSetFrontClipRects( i810ContextPtr imesa
)
378 __DRIdrawable
*dPriv
= imesa
->driDrawable
;
380 imesa
->numClipRects
= dPriv
->numClipRects
;
381 imesa
->pClipRects
= dPriv
->pClipRects
;
382 imesa
->drawX
= dPriv
->x
;
383 imesa
->drawY
= dPriv
->y
;
385 i810EmitDrawingRectangle( imesa
);
386 imesa
->upload_cliprects
= GL_TRUE
;
390 void i810XMesaSetBackClipRects( i810ContextPtr imesa
)
392 __DRIdrawable
*dPriv
= imesa
->driDrawable
;
394 if (imesa
->sarea
->pf_enabled
== 0 && dPriv
->numBackClipRects
== 0)
396 imesa
->numClipRects
= dPriv
->numClipRects
;
397 imesa
->pClipRects
= dPriv
->pClipRects
;
398 imesa
->drawX
= dPriv
->x
;
399 imesa
->drawY
= dPriv
->y
;
401 imesa
->numClipRects
= dPriv
->numBackClipRects
;
402 imesa
->pClipRects
= dPriv
->pBackClipRects
;
403 imesa
->drawX
= dPriv
->backX
;
404 imesa
->drawY
= dPriv
->backY
;
407 i810EmitDrawingRectangle( imesa
);
408 imesa
->upload_cliprects
= GL_TRUE
;
412 static void i810XMesaWindowMoved( i810ContextPtr imesa
)
414 /* Determine current color drawing buffer */
415 switch (imesa
->glCtx
->DrawBuffer
->_ColorDrawBufferIndexes
[0]) {
416 case BUFFER_FRONT_LEFT
:
417 i810XMesaSetFrontClipRects( imesa
);
419 case BUFFER_BACK_LEFT
:
420 i810XMesaSetBackClipRects( imesa
);
423 /* glDrawBuffer(GL_NONE or GL_FRONT_AND_BACK): software fallback */
424 i810XMesaSetFrontClipRects( imesa
);
430 i810UnbindContext(__DRIcontext
*driContextPriv
)
432 i810ContextPtr imesa
= (i810ContextPtr
) driContextPriv
->driverPrivate
;
434 imesa
->dirty
= I810_UPLOAD_CTX
|I810_UPLOAD_BUFFERS
;
435 if (imesa
->CurrentTexObj
[0]) imesa
->dirty
|= I810_UPLOAD_TEX0
;
436 if (imesa
->CurrentTexObj
[1]) imesa
->dirty
|= I810_UPLOAD_TEX1
;
444 i810MakeCurrent(__DRIcontext
*driContextPriv
,
445 __DRIdrawable
*driDrawPriv
,
446 __DRIdrawable
*driReadPriv
)
448 if (driContextPriv
) {
449 i810ContextPtr imesa
= (i810ContextPtr
) driContextPriv
->driverPrivate
;
451 /* Shouldn't the readbuffer be stored also?
453 imesa
->driDrawable
= driDrawPriv
;
455 _mesa_make_current(imesa
->glCtx
,
456 (struct gl_framebuffer
*) driDrawPriv
->driverPrivate
,
457 (struct gl_framebuffer
*) driReadPriv
->driverPrivate
);
459 /* Are these necessary?
461 i810XMesaWindowMoved( imesa
);
464 _mesa_make_current(NULL
, NULL
, NULL
);
471 i810UpdatePageFlipping( i810ContextPtr imesa
)
473 struct gl_context
*ctx
= imesa
->glCtx
;
476 /* Determine current color drawing buffer */
477 switch (ctx
->DrawBuffer
->_ColorDrawBufferIndexes
[0]) {
478 case BUFFER_FRONT_LEFT
:
481 case BUFFER_BACK_LEFT
:
488 if ( imesa
->sarea
->pf_current_page
== 1 )
491 driFlipRenderbuffers(ctx
->WinSysDrawBuffer
, front
);
494 imesa
->BufferSetup
[I810_DESTREG_DI1
] = imesa
->i810Screen
->fbOffset
| imesa
->i810Screen
->backPitchBits
;
496 imesa
->BufferSetup
[I810_DESTREG_DI1
] = imesa
->i810Screen
->backOffset
| imesa
->i810Screen
->backPitchBits
;
499 imesa
->dirty
|= I810_UPLOAD_BUFFERS
;
502 void i810GetLock( i810ContextPtr imesa
, GLuint flags
)
504 __DRIdrawable
*dPriv
= imesa
->driDrawable
;
505 __DRIscreen
*sPriv
= imesa
->driScreen
;
506 I810SAREAPtr sarea
= imesa
->sarea
;
507 int me
= imesa
->hHWContext
;
510 drmGetLock(imesa
->driFd
, imesa
->hHWContext
, flags
);
512 /* If the window moved, may need to set a new cliprect now.
514 * NOTE: This releases and regains the hw lock, so all state
515 * checking must be done *after* this call:
517 DRI_VALIDATE_DRAWABLE_INFO(sPriv
, dPriv
);
520 /* If we lost context, need to dump all registers to hardware.
521 * Note that we don't care about 2d contexts, even if they perform
522 * accelerated commands, so the DRI locking in the X server is even
523 * more broken than usual.
525 if (sarea
->ctxOwner
!= me
) {
526 driUpdateFramebufferSize(imesa
->glCtx
, dPriv
);
527 imesa
->upload_cliprects
= GL_TRUE
;
528 imesa
->dirty
= I810_UPLOAD_CTX
|I810_UPLOAD_BUFFERS
;
529 if (imesa
->CurrentTexObj
[0]) imesa
->dirty
|= I810_UPLOAD_TEX0
;
530 if (imesa
->CurrentTexObj
[1]) imesa
->dirty
|= I810_UPLOAD_TEX1
;
531 sarea
->ctxOwner
= me
;
534 /* Shared texture managment - if another client has played with
535 * texture space, figure out which if any of our textures have been
536 * ejected, and update our global LRU.
538 for ( i
= 0 ; i
< imesa
->nr_heaps
; i
++ ) {
539 DRI_AGE_TEXTURES( imesa
->texture_heaps
[ i
] );
542 if (imesa
->lastStamp
!= dPriv
->lastStamp
) {
543 i810UpdatePageFlipping( imesa
);
544 i810XMesaWindowMoved( imesa
);
545 imesa
->lastStamp
= dPriv
->lastStamp
;
551 i810SwapBuffers( __DRIdrawable
*dPriv
)
553 if (dPriv
->driContextPriv
&& dPriv
->driContextPriv
->driverPrivate
) {
554 i810ContextPtr imesa
;
555 struct gl_context
*ctx
;
556 imesa
= (i810ContextPtr
) dPriv
->driContextPriv
->driverPrivate
;
558 if (ctx
->Visual
.doubleBufferMode
) {
559 _mesa_notifySwapBuffers( ctx
); /* flush pending rendering comands */
560 if ( imesa
->sarea
->pf_active
) {
561 i810PageFlip( dPriv
);
563 i810CopyBuffer( dPriv
);
568 /* XXX this shouldn't be an error but we can't handle it for now */
569 _mesa_problem(NULL
, "i810SwapBuffers: drawable has no context!\n");