0945fa803f384ffa4c972388d47f8dc08a2abcd8
[profile/ivi/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
152    switch ( rmesa->radeonScreen->cpp ) {
153    case 2:
154       color_fmt = RADEON_COLOR_FORMAT_RGB565;
155       break;
156    case 4:
157       color_fmt = RADEON_COLOR_FORMAT_ARGB8888;
158       break;
159    default:
160       fprintf( stderr, "Error: Unsupported pixel depth... exiting\n" );
161       exit( -1 );
162    }
163
164    rmesa->state.color.clear = 0x00000000;
165
166    switch ( ctx->Visual.depthBits ) {
167    case 16:
168       rmesa->state.depth.clear = 0x0000ffff;
169       rmesa->state.depth.scale = 1.0 / (GLfloat)0xffff;
170       depth_fmt = RADEON_DEPTH_FORMAT_16BIT_INT_Z;
171       rmesa->state.stencil.clear = 0x00000000;
172       break;
173    case 24:
174       rmesa->state.depth.clear = 0x00ffffff;
175       rmesa->state.depth.scale = 1.0 / (GLfloat)0xffffff;
176       depth_fmt = RADEON_DEPTH_FORMAT_24BIT_INT_Z;
177       rmesa->state.stencil.clear = 0xff000000;
178       break;
179    default:
180       fprintf( stderr, "Error: Unsupported depth %d... exiting\n",
181                ctx->Visual.depthBits );
182       exit( -1 );
183    }
184
185    /* Only have hw stencil when depth buffer is 24 bits deep */
186    rmesa->state.stencil.hwBuffer = ( ctx->Visual.stencilBits > 0 &&
187                                      ctx->Visual.depthBits == 24 );
188
189    rmesa->Fallback = 0;
190
191    if ( ctx->Visual.doubleBufferMode && rmesa->sarea->pfCurrentPage == 0 ) {
192       rmesa->state.color.drawOffset = rmesa->radeonScreen->backOffset;
193       rmesa->state.color.drawPitch  = rmesa->radeonScreen->backPitch;
194    } else {
195       rmesa->state.color.drawOffset = rmesa->radeonScreen->frontOffset;
196       rmesa->state.color.drawPitch  = rmesa->radeonScreen->frontPitch;
197    }
198    rmesa->state.pixel.readOffset = rmesa->state.color.drawOffset;
199    rmesa->state.pixel.readPitch  = rmesa->state.color.drawPitch;
200
201    rmesa->hw.max_state_size = 0;
202
203 #define ALLOC_STATE( ATOM, CHK, SZ, NM, FLAG )                          \
204    do {                                                         \
205       rmesa->hw.ATOM.cmd_size = SZ;                             \
206       rmesa->hw.ATOM.cmd = (int *)CALLOC(SZ * sizeof(int));     \
207       rmesa->hw.ATOM.lastcmd = (int *)CALLOC(SZ * sizeof(int)); \
208       rmesa->hw.ATOM.name = NM;                                 \
209       rmesa->hw.ATOM.is_tcl = FLAG;                                     \
210       rmesa->hw.ATOM.check = check_##CHK;                               \
211       rmesa->hw.ATOM.dirty = GL_TRUE;                           \
212       rmesa->hw.max_state_size += SZ * sizeof(int);             \
213    } while (0)
214       
215       
216    /* Allocate state buffers:
217     */
218    ALLOC_STATE( ctx, always, CTX_STATE_SIZE, "CTX/context", 0 );
219    ALLOC_STATE( lin, always, LIN_STATE_SIZE, "LIN/line", 0 );
220    ALLOC_STATE( msk, always, MSK_STATE_SIZE, "MSK/mask", 0 );
221    ALLOC_STATE( vpt, always, VPT_STATE_SIZE, "VPT/viewport", 0 );
222    ALLOC_STATE( set, always, SET_STATE_SIZE, "SET/setup", 0 );
223    ALLOC_STATE( msc, always, MSC_STATE_SIZE, "MSC/misc", 0 );
224    ALLOC_STATE( zbs, always, ZBS_STATE_SIZE, "ZBS/zbias", 0 );
225    ALLOC_STATE( tcl, always, TCL_STATE_SIZE, "TCL/tcl", 1 );
226    ALLOC_STATE( mtl, tcl_lighting, MTL_STATE_SIZE, "MTL/material", 1 );
227    ALLOC_STATE( grd, always, GRD_STATE_SIZE, "GRD/guard-band", 1 );
228    ALLOC_STATE( fog, fog, FOG_STATE_SIZE, "FOG/fog", 1 );
229    ALLOC_STATE( glt, tcl_lighting, GLT_STATE_SIZE, "GLT/light-global", 1 );
230    ALLOC_STATE( eye, tcl_lighting, EYE_STATE_SIZE, "EYE/eye-vector", 1 );
231    ALLOC_STATE( tex[0], tex0, TEX_STATE_SIZE, "TEX/tex-0", 0 );
232    ALLOC_STATE( tex[1], tex1, TEX_STATE_SIZE, "TEX/tex-1", 0 );
233    ALLOC_STATE( mat[0], tcl, MAT_STATE_SIZE, "MAT/modelproject", 1 );
234    ALLOC_STATE( mat[1], tcl_eyespace_or_fog, MAT_STATE_SIZE, "MAT/modelview", 1 );
235    ALLOC_STATE( mat[2], tcl_eyespace_or_lighting, MAT_STATE_SIZE, "MAT/it-modelview", 1 );
236    ALLOC_STATE( mat[3], tcl_tex0, MAT_STATE_SIZE, "MAT/texmat0", 1 );
237    ALLOC_STATE( mat[4], tcl_tex1, MAT_STATE_SIZE, "MAT/texmat1", 1 );
238    ALLOC_STATE( ucp[0], tcl_ucp0, UCP_STATE_SIZE, "UCP/userclip-0", 1 );
239    ALLOC_STATE( ucp[1], tcl_ucp1, UCP_STATE_SIZE, "UCP/userclip-1", 1 );
240    ALLOC_STATE( ucp[2], tcl_ucp2, UCP_STATE_SIZE, "UCP/userclip-2", 1 );
241    ALLOC_STATE( ucp[3], tcl_ucp3, UCP_STATE_SIZE, "UCP/userclip-3", 1 );
242    ALLOC_STATE( ucp[4], tcl_ucp4, UCP_STATE_SIZE, "UCP/userclip-4", 1 );
243    ALLOC_STATE( ucp[5], tcl_ucp5, UCP_STATE_SIZE, "UCP/userclip-5", 1 );
244    ALLOC_STATE( lit[0], tcl_lit0, LIT_STATE_SIZE, "LIT/light-0", 1 );
245    ALLOC_STATE( lit[1], tcl_lit1, LIT_STATE_SIZE, "LIT/light-1", 1 );
246    ALLOC_STATE( lit[2], tcl_lit2, LIT_STATE_SIZE, "LIT/light-2", 1 );
247    ALLOC_STATE( lit[3], tcl_lit3, LIT_STATE_SIZE, "LIT/light-3", 1 );
248    ALLOC_STATE( lit[4], tcl_lit4, LIT_STATE_SIZE, "LIT/light-4", 1 );
249    ALLOC_STATE( lit[5], tcl_lit5, LIT_STATE_SIZE, "LIT/light-5", 1 );
250    ALLOC_STATE( lit[6], tcl_lit6, LIT_STATE_SIZE, "LIT/light-6", 1 );
251    ALLOC_STATE( lit[7], tcl_lit7, LIT_STATE_SIZE, "LIT/light-7", 1 );
252    ALLOC_STATE( txr[0], txr0, TXR_STATE_SIZE, "TXR/txr-0", 0 );
253    ALLOC_STATE( txr[1], txr1, TXR_STATE_SIZE, "TXR/txr-1", 0 );
254
255    radeonSetUpAtomList( rmesa );
256
257    /* Fill in the packet headers:
258     */
259    rmesa->hw.ctx.cmd[CTX_CMD_0] = cmdpkt(RADEON_EMIT_PP_MISC);
260    rmesa->hw.ctx.cmd[CTX_CMD_1] = cmdpkt(RADEON_EMIT_PP_CNTL);
261    rmesa->hw.ctx.cmd[CTX_CMD_2] = cmdpkt(RADEON_EMIT_RB3D_COLORPITCH);
262    rmesa->hw.lin.cmd[LIN_CMD_0] = cmdpkt(RADEON_EMIT_RE_LINE_PATTERN);
263    rmesa->hw.lin.cmd[LIN_CMD_1] = cmdpkt(RADEON_EMIT_SE_LINE_WIDTH);
264    rmesa->hw.msk.cmd[MSK_CMD_0] = cmdpkt(RADEON_EMIT_RB3D_STENCILREFMASK);
265    rmesa->hw.vpt.cmd[VPT_CMD_0] = cmdpkt(RADEON_EMIT_SE_VPORT_XSCALE);
266    rmesa->hw.set.cmd[SET_CMD_0] = cmdpkt(RADEON_EMIT_SE_CNTL);
267    rmesa->hw.set.cmd[SET_CMD_1] = cmdpkt(RADEON_EMIT_SE_CNTL_STATUS);
268    rmesa->hw.msc.cmd[MSC_CMD_0] = cmdpkt(RADEON_EMIT_RE_MISC);
269    rmesa->hw.tex[0].cmd[TEX_CMD_0] = cmdpkt(RADEON_EMIT_PP_TXFILTER_0);
270    rmesa->hw.tex[0].cmd[TEX_CMD_1] = cmdpkt(RADEON_EMIT_PP_BORDER_COLOR_0);
271    rmesa->hw.tex[1].cmd[TEX_CMD_0] = cmdpkt(RADEON_EMIT_PP_TXFILTER_1);
272    rmesa->hw.tex[1].cmd[TEX_CMD_1] = cmdpkt(RADEON_EMIT_PP_BORDER_COLOR_1);
273    rmesa->hw.zbs.cmd[ZBS_CMD_0] = cmdpkt(RADEON_EMIT_SE_ZBIAS_FACTOR);
274    rmesa->hw.tcl.cmd[TCL_CMD_0] = cmdpkt(RADEON_EMIT_SE_TCL_OUTPUT_VTX_FMT);
275    rmesa->hw.mtl.cmd[MTL_CMD_0] = 
276       cmdpkt(RADEON_EMIT_SE_TCL_MATERIAL_EMMISSIVE_RED);
277    rmesa->hw.txr[0].cmd[TXR_CMD_0] = cmdpkt(RADEON_EMIT_PP_TEX_SIZE_0);
278    rmesa->hw.txr[1].cmd[TXR_CMD_0] = cmdpkt(RADEON_EMIT_PP_TEX_SIZE_1);
279    rmesa->hw.grd.cmd[GRD_CMD_0] = 
280       cmdscl( RADEON_SS_VERT_GUARD_CLIP_ADJ_ADDR, 1, 4 );
281    rmesa->hw.fog.cmd[FOG_CMD_0] = 
282       cmdvec( RADEON_VS_FOG_PARAM_ADDR, 1, 4 );
283    rmesa->hw.glt.cmd[GLT_CMD_0] = 
284       cmdvec( RADEON_VS_GLOBAL_AMBIENT_ADDR, 1, 4 );
285    rmesa->hw.eye.cmd[EYE_CMD_0] = 
286       cmdvec( RADEON_VS_EYE_VECTOR_ADDR, 1, 4 );
287
288    for (i = 0 ; i < 5; i++) {
289       rmesa->hw.mat[i].cmd[MAT_CMD_0] = 
290          cmdvec( RADEON_VS_MATRIX_0_ADDR + i*4, 1, 16);
291    }
292
293    for (i = 0 ; i < 8; i++) {
294       rmesa->hw.lit[i].cmd[LIT_CMD_0] = 
295          cmdvec( RADEON_VS_LIGHT_AMBIENT_ADDR + i, 8, 24 );
296       rmesa->hw.lit[i].cmd[LIT_CMD_1] = 
297          cmdscl( RADEON_SS_LIGHT_DCD_ADDR + i, 8, 6 );
298    }
299
300    for (i = 0 ; i < 6; i++) {
301       rmesa->hw.ucp[i].cmd[UCP_CMD_0] = 
302          cmdvec( RADEON_VS_UCP_ADDR + i, 1, 4 );
303    }
304
305    rmesa->last_ReallyEnabled = -1;
306
307    /* Initial Harware state:
308     */
309    rmesa->hw.ctx.cmd[CTX_PP_MISC] = (RADEON_ALPHA_TEST_PASS |
310                                      RADEON_CHROMA_FUNC_FAIL |
311                                      RADEON_CHROMA_KEY_NEAREST |
312                                      RADEON_SHADOW_FUNC_EQUAL |
313                                      RADEON_SHADOW_PASS_1 |
314                                      RADEON_RIGHT_HAND_CUBE_OGL);
315
316    rmesa->hw.ctx.cmd[CTX_PP_FOG_COLOR] = (RADEON_FOG_VERTEX |
317                                           RADEON_FOG_USE_DEPTH);
318
319    rmesa->hw.ctx.cmd[CTX_RE_SOLID_COLOR] = 0x00000000;
320
321    rmesa->hw.ctx.cmd[CTX_RB3D_BLENDCNTL] = (RADEON_COMB_FCN_ADD_CLAMP |
322                                             RADEON_SRC_BLEND_GL_ONE |
323                                             RADEON_DST_BLEND_GL_ZERO );
324
325    rmesa->hw.ctx.cmd[CTX_RB3D_DEPTHOFFSET] =
326       rmesa->radeonScreen->depthOffset + rmesa->radeonScreen->fbLocation;
327
328    rmesa->hw.ctx.cmd[CTX_RB3D_DEPTHPITCH] = 
329       ((rmesa->radeonScreen->depthPitch &
330         RADEON_DEPTHPITCH_MASK) |
331        RADEON_DEPTH_ENDIAN_NO_SWAP);
332
333    rmesa->hw.ctx.cmd[CTX_RB3D_ZSTENCILCNTL] = (depth_fmt |
334                                                RADEON_Z_TEST_LESS |
335                                                RADEON_STENCIL_TEST_ALWAYS |
336                                                RADEON_STENCIL_FAIL_KEEP |
337                                                RADEON_STENCIL_ZPASS_KEEP |
338                                                RADEON_STENCIL_ZFAIL_KEEP |
339                                                RADEON_Z_WRITE_ENABLE);
340
341    rmesa->hw.ctx.cmd[CTX_PP_CNTL] = (RADEON_SCISSOR_ENABLE |
342                                      RADEON_ANTI_ALIAS_NONE);
343
344    rmesa->hw.ctx.cmd[CTX_RB3D_CNTL] = (RADEON_PLANE_MASK_ENABLE |
345                                        color_fmt |
346                                        (1<<15));
347
348    switch ( driQueryOptioni( &rmesa->optionCache, "dither_mode" ) ) {
349    case DRI_CONF_DITHER_XERRORDIFFRESET:
350       rmesa->hw.ctx.cmd[CTX_RB3D_CNTL] |= RADEON_DITHER_INIT;
351       break;
352    case DRI_CONF_DITHER_ORDERED:
353       rmesa->hw.ctx.cmd[CTX_RB3D_CNTL] |= RADEON_SCALE_DITHER_ENABLE;
354       break;
355    }
356    if ( driQueryOptioni( &rmesa->optionCache, "round_mode" ) ==
357         DRI_CONF_ROUND_ROUND )
358       rmesa->state.color.roundEnable = RADEON_ROUND_ENABLE;
359    else
360       rmesa->state.color.roundEnable = 0;
361    if ( driQueryOptioni (&rmesa->optionCache, "color_reduction" ) ==
362         DRI_CONF_COLOR_REDUCTION_DITHER )
363       rmesa->hw.ctx.cmd[CTX_RB3D_CNTL] |= RADEON_DITHER_ENABLE;
364    else
365       rmesa->hw.ctx.cmd[CTX_RB3D_CNTL] |= rmesa->state.color.roundEnable;
366
367    rmesa->hw.ctx.cmd[CTX_RB3D_COLOROFFSET] = ((rmesa->state.color.drawOffset +
368                                                rmesa->radeonScreen->fbLocation)
369                                               & RADEON_COLOROFFSET_MASK);
370
371    rmesa->hw.ctx.cmd[CTX_RB3D_COLORPITCH] = ((rmesa->state.color.drawPitch &
372                                               RADEON_COLORPITCH_MASK) |
373                                              RADEON_COLOR_ENDIAN_NO_SWAP);
374
375    rmesa->hw.set.cmd[SET_SE_CNTL] = (RADEON_FFACE_CULL_CCW |
376                                      RADEON_BFACE_SOLID |
377                                      RADEON_FFACE_SOLID |
378 /*                           RADEON_BADVTX_CULL_DISABLE | */
379                                      RADEON_FLAT_SHADE_VTX_LAST |
380                                      RADEON_DIFFUSE_SHADE_GOURAUD |
381                                      RADEON_ALPHA_SHADE_GOURAUD |
382                                      RADEON_SPECULAR_SHADE_GOURAUD |
383                                      RADEON_FOG_SHADE_GOURAUD |
384                                      RADEON_VPORT_XY_XFORM_ENABLE |
385                                      RADEON_VPORT_Z_XFORM_ENABLE |
386                                      RADEON_VTX_PIX_CENTER_OGL |
387                                      RADEON_ROUND_MODE_TRUNC |
388                                      RADEON_ROUND_PREC_8TH_PIX);
389
390    rmesa->hw.set.cmd[SET_SE_CNTL_STATUS] =
391 #ifdef MESA_BIG_ENDIAN
392                                             RADEON_VC_32BIT_SWAP;
393 #else
394                                             RADEON_VC_NO_SWAP;
395 #endif
396
397    if (!(rmesa->radeonScreen->chipset & RADEON_CHIPSET_TCL)) {
398      rmesa->hw.set.cmd[SET_SE_CNTL_STATUS] |= RADEON_TCL_BYPASS;
399    }
400
401    rmesa->hw.set.cmd[SET_SE_COORDFMT] = (
402       RADEON_VTX_W0_IS_NOT_1_OVER_W0 |
403       RADEON_TEX1_W_ROUTING_USE_Q1);
404
405
406    rmesa->hw.lin.cmd[LIN_RE_LINE_PATTERN] = ((1 << 16) | 0xffff);
407
408    rmesa->hw.lin.cmd[LIN_RE_LINE_STATE] = 
409       ((0 << RADEON_LINE_CURRENT_PTR_SHIFT) |
410        (1 << RADEON_LINE_CURRENT_COUNT_SHIFT));
411
412    rmesa->hw.lin.cmd[LIN_SE_LINE_WIDTH] = (1 << 4);
413
414    rmesa->hw.msk.cmd[MSK_RB3D_STENCILREFMASK] = 
415       ((0x00 << RADEON_STENCIL_REF_SHIFT) |
416        (0xff << RADEON_STENCIL_MASK_SHIFT) |
417        (0xff << RADEON_STENCIL_WRITEMASK_SHIFT));
418
419    rmesa->hw.msk.cmd[MSK_RB3D_ROPCNTL] = RADEON_ROP_COPY;
420    rmesa->hw.msk.cmd[MSK_RB3D_PLANEMASK] = 0xffffffff;
421
422    rmesa->hw.msc.cmd[MSC_RE_MISC] = 
423       ((0 << RADEON_STIPPLE_X_OFFSET_SHIFT) |
424        (0 << RADEON_STIPPLE_Y_OFFSET_SHIFT) |
425        RADEON_STIPPLE_BIG_BIT_ORDER);
426
427    rmesa->hw.vpt.cmd[VPT_SE_VPORT_XSCALE]  = 0x00000000;
428    rmesa->hw.vpt.cmd[VPT_SE_VPORT_XOFFSET] = 0x00000000;
429    rmesa->hw.vpt.cmd[VPT_SE_VPORT_YSCALE]  = 0x00000000;
430    rmesa->hw.vpt.cmd[VPT_SE_VPORT_YOFFSET] = 0x00000000;
431    rmesa->hw.vpt.cmd[VPT_SE_VPORT_ZSCALE]  = 0x00000000;
432    rmesa->hw.vpt.cmd[VPT_SE_VPORT_ZOFFSET] = 0x00000000;
433
434    for ( i = 0 ; i < ctx->Const.MaxTextureUnits ; i++ ) {
435       rmesa->hw.tex[i].cmd[TEX_PP_TXFILTER] = RADEON_BORDER_MODE_OGL;
436       rmesa->hw.tex[i].cmd[TEX_PP_TXFORMAT] = 
437           (RADEON_TXFORMAT_ENDIAN_NO_SWAP |
438            RADEON_TXFORMAT_PERSPECTIVE_ENABLE |
439            (i << 24) | /* This is one of RADEON_TXFORMAT_ST_ROUTE_STQ[012] */
440            (2 << RADEON_TXFORMAT_WIDTH_SHIFT) |
441            (2 << RADEON_TXFORMAT_HEIGHT_SHIFT));
442
443       /* Initialize the texture offset to the start of the card texture heap */
444       rmesa->hw.tex[i].cmd[TEX_PP_TXOFFSET] =
445           rmesa->radeonScreen->texOffset[RADEON_LOCAL_TEX_HEAP];
446
447       rmesa->hw.tex[i].cmd[TEX_PP_BORDER_COLOR] = 0;
448       rmesa->hw.tex[i].cmd[TEX_PP_TXCBLEND] =  
449           (RADEON_COLOR_ARG_A_ZERO |
450            RADEON_COLOR_ARG_B_ZERO |
451            RADEON_COLOR_ARG_C_CURRENT_COLOR |
452            RADEON_BLEND_CTL_ADD |
453            RADEON_SCALE_1X |
454            RADEON_CLAMP_TX);
455       rmesa->hw.tex[i].cmd[TEX_PP_TXABLEND] = 
456           (RADEON_ALPHA_ARG_A_ZERO |
457            RADEON_ALPHA_ARG_B_ZERO |
458            RADEON_ALPHA_ARG_C_CURRENT_ALPHA |
459            RADEON_BLEND_CTL_ADD |
460            RADEON_SCALE_1X |
461            RADEON_CLAMP_TX);
462       rmesa->hw.tex[i].cmd[TEX_PP_TFACTOR] = 0;
463    }
464
465    /* Can only add ST1 at the time of doing some multitex but can keep
466     * it after that.  Errors if DIFFUSE is missing.
467     */
468    rmesa->hw.tcl.cmd[TCL_OUTPUT_VTXFMT] = 
469       (RADEON_TCL_VTX_Z0 |
470        RADEON_TCL_VTX_W0 |
471        RADEON_TCL_VTX_PK_DIFFUSE
472          );     /* need to keep this uptodate */
473                                                    
474    rmesa->hw.tcl.cmd[TCL_OUTPUT_VTXSEL] =
475       ( RADEON_TCL_COMPUTE_XYZW         |
476         (RADEON_TCL_TEX_INPUT_TEX_0 << RADEON_TCL_TEX_0_OUTPUT_SHIFT) |
477         (RADEON_TCL_TEX_INPUT_TEX_1 << RADEON_TCL_TEX_1_OUTPUT_SHIFT) |
478         (RADEON_TCL_TEX_INPUT_TEX_2 << RADEON_TCL_TEX_2_OUTPUT_SHIFT));
479
480
481    /* XXX */
482    rmesa->hw.tcl.cmd[TCL_MATRIX_SELECT_0] = 
483       ((MODEL << RADEON_MODELVIEW_0_SHIFT) |
484        (MODEL_IT << RADEON_IT_MODELVIEW_0_SHIFT));
485
486    rmesa->hw.tcl.cmd[TCL_MATRIX_SELECT_1] = 
487       ((MODEL_PROJ << RADEON_MODELPROJECT_0_SHIFT) |
488        (TEXMAT_0 << RADEON_TEXMAT_0_SHIFT) |
489        (TEXMAT_1 << RADEON_TEXMAT_1_SHIFT));
490
491    rmesa->hw.tcl.cmd[TCL_UCP_VERT_BLEND_CTL] = 
492       (RADEON_UCP_IN_CLIP_SPACE |
493        RADEON_CULL_FRONT_IS_CCW);
494
495    rmesa->hw.tcl.cmd[TCL_TEXTURE_PROC_CTL] = 0; 
496
497    rmesa->hw.tcl.cmd[TCL_LIGHT_MODEL_CTL] = 
498       (RADEON_SPECULAR_LIGHTS |
499        RADEON_DIFFUSE_SPECULAR_COMBINE |
500        RADEON_LOCAL_LIGHT_VEC_GL |
501        (RADEON_LM_SOURCE_STATE_MULT << RADEON_EMISSIVE_SOURCE_SHIFT) |
502        (RADEON_LM_SOURCE_STATE_MULT << RADEON_AMBIENT_SOURCE_SHIFT) |
503        (RADEON_LM_SOURCE_STATE_MULT << RADEON_DIFFUSE_SOURCE_SHIFT) |
504        (RADEON_LM_SOURCE_STATE_MULT << RADEON_SPECULAR_SOURCE_SHIFT));
505
506    for (i = 0 ; i < 8; i++) {
507       struct gl_light *l = &ctx->Light.Light[i];
508       GLenum p = GL_LIGHT0 + i;
509       *(float *)&(rmesa->hw.lit[i].cmd[LIT_RANGE_CUTOFF]) = FLT_MAX;
510
511       ctx->Driver.Lightfv( ctx, p, GL_AMBIENT, l->Ambient );
512       ctx->Driver.Lightfv( ctx, p, GL_DIFFUSE, l->Diffuse );
513       ctx->Driver.Lightfv( ctx, p, GL_SPECULAR, l->Specular );
514       ctx->Driver.Lightfv( ctx, p, GL_POSITION, 0 );
515       ctx->Driver.Lightfv( ctx, p, GL_SPOT_DIRECTION, 0 );
516       ctx->Driver.Lightfv( ctx, p, GL_SPOT_EXPONENT, &l->SpotExponent );
517       ctx->Driver.Lightfv( ctx, p, GL_SPOT_CUTOFF, &l->SpotCutoff );
518       ctx->Driver.Lightfv( ctx, p, GL_CONSTANT_ATTENUATION,
519                            &l->ConstantAttenuation );
520       ctx->Driver.Lightfv( ctx, p, GL_LINEAR_ATTENUATION, 
521                            &l->LinearAttenuation );
522       ctx->Driver.Lightfv( ctx, p, GL_QUADRATIC_ATTENUATION, 
523                      &l->QuadraticAttenuation );
524       *(float *)&(rmesa->hw.lit[i].cmd[LIT_ATTEN_XXX]) = 0.0;
525    }
526
527    ctx->Driver.LightModelfv( ctx, GL_LIGHT_MODEL_AMBIENT, 
528                              ctx->Light.Model.Ambient );
529
530    TNL_CONTEXT(ctx)->Driver.NotifyMaterialChange( ctx );
531
532    for (i = 0 ; i < 6; i++) {
533       ctx->Driver.ClipPlane( ctx, GL_CLIP_PLANE0 + i, NULL );
534    }
535
536    ctx->Driver.Fogfv( ctx, GL_FOG_MODE, 0 );
537    ctx->Driver.Fogfv( ctx, GL_FOG_DENSITY, &ctx->Fog.Density );
538    ctx->Driver.Fogfv( ctx, GL_FOG_START, &ctx->Fog.Start );
539    ctx->Driver.Fogfv( ctx, GL_FOG_END, &ctx->Fog.End );
540    ctx->Driver.Fogfv( ctx, GL_FOG_COLOR, ctx->Fog.Color );
541    ctx->Driver.Fogfv( ctx, GL_FOG_COORDINATE_SOURCE_EXT, 0 );
542    
543    rmesa->hw.grd.cmd[GRD_VERT_GUARD_CLIP_ADJ] = IEEE_ONE;
544    rmesa->hw.grd.cmd[GRD_VERT_GUARD_DISCARD_ADJ] = IEEE_ONE;
545    rmesa->hw.grd.cmd[GRD_HORZ_GUARD_CLIP_ADJ] = IEEE_ONE;
546    rmesa->hw.grd.cmd[GRD_HORZ_GUARD_DISCARD_ADJ] = IEEE_ONE;
547
548    rmesa->hw.eye.cmd[EYE_X] = 0;
549    rmesa->hw.eye.cmd[EYE_Y] = 0;
550    rmesa->hw.eye.cmd[EYE_Z] = IEEE_ONE;
551    rmesa->hw.eye.cmd[EYE_RESCALE_FACTOR] = IEEE_ONE;
552    
553    rmesa->hw.all_dirty = GL_TRUE;
554 }