2 /**************************************************************************
4 Copyright (C) The Weather Channel, Inc. 2002. All Rights Reserved.
6 The Weather Channel (TM) funded Tungsten Graphics to develop the
7 initial release of the Radeon 8500 driver under the XFree86 license.
8 This notice must be preserved.
10 Permission is hereby granted, free of charge, to any person obtaining
11 a copy of this software and associated documentation files (the
12 "Software"), to deal in the Software without restriction, including
13 without limitation the rights to use, copy, modify, merge, publish,
14 distribute, sublicense, and/or sell copies of the Software, and to
15 permit persons to whom the Software is furnished to do so, subject to
16 the following conditions:
18 The above copyright notice and this permission notice (including the
19 next paragraph) shall be included in all copies or substantial
20 portions of the Software.
22 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
25 IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
26 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30 **************************************************************************/
34 * Keith Whitwell <keith@tungstengraphics.com>
38 #include "api_arrayelt.h"
40 #include "simple_list.h"
43 #include "extensions.h"
46 #include "swrast/swrast.h"
47 #include "swrast_setup/swrast_setup.h"
48 #include "array_cache/acache.h"
51 #include "tnl/t_pipeline.h"
53 #include "r200_context.h"
54 #include "r200_ioctl.h"
55 #include "r200_state.h"
56 #include "r200_span.h"
57 #include "r200_pixel.h"
59 #include "r200_swtcl.h"
61 #include "r200_vtxfmt.h"
62 #include "r200_maos.h"
64 #define DRIVER_DATE "20030328"
74 /* Return the width and height of the given buffer.
76 static void r200GetBufferSize( GLframebuffer
*buffer
,
77 GLuint
*width
, GLuint
*height
)
79 GET_CURRENT_CONTEXT(ctx
);
80 r200ContextPtr rmesa
= R200_CONTEXT(ctx
);
82 LOCK_HARDWARE( rmesa
);
83 *width
= rmesa
->dri
.drawable
->w
;
84 *height
= rmesa
->dri
.drawable
->h
;
85 UNLOCK_HARDWARE( rmesa
);
88 /* Return various strings for glGetString().
90 static const GLubyte
*r200GetString( GLcontext
*ctx
, GLenum name
)
92 r200ContextPtr rmesa
= R200_CONTEXT(ctx
);
93 static char buffer
[128];
95 GLuint agp_mode
= rmesa
->r200Screen
->IsPCI
? 0 :
96 rmesa
->r200Screen
->AGPMode
;
100 return (GLubyte
*)"Tungsten Graphics, Inc.";
103 offset
= driGetRendererString( buffer
, "R200", DRIVER_DATE
,
106 sprintf( & buffer
[ offset
], " %sTCL",
107 !(rmesa
->TclFallback
& R200_TCL_FALLBACK_TCL_DISABLE
)
110 return (GLubyte
*)buffer
;
118 /* Extension strings exported by the R200 driver.
120 static const char * const card_extensions
[] =
122 "GL_ARB_multisample",
123 "GL_ARB_multitexture",
124 "GL_ARB_texture_border_clamp",
125 "GL_ARB_texture_compression",
126 "GL_ARB_texture_env_add",
127 "GL_ARB_texture_env_combine",
128 "GL_ARB_texture_env_dot3",
129 "GL_ARB_texture_mirrored_repeat",
130 "GL_EXT_blend_logic_op",
131 "GL_EXT_blend_minmax",
132 "GL_EXT_blend_subtract",
133 "GL_EXT_secondary_color",
134 "GL_EXT_stencil_wrap",
135 "GL_EXT_texture_edge_clamp",
136 "GL_EXT_texture_env_add",
137 "GL_EXT_texture_env_combine",
138 "GL_EXT_texture_env_dot3",
139 "GL_EXT_texture_filter_anisotropic",
140 "GL_EXT_texture_lod_bias",
141 "GL_ATI_texture_env_combine3",
142 "GL_ATI_texture_mirror_once",
143 "GL_IBM_texture_mirrored_repeat",
144 "GL_MESA_pack_invert",
145 "GL_MESA_ycbcr_texture",
146 "GL_NV_blend_square",
147 "GL_NV_texture_rectangle",
148 "GL_SGIS_generate_mipmap",
149 "GL_SGIS_texture_border_clamp",
150 "GL_SGIS_texture_edge_clamp",
154 extern const struct gl_pipeline_stage _r200_render_stage
;
155 extern const struct gl_pipeline_stage _r200_tcl_stage
;
157 static const struct gl_pipeline_stage
*r200_pipeline
[] = {
159 /* Try and go straight to t&l
163 /* Catch any t&l fallbacks
165 &_tnl_vertex_transform_stage
,
166 &_tnl_normal_transform_stage
,
167 &_tnl_lighting_stage
,
168 &_tnl_fog_coordinate_stage
,
170 &_tnl_texture_transform_stage
,
172 /* Try again to go to tcl?
173 * - no good for asymmetric-twoside (do with multipass)
174 * - no good for asymmetric-unfilled (do with multipass)
175 * - good for material
177 * - need to manipulate a bit of state
179 * - worth it/not worth it?
182 /* Else do them here.
184 /* &_r200_render_stage, */ /* FIXME: bugs with ut2003 */
185 &_tnl_render_stage
, /* FALLBACK: */
191 /* Initialize the driver's misc functions.
193 static void r200InitDriverFuncs( GLcontext
*ctx
)
195 ctx
->Driver
.GetBufferSize
= r200GetBufferSize
;
196 ctx
->Driver
.ResizeBuffers
= _swrast_alloc_buffers
;
197 ctx
->Driver
.GetString
= r200GetString
;
199 ctx
->Driver
.Error
= NULL
;
200 ctx
->Driver
.DrawPixels
= NULL
;
201 ctx
->Driver
.Bitmap
= NULL
;
204 static const struct dri_debug_control debug_control
[] =
206 { "fall", DEBUG_FALLBACKS
},
207 { "tex", DEBUG_TEXTURE
},
208 { "ioctl", DEBUG_IOCTL
},
209 { "prim", DEBUG_PRIMS
},
210 { "vert", DEBUG_VERTS
},
211 { "state", DEBUG_STATE
},
212 { "code", DEBUG_CODEGEN
},
213 { "vfmt", DEBUG_VFMT
},
214 { "vtxf", DEBUG_VFMT
},
215 { "verb", DEBUG_VERBOSE
},
216 { "dri", DEBUG_DRI
},
217 { "dma", DEBUG_DMA
},
218 { "san", DEBUG_SANITY
},
219 { "sync", DEBUG_SYNC
},
220 { "pix", DEBUG_PIXEL
},
221 { "mem", DEBUG_MEMORY
},
227 get_ust_nop( int64_t * ust
)
234 /* Create the device specific context.
236 GLboolean
r200CreateContext( const __GLcontextModes
*glVisual
,
237 __DRIcontextPrivate
*driContextPriv
,
238 void *sharedContextPrivate
)
240 __DRIscreenPrivate
*sPriv
= driContextPriv
->driScreenPriv
;
241 r200ScreenPtr screen
= (r200ScreenPtr
)(sPriv
->private);
242 r200ContextPtr rmesa
;
243 GLcontext
*ctx
, *shareCtx
;
247 assert(driContextPriv
);
250 /* Allocate the R200 context */
251 rmesa
= (r200ContextPtr
) CALLOC( sizeof(*rmesa
) );
255 /* Allocate the Mesa context */
256 if (sharedContextPrivate
)
257 shareCtx
= ((r200ContextPtr
) sharedContextPrivate
)->glCtx
;
260 rmesa
->glCtx
= _mesa_create_context(glVisual
, shareCtx
, (void *) rmesa
, GL_TRUE
);
265 driContextPriv
->driverPrivate
= rmesa
;
267 /* Init r200 context data */
268 rmesa
->dri
.context
= driContextPriv
;
269 rmesa
->dri
.screen
= sPriv
;
270 rmesa
->dri
.drawable
= NULL
; /* Set by XMesaMakeCurrent */
271 rmesa
->dri
.hwContext
= driContextPriv
->hHWContext
;
272 rmesa
->dri
.hwLock
= &sPriv
->pSAREA
->lock
;
273 rmesa
->dri
.fd
= sPriv
->fd
;
274 rmesa
->dri
.drmMinor
= sPriv
->drmMinor
;
276 rmesa
->r200Screen
= screen
;
277 rmesa
->sarea
= (RADEONSAREAPrivPtr
)((GLubyte
*)sPriv
->pSAREA
+
278 screen
->sarea_priv_offset
);
281 rmesa
->dma
.buf0_address
= rmesa
->r200Screen
->buffers
->list
[0].address
;
283 (void) memset( rmesa
->texture_heaps
, 0, sizeof( rmesa
->texture_heaps
) );
284 make_empty_list( & rmesa
->swapped
);
286 rmesa
->nr_heaps
= 1 /* screen->numTexHeaps */ ;
287 for ( i
= 0 ; i
< rmesa
->nr_heaps
; i
++ ) {
288 rmesa
->texture_heaps
[i
] = driCreateTextureHeap( i
, rmesa
,
291 RADEON_NR_TEX_REGIONS
,
292 rmesa
->sarea
->texList
[i
],
293 & rmesa
->sarea
->texAge
[i
],
295 sizeof( r200TexObj
),
296 (destroy_texture_object_t
*) r200DestroyTexObj
);
299 rmesa
->swtcl
.RenderIndex
= ~0;
300 rmesa
->lost_context
= 1;
302 /* Set the maximum texture size small enough that we can guarentee that
303 * all texture units can bind a maximal texture and have them both in
304 * texturable memory at once.
308 ctx
->Const
.MaxTextureUnits
= 2;
310 driCalculateMaxTextureLevels( rmesa
->texture_heaps
,
314 11, /* max 2D texture size is 2048x2048 */
315 #if ENABLE_HW_3D_TEXTURE
316 8, /* max 3D texture size is 256^3 */
318 0, /* 3D textures unsupported */
320 11, /* max cube texture size is 2048x2048 */
321 11, /* max texture rectangle size is 2048x2048 */
325 ctx
->Const
.MaxTextureMaxAnisotropy
= 16.0;
329 ctx
->Const
.MinPointSize
= 1.0;
330 ctx
->Const
.MinPointSizeAA
= 1.0;
331 ctx
->Const
.MaxPointSize
= 1.0;
332 ctx
->Const
.MaxPointSizeAA
= 1.0;
334 ctx
->Const
.MinLineWidth
= 1.0;
335 ctx
->Const
.MinLineWidthAA
= 1.0;
336 ctx
->Const
.MaxLineWidth
= 10.0;
337 ctx
->Const
.MaxLineWidthAA
= 10.0;
338 ctx
->Const
.LineWidthGranularity
= 0.0625;
340 /* Initialize the software rasterizer and helper modules.
342 _swrast_CreateContext( ctx
);
343 _ac_CreateContext( ctx
);
344 _tnl_CreateContext( ctx
);
345 _swsetup_CreateContext( ctx
);
346 _ae_create_context( ctx
);
348 /* Install the customized pipeline:
350 _tnl_destroy_pipeline( ctx
);
351 _tnl_install_pipeline( ctx
, r200_pipeline
);
352 ctx
->Driver
.FlushVertices
= r200FlushVertices
;
354 /* Try and keep materials and vertices separate:
356 _tnl_isolate_materials( ctx
, GL_TRUE
);
359 /* Configure swrast to match hardware characteristics:
361 _swrast_allow_pixel_fog( ctx
, GL_FALSE
);
362 _swrast_allow_vertex_fog( ctx
, GL_TRUE
);
365 _math_matrix_ctr( &rmesa
->TexGenMatrix
[0] );
366 _math_matrix_ctr( &rmesa
->TexGenMatrix
[1] );
367 _math_matrix_ctr( &rmesa
->tmpmat
);
368 _math_matrix_set_identity( &rmesa
->TexGenMatrix
[0] );
369 _math_matrix_set_identity( &rmesa
->TexGenMatrix
[1] );
370 _math_matrix_set_identity( &rmesa
->tmpmat
);
372 driInitExtensions( ctx
, card_extensions
, GL_TRUE
);
373 if (rmesa
->r200Screen
->drmSupportsCubeMaps
)
374 _mesa_enable_extension( ctx
, "GL_ARB_texture_cube_map" );
376 r200InitDriverFuncs( ctx
);
377 r200InitIoctlFuncs( ctx
);
378 r200InitStateFuncs( ctx
);
379 r200InitSpanFuncs( ctx
);
380 r200InitPixelFuncs( ctx
);
381 r200InitTextureFuncs( ctx
);
382 r200InitState( rmesa
);
383 r200InitSwtcl( ctx
);
385 rmesa
->iw
.irq_seq
= -1;
386 rmesa
->irqsEmitted
= 0;
387 rmesa
->do_irqs
= (rmesa
->dri
.drmMinor
>= 6 &&
388 !getenv("R200_NO_IRQS") &&
389 rmesa
->r200Screen
->irq
);
393 "IRQ's not enabled, falling back to busy waits: %d %d %d\n",
395 !!getenv("R200_NO_IRQS"),
396 rmesa
->r200Screen
->irq
);
399 rmesa
->do_usleeps
= !getenv("R200_NO_USLEEPS");
401 rmesa
->vblank_flags
= (rmesa
->do_irqs
)
402 ? driGetDefaultVBlankFlags() : VBLANK_FLAG_NO_IRQ
;
404 rmesa
->prefer_agp_client_texturing
=
405 (getenv("R200_AGP_CLIENT_TEXTURES") != 0);
408 rmesa
->get_ust
= (PFNGLXGETUSTPROC
) glXGetProcAddress( "__glXGetUST" );
409 if ( rmesa
->get_ust
== NULL
) {
410 rmesa
->get_ust
= get_ust_nop
;
413 (*rmesa
->get_ust
)( & rmesa
->swap_ust
);
417 R200_DEBUG
= driParseDebugString( getenv( "R200_DEBUG" ),
419 R200_DEBUG
|= driParseDebugString( getenv( "RADEON_DEBUG" ),
423 if (getenv("R200_NO_RAST")) {
424 fprintf(stderr
, "disabling 3D acceleration\n");
425 FALLBACK(rmesa
, R200_FALLBACK_DISABLE
, 1);
427 else if (getenv("R200_NO_TCL")) {
428 fprintf(stderr
, "disabling TCL support\n");
429 TCL_FALLBACK(rmesa
->glCtx
, R200_TCL_FALLBACK_TCL_DISABLE
, 1);
432 if (!getenv("R200_NO_VTXFMT")) {
433 r200VtxfmtInit( ctx
);
435 _tnl_need_dlist_norm_lengths( ctx
, GL_FALSE
);
441 /* Destroy the device specific context.
443 /* Destroy the Mesa and driver specific context data.
445 void r200DestroyContext( __DRIcontextPrivate
*driContextPriv
)
447 GET_CURRENT_CONTEXT(ctx
);
448 r200ContextPtr rmesa
= (r200ContextPtr
) driContextPriv
->driverPrivate
;
449 r200ContextPtr current
= ctx
? R200_CONTEXT(ctx
) : NULL
;
451 /* check if we're deleting the currently bound context */
452 if (rmesa
== current
) {
453 R200_FIREVERTICES( rmesa
);
454 _mesa_make_current2(NULL
, NULL
, NULL
);
457 /* Free r200 context resources */
458 assert(rmesa
); /* should never be null */
460 GLboolean release_texture_heaps
;
463 release_texture_heaps
= (rmesa
->glCtx
->Shared
->RefCount
== 1);
464 _swsetup_DestroyContext( rmesa
->glCtx
);
465 _tnl_DestroyContext( rmesa
->glCtx
);
466 _ac_DestroyContext( rmesa
->glCtx
);
467 _swrast_DestroyContext( rmesa
->glCtx
);
469 r200DestroySwtcl( rmesa
->glCtx
);
470 r200ReleaseArrays( rmesa
->glCtx
, ~0 );
472 if (rmesa
->dma
.current
.buf
) {
473 r200ReleaseDmaRegion( rmesa
, &rmesa
->dma
.current
, __FUNCTION__
);
474 r200FlushCmdBuf( rmesa
, __FUNCTION__
);
477 if (!rmesa
->TclFallback
& R200_TCL_FALLBACK_TCL_DISABLE
)
478 if (!getenv("R200_NO_VTXFMT"))
479 r200VtxfmtDestroy( rmesa
->glCtx
);
481 /* free the Mesa context */
482 rmesa
->glCtx
->DriverCtx
= NULL
;
483 _mesa_destroy_context( rmesa
->glCtx
);
485 if (rmesa
->state
.scissor
.pClipRects
) {
486 FREE(rmesa
->state
.scissor
.pClipRects
);
487 rmesa
->state
.scissor
.pClipRects
= 0;
490 if ( release_texture_heaps
) {
491 /* This share group is about to go away, free our private
492 * texture object data.
496 /* this assert is wrong. The default textures are always on swap list
497 assert( is_empty_list( & rmesa->swapped ) ); */
499 for ( i
= 0 ; i
< rmesa
->nr_heaps
; i
++ ) {
500 driDestroyTextureHeap( rmesa
->texture_heaps
[ i
] );
501 rmesa
->texture_heaps
[ i
] = NULL
;
513 r200SwapBuffers( __DRIdrawablePrivate
*dPriv
)
515 if (dPriv
->driContextPriv
&& dPriv
->driContextPriv
->driverPrivate
) {
516 r200ContextPtr rmesa
;
518 rmesa
= (r200ContextPtr
) dPriv
->driContextPriv
->driverPrivate
;
520 if (ctx
->Visual
.doubleBufferMode
) {
521 _mesa_notifySwapBuffers( ctx
); /* flush pending rendering comands */
522 if ( rmesa
->doPageFlip
) {
523 r200PageFlip( dPriv
);
526 r200CopyBuffer( dPriv
);
531 /* XXX this shouldn't be an error but we can't handle it for now */
532 _mesa_problem(NULL
, "%s: drawable has no context!", __FUNCTION__
);
537 /* Force the context `c' to be the current context and associate with it
541 r200MakeCurrent( __DRIcontextPrivate
*driContextPriv
,
542 __DRIdrawablePrivate
*driDrawPriv
,
543 __DRIdrawablePrivate
*driReadPriv
)
545 if ( driContextPriv
) {
546 r200ContextPtr newCtx
=
547 (r200ContextPtr
) driContextPriv
->driverPrivate
;
549 if (R200_DEBUG
& DEBUG_DRI
)
550 fprintf(stderr
, "%s ctx %p\n", __FUNCTION__
, newCtx
->glCtx
);
552 if ( newCtx
->dri
.drawable
!= driDrawPriv
) {
553 newCtx
->dri
.drawable
= driDrawPriv
;
554 r200UpdateWindow( newCtx
->glCtx
);
555 r200UpdateViewportOffset( newCtx
->glCtx
);
558 _mesa_make_current2( newCtx
->glCtx
,
559 (GLframebuffer
*) driDrawPriv
->driverPrivate
,
560 (GLframebuffer
*) driReadPriv
->driverPrivate
);
562 if ( !newCtx
->glCtx
->Viewport
.Width
) {
563 _mesa_set_viewport( newCtx
->glCtx
, 0, 0,
564 driDrawPriv
->w
, driDrawPriv
->h
);
567 if (newCtx
->vb
.enabled
)
568 r200VtxfmtMakeCurrent( newCtx
->glCtx
);
570 _mesa_update_state( newCtx
->glCtx
);
571 r200ValidateState( newCtx
->glCtx
);
574 if (R200_DEBUG
& DEBUG_DRI
)
575 fprintf(stderr
, "%s ctx is null\n", __FUNCTION__
);
576 _mesa_make_current( 0, 0 );
579 if (R200_DEBUG
& DEBUG_DRI
)
580 fprintf(stderr
, "End %s\n", __FUNCTION__
);
584 /* Force the context `c' to be unbound from its buffer.
587 r200UnbindContext( __DRIcontextPrivate
*driContextPriv
)
589 r200ContextPtr rmesa
= (r200ContextPtr
) driContextPriv
->driverPrivate
;
591 if (R200_DEBUG
& DEBUG_DRI
)
592 fprintf(stderr
, "%s ctx %p\n", __FUNCTION__
, rmesa
->glCtx
);
594 r200VtxfmtUnbindContext( rmesa
->glCtx
);