Add structs describing vertex and pixel shader state to r300_state.
[profile/ivi/mesa.git] / src / mesa / drivers / dri / r300 / r300_state.c
1 /*
2 Copyright (C) The Weather Channel, Inc.  2002.
3 Copyright (C) 2004 Nicolai Haehnle.
4 All Rights Reserved.
5
6 The Weather Channel (TM) funded Tungsten Graphics to develop the
7 initial release of the Radeon 8500 driver under the XFree86 license.
8 This notice must be preserved.
9
10 Permission is hereby granted, free of charge, to any person obtaining
11 a copy of this software and associated documentation files (the
12 "Software"), to deal in the Software without restriction, including
13 without limitation the rights to use, copy, modify, merge, publish,
14 distribute, sublicense, and/or sell copies of the Software, and to
15 permit persons to whom the Software is furnished to do so, subject to
16 the following conditions:
17
18 The above copyright notice and this permission notice (including the
19 next paragraph) shall be included in all copies or substantial
20 portions of the Software.
21
22 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
25 IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
26 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29
30 **************************************************************************/
31
32 /*
33  * Authors:
34  *   Nicolai Haehnle <prefect_@gmx.net>
35  */
36
37 #include "glheader.h"
38 #include "state.h"
39 #include "imports.h"
40 #include "enums.h"
41 #include "macros.h"
42 #include "context.h"
43 #include "dd.h"
44 #include "simple_list.h"
45
46 #include "api_arrayelt.h"
47 #include "swrast/swrast.h"
48 #include "swrast_setup/swrast_setup.h"
49 #include "array_cache/acache.h"
50 #include "tnl/tnl.h"
51
52 #include "radeon_ioctl.h"
53 #include "radeon_state.h"
54 #include "r300_context.h"
55 #include "r300_ioctl.h"
56 #include "r300_state.h"
57 #include "r300_reg.h"
58 #include "r300_program.h"
59
60 static void r300AlphaFunc(GLcontext * ctx, GLenum func, GLfloat ref)
61 {
62         r300ContextPtr rmesa = R300_CONTEXT(ctx);
63         int pp_misc = rmesa->hw.at.cmd[R300_AT_ALPHA_TEST];
64         GLubyte refByte;
65
66         CLAMPED_FLOAT_TO_UBYTE(refByte, ref);
67
68         R300_STATECHANGE(rmesa, at);
69
70         pp_misc &= ~(R300_ALPHA_TEST_OP_MASK | R300_REF_ALPHA_MASK);
71         pp_misc |= (refByte & R300_REF_ALPHA_MASK);
72
73         switch (func) {
74         case GL_NEVER:
75                 pp_misc |= R300_ALPHA_TEST_FAIL;
76                 break;
77         case GL_LESS:
78                 pp_misc |= R300_ALPHA_TEST_LESS;
79                 break;
80         case GL_EQUAL:
81                 pp_misc |= R300_ALPHA_TEST_EQUAL;
82                 break;
83         case GL_LEQUAL:
84                 pp_misc |= R300_ALPHA_TEST_LEQUAL;
85                 break;
86         case GL_GREATER:
87                 pp_misc |= R300_ALPHA_TEST_GREATER;
88                 break;
89         case GL_NOTEQUAL:
90                 pp_misc |= R300_ALPHA_TEST_NEQUAL;
91                 break;
92         case GL_GEQUAL:
93                 pp_misc |= R300_ALPHA_TEST_GEQUAL;
94                 break;
95         case GL_ALWAYS:
96                 pp_misc |= R300_ALPHA_TEST_PASS;
97                 break;
98         }
99
100         rmesa->hw.at.cmd[R300_AT_ALPHA_TEST] = pp_misc;
101 }
102
103 /**
104  * Update our tracked culling state based on Mesa's state.
105  */
106 static void r300UpdateCulling(GLcontext* ctx)
107 {
108         r300ContextPtr r300 = R300_CONTEXT(ctx);
109         uint32_t val = 0;
110
111         R300_STATECHANGE(r300, cul);
112         if (ctx->Polygon.CullFlag) {
113                 if (ctx->Polygon.CullFaceMode == GL_FRONT_AND_BACK)
114                         val = R300_CULL_FRONT|R300_CULL_BACK;
115                 else if (ctx->Polygon.CullFaceMode == GL_FRONT)
116                         val = R300_CULL_FRONT;
117                 else
118                         val = R300_CULL_BACK;
119
120                 if (ctx->Polygon.FrontFace == GL_CW)
121                         val |= R300_FRONT_FACE_CW;
122                 else
123                         val |= R300_FRONT_FACE_CCW;
124         }
125
126         r300->hw.cul.cmd[R300_CUL_CULL] = val;
127 }
128
129
130 /**
131  * Handle glEnable()/glDisable().
132  *
133  * \note Mesa already filters redundant calls to glEnable/glDisable.
134  */
135 static void r300Enable(GLcontext* ctx, GLenum cap, GLboolean state)
136 {
137         r300ContextPtr r300 = R300_CONTEXT(ctx);
138         uint32_t newval;
139
140         if (RADEON_DEBUG & DEBUG_STATE)
141                 fprintf(stderr, "%s( %s = %s )\n", __FUNCTION__,
142                         _mesa_lookup_enum_by_nr(cap),
143                         state ? "GL_TRUE" : "GL_FALSE");
144
145         switch (cap) {
146         case GL_DEPTH_TEST:
147                 R300_STATECHANGE(r300, zc);
148
149                 if (state) {
150                         if (ctx->Depth.Mask)
151                                 newval = R300_RB3D_Z_TEST_AND_WRITE;
152                         else
153                                 newval = R300_RB3D_Z_TEST;
154                 } else
155                         newval = 0;
156
157                 r300->hw.zc.cmd[R300_ZC_CNTL_0] = newval;
158                 break;
159
160         case GL_CULL_FACE:
161                 r300UpdateCulling(ctx);
162                 break;
163
164         default:
165                 radeonEnable(ctx, cap, state);
166                 return;
167         }
168 }
169
170
171 /**
172  * Change the culling mode.
173  *
174  * \note Mesa already filters redundant calls to this function.
175  */
176 static void r300CullFace(GLcontext* ctx, GLenum mode)
177 {
178         (void)mode;
179
180         r300UpdateCulling(ctx);
181 }
182
183
184 /**
185  * Change the polygon orientation.
186  *
187  * \note Mesa already filters redundant calls to this function.
188  */
189 static void r300FrontFace(GLcontext* ctx, GLenum mode)
190 {
191         (void)mode;
192
193         r300UpdateCulling(ctx);
194 }
195
196
197 /**
198  * Change the depth testing function.
199  *
200  * \note Mesa already filters redundant calls to this function.
201  */
202 static void r300DepthFunc(GLcontext* ctx, GLenum func)
203 {
204         r300ContextPtr r300 = R300_CONTEXT(ctx);
205
206         R300_STATECHANGE(r300, zc);
207
208         switch(func) {
209         case GL_NEVER:
210                 r300->hw.zc.cmd[R300_ZC_CNTL_1] = R300_Z_TEST_NEVER;
211                 break;
212         case GL_LESS:
213                 r300->hw.zc.cmd[R300_ZC_CNTL_1] = R300_Z_TEST_LESS;
214                 break;
215         case GL_EQUAL:
216                 r300->hw.zc.cmd[R300_ZC_CNTL_1] = R300_Z_TEST_EQUAL;
217                 break;
218         case GL_LEQUAL:
219                 r300->hw.zc.cmd[R300_ZC_CNTL_1] = R300_Z_TEST_LEQUAL;
220                 break;
221         case GL_GREATER:
222                 r300->hw.zc.cmd[R300_ZC_CNTL_1] = R300_Z_TEST_GREATER;
223                 break;
224         case GL_NOTEQUAL:
225                 r300->hw.zc.cmd[R300_ZC_CNTL_1] = R300_Z_TEST_NEQUAL;
226                 break;
227         case GL_GEQUAL:
228                 r300->hw.zc.cmd[R300_ZC_CNTL_1] = R300_Z_TEST_GEQUAL;
229                 break;
230         case GL_ALWAYS:
231                 r300->hw.zc.cmd[R300_ZC_CNTL_1] = R300_Z_TEST_ALWAYS;
232                 break;
233         }
234 }
235
236
237 /**
238  * Enable/Disable depth writing.
239  *
240  * \note Mesa already filters redundant calls to this function.
241  */
242 static void r300DepthMask(GLcontext* ctx, GLboolean mask)
243 {
244         r300ContextPtr r300 = R300_CONTEXT(ctx);
245
246         if (!ctx->Depth.Test)
247                 return;
248
249         R300_STATECHANGE(r300, zc);
250         r300->hw.zc.cmd[R300_ZC_CNTL_0] = mask
251                 ? R300_RB3D_Z_TEST_AND_WRITE : R300_RB3D_Z_TEST;
252 }
253
254
255 /**
256  * Handle glColorMask()
257  */
258 static void r300ColorMask(GLcontext* ctx,
259                           GLboolean r, GLboolean g, GLboolean b, GLboolean a)
260 {
261         r300ContextPtr r300 = R300_CONTEXT(ctx);
262         int mask = (b << 0) | (g << 1) | (r << 2) | (a << 3);
263
264         if (mask != r300->hw.cmk.cmd[R300_CMK_COLORMASK]) {
265                 R300_STATECHANGE(r300, cmk);
266                 r300->hw.cmk.cmd[R300_CMK_COLORMASK] = mask;
267         }
268 }
269
270 /* =============================================================
271  * Point state
272  */
273 static void r300PointSize(GLcontext * ctx, GLfloat size)
274 {
275         r300ContextPtr r300 = R300_CONTEXT(ctx);
276         
277         /* This might need fixing later */
278         R300_STATECHANGE(r300, vps);
279         r300->hw.vps.cmd[R300_VPS_POINTSIZE] = r300PackFloat32(1.0);
280 }
281
282 /* =============================================================
283  * Window position and viewport transformation
284  */
285
286 /*
287  * To correctly position primitives:
288  */
289 #define SUBPIXEL_X 0.125
290 #define SUBPIXEL_Y 0.125
291
292 void r300UpdateWindow(GLcontext * ctx)
293 {
294         r300ContextPtr rmesa = R300_CONTEXT(ctx);
295         __DRIdrawablePrivate *dPriv = rmesa->radeon.dri.drawable;
296         GLfloat xoffset = dPriv ? (GLfloat) dPriv->x : 0;
297         GLfloat yoffset = dPriv ? (GLfloat) dPriv->y + dPriv->h : 0;
298         const GLfloat *v = ctx->Viewport._WindowMap.m;
299
300         GLfloat sx = v[MAT_SX];
301         GLfloat tx = v[MAT_TX] + xoffset + SUBPIXEL_X;
302         GLfloat sy = -v[MAT_SY];
303         GLfloat ty = (-v[MAT_TY]) + yoffset + SUBPIXEL_Y;
304         GLfloat sz = v[MAT_SZ] * rmesa->state.depth.scale;
305         GLfloat tz = v[MAT_TZ] * rmesa->state.depth.scale;
306
307         R300_FIREVERTICES(rmesa);
308         R300_STATECHANGE(rmesa, vpt);
309
310         rmesa->hw.vpt.cmd[R300_VPT_XSCALE]  = r300PackFloat32(sx);
311         rmesa->hw.vpt.cmd[R300_VPT_XOFFSET] = r300PackFloat32(tx);
312         rmesa->hw.vpt.cmd[R300_VPT_YSCALE]  = r300PackFloat32(sy);
313         rmesa->hw.vpt.cmd[R300_VPT_YOFFSET] = r300PackFloat32(ty);
314         rmesa->hw.vpt.cmd[R300_VPT_ZSCALE]  = r300PackFloat32(sz);
315         rmesa->hw.vpt.cmd[R300_VPT_ZOFFSET] = r300PackFloat32(tz);
316 }
317
318 static void r300Viewport(GLcontext * ctx, GLint x, GLint y,
319                          GLsizei width, GLsizei height)
320 {
321         /* Don't pipeline viewport changes, conflict with window offset
322          * setting below.  Could apply deltas to rescue pipelined viewport
323          * values, or keep the originals hanging around.
324          */
325         R200_FIREVERTICES(R200_CONTEXT(ctx));
326         r300UpdateWindow(ctx);
327 }
328
329 static void r300DepthRange(GLcontext * ctx, GLclampd nearval, GLclampd farval)
330 {
331         r300UpdateWindow(ctx);
332 }
333
334
335 /**
336  * Called by Mesa after an internal state update.
337  */
338 static void r300InvalidateState(GLcontext * ctx, GLuint new_state)
339 {
340         r300ContextPtr r300 = R300_CONTEXT(ctx);
341
342         _swrast_InvalidateState(ctx, new_state);
343         _swsetup_InvalidateState(ctx, new_state);
344         _ac_InvalidateState(ctx, new_state);
345         _tnl_InvalidateState(ctx, new_state);
346         _ae_invalidate_state(ctx, new_state);
347
348         /* Go inefficiency! */
349         r300ResetHwState(r300);
350 }
351
352
353 /**
354  * Completely recalculates hardware state based on the Mesa state.
355  */
356 void r300ResetHwState(r300ContextPtr r300)
357 {
358         GLcontext* ctx = r300->radeon.glCtx;
359         int i;
360
361         if (RADEON_DEBUG & DEBUG_STATE)
362                 fprintf(stderr, "%s\n", __FUNCTION__);
363
364         r300UpdateWindow(ctx);
365         
366         r300ColorMask(ctx,
367                 ctx->Color.ColorMask[RCOMP],
368                 ctx->Color.ColorMask[GCOMP],
369                 ctx->Color.ColorMask[BCOMP],
370                 ctx->Color.ColorMask[ACOMP]);
371
372         r300Enable(ctx, GL_DEPTH_TEST, ctx->Depth.Test);
373         r300DepthMask(ctx, ctx->Depth.Mask);
374         r300DepthFunc(ctx, ctx->Depth.Func);
375
376         r300UpdateCulling(ctx);
377
378 //BEGIN: TODO
379         r300->hw.unk2080.cmd[1] = 0x0030045A;
380
381         r300->hw.ovf.cmd[R300_OVF_FMT_0] = 0x00000003;
382         r300->hw.ovf.cmd[R300_OVF_FMT_1] = 0x00000000;
383
384         r300->hw.vte.cmd[1] = R300_VPORT_X_SCALE_ENA
385                                 | R300_VPORT_X_OFFSET_ENA
386                                 | R300_VPORT_Y_SCALE_ENA
387                                 | R300_VPORT_Y_OFFSET_ENA
388                                 | R300_VPORT_Z_SCALE_ENA
389                                 | R300_VPORT_Z_OFFSET_ENA
390                                 | R300_VTX_W0_FMT;
391         r300->hw.vte.cmd[2] = 0x00000008;
392
393         r300->hw.unk2134.cmd[1] = 0x00FFFFFF;
394         r300->hw.unk2134.cmd[2] = 0x00000000;
395
396         r300->hw.unk2140.cmd[1] = 0x00000000;
397
398         ((drm_r300_cmd_header_t*)r300->hw.vir[0].cmd)->unchecked_state.count = 1;
399         r300->hw.vir[0].cmd[1] = 0x21030003;
400
401         ((drm_r300_cmd_header_t*)r300->hw.vir[1].cmd)->unchecked_state.count = 1;
402         r300->hw.vir[1].cmd[1] = 0xF688F688;
403
404         r300->hw.vic.cmd[R300_VIR_CNTL_0] = 0x00000001;
405         r300->hw.vic.cmd[R300_VIR_CNTL_1] = 0x00000405;
406
407         r300->hw.unk21DC.cmd[1] = 0xAAAAAAAA;
408
409         r300->hw.unk221C.cmd[1] = R300_221C_NORMAL;
410
411         r300->hw.unk2220.cmd[1] = r300PackFloat32(1.0);
412         r300->hw.unk2220.cmd[2] = r300PackFloat32(1.0);
413         r300->hw.unk2220.cmd[3] = r300PackFloat32(1.0);
414         r300->hw.unk2220.cmd[4] = r300PackFloat32(1.0);
415
416         if (GET_CHIP(r300->radeon.radeonScreen) == RADEON_CHIP_R300)
417                 r300->hw.unk2288.cmd[1] = R300_2288_R300;
418         else
419                 r300->hw.unk2288.cmd[1] = R300_2288_RV350;
420
421         r300->hw.vof.cmd[R300_VOF_CNTL_0] = R300_VAP_OUTPUT_VTX_FMT_0__POS_PRESENT
422                                 | R300_VAP_OUTPUT_VTX_FMT_0__COLOR_PRESENT;
423         r300->hw.vof.cmd[R300_VOF_CNTL_1] = 0; /* no textures */
424                 
425         r300->hw.pvs.cmd[R300_PVS_CNTL_1] = 0;
426         r300->hw.pvs.cmd[R300_PVS_CNTL_2] = 0;
427         r300->hw.pvs.cmd[R300_PVS_CNTL_3] = 0;
428
429         r300->hw.gb_enable.cmd[1] = R300_GB_POINT_STUFF_ENABLE
430                 | R300_GB_LINE_STUFF_ENABLE
431                 | R300_GB_TRIANGLE_STUFF_ENABLE;
432
433         r300->hw.gb_misc.cmd[R300_GB_MISC_MSPOS_0] = 0x66666666;
434         r300->hw.gb_misc.cmd[R300_GB_MISC_MSPOS_1] = 0x06666666;
435         if (GET_CHIP(r300->radeon.radeonScreen) == RADEON_CHIP_R300)
436                 r300->hw.gb_misc.cmd[R300_GB_MISC_TILE_CONFIG] = R300_GB_TILE_ENABLE
437                                                         | R300_GB_TILE_PIPE_COUNT_R300
438                                                         | R300_GB_TILE_SIZE_16;
439         else
440                 r300->hw.gb_misc.cmd[R300_GB_MISC_TILE_CONFIG] = R300_GB_TILE_ENABLE
441                                                         | R300_GB_TILE_PIPE_COUNT_RV300
442                                                         | R300_GB_TILE_SIZE_16;
443         r300->hw.gb_misc.cmd[R300_GB_MISC_SELECT] = 0x00000000;
444         r300->hw.gb_misc.cmd[R300_GB_MISC_AA_CONFIG] = 0x00000000; /* No antialiasing */
445
446         r300->hw.txe.cmd[R300_TXE_ENABLE] = 0;
447
448         r300->hw.unk4200.cmd[1] = r300PackFloat32(0.0);
449         r300->hw.unk4200.cmd[2] = r300PackFloat32(0.0);
450         r300->hw.unk4200.cmd[3] = r300PackFloat32(1.0);
451         r300->hw.unk4200.cmd[4] = r300PackFloat32(1.0);
452
453         r300->hw.unk4214.cmd[1] = 0x00050005;
454
455         r300->hw.ps.cmd[R300_PS_POINTSIZE] = (6 << R300_POINTSIZE_X_SHIFT) |
456                                              (6 << R300_POINTSIZE_Y_SHIFT);
457
458         r300->hw.unk4230.cmd[1] = 0x01800000;
459         r300->hw.unk4230.cmd[2] = 0x00020006;
460         r300->hw.unk4230.cmd[3] = r300PackFloat32(1.0 / 192.0);
461
462         r300->hw.unk4260.cmd[1] = 0;
463         r300->hw.unk4260.cmd[2] = r300PackFloat32(0.0);
464         r300->hw.unk4260.cmd[3] = r300PackFloat32(1.0);
465
466         r300->hw.unk4274.cmd[1] = 0x00000002;
467         r300->hw.unk4274.cmd[2] = 0x0003AAAA;
468         r300->hw.unk4274.cmd[3] = 0x00000000;
469         r300->hw.unk4274.cmd[4] = 0x00000000;
470
471         r300->hw.unk4288.cmd[1] = 0x00000000;
472         r300->hw.unk4288.cmd[2] = 0x00000001;
473         r300->hw.unk4288.cmd[3] = 0x00000000;
474         r300->hw.unk4288.cmd[4] = 0x00000000;
475         r300->hw.unk4288.cmd[5] = 0x00000000;
476
477         r300->hw.unk42A0.cmd[1] = 0x00000000;
478
479         r300->hw.unk42B4.cmd[1] = 0x00000000;
480
481         r300->hw.unk42C0.cmd[1] = 0x4B7FFFFF;
482         r300->hw.unk42C0.cmd[2] = 0x00000000;
483
484         /* The second constant is needed to get glxgears display anything .. */
485         r300->hw.rc.cmd[1] = R300_RS_CNTL_0_UNKNOWN_7 | R300_RS_CNTL_0_UNKNOWN_18;
486         r300->hw.rc.cmd[2] = 0;
487
488         for(i = 1; i <= 8; ++i)
489                 r300->hw.ri.cmd[i] = 0x00d10000;
490         r300->hw.ri.cmd[R300_RI_INTERP_1] |= R300_RS_INTERP_1_UNKNOWN;
491         r300->hw.ri.cmd[R300_RI_INTERP_2] |= R300_RS_INTERP_2_UNKNOWN;
492         r300->hw.ri.cmd[R300_RI_INTERP_3] |= R300_RS_INTERP_3_UNKNOWN;
493
494         ((drm_r300_cmd_header_t*)r300->hw.rr.cmd)->unchecked_state.count = 1;
495         for(i = 1; i <= 8; ++i)
496                 r300->hw.rr.cmd[i] = 0;
497         r300->hw.rr.cmd[R300_RR_ROUTE_0] = 0x4000;
498
499         r300->hw.unk43A4.cmd[1] = 0x0000001C;
500         r300->hw.unk43A4.cmd[2] = 0x2DA49525;
501
502         r300->hw.unk43E8.cmd[1] = 0x00FFFFFF;
503
504         r300->hw.fp.cmd[R300_FP_CNTL0] = 0;
505         r300->hw.fp.cmd[R300_FP_CNTL1] = 0;
506         r300->hw.fp.cmd[R300_FP_CNTL2] = 0;
507         r300->hw.fp.cmd[R300_FP_NODE0] = 0;
508         r300->hw.fp.cmd[R300_FP_NODE1] = 0;
509         r300->hw.fp.cmd[R300_FP_NODE2] = 0;
510         r300->hw.fp.cmd[R300_FP_NODE3] = 0;
511
512         r300->hw.unk46A4.cmd[1] = 0x00001B01;
513         r300->hw.unk46A4.cmd[2] = 0x00001B0F;
514         r300->hw.unk46A4.cmd[3] = 0x00001B0F;
515         r300->hw.unk46A4.cmd[4] = 0x00001B0F;
516         r300->hw.unk46A4.cmd[5] = 0x00000001;
517
518         for(i = 1; i <= 64; ++i) {
519                 /* create NOP instructions */
520                 r300->hw.fpi[0].cmd[i] = FP_INSTRC(MAD, FP_ARGC(SRC0C_XYZ), FP_ARGC(ONE), FP_ARGC(ZERO));
521                 r300->hw.fpi[1].cmd[i] = FP_SELC(0,XYZ,NO,FP_TMP(0),0,0);
522                 r300->hw.fpi[2].cmd[i] = FP_INSTRA(MAD, FP_ARGA(SRC0A), FP_ARGA(ONE), FP_ARGA(ZERO));
523                 r300->hw.fpi[3].cmd[i] = FP_SELA(0,W,NO,FP_TMP(0),0,0);
524         }
525
526         r300->hw.unk4BC0.cmd[1] = 0;
527
528         r300->hw.unk4BC8.cmd[1] = 0;
529         r300->hw.unk4BC8.cmd[2] = 0;
530         r300->hw.unk4BC8.cmd[3] = 0;
531
532         r300->hw.at.cmd[R300_AT_ALPHA_TEST] = 0;
533
534         r300->hw.unk4BD8.cmd[1] = 0;
535
536         r300->hw.unk4E00.cmd[1] = 0;
537
538         r300->hw.bld.cmd[R300_BLD_CBLEND] = 0;
539         r300->hw.bld.cmd[R300_BLD_ABLEND] = 0;
540
541         r300->hw.unk4E10.cmd[1] = 0;
542         r300->hw.unk4E10.cmd[2] = 0;
543         r300->hw.unk4E10.cmd[3] = 0;
544
545         r300->hw.cb.cmd[R300_CB_OFFSET] =
546                 r300->radeon.radeonScreen->backOffset +
547                 r300->radeon.radeonScreen->fbLocation;
548         r300->hw.cb.cmd[R300_CB_PITCH] = r300->radeon.radeonScreen->backPitch
549                 | R300_COLOR_UNKNOWN_22_23;
550
551         r300->hw.unk4E50.cmd[1] = 0;
552         r300->hw.unk4E50.cmd[2] = 0;
553         r300->hw.unk4E50.cmd[3] = 0;
554         r300->hw.unk4E50.cmd[4] = 0;
555         r300->hw.unk4E50.cmd[5] = 0;
556         r300->hw.unk4E50.cmd[6] = 0;
557         r300->hw.unk4E50.cmd[7] = 0;
558         r300->hw.unk4E50.cmd[8] = 0;
559         r300->hw.unk4E50.cmd[9] = 0;
560
561         r300->hw.unk4E88.cmd[1] = 0;
562
563         r300->hw.unk4EA0.cmd[1] = 0x00000000;
564         r300->hw.unk4EA0.cmd[2] = 0xffffffff;
565
566         r300->hw.unk4F08.cmd[1] = 0x00FFFF00;
567
568         r300->hw.unk4F10.cmd[1] = 0x00000002; // depthbuffer format?
569         r300->hw.unk4F10.cmd[2] = 0x00000000;
570         r300->hw.unk4F10.cmd[3] = 0x00000003;
571         r300->hw.unk4F10.cmd[4] = 0x00000000;
572
573         r300->hw.zb.cmd[R300_ZB_OFFSET] =
574                 r300->radeon.radeonScreen->depthOffset +
575                 r300->radeon.radeonScreen->fbLocation;
576         r300->hw.zb.cmd[R300_ZB_PITCH] = r300->radeon.radeonScreen->depthPitch;
577
578         r300->hw.unk4F28.cmd[1] = 0;
579
580         r300->hw.unk4F30.cmd[1] = 0;
581         r300->hw.unk4F30.cmd[2] = 0;
582
583         r300->hw.unk4F44.cmd[1] = 0;
584
585         r300->hw.unk4F54.cmd[1] = 0;
586
587         ((drm_r300_cmd_header_t*)r300->hw.vpi.cmd)->vpu.count = 0;
588         for(i = 1; i < R300_VPI_CMDSIZE; i += 4) {
589                 /* MOV t0, t0 */
590                 r300->hw.vpi.cmd[i+0] = VP_OUT(ADD,TMP,0,XYZW);
591                 r300->hw.vpi.cmd[i+1] = VP_IN(TMP,0);
592                 r300->hw.vpi.cmd[i+2] = VP_ZERO();
593                 r300->hw.vpi.cmd[i+3] = VP_ZERO();
594         }
595
596         ((drm_r300_cmd_header_t*)r300->hw.vpp.cmd)->vpu.count = 0;
597         for(i = 1; i < R300_VPP_CMDSIZE; ++i)
598                 r300->hw.vpp.cmd[i] = 0;
599
600         r300->hw.vps.cmd[R300_VPS_ZERO_0] = 0;
601         r300->hw.vps.cmd[R300_VPS_ZERO_1] = 0;
602         r300->hw.vps.cmd[R300_VPS_POINTSIZE] = r300PackFloat32(1.0);
603         r300->hw.vps.cmd[R300_VPS_ZERO_3] = 0;
604         
605         /* Initialize texture units */
606         for(i=0;i<r300->radeon.glCtx->Const.MaxTextureUnits;i++){
607                 r300->hw.tex.filter.cmd[R300_TEX_VALUE_0+i]=0x0;
608                 r300->hw.tex.unknown1.cmd[R300_TEX_VALUE_0+i]=0x0;
609                 r300->hw.tex.size.cmd[R300_TEX_VALUE_0+i]=0x0;
610                 r300->hw.tex.format.cmd[R300_TEX_VALUE_0+i]=0x0;
611                 r300->hw.tex.offset.cmd[R300_TEX_VALUE_0+i]=0x0;
612                 r300->hw.tex.unknown4.cmd[R300_TEX_VALUE_0+i]=0x0;
613                 r300->hw.tex.unknown5.cmd[R300_TEX_VALUE_0+i]=0x0;
614                 }
615 //END: TODO
616         
617         r300->hw.all_dirty = GL_TRUE;
618 }
619
620
621
622 /**
623  * Calculate initial hardware state and register state functions.
624  * Assumes that the command buffer and state atoms have been
625  * initialized already.
626  */
627 void r300InitState(r300ContextPtr r300)
628 {
629         radeonInitState(&r300->radeon);
630         
631         r300->state.depth.scale = 1.0 / (GLfloat) 0xffff;
632
633         r300ResetHwState(r300);
634 }
635
636
637
638 /**
639  * Initialize driver's state callback functions
640  */
641 void r300InitStateFuncs(struct dd_function_table* functions)
642 {
643         radeonInitStateFuncs(functions);
644
645         functions->UpdateState = r300InvalidateState;
646         functions->AlphaFunc = r300AlphaFunc;
647         functions->Enable = r300Enable;
648         functions->ColorMask = r300ColorMask;
649         functions->DepthFunc = r300DepthFunc;
650         functions->DepthMask = r300DepthMask;
651         functions->CullFace = r300CullFace;
652         functions->FrontFace = r300FrontFace;
653
654         /* Viewport related */
655         functions->Viewport = r300Viewport;
656         functions->DepthRange = r300DepthRange;
657         functions->PointSize = r300PointSize;
658 }
659