r200: add missing symbols
[mesa.git] / src / mesa / drivers / dri / r200 / r200_context.c
1 /*
2 Copyright (C) The Weather Channel, Inc. 2002. All Rights Reserved.
3
4 The Weather Channel (TM) funded Tungsten Graphics to develop the
5 initial release of the Radeon 8500 driver under the XFree86 license.
6 This notice must be preserved.
7
8 Permission is hereby granted, free of charge, to any person obtaining
9 a copy of this software and associated documentation files (the
10 "Software"), to deal in the Software without restriction, including
11 without limitation the rights to use, copy, modify, merge, publish,
12 distribute, sublicense, and/or sell copies of the Software, and to
13 permit persons to whom the Software is furnished to do so, subject to
14 the following conditions:
15
16 The above copyright notice and this permission notice (including the
17 next paragraph) shall be included in all copies or substantial
18 portions of the Software.
19
20 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
23 IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
24 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27
28 **************************************************************************/
29
30 /*
31 * Authors:
32 * Keith Whitwell <keith@tungstengraphics.com>
33 */
34
35 #include "main/glheader.h"
36 #include "main/api_arrayelt.h"
37 #include "main/context.h"
38 #include "main/simple_list.h"
39 #include "main/imports.h"
40 #include "main/matrix.h"
41 #include "main/extensions.h"
42 #include "main/framebuffer.h"
43 #include "main/state.h"
44
45 #include "swrast/swrast.h"
46 #include "swrast_setup/swrast_setup.h"
47 #include "vbo/vbo.h"
48
49 #include "tnl/tnl.h"
50 #include "tnl/t_pipeline.h"
51
52 #include "drivers/common/driverfuncs.h"
53
54 #include "r200_context.h"
55 #include "r200_ioctl.h"
56 #include "r200_state.h"
57 #include "r200_span.h"
58 #include "r200_pixel.h"
59 #include "r200_tex.h"
60 #include "r200_swtcl.h"
61 #include "r200_tcl.h"
62 #include "r200_maos.h"
63 #include "r200_vertprog.h"
64
65 #define need_GL_ARB_multisample
66 #define need_GL_ARB_texture_compression
67 #define need_GL_ARB_vertex_buffer_object
68 #define need_GL_ARB_vertex_program
69 #define need_GL_ATI_fragment_shader
70 #define need_GL_EXT_blend_minmax
71 #define need_GL_EXT_fog_coord
72 #define need_GL_EXT_multi_draw_arrays
73 #define need_GL_EXT_secondary_color
74 #define need_GL_EXT_blend_equation_separate
75 #define need_GL_EXT_blend_func_separate
76 #define need_GL_NV_vertex_program
77 #define need_GL_ARB_point_parameters
78 #include "extension_helper.h"
79
80 #define DRIVER_DATE "20060602"
81
82 #include "vblank.h"
83 #include "utils.h"
84 #include "xmlpool.h" /* for symbolic values of enum-type options */
85
86 /* Return various strings for glGetString().
87 */
88 static const GLubyte *r200GetString( GLcontext *ctx, GLenum name )
89 {
90 r200ContextPtr rmesa = R200_CONTEXT(ctx);
91 static char buffer[128];
92 unsigned offset;
93 GLuint agp_mode = (rmesa->radeon.radeonScreen->card_type == RADEON_CARD_PCI)? 0 :
94 rmesa->radeon.radeonScreen->AGPMode;
95
96 switch ( name ) {
97 case GL_VENDOR:
98 return (GLubyte *)"Tungsten Graphics, Inc.";
99
100 case GL_RENDERER:
101 offset = driGetRendererString( buffer, "R200", DRIVER_DATE,
102 agp_mode );
103
104 sprintf( & buffer[ offset ], " %sTCL",
105 !(rmesa->radeon.TclFallback & R200_TCL_FALLBACK_TCL_DISABLE)
106 ? "" : "NO-" );
107
108 return (GLubyte *)buffer;
109
110 default:
111 return NULL;
112 }
113 }
114
115
116 /* Extension strings exported by the R200 driver.
117 */
118 const struct dri_extension card_extensions[] =
119 {
120 { "GL_ARB_multisample", GL_ARB_multisample_functions },
121 { "GL_ARB_multitexture", NULL },
122 { "GL_ARB_texture_border_clamp", NULL },
123 { "GL_ARB_texture_compression", GL_ARB_texture_compression_functions },
124 { "GL_ARB_texture_env_add", NULL },
125 { "GL_ARB_texture_env_combine", NULL },
126 { "GL_ARB_texture_env_dot3", NULL },
127 { "GL_ARB_texture_env_crossbar", NULL },
128 { "GL_ARB_texture_mirrored_repeat", NULL },
129 { "GL_ARB_vertex_buffer_object", GL_ARB_vertex_buffer_object_functions },
130 { "GL_EXT_blend_minmax", GL_EXT_blend_minmax_functions },
131 { "GL_EXT_blend_subtract", NULL },
132 { "GL_EXT_fog_coord", GL_EXT_fog_coord_functions },
133 { "GL_EXT_multi_draw_arrays", GL_EXT_multi_draw_arrays_functions },
134 { "GL_EXT_secondary_color", GL_EXT_secondary_color_functions },
135 { "GL_EXT_stencil_wrap", NULL },
136 { "GL_EXT_texture_edge_clamp", NULL },
137 { "GL_EXT_texture_env_combine", NULL },
138 { "GL_EXT_texture_env_dot3", NULL },
139 { "GL_EXT_texture_filter_anisotropic", NULL },
140 { "GL_EXT_texture_lod_bias", NULL },
141 { "GL_EXT_texture_mirror_clamp", NULL },
142 { "GL_EXT_texture_rectangle", NULL },
143 { "GL_ATI_texture_env_combine3", NULL },
144 { "GL_ATI_texture_mirror_once", NULL },
145 { "GL_MESA_pack_invert", NULL },
146 { "GL_NV_blend_square", NULL },
147 { "GL_SGIS_generate_mipmap", NULL },
148 { NULL, NULL }
149 };
150
151 const struct dri_extension blend_extensions[] = {
152 { "GL_EXT_blend_equation_separate", GL_EXT_blend_equation_separate_functions },
153 { "GL_EXT_blend_func_separate", GL_EXT_blend_func_separate_functions },
154 { NULL, NULL }
155 };
156
157 const struct dri_extension ARB_vp_extension[] = {
158 { "GL_ARB_vertex_program", GL_ARB_vertex_program_functions }
159 };
160
161 const struct dri_extension NV_vp_extension[] = {
162 { "GL_NV_vertex_program", GL_NV_vertex_program_functions }
163 };
164
165 const struct dri_extension ATI_fs_extension[] = {
166 { "GL_ATI_fragment_shader", GL_ATI_fragment_shader_functions }
167 };
168
169 const struct dri_extension point_extensions[] = {
170 { "GL_ARB_point_sprite", NULL },
171 { "GL_ARB_point_parameters", GL_ARB_point_parameters_functions },
172 { NULL, NULL }
173 };
174
175 extern const struct tnl_pipeline_stage _r200_render_stage;
176 extern const struct tnl_pipeline_stage _r200_tcl_stage;
177
178 static const struct tnl_pipeline_stage *r200_pipeline[] = {
179
180 /* Try and go straight to t&l
181 */
182 &_r200_tcl_stage,
183
184 /* Catch any t&l fallbacks
185 */
186 &_tnl_vertex_transform_stage,
187 &_tnl_normal_transform_stage,
188 &_tnl_lighting_stage,
189 &_tnl_fog_coordinate_stage,
190 &_tnl_texgen_stage,
191 &_tnl_texture_transform_stage,
192 &_tnl_point_attenuation_stage,
193 &_tnl_vertex_program_stage,
194 /* Try again to go to tcl?
195 * - no good for asymmetric-twoside (do with multipass)
196 * - no good for asymmetric-unfilled (do with multipass)
197 * - good for material
198 * - good for texgen
199 * - need to manipulate a bit of state
200 *
201 * - worth it/not worth it?
202 */
203
204 /* Else do them here.
205 */
206 /* &_r200_render_stage, */ /* FIXME: bugs with ut2003 */
207 &_tnl_render_stage, /* FALLBACK: */
208 NULL,
209 };
210
211
212
213 /* Initialize the driver's misc functions.
214 */
215 static void r200InitDriverFuncs( struct dd_function_table *functions )
216 {
217 functions->GetBufferSize = NULL; /* OBSOLETE */
218 functions->GetString = r200GetString;
219 }
220
221 static const struct dri_debug_control debug_control[] =
222 {
223 { "fall", DEBUG_FALLBACKS },
224 { "tex", DEBUG_TEXTURE },
225 { "ioctl", DEBUG_IOCTL },
226 { "prim", DEBUG_PRIMS },
227 { "vert", DEBUG_VERTS },
228 { "state", DEBUG_STATE },
229 { "code", DEBUG_CODEGEN },
230 { "vfmt", DEBUG_VFMT },
231 { "vtxf", DEBUG_VFMT },
232 { "verb", DEBUG_VERBOSE },
233 { "dri", DEBUG_DRI },
234 { "dma", DEBUG_DMA },
235 { "san", DEBUG_SANITY },
236 { "sync", DEBUG_SYNC },
237 { "pix", DEBUG_PIXEL },
238 { "mem", DEBUG_MEMORY },
239 { NULL, 0 }
240 };
241
242 static void r200_get_lock(radeonContextPtr radeon)
243 {
244 r200ContextPtr rmesa = (r200ContextPtr)radeon;
245 drm_radeon_sarea_t *sarea = radeon->sarea;
246 int i;
247
248 R200_STATECHANGE( rmesa, ctx );
249 if (rmesa->radeon.sarea->tiling_enabled) {
250 rmesa->hw.ctx.cmd[CTX_RB3D_COLORPITCH] |= R200_COLOR_TILE_ENABLE;
251 }
252 else rmesa->hw.ctx.cmd[CTX_RB3D_COLORPITCH] &= ~R200_COLOR_TILE_ENABLE;
253
254 if ( sarea->ctx_owner != rmesa->radeon.dri.hwContext ) {
255 sarea->ctx_owner = rmesa->radeon.dri.hwContext;
256 }
257
258 for ( i = 0 ; i < rmesa->radeon.nr_heaps ; i++ ) {
259 DRI_AGE_TEXTURES( rmesa->radeon.texture_heaps[ i ] );
260 }
261 }
262
263
264 static void r200_vtbl_flush(GLcontext *ctx)
265 {
266 R200_FIREVERTICES(R200_CONTEXT(ctx));
267 }
268
269 static void r200_vtbl_set_all_dirty(GLcontext *ctx)
270 {
271 r200ContextPtr rmesa = R200_CONTEXT(ctx);
272 rmesa->hw.all_dirty = GL_TRUE;
273 }
274
275 static void r200_vtbl_emit_cs_header(struct radeon_cs *cs, radeonContextPtr rmesa)
276 {
277 }
278
279 static void r200_init_vtbl(radeonContextPtr radeon)
280 {
281 radeon->vtbl.get_lock = r200_get_lock;
282 radeon->vtbl.update_viewport_offset = r200UpdateViewportOffset;
283 radeon->vtbl.flush = r200_vtbl_flush;
284 radeon->vtbl.set_all_dirty = r200_vtbl_set_all_dirty;
285 radeon->vtbl.update_draw_buffer = r200UpdateDrawBuffer;
286 radeon->vtbl.emit_cs_header = r200_vtbl_emit_cs_header;
287 }
288
289
290 /* Create the device specific rendering context.
291 */
292 GLboolean r200CreateContext( const __GLcontextModes *glVisual,
293 __DRIcontextPrivate *driContextPriv,
294 void *sharedContextPrivate)
295 {
296 __DRIscreenPrivate *sPriv = driContextPriv->driScreenPriv;
297 radeonScreenPtr screen = (radeonScreenPtr)(sPriv->private);
298 struct dd_function_table functions;
299 r200ContextPtr rmesa;
300 GLcontext *ctx, *shareCtx;
301 int i;
302 int tcl_mode, fthrottle_mode;
303
304 assert(glVisual);
305 assert(driContextPriv);
306 assert(screen);
307
308 /* Allocate the R200 context */
309 rmesa = (r200ContextPtr) CALLOC( sizeof(*rmesa) );
310 if ( !rmesa )
311 return GL_FALSE;
312
313 r200_init_vtbl(&rmesa->radeon);
314 /* init exp fog table data */
315 r200InitStaticFogData();
316
317 /* Parse configuration files.
318 * Do this here so that initialMaxAnisotropy is set before we create
319 * the default textures.
320 */
321 driParseConfigFiles (&rmesa->radeon.optionCache, &screen->optionCache,
322 screen->driScreen->myNum, "r200");
323 rmesa->radeon.initialMaxAnisotropy = driQueryOptionf(&rmesa->radeon.optionCache,
324 "def_max_anisotropy");
325
326 if ( driQueryOptionb( &rmesa->radeon.optionCache, "hyperz" ) ) {
327 if ( sPriv->drm_version.minor < 13 )
328 fprintf( stderr, "DRM version 1.%d too old to support HyperZ, "
329 "disabling.\n", sPriv->drm_version.minor );
330 else
331 rmesa->using_hyperz = GL_TRUE;
332 }
333
334 if ( sPriv->drm_version.minor >= 15 )
335 rmesa->texmicrotile = GL_TRUE;
336
337 /* Init default driver functions then plug in our R200-specific functions
338 * (the texture functions are especially important)
339 */
340 _mesa_init_driver_functions(&functions);
341 r200InitDriverFuncs(&functions);
342 r200InitIoctlFuncs(&functions);
343 r200InitStateFuncs(&functions);
344 r200InitTextureFuncs(&functions);
345 r200InitShaderFuncs(&functions);
346
347 /* Allocate and initialize the Mesa context */
348 if (sharedContextPrivate)
349 shareCtx = ((r200ContextPtr) sharedContextPrivate)->radeon.glCtx;
350 else
351 shareCtx = NULL;
352 rmesa->radeon.glCtx = _mesa_create_context(glVisual, shareCtx,
353 &functions, (void *) rmesa);
354 if (!rmesa->radeon.glCtx) {
355 FREE(rmesa);
356 return GL_FALSE;
357 }
358 driContextPriv->driverPrivate = rmesa;
359
360 /* Init r200 context data */
361 rmesa->radeon.dri.context = driContextPriv;
362 rmesa->radeon.dri.screen = sPriv;
363 rmesa->radeon.dri.drawable = NULL; /* Set by XMesaMakeCurrent */
364 rmesa->radeon.dri.hwContext = driContextPriv->hHWContext;
365 rmesa->radeon.dri.hwLock = &sPriv->pSAREA->lock;
366 rmesa->radeon.dri.fd = sPriv->fd;
367 rmesa->radeon.dri.drmMinor = sPriv->drm_version.minor;
368
369 rmesa->radeon.radeonScreen = screen;
370 rmesa->radeon.sarea = (drm_radeon_sarea_t *)((GLubyte *)sPriv->pSAREA +
371 screen->sarea_priv_offset);
372
373
374 rmesa->dma.buf0_address = rmesa->radeon.radeonScreen->buffers->list[0].address;
375
376 (void) memset( rmesa->radeon.texture_heaps, 0, sizeof( rmesa->radeon.texture_heaps ) );
377 make_empty_list( & rmesa->radeon.swapped );
378
379 rmesa->radeon.nr_heaps = 1 /* screen->numTexHeaps */ ;
380 assert(rmesa->radeon.nr_heaps < RADEON_NR_TEX_HEAPS);
381 for ( i = 0 ; i < rmesa->radeon.nr_heaps ; i++ ) {
382 rmesa->radeon.texture_heaps[i] = driCreateTextureHeap( i, rmesa,
383 screen->texSize[i],
384 12,
385 RADEON_NR_TEX_REGIONS,
386 (drmTextureRegionPtr)rmesa->radeon.sarea->tex_list[i],
387 & rmesa->radeon.sarea->tex_age[i],
388 & rmesa->radeon.swapped,
389 sizeof( radeonTexObj ),
390 (destroy_texture_object_t *) r200DestroyTexObj );
391 }
392 rmesa->radeon.texture_depth = driQueryOptioni (&rmesa->radeon.optionCache,
393 "texture_depth");
394 if (rmesa->radeon.texture_depth == DRI_CONF_TEXTURE_DEPTH_FB)
395 rmesa->radeon.texture_depth = ( screen->cpp == 4 ) ?
396 DRI_CONF_TEXTURE_DEPTH_32 : DRI_CONF_TEXTURE_DEPTH_16;
397
398 rmesa->swtcl.RenderIndex = ~0;
399 rmesa->hw.all_dirty = 1;
400
401 /* Set the maximum texture size small enough that we can guarentee that
402 * all texture units can bind a maximal texture and have all of them in
403 * texturable memory at once. Depending on the allow_large_textures driconf
404 * setting allow larger textures.
405 */
406
407 ctx = rmesa->radeon.glCtx;
408 ctx->Const.MaxTextureUnits = driQueryOptioni (&rmesa->radeon.optionCache,
409 "texture_units");
410 ctx->Const.MaxTextureImageUnits = ctx->Const.MaxTextureUnits;
411 ctx->Const.MaxTextureCoordUnits = ctx->Const.MaxTextureUnits;
412
413 i = driQueryOptioni( &rmesa->radeon.optionCache, "allow_large_textures");
414
415 driCalculateMaxTextureLevels( rmesa->radeon.texture_heaps,
416 rmesa->radeon.nr_heaps,
417 & ctx->Const,
418 4,
419 11, /* max 2D texture size is 2048x2048 */
420 #if ENABLE_HW_3D_TEXTURE
421 8, /* max 3D texture size is 256^3 */
422 #else
423 0, /* 3D textures unsupported */
424 #endif
425 11, /* max cube texture size is 2048x2048 */
426 11, /* max texture rectangle size is 2048x2048 */
427 12,
428 GL_FALSE,
429 i );
430
431 ctx->Const.MaxTextureMaxAnisotropy = 16.0;
432
433 /* No wide AA points.
434 */
435 ctx->Const.MinPointSize = 1.0;
436 ctx->Const.MinPointSizeAA = 1.0;
437 ctx->Const.MaxPointSizeAA = 1.0;
438 ctx->Const.PointSizeGranularity = 0.0625;
439 if (rmesa->radeon.radeonScreen->drmSupportsPointSprites)
440 ctx->Const.MaxPointSize = 2047.0;
441 else
442 ctx->Const.MaxPointSize = 1.0;
443
444 /* mesa initialization problem - _mesa_init_point was already called */
445 ctx->Point.MaxSize = ctx->Const.MaxPointSize;
446
447 ctx->Const.MinLineWidth = 1.0;
448 ctx->Const.MinLineWidthAA = 1.0;
449 ctx->Const.MaxLineWidth = 10.0;
450 ctx->Const.MaxLineWidthAA = 10.0;
451 ctx->Const.LineWidthGranularity = 0.0625;
452
453 ctx->Const.VertexProgram.MaxNativeInstructions = R200_VSF_MAX_INST;
454 ctx->Const.VertexProgram.MaxNativeAttribs = 12;
455 ctx->Const.VertexProgram.MaxNativeTemps = R200_VSF_MAX_TEMPS;
456 ctx->Const.VertexProgram.MaxNativeParameters = R200_VSF_MAX_PARAM;
457 ctx->Const.VertexProgram.MaxNativeAddressRegs = 1;
458
459 /* Initialize the software rasterizer and helper modules.
460 */
461 _swrast_CreateContext( ctx );
462 _vbo_CreateContext( ctx );
463 _tnl_CreateContext( ctx );
464 _swsetup_CreateContext( ctx );
465 _ae_create_context( ctx );
466
467 /* Install the customized pipeline:
468 */
469 _tnl_destroy_pipeline( ctx );
470 _tnl_install_pipeline( ctx, r200_pipeline );
471
472 /* Try and keep materials and vertices separate:
473 */
474 /* _tnl_isolate_materials( ctx, GL_TRUE ); */
475
476
477 /* Configure swrast and TNL to match hardware characteristics:
478 */
479 _swrast_allow_pixel_fog( ctx, GL_FALSE );
480 _swrast_allow_vertex_fog( ctx, GL_TRUE );
481 _tnl_allow_pixel_fog( ctx, GL_FALSE );
482 _tnl_allow_vertex_fog( ctx, GL_TRUE );
483
484
485 for ( i = 0 ; i < R200_MAX_TEXTURE_UNITS ; i++ ) {
486 _math_matrix_ctr( &rmesa->TexGenMatrix[i] );
487 _math_matrix_set_identity( &rmesa->TexGenMatrix[i] );
488 }
489 _math_matrix_ctr( &rmesa->tmpmat );
490 _math_matrix_set_identity( &rmesa->tmpmat );
491
492 driInitExtensions( ctx, card_extensions, GL_TRUE );
493 if (!(rmesa->radeon.radeonScreen->chip_flags & R200_CHIPSET_YCBCR_BROKEN)) {
494 /* yuv textures don't work with some chips - R200 / rv280 okay so far
495 others get the bit ordering right but don't actually do YUV-RGB conversion */
496 _mesa_enable_extension( ctx, "GL_MESA_ycbcr_texture" );
497 }
498 if (rmesa->radeon.glCtx->Mesa_DXTn) {
499 _mesa_enable_extension( ctx, "GL_EXT_texture_compression_s3tc" );
500 _mesa_enable_extension( ctx, "GL_S3_s3tc" );
501 }
502 else if (driQueryOptionb (&rmesa->radeon.optionCache, "force_s3tc_enable")) {
503 _mesa_enable_extension( ctx, "GL_EXT_texture_compression_s3tc" );
504 }
505
506 if (rmesa->radeon.radeonScreen->drmSupportsCubeMapsR200)
507 _mesa_enable_extension( ctx, "GL_ARB_texture_cube_map" );
508 if (rmesa->radeon.radeonScreen->drmSupportsBlendColor) {
509 driInitExtensions( ctx, blend_extensions, GL_FALSE );
510 }
511 if(rmesa->radeon.radeonScreen->drmSupportsVertexProgram)
512 driInitSingleExtension( ctx, ARB_vp_extension );
513 if(driQueryOptionb(&rmesa->radeon.optionCache, "nv_vertex_program"))
514 driInitSingleExtension( ctx, NV_vp_extension );
515
516 if ((ctx->Const.MaxTextureUnits == 6) && rmesa->radeon.radeonScreen->drmSupportsFragShader)
517 driInitSingleExtension( ctx, ATI_fs_extension );
518 if (rmesa->radeon.radeonScreen->drmSupportsPointSprites)
519 driInitExtensions( ctx, point_extensions, GL_FALSE );
520 #if 0
521 r200InitDriverFuncs( ctx );
522 r200InitIoctlFuncs( ctx );
523 r200InitStateFuncs( ctx );
524 r200InitTextureFuncs( ctx );
525 #endif
526 /* plug in a few more device driver functions */
527 /* XXX these should really go right after _mesa_init_driver_functions() */
528 r200InitPixelFuncs( ctx );
529 r200InitSpanFuncs( ctx );
530 r200InitTnlFuncs( ctx );
531 r200InitState( rmesa );
532 r200InitSwtcl( ctx );
533
534 fthrottle_mode = driQueryOptioni(&rmesa->radeon.optionCache, "fthrottle_mode");
535 rmesa->radeon.iw.irq_seq = -1;
536 rmesa->radeon.irqsEmitted = 0;
537 rmesa->radeon.do_irqs = (fthrottle_mode == DRI_CONF_FTHROTTLE_IRQS &&
538 rmesa->radeon.radeonScreen->irq);
539
540 rmesa->radeon.do_usleeps = (fthrottle_mode == DRI_CONF_FTHROTTLE_USLEEPS);
541
542 if (!rmesa->radeon.do_irqs)
543 fprintf(stderr,
544 "IRQ's not enabled, falling back to %s: %d %d\n",
545 rmesa->radeon.do_usleeps ? "usleeps" : "busy waits",
546 fthrottle_mode,
547 rmesa->radeon.radeonScreen->irq);
548
549 rmesa->prefer_gart_client_texturing =
550 (getenv("R200_GART_CLIENT_TEXTURES") != 0);
551
552 (*sPriv->systemTime->getUST)( & rmesa->radeon.swap_ust );
553
554
555 #if DO_DEBUG
556 R200_DEBUG = driParseDebugString( getenv( "R200_DEBUG" ),
557 debug_control );
558 R200_DEBUG |= driParseDebugString( getenv( "RADEON_DEBUG" ),
559 debug_control );
560 #endif
561
562 tcl_mode = driQueryOptioni(&rmesa->radeon.optionCache, "tcl_mode");
563 if (driQueryOptionb(&rmesa->radeon.optionCache, "no_rast")) {
564 fprintf(stderr, "disabling 3D acceleration\n");
565 FALLBACK(rmesa, R200_FALLBACK_DISABLE, 1);
566 }
567 else if (tcl_mode == DRI_CONF_TCL_SW || getenv("R200_NO_TCL") ||
568 !(rmesa->radeon.radeonScreen->chip_flags & RADEON_CHIPSET_TCL)) {
569 if (rmesa->radeon.radeonScreen->chip_flags & RADEON_CHIPSET_TCL) {
570 rmesa->radeon.radeonScreen->chip_flags &= ~RADEON_CHIPSET_TCL;
571 fprintf(stderr, "Disabling HW TCL support\n");
572 }
573 TCL_FALLBACK(rmesa->radeon.glCtx, R200_TCL_FALLBACK_TCL_DISABLE, 1);
574 }
575
576 return GL_TRUE;
577 }
578
579
580 /* Destroy the device specific context.
581 */
582 /* Destroy the Mesa and driver specific context data.
583 */
584 void r200DestroyContext( __DRIcontextPrivate *driContextPriv )
585 {
586 GET_CURRENT_CONTEXT(ctx);
587 r200ContextPtr rmesa = (r200ContextPtr) driContextPriv->driverPrivate;
588 r200ContextPtr current = ctx ? R200_CONTEXT(ctx) : NULL;
589
590 /* check if we're deleting the currently bound context */
591 if (rmesa == current) {
592 R200_FIREVERTICES( rmesa );
593 _mesa_make_current(NULL, NULL, NULL);
594 }
595
596 /* Free r200 context resources */
597 assert(rmesa); /* should never be null */
598 if ( rmesa ) {
599 GLboolean release_texture_heaps;
600
601
602 release_texture_heaps = (rmesa->radeon.glCtx->Shared->RefCount == 1);
603 _swsetup_DestroyContext( rmesa->radeon.glCtx );
604 _tnl_DestroyContext( rmesa->radeon.glCtx );
605 _vbo_DestroyContext( rmesa->radeon.glCtx );
606 _swrast_DestroyContext( rmesa->radeon.glCtx );
607
608 r200DestroySwtcl( rmesa->radeon.glCtx );
609 r200ReleaseArrays( rmesa->radeon.glCtx, ~0 );
610
611 if (rmesa->dma.current.buf) {
612 r200ReleaseDmaRegion( rmesa, &rmesa->dma.current, __FUNCTION__ );
613 r200FlushCmdBuf( rmesa, __FUNCTION__ );
614 }
615
616 if (rmesa->radeon.state.scissor.pClipRects) {
617 FREE(rmesa->radeon.state.scissor.pClipRects);
618 rmesa->radeon.state.scissor.pClipRects = NULL;
619 }
620
621 if ( release_texture_heaps ) {
622 /* This share group is about to go away, free our private
623 * texture object data.
624 */
625 int i;
626
627 for ( i = 0 ; i < rmesa->radeon.nr_heaps ; i++ ) {
628 driDestroyTextureHeap( rmesa->radeon.texture_heaps[ i ] );
629 rmesa->radeon.texture_heaps[ i ] = NULL;
630 }
631
632 assert( is_empty_list( & rmesa->radeon.swapped ) );
633 }
634
635 /* free the Mesa context */
636 rmesa->radeon.glCtx->DriverCtx = NULL;
637 _mesa_destroy_context( rmesa->radeon.glCtx );
638
639 /* free the option cache */
640 driDestroyOptionCache (&rmesa->radeon.optionCache);
641
642 FREE( rmesa );
643 }
644 }
645
646 /* Force the context `c' to be the current context and associate with it
647 * buffer `b'.
648 */
649 GLboolean
650 r200MakeCurrent( __DRIcontextPrivate *driContextPriv,
651 __DRIdrawablePrivate *driDrawPriv,
652 __DRIdrawablePrivate *driReadPriv )
653 {
654 if ( driContextPriv ) {
655 r200ContextPtr newCtx =
656 (r200ContextPtr) driContextPriv->driverPrivate;
657
658 if (R200_DEBUG & DEBUG_DRI)
659 fprintf(stderr, "%s ctx %p\n", __FUNCTION__, (void *)newCtx->radeon.glCtx);
660
661 newCtx->radeon.dri.readable = driReadPriv;
662
663 if ( newCtx->radeon.dri.drawable != driDrawPriv ||
664 newCtx->radeon.lastStamp != driDrawPriv->lastStamp ) {
665 if (driDrawPriv->swap_interval == (unsigned)-1) {
666 driDrawPriv->vblFlags = (newCtx->radeon.radeonScreen->irq != 0)
667 ? driGetDefaultVBlankFlags(&newCtx->radeon.optionCache)
668 : VBLANK_FLAG_NO_IRQ;
669
670 driDrawableInitVBlank( driDrawPriv );
671 }
672
673 newCtx->radeon.dri.drawable = driDrawPriv;
674
675 radeonSetCliprects(&newCtx->radeon);
676 r200UpdateViewportOffset( newCtx->radeon.glCtx );
677 }
678
679 _mesa_make_current( newCtx->radeon.glCtx,
680 (GLframebuffer *) driDrawPriv->driverPrivate,
681 (GLframebuffer *) driReadPriv->driverPrivate );
682
683 _mesa_update_state( newCtx->radeon.glCtx );
684 r200ValidateState( newCtx->radeon.glCtx );
685
686 } else {
687 if (R200_DEBUG & DEBUG_DRI)
688 fprintf(stderr, "%s ctx is null\n", __FUNCTION__);
689 _mesa_make_current( NULL, NULL, NULL );
690 }
691
692 if (R200_DEBUG & DEBUG_DRI)
693 fprintf(stderr, "End %s\n", __FUNCTION__);
694 return GL_TRUE;
695 }
696
697 /* Force the context `c' to be unbound from its buffer.
698 */
699 GLboolean
700 r200UnbindContext( __DRIcontextPrivate *driContextPriv )
701 {
702 r200ContextPtr rmesa = (r200ContextPtr) driContextPriv->driverPrivate;
703
704 if (R200_DEBUG & DEBUG_DRI)
705 fprintf(stderr, "%s ctx %p\n", __FUNCTION__, (void *)rmesa->radeon.glCtx);
706
707 return GL_TRUE;
708 }