updated comment
[mesa.git] / src / mesa / drivers / dri / radeon / radeon_state_init.c
1 /* $XFree86: xc/lib/GL/mesa/src/drv/radeon/radeon_state_init.c,v 1.3 2003/02/22 06:21:11 dawes Exp $ */
2 /*
3 * Copyright 2000, 2001 VA Linux Systems Inc., Fremont, California.
4 *
5 * All Rights Reserved.
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * on the rights to use, copy, modify, merge, publish, distribute, sub
11 * license, and/or sell copies of the Software, and to permit persons to whom
12 * the Software is furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the next
15 * paragraph) shall be included in all copies or substantial portions of the
16 * Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
21 * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
22 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
23 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
24 * OTHER DEALINGS IN THE SOFTWARE.
25 *
26 * Authors:
27 * Gareth Hughes <gareth@valinux.com>
28 * Keith Whitwell <keith@tungstengraphics.com>
29 */
30
31 #include "glheader.h"
32 #include "imports.h"
33 #include "api_arrayelt.h"
34
35 #include "swrast/swrast.h"
36 #include "array_cache/acache.h"
37 #include "tnl/tnl.h"
38 #include "tnl/t_pipeline.h"
39 #include "swrast_setup/swrast_setup.h"
40
41 #include "radeon_context.h"
42 #include "radeon_ioctl.h"
43 #include "radeon_state.h"
44 #include "radeon_tcl.h"
45 #include "radeon_tex.h"
46 #include "radeon_swtcl.h"
47 #include "radeon_vtxfmt.h"
48
49 #include "xmlpool.h"
50
51 /* =============================================================
52 * State initialization
53 */
54
55 void radeonPrintDirty( radeonContextPtr rmesa, const char *msg )
56 {
57 struct radeon_state_atom *l;
58
59 fprintf(stderr, msg);
60 fprintf(stderr, ": ");
61
62 foreach(l, &rmesa->hw.atomlist) {
63 if (l->dirty || rmesa->hw.all_dirty)
64 fprintf(stderr, "%s, ", l->name);
65 }
66
67 fprintf(stderr, "\n");
68 }
69
70 static int cmdpkt( int id )
71 {
72 drm_radeon_cmd_header_t h;
73 h.i = 0;
74 h.packet.cmd_type = RADEON_CMD_PACKET;
75 h.packet.packet_id = id;
76 return h.i;
77 }
78
79 static int cmdvec( int offset, int stride, int count )
80 {
81 drm_radeon_cmd_header_t h;
82 h.i = 0;
83 h.vectors.cmd_type = RADEON_CMD_VECTORS;
84 h.vectors.offset = offset;
85 h.vectors.stride = stride;
86 h.vectors.count = count;
87 return h.i;
88 }
89
90 static int cmdscl( int offset, int stride, int count )
91 {
92 drm_radeon_cmd_header_t h;
93 h.i = 0;
94 h.scalars.cmd_type = RADEON_CMD_SCALARS;
95 h.scalars.offset = offset;
96 h.scalars.stride = stride;
97 h.scalars.count = count;
98 return h.i;
99 }
100
101 #define CHECK( NM, FLAG ) \
102 static GLboolean check_##NM( GLcontext *ctx ) \
103 { \
104 return FLAG; \
105 }
106
107 #define TCL_CHECK( NM, FLAG ) \
108 static GLboolean check_##NM( GLcontext *ctx ) \
109 { \
110 radeonContextPtr rmesa = RADEON_CONTEXT(ctx); \
111 return !rmesa->TclFallback && (FLAG); \
112 }
113
114
115 CHECK( always, GL_TRUE )
116 CHECK( tex0, ctx->Texture.Unit[0]._ReallyEnabled )
117 CHECK( tex1, ctx->Texture.Unit[1]._ReallyEnabled )
118 CHECK( fog, ctx->Fog.Enabled )
119 TCL_CHECK( tcl, GL_TRUE )
120 TCL_CHECK( tcl_tex0, ctx->Texture.Unit[0]._ReallyEnabled )
121 TCL_CHECK( tcl_tex1, ctx->Texture.Unit[1]._ReallyEnabled )
122 TCL_CHECK( tcl_lighting, ctx->Light.Enabled )
123 TCL_CHECK( tcl_eyespace_or_lighting, ctx->_NeedEyeCoords || ctx->Light.Enabled )
124 TCL_CHECK( tcl_lit0, ctx->Light.Enabled && ctx->Light.Light[0].Enabled )
125 TCL_CHECK( tcl_lit1, ctx->Light.Enabled && ctx->Light.Light[1].Enabled )
126 TCL_CHECK( tcl_lit2, ctx->Light.Enabled && ctx->Light.Light[2].Enabled )
127 TCL_CHECK( tcl_lit3, ctx->Light.Enabled && ctx->Light.Light[3].Enabled )
128 TCL_CHECK( tcl_lit4, ctx->Light.Enabled && ctx->Light.Light[4].Enabled )
129 TCL_CHECK( tcl_lit5, ctx->Light.Enabled && ctx->Light.Light[5].Enabled )
130 TCL_CHECK( tcl_lit6, ctx->Light.Enabled && ctx->Light.Light[6].Enabled )
131 TCL_CHECK( tcl_lit7, ctx->Light.Enabled && ctx->Light.Light[7].Enabled )
132 TCL_CHECK( tcl_ucp0, (ctx->Transform.ClipPlanesEnabled & 0x1) )
133 TCL_CHECK( tcl_ucp1, (ctx->Transform.ClipPlanesEnabled & 0x2) )
134 TCL_CHECK( tcl_ucp2, (ctx->Transform.ClipPlanesEnabled & 0x4) )
135 TCL_CHECK( tcl_ucp3, (ctx->Transform.ClipPlanesEnabled & 0x8) )
136 TCL_CHECK( tcl_ucp4, (ctx->Transform.ClipPlanesEnabled & 0x10) )
137 TCL_CHECK( tcl_ucp5, (ctx->Transform.ClipPlanesEnabled & 0x20) )
138 TCL_CHECK( tcl_eyespace_or_fog, ctx->_NeedEyeCoords || ctx->Fog.Enabled )
139
140 CHECK( txr0, (ctx->Texture.Unit[0]._ReallyEnabled & TEXTURE_RECT_BIT))
141 CHECK( txr1, (ctx->Texture.Unit[1]._ReallyEnabled & TEXTURE_RECT_BIT))
142
143
144
145 /* Initialize the context's hardware state.
146 */
147 void radeonInitState( radeonContextPtr rmesa )
148 {
149 GLcontext *ctx = rmesa->glCtx;
150 GLuint color_fmt, depth_fmt, i;
151 GLint drawPitch, drawOffset;
152
153 switch ( rmesa->radeonScreen->cpp ) {
154 case 2:
155 color_fmt = RADEON_COLOR_FORMAT_RGB565;
156 break;
157 case 4:
158 color_fmt = RADEON_COLOR_FORMAT_ARGB8888;
159 break;
160 default:
161 fprintf( stderr, "Error: Unsupported pixel depth... exiting\n" );
162 exit( -1 );
163 }
164
165 rmesa->state.color.clear = 0x00000000;
166
167 switch ( ctx->Visual.depthBits ) {
168 case 16:
169 rmesa->state.depth.clear = 0x0000ffff;
170 rmesa->state.depth.scale = 1.0 / (GLfloat)0xffff;
171 depth_fmt = RADEON_DEPTH_FORMAT_16BIT_INT_Z;
172 rmesa->state.stencil.clear = 0x00000000;
173 break;
174 case 24:
175 rmesa->state.depth.clear = 0x00ffffff;
176 rmesa->state.depth.scale = 1.0 / (GLfloat)0xffffff;
177 depth_fmt = RADEON_DEPTH_FORMAT_24BIT_INT_Z;
178 rmesa->state.stencil.clear = 0xffff0000;
179 break;
180 default:
181 fprintf( stderr, "Error: Unsupported depth %d... exiting\n",
182 ctx->Visual.depthBits );
183 exit( -1 );
184 }
185
186 /* Only have hw stencil when depth buffer is 24 bits deep */
187 rmesa->state.stencil.hwBuffer = ( ctx->Visual.stencilBits > 0 &&
188 ctx->Visual.depthBits == 24 );
189
190 rmesa->Fallback = 0;
191
192 if ( ctx->Visual.doubleBufferMode && rmesa->sarea->pfCurrentPage == 0 ) {
193 drawOffset = rmesa->radeonScreen->backOffset;
194 drawPitch = rmesa->radeonScreen->backPitch;
195 } else {
196 drawOffset = rmesa->radeonScreen->frontOffset;
197 drawPitch = rmesa->radeonScreen->frontPitch;
198 }
199
200 rmesa->hw.max_state_size = 0;
201
202 #define ALLOC_STATE( ATOM, CHK, SZ, NM, FLAG ) \
203 do { \
204 rmesa->hw.ATOM.cmd_size = SZ; \
205 rmesa->hw.ATOM.cmd = (int *)CALLOC(SZ * sizeof(int)); \
206 rmesa->hw.ATOM.lastcmd = (int *)CALLOC(SZ * sizeof(int)); \
207 rmesa->hw.ATOM.name = NM; \
208 rmesa->hw.ATOM.is_tcl = FLAG; \
209 rmesa->hw.ATOM.check = check_##CHK; \
210 rmesa->hw.ATOM.dirty = GL_TRUE; \
211 rmesa->hw.max_state_size += SZ * sizeof(int); \
212 } while (0)
213
214
215 /* Allocate state buffers:
216 */
217 ALLOC_STATE( ctx, always, CTX_STATE_SIZE, "CTX/context", 0 );
218 ALLOC_STATE( lin, always, LIN_STATE_SIZE, "LIN/line", 0 );
219 ALLOC_STATE( msk, always, MSK_STATE_SIZE, "MSK/mask", 0 );
220 ALLOC_STATE( vpt, always, VPT_STATE_SIZE, "VPT/viewport", 0 );
221 ALLOC_STATE( set, always, SET_STATE_SIZE, "SET/setup", 0 );
222 ALLOC_STATE( msc, always, MSC_STATE_SIZE, "MSC/misc", 0 );
223 ALLOC_STATE( zbs, always, ZBS_STATE_SIZE, "ZBS/zbias", 0 );
224 ALLOC_STATE( tcl, always, TCL_STATE_SIZE, "TCL/tcl", 1 );
225 ALLOC_STATE( mtl, tcl_lighting, MTL_STATE_SIZE, "MTL/material", 1 );
226 ALLOC_STATE( grd, always, GRD_STATE_SIZE, "GRD/guard-band", 1 );
227 ALLOC_STATE( fog, fog, FOG_STATE_SIZE, "FOG/fog", 1 );
228 ALLOC_STATE( glt, tcl_lighting, GLT_STATE_SIZE, "GLT/light-global", 1 );
229 ALLOC_STATE( eye, tcl_lighting, EYE_STATE_SIZE, "EYE/eye-vector", 1 );
230 ALLOC_STATE( tex[0], tex0, TEX_STATE_SIZE, "TEX/tex-0", 0 );
231 ALLOC_STATE( tex[1], tex1, TEX_STATE_SIZE, "TEX/tex-1", 0 );
232 ALLOC_STATE( mat[0], tcl, MAT_STATE_SIZE, "MAT/modelproject", 1 );
233 ALLOC_STATE( mat[1], tcl_eyespace_or_fog, MAT_STATE_SIZE, "MAT/modelview", 1 );
234 ALLOC_STATE( mat[2], tcl_eyespace_or_lighting, MAT_STATE_SIZE, "MAT/it-modelview", 1 );
235 ALLOC_STATE( mat[3], tcl_tex0, MAT_STATE_SIZE, "MAT/texmat0", 1 );
236 ALLOC_STATE( mat[4], tcl_tex1, MAT_STATE_SIZE, "MAT/texmat1", 1 );
237 ALLOC_STATE( ucp[0], tcl_ucp0, UCP_STATE_SIZE, "UCP/userclip-0", 1 );
238 ALLOC_STATE( ucp[1], tcl_ucp1, UCP_STATE_SIZE, "UCP/userclip-1", 1 );
239 ALLOC_STATE( ucp[2], tcl_ucp2, UCP_STATE_SIZE, "UCP/userclip-2", 1 );
240 ALLOC_STATE( ucp[3], tcl_ucp3, UCP_STATE_SIZE, "UCP/userclip-3", 1 );
241 ALLOC_STATE( ucp[4], tcl_ucp4, UCP_STATE_SIZE, "UCP/userclip-4", 1 );
242 ALLOC_STATE( ucp[5], tcl_ucp5, UCP_STATE_SIZE, "UCP/userclip-5", 1 );
243 ALLOC_STATE( lit[0], tcl_lit0, LIT_STATE_SIZE, "LIT/light-0", 1 );
244 ALLOC_STATE( lit[1], tcl_lit1, LIT_STATE_SIZE, "LIT/light-1", 1 );
245 ALLOC_STATE( lit[2], tcl_lit2, LIT_STATE_SIZE, "LIT/light-2", 1 );
246 ALLOC_STATE( lit[3], tcl_lit3, LIT_STATE_SIZE, "LIT/light-3", 1 );
247 ALLOC_STATE( lit[4], tcl_lit4, LIT_STATE_SIZE, "LIT/light-4", 1 );
248 ALLOC_STATE( lit[5], tcl_lit5, LIT_STATE_SIZE, "LIT/light-5", 1 );
249 ALLOC_STATE( lit[6], tcl_lit6, LIT_STATE_SIZE, "LIT/light-6", 1 );
250 ALLOC_STATE( lit[7], tcl_lit7, LIT_STATE_SIZE, "LIT/light-7", 1 );
251 ALLOC_STATE( txr[0], txr0, TXR_STATE_SIZE, "TXR/txr-0", 0 );
252 ALLOC_STATE( txr[1], txr1, TXR_STATE_SIZE, "TXR/txr-1", 0 );
253
254 radeonSetUpAtomList( rmesa );
255
256 /* Fill in the packet headers:
257 */
258 rmesa->hw.ctx.cmd[CTX_CMD_0] = cmdpkt(RADEON_EMIT_PP_MISC);
259 rmesa->hw.ctx.cmd[CTX_CMD_1] = cmdpkt(RADEON_EMIT_PP_CNTL);
260 rmesa->hw.ctx.cmd[CTX_CMD_2] = cmdpkt(RADEON_EMIT_RB3D_COLORPITCH);
261 rmesa->hw.lin.cmd[LIN_CMD_0] = cmdpkt(RADEON_EMIT_RE_LINE_PATTERN);
262 rmesa->hw.lin.cmd[LIN_CMD_1] = cmdpkt(RADEON_EMIT_SE_LINE_WIDTH);
263 rmesa->hw.msk.cmd[MSK_CMD_0] = cmdpkt(RADEON_EMIT_RB3D_STENCILREFMASK);
264 rmesa->hw.vpt.cmd[VPT_CMD_0] = cmdpkt(RADEON_EMIT_SE_VPORT_XSCALE);
265 rmesa->hw.set.cmd[SET_CMD_0] = cmdpkt(RADEON_EMIT_SE_CNTL);
266 rmesa->hw.set.cmd[SET_CMD_1] = cmdpkt(RADEON_EMIT_SE_CNTL_STATUS);
267 rmesa->hw.msc.cmd[MSC_CMD_0] = cmdpkt(RADEON_EMIT_RE_MISC);
268 rmesa->hw.tex[0].cmd[TEX_CMD_0] = cmdpkt(RADEON_EMIT_PP_TXFILTER_0);
269 rmesa->hw.tex[0].cmd[TEX_CMD_1] = cmdpkt(RADEON_EMIT_PP_BORDER_COLOR_0);
270 rmesa->hw.tex[1].cmd[TEX_CMD_0] = cmdpkt(RADEON_EMIT_PP_TXFILTER_1);
271 rmesa->hw.tex[1].cmd[TEX_CMD_1] = cmdpkt(RADEON_EMIT_PP_BORDER_COLOR_1);
272 rmesa->hw.zbs.cmd[ZBS_CMD_0] = cmdpkt(RADEON_EMIT_SE_ZBIAS_FACTOR);
273 rmesa->hw.tcl.cmd[TCL_CMD_0] = cmdpkt(RADEON_EMIT_SE_TCL_OUTPUT_VTX_FMT);
274 rmesa->hw.mtl.cmd[MTL_CMD_0] =
275 cmdpkt(RADEON_EMIT_SE_TCL_MATERIAL_EMMISSIVE_RED);
276 rmesa->hw.txr[0].cmd[TXR_CMD_0] = cmdpkt(RADEON_EMIT_PP_TEX_SIZE_0);
277 rmesa->hw.txr[1].cmd[TXR_CMD_0] = cmdpkt(RADEON_EMIT_PP_TEX_SIZE_1);
278 rmesa->hw.grd.cmd[GRD_CMD_0] =
279 cmdscl( RADEON_SS_VERT_GUARD_CLIP_ADJ_ADDR, 1, 4 );
280 rmesa->hw.fog.cmd[FOG_CMD_0] =
281 cmdvec( RADEON_VS_FOG_PARAM_ADDR, 1, 4 );
282 rmesa->hw.glt.cmd[GLT_CMD_0] =
283 cmdvec( RADEON_VS_GLOBAL_AMBIENT_ADDR, 1, 4 );
284 rmesa->hw.eye.cmd[EYE_CMD_0] =
285 cmdvec( RADEON_VS_EYE_VECTOR_ADDR, 1, 4 );
286
287 for (i = 0 ; i < 5; i++) {
288 rmesa->hw.mat[i].cmd[MAT_CMD_0] =
289 cmdvec( RADEON_VS_MATRIX_0_ADDR + i*4, 1, 16);
290 }
291
292 for (i = 0 ; i < 8; i++) {
293 rmesa->hw.lit[i].cmd[LIT_CMD_0] =
294 cmdvec( RADEON_VS_LIGHT_AMBIENT_ADDR + i, 8, 24 );
295 rmesa->hw.lit[i].cmd[LIT_CMD_1] =
296 cmdscl( RADEON_SS_LIGHT_DCD_ADDR + i, 8, 6 );
297 }
298
299 for (i = 0 ; i < 6; i++) {
300 rmesa->hw.ucp[i].cmd[UCP_CMD_0] =
301 cmdvec( RADEON_VS_UCP_ADDR + i, 1, 4 );
302 }
303
304 rmesa->last_ReallyEnabled = -1;
305
306 /* Initial Harware state:
307 */
308 rmesa->hw.ctx.cmd[CTX_PP_MISC] = (RADEON_ALPHA_TEST_PASS |
309 RADEON_CHROMA_FUNC_FAIL |
310 RADEON_CHROMA_KEY_NEAREST |
311 RADEON_SHADOW_FUNC_EQUAL |
312 RADEON_SHADOW_PASS_1 |
313 RADEON_RIGHT_HAND_CUBE_OGL);
314
315 rmesa->hw.ctx.cmd[CTX_PP_FOG_COLOR] = (RADEON_FOG_VERTEX |
316 RADEON_FOG_USE_DEPTH);
317
318 rmesa->hw.ctx.cmd[CTX_RE_SOLID_COLOR] = 0x00000000;
319
320 rmesa->hw.ctx.cmd[CTX_RB3D_BLENDCNTL] = (RADEON_COMB_FCN_ADD_CLAMP |
321 RADEON_SRC_BLEND_GL_ONE |
322 RADEON_DST_BLEND_GL_ZERO );
323
324 rmesa->hw.ctx.cmd[CTX_RB3D_DEPTHOFFSET] =
325 rmesa->radeonScreen->depthOffset + rmesa->radeonScreen->fbLocation;
326
327 rmesa->hw.ctx.cmd[CTX_RB3D_DEPTHPITCH] =
328 ((rmesa->radeonScreen->depthPitch &
329 RADEON_DEPTHPITCH_MASK) |
330 RADEON_DEPTH_ENDIAN_NO_SWAP);
331
332 if (rmesa->using_hyperz)
333 rmesa->hw.ctx.cmd[CTX_RB3D_DEPTHPITCH] |= RADEON_DEPTH_HYPERZ;
334
335 rmesa->hw.ctx.cmd[CTX_RB3D_ZSTENCILCNTL] = (depth_fmt |
336 RADEON_Z_TEST_LESS |
337 RADEON_STENCIL_TEST_ALWAYS |
338 RADEON_STENCIL_FAIL_KEEP |
339 RADEON_STENCIL_ZPASS_KEEP |
340 RADEON_STENCIL_ZFAIL_KEEP |
341 RADEON_Z_WRITE_ENABLE);
342
343 if (rmesa->using_hyperz) {
344 rmesa->hw.ctx.cmd[CTX_RB3D_ZSTENCILCNTL] |= RADEON_Z_COMPRESSION_ENABLE |
345 RADEON_Z_DECOMPRESSION_ENABLE;
346 if (rmesa->radeonScreen->chipset & RADEON_CHIPSET_TCL) {
347 /* works for q3, but slight rendering errors with glxgears ? */
348 /* rmesa->hw.ctx.cmd[CTX_RB3D_ZSTENCILCNTL] |= RADEON_Z_HIERARCHY_ENABLE;*/
349 /* need this otherwise get lots of lockups with q3 ??? */
350 rmesa->hw.ctx.cmd[CTX_RB3D_ZSTENCILCNTL] |= RADEON_FORCE_Z_DIRTY;
351 }
352 }
353
354 rmesa->hw.ctx.cmd[CTX_PP_CNTL] = (RADEON_SCISSOR_ENABLE |
355 RADEON_ANTI_ALIAS_NONE);
356
357 rmesa->hw.ctx.cmd[CTX_RB3D_CNTL] = (RADEON_PLANE_MASK_ENABLE |
358 color_fmt |
359 RADEON_ZBLOCK16);
360
361 switch ( driQueryOptioni( &rmesa->optionCache, "dither_mode" ) ) {
362 case DRI_CONF_DITHER_XERRORDIFFRESET:
363 rmesa->hw.ctx.cmd[CTX_RB3D_CNTL] |= RADEON_DITHER_INIT;
364 break;
365 case DRI_CONF_DITHER_ORDERED:
366 rmesa->hw.ctx.cmd[CTX_RB3D_CNTL] |= RADEON_SCALE_DITHER_ENABLE;
367 break;
368 }
369 if ( driQueryOptioni( &rmesa->optionCache, "round_mode" ) ==
370 DRI_CONF_ROUND_ROUND )
371 rmesa->state.color.roundEnable = RADEON_ROUND_ENABLE;
372 else
373 rmesa->state.color.roundEnable = 0;
374 if ( driQueryOptioni (&rmesa->optionCache, "color_reduction" ) ==
375 DRI_CONF_COLOR_REDUCTION_DITHER )
376 rmesa->hw.ctx.cmd[CTX_RB3D_CNTL] |= RADEON_DITHER_ENABLE;
377 else
378 rmesa->hw.ctx.cmd[CTX_RB3D_CNTL] |= rmesa->state.color.roundEnable;
379
380 rmesa->hw.ctx.cmd[CTX_RB3D_COLOROFFSET] = ((drawOffset +
381 rmesa->radeonScreen->fbLocation)
382 & RADEON_COLOROFFSET_MASK);
383
384 rmesa->hw.ctx.cmd[CTX_RB3D_COLORPITCH] = ((drawPitch &
385 RADEON_COLORPITCH_MASK) |
386 RADEON_COLOR_ENDIAN_NO_SWAP);
387
388
389 /* (fixed size) sarea is initialized to zero afaics so can omit version check. Phew! */
390 if (rmesa->sarea->tiling_enabled) {
391 rmesa->hw.ctx.cmd[CTX_RB3D_COLORPITCH] |= RADEON_COLOR_TILE_ENABLE;
392 }
393
394 rmesa->hw.set.cmd[SET_SE_CNTL] = (RADEON_FFACE_CULL_CCW |
395 RADEON_BFACE_SOLID |
396 RADEON_FFACE_SOLID |
397 /* RADEON_BADVTX_CULL_DISABLE | */
398 RADEON_FLAT_SHADE_VTX_LAST |
399 RADEON_DIFFUSE_SHADE_GOURAUD |
400 RADEON_ALPHA_SHADE_GOURAUD |
401 RADEON_SPECULAR_SHADE_GOURAUD |
402 RADEON_FOG_SHADE_GOURAUD |
403 RADEON_VPORT_XY_XFORM_ENABLE |
404 RADEON_VPORT_Z_XFORM_ENABLE |
405 RADEON_VTX_PIX_CENTER_OGL |
406 RADEON_ROUND_MODE_TRUNC |
407 RADEON_ROUND_PREC_8TH_PIX);
408
409 rmesa->hw.set.cmd[SET_SE_CNTL_STATUS] =
410 #ifdef MESA_BIG_ENDIAN
411 RADEON_VC_32BIT_SWAP;
412 #else
413 RADEON_VC_NO_SWAP;
414 #endif
415
416 if (!(rmesa->radeonScreen->chipset & RADEON_CHIPSET_TCL)) {
417 rmesa->hw.set.cmd[SET_SE_CNTL_STATUS] |= RADEON_TCL_BYPASS;
418 }
419
420 rmesa->hw.set.cmd[SET_SE_COORDFMT] = (
421 RADEON_VTX_W0_IS_NOT_1_OVER_W0 |
422 RADEON_TEX1_W_ROUTING_USE_Q1);
423
424
425 rmesa->hw.lin.cmd[LIN_RE_LINE_PATTERN] = ((1 << 16) | 0xffff);
426
427 rmesa->hw.lin.cmd[LIN_RE_LINE_STATE] =
428 ((0 << RADEON_LINE_CURRENT_PTR_SHIFT) |
429 (1 << RADEON_LINE_CURRENT_COUNT_SHIFT));
430
431 rmesa->hw.lin.cmd[LIN_SE_LINE_WIDTH] = (1 << 4);
432
433 rmesa->hw.msk.cmd[MSK_RB3D_STENCILREFMASK] =
434 ((0x00 << RADEON_STENCIL_REF_SHIFT) |
435 (0xff << RADEON_STENCIL_MASK_SHIFT) |
436 (0xff << RADEON_STENCIL_WRITEMASK_SHIFT));
437
438 rmesa->hw.msk.cmd[MSK_RB3D_ROPCNTL] = RADEON_ROP_COPY;
439 rmesa->hw.msk.cmd[MSK_RB3D_PLANEMASK] = 0xffffffff;
440
441 rmesa->hw.msc.cmd[MSC_RE_MISC] =
442 ((0 << RADEON_STIPPLE_X_OFFSET_SHIFT) |
443 (0 << RADEON_STIPPLE_Y_OFFSET_SHIFT) |
444 RADEON_STIPPLE_BIG_BIT_ORDER);
445
446 rmesa->hw.vpt.cmd[VPT_SE_VPORT_XSCALE] = 0x00000000;
447 rmesa->hw.vpt.cmd[VPT_SE_VPORT_XOFFSET] = 0x00000000;
448 rmesa->hw.vpt.cmd[VPT_SE_VPORT_YSCALE] = 0x00000000;
449 rmesa->hw.vpt.cmd[VPT_SE_VPORT_YOFFSET] = 0x00000000;
450 rmesa->hw.vpt.cmd[VPT_SE_VPORT_ZSCALE] = 0x00000000;
451 rmesa->hw.vpt.cmd[VPT_SE_VPORT_ZOFFSET] = 0x00000000;
452
453 for ( i = 0 ; i < ctx->Const.MaxTextureUnits ; i++ ) {
454 rmesa->hw.tex[i].cmd[TEX_PP_TXFILTER] = RADEON_BORDER_MODE_OGL;
455 rmesa->hw.tex[i].cmd[TEX_PP_TXFORMAT] =
456 (RADEON_TXFORMAT_ENDIAN_NO_SWAP |
457 RADEON_TXFORMAT_PERSPECTIVE_ENABLE |
458 (i << 24) | /* This is one of RADEON_TXFORMAT_ST_ROUTE_STQ[012] */
459 (2 << RADEON_TXFORMAT_WIDTH_SHIFT) |
460 (2 << RADEON_TXFORMAT_HEIGHT_SHIFT));
461
462 /* Initialize the texture offset to the start of the card texture heap */
463 rmesa->hw.tex[i].cmd[TEX_PP_TXOFFSET] =
464 rmesa->radeonScreen->texOffset[RADEON_LOCAL_TEX_HEAP];
465
466 rmesa->hw.tex[i].cmd[TEX_PP_BORDER_COLOR] = 0;
467 rmesa->hw.tex[i].cmd[TEX_PP_TXCBLEND] =
468 (RADEON_COLOR_ARG_A_ZERO |
469 RADEON_COLOR_ARG_B_ZERO |
470 RADEON_COLOR_ARG_C_CURRENT_COLOR |
471 RADEON_BLEND_CTL_ADD |
472 RADEON_SCALE_1X |
473 RADEON_CLAMP_TX);
474 rmesa->hw.tex[i].cmd[TEX_PP_TXABLEND] =
475 (RADEON_ALPHA_ARG_A_ZERO |
476 RADEON_ALPHA_ARG_B_ZERO |
477 RADEON_ALPHA_ARG_C_CURRENT_ALPHA |
478 RADEON_BLEND_CTL_ADD |
479 RADEON_SCALE_1X |
480 RADEON_CLAMP_TX);
481 rmesa->hw.tex[i].cmd[TEX_PP_TFACTOR] = 0;
482 }
483
484 /* Can only add ST1 at the time of doing some multitex but can keep
485 * it after that. Errors if DIFFUSE is missing.
486 */
487 rmesa->hw.tcl.cmd[TCL_OUTPUT_VTXFMT] =
488 (RADEON_TCL_VTX_Z0 |
489 RADEON_TCL_VTX_W0 |
490 RADEON_TCL_VTX_PK_DIFFUSE
491 ); /* need to keep this uptodate */
492
493 rmesa->hw.tcl.cmd[TCL_OUTPUT_VTXSEL] =
494 ( RADEON_TCL_COMPUTE_XYZW |
495 (RADEON_TCL_TEX_INPUT_TEX_0 << RADEON_TCL_TEX_0_OUTPUT_SHIFT) |
496 (RADEON_TCL_TEX_INPUT_TEX_1 << RADEON_TCL_TEX_1_OUTPUT_SHIFT) |
497 (RADEON_TCL_TEX_INPUT_TEX_2 << RADEON_TCL_TEX_2_OUTPUT_SHIFT));
498
499
500 /* XXX */
501 rmesa->hw.tcl.cmd[TCL_MATRIX_SELECT_0] =
502 ((MODEL << RADEON_MODELVIEW_0_SHIFT) |
503 (MODEL_IT << RADEON_IT_MODELVIEW_0_SHIFT));
504
505 rmesa->hw.tcl.cmd[TCL_MATRIX_SELECT_1] =
506 ((MODEL_PROJ << RADEON_MODELPROJECT_0_SHIFT) |
507 (TEXMAT_0 << RADEON_TEXMAT_0_SHIFT) |
508 (TEXMAT_1 << RADEON_TEXMAT_1_SHIFT));
509
510 rmesa->hw.tcl.cmd[TCL_UCP_VERT_BLEND_CTL] =
511 (RADEON_UCP_IN_CLIP_SPACE |
512 RADEON_CULL_FRONT_IS_CCW);
513
514 rmesa->hw.tcl.cmd[TCL_TEXTURE_PROC_CTL] = 0;
515
516 rmesa->hw.tcl.cmd[TCL_LIGHT_MODEL_CTL] =
517 (RADEON_SPECULAR_LIGHTS |
518 RADEON_DIFFUSE_SPECULAR_COMBINE |
519 RADEON_LOCAL_LIGHT_VEC_GL |
520 (RADEON_LM_SOURCE_STATE_MULT << RADEON_EMISSIVE_SOURCE_SHIFT) |
521 (RADEON_LM_SOURCE_STATE_MULT << RADEON_AMBIENT_SOURCE_SHIFT) |
522 (RADEON_LM_SOURCE_STATE_MULT << RADEON_DIFFUSE_SOURCE_SHIFT) |
523 (RADEON_LM_SOURCE_STATE_MULT << RADEON_SPECULAR_SOURCE_SHIFT));
524
525 for (i = 0 ; i < 8; i++) {
526 struct gl_light *l = &ctx->Light.Light[i];
527 GLenum p = GL_LIGHT0 + i;
528 *(float *)&(rmesa->hw.lit[i].cmd[LIT_RANGE_CUTOFF]) = FLT_MAX;
529
530 ctx->Driver.Lightfv( ctx, p, GL_AMBIENT, l->Ambient );
531 ctx->Driver.Lightfv( ctx, p, GL_DIFFUSE, l->Diffuse );
532 ctx->Driver.Lightfv( ctx, p, GL_SPECULAR, l->Specular );
533 ctx->Driver.Lightfv( ctx, p, GL_POSITION, NULL );
534 ctx->Driver.Lightfv( ctx, p, GL_SPOT_DIRECTION, NULL );
535 ctx->Driver.Lightfv( ctx, p, GL_SPOT_EXPONENT, &l->SpotExponent );
536 ctx->Driver.Lightfv( ctx, p, GL_SPOT_CUTOFF, &l->SpotCutoff );
537 ctx->Driver.Lightfv( ctx, p, GL_CONSTANT_ATTENUATION,
538 &l->ConstantAttenuation );
539 ctx->Driver.Lightfv( ctx, p, GL_LINEAR_ATTENUATION,
540 &l->LinearAttenuation );
541 ctx->Driver.Lightfv( ctx, p, GL_QUADRATIC_ATTENUATION,
542 &l->QuadraticAttenuation );
543 *(float *)&(rmesa->hw.lit[i].cmd[LIT_ATTEN_XXX]) = 0.0;
544 }
545
546 ctx->Driver.LightModelfv( ctx, GL_LIGHT_MODEL_AMBIENT,
547 ctx->Light.Model.Ambient );
548
549 TNL_CONTEXT(ctx)->Driver.NotifyMaterialChange( ctx );
550
551 for (i = 0 ; i < 6; i++) {
552 ctx->Driver.ClipPlane( ctx, GL_CLIP_PLANE0 + i, NULL );
553 }
554
555 ctx->Driver.Fogfv( ctx, GL_FOG_MODE, NULL );
556 ctx->Driver.Fogfv( ctx, GL_FOG_DENSITY, &ctx->Fog.Density );
557 ctx->Driver.Fogfv( ctx, GL_FOG_START, &ctx->Fog.Start );
558 ctx->Driver.Fogfv( ctx, GL_FOG_END, &ctx->Fog.End );
559 ctx->Driver.Fogfv( ctx, GL_FOG_COLOR, ctx->Fog.Color );
560 ctx->Driver.Fogfv( ctx, GL_FOG_COORDINATE_SOURCE_EXT, NULL );
561
562 rmesa->hw.grd.cmd[GRD_VERT_GUARD_CLIP_ADJ] = IEEE_ONE;
563 rmesa->hw.grd.cmd[GRD_VERT_GUARD_DISCARD_ADJ] = IEEE_ONE;
564 rmesa->hw.grd.cmd[GRD_HORZ_GUARD_CLIP_ADJ] = IEEE_ONE;
565 rmesa->hw.grd.cmd[GRD_HORZ_GUARD_DISCARD_ADJ] = IEEE_ONE;
566
567 rmesa->hw.eye.cmd[EYE_X] = 0;
568 rmesa->hw.eye.cmd[EYE_Y] = 0;
569 rmesa->hw.eye.cmd[EYE_Z] = IEEE_ONE;
570 rmesa->hw.eye.cmd[EYE_RESCALE_FACTOR] = IEEE_ONE;
571
572 rmesa->hw.all_dirty = GL_TRUE;
573 }