Reduce amount of stderr output.
[mesa.git] / src / mesa / drivers / dri / r300 / r300_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 * Nicolai Haehnle <prefect_@gmx.net>
34 */
35
36 #include "glheader.h"
37 #include "api_arrayelt.h"
38 #include "context.h"
39 #include "simple_list.h"
40 #include "imports.h"
41 #include "matrix.h"
42 #include "extensions.h"
43 #include "state.h"
44
45 #include "swrast/swrast.h"
46 #include "swrast_setup/swrast_setup.h"
47 #include "array_cache/acache.h"
48
49 #include "tnl/tnl.h"
50 #include "tnl/t_pipeline.h"
51
52 #include "drivers/common/driverfuncs.h"
53
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"
60 #include "r300_tex.h"
61
62 #include "vblank.h"
63 #include "utils.h"
64 #include "xmlpool.h" /* for symbolic values of enum-type options */
65
66
67 /* Extension strings exported by the R300 driver.
68 */
69 static const char *const card_extensions[] = {
70 "GL_ARB_multisample",
71 "GL_ARB_multitexture",
72 "GL_ARB_texture_border_clamp",
73 "GL_ARB_texture_compression",
74 "GL_ARB_texture_cube_map",
75 "GL_ARB_texture_env_add",
76 "GL_ARB_texture_env_combine",
77 "GL_ARB_texture_env_dot3",
78 "GL_ARB_texture_mirrored_repeat",
79 "GL_ARB_vertex_buffer_object",
80 "GL_ARB_vertex_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",
98 "GL_NV_blend_square",
99 "GL_NV_vertex_program",
100 "GL_SGIS_generate_mipmap",
101 NULL
102 };
103
104 extern struct tnl_pipeline_stage _r300_render_stage;
105
106 static const struct tnl_pipeline_stage *r300_pipeline[] = {
107
108 /* Try and go straight to t&l
109 */
110 // &_r300_tcl_stage,
111
112 /* Catch any t&l fallbacks
113 */
114 &_tnl_vertex_transform_stage,
115 &_tnl_normal_transform_stage,
116 &_tnl_lighting_stage,
117 &_tnl_fog_coordinate_stage,
118 &_tnl_texgen_stage,
119 &_tnl_texture_transform_stage,
120 &_tnl_vertex_program_stage,
121
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
126 * - good for texgen
127 * - need to manipulate a bit of state
128 *
129 * - worth it/not worth it?
130 */
131
132 /* Else do them here.
133 */
134 &_r300_render_stage,
135 &_tnl_render_stage, /* FALLBACK */
136 0,
137 };
138
139
140 /* Create the device specific rendering context.
141 */
142 GLboolean r300CreateContext(const __GLcontextModes * glVisual,
143 __DRIcontextPrivate * driContextPriv,
144 void *sharedContextPrivate)
145 {
146 __DRIscreenPrivate *sPriv = driContextPriv->driScreenPriv;
147 radeonScreenPtr screen = (radeonScreenPtr) (sPriv->private);
148 struct dd_function_table functions;
149 r300ContextPtr r300;
150 GLcontext *ctx;
151 int tcl_mode, i;
152
153 assert(glVisual);
154 assert(driContextPriv);
155 assert(screen);
156
157 /* Allocate the R300 context */
158 r300 = (r300ContextPtr)CALLOC(sizeof(*r300));
159 if (!r300)
160 return GL_FALSE;
161
162 /* Parse configuration files.
163 * Do this here so that initialMaxAnisotropy is set before we create
164 * the default textures.
165 */
166 driParseConfigFiles(&r300->radeon.optionCache, &screen->optionCache,
167 screen->driScreen->myNum, "r300");
168
169 /* Init default driver functions then plug in our R300-specific functions
170 * (the texture functions are especially important)
171 */
172 _mesa_init_driver_functions(&functions);
173 r300InitIoctlFuncs(&functions);
174 r300InitStateFuncs(&functions);
175 r300InitTextureFuncs(&functions);
176
177 if (!radeonInitContext(&r300->radeon, &functions,
178 glVisual, driContextPriv, sharedContextPrivate)) {
179 FREE(r300);
180 return GL_FALSE;
181 }
182
183 /* Init r300 context data */
184 r300->dma.buf0_address = r300->radeon.radeonScreen->buffers->list[0].address;
185
186 (void)memset(r300->texture_heaps, 0, sizeof(r300->texture_heaps));
187 make_empty_list(&r300->swapped);
188
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,
193 screen->
194 texSize[i], 12,
195 RADEON_NR_TEX_REGIONS,
196 (drmTextureRegionPtr)
197 r300->radeon.sarea->
198 tex_list[i],
199 &r300->radeon.sarea->
200 tex_age[i],
201 &r300->swapped,
202 sizeof
203 (r300TexObj),
204 (destroy_texture_object_t
205 *)
206 r300DestroyTexObj);
207 }
208 r300->texture_depth = driQueryOptioni(&r300->radeon.optionCache,
209 "texture_depth");
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;
213
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.
217 */
218
219 ctx = r300->radeon.glCtx;
220 ctx->Const.MaxTextureImageUnits = driQueryOptioni(&r300->radeon.optionCache,
221 "texture_image_units");
222 ctx->Const.MaxTextureCoordUnits = driQueryOptioni(&r300->radeon.optionCache,
223 "texture_coord_units");
224 ctx->Const.MaxTextureUnits = MIN2(ctx->Const.MaxTextureImageUnits,
225 ctx->Const.MaxTextureCoordUnits);
226 ctx->Const.MaxTextureMaxAnisotropy = 16.0;
227
228 /* No wide points.
229 */
230 ctx->Const.MinPointSize = 1.0;
231 ctx->Const.MinPointSizeAA = 1.0;
232 ctx->Const.MaxPointSize = 1.0;
233 ctx->Const.MaxPointSizeAA = 1.0;
234
235 ctx->Const.MinLineWidth = 1.0;
236 ctx->Const.MinLineWidthAA = 1.0;
237 ctx->Const.MaxLineWidth = 1.0;
238 ctx->Const.MaxLineWidthAA = 1.0;
239
240 /* Initialize the software rasterizer and helper modules.
241 */
242 _swrast_CreateContext(ctx);
243 _ac_CreateContext(ctx);
244 _tnl_CreateContext(ctx);
245 _swsetup_CreateContext(ctx);
246 _ae_create_context(ctx);
247
248 /* Install the customized pipeline:
249 */
250 _tnl_destroy_pipeline(ctx);
251 _tnl_install_pipeline(ctx, r300_pipeline);
252
253 /* Try and keep materials and vertices separate:
254 */
255 _tnl_isolate_materials(ctx, GL_TRUE);
256
257 /* Configure swrast and TNL to match hardware characteristics:
258 */
259 _swrast_allow_pixel_fog(ctx, GL_FALSE);
260 _swrast_allow_vertex_fog(ctx, GL_TRUE);
261 _tnl_allow_pixel_fog(ctx, GL_FALSE);
262 _tnl_allow_vertex_fog(ctx, GL_TRUE);
263
264 driInitExtensions(ctx, card_extensions, GL_TRUE);
265
266 radeonInitSpanFuncs(ctx);
267 r300InitCmdBuf(r300);
268 r300InitState(r300);
269 #if 0
270 /* plug in a few more device driver functions */
271 /* XXX these should really go right after _mesa_init_driver_functions() */
272 r300InitPixelFuncs(ctx);
273 r300InitSwtcl(ctx);
274 #endif
275 TNL_CONTEXT(ctx)->Driver.RunPipeline = _tnl_run_pipeline;
276
277 tcl_mode = driQueryOptioni(&r300->radeon.optionCache, "tcl_mode");
278 if (driQueryOptionb(&r300->radeon.optionCache, "no_rast")) {
279 fprintf(stderr, "disabling 3D acceleration\n");
280 FALLBACK(&r300->radeon, RADEON_FALLBACK_DISABLE, 1);
281 }
282 if (tcl_mode == DRI_CONF_TCL_SW ||
283 !(r300->radeon.radeonScreen->chipset & RADEON_CHIPSET_TCL)) {
284 if (r300->radeon.radeonScreen->chipset & RADEON_CHIPSET_TCL) {
285 r300->radeon.radeonScreen->chipset &= ~RADEON_CHIPSET_TCL;
286 fprintf(stderr, "Disabling HW TCL support\n");
287 }
288 TCL_FALLBACK(r300->radeon.glCtx, RADEON_TCL_FALLBACK_TCL_DISABLE, 1);
289 }
290
291 return GL_TRUE;
292 }
293
294 /* Destroy the device specific context.
295 */
296 void r300DestroyContext(__DRIcontextPrivate * driContextPriv)
297 {
298 GET_CURRENT_CONTEXT(ctx);
299 r300ContextPtr r300 = (r300ContextPtr) driContextPriv->driverPrivate;
300 radeonContextPtr current = ctx ? RADEON_CONTEXT(ctx) : NULL;
301
302 fprintf(stderr, "Destroying context !\n");
303 sleep(1);
304 /* check if we're deleting the currently bound context */
305 if (&r300->radeon == current) {
306 radeonFlush(r300->radeon.glCtx);
307 _mesa_make_current2(NULL, NULL, NULL);
308 }
309
310 /* Free r300 context resources */
311 assert(r300); /* should never be null */
312
313 if (r300) {
314 GLboolean release_texture_heaps;
315
316 release_texture_heaps = (r300->radeon.glCtx->Shared->RefCount == 1);
317 _swsetup_DestroyContext(r300->radeon.glCtx);
318 _tnl_DestroyContext(r300->radeon.glCtx);
319 _ac_DestroyContext(r300->radeon.glCtx);
320 _swrast_DestroyContext(r300->radeon.glCtx);
321
322 r300DestroyCmdBuf(r300);
323
324 radeonCleanupContext(&r300->radeon);
325
326 /* free the option cache */
327 driDestroyOptionCache(&r300->radeon.optionCache);
328
329 FREE(r300);
330 }
331 }