r600: fix typo in the last commit
[mesa.git] / src / mesa / drivers / dri / r600 / r600_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 * \file
32 *
33 * \author Keith Whitwell <keith@tungstengraphics.com>
34 *
35 * \author Nicolai Haehnle <prefect_@gmx.net>
36 */
37
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"
47 #include "main/texobj.h"
48
49 #include "swrast/swrast.h"
50 #include "swrast_setup/swrast_setup.h"
51 #include "vbo/vbo.h"
52
53 #include "tnl/tnl.h"
54 #include "tnl/t_pipeline.h"
55 #include "tnl/t_vp_build.h"
56
57 #include "drivers/common/driverfuncs.h"
58
59 #include "radeon_debug.h"
60 #include "r600_context.h"
61 #include "radeon_common_context.h"
62 #include "radeon_span.h"
63 #include "r600_cmdbuf.h"
64 #include "r600_emit.h"
65 #include "radeon_bocs_wrapper.h"
66
67 #include "r700_state.h"
68 #include "r700_ioctl.h"
69
70
71 #include "vblank.h"
72 #include "utils.h"
73 #include "xmlpool.h" /* for symbolic values of enum-type options */
74
75 /* hw_tcl_on derives from future_hw_tcl_on when its safe to change it. */
76 int future_hw_tcl_on = 1;
77 int hw_tcl_on = 1;
78
79 #define need_GL_VERSION_2_0
80 #define need_GL_ARB_point_parameters
81 #define need_GL_ARB_vertex_program
82 #define need_GL_EXT_blend_equation_separate
83 #define need_GL_EXT_blend_func_separate
84 #define need_GL_EXT_blend_minmax
85 #define need_GL_EXT_framebuffer_object
86 #define need_GL_EXT_fog_coord
87 #define need_GL_EXT_gpu_program_parameters
88 #define need_GL_EXT_secondary_color
89 #define need_GL_EXT_stencil_two_side
90 #define need_GL_ATI_separate_stencil
91 #define need_GL_NV_vertex_program
92
93 #include "extension_helper.h"
94
95 extern const struct tnl_pipeline_stage *r700_pipeline[];
96
97 const struct dri_extension card_extensions[] = {
98 /* *INDENT-OFF* */
99 {"GL_ARB_depth_texture", NULL},
100 {"GL_ARB_fragment_program", NULL},
101 {"GL_ARB_multitexture", NULL},
102 {"GL_ARB_point_parameters", GL_ARB_point_parameters_functions},
103 {"GL_ARB_shadow", NULL},
104 {"GL_ARB_shadow_ambient", NULL},
105 {"GL_ARB_texture_border_clamp", NULL},
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_program", GL_ARB_vertex_program_functions},
113 {"GL_EXT_blend_equation_separate", GL_EXT_blend_equation_separate_functions},
114 {"GL_EXT_blend_func_separate", GL_EXT_blend_func_separate_functions},
115 {"GL_EXT_blend_minmax", GL_EXT_blend_minmax_functions},
116 {"GL_EXT_blend_subtract", NULL},
117 {"GL_EXT_packed_depth_stencil", NULL},
118 {"GL_EXT_fog_coord", GL_EXT_fog_coord_functions },
119 {"GL_EXT_gpu_program_parameters", GL_EXT_gpu_program_parameters_functions},
120 {"GL_EXT_secondary_color", GL_EXT_secondary_color_functions},
121 {"GL_EXT_shadow_funcs", NULL},
122 {"GL_EXT_stencil_two_side", GL_EXT_stencil_two_side_functions},
123 {"GL_EXT_stencil_wrap", NULL},
124 {"GL_EXT_texture_edge_clamp", NULL},
125 {"GL_EXT_texture_env_combine", NULL},
126 {"GL_EXT_texture_env_dot3", NULL},
127 {"GL_EXT_texture_filter_anisotropic", NULL},
128 {"GL_EXT_texture_lod_bias", NULL},
129 {"GL_EXT_texture_mirror_clamp", NULL},
130 {"GL_EXT_texture_rectangle", NULL},
131 {"GL_ATI_separate_stencil", GL_ATI_separate_stencil_functions},
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},
140 {NULL, NULL}
141 /* *INDENT-ON* */
142 };
143
144
145 const struct dri_extension mm_extensions[] = {
146 { "GL_EXT_framebuffer_object", GL_EXT_framebuffer_object_functions },
147 { NULL, NULL }
148 };
149
150 /**
151 * The GL 2.0 functions are needed to make display lists work with
152 * functions added by GL_ATI_separate_stencil.
153 */
154 const struct dri_extension gl_20_extension[] = {
155 {"GL_VERSION_2_0", GL_VERSION_2_0_functions },
156 };
157
158
159 static void r600RunPipeline(GLcontext * ctx)
160 {
161 _mesa_lock_context_textures(ctx);
162
163 if (ctx->NewState)
164 _mesa_update_state_locked(ctx);
165
166 _tnl_run_pipeline(ctx);
167 _mesa_unlock_context_textures(ctx);
168 }
169
170 static void r600_get_lock(radeonContextPtr rmesa)
171 {
172 drm_radeon_sarea_t *sarea = rmesa->sarea;
173
174 if (sarea->ctx_owner != rmesa->dri.hwContext) {
175 sarea->ctx_owner = rmesa->dri.hwContext;
176 if (!rmesa->radeonScreen->kernel_mm)
177 radeon_bo_legacy_texture_age(rmesa->radeonScreen->bom);
178 }
179 }
180
181 static void r600_vtbl_emit_cs_header(struct radeon_cs *cs, radeonContextPtr rmesa)
182 {
183 /* please flush pipe do all pending work */
184 /* to be enabled */
185 }
186
187 static void r600_vtbl_pre_emit_atoms(radeonContextPtr radeon)
188 {
189 r700Start3D((context_t *)radeon);
190 }
191
192 static void r600_fallback(GLcontext *ctx, GLuint bit, GLboolean mode)
193 {
194 context_t *context = R700_CONTEXT(ctx);
195 if (mode)
196 context->radeon.Fallback |= bit;
197 else
198 context->radeon.Fallback &= ~bit;
199 }
200
201 static void r600_init_vtbl(radeonContextPtr radeon)
202 {
203 radeon->vtbl.get_lock = r600_get_lock;
204 radeon->vtbl.update_viewport_offset = r700UpdateViewportOffset;
205 radeon->vtbl.emit_cs_header = r600_vtbl_emit_cs_header;
206 radeon->vtbl.swtcl_flush = NULL;
207 radeon->vtbl.pre_emit_atoms = r600_vtbl_pre_emit_atoms;
208 radeon->vtbl.fallback = r600_fallback;
209 }
210
211 /* Create the device specific rendering context.
212 */
213 GLboolean r600CreateContext(const __GLcontextModes * glVisual,
214 __DRIcontextPrivate * driContextPriv,
215 void *sharedContextPrivate)
216 {
217 __DRIscreenPrivate *sPriv = driContextPriv->driScreenPriv;
218 radeonScreenPtr screen = (radeonScreenPtr) (sPriv->private);
219 struct dd_function_table functions;
220 context_t *r600;
221 GLcontext *ctx;
222
223 assert(glVisual);
224 assert(driContextPriv);
225 assert(screen);
226
227 /* Allocate the R600 context */
228 r600 = (context_t*) CALLOC(sizeof(*r600));
229 if (!r600) {
230 radeon_error("Failed to allocate memory for context.\n");
231 return GL_FALSE;
232 }
233
234 if (!(screen->chip_flags & RADEON_CHIPSET_TCL))
235 hw_tcl_on = future_hw_tcl_on = 0;
236
237 r600_init_vtbl(&r600->radeon);
238 /* Parse configuration files.
239 * Do this here so that initialMaxAnisotropy is set before we create
240 * the default textures.
241 */
242 driParseConfigFiles(&r600->radeon.optionCache, &screen->optionCache,
243 screen->driScreen->myNum, "r600");
244
245 r600->radeon.initialMaxAnisotropy = driQueryOptionf(&r600->radeon.optionCache,
246 "def_max_anisotropy");
247
248 /* Init default driver functions then plug in our R600-specific functions
249 * (the texture functions are especially important)
250 */
251 _mesa_init_driver_functions(&functions);
252
253 r700InitStateFuncs(&functions);
254 r600InitTextureFuncs(&functions);
255 r700InitShaderFuncs(&functions);
256 r700InitIoctlFuncs(&functions);
257
258 if (!radeonInitContext(&r600->radeon, &functions,
259 glVisual, driContextPriv,
260 sharedContextPrivate)) {
261 radeon_error("Initializing context failed.\n");
262 FREE(r600);
263 return GL_FALSE;
264 }
265
266 /* Init r600 context data */
267 /* Set the maximum texture size small enough that we can guarentee that
268 * all texture units can bind a maximal texture and have them both in
269 * texturable memory at once.
270 */
271
272 ctx = r600->radeon.glCtx;
273
274 ctx->Const.MaxTextureImageUnits =
275 driQueryOptioni(&r600->radeon.optionCache, "texture_image_units");
276 ctx->Const.MaxTextureCoordUnits =
277 driQueryOptioni(&r600->radeon.optionCache, "texture_coord_units");
278 ctx->Const.MaxTextureUnits =
279 MIN2(ctx->Const.MaxTextureImageUnits,
280 ctx->Const.MaxTextureCoordUnits);
281 ctx->Const.MaxTextureMaxAnisotropy = 16.0;
282 ctx->Const.MaxTextureLodBias = 16.0;
283
284 ctx->Const.MaxTextureLevels = 13; /* hw support 14 */
285 ctx->Const.MaxTextureRectSize = 4096; /* hw support 8192 */
286
287 ctx->Const.MinPointSize = 0x0001 / 8.0;
288 ctx->Const.MinPointSizeAA = 0x0001 / 8.0;
289 ctx->Const.MaxPointSize = 0xffff / 8.0;
290 ctx->Const.MaxPointSizeAA = 0xffff / 8.0;
291
292 ctx->Const.MinLineWidth = 0x0001 / 8.0;
293 ctx->Const.MinLineWidthAA = 0x0001 / 8.0;
294 ctx->Const.MaxLineWidth = 0xffff / 8.0;
295 ctx->Const.MaxLineWidthAA = 0xffff / 8.0;
296
297 /* Needs further modifications */
298 #if 0
299 ctx->Const.MaxArrayLockSize =
300 ( /*512 */ RADEON_BUFFER_SIZE * 16 * 1024) / (4 * 4);
301 #endif
302
303 ctx->Const.MaxDrawBuffers = 1;
304
305 /* Initialize the software rasterizer and helper modules.
306 */
307 _swrast_CreateContext(ctx);
308 _vbo_CreateContext(ctx);
309 _tnl_CreateContext(ctx);
310 _swsetup_CreateContext(ctx);
311 _swsetup_Wakeup(ctx);
312 _ae_create_context(ctx);
313
314 /* Install the customized pipeline:
315 */
316 _tnl_destroy_pipeline(ctx);
317 _tnl_install_pipeline(ctx, r700_pipeline);
318
319 /* Try and keep materials and vertices separate:
320 */
321 /* _tnl_isolate_materials(ctx, GL_TRUE); */
322
323 /* Configure swrast and TNL to match hardware characteristics:
324 */
325 _swrast_allow_pixel_fog(ctx, GL_FALSE);
326 _swrast_allow_vertex_fog(ctx, GL_TRUE);
327 _tnl_allow_pixel_fog(ctx, GL_FALSE);
328 _tnl_allow_vertex_fog(ctx, GL_TRUE);
329
330 /* 256 for reg-based consts, inline consts also supported */
331 ctx->Const.VertexProgram.MaxInstructions = 8192; /* in theory no limit */
332 ctx->Const.VertexProgram.MaxNativeInstructions = 8192;
333 ctx->Const.VertexProgram.MaxNativeAttribs = 160;
334 ctx->Const.VertexProgram.MaxTemps = 128;
335 ctx->Const.VertexProgram.MaxNativeTemps = 128;
336 ctx->Const.VertexProgram.MaxNativeParameters = 256;
337 ctx->Const.VertexProgram.MaxNativeAddressRegs = 1; /* ??? */
338
339 ctx->Const.FragmentProgram.MaxNativeTemps = 128;
340 ctx->Const.FragmentProgram.MaxNativeAttribs = 32;
341 ctx->Const.FragmentProgram.MaxNativeParameters = 256;
342 ctx->Const.FragmentProgram.MaxNativeAluInstructions = 8192;
343 /* 8 per clause on r6xx, 16 on rv670/r7xx */
344 if ((screen->chip_family == CHIP_FAMILY_RV670) ||
345 (screen->chip_family >= CHIP_FAMILY_RV770))
346 ctx->Const.FragmentProgram.MaxNativeTexInstructions = 16;
347 else
348 ctx->Const.FragmentProgram.MaxNativeTexInstructions = 8;
349 ctx->Const.FragmentProgram.MaxNativeInstructions = 8192;
350 ctx->Const.FragmentProgram.MaxNativeTexIndirections = 8; /* ??? */
351 ctx->Const.FragmentProgram.MaxNativeAddressRegs = 0; /* and these are?? */
352 ctx->VertexProgram._MaintainTnlProgram = GL_TRUE;
353 ctx->FragmentProgram._MaintainTexEnvProgram = GL_TRUE;
354
355 radeon_init_debug();
356
357 driInitExtensions(ctx, card_extensions, GL_TRUE);
358 if (r600->radeon.radeonScreen->kernel_mm)
359 driInitExtensions(ctx, mm_extensions, GL_FALSE);
360
361 if (driQueryOptionb
362 (&r600->radeon.optionCache, "disable_stencil_two_side"))
363 _mesa_disable_extension(ctx, "GL_EXT_stencil_two_side");
364
365 if (r600->radeon.glCtx->Mesa_DXTn
366 && !driQueryOptionb(&r600->radeon.optionCache, "disable_s3tc")) {
367 _mesa_enable_extension(ctx, "GL_EXT_texture_compression_s3tc");
368 _mesa_enable_extension(ctx, "GL_S3_s3tc");
369 } else
370 if (driQueryOptionb(&r600->radeon.optionCache, "force_s3tc_enable"))
371 {
372 _mesa_enable_extension(ctx, "GL_EXT_texture_compression_s3tc");
373 }
374
375 radeon_fbo_init(&r600->radeon);
376 radeonInitSpanFuncs( ctx );
377
378 r600InitCmdBuf(r600);
379
380 r700InitState(r600->radeon.glCtx);
381
382 TNL_CONTEXT(ctx)->Driver.RunPipeline = r600RunPipeline;
383
384 if (driQueryOptionb(&r600->radeon.optionCache, "no_rast")) {
385 radeon_warning("disabling 3D acceleration\n");
386 #if R200_MERGED
387 FALLBACK(&r600->radeon, RADEON_FALLBACK_DISABLE, 1);
388 #endif
389 }
390
391 return GL_TRUE;
392 }
393
394