radeon: move debug symbol add DRI2
[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_init_vtbl(radeonContextPtr radeon)
276 {
277 radeon->vtbl.get_lock = r200_get_lock;
278 radeon->vtbl.update_viewport_offset = r200UpdateViewportOffset;
279 radeon->vtbl.flush = r200_vtbl_flush;
280 radeon->vtbl.set_all_dirty = r200_vtbl_set_all_dirty;
281 radeon->vtbl.update_draw_buffer = r200UpdateDrawBuffer;
282 }
283
284 /* Create the device specific rendering context.
285 */
286 GLboolean r200CreateContext( const __GLcontextModes *glVisual,
287 __DRIcontextPrivate *driContextPriv,
288 void *sharedContextPrivate)
289 {
290 __DRIscreenPrivate *sPriv = driContextPriv->driScreenPriv;
291 radeonScreenPtr screen = (radeonScreenPtr)(sPriv->private);
292 struct dd_function_table functions;
293 r200ContextPtr rmesa;
294 GLcontext *ctx, *shareCtx;
295 int i;
296 int tcl_mode, fthrottle_mode;
297
298 assert(glVisual);
299 assert(driContextPriv);
300 assert(screen);
301
302 /* Allocate the R200 context */
303 rmesa = (r200ContextPtr) CALLOC( sizeof(*rmesa) );
304 if ( !rmesa )
305 return GL_FALSE;
306
307 r200_init_vtbl(&rmesa->radeon);
308 /* init exp fog table data */
309 r200InitStaticFogData();
310
311 /* Parse configuration files.
312 * Do this here so that initialMaxAnisotropy is set before we create
313 * the default textures.
314 */
315 driParseConfigFiles (&rmesa->radeon.optionCache, &screen->optionCache,
316 screen->driScreen->myNum, "r200");
317 rmesa->radeon.initialMaxAnisotropy = driQueryOptionf(&rmesa->radeon.optionCache,
318 "def_max_anisotropy");
319
320 if ( driQueryOptionb( &rmesa->radeon.optionCache, "hyperz" ) ) {
321 if ( sPriv->drm_version.minor < 13 )
322 fprintf( stderr, "DRM version 1.%d too old to support HyperZ, "
323 "disabling.\n", sPriv->drm_version.minor );
324 else
325 rmesa->using_hyperz = GL_TRUE;
326 }
327
328 if ( sPriv->drm_version.minor >= 15 )
329 rmesa->texmicrotile = GL_TRUE;
330
331 /* Init default driver functions then plug in our R200-specific functions
332 * (the texture functions are especially important)
333 */
334 _mesa_init_driver_functions(&functions);
335 r200InitDriverFuncs(&functions);
336 r200InitIoctlFuncs(&functions);
337 r200InitStateFuncs(&functions);
338 r200InitTextureFuncs(&functions);
339 r200InitShaderFuncs(&functions);
340
341 /* Allocate and initialize the Mesa context */
342 if (sharedContextPrivate)
343 shareCtx = ((r200ContextPtr) sharedContextPrivate)->radeon.glCtx;
344 else
345 shareCtx = NULL;
346 rmesa->radeon.glCtx = _mesa_create_context(glVisual, shareCtx,
347 &functions, (void *) rmesa);
348 if (!rmesa->radeon.glCtx) {
349 FREE(rmesa);
350 return GL_FALSE;
351 }
352 driContextPriv->driverPrivate = rmesa;
353
354 /* Init r200 context data */
355 rmesa->radeon.dri.context = driContextPriv;
356 rmesa->radeon.dri.screen = sPriv;
357 rmesa->radeon.dri.drawable = NULL; /* Set by XMesaMakeCurrent */
358 rmesa->radeon.dri.hwContext = driContextPriv->hHWContext;
359 rmesa->radeon.dri.hwLock = &sPriv->pSAREA->lock;
360 rmesa->radeon.dri.fd = sPriv->fd;
361 rmesa->radeon.dri.drmMinor = sPriv->drm_version.minor;
362
363 rmesa->radeon.radeonScreen = screen;
364 rmesa->radeon.sarea = (drm_radeon_sarea_t *)((GLubyte *)sPriv->pSAREA +
365 screen->sarea_priv_offset);
366
367
368 rmesa->dma.buf0_address = rmesa->radeon.radeonScreen->buffers->list[0].address;
369
370 (void) memset( rmesa->radeon.texture_heaps, 0, sizeof( rmesa->radeon.texture_heaps ) );
371 make_empty_list( & rmesa->radeon.swapped );
372
373 rmesa->radeon.nr_heaps = 1 /* screen->numTexHeaps */ ;
374 assert(rmesa->radeon.nr_heaps < RADEON_NR_TEX_HEAPS);
375 for ( i = 0 ; i < rmesa->radeon.nr_heaps ; i++ ) {
376 rmesa->radeon.texture_heaps[i] = driCreateTextureHeap( i, rmesa,
377 screen->texSize[i],
378 12,
379 RADEON_NR_TEX_REGIONS,
380 (drmTextureRegionPtr)rmesa->radeon.sarea->tex_list[i],
381 & rmesa->radeon.sarea->tex_age[i],
382 & rmesa->radeon.swapped,
383 sizeof( radeonTexObj ),
384 (destroy_texture_object_t *) r200DestroyTexObj );
385 }
386 rmesa->radeon.texture_depth = driQueryOptioni (&rmesa->radeon.optionCache,
387 "texture_depth");
388 if (rmesa->radeon.texture_depth == DRI_CONF_TEXTURE_DEPTH_FB)
389 rmesa->radeon.texture_depth = ( screen->cpp == 4 ) ?
390 DRI_CONF_TEXTURE_DEPTH_32 : DRI_CONF_TEXTURE_DEPTH_16;
391
392 rmesa->swtcl.RenderIndex = ~0;
393 rmesa->hw.all_dirty = 1;
394
395 /* Set the maximum texture size small enough that we can guarentee that
396 * all texture units can bind a maximal texture and have all of them in
397 * texturable memory at once. Depending on the allow_large_textures driconf
398 * setting allow larger textures.
399 */
400
401 ctx = rmesa->radeon.glCtx;
402 ctx->Const.MaxTextureUnits = driQueryOptioni (&rmesa->radeon.optionCache,
403 "texture_units");
404 ctx->Const.MaxTextureImageUnits = ctx->Const.MaxTextureUnits;
405 ctx->Const.MaxTextureCoordUnits = ctx->Const.MaxTextureUnits;
406
407 i = driQueryOptioni( &rmesa->radeon.optionCache, "allow_large_textures");
408
409 driCalculateMaxTextureLevels( rmesa->radeon.texture_heaps,
410 rmesa->radeon.nr_heaps,
411 & ctx->Const,
412 4,
413 11, /* max 2D texture size is 2048x2048 */
414 #if ENABLE_HW_3D_TEXTURE
415 8, /* max 3D texture size is 256^3 */
416 #else
417 0, /* 3D textures unsupported */
418 #endif
419 11, /* max cube texture size is 2048x2048 */
420 11, /* max texture rectangle size is 2048x2048 */
421 12,
422 GL_FALSE,
423 i );
424
425 ctx->Const.MaxTextureMaxAnisotropy = 16.0;
426
427 /* No wide AA points.
428 */
429 ctx->Const.MinPointSize = 1.0;
430 ctx->Const.MinPointSizeAA = 1.0;
431 ctx->Const.MaxPointSizeAA = 1.0;
432 ctx->Const.PointSizeGranularity = 0.0625;
433 if (rmesa->radeon.radeonScreen->drmSupportsPointSprites)
434 ctx->Const.MaxPointSize = 2047.0;
435 else
436 ctx->Const.MaxPointSize = 1.0;
437
438 /* mesa initialization problem - _mesa_init_point was already called */
439 ctx->Point.MaxSize = ctx->Const.MaxPointSize;
440
441 ctx->Const.MinLineWidth = 1.0;
442 ctx->Const.MinLineWidthAA = 1.0;
443 ctx->Const.MaxLineWidth = 10.0;
444 ctx->Const.MaxLineWidthAA = 10.0;
445 ctx->Const.LineWidthGranularity = 0.0625;
446
447 ctx->Const.VertexProgram.MaxNativeInstructions = R200_VSF_MAX_INST;
448 ctx->Const.VertexProgram.MaxNativeAttribs = 12;
449 ctx->Const.VertexProgram.MaxNativeTemps = R200_VSF_MAX_TEMPS;
450 ctx->Const.VertexProgram.MaxNativeParameters = R200_VSF_MAX_PARAM;
451 ctx->Const.VertexProgram.MaxNativeAddressRegs = 1;
452
453 /* Initialize the software rasterizer and helper modules.
454 */
455 _swrast_CreateContext( ctx );
456 _vbo_CreateContext( ctx );
457 _tnl_CreateContext( ctx );
458 _swsetup_CreateContext( ctx );
459 _ae_create_context( ctx );
460
461 /* Install the customized pipeline:
462 */
463 _tnl_destroy_pipeline( ctx );
464 _tnl_install_pipeline( ctx, r200_pipeline );
465
466 /* Try and keep materials and vertices separate:
467 */
468 /* _tnl_isolate_materials( ctx, GL_TRUE ); */
469
470
471 /* Configure swrast and TNL to match hardware characteristics:
472 */
473 _swrast_allow_pixel_fog( ctx, GL_FALSE );
474 _swrast_allow_vertex_fog( ctx, GL_TRUE );
475 _tnl_allow_pixel_fog( ctx, GL_FALSE );
476 _tnl_allow_vertex_fog( ctx, GL_TRUE );
477
478
479 for ( i = 0 ; i < R200_MAX_TEXTURE_UNITS ; i++ ) {
480 _math_matrix_ctr( &rmesa->TexGenMatrix[i] );
481 _math_matrix_set_identity( &rmesa->TexGenMatrix[i] );
482 }
483 _math_matrix_ctr( &rmesa->tmpmat );
484 _math_matrix_set_identity( &rmesa->tmpmat );
485
486 driInitExtensions( ctx, card_extensions, GL_TRUE );
487 if (!(rmesa->radeon.radeonScreen->chip_flags & R200_CHIPSET_YCBCR_BROKEN)) {
488 /* yuv textures don't work with some chips - R200 / rv280 okay so far
489 others get the bit ordering right but don't actually do YUV-RGB conversion */
490 _mesa_enable_extension( ctx, "GL_MESA_ycbcr_texture" );
491 }
492 if (rmesa->radeon.glCtx->Mesa_DXTn) {
493 _mesa_enable_extension( ctx, "GL_EXT_texture_compression_s3tc" );
494 _mesa_enable_extension( ctx, "GL_S3_s3tc" );
495 }
496 else if (driQueryOptionb (&rmesa->radeon.optionCache, "force_s3tc_enable")) {
497 _mesa_enable_extension( ctx, "GL_EXT_texture_compression_s3tc" );
498 }
499
500 if (rmesa->radeon.radeonScreen->drmSupportsCubeMapsR200)
501 _mesa_enable_extension( ctx, "GL_ARB_texture_cube_map" );
502 if (rmesa->radeon.radeonScreen->drmSupportsBlendColor) {
503 driInitExtensions( ctx, blend_extensions, GL_FALSE );
504 }
505 if(rmesa->radeon.radeonScreen->drmSupportsVertexProgram)
506 driInitSingleExtension( ctx, ARB_vp_extension );
507 if(driQueryOptionb(&rmesa->radeon.optionCache, "nv_vertex_program"))
508 driInitSingleExtension( ctx, NV_vp_extension );
509
510 if ((ctx->Const.MaxTextureUnits == 6) && rmesa->radeon.radeonScreen->drmSupportsFragShader)
511 driInitSingleExtension( ctx, ATI_fs_extension );
512 if (rmesa->radeon.radeonScreen->drmSupportsPointSprites)
513 driInitExtensions( ctx, point_extensions, GL_FALSE );
514 #if 0
515 r200InitDriverFuncs( ctx );
516 r200InitIoctlFuncs( ctx );
517 r200InitStateFuncs( ctx );
518 r200InitTextureFuncs( ctx );
519 #endif
520 /* plug in a few more device driver functions */
521 /* XXX these should really go right after _mesa_init_driver_functions() */
522 r200InitPixelFuncs( ctx );
523 r200InitSpanFuncs( ctx );
524 r200InitTnlFuncs( ctx );
525 r200InitState( rmesa );
526 r200InitSwtcl( ctx );
527
528 fthrottle_mode = driQueryOptioni(&rmesa->radeon.optionCache, "fthrottle_mode");
529 rmesa->radeon.iw.irq_seq = -1;
530 rmesa->radeon.irqsEmitted = 0;
531 rmesa->radeon.do_irqs = (fthrottle_mode == DRI_CONF_FTHROTTLE_IRQS &&
532 rmesa->radeon.radeonScreen->irq);
533
534 rmesa->radeon.do_usleeps = (fthrottle_mode == DRI_CONF_FTHROTTLE_USLEEPS);
535
536 if (!rmesa->radeon.do_irqs)
537 fprintf(stderr,
538 "IRQ's not enabled, falling back to %s: %d %d\n",
539 rmesa->radeon.do_usleeps ? "usleeps" : "busy waits",
540 fthrottle_mode,
541 rmesa->radeon.radeonScreen->irq);
542
543 rmesa->prefer_gart_client_texturing =
544 (getenv("R200_GART_CLIENT_TEXTURES") != 0);
545
546 (*sPriv->systemTime->getUST)( & rmesa->radeon.swap_ust );
547
548
549 #if DO_DEBUG
550 R200_DEBUG = driParseDebugString( getenv( "R200_DEBUG" ),
551 debug_control );
552 R200_DEBUG |= driParseDebugString( getenv( "RADEON_DEBUG" ),
553 debug_control );
554 #endif
555
556 tcl_mode = driQueryOptioni(&rmesa->radeon.optionCache, "tcl_mode");
557 if (driQueryOptionb(&rmesa->radeon.optionCache, "no_rast")) {
558 fprintf(stderr, "disabling 3D acceleration\n");
559 FALLBACK(rmesa, R200_FALLBACK_DISABLE, 1);
560 }
561 else if (tcl_mode == DRI_CONF_TCL_SW || getenv("R200_NO_TCL") ||
562 !(rmesa->radeon.radeonScreen->chip_flags & RADEON_CHIPSET_TCL)) {
563 if (rmesa->radeon.radeonScreen->chip_flags & RADEON_CHIPSET_TCL) {
564 rmesa->radeon.radeonScreen->chip_flags &= ~RADEON_CHIPSET_TCL;
565 fprintf(stderr, "Disabling HW TCL support\n");
566 }
567 TCL_FALLBACK(rmesa->radeon.glCtx, R200_TCL_FALLBACK_TCL_DISABLE, 1);
568 }
569
570 return GL_TRUE;
571 }
572
573
574 /* Destroy the device specific context.
575 */
576 /* Destroy the Mesa and driver specific context data.
577 */
578 void r200DestroyContext( __DRIcontextPrivate *driContextPriv )
579 {
580 GET_CURRENT_CONTEXT(ctx);
581 r200ContextPtr rmesa = (r200ContextPtr) driContextPriv->driverPrivate;
582 r200ContextPtr current = ctx ? R200_CONTEXT(ctx) : NULL;
583
584 /* check if we're deleting the currently bound context */
585 if (rmesa == current) {
586 R200_FIREVERTICES( rmesa );
587 _mesa_make_current(NULL, NULL, NULL);
588 }
589
590 /* Free r200 context resources */
591 assert(rmesa); /* should never be null */
592 if ( rmesa ) {
593 GLboolean release_texture_heaps;
594
595
596 release_texture_heaps = (rmesa->radeon.glCtx->Shared->RefCount == 1);
597 _swsetup_DestroyContext( rmesa->radeon.glCtx );
598 _tnl_DestroyContext( rmesa->radeon.glCtx );
599 _vbo_DestroyContext( rmesa->radeon.glCtx );
600 _swrast_DestroyContext( rmesa->radeon.glCtx );
601
602 r200DestroySwtcl( rmesa->radeon.glCtx );
603 r200ReleaseArrays( rmesa->radeon.glCtx, ~0 );
604
605 if (rmesa->dma.current.buf) {
606 r200ReleaseDmaRegion( rmesa, &rmesa->dma.current, __FUNCTION__ );
607 r200FlushCmdBuf( rmesa, __FUNCTION__ );
608 }
609
610 if (rmesa->radeon.state.scissor.pClipRects) {
611 FREE(rmesa->radeon.state.scissor.pClipRects);
612 rmesa->radeon.state.scissor.pClipRects = NULL;
613 }
614
615 if ( release_texture_heaps ) {
616 /* This share group is about to go away, free our private
617 * texture object data.
618 */
619 int i;
620
621 for ( i = 0 ; i < rmesa->radeon.nr_heaps ; i++ ) {
622 driDestroyTextureHeap( rmesa->radeon.texture_heaps[ i ] );
623 rmesa->radeon.texture_heaps[ i ] = NULL;
624 }
625
626 assert( is_empty_list( & rmesa->radeon.swapped ) );
627 }
628
629 /* free the Mesa context */
630 rmesa->radeon.glCtx->DriverCtx = NULL;
631 _mesa_destroy_context( rmesa->radeon.glCtx );
632
633 /* free the option cache */
634 driDestroyOptionCache (&rmesa->radeon.optionCache);
635
636 FREE( rmesa );
637 }
638 }
639
640 /* Force the context `c' to be the current context and associate with it
641 * buffer `b'.
642 */
643 GLboolean
644 r200MakeCurrent( __DRIcontextPrivate *driContextPriv,
645 __DRIdrawablePrivate *driDrawPriv,
646 __DRIdrawablePrivate *driReadPriv )
647 {
648 if ( driContextPriv ) {
649 r200ContextPtr newCtx =
650 (r200ContextPtr) driContextPriv->driverPrivate;
651
652 if (R200_DEBUG & DEBUG_DRI)
653 fprintf(stderr, "%s ctx %p\n", __FUNCTION__, (void *)newCtx->radeon.glCtx);
654
655 newCtx->radeon.dri.readable = driReadPriv;
656
657 if ( newCtx->radeon.dri.drawable != driDrawPriv ||
658 newCtx->radeon.lastStamp != driDrawPriv->lastStamp ) {
659 if (driDrawPriv->swap_interval == (unsigned)-1) {
660 driDrawPriv->vblFlags = (newCtx->radeon.radeonScreen->irq != 0)
661 ? driGetDefaultVBlankFlags(&newCtx->radeon.optionCache)
662 : VBLANK_FLAG_NO_IRQ;
663
664 driDrawableInitVBlank( driDrawPriv );
665 }
666
667 newCtx->radeon.dri.drawable = driDrawPriv;
668
669 r200SetCliprects(newCtx);
670 r200UpdateViewportOffset( newCtx->radeon.glCtx );
671 }
672
673 _mesa_make_current( newCtx->radeon.glCtx,
674 (GLframebuffer *) driDrawPriv->driverPrivate,
675 (GLframebuffer *) driReadPriv->driverPrivate );
676
677 _mesa_update_state( newCtx->radeon.glCtx );
678 r200ValidateState( newCtx->radeon.glCtx );
679
680 } else {
681 if (R200_DEBUG & DEBUG_DRI)
682 fprintf(stderr, "%s ctx is null\n", __FUNCTION__);
683 _mesa_make_current( NULL, NULL, NULL );
684 }
685
686 if (R200_DEBUG & DEBUG_DRI)
687 fprintf(stderr, "End %s\n", __FUNCTION__);
688 return GL_TRUE;
689 }
690
691 /* Force the context `c' to be unbound from its buffer.
692 */
693 GLboolean
694 r200UnbindContext( __DRIcontextPrivate *driContextPriv )
695 {
696 r200ContextPtr rmesa = (r200ContextPtr) driContextPriv->driverPrivate;
697
698 if (R200_DEBUG & DEBUG_DRI)
699 fprintf(stderr, "%s ctx %p\n", __FUNCTION__, (void *)rmesa->radeon.glCtx);
700
701 return GL_TRUE;
702 }