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 **************************************************************************/
33 * \author Keith Whitwell <keith@tungstengraphics.com>
35 * \author Nicolai Haehnle <prefect_@gmx.net>
38 #include "main/glheader.h"
39 #include "main/api_arrayelt.h"
40 #include "main/context.h"
41 #include "main/simple_list.h"
42 #include "main/imports.h"
43 #include "main/matrix.h"
44 #include "main/extensions.h"
45 #include "main/state.h"
46 #include "main/bufferobj.h"
48 #include "swrast/swrast.h"
49 #include "swrast_setup/swrast_setup.h"
53 #include "tnl/t_pipeline.h"
54 #include "tnl/t_vp_build.h"
56 #include "drivers/common/driverfuncs.h"
58 #include "radeon_ioctl.h"
59 #include "radeon_span.h"
60 #include "r300_context.h"
61 #include "r300_cmdbuf.h"
62 #include "r300_mipmap_tree.h"
63 #include "r300_state.h"
64 #include "r300_ioctl.h"
66 #include "r300_emit.h"
67 #include "r300_swtcl.h"
68 #include "radeon_bo_legacy.h"
73 #include "xmlpool.h" /* for symbolic values of enum-type options */
75 /* hw_tcl_on derives from future_hw_tcl_on when its safe to change it. */
76 int future_hw_tcl_on
= 1;
79 #define need_GL_EXT_stencil_two_side
80 #define need_GL_ARB_multisample
81 #define need_GL_ARB_point_parameters
82 #define need_GL_ARB_texture_compression
83 #define need_GL_ARB_vertex_buffer_object
84 #define need_GL_ARB_vertex_program
85 #define need_GL_EXT_blend_minmax
86 //#define need_GL_EXT_fog_coord
87 #define need_GL_EXT_multi_draw_arrays
88 #define need_GL_EXT_secondary_color
89 #define need_GL_EXT_blend_equation_separate
90 #define need_GL_EXT_blend_func_separate
91 #define need_GL_EXT_gpu_program_parameters
92 #define need_GL_NV_vertex_program
93 #include "extension_helper.h"
95 const struct dri_extension card_extensions
[] = {
97 {"GL_ARB_depth_texture", NULL
},
98 {"GL_ARB_fragment_program", NULL
},
99 {"GL_ARB_multisample", GL_ARB_multisample_functions
},
100 {"GL_ARB_multitexture", NULL
},
101 {"GL_ARB_point_parameters", GL_ARB_point_parameters_functions
},
102 {"GL_ARB_shadow", NULL
},
103 {"GL_ARB_shadow_ambient", NULL
},
104 {"GL_ARB_texture_border_clamp", NULL
},
105 {"GL_ARB_texture_compression", GL_ARB_texture_compression_functions
},
106 {"GL_ARB_texture_cube_map", NULL
},
107 {"GL_ARB_texture_env_add", NULL
},
108 {"GL_ARB_texture_env_combine", NULL
},
109 {"GL_ARB_texture_env_crossbar", NULL
},
110 {"GL_ARB_texture_env_dot3", NULL
},
111 {"GL_ARB_texture_mirrored_repeat", NULL
},
112 {"GL_ARB_vertex_buffer_object", GL_ARB_vertex_buffer_object_functions
},
113 {"GL_ARB_vertex_program", GL_ARB_vertex_program_functions
},
114 {"GL_EXT_blend_equation_separate", GL_EXT_blend_equation_separate_functions
},
115 {"GL_EXT_blend_func_separate", GL_EXT_blend_func_separate_functions
},
116 {"GL_EXT_blend_minmax", GL_EXT_blend_minmax_functions
},
117 {"GL_EXT_blend_subtract", NULL
},
118 // {"GL_EXT_fog_coord", GL_EXT_fog_coord_functions },
119 {"GL_EXT_multi_draw_arrays", GL_EXT_multi_draw_arrays_functions
},
120 {"GL_EXT_gpu_program_parameters", GL_EXT_gpu_program_parameters_functions
},
121 {"GL_EXT_secondary_color", GL_EXT_secondary_color_functions
},
122 {"GL_EXT_shadow_funcs", NULL
},
123 {"GL_EXT_stencil_two_side", GL_EXT_stencil_two_side_functions
},
124 {"GL_EXT_stencil_wrap", NULL
},
125 {"GL_EXT_texture_edge_clamp", NULL
},
126 {"GL_EXT_texture_env_combine", NULL
},
127 {"GL_EXT_texture_env_dot3", NULL
},
128 {"GL_EXT_texture_filter_anisotropic", NULL
},
129 {"GL_EXT_texture_lod_bias", NULL
},
130 {"GL_EXT_texture_mirror_clamp", NULL
},
131 {"GL_EXT_texture_rectangle", NULL
},
132 {"GL_ATI_texture_env_combine3", NULL
},
133 {"GL_ATI_texture_mirror_once", NULL
},
134 {"GL_MESA_pack_invert", NULL
},
135 {"GL_MESA_ycbcr_texture", NULL
},
136 {"GL_MESAX_texture_float", NULL
},
137 {"GL_NV_blend_square", NULL
},
138 {"GL_NV_vertex_program", GL_NV_vertex_program_functions
},
139 {"GL_SGIS_generate_mipmap", NULL
},
144 extern struct tnl_pipeline_stage _r300_render_stage
;
145 extern const struct tnl_pipeline_stage _r300_tcl_stage
;
147 static const struct tnl_pipeline_stage
*r300_pipeline
[] = {
149 /* Try and go straight to t&l
153 /* Catch any t&l fallbacks
155 &_tnl_vertex_transform_stage
,
156 &_tnl_normal_transform_stage
,
157 &_tnl_lighting_stage
,
158 &_tnl_fog_coordinate_stage
,
160 &_tnl_texture_transform_stage
,
161 &_tnl_vertex_program_stage
,
163 /* Try again to go to tcl?
164 * - no good for asymmetric-twoside (do with multipass)
165 * - no good for asymmetric-unfilled (do with multipass)
166 * - good for material
168 * - need to manipulate a bit of state
170 * - worth it/not worth it?
173 /* Else do them here.
176 &_tnl_render_stage
, /* FALLBACK */
180 static void r300RunPipeline(GLcontext
* ctx
)
182 _mesa_lock_context_textures(ctx
);
185 _mesa_update_state_locked(ctx
);
187 _tnl_run_pipeline(ctx
);
188 _mesa_unlock_context_textures(ctx
);
191 static void r300_get_lock(radeonContextPtr rmesa
)
193 drm_radeon_sarea_t
*sarea
= rmesa
->sarea
;
195 if (sarea
->ctx_owner
!= rmesa
->dri
.hwContext
) {
196 sarea
->ctx_owner
= rmesa
->dri
.hwContext
;
197 if (!rmesa
->radeonScreen
->kernel_mm
)
198 radeon_bo_legacy_texture_age(rmesa
->radeonScreen
->bom
);
202 static void r300_vtbl_flush(GLcontext
*ctx
)
207 static void r300_vtbl_set_all_dirty(GLcontext
*ctx
)
209 r300ContextPtr rmesa
= R300_CONTEXT(ctx
);
210 rmesa
->hw
.all_dirty
= GL_TRUE
;
213 extern int cs_write_dword(struct radeon_cs
*cs
, uint32_t dword
);
215 static void r300_vtbl_emit_cs_header(struct radeon_cs
*cs
, radeonContextPtr rmesa
)
217 /* please flush pipe do all pending work */
218 cs_write_dword(cs
, cmdpacket0(rmesa
->radeonScreen
,
219 R300_SC_SCREENDOOR
, 1));
220 cs_write_dword(cs
, 0x0);
221 cs_write_dword(cs
, cmdpacket0(rmesa
->radeonScreen
,
222 R300_SC_SCREENDOOR
, 1));
223 cs_write_dword(cs
, 0x00FFFFFF);
224 cs_write_dword(cs
, cmdpacket0(rmesa
->radeonScreen
,
226 cs_write_dword(cs
, 0x0);
227 cs_write_dword(cs
, cmdpacket0(rmesa
->radeonScreen
,
229 cs_write_dword(cs
, 0x0);
230 cs_write_dword(cs
, cmdpacket0(rmesa
->radeonScreen
,
232 cs_write_dword(cs
, 0x0);
233 cs_write_dword(cs
, cmdwait(rmesa
->radeonScreen
, R300_WAIT_3D
));
234 cs_write_dword(cs
, cmdpacket0(rmesa
->radeonScreen
,
235 R300_RB3D_DSTCACHE_CTLSTAT
, 1));
236 cs_write_dword(cs
, R300_RB3D_DSTCACHE_CTLSTAT_DC_FLUSH_FLUSH_DIRTY_3D
);
237 cs_write_dword(cs
, cmdpacket0(rmesa
->radeonScreen
,
238 R300_ZB_ZCACHE_CTLSTAT
, 1));
239 cs_write_dword(cs
, R300_ZB_ZCACHE_CTLSTAT_ZC_FLUSH_FLUSH_AND_FREE
);
240 cs_write_dword(cs
, cmdwait(rmesa
->radeonScreen
,
241 R300_WAIT_3D
| R300_WAIT_3D_CLEAN
));
244 static void r300_init_vtbl(radeonContextPtr radeon
)
246 radeon
->vtbl
.get_lock
= r300_get_lock
;
247 radeon
->vtbl
.update_viewport_offset
= r300UpdateViewportOffset
;
248 radeon
->vtbl
.flush
= r300_vtbl_flush
;
249 radeon
->vtbl
.set_all_dirty
= r300_vtbl_set_all_dirty
;
250 radeon
->vtbl
.update_draw_buffer
= r300UpdateDrawBuffer
;
251 radeon
->vtbl
.emit_cs_header
= r300_vtbl_emit_cs_header
;
255 /* Create the device specific rendering context.
257 GLboolean
r300CreateContext(const __GLcontextModes
* glVisual
,
258 __DRIcontextPrivate
* driContextPriv
,
259 void *sharedContextPrivate
)
261 __DRIscreenPrivate
*sPriv
= driContextPriv
->driScreenPriv
;
262 radeonScreenPtr screen
= (radeonScreenPtr
) (sPriv
->private);
263 struct dd_function_table functions
;
269 assert(driContextPriv
);
272 /* Allocate the R300 context */
273 r300
= (r300ContextPtr
) CALLOC(sizeof(*r300
));
277 if (!(screen
->chip_flags
& RADEON_CHIPSET_TCL
))
278 hw_tcl_on
= future_hw_tcl_on
= 0;
280 r300_init_vtbl(&r300
->radeon
);
281 /* Parse configuration files.
282 * Do this here so that initialMaxAnisotropy is set before we create
283 * the default textures.
285 driParseConfigFiles(&r300
->radeon
.optionCache
, &screen
->optionCache
,
286 screen
->driScreen
->myNum
, "r300");
287 r300
->initialMaxAnisotropy
= driQueryOptionf(&r300
->radeon
.optionCache
,
288 "def_max_anisotropy");
290 /* Init default driver functions then plug in our R300-specific functions
291 * (the texture functions are especially important)
293 _mesa_init_driver_functions(&functions
);
294 r300InitIoctlFuncs(&functions
);
295 r300InitStateFuncs(&functions
);
296 r300InitTextureFuncs(&functions
);
297 r300InitShaderFuncs(&functions
);
299 if (!radeonInitContext(&r300
->radeon
, &functions
,
300 glVisual
, driContextPriv
,
301 sharedContextPrivate
)) {
306 /* Init r300 context data */
307 r300
->texture_depth
= driQueryOptioni(&r300
->radeon
.optionCache
,
309 if (r300
->texture_depth
== DRI_CONF_TEXTURE_DEPTH_FB
)
310 r300
->texture_depth
= (screen
->cpp
== 4) ?
311 DRI_CONF_TEXTURE_DEPTH_32
: DRI_CONF_TEXTURE_DEPTH_16
;
313 /* Set the maximum texture size small enough that we can guarentee that
314 * all texture units can bind a maximal texture and have them both in
315 * texturable memory at once.
318 ctx
= r300
->radeon
.glCtx
;
320 ctx
->Const
.MaxTextureImageUnits
=
321 driQueryOptioni(&r300
->radeon
.optionCache
, "texture_image_units");
322 ctx
->Const
.MaxTextureCoordUnits
=
323 driQueryOptioni(&r300
->radeon
.optionCache
, "texture_coord_units");
324 ctx
->Const
.MaxTextureUnits
=
325 MIN2(ctx
->Const
.MaxTextureImageUnits
,
326 ctx
->Const
.MaxTextureCoordUnits
);
327 ctx
->Const
.MaxTextureMaxAnisotropy
= 16.0;
328 ctx
->Const
.MaxTextureLodBias
= 16.0;
330 if (screen
->chip_family
>= CHIP_FAMILY_RV515
) {
331 ctx
->Const
.MaxTextureLevels
= 13;
332 ctx
->Const
.MaxTextureRectSize
= 4096;
335 ctx
->Const
.MinPointSize
= 1.0;
336 ctx
->Const
.MinPointSizeAA
= 1.0;
337 ctx
->Const
.MaxPointSize
= R300_POINTSIZE_MAX
;
338 ctx
->Const
.MaxPointSizeAA
= R300_POINTSIZE_MAX
;
340 ctx
->Const
.MinLineWidth
= 1.0;
341 ctx
->Const
.MinLineWidthAA
= 1.0;
342 ctx
->Const
.MaxLineWidth
= R300_LINESIZE_MAX
;
343 ctx
->Const
.MaxLineWidthAA
= R300_LINESIZE_MAX
;
345 /* Needs further modifications */
347 ctx
->Const
.MaxArrayLockSize
=
348 ( /*512 */ RADEON_BUFFER_SIZE
* 16 * 1024) / (4 * 4);
351 /* Initialize the software rasterizer and helper modules.
353 _swrast_CreateContext(ctx
);
354 _vbo_CreateContext(ctx
);
355 _tnl_CreateContext(ctx
);
356 _swsetup_CreateContext(ctx
);
357 _swsetup_Wakeup(ctx
);
358 _ae_create_context(ctx
);
360 /* Install the customized pipeline:
362 _tnl_destroy_pipeline(ctx
);
363 _tnl_install_pipeline(ctx
, r300_pipeline
);
365 /* Try and keep materials and vertices separate:
367 /* _tnl_isolate_materials(ctx, GL_TRUE); */
369 /* Configure swrast and TNL to match hardware characteristics:
371 _swrast_allow_pixel_fog(ctx
, GL_FALSE
);
372 _swrast_allow_vertex_fog(ctx
, GL_TRUE
);
373 _tnl_allow_pixel_fog(ctx
, GL_FALSE
);
374 _tnl_allow_vertex_fog(ctx
, GL_TRUE
);
376 /* currently bogus data */
377 if (screen
->chip_flags
& RADEON_CHIPSET_TCL
) {
378 ctx
->Const
.VertexProgram
.MaxInstructions
= VSF_MAX_FRAGMENT_LENGTH
/ 4;
379 ctx
->Const
.VertexProgram
.MaxNativeInstructions
=
380 VSF_MAX_FRAGMENT_LENGTH
/ 4;
381 ctx
->Const
.VertexProgram
.MaxNativeAttribs
= 16; /* r420 */
382 ctx
->Const
.VertexProgram
.MaxTemps
= 32;
383 ctx
->Const
.VertexProgram
.MaxNativeTemps
=
384 /*VSF_MAX_FRAGMENT_TEMPS */ 32;
385 ctx
->Const
.VertexProgram
.MaxNativeParameters
= 256; /* r420 */
386 ctx
->Const
.VertexProgram
.MaxNativeAddressRegs
= 1;
389 ctx
->Const
.FragmentProgram
.MaxNativeTemps
= PFS_NUM_TEMP_REGS
;
390 ctx
->Const
.FragmentProgram
.MaxNativeAttribs
= 11; /* copy i915... */
391 ctx
->Const
.FragmentProgram
.MaxNativeParameters
= PFS_NUM_CONST_REGS
;
392 ctx
->Const
.FragmentProgram
.MaxNativeAluInstructions
= PFS_MAX_ALU_INST
;
393 ctx
->Const
.FragmentProgram
.MaxNativeTexInstructions
= PFS_MAX_TEX_INST
;
394 ctx
->Const
.FragmentProgram
.MaxNativeInstructions
=
395 PFS_MAX_ALU_INST
+ PFS_MAX_TEX_INST
;
396 ctx
->Const
.FragmentProgram
.MaxNativeTexIndirections
=
397 PFS_MAX_TEX_INDIRECT
;
398 ctx
->Const
.FragmentProgram
.MaxNativeAddressRegs
= 0; /* and these are?? */
399 ctx
->VertexProgram
._MaintainTnlProgram
= GL_TRUE
;
400 ctx
->FragmentProgram
._MaintainTexEnvProgram
= GL_TRUE
;
402 driInitExtensions(ctx
, card_extensions
, GL_TRUE
);
405 (&r300
->radeon
.optionCache
, "disable_stencil_two_side"))
406 _mesa_disable_extension(ctx
, "GL_EXT_stencil_two_side");
408 if (r300
->radeon
.glCtx
->Mesa_DXTn
409 && !driQueryOptionb(&r300
->radeon
.optionCache
, "disable_s3tc")) {
410 _mesa_enable_extension(ctx
, "GL_EXT_texture_compression_s3tc");
411 _mesa_enable_extension(ctx
, "GL_S3_s3tc");
413 if (driQueryOptionb(&r300
->radeon
.optionCache
, "force_s3tc_enable"))
415 _mesa_enable_extension(ctx
, "GL_EXT_texture_compression_s3tc");
418 r300
->disable_lowimpact_fallback
=
419 driQueryOptionb(&r300
->radeon
.optionCache
,
420 "disable_lowimpact_fallback");
422 radeonInitSpanFuncs(ctx
);
423 r300InitCmdBuf(r300
);
425 if (!(screen
->chip_flags
& RADEON_CHIPSET_TCL
))
428 TNL_CONTEXT(ctx
)->Driver
.RunPipeline
= r300RunPipeline
;
430 tcl_mode
= driQueryOptioni(&r300
->radeon
.optionCache
, "tcl_mode");
431 if (driQueryOptionb(&r300
->radeon
.optionCache
, "no_rast")) {
432 fprintf(stderr
, "disabling 3D acceleration\n");
434 FALLBACK(&r300
->radeon
, RADEON_FALLBACK_DISABLE
, 1);
437 if (tcl_mode
== DRI_CONF_TCL_SW
||
438 !(r300
->radeon
.radeonScreen
->chip_flags
& RADEON_CHIPSET_TCL
)) {
439 if (r300
->radeon
.radeonScreen
->chip_flags
& RADEON_CHIPSET_TCL
) {
440 r300
->radeon
.radeonScreen
->chip_flags
&=
442 fprintf(stderr
, "Disabling HW TCL support\n");
444 TCL_FALLBACK(r300
->radeon
.glCtx
,
445 RADEON_TCL_FALLBACK_TCL_DISABLE
, 1);
451 /* Destroy the device specific context.
453 void r300DestroyContext(__DRIcontextPrivate
* driContextPriv
)
455 GET_CURRENT_CONTEXT(ctx
);
456 r300ContextPtr r300
= (r300ContextPtr
) driContextPriv
->driverPrivate
;
457 radeonContextPtr radeon
= (radeonContextPtr
) r300
;
458 radeonContextPtr current
= ctx
? RADEON_CONTEXT(ctx
) : NULL
;
460 if (RADEON_DEBUG
& DEBUG_DRI
) {
461 fprintf(stderr
, "Destroying context !\n");
464 /* check if we're deleting the currently bound context */
465 if (&r300
->radeon
== current
) {
466 radeonFlush(r300
->radeon
.glCtx
);
467 _mesa_make_current(NULL
, NULL
, NULL
);
470 /* Free r300 context resources */
471 assert(r300
); /* should never be null */
474 _swsetup_DestroyContext(r300
->radeon
.glCtx
);
475 _tnl_DestroyContext(r300
->radeon
.glCtx
);
476 _vbo_DestroyContext(r300
->radeon
.glCtx
);
477 _swrast_DestroyContext(r300
->radeon
.glCtx
);
479 rcommonFlushCmdBuf(&r300
->radeon
, __FUNCTION__
);
480 r300DestroyCmdBuf(r300
);
482 if (radeon
->state
.scissor
.pClipRects
) {
483 FREE(radeon
->state
.scissor
.pClipRects
);
484 radeon
->state
.scissor
.pClipRects
= NULL
;
487 radeonCleanupContext(&r300
->radeon
);
489 /* the memory manager might be accessed when Mesa frees the shared
490 * state, so don't destroy it earlier
493 /* free the option cache */
494 driDestroyOptionCache(&r300
->radeon
.optionCache
);