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"
44 #include "swrast/swrast.h"
45 #include "swrast_setup/swrast_setup.h"
46 #include "array_cache/acache.h"
49 #include "tnl/t_pipeline.h"
51 #include "drivers/common/driverfuncs.h"
53 #include "radeon_ioctl.h"
54 #include "radeon_span.h"
55 #include "r300_context.h"
56 #include "r300_cmdbuf.h"
57 #include "r300_state.h"
58 #include "r300_ioctl.h"
63 #include "xmlpool.h" /* for symbolic values of enum-type options */
66 /* Extension strings exported by the R300 driver.
68 static const char *const card_extensions
[] = {
70 "GL_ARB_multitexture",
71 "GL_ARB_texture_border_clamp",
72 "GL_ARB_texture_compression",
73 "GL_ARB_texture_cube_map",
74 "GL_ARB_texture_env_add",
75 "GL_ARB_texture_env_combine",
76 "GL_ARB_texture_env_dot3",
77 "GL_ARB_texture_mirrored_repeat",
78 "GL_ARB_vertex_buffer_object",
79 "GL_ARB_vertex_program",
80 //"GL_ARB_fragment_program",
81 "GL_EXT_blend_equation_separate",
82 "GL_EXT_blend_func_separate",
83 "GL_EXT_blend_minmax",
84 "GL_EXT_blend_subtract",
85 "GL_EXT_secondary_color",
86 "GL_EXT_stencil_wrap",
87 "GL_EXT_texture_edge_clamp",
88 "GL_EXT_texture_env_combine",
89 "GL_EXT_texture_env_dot3",
90 "GL_EXT_texture_filter_anisotropic",
91 "GL_EXT_texture_lod_bias",
92 "GL_EXT_texture_mirror_clamp",
93 "GL_EXT_texture_rectangle",
94 "GL_ATI_texture_env_combine3",
95 "GL_ATI_texture_mirror_once",
96 "GL_MESA_pack_invert",
97 "GL_MESA_ycbcr_texture",
99 "GL_NV_vertex_program",
100 "GL_SGIS_generate_mipmap",
104 extern struct tnl_pipeline_stage _r300_render_stage
;
106 static const struct tnl_pipeline_stage
*r300_pipeline
[] = {
108 /* Try and go straight to t&l
112 /* Catch any t&l fallbacks
114 &_tnl_vertex_transform_stage
,
115 &_tnl_normal_transform_stage
,
116 &_tnl_lighting_stage
,
117 &_tnl_fog_coordinate_stage
,
119 &_tnl_texture_transform_stage
,
120 &_tnl_vertex_program_stage
,
122 /* Try again to go to tcl?
123 * - no good for asymmetric-twoside (do with multipass)
124 * - no good for asymmetric-unfilled (do with multipass)
125 * - good for material
127 * - need to manipulate a bit of state
129 * - worth it/not worth it?
132 /* Else do them here.
135 &_tnl_render_stage
, /* FALLBACK */
139 /* Create the device specific rendering context.
141 GLboolean
r300CreateContext(const __GLcontextModes
* glVisual
,
142 __DRIcontextPrivate
* driContextPriv
,
143 void *sharedContextPrivate
)
145 __DRIscreenPrivate
*sPriv
= driContextPriv
->driScreenPriv
;
146 radeonScreenPtr screen
= (radeonScreenPtr
) (sPriv
->private);
147 struct dd_function_table functions
;
153 assert(driContextPriv
);
156 /* Allocate the R300 context */
157 r300
= (r300ContextPtr
)CALLOC(sizeof(*r300
));
161 /* Parse configuration files.
162 * Do this here so that initialMaxAnisotropy is set before we create
163 * the default textures.
165 driParseConfigFiles(&r300
->radeon
.optionCache
, &screen
->optionCache
,
166 screen
->driScreen
->myNum
, "r300");
168 /* Init default driver functions then plug in our R300-specific functions
169 * (the texture functions are especially important)
171 _mesa_init_driver_functions(&functions
);
172 r300InitIoctlFuncs(&functions
);
173 r300InitStateFuncs(&functions
);
174 r300InitTextureFuncs(&functions
);
175 r300InitVertexProgFuncs(&functions
);
177 if (!radeonInitContext(&r300
->radeon
, &functions
,
178 glVisual
, driContextPriv
, sharedContextPrivate
)) {
183 /* Init r300 context data */
184 r300
->dma
.buf0_address
= r300
->radeon
.radeonScreen
->buffers
->list
[0].address
;
186 (void)memset(r300
->texture_heaps
, 0, sizeof(r300
->texture_heaps
));
187 make_empty_list(&r300
->swapped
);
189 r300
->nr_heaps
= 1 /* screen->numTexHeaps */ ;
190 assert(r300
->nr_heaps
< R200_NR_TEX_HEAPS
);
191 for (i
= 0; i
< r300
->nr_heaps
; i
++) {
192 r300
->texture_heaps
[i
] = driCreateTextureHeap(i
, r300
,
195 RADEON_NR_TEX_REGIONS
,
196 (drmTextureRegionPtr
)
199 &r300
->radeon
.sarea
->
204 (destroy_texture_object_t
208 r300
->texture_depth
= driQueryOptioni(&r300
->radeon
.optionCache
,
210 if (r300
->texture_depth
== DRI_CONF_TEXTURE_DEPTH_FB
)
211 r300
->texture_depth
= (screen
->cpp
== 4) ?
212 DRI_CONF_TEXTURE_DEPTH_32
: DRI_CONF_TEXTURE_DEPTH_16
;
214 /* Set the maximum texture size small enough that we can guarentee that
215 * all texture units can bind a maximal texture and have them both in
216 * texturable memory at once.
219 ctx
= r300
->radeon
.glCtx
;
221 ctx
->Const
.MaxTextureImageUnits
= driQueryOptioni(&r300
->radeon
.optionCache
,
222 "texture_image_units");
223 ctx
->Const
.MaxTextureCoordUnits
= driQueryOptioni(&r300
->radeon
.optionCache
,
224 "texture_coord_units");
225 ctx
->Const
.MaxTextureUnits
= MIN2(ctx
->Const
.MaxTextureImageUnits
,
226 ctx
->Const
.MaxTextureCoordUnits
);
227 ctx
->Const
.MaxTextureMaxAnisotropy
= 16.0;
229 ctx
->Const
.MinPointSize
= 1.0;
230 ctx
->Const
.MinPointSizeAA
= 1.0;
231 ctx
->Const
.MaxPointSize
= R300_POINTSIZE_MAX
;
232 ctx
->Const
.MaxPointSizeAA
= R300_POINTSIZE_MAX
;
234 ctx
->Const
.MinLineWidth
= 1.0;
235 ctx
->Const
.MinLineWidthAA
= 1.0;
236 ctx
->Const
.MaxLineWidth
= R300_LINESIZE_MAX
;
237 ctx
->Const
.MaxLineWidthAA
= R300_LINESIZE_MAX
;
239 /* Initialize the software rasterizer and helper modules.
241 _swrast_CreateContext(ctx
);
242 _ac_CreateContext(ctx
);
243 _tnl_CreateContext(ctx
);
244 _swsetup_CreateContext(ctx
);
245 _ae_create_context(ctx
);
247 /* Install the customized pipeline:
249 _tnl_destroy_pipeline(ctx
);
250 _tnl_install_pipeline(ctx
, r300_pipeline
);
252 /* Try and keep materials and vertices separate:
254 _tnl_isolate_materials(ctx
, GL_TRUE
);
256 /* Configure swrast and TNL to match hardware characteristics:
258 _swrast_allow_pixel_fog(ctx
, GL_FALSE
);
259 _swrast_allow_vertex_fog(ctx
, GL_TRUE
);
260 _tnl_allow_pixel_fog(ctx
, GL_FALSE
);
261 _tnl_allow_vertex_fog(ctx
, GL_TRUE
);
264 //if(driQueryOptionb(&rmesa->optionCache, "arb_vertex_program"))
265 _mesa_enable_extension( ctx
, "GL_ARB_vertex_program");
266 //if(driQueryOptionb(&rmesa->optionCache, "nv_vertex_program"))
267 _mesa_enable_extension( ctx
, "GL_NV_vertex_program");
269 /* currently bogus data */
270 ctx
->Const
.MaxVertexProgramInstructions
=128;
271 ctx
->Const
.MaxVertexProgramAttribs
=64;
272 ctx
->Const
.MaxVertexProgramTemps
=64;
273 ctx
->Const
.MaxVertexProgramLocalParams
=64;
274 ctx
->Const
.MaxVertexProgramEnvParams
=64;
275 ctx
->Const
.MaxVertexProgramAddressRegs
=8;
277 driInitExtensions(ctx
, card_extensions
, GL_TRUE
);
279 radeonInitSpanFuncs(ctx
);
280 r300InitCmdBuf(r300
);
284 /* plug in a few more device driver functions */
285 /* XXX these should really go right after _mesa_init_driver_functions() */
286 r300InitPixelFuncs(ctx
);
289 TNL_CONTEXT(ctx
)->Driver
.RunPipeline
= _tnl_run_pipeline
;
291 tcl_mode
= driQueryOptioni(&r300
->radeon
.optionCache
, "tcl_mode");
292 if (driQueryOptionb(&r300
->radeon
.optionCache
, "no_rast")) {
293 fprintf(stderr
, "disabling 3D acceleration\n");
294 FALLBACK(&r300
->radeon
, RADEON_FALLBACK_DISABLE
, 1);
296 if (tcl_mode
== DRI_CONF_TCL_SW
||
297 !(r300
->radeon
.radeonScreen
->chipset
& RADEON_CHIPSET_TCL
)) {
298 if (r300
->radeon
.radeonScreen
->chipset
& RADEON_CHIPSET_TCL
) {
299 r300
->radeon
.radeonScreen
->chipset
&= ~RADEON_CHIPSET_TCL
;
300 fprintf(stderr
, "Disabling HW TCL support\n");
302 TCL_FALLBACK(r300
->radeon
.glCtx
, RADEON_TCL_FALLBACK_TCL_DISABLE
, 1);
308 /* Destroy the device specific context.
310 void r300DestroyContext(__DRIcontextPrivate
* driContextPriv
)
312 GET_CURRENT_CONTEXT(ctx
);
313 r300ContextPtr r300
= (r300ContextPtr
) driContextPriv
->driverPrivate
;
314 radeonContextPtr current
= ctx
? RADEON_CONTEXT(ctx
) : NULL
;
316 fprintf(stderr
, "Destroying context !\n");
318 /* check if we're deleting the currently bound context */
319 if (&r300
->radeon
== current
) {
320 radeonFlush(r300
->radeon
.glCtx
);
321 _mesa_make_current2(NULL
, NULL
, NULL
);
324 /* Free r300 context resources */
325 assert(r300
); /* should never be null */
328 GLboolean release_texture_heaps
;
330 release_texture_heaps
= (r300
->radeon
.glCtx
->Shared
->RefCount
== 1);
331 _swsetup_DestroyContext(r300
->radeon
.glCtx
);
332 _tnl_DestroyContext(r300
->radeon
.glCtx
);
333 _ac_DestroyContext(r300
->radeon
.glCtx
);
334 _swrast_DestroyContext(r300
->radeon
.glCtx
);
336 r300DestroyCmdBuf(r300
);
338 radeonCleanupContext(&r300
->radeon
);
340 /* free the option cache */
341 driDestroyOptionCache(&r300
->radeon
.optionCache
);