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>
33 * Nicolai Haehnle <prefect_@gmx.net>
36 #include "api_arrayelt.h"
38 #include "simple_list.h"
41 #include "extensions.h"
43 #include "bufferobj.h"
45 #include "swrast/swrast.h"
46 #include "swrast_setup/swrast_setup.h"
47 #include "array_cache/acache.h"
50 #include "tnl/t_pipeline.h"
52 #include "drivers/common/driverfuncs.h"
54 #include "radeon_ioctl.h"
55 #include "radeon_span.h"
56 #include "r300_context.h"
57 #include "r300_cmdbuf.h"
58 #include "r300_state.h"
59 #include "r300_ioctl.h"
63 #include "radeon_mm.h"
68 #include "xmlpool.h" /* for symbolic values of enum-type options */
70 /* hw_tcl_on derives from future_hw_tcl_on when its safe to change it. */
71 int future_hw_tcl_on
=1;
74 #define need_GL_ARB_multisample
75 #define need_GL_ARB_texture_compression
76 #define need_GL_ARB_vertex_buffer_object
77 #define need_GL_ARB_vertex_program
78 #define need_GL_EXT_blend_minmax
79 #define need_GL_EXT_secondary_color
80 #define need_GL_EXT_blend_equation_separate
81 #define need_GL_EXT_blend_func_separate
82 #define need_GL_NV_vertex_program
83 #include "extension_helper.h"
85 const struct dri_extension card_extensions
[] = {
86 {"GL_ARB_multisample", GL_ARB_multisample_functions
},
87 {"GL_ARB_multitexture", NULL
},
88 {"GL_ARB_texture_border_clamp", NULL
},
89 {"GL_ARB_texture_compression", GL_ARB_texture_compression_functions
},
90 {"GL_ARB_texture_cube_map", NULL
},
91 {"GL_ARB_texture_env_add", NULL
},
92 {"GL_ARB_texture_env_combine", NULL
},
93 {"GL_ARB_texture_env_crossbar", NULL
},
94 {"GL_ARB_texture_env_dot3", NULL
},
95 {"GL_ARB_texture_mirrored_repeat", NULL
},
96 {"GL_ARB_vertex_buffer_object", GL_ARB_vertex_buffer_object_functions
},
97 {"GL_ARB_vertex_program", GL_ARB_vertex_program_functions
},
99 {"GL_ARB_fragment_program", NULL
},
101 {"GL_EXT_blend_equation_separate", GL_EXT_blend_equation_separate_functions
},
102 {"GL_EXT_blend_func_separate", GL_EXT_blend_func_separate_functions
},
103 {"GL_EXT_blend_minmax", GL_EXT_blend_minmax_functions
},
104 {"GL_EXT_blend_subtract", NULL
},
105 {"GL_EXT_secondary_color", GL_EXT_secondary_color_functions
},
106 {"GL_EXT_stencil_wrap", NULL
},
107 {"GL_EXT_texture_edge_clamp", NULL
},
108 {"GL_EXT_texture_env_combine", NULL
},
109 {"GL_EXT_texture_env_dot3", NULL
},
110 {"GL_EXT_texture_filter_anisotropic", NULL
},
111 {"GL_EXT_texture_lod_bias", NULL
},
112 {"GL_EXT_texture_mirror_clamp", NULL
},
113 {"GL_EXT_texture_rectangle", NULL
},
114 {"GL_ATI_texture_env_combine3", NULL
},
115 {"GL_ATI_texture_mirror_once", NULL
},
116 {"GL_MESA_pack_invert", NULL
},
117 {"GL_MESA_ycbcr_texture", NULL
},
118 {"GL_NV_blend_square", NULL
},
119 {"GL_NV_vertex_program", GL_NV_vertex_program_functions
},
120 {"GL_SGIS_generate_mipmap", NULL
},
124 extern struct tnl_pipeline_stage _r300_render_stage
;
125 extern const struct tnl_pipeline_stage _r300_tcl_stage
;
126 extern const struct tnl_pipeline_stage _r300_texrect_stage
;
128 static const struct tnl_pipeline_stage
*r300_pipeline
[] = {
130 /* Try and go straight to t&l
134 /* Catch any t&l fallbacks
136 &_tnl_vertex_transform_stage
,
137 &_tnl_normal_transform_stage
,
138 &_tnl_lighting_stage
,
139 &_tnl_fog_coordinate_stage
,
141 &_tnl_texture_transform_stage
,
142 &_tnl_arb_vertex_program_stage
,
143 &_tnl_vertex_program_stage
,
145 /* Try again to go to tcl?
146 * - no good for asymmetric-twoside (do with multipass)
147 * - no good for asymmetric-unfilled (do with multipass)
148 * - good for material
150 * - need to manipulate a bit of state
152 * - worth it/not worth it?
155 /* Else do them here.
157 /* scale texture rectangle to 0..1. */
158 &_r300_texrect_stage
,
160 &_tnl_render_stage
, /* FALLBACK */
165 /* Create the device specific rendering context.
167 GLboolean
r300CreateContext(const __GLcontextModes
* glVisual
,
168 __DRIcontextPrivate
* driContextPriv
,
169 void *sharedContextPrivate
)
171 __DRIscreenPrivate
*sPriv
= driContextPriv
->driScreenPriv
;
172 radeonScreenPtr screen
= (radeonScreenPtr
) (sPriv
->private);
173 struct dd_function_table functions
;
179 assert(driContextPriv
);
182 /* Allocate the R300 context */
183 r300
= (r300ContextPtr
)CALLOC(sizeof(*r300
));
187 /* Parse configuration files.
188 * Do this here so that initialMaxAnisotropy is set before we create
189 * the default textures.
191 driParseConfigFiles(&r300
->radeon
.optionCache
, &screen
->optionCache
,
192 screen
->driScreen
->myNum
, "r300");
194 /* Init default driver functions then plug in our R300-specific functions
195 * (the texture functions are especially important)
197 _mesa_init_driver_functions(&functions
);
198 r300InitIoctlFuncs(&functions
);
199 r300InitStateFuncs(&functions
);
200 r300InitTextureFuncs(&functions
);
201 r300InitShaderFuncs(&functions
);
204 radeon_mm_init(r300
);
208 r300_init_vbo_funcs(&functions
);
211 if (!radeonInitContext(&r300
->radeon
, &functions
,
212 glVisual
, driContextPriv
, sharedContextPrivate
)) {
217 /* Init r300 context data */
218 r300
->dma
.buf0_address
= r300
->radeon
.radeonScreen
->buffers
->list
[0].address
;
220 (void)memset(r300
->texture_heaps
, 0, sizeof(r300
->texture_heaps
));
221 make_empty_list(&r300
->swapped
);
223 r300
->nr_heaps
= 1 /* screen->numTexHeaps */ ;
224 assert(r300
->nr_heaps
< RADEON_NR_TEX_HEAPS
);
225 for (i
= 0; i
< r300
->nr_heaps
; i
++) {
226 r300
->texture_heaps
[i
] = driCreateTextureHeap(i
, r300
,
229 RADEON_NR_TEX_REGIONS
,
230 (drmTextureRegionPtr
)
233 &r300
->radeon
.sarea
->
238 (destroy_texture_object_t
242 r300
->texture_depth
= driQueryOptioni(&r300
->radeon
.optionCache
,
244 if (r300
->texture_depth
== DRI_CONF_TEXTURE_DEPTH_FB
)
245 r300
->texture_depth
= (screen
->cpp
== 4) ?
246 DRI_CONF_TEXTURE_DEPTH_32
: DRI_CONF_TEXTURE_DEPTH_16
;
248 /* Set the maximum texture size small enough that we can guarentee that
249 * all texture units can bind a maximal texture and have them both in
250 * texturable memory at once.
253 ctx
= r300
->radeon
.glCtx
;
255 ctx
->Const
.MaxTextureImageUnits
= driQueryOptioni(&r300
->radeon
.optionCache
,
256 "texture_image_units");
257 ctx
->Const
.MaxTextureCoordUnits
= driQueryOptioni(&r300
->radeon
.optionCache
,
258 "texture_coord_units");
259 ctx
->Const
.MaxTextureUnits
= MIN2(ctx
->Const
.MaxTextureImageUnits
,
260 ctx
->Const
.MaxTextureCoordUnits
);
261 ctx
->Const
.MaxTextureMaxAnisotropy
= 16.0;
263 ctx
->Const
.MinPointSize
= 1.0;
264 ctx
->Const
.MinPointSizeAA
= 1.0;
265 ctx
->Const
.MaxPointSize
= R300_POINTSIZE_MAX
;
266 ctx
->Const
.MaxPointSizeAA
= R300_POINTSIZE_MAX
;
268 ctx
->Const
.MinLineWidth
= 1.0;
269 ctx
->Const
.MinLineWidthAA
= 1.0;
270 ctx
->Const
.MaxLineWidth
= R300_LINESIZE_MAX
;
271 ctx
->Const
.MaxLineWidthAA
= R300_LINESIZE_MAX
;
274 ctx
->_MaintainTnlProgram
= GL_TRUE
;
277 /* Needs further modifications */
279 ctx
->Const
.MaxArrayLockSize
= (/*512*/RADEON_BUFFER_SIZE
*16*1024) / (4*4);
283 /* Initialize the software rasterizer and helper modules.
285 _swrast_CreateContext(ctx
);
286 _ac_CreateContext(ctx
);
287 _tnl_CreateContext(ctx
);
288 _swsetup_CreateContext(ctx
);
289 _swsetup_Wakeup(ctx
);
290 _ae_create_context(ctx
);
292 /* Install the customized pipeline:
294 _tnl_destroy_pipeline(ctx
);
295 _tnl_install_pipeline(ctx
, r300_pipeline
);
297 /* Try and keep materials and vertices separate:
299 _tnl_isolate_materials(ctx
, GL_TRUE
);
301 /* Configure swrast and TNL to match hardware characteristics:
303 _swrast_allow_pixel_fog(ctx
, GL_FALSE
);
304 _swrast_allow_vertex_fog(ctx
, GL_TRUE
);
305 _tnl_allow_pixel_fog(ctx
, GL_FALSE
);
306 _tnl_allow_vertex_fog(ctx
, GL_TRUE
);
308 /* currently bogus data */
309 ctx
->Const
.VertexProgram
.MaxNativeInstructions
=VSF_MAX_FRAGMENT_LENGTH
;
310 ctx
->Const
.VertexProgram
.MaxNativeAttribs
=16; /* r420 */
311 ctx
->Const
.VertexProgram
.MaxTemps
=32;
312 ctx
->Const
.VertexProgram
.MaxNativeTemps
=/*VSF_MAX_FRAGMENT_TEMPS*/32;
313 ctx
->Const
.VertexProgram
.MaxNativeParameters
=256; /* r420 */
314 ctx
->Const
.VertexProgram
.MaxNativeAddressRegs
=1;
317 ctx
->Const
.FragmentProgram
.MaxNativeTemps
= PFS_NUM_TEMP_REGS
;
318 ctx
->Const
.FragmentProgram
.MaxNativeAttribs
= 11; /* copy i915... */
319 ctx
->Const
.FragmentProgram
.MaxNativeParameters
= PFS_NUM_CONST_REGS
;
320 ctx
->Const
.FragmentProgram
.MaxNativeAluInstructions
= PFS_MAX_ALU_INST
;
321 ctx
->Const
.FragmentProgram
.MaxNativeTexInstructions
= PFS_MAX_TEX_INST
;
322 ctx
->Const
.FragmentProgram
.MaxNativeInstructions
= PFS_MAX_ALU_INST
+PFS_MAX_TEX_INST
;
323 ctx
->Const
.FragmentProgram
.MaxNativeTexIndirections
= PFS_MAX_TEX_INDIRECT
;
324 ctx
->Const
.FragmentProgram
.MaxNativeAddressRegs
= 0; /* and these are?? */
325 ctx
->_MaintainTexEnvProgram
= GL_TRUE
;
328 driInitExtensions(ctx
, card_extensions
, GL_TRUE
);
330 if (r300
->radeon
.glCtx
->Mesa_DXTn
) {
331 _mesa_enable_extension( ctx
, "GL_EXT_texture_compression_s3tc" );
332 _mesa_enable_extension( ctx
, "GL_S3_s3tc" );
334 else if (driQueryOptionb (&r300
->radeon
.optionCache
, "force_s3tc_enable")) {
335 _mesa_enable_extension( ctx
, "GL_EXT_texture_compression_s3tc" );
338 radeonInitSpanFuncs(ctx
);
339 r300InitCmdBuf(r300
);
342 #ifdef RADEON_VTXFMT_A
343 radeon_init_vtxfmt_a(r300
);
347 /* plug in a few more device driver functions */
348 /* XXX these should really go right after _mesa_init_driver_functions() */
349 r300InitPixelFuncs(ctx
);
352 TNL_CONTEXT(ctx
)->Driver
.RunPipeline
= _tnl_run_pipeline
;
354 tcl_mode
= driQueryOptioni(&r300
->radeon
.optionCache
, "tcl_mode");
355 if (driQueryOptionb(&r300
->radeon
.optionCache
, "no_rast")) {
356 fprintf(stderr
, "disabling 3D acceleration\n");
358 FALLBACK(&r300
->radeon
, RADEON_FALLBACK_DISABLE
, 1);
361 if (tcl_mode
== DRI_CONF_TCL_SW
||
362 !(r300
->radeon
.radeonScreen
->chip_flags
& RADEON_CHIPSET_TCL
)) {
363 if (r300
->radeon
.radeonScreen
->chip_flags
& RADEON_CHIPSET_TCL
) {
364 r300
->radeon
.radeonScreen
->chip_flags
&= ~RADEON_CHIPSET_TCL
;
365 fprintf(stderr
, "Disabling HW TCL support\n");
367 TCL_FALLBACK(r300
->radeon
.glCtx
, RADEON_TCL_FALLBACK_TCL_DISABLE
, 1);
373 /* Destroy the device specific context.
375 void r300DestroyContext(__DRIcontextPrivate
* driContextPriv
)
377 GET_CURRENT_CONTEXT(ctx
);
378 r300ContextPtr r300
= (r300ContextPtr
) driContextPriv
->driverPrivate
;
379 radeonContextPtr radeon
= (radeonContextPtr
) r300
;
380 radeonContextPtr current
= ctx
? RADEON_CONTEXT(ctx
) : NULL
;
382 if (RADEON_DEBUG
& DEBUG_DRI
) {
383 fprintf(stderr
, "Destroying context !\n");
386 /* check if we're deleting the currently bound context */
387 if (&r300
->radeon
== current
) {
388 radeonFlush(r300
->radeon
.glCtx
);
389 _mesa_make_current(NULL
, NULL
, NULL
);
392 /* Free r300 context resources */
393 assert(r300
); /* should never be null */
396 GLboolean release_texture_heaps
;
398 release_texture_heaps
= (r300
->radeon
.glCtx
->Shared
->RefCount
== 1);
399 _swsetup_DestroyContext(r300
->radeon
.glCtx
);
400 _tnl_DestroyContext(r300
->radeon
.glCtx
);
401 _ac_DestroyContext(r300
->radeon
.glCtx
);
402 _swrast_DestroyContext(r300
->radeon
.glCtx
);
404 r300ReleaseArrays(r300
->radeon
.glCtx
);
405 if (r300
->dma
.current
.buf
) {
406 r300ReleaseDmaRegion(r300
, &r300
->dma
.current
, __FUNCTION__
);
407 r300FlushCmdBuf(r300
, __FUNCTION__
);
410 r300DestroyCmdBuf(r300
);
412 if (radeon
->state
.scissor
.pClipRects
) {
413 FREE(radeon
->state
.scissor
.pClipRects
);
414 radeon
->state
.scissor
.pClipRects
= NULL
;
417 if (release_texture_heaps
) {
418 /* This share group is about to go away, free our private
419 * texture object data.
423 for (i
= 0; i
< r300
->nr_heaps
; i
++) {
424 driDestroyTextureHeap(r300
->texture_heaps
[i
]);
425 r300
->texture_heaps
[i
] = NULL
;
428 assert(is_empty_list(&r300
->swapped
));
431 radeonCleanupContext(&r300
->radeon
);
433 /* free the option cache */
434 driDestroyOptionCache(&r300
->radeon
.optionCache
);