2 Copyright (C) The Weather Channel, Inc. 2002. All Rights Reserved.
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.
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:
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.
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.
28 **************************************************************************/
32 * Keith Whitwell <keith@tungstengraphics.com>
36 #include "main/glheader.h"
37 #include "main/api_arrayelt.h"
38 #include "main/api_exec.h"
39 #include "main/context.h"
40 #include "main/simple_list.h"
41 #include "main/imports.h"
42 #include "main/extensions.h"
43 #include "main/version.h"
44 #include "main/vtxfmt.h"
46 #include "swrast/swrast.h"
47 #include "swrast_setup/swrast_setup.h"
51 #include "tnl/t_pipeline.h"
53 #include "drivers/common/driverfuncs.h"
55 #include "r200_context.h"
56 #include "r200_ioctl.h"
57 #include "r200_state.h"
59 #include "r200_swtcl.h"
61 #include "r200_vertprog.h"
62 #include "radeon_queryobj.h"
63 #include "r200_blit.h"
64 #include "radeon_fog.h"
66 #include "radeon_span.h"
69 #include "xmlpool.h" /* for symbolic values of enum-type options */
71 /* Return various strings for glGetString().
73 static const GLubyte
*r200GetString( struct gl_context
*ctx
, GLenum name
)
75 r200ContextPtr rmesa
= R200_CONTEXT(ctx
);
76 static char buffer
[128];
78 GLuint agp_mode
= (rmesa
->radeon
.radeonScreen
->card_type
== RADEON_CARD_PCI
)? 0 :
79 rmesa
->radeon
.radeonScreen
->AGPMode
;
83 return (GLubyte
*)"Tungsten Graphics, Inc.";
86 offset
= driGetRendererString( buffer
, "R200", agp_mode
);
88 sprintf( & buffer
[ offset
], " %sTCL",
89 !(rmesa
->radeon
.TclFallback
& R200_TCL_FALLBACK_TCL_DISABLE
)
92 return (GLubyte
*)buffer
;
100 extern const struct tnl_pipeline_stage _r200_render_stage
;
101 extern const struct tnl_pipeline_stage _r200_tcl_stage
;
103 static const struct tnl_pipeline_stage
*r200_pipeline
[] = {
105 /* Try and go straight to t&l
109 /* Catch any t&l fallbacks
111 &_tnl_vertex_transform_stage
,
112 &_tnl_normal_transform_stage
,
113 &_tnl_lighting_stage
,
114 &_tnl_fog_coordinate_stage
,
116 &_tnl_texture_transform_stage
,
117 &_tnl_point_attenuation_stage
,
118 &_tnl_vertex_program_stage
,
119 /* Try again to go to tcl?
120 * - no good for asymmetric-twoside (do with multipass)
121 * - no good for asymmetric-unfilled (do with multipass)
122 * - good for material
124 * - need to manipulate a bit of state
126 * - worth it/not worth it?
129 /* Else do them here.
131 /* &_r200_render_stage, */ /* FIXME: bugs with ut2003 */
132 &_tnl_render_stage
, /* FALLBACK: */
138 /* Initialize the driver's misc functions.
140 static void r200InitDriverFuncs( struct dd_function_table
*functions
)
142 functions
->GetString
= r200GetString
;
146 static void r200_get_lock(radeonContextPtr radeon
)
148 r200ContextPtr rmesa
= (r200ContextPtr
)radeon
;
149 drm_radeon_sarea_t
*sarea
= radeon
->sarea
;
151 R200_STATECHANGE( rmesa
, ctx
);
152 if (rmesa
->radeon
.sarea
->tiling_enabled
) {
153 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_COLORPITCH
] |= R200_COLOR_TILE_ENABLE
;
155 else rmesa
->hw
.ctx
.cmd
[CTX_RB3D_COLORPITCH
] &= ~R200_COLOR_TILE_ENABLE
;
157 if ( sarea
->ctx_owner
!= rmesa
->radeon
.dri
.hwContext
) {
158 sarea
->ctx_owner
= rmesa
->radeon
.dri
.hwContext
;
163 static void r200_vtbl_emit_cs_header(struct radeon_cs
*cs
, radeonContextPtr rmesa
)
167 static void r200_emit_query_finish(radeonContextPtr radeon
)
169 BATCH_LOCALS(radeon
);
170 struct radeon_query_object
*query
= radeon
->query
.current
;
172 BEGIN_BATCH_NO_AUTOSTATE(4);
173 OUT_BATCH(CP_PACKET0(RADEON_RB3D_ZPASS_ADDR
, 0));
174 OUT_BATCH_RELOC(0, query
->bo
, query
->curr_offset
, 0, RADEON_GEM_DOMAIN_GTT
, 0);
176 query
->curr_offset
+= sizeof(uint32_t);
177 assert(query
->curr_offset
< RADEON_QUERY_PAGE_SIZE
);
178 query
->emitted_begin
= GL_FALSE
;
181 static void r200_init_vtbl(radeonContextPtr radeon
)
183 radeon
->vtbl
.get_lock
= r200_get_lock
;
184 radeon
->vtbl
.update_viewport_offset
= r200UpdateViewportOffset
;
185 radeon
->vtbl
.emit_cs_header
= r200_vtbl_emit_cs_header
;
186 radeon
->vtbl
.swtcl_flush
= r200_swtcl_flush
;
187 radeon
->vtbl
.fallback
= r200Fallback
;
188 radeon
->vtbl
.update_scissor
= r200_vtbl_update_scissor
;
189 radeon
->vtbl
.emit_query_finish
= r200_emit_query_finish
;
190 radeon
->vtbl
.check_blit
= r200_check_blit
;
191 radeon
->vtbl
.blit
= r200_blit
;
192 radeon
->vtbl
.is_format_renderable
= radeonIsFormatRenderable
;
196 /* Create the device specific rendering context.
198 GLboolean
r200CreateContext( gl_api api
,
199 const struct gl_config
*glVisual
,
200 __DRIcontext
*driContextPriv
,
201 unsigned major_version
,
202 unsigned minor_version
,
205 void *sharedContextPrivate
)
207 __DRIscreen
*sPriv
= driContextPriv
->driScreenPriv
;
208 radeonScreenPtr screen
= (radeonScreenPtr
)(sPriv
->driverPrivate
);
209 struct dd_function_table functions
;
210 r200ContextPtr rmesa
;
211 struct gl_context
*ctx
;
215 /* Flag filtering is handled in dri2CreateContextAttribs.
220 assert(driContextPriv
);
223 /* Allocate the R200 context */
224 rmesa
= calloc(1, sizeof(*rmesa
));
226 *error
= __DRI_CTX_ERROR_NO_MEMORY
;
230 rmesa
->radeon
.radeonScreen
= screen
;
231 r200_init_vtbl(&rmesa
->radeon
);
232 /* init exp fog table data */
233 radeonInitStaticFogData();
235 /* Parse configuration files.
236 * Do this here so that initialMaxAnisotropy is set before we create
237 * the default textures.
239 driParseConfigFiles (&rmesa
->radeon
.optionCache
, &screen
->optionCache
,
240 screen
->driScreen
->myNum
, "r200");
241 rmesa
->radeon
.initialMaxAnisotropy
= driQueryOptionf(&rmesa
->radeon
.optionCache
,
242 "def_max_anisotropy");
244 if ( sPriv
->drm_version
.major
== 1
245 && driQueryOptionb( &rmesa
->radeon
.optionCache
, "hyperz" ) ) {
246 if ( sPriv
->drm_version
.minor
< 13 )
247 fprintf( stderr
, "DRM version 1.%d too old to support HyperZ, "
248 "disabling.\n", sPriv
->drm_version
.minor
);
250 rmesa
->using_hyperz
= GL_TRUE
;
253 if ( sPriv
->drm_version
.minor
>= 15 )
254 rmesa
->texmicrotile
= GL_TRUE
;
256 /* Init default driver functions then plug in our R200-specific functions
257 * (the texture functions are especially important)
259 _mesa_init_driver_functions(&functions
);
260 r200InitDriverFuncs(&functions
);
261 r200InitIoctlFuncs(&functions
);
262 r200InitStateFuncs(&rmesa
->radeon
, &functions
);
263 r200InitTextureFuncs(&rmesa
->radeon
, &functions
);
264 r200InitShaderFuncs(&functions
);
265 radeonInitQueryObjFunctions(&functions
);
267 if (!radeonInitContext(&rmesa
->radeon
, &functions
,
268 glVisual
, driContextPriv
,
269 sharedContextPrivate
)) {
271 *error
= __DRI_CTX_ERROR_NO_MEMORY
;
275 rmesa
->radeon
.swtcl
.RenderIndex
= ~0;
276 rmesa
->radeon
.hw
.all_dirty
= 1;
278 ctx
= &rmesa
->radeon
.glCtx
;
279 /* Initialize the software rasterizer and helper modules.
281 _swrast_CreateContext( ctx
);
282 _vbo_CreateContext( ctx
);
283 _tnl_CreateContext( ctx
);
284 _swsetup_CreateContext( ctx
);
285 _ae_create_context( ctx
);
287 ctx
->Const
.MaxTextureUnits
= driQueryOptioni (&rmesa
->radeon
.optionCache
,
289 ctx
->Const
.FragmentProgram
.MaxTextureImageUnits
= ctx
->Const
.MaxTextureUnits
;
290 ctx
->Const
.MaxTextureCoordUnits
= ctx
->Const
.MaxTextureUnits
;
292 ctx
->Const
.MaxCombinedTextureImageUnits
= ctx
->Const
.MaxTextureUnits
;
294 ctx
->Const
.StripTextureBorder
= GL_TRUE
;
296 /* FIXME: When no memory manager is available we should set this
297 * to some reasonable value based on texture memory pool size */
298 ctx
->Const
.MaxTextureLevels
= 12;
299 ctx
->Const
.Max3DTextureLevels
= 9;
300 ctx
->Const
.MaxCubeTextureLevels
= 12;
301 ctx
->Const
.MaxTextureRectSize
= 2048;
302 ctx
->Const
.MaxRenderbufferSize
= 2048;
304 ctx
->Const
.MaxTextureMaxAnisotropy
= 16.0;
306 /* No wide AA points.
308 ctx
->Const
.MinPointSize
= 1.0;
309 ctx
->Const
.MinPointSizeAA
= 1.0;
310 ctx
->Const
.MaxPointSizeAA
= 1.0;
311 ctx
->Const
.PointSizeGranularity
= 0.0625;
312 ctx
->Const
.MaxPointSize
= 2047.0;
314 /* mesa initialization problem - _mesa_init_point was already called */
315 ctx
->Point
.MaxSize
= ctx
->Const
.MaxPointSize
;
317 ctx
->Const
.MinLineWidth
= 1.0;
318 ctx
->Const
.MinLineWidthAA
= 1.0;
319 ctx
->Const
.MaxLineWidth
= 10.0;
320 ctx
->Const
.MaxLineWidthAA
= 10.0;
321 ctx
->Const
.LineWidthGranularity
= 0.0625;
323 ctx
->Const
.VertexProgram
.MaxNativeInstructions
= R200_VSF_MAX_INST
;
324 ctx
->Const
.VertexProgram
.MaxNativeAttribs
= 12;
325 ctx
->Const
.VertexProgram
.MaxNativeTemps
= R200_VSF_MAX_TEMPS
;
326 ctx
->Const
.VertexProgram
.MaxNativeParameters
= R200_VSF_MAX_PARAM
;
327 ctx
->Const
.VertexProgram
.MaxNativeAddressRegs
= 1;
329 ctx
->Const
.MaxDrawBuffers
= 1;
330 ctx
->Const
.MaxColorAttachments
= 1;
332 ctx
->ShaderCompilerOptions
[MESA_SHADER_VERTEX
].PreferDP4
= GL_TRUE
;
334 /* Install the customized pipeline:
336 _tnl_destroy_pipeline( ctx
);
337 _tnl_install_pipeline( ctx
, r200_pipeline
);
339 /* Try and keep materials and vertices separate:
341 /* _tnl_isolate_materials( ctx, GL_TRUE ); */
344 /* Configure swrast and TNL to match hardware characteristics:
346 _swrast_allow_pixel_fog( ctx
, GL_FALSE
);
347 _swrast_allow_vertex_fog( ctx
, GL_TRUE
);
348 _tnl_allow_pixel_fog( ctx
, GL_FALSE
);
349 _tnl_allow_vertex_fog( ctx
, GL_TRUE
);
352 for ( i
= 0 ; i
< R200_MAX_TEXTURE_UNITS
; i
++ ) {
353 _math_matrix_ctr( &rmesa
->TexGenMatrix
[i
] );
354 _math_matrix_set_identity( &rmesa
->TexGenMatrix
[i
] );
356 _math_matrix_ctr( &rmesa
->tmpmat
);
357 _math_matrix_set_identity( &rmesa
->tmpmat
);
359 ctx
->Extensions
.ARB_half_float_pixel
= true;
360 ctx
->Extensions
.ARB_occlusion_query
= true;
361 ctx
->Extensions
.ARB_texture_border_clamp
= true;
362 ctx
->Extensions
.ARB_texture_env_combine
= true;
363 ctx
->Extensions
.ARB_texture_env_dot3
= true;
364 ctx
->Extensions
.ARB_texture_env_crossbar
= true;
365 ctx
->Extensions
.EXT_blend_color
= true;
366 ctx
->Extensions
.EXT_blend_minmax
= true;
367 ctx
->Extensions
.EXT_packed_depth_stencil
= true;
368 ctx
->Extensions
.EXT_texture_env_dot3
= true;
369 ctx
->Extensions
.EXT_texture_filter_anisotropic
= true;
370 ctx
->Extensions
.EXT_texture_mirror_clamp
= true;
371 ctx
->Extensions
.ATI_texture_env_combine3
= true;
372 ctx
->Extensions
.ATI_texture_mirror_once
= true;
373 ctx
->Extensions
.MESA_pack_invert
= true;
374 ctx
->Extensions
.NV_texture_rectangle
= true;
375 ctx
->Extensions
.OES_EGL_image
= true;
376 ctx
->Extensions
.ARB_occlusion_query
= true;
378 if (!(rmesa
->radeon
.radeonScreen
->chip_flags
& R200_CHIPSET_YCBCR_BROKEN
)) {
379 /* yuv textures don't work with some chips - R200 / rv280 okay so far
380 others get the bit ordering right but don't actually do YUV-RGB conversion */
381 ctx
->Extensions
.MESA_ycbcr_texture
= true;
383 if (rmesa
->radeon
.glCtx
.Mesa_DXTn
) {
384 ctx
->Extensions
.EXT_texture_compression_s3tc
= true;
385 ctx
->Extensions
.ANGLE_texture_compression_dxt
= true;
387 else if (driQueryOptionb (&rmesa
->radeon
.optionCache
, "force_s3tc_enable")) {
388 ctx
->Extensions
.EXT_texture_compression_s3tc
= true;
389 ctx
->Extensions
.ANGLE_texture_compression_dxt
= true;
392 ctx
->Extensions
.ARB_texture_cube_map
= true;
394 ctx
->Extensions
.EXT_blend_equation_separate
= true;
395 ctx
->Extensions
.EXT_blend_func_separate
= true;
397 ctx
->Extensions
.ARB_vertex_program
= true;
398 ctx
->Extensions
.EXT_gpu_program_parameters
= true;
400 ctx
->Extensions
.ATI_fragment_shader
= (ctx
->Const
.MaxTextureUnits
== 6);
402 ctx
->Extensions
.ARB_point_sprite
= true;
403 ctx
->Extensions
.EXT_point_parameters
= true;
406 r200InitDriverFuncs( ctx
);
407 r200InitIoctlFuncs( ctx
);
408 r200InitStateFuncs( ctx
);
409 r200InitTextureFuncs( ctx
);
411 /* plug in a few more device driver functions */
412 /* XXX these should really go right after _mesa_init_driver_functions() */
413 radeon_fbo_init(&rmesa
->radeon
);
414 radeonInitSpanFuncs( ctx
);
415 r200InitTnlFuncs( ctx
);
416 r200InitState( rmesa
);
417 r200InitSwtcl( ctx
);
419 rmesa
->prefer_gart_client_texturing
=
420 (getenv("R200_GART_CLIENT_TEXTURES") != 0);
422 tcl_mode
= driQueryOptioni(&rmesa
->radeon
.optionCache
, "tcl_mode");
423 if (driQueryOptionb(&rmesa
->radeon
.optionCache
, "no_rast")) {
424 fprintf(stderr
, "disabling 3D acceleration\n");
425 FALLBACK(rmesa
, R200_FALLBACK_DISABLE
, 1);
427 else if (tcl_mode
== DRI_CONF_TCL_SW
|| getenv("R200_NO_TCL") ||
428 !(rmesa
->radeon
.radeonScreen
->chip_flags
& RADEON_CHIPSET_TCL
)) {
429 if (rmesa
->radeon
.radeonScreen
->chip_flags
& RADEON_CHIPSET_TCL
) {
430 rmesa
->radeon
.radeonScreen
->chip_flags
&= ~RADEON_CHIPSET_TCL
;
431 fprintf(stderr
, "Disabling HW TCL support\n");
433 TCL_FALLBACK(&rmesa
->radeon
.glCtx
, R200_TCL_FALLBACK_TCL_DISABLE
, 1);
436 _mesa_compute_version(ctx
);
438 /* Exec table initialization requires the version to be computed */
439 _mesa_initialize_dispatch_tables(ctx
);
440 _mesa_initialize_vbo_vtxfmt(ctx
);
442 *error
= __DRI_CTX_ERROR_SUCCESS
;
447 void r200DestroyContext( __DRIcontext
*driContextPriv
)
450 r200ContextPtr rmesa
= (r200ContextPtr
)driContextPriv
->driverPrivate
;
453 for ( i
= 0 ; i
< R200_MAX_TEXTURE_UNITS
; i
++ ) {
454 _math_matrix_dtr( &rmesa
->TexGenMatrix
[i
] );
457 radeonDestroyContext(driContextPriv
);