radeon: Differentiate 16 bpp destination formats.
[mesa.git] / src / mesa / drivers / dri / radeon / radeon_state_init.c
1 /*
2 * Copyright 2000, 2001 VA Linux Systems Inc., Fremont, California.
3 *
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * on the rights to use, copy, modify, merge, publish, distribute, sub
10 * license, and/or sell copies of the Software, and to permit persons to whom
11 * the Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice (including the next
14 * paragraph) shall be included in all copies or substantial portions of the
15 * Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
20 * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
21 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23 * OTHER DEALINGS IN THE SOFTWARE.
24 *
25 * Authors:
26 * Gareth Hughes <gareth@valinux.com>
27 * Keith Whitwell <keith@tungstengraphics.com>
28 */
29
30 #include "main/glheader.h"
31 #include "main/imports.h"
32 #include "main/api_arrayelt.h"
33
34 #include "swrast/swrast.h"
35 #include "vbo/vbo.h"
36 #include "tnl/tnl.h"
37 #include "tnl/t_pipeline.h"
38 #include "swrast_setup/swrast_setup.h"
39
40 #include "radeon_context.h"
41 #include "radeon_mipmap_tree.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
48 #include "../r200/r200_reg.h"
49
50 #include "xmlpool.h"
51
52 /* New (1.3) state mechanism. 3 commands (packet, scalar, vector) in
53 * 1.3 cmdbuffers allow all previous state to be updated as well as
54 * the tcl scalar and vector areas.
55 */
56 static struct {
57 int start;
58 int len;
59 const char *name;
60 } packet[RADEON_MAX_STATE_PACKETS] = {
61 {RADEON_PP_MISC, 7, "RADEON_PP_MISC"},
62 {RADEON_PP_CNTL, 3, "RADEON_PP_CNTL"},
63 {RADEON_RB3D_COLORPITCH, 1, "RADEON_RB3D_COLORPITCH"},
64 {RADEON_RE_LINE_PATTERN, 2, "RADEON_RE_LINE_PATTERN"},
65 {RADEON_SE_LINE_WIDTH, 1, "RADEON_SE_LINE_WIDTH"},
66 {RADEON_PP_LUM_MATRIX, 1, "RADEON_PP_LUM_MATRIX"},
67 {RADEON_PP_ROT_MATRIX_0, 2, "RADEON_PP_ROT_MATRIX_0"},
68 {RADEON_RB3D_STENCILREFMASK, 3, "RADEON_RB3D_STENCILREFMASK"},
69 {RADEON_SE_VPORT_XSCALE, 6, "RADEON_SE_VPORT_XSCALE"},
70 {RADEON_SE_CNTL, 2, "RADEON_SE_CNTL"},
71 {RADEON_SE_CNTL_STATUS, 1, "RADEON_SE_CNTL_STATUS"},
72 {RADEON_RE_MISC, 1, "RADEON_RE_MISC"},
73 {RADEON_PP_TXFILTER_0, 6, "RADEON_PP_TXFILTER_0"},
74 {RADEON_PP_BORDER_COLOR_0, 1, "RADEON_PP_BORDER_COLOR_0"},
75 {RADEON_PP_TXFILTER_1, 6, "RADEON_PP_TXFILTER_1"},
76 {RADEON_PP_BORDER_COLOR_1, 1, "RADEON_PP_BORDER_COLOR_1"},
77 {RADEON_PP_TXFILTER_2, 6, "RADEON_PP_TXFILTER_2"},
78 {RADEON_PP_BORDER_COLOR_2, 1, "RADEON_PP_BORDER_COLOR_2"},
79 {RADEON_SE_ZBIAS_FACTOR, 2, "RADEON_SE_ZBIAS_FACTOR"},
80 {RADEON_SE_TCL_OUTPUT_VTX_FMT, 11, "RADEON_SE_TCL_OUTPUT_VTX_FMT"},
81 {RADEON_SE_TCL_MATERIAL_EMMISSIVE_RED, 17,
82 "RADEON_SE_TCL_MATERIAL_EMMISSIVE_RED"},
83 {R200_PP_TXCBLEND_0, 4, "R200_PP_TXCBLEND_0"},
84 {R200_PP_TXCBLEND_1, 4, "R200_PP_TXCBLEND_1"},
85 {R200_PP_TXCBLEND_2, 4, "R200_PP_TXCBLEND_2"},
86 {R200_PP_TXCBLEND_3, 4, "R200_PP_TXCBLEND_3"},
87 {R200_PP_TXCBLEND_4, 4, "R200_PP_TXCBLEND_4"},
88 {R200_PP_TXCBLEND_5, 4, "R200_PP_TXCBLEND_5"},
89 {R200_PP_TXCBLEND_6, 4, "R200_PP_TXCBLEND_6"},
90 {R200_PP_TXCBLEND_7, 4, "R200_PP_TXCBLEND_7"},
91 {R200_SE_TCL_LIGHT_MODEL_CTL_0, 6, "R200_SE_TCL_LIGHT_MODEL_CTL_0"},
92 {R200_PP_TFACTOR_0, 6, "R200_PP_TFACTOR_0"},
93 {R200_SE_VTX_FMT_0, 4, "R200_SE_VTX_FMT_0"},
94 {R200_SE_VAP_CNTL, 1, "R200_SE_VAP_CNTL"},
95 {R200_SE_TCL_MATRIX_SEL_0, 5, "R200_SE_TCL_MATRIX_SEL_0"},
96 {R200_SE_TCL_TEX_PROC_CTL_2, 5, "R200_SE_TCL_TEX_PROC_CTL_2"},
97 {R200_SE_TCL_UCP_VERT_BLEND_CTL, 1, "R200_SE_TCL_UCP_VERT_BLEND_CTL"},
98 {R200_PP_TXFILTER_0, 6, "R200_PP_TXFILTER_0"},
99 {R200_PP_TXFILTER_1, 6, "R200_PP_TXFILTER_1"},
100 {R200_PP_TXFILTER_2, 6, "R200_PP_TXFILTER_2"},
101 {R200_PP_TXFILTER_3, 6, "R200_PP_TXFILTER_3"},
102 {R200_PP_TXFILTER_4, 6, "R200_PP_TXFILTER_4"},
103 {R200_PP_TXFILTER_5, 6, "R200_PP_TXFILTER_5"},
104 {R200_PP_TXOFFSET_0, 1, "R200_PP_TXOFFSET_0"},
105 {R200_PP_TXOFFSET_1, 1, "R200_PP_TXOFFSET_1"},
106 {R200_PP_TXOFFSET_2, 1, "R200_PP_TXOFFSET_2"},
107 {R200_PP_TXOFFSET_3, 1, "R200_PP_TXOFFSET_3"},
108 {R200_PP_TXOFFSET_4, 1, "R200_PP_TXOFFSET_4"},
109 {R200_PP_TXOFFSET_5, 1, "R200_PP_TXOFFSET_5"},
110 {R200_SE_VTE_CNTL, 1, "R200_SE_VTE_CNTL"},
111 {R200_SE_TCL_OUTPUT_VTX_COMP_SEL, 1,
112 "R200_SE_TCL_OUTPUT_VTX_COMP_SEL"},
113 {R200_PP_TAM_DEBUG3, 1, "R200_PP_TAM_DEBUG3"},
114 {R200_PP_CNTL_X, 1, "R200_PP_CNTL_X"},
115 {R200_RB3D_DEPTHXY_OFFSET, 1, "R200_RB3D_DEPTHXY_OFFSET"},
116 {R200_RE_AUX_SCISSOR_CNTL, 1, "R200_RE_AUX_SCISSOR_CNTL"},
117 {R200_RE_SCISSOR_TL_0, 2, "R200_RE_SCISSOR_TL_0"},
118 {R200_RE_SCISSOR_TL_1, 2, "R200_RE_SCISSOR_TL_1"},
119 {R200_RE_SCISSOR_TL_2, 2, "R200_RE_SCISSOR_TL_2"},
120 {R200_SE_VAP_CNTL_STATUS, 1, "R200_SE_VAP_CNTL_STATUS"},
121 {R200_SE_VTX_STATE_CNTL, 1, "R200_SE_VTX_STATE_CNTL"},
122 {R200_RE_POINTSIZE, 1, "R200_RE_POINTSIZE"},
123 {R200_SE_TCL_INPUT_VTX_VECTOR_ADDR_0, 4,
124 "R200_SE_TCL_INPUT_VTX_VECTOR_ADDR_0"},
125 {R200_PP_CUBIC_FACES_0, 1, "R200_PP_CUBIC_FACES_0"}, /* 61 */
126 {R200_PP_CUBIC_OFFSET_F1_0, 5, "R200_PP_CUBIC_OFFSET_F1_0"}, /* 62 */
127 {R200_PP_CUBIC_FACES_1, 1, "R200_PP_CUBIC_FACES_1"},
128 {R200_PP_CUBIC_OFFSET_F1_1, 5, "R200_PP_CUBIC_OFFSET_F1_1"},
129 {R200_PP_CUBIC_FACES_2, 1, "R200_PP_CUBIC_FACES_2"},
130 {R200_PP_CUBIC_OFFSET_F1_2, 5, "R200_PP_CUBIC_OFFSET_F1_2"},
131 {R200_PP_CUBIC_FACES_3, 1, "R200_PP_CUBIC_FACES_3"},
132 {R200_PP_CUBIC_OFFSET_F1_3, 5, "R200_PP_CUBIC_OFFSET_F1_3"},
133 {R200_PP_CUBIC_FACES_4, 1, "R200_PP_CUBIC_FACES_4"},
134 {R200_PP_CUBIC_OFFSET_F1_4, 5, "R200_PP_CUBIC_OFFSET_F1_4"},
135 {R200_PP_CUBIC_FACES_5, 1, "R200_PP_CUBIC_FACES_5"},
136 {R200_PP_CUBIC_OFFSET_F1_5, 5, "R200_PP_CUBIC_OFFSET_F1_5"},
137 {RADEON_PP_TEX_SIZE_0, 2, "RADEON_PP_TEX_SIZE_0"},
138 {RADEON_PP_TEX_SIZE_1, 2, "RADEON_PP_TEX_SIZE_1"},
139 {RADEON_PP_TEX_SIZE_2, 2, "RADEON_PP_TEX_SIZE_2"},
140 {R200_RB3D_BLENDCOLOR, 3, "R200_RB3D_BLENDCOLOR"},
141 {R200_SE_TCL_POINT_SPRITE_CNTL, 1, "R200_SE_TCL_POINT_SPRITE_CNTL"},
142 {RADEON_PP_CUBIC_FACES_0, 1, "RADEON_PP_CUBIC_FACES_0"},
143 {RADEON_PP_CUBIC_OFFSET_T0_0, 5, "RADEON_PP_CUBIC_OFFSET_T0_0"},
144 {RADEON_PP_CUBIC_FACES_1, 1, "RADEON_PP_CUBIC_FACES_1"},
145 {RADEON_PP_CUBIC_OFFSET_T1_0, 5, "RADEON_PP_CUBIC_OFFSET_T1_0"},
146 {RADEON_PP_CUBIC_FACES_2, 1, "RADEON_PP_CUBIC_FACES_2"},
147 {RADEON_PP_CUBIC_OFFSET_T2_0, 5, "RADEON_PP_CUBIC_OFFSET_T2_0"},
148 {R200_PP_TRI_PERF, 2, "R200_PP_TRI_PERF"},
149 {R200_PP_TXCBLEND_8, 32, "R200_PP_AFS_0"}, /* 85 */
150 {R200_PP_TXCBLEND_0, 32, "R200_PP_AFS_1"},
151 {R200_PP_TFACTOR_0, 8, "R200_ATF_TFACTOR"},
152 {R200_PP_TXFILTER_0, 8, "R200_PP_TXCTLALL_0"},
153 {R200_PP_TXFILTER_1, 8, "R200_PP_TXCTLALL_1"},
154 {R200_PP_TXFILTER_2, 8, "R200_PP_TXCTLALL_2"},
155 {R200_PP_TXFILTER_3, 8, "R200_PP_TXCTLALL_3"},
156 {R200_PP_TXFILTER_4, 8, "R200_PP_TXCTLALL_4"},
157 {R200_PP_TXFILTER_5, 8, "R200_PP_TXCTLALL_5"},
158 {R200_VAP_PVS_CNTL_1, 2, "R200_VAP_PVS_CNTL"},
159 };
160
161 /* =============================================================
162 * State initialization
163 */
164 static int cmdpkt( r100ContextPtr rmesa, int id )
165 {
166 drm_radeon_cmd_header_t h;
167
168 if (rmesa->radeon.radeonScreen->kernel_mm) {
169 return CP_PACKET0(packet[id].start, packet[id].len - 1);
170 } else {
171 h.i = 0;
172 h.packet.cmd_type = RADEON_CMD_PACKET;
173 h.packet.packet_id = id;
174 }
175 return h.i;
176 }
177
178 static int cmdvec( int offset, int stride, int count )
179 {
180 drm_radeon_cmd_header_t h;
181 h.i = 0;
182 h.vectors.cmd_type = RADEON_CMD_VECTORS;
183 h.vectors.offset = offset;
184 h.vectors.stride = stride;
185 h.vectors.count = count;
186 return h.i;
187 }
188
189 static int cmdscl( int offset, int stride, int count )
190 {
191 drm_radeon_cmd_header_t h;
192 h.i = 0;
193 h.scalars.cmd_type = RADEON_CMD_SCALARS;
194 h.scalars.offset = offset;
195 h.scalars.stride = stride;
196 h.scalars.count = count;
197 return h.i;
198 }
199
200 #define CHECK( NM, FLAG ) \
201 static int check_##NM( GLcontext *ctx, struct radeon_state_atom *atom ) \
202 { \
203 return FLAG ? atom->cmd_size : 0; \
204 }
205
206 #define TCL_CHECK( NM, FLAG ) \
207 static int check_##NM( GLcontext *ctx, struct radeon_state_atom *atom ) \
208 { \
209 r100ContextPtr rmesa = R100_CONTEXT(ctx); \
210 return (!rmesa->radeon.TclFallback && (FLAG)) ? atom->cmd_size : 0; \
211 }
212
213
214 CHECK( always, GL_TRUE )
215 CHECK( never, GL_FALSE )
216 CHECK( tex0, ctx->Texture.Unit[0]._ReallyEnabled )
217 CHECK( tex1, ctx->Texture.Unit[1]._ReallyEnabled )
218 /* need this for the cubic_map on disabled unit 2 bug, maybe r100 only? */
219 CHECK( tex2, ctx->Texture._EnabledUnits )
220 CHECK( cube0, (ctx->Texture.Unit[0]._ReallyEnabled & TEXTURE_CUBE_BIT))
221 CHECK( cube1, (ctx->Texture.Unit[1]._ReallyEnabled & TEXTURE_CUBE_BIT))
222 CHECK( cube2, (ctx->Texture.Unit[2]._ReallyEnabled & TEXTURE_CUBE_BIT))
223 CHECK( fog, ctx->Fog.Enabled )
224 TCL_CHECK( tcl, GL_TRUE )
225 TCL_CHECK( tcl_tex0, ctx->Texture.Unit[0]._ReallyEnabled )
226 TCL_CHECK( tcl_tex1, ctx->Texture.Unit[1]._ReallyEnabled )
227 TCL_CHECK( tcl_tex2, ctx->Texture.Unit[2]._ReallyEnabled )
228 TCL_CHECK( tcl_lighting, ctx->Light.Enabled )
229 TCL_CHECK( tcl_eyespace_or_lighting, ctx->_NeedEyeCoords || ctx->Light.Enabled )
230 TCL_CHECK( tcl_lit0, ctx->Light.Enabled && ctx->Light.Light[0].Enabled )
231 TCL_CHECK( tcl_lit1, ctx->Light.Enabled && ctx->Light.Light[1].Enabled )
232 TCL_CHECK( tcl_lit2, ctx->Light.Enabled && ctx->Light.Light[2].Enabled )
233 TCL_CHECK( tcl_lit3, ctx->Light.Enabled && ctx->Light.Light[3].Enabled )
234 TCL_CHECK( tcl_lit4, ctx->Light.Enabled && ctx->Light.Light[4].Enabled )
235 TCL_CHECK( tcl_lit5, ctx->Light.Enabled && ctx->Light.Light[5].Enabled )
236 TCL_CHECK( tcl_lit6, ctx->Light.Enabled && ctx->Light.Light[6].Enabled )
237 TCL_CHECK( tcl_lit7, ctx->Light.Enabled && ctx->Light.Light[7].Enabled )
238 TCL_CHECK( tcl_ucp0, (ctx->Transform.ClipPlanesEnabled & 0x1) )
239 TCL_CHECK( tcl_ucp1, (ctx->Transform.ClipPlanesEnabled & 0x2) )
240 TCL_CHECK( tcl_ucp2, (ctx->Transform.ClipPlanesEnabled & 0x4) )
241 TCL_CHECK( tcl_ucp3, (ctx->Transform.ClipPlanesEnabled & 0x8) )
242 TCL_CHECK( tcl_ucp4, (ctx->Transform.ClipPlanesEnabled & 0x10) )
243 TCL_CHECK( tcl_ucp5, (ctx->Transform.ClipPlanesEnabled & 0x20) )
244 TCL_CHECK( tcl_eyespace_or_fog, ctx->_NeedEyeCoords || ctx->Fog.Enabled )
245
246 CHECK( txr0, (ctx->Texture.Unit[0]._ReallyEnabled & TEXTURE_RECT_BIT))
247 CHECK( txr1, (ctx->Texture.Unit[1]._ReallyEnabled & TEXTURE_RECT_BIT))
248 CHECK( txr2, (ctx->Texture.Unit[2]._ReallyEnabled & TEXTURE_RECT_BIT))
249
250 #define OUT_VEC(hdr, data) do { \
251 drm_radeon_cmd_header_t h; \
252 h.i = hdr; \
253 OUT_BATCH(CP_PACKET0(RADEON_SE_TCL_STATE_FLUSH, 0)); \
254 OUT_BATCH(0); \
255 OUT_BATCH(CP_PACKET0(R200_SE_TCL_VECTOR_INDX_REG, 0)); \
256 OUT_BATCH(h.vectors.offset | (h.vectors.stride << RADEON_VEC_INDX_OCTWORD_STRIDE_SHIFT)); \
257 OUT_BATCH(CP_PACKET0_ONE(R200_SE_TCL_VECTOR_DATA_REG, h.vectors.count - 1)); \
258 OUT_BATCH_TABLE((data), h.vectors.count); \
259 } while(0)
260
261 #define OUT_SCL(hdr, data) do { \
262 drm_radeon_cmd_header_t h; \
263 h.i = hdr; \
264 OUT_BATCH(CP_PACKET0(R200_SE_TCL_SCALAR_INDX_REG, 0)); \
265 OUT_BATCH((h.scalars.offset) | (h.scalars.stride << RADEON_SCAL_INDX_DWORD_STRIDE_SHIFT)); \
266 OUT_BATCH(CP_PACKET0_ONE(R200_SE_TCL_SCALAR_DATA_REG, h.scalars.count - 1)); \
267 OUT_BATCH_TABLE((data), h.scalars.count); \
268 } while(0)
269
270 static void scl_emit(GLcontext *ctx, struct radeon_state_atom *atom)
271 {
272 r100ContextPtr r100 = R100_CONTEXT(ctx);
273 BATCH_LOCALS(&r100->radeon);
274 uint32_t dwords = atom->cmd_size;
275
276 dwords += 2;
277 BEGIN_BATCH_NO_AUTOSTATE(dwords);
278 OUT_SCL(atom->cmd[0], atom->cmd+1);
279 END_BATCH();
280 }
281
282
283 static void vec_emit(GLcontext *ctx, struct radeon_state_atom *atom)
284 {
285 r100ContextPtr r100 = R100_CONTEXT(ctx);
286 BATCH_LOCALS(&r100->radeon);
287 uint32_t dwords = atom->cmd_size;
288
289 dwords += 4;
290 BEGIN_BATCH_NO_AUTOSTATE(dwords);
291 OUT_VEC(atom->cmd[0], atom->cmd+1);
292 END_BATCH();
293 }
294
295
296 static void lit_emit(GLcontext *ctx, struct radeon_state_atom *atom)
297 {
298 r100ContextPtr r100 = R100_CONTEXT(ctx);
299 BATCH_LOCALS(&r100->radeon);
300 uint32_t dwords = atom->cmd_size;
301
302 dwords += 6;
303 BEGIN_BATCH_NO_AUTOSTATE(dwords);
304 OUT_VEC(atom->cmd[LIT_CMD_0], atom->cmd+1);
305 OUT_SCL(atom->cmd[LIT_CMD_1], atom->cmd+LIT_CMD_1+1);
306 END_BATCH();
307 }
308
309 static void ctx_emit(GLcontext *ctx, struct radeon_state_atom *atom)
310 {
311 r100ContextPtr r100 = R100_CONTEXT(ctx);
312 BATCH_LOCALS(&r100->radeon);
313 struct radeon_renderbuffer *rrb;
314 uint32_t cbpitch;
315 uint32_t zbpitch, depth_fmt;
316 uint32_t dwords = atom->cmd_size;
317
318 /* output the first 7 bytes of context */
319 BEGIN_BATCH_NO_AUTOSTATE(dwords + 4);
320 OUT_BATCH_TABLE(atom->cmd, 5);
321
322 rrb = radeon_get_depthbuffer(&r100->radeon);
323 if (!rrb) {
324 OUT_BATCH(0);
325 OUT_BATCH(0);
326 } else {
327 zbpitch = (rrb->pitch / rrb->cpp);
328 if (r100->using_hyperz)
329 zbpitch |= RADEON_DEPTH_HYPERZ;
330
331 OUT_BATCH_RELOC(0, rrb->bo, 0, 0, RADEON_GEM_DOMAIN_VRAM, 0);
332 OUT_BATCH(zbpitch);
333 if (rrb->cpp == 4)
334 depth_fmt = RADEON_DEPTH_FORMAT_24BIT_INT_Z;
335 else
336 depth_fmt = RADEON_DEPTH_FORMAT_16BIT_INT_Z;
337 atom->cmd[CTX_RB3D_ZSTENCILCNTL] &= ~RADEON_DEPTH_FORMAT_MASK;
338 atom->cmd[CTX_RB3D_ZSTENCILCNTL] |= depth_fmt;
339 }
340
341 OUT_BATCH(atom->cmd[CTX_RB3D_ZSTENCILCNTL]);
342 OUT_BATCH(atom->cmd[CTX_CMD_1]);
343 OUT_BATCH(atom->cmd[CTX_PP_CNTL]);
344
345 rrb = radeon_get_colorbuffer(&r100->radeon);
346 if (!rrb || !rrb->bo) {
347 OUT_BATCH(atom->cmd[CTX_RB3D_CNTL]);
348 OUT_BATCH(atom->cmd[CTX_RB3D_COLOROFFSET]);
349 } else {
350 atom->cmd[CTX_RB3D_CNTL] &= ~(0xf << 10);
351 if (rrb->cpp == 4)
352 atom->cmd[CTX_RB3D_CNTL] |= RADEON_COLOR_FORMAT_ARGB8888;
353 else
354 atom->cmd[CTX_RB3D_CNTL] |= RADEON_COLOR_FORMAT_RGB565;
355
356 OUT_BATCH(atom->cmd[CTX_RB3D_CNTL]);
357 OUT_BATCH_RELOC(0, rrb->bo, 0, 0, RADEON_GEM_DOMAIN_VRAM, 0);
358 }
359
360 OUT_BATCH(atom->cmd[CTX_CMD_2]);
361
362 if (!rrb || !rrb->bo) {
363 OUT_BATCH(atom->cmd[CTX_RB3D_COLORPITCH]);
364 } else {
365 cbpitch = (rrb->pitch / rrb->cpp);
366 if (rrb->bo->flags & RADEON_BO_FLAGS_MACRO_TILE)
367 cbpitch |= RADEON_COLOR_TILE_ENABLE;
368 OUT_BATCH(cbpitch);
369 }
370
371 END_BATCH();
372 }
373
374 static void ctx_emit_cs(GLcontext *ctx, struct radeon_state_atom *atom)
375 {
376 r100ContextPtr r100 = R100_CONTEXT(ctx);
377 BATCH_LOCALS(&r100->radeon);
378 struct radeon_renderbuffer *rrb, *drb;
379 uint32_t cbpitch = 0;
380 uint32_t zbpitch = 0;
381 uint32_t dwords = atom->cmd_size;
382 uint32_t depth_fmt;
383
384 rrb = radeon_get_colorbuffer(&r100->radeon);
385 if (!rrb || !rrb->bo) {
386 fprintf(stderr, "no rrb\n");
387 return;
388 }
389
390 atom->cmd[CTX_RB3D_CNTL] &= ~(0xf << 10);
391 if (rrb->cpp == 4)
392 atom->cmd[CTX_RB3D_CNTL] |= RADEON_COLOR_FORMAT_ARGB8888;
393 else switch (rrb->base._ActualFormat) {
394 case GL_RGB5:
395 atom->cmd[CTX_RB3D_CNTL] |= RADEON_COLOR_FORMAT_RGB565;
396 break;
397 case GL_RGBA4:
398 atom->cmd[CTX_RB3D_CNTL] |= RADEON_COLOR_FORMAT_ARGB4444;
399 break;
400 case GL_RGB5_A1:
401 atom->cmd[CTX_RB3D_CNTL] |= RADEON_COLOR_FORMAT_ARGB1555;
402 break;
403 }
404
405 cbpitch = (rrb->pitch / rrb->cpp);
406 if (rrb->bo->flags & RADEON_BO_FLAGS_MACRO_TILE)
407 cbpitch |= R200_COLOR_TILE_ENABLE;
408
409 drb = radeon_get_depthbuffer(&r100->radeon);
410 if (drb) {
411 zbpitch = (drb->pitch / drb->cpp);
412 if (drb->cpp == 4)
413 depth_fmt = RADEON_DEPTH_FORMAT_24BIT_INT_Z;
414 else
415 depth_fmt = RADEON_DEPTH_FORMAT_16BIT_INT_Z;
416 atom->cmd[CTX_RB3D_ZSTENCILCNTL] &= ~RADEON_DEPTH_FORMAT_MASK;
417 atom->cmd[CTX_RB3D_ZSTENCILCNTL] |= depth_fmt;
418
419 }
420
421 /* output the first 7 bytes of context */
422 dwords = 10;
423 if (drb)
424 dwords += 6;
425 if (rrb)
426 dwords += 6;
427 BEGIN_BATCH_NO_AUTOSTATE(dwords);
428
429 /* In the CS case we need to split this up */
430 OUT_BATCH(CP_PACKET0(packet[0].start, 3));
431 OUT_BATCH_TABLE((atom->cmd + 1), 4);
432
433 if (drb) {
434 OUT_BATCH(CP_PACKET0(RADEON_RB3D_DEPTHOFFSET, 0));
435 OUT_BATCH_RELOC(0, drb->bo, 0, 0, RADEON_GEM_DOMAIN_VRAM, 0);
436
437 OUT_BATCH(CP_PACKET0(RADEON_RB3D_DEPTHPITCH, 0));
438 OUT_BATCH(zbpitch);
439 }
440
441 OUT_BATCH(CP_PACKET0(RADEON_RB3D_ZSTENCILCNTL, 0));
442 OUT_BATCH(atom->cmd[CTX_RB3D_ZSTENCILCNTL]);
443 OUT_BATCH(CP_PACKET0(RADEON_PP_CNTL, 1));
444 OUT_BATCH(atom->cmd[CTX_PP_CNTL]);
445 OUT_BATCH(atom->cmd[CTX_RB3D_CNTL]);
446
447 if (rrb) {
448 OUT_BATCH(CP_PACKET0(RADEON_RB3D_COLOROFFSET, 0));
449 OUT_BATCH_RELOC(0, rrb->bo, 0, 0, RADEON_GEM_DOMAIN_VRAM, 0);
450
451 OUT_BATCH(CP_PACKET0(RADEON_RB3D_COLORPITCH, 0));
452 OUT_BATCH(cbpitch);
453 }
454
455 // if (atom->cmd_size == CTX_STATE_SIZE_NEWDRM) {
456 // OUT_BATCH_TABLE((atom->cmd + 14), 4);
457 // }
458
459 END_BATCH();
460 BEGIN_BATCH_NO_AUTOSTATE(4);
461 OUT_BATCH(CP_PACKET0(RADEON_RE_TOP_LEFT, 0));
462 OUT_BATCH(0);
463 OUT_BATCH(CP_PACKET0(RADEON_RE_WIDTH_HEIGHT, 0));
464 if (rrb) {
465 OUT_BATCH(((rrb->base.Width - 1) << RADEON_RE_WIDTH_SHIFT) |
466 ((rrb->base.Height - 1) << RADEON_RE_HEIGHT_SHIFT));
467 } else {
468 OUT_BATCH(0);
469 }
470 END_BATCH();
471 }
472
473 static void cube_emit(GLcontext *ctx, struct radeon_state_atom *atom)
474 {
475 r100ContextPtr r100 = R100_CONTEXT(ctx);
476 BATCH_LOCALS(&r100->radeon);
477 uint32_t dwords = 3;
478 int i = atom->idx, j;
479 radeonTexObj *t = r100->state.texture.unit[i].texobj;
480 radeon_mipmap_level *lvl;
481
482 if (!(ctx->Texture.Unit[i]._ReallyEnabled & TEXTURE_CUBE_BIT))
483 return;
484
485 if (!t)
486 return;
487
488 if (!t->mt)
489 return;
490
491 BEGIN_BATCH_NO_AUTOSTATE(dwords + (5 * 3));
492 OUT_BATCH_TABLE(atom->cmd, 3);
493 lvl = &t->mt->levels[0];
494 for (j = 0; j < 5; j++) {
495 OUT_BATCH_RELOC(lvl->faces[j].offset, t->mt->bo, lvl->faces[j].offset,
496 RADEON_GEM_DOMAIN_VRAM, 0, 0);
497 }
498 END_BATCH();
499 }
500
501 static void cube_emit_cs(GLcontext *ctx, struct radeon_state_atom *atom)
502 {
503 r100ContextPtr r100 = R100_CONTEXT(ctx);
504 BATCH_LOCALS(&r100->radeon);
505 uint32_t dwords = 2;
506 int i = atom->idx, j;
507 radeonTexObj *t = r100->state.texture.unit[i].texobj;
508 radeon_mipmap_level *lvl;
509 uint32_t base_reg;
510
511 if (!(ctx->Texture.Unit[i]._ReallyEnabled & TEXTURE_CUBE_BIT))
512 return;
513
514 if (!t)
515 return;
516
517 if (!t->mt)
518 return;
519
520 switch(i) {
521 case 1: base_reg = RADEON_PP_CUBIC_OFFSET_T1_0; break;
522 case 2: base_reg = RADEON_PP_CUBIC_OFFSET_T2_0; break;
523 default:
524 case 0: base_reg = RADEON_PP_CUBIC_OFFSET_T0_0; break;
525 };
526 BEGIN_BATCH_NO_AUTOSTATE(dwords + (5 * 4));
527 OUT_BATCH_TABLE(atom->cmd, 2);
528 lvl = &t->mt->levels[0];
529 for (j = 0; j < 5; j++) {
530 OUT_BATCH(CP_PACKET0(base_reg + (4 * j), 0));
531 OUT_BATCH_RELOC(lvl->faces[j].offset, t->mt->bo, lvl->faces[j].offset,
532 RADEON_GEM_DOMAIN_VRAM, 0, 0);
533 }
534 END_BATCH();
535 }
536
537 static void tex_emit(GLcontext *ctx, struct radeon_state_atom *atom)
538 {
539 r100ContextPtr r100 = R100_CONTEXT(ctx);
540 BATCH_LOCALS(&r100->radeon);
541 uint32_t dwords = atom->cmd_size;
542 int i = atom->idx;
543 radeonTexObj *t = r100->state.texture.unit[i].texobj;
544 radeon_mipmap_level *lvl;
545
546 if (t && t->mt && !t->image_override)
547 dwords += 2;
548 BEGIN_BATCH_NO_AUTOSTATE(dwords);
549
550 OUT_BATCH_TABLE(atom->cmd, 3);
551 if (t && t->mt && !t->image_override) {
552 if ((ctx->Texture.Unit[i]._ReallyEnabled & TEXTURE_CUBE_BIT)) {
553 lvl = &t->mt->levels[0];
554 OUT_BATCH_RELOC(lvl->faces[5].offset, t->mt->bo, lvl->faces[5].offset,
555 RADEON_GEM_DOMAIN_GTT|RADEON_GEM_DOMAIN_VRAM, 0, 0);
556 } else {
557 OUT_BATCH_RELOC(t->tile_bits, t->mt->bo, 0,
558 RADEON_GEM_DOMAIN_GTT|RADEON_GEM_DOMAIN_VRAM, 0, 0);
559 }
560 } else if (!t) {
561 /* workaround for old CS mechanism */
562 OUT_BATCH(r100->radeon.radeonScreen->texOffset[RADEON_LOCAL_TEX_HEAP]);
563 // OUT_BATCH(r100->radeon.radeonScreen);
564 } else {
565 OUT_BATCH(t->override_offset);
566 }
567
568 OUT_BATCH_TABLE((atom->cmd+4), 5);
569 END_BATCH();
570 }
571
572 static void tex_emit_cs(GLcontext *ctx, struct radeon_state_atom *atom)
573 {
574 r100ContextPtr r100 = R100_CONTEXT(ctx);
575 BATCH_LOCALS(&r100->radeon);
576 uint32_t dwords = atom->cmd_size;
577 int i = atom->idx;
578 radeonTexObj *t = r100->state.texture.unit[i].texobj;
579 radeon_mipmap_level *lvl;
580 int hastexture = 1;
581
582 if (!t)
583 hastexture = 0;
584 else {
585 if (!t->mt && !t->bo)
586 hastexture = 0;
587 }
588 dwords += 1;
589 if (hastexture)
590 dwords += 2;
591 else
592 dwords -= 2;
593 BEGIN_BATCH_NO_AUTOSTATE(dwords);
594
595 OUT_BATCH(CP_PACKET0(RADEON_PP_TXFILTER_0 + (24 * i), 1));
596 OUT_BATCH_TABLE((atom->cmd + 1), 2);
597
598 if (hastexture) {
599 OUT_BATCH(CP_PACKET0(RADEON_PP_TXOFFSET_0 + (24 * i), 0));
600 if (t->mt && !t->image_override) {
601 if ((ctx->Texture.Unit[i]._ReallyEnabled & TEXTURE_CUBE_BIT)) {
602 lvl = &t->mt->levels[0];
603 OUT_BATCH_RELOC(lvl->faces[5].offset, t->mt->bo, lvl->faces[5].offset,
604 RADEON_GEM_DOMAIN_GTT|RADEON_GEM_DOMAIN_VRAM, 0, 0);
605 } else {
606 OUT_BATCH_RELOC(t->tile_bits, t->mt->bo, 0,
607 RADEON_GEM_DOMAIN_GTT|RADEON_GEM_DOMAIN_VRAM, 0, 0);
608 }
609 } else {
610 if (t->bo)
611 OUT_BATCH_RELOC(t->tile_bits, t->bo, 0,
612 RADEON_GEM_DOMAIN_GTT|RADEON_GEM_DOMAIN_VRAM, 0, 0);
613 }
614 }
615
616 OUT_BATCH(CP_PACKET0(RADEON_PP_TXCBLEND_0 + (i * 24), 1));
617 OUT_BATCH_TABLE((atom->cmd+4), 2);
618 OUT_BATCH(CP_PACKET0(RADEON_PP_BORDER_COLOR_0 + (i * 4), 0));
619 OUT_BATCH((atom->cmd[TEX_PP_BORDER_COLOR]));
620 END_BATCH();
621 }
622
623 /* Initialize the context's hardware state.
624 */
625 void radeonInitState( r100ContextPtr rmesa )
626 {
627 GLcontext *ctx = rmesa->radeon.glCtx;
628 GLuint i;
629
630 rmesa->radeon.state.color.clear = 0x00000000;
631
632 switch ( ctx->Visual.depthBits ) {
633 case 16:
634 rmesa->radeon.state.depth.clear = 0x0000ffff;
635 rmesa->radeon.state.stencil.clear = 0x00000000;
636 break;
637 case 24:
638 rmesa->radeon.state.depth.clear = 0x00ffffff;
639 rmesa->radeon.state.stencil.clear = 0xffff0000;
640 break;
641 default:
642 break;
643 }
644
645 rmesa->radeon.Fallback = 0;
646
647
648 rmesa->radeon.hw.max_state_size = 0;
649
650 #define ALLOC_STATE_IDX( ATOM, CHK, SZ, NM, FLAG, IDX ) \
651 do { \
652 rmesa->hw.ATOM.cmd_size = SZ; \
653 rmesa->hw.ATOM.cmd = (GLuint *)CALLOC(SZ * sizeof(int)); \
654 rmesa->hw.ATOM.lastcmd = (GLuint *)CALLOC(SZ * sizeof(int)); \
655 rmesa->hw.ATOM.name = NM; \
656 rmesa->hw.ATOM.is_tcl = FLAG; \
657 rmesa->hw.ATOM.check = check_##CHK; \
658 rmesa->hw.ATOM.dirty = GL_TRUE; \
659 rmesa->hw.ATOM.idx = IDX; \
660 rmesa->radeon.hw.max_state_size += SZ * sizeof(int); \
661 } while (0)
662
663 #define ALLOC_STATE( ATOM, CHK, SZ, NM, FLAG ) \
664 ALLOC_STATE_IDX(ATOM, CHK, SZ, NM, FLAG, 0)
665
666 /* Allocate state buffers:
667 */
668 ALLOC_STATE( ctx, always, CTX_STATE_SIZE, "CTX/context", 0 );
669 if (rmesa->radeon.radeonScreen->kernel_mm)
670 rmesa->hw.ctx.emit = ctx_emit_cs;
671 else
672 rmesa->hw.ctx.emit = ctx_emit;
673 ALLOC_STATE( lin, always, LIN_STATE_SIZE, "LIN/line", 0 );
674 ALLOC_STATE( msk, always, MSK_STATE_SIZE, "MSK/mask", 0 );
675 ALLOC_STATE( vpt, always, VPT_STATE_SIZE, "VPT/viewport", 0 );
676 ALLOC_STATE( set, always, SET_STATE_SIZE, "SET/setup", 0 );
677 ALLOC_STATE( msc, always, MSC_STATE_SIZE, "MSC/misc", 0 );
678 ALLOC_STATE( zbs, always, ZBS_STATE_SIZE, "ZBS/zbias", 0 );
679 ALLOC_STATE( tcl, always, TCL_STATE_SIZE, "TCL/tcl", 1 );
680 ALLOC_STATE( mtl, tcl_lighting, MTL_STATE_SIZE, "MTL/material", 1 );
681 ALLOC_STATE( grd, always, GRD_STATE_SIZE, "GRD/guard-band", 1 );
682 ALLOC_STATE( fog, fog, FOG_STATE_SIZE, "FOG/fog", 1 );
683 ALLOC_STATE( glt, tcl_lighting, GLT_STATE_SIZE, "GLT/light-global", 1 );
684 ALLOC_STATE( eye, tcl_lighting, EYE_STATE_SIZE, "EYE/eye-vector", 1 );
685 ALLOC_STATE_IDX( tex[0], tex0, TEX_STATE_SIZE, "TEX/tex-0", 0, 0);
686 ALLOC_STATE_IDX( tex[1], tex1, TEX_STATE_SIZE, "TEX/tex-1", 0, 1);
687 ALLOC_STATE_IDX( tex[2], tex2, TEX_STATE_SIZE, "TEX/tex-2", 0, 2);
688
689 for (i = 0; i < 3; i++) {
690 if (rmesa->radeon.radeonScreen->kernel_mm)
691 rmesa->hw.tex[i].emit = tex_emit_cs;
692 else
693 rmesa->hw.tex[i].emit = tex_emit;
694 }
695 if (rmesa->radeon.radeonScreen->drmSupportsCubeMapsR100)
696 {
697 ALLOC_STATE_IDX( cube[0], cube0, CUBE_STATE_SIZE, "CUBE/cube-0", 0, 0 );
698 ALLOC_STATE_IDX( cube[1], cube1, CUBE_STATE_SIZE, "CUBE/cube-1", 0, 1 );
699 ALLOC_STATE_IDX( cube[2], cube2, CUBE_STATE_SIZE, "CUBE/cube-2", 0, 2 );
700 for (i = 0; i < 3; i++)
701 if (rmesa->radeon.radeonScreen->kernel_mm)
702 rmesa->hw.cube[i].emit = cube_emit_cs;
703 else
704 rmesa->hw.cube[i].emit = cube_emit;
705 }
706 else
707 {
708 ALLOC_STATE_IDX( cube[0], never, CUBE_STATE_SIZE, "CUBE/cube-0", 0, 0 );
709 ALLOC_STATE_IDX( cube[1], never, CUBE_STATE_SIZE, "CUBE/cube-1", 0, 1 );
710 ALLOC_STATE_IDX( cube[2], never, CUBE_STATE_SIZE, "CUBE/cube-2", 0, 2 );
711 }
712 ALLOC_STATE( mat[0], tcl, MAT_STATE_SIZE, "MAT/modelproject", 1 );
713 ALLOC_STATE( mat[1], tcl_eyespace_or_fog, MAT_STATE_SIZE, "MAT/modelview", 1 );
714 ALLOC_STATE( mat[2], tcl_eyespace_or_lighting, MAT_STATE_SIZE, "MAT/it-modelview", 1 );
715 ALLOC_STATE( mat[3], tcl_tex0, MAT_STATE_SIZE, "MAT/texmat0", 1 );
716 ALLOC_STATE( mat[4], tcl_tex1, MAT_STATE_SIZE, "MAT/texmat1", 1 );
717 ALLOC_STATE( mat[5], tcl_tex2, MAT_STATE_SIZE, "MAT/texmat2", 1 );
718 ALLOC_STATE( ucp[0], tcl_ucp0, UCP_STATE_SIZE, "UCP/userclip-0", 1 );
719 ALLOC_STATE( ucp[1], tcl_ucp1, UCP_STATE_SIZE, "UCP/userclip-1", 1 );
720 ALLOC_STATE( ucp[2], tcl_ucp2, UCP_STATE_SIZE, "UCP/userclip-2", 1 );
721 ALLOC_STATE( ucp[3], tcl_ucp3, UCP_STATE_SIZE, "UCP/userclip-3", 1 );
722 ALLOC_STATE( ucp[4], tcl_ucp4, UCP_STATE_SIZE, "UCP/userclip-4", 1 );
723 ALLOC_STATE( ucp[5], tcl_ucp5, UCP_STATE_SIZE, "UCP/userclip-5", 1 );
724 ALLOC_STATE( lit[0], tcl_lit0, LIT_STATE_SIZE, "LIT/light-0", 1 );
725 ALLOC_STATE( lit[1], tcl_lit1, LIT_STATE_SIZE, "LIT/light-1", 1 );
726 ALLOC_STATE( lit[2], tcl_lit2, LIT_STATE_SIZE, "LIT/light-2", 1 );
727 ALLOC_STATE( lit[3], tcl_lit3, LIT_STATE_SIZE, "LIT/light-3", 1 );
728 ALLOC_STATE( lit[4], tcl_lit4, LIT_STATE_SIZE, "LIT/light-4", 1 );
729 ALLOC_STATE( lit[5], tcl_lit5, LIT_STATE_SIZE, "LIT/light-5", 1 );
730 ALLOC_STATE( lit[6], tcl_lit6, LIT_STATE_SIZE, "LIT/light-6", 1 );
731 ALLOC_STATE( lit[7], tcl_lit7, LIT_STATE_SIZE, "LIT/light-7", 1 );
732 ALLOC_STATE_IDX( txr[0], txr0, TXR_STATE_SIZE, "TXR/txr-0", 0, 0 );
733 ALLOC_STATE_IDX( txr[1], txr1, TXR_STATE_SIZE, "TXR/txr-1", 0, 1 );
734 ALLOC_STATE_IDX( txr[2], txr2, TXR_STATE_SIZE, "TXR/txr-2", 0, 2 );
735
736 radeonSetUpAtomList( rmesa );
737
738 /* Fill in the packet headers:
739 */
740 rmesa->hw.ctx.cmd[CTX_CMD_0] = cmdpkt(rmesa, RADEON_EMIT_PP_MISC);
741 rmesa->hw.ctx.cmd[CTX_CMD_1] = cmdpkt(rmesa, RADEON_EMIT_PP_CNTL);
742 rmesa->hw.ctx.cmd[CTX_CMD_2] = cmdpkt(rmesa, RADEON_EMIT_RB3D_COLORPITCH);
743 rmesa->hw.lin.cmd[LIN_CMD_0] = cmdpkt(rmesa, RADEON_EMIT_RE_LINE_PATTERN);
744 rmesa->hw.lin.cmd[LIN_CMD_1] = cmdpkt(rmesa, RADEON_EMIT_SE_LINE_WIDTH);
745 rmesa->hw.msk.cmd[MSK_CMD_0] = cmdpkt(rmesa, RADEON_EMIT_RB3D_STENCILREFMASK);
746 rmesa->hw.vpt.cmd[VPT_CMD_0] = cmdpkt(rmesa, RADEON_EMIT_SE_VPORT_XSCALE);
747 rmesa->hw.set.cmd[SET_CMD_0] = cmdpkt(rmesa, RADEON_EMIT_SE_CNTL);
748 rmesa->hw.set.cmd[SET_CMD_1] = cmdpkt(rmesa, RADEON_EMIT_SE_CNTL_STATUS);
749 rmesa->hw.msc.cmd[MSC_CMD_0] = cmdpkt(rmesa, RADEON_EMIT_RE_MISC);
750 rmesa->hw.tex[0].cmd[TEX_CMD_0] = cmdpkt(rmesa, RADEON_EMIT_PP_TXFILTER_0);
751 rmesa->hw.tex[0].cmd[TEX_CMD_1] = cmdpkt(rmesa, RADEON_EMIT_PP_BORDER_COLOR_0);
752 rmesa->hw.tex[1].cmd[TEX_CMD_0] = cmdpkt(rmesa, RADEON_EMIT_PP_TXFILTER_1);
753 rmesa->hw.tex[1].cmd[TEX_CMD_1] = cmdpkt(rmesa, RADEON_EMIT_PP_BORDER_COLOR_1);
754 rmesa->hw.tex[2].cmd[TEX_CMD_0] = cmdpkt(rmesa, RADEON_EMIT_PP_TXFILTER_2);
755 rmesa->hw.tex[2].cmd[TEX_CMD_1] = cmdpkt(rmesa, RADEON_EMIT_PP_BORDER_COLOR_2);
756 rmesa->hw.cube[0].cmd[CUBE_CMD_0] = cmdpkt(rmesa, RADEON_EMIT_PP_CUBIC_FACES_0);
757 rmesa->hw.cube[0].cmd[CUBE_CMD_1] = cmdpkt(rmesa, RADEON_EMIT_PP_CUBIC_OFFSETS_T0);
758 rmesa->hw.cube[1].cmd[CUBE_CMD_0] = cmdpkt(rmesa, RADEON_EMIT_PP_CUBIC_FACES_1);
759 rmesa->hw.cube[1].cmd[CUBE_CMD_1] = cmdpkt(rmesa, RADEON_EMIT_PP_CUBIC_OFFSETS_T1);
760 rmesa->hw.cube[2].cmd[CUBE_CMD_0] = cmdpkt(rmesa, RADEON_EMIT_PP_CUBIC_FACES_2);
761 rmesa->hw.cube[2].cmd[CUBE_CMD_1] = cmdpkt(rmesa, RADEON_EMIT_PP_CUBIC_OFFSETS_T2);
762 rmesa->hw.zbs.cmd[ZBS_CMD_0] = cmdpkt(rmesa, RADEON_EMIT_SE_ZBIAS_FACTOR);
763 rmesa->hw.tcl.cmd[TCL_CMD_0] = cmdpkt(rmesa, RADEON_EMIT_SE_TCL_OUTPUT_VTX_FMT);
764 rmesa->hw.mtl.cmd[MTL_CMD_0] =
765 cmdpkt(rmesa, RADEON_EMIT_SE_TCL_MATERIAL_EMMISSIVE_RED);
766 rmesa->hw.txr[0].cmd[TXR_CMD_0] = cmdpkt(rmesa, RADEON_EMIT_PP_TEX_SIZE_0);
767 rmesa->hw.txr[1].cmd[TXR_CMD_0] = cmdpkt(rmesa, RADEON_EMIT_PP_TEX_SIZE_1);
768 rmesa->hw.txr[2].cmd[TXR_CMD_0] = cmdpkt(rmesa, RADEON_EMIT_PP_TEX_SIZE_2);
769 rmesa->hw.grd.cmd[GRD_CMD_0] =
770 cmdscl( RADEON_SS_VERT_GUARD_CLIP_ADJ_ADDR, 1, 4 );
771 rmesa->hw.fog.cmd[FOG_CMD_0] =
772 cmdvec( RADEON_VS_FOG_PARAM_ADDR, 1, 4 );
773 rmesa->hw.glt.cmd[GLT_CMD_0] =
774 cmdvec( RADEON_VS_GLOBAL_AMBIENT_ADDR, 1, 4 );
775 rmesa->hw.eye.cmd[EYE_CMD_0] =
776 cmdvec( RADEON_VS_EYE_VECTOR_ADDR, 1, 4 );
777
778 for (i = 0 ; i < 6; i++) {
779 rmesa->hw.mat[i].cmd[MAT_CMD_0] =
780 cmdvec( RADEON_VS_MATRIX_0_ADDR + i*4, 1, 16);
781 }
782
783 for (i = 0 ; i < 8; i++) {
784 rmesa->hw.lit[i].cmd[LIT_CMD_0] =
785 cmdvec( RADEON_VS_LIGHT_AMBIENT_ADDR + i, 8, 24 );
786 rmesa->hw.lit[i].cmd[LIT_CMD_1] =
787 cmdscl( RADEON_SS_LIGHT_DCD_ADDR + i, 8, 6 );
788 }
789
790 for (i = 0 ; i < 6; i++) {
791 rmesa->hw.ucp[i].cmd[UCP_CMD_0] =
792 cmdvec( RADEON_VS_UCP_ADDR + i, 1, 4 );
793 }
794
795 if (rmesa->radeon.radeonScreen->kernel_mm) {
796 rmesa->hw.grd.emit = scl_emit;
797 rmesa->hw.fog.emit = vec_emit;
798 rmesa->hw.glt.emit = vec_emit;
799 rmesa->hw.eye.emit = vec_emit;
800
801 for (i = 0; i <= 6; i++)
802 rmesa->hw.mat[i].emit = vec_emit;
803
804 for (i = 0; i < 8; i++)
805 rmesa->hw.lit[i].emit = lit_emit;
806
807 for (i = 0; i < 6; i++)
808 rmesa->hw.ucp[i].emit = vec_emit;
809 }
810
811 rmesa->last_ReallyEnabled = -1;
812
813 /* Initial Harware state:
814 */
815 rmesa->hw.ctx.cmd[CTX_PP_MISC] = (RADEON_ALPHA_TEST_PASS |
816 RADEON_CHROMA_FUNC_FAIL |
817 RADEON_CHROMA_KEY_NEAREST |
818 RADEON_SHADOW_FUNC_EQUAL |
819 RADEON_SHADOW_PASS_1 /*|
820 RADEON_RIGHT_HAND_CUBE_OGL */);
821
822 rmesa->hw.ctx.cmd[CTX_PP_FOG_COLOR] = (RADEON_FOG_VERTEX |
823 /* this bit unused for vertex fog */
824 RADEON_FOG_USE_DEPTH);
825
826 rmesa->hw.ctx.cmd[CTX_RE_SOLID_COLOR] = 0x00000000;
827
828 rmesa->hw.ctx.cmd[CTX_RB3D_BLENDCNTL] = (RADEON_COMB_FCN_ADD_CLAMP |
829 RADEON_SRC_BLEND_GL_ONE |
830 RADEON_DST_BLEND_GL_ZERO );
831
832 rmesa->hw.ctx.cmd[CTX_RB3D_ZSTENCILCNTL] = (RADEON_Z_TEST_LESS |
833 RADEON_STENCIL_TEST_ALWAYS |
834 RADEON_STENCIL_FAIL_KEEP |
835 RADEON_STENCIL_ZPASS_KEEP |
836 RADEON_STENCIL_ZFAIL_KEEP |
837 RADEON_Z_WRITE_ENABLE);
838
839 if (rmesa->using_hyperz) {
840 rmesa->hw.ctx.cmd[CTX_RB3D_ZSTENCILCNTL] |= RADEON_Z_COMPRESSION_ENABLE |
841 RADEON_Z_DECOMPRESSION_ENABLE;
842 if (rmesa->radeon.radeonScreen->chip_flags & RADEON_CHIPSET_TCL) {
843 /* works for q3, but slight rendering errors with glxgears ? */
844 /* rmesa->hw.ctx.cmd[CTX_RB3D_ZSTENCILCNTL] |= RADEON_Z_HIERARCHY_ENABLE;*/
845 /* need this otherwise get lots of lockups with q3 ??? */
846 rmesa->hw.ctx.cmd[CTX_RB3D_ZSTENCILCNTL] |= RADEON_FORCE_Z_DIRTY;
847 }
848 }
849
850 rmesa->hw.ctx.cmd[CTX_PP_CNTL] = (RADEON_SCISSOR_ENABLE |
851 RADEON_ANTI_ALIAS_NONE);
852
853 rmesa->hw.ctx.cmd[CTX_RB3D_CNTL] = (RADEON_PLANE_MASK_ENABLE |
854 RADEON_ZBLOCK16);
855
856 switch ( driQueryOptioni( &rmesa->radeon.optionCache, "dither_mode" ) ) {
857 case DRI_CONF_DITHER_XERRORDIFFRESET:
858 rmesa->hw.ctx.cmd[CTX_RB3D_CNTL] |= RADEON_DITHER_INIT;
859 break;
860 case DRI_CONF_DITHER_ORDERED:
861 rmesa->hw.ctx.cmd[CTX_RB3D_CNTL] |= RADEON_SCALE_DITHER_ENABLE;
862 break;
863 }
864 if ( driQueryOptioni( &rmesa->radeon.optionCache, "round_mode" ) ==
865 DRI_CONF_ROUND_ROUND )
866 rmesa->radeon.state.color.roundEnable = RADEON_ROUND_ENABLE;
867 else
868 rmesa->radeon.state.color.roundEnable = 0;
869 if ( driQueryOptioni (&rmesa->radeon.optionCache, "color_reduction" ) ==
870 DRI_CONF_COLOR_REDUCTION_DITHER )
871 rmesa->hw.ctx.cmd[CTX_RB3D_CNTL] |= RADEON_DITHER_ENABLE;
872 else
873 rmesa->hw.ctx.cmd[CTX_RB3D_CNTL] |= rmesa->radeon.state.color.roundEnable;
874
875
876 rmesa->hw.set.cmd[SET_SE_CNTL] = (RADEON_FFACE_CULL_CCW |
877 RADEON_BFACE_SOLID |
878 RADEON_FFACE_SOLID |
879 /* RADEON_BADVTX_CULL_DISABLE | */
880 RADEON_FLAT_SHADE_VTX_LAST |
881 RADEON_DIFFUSE_SHADE_GOURAUD |
882 RADEON_ALPHA_SHADE_GOURAUD |
883 RADEON_SPECULAR_SHADE_GOURAUD |
884 RADEON_FOG_SHADE_GOURAUD |
885 RADEON_VPORT_XY_XFORM_ENABLE |
886 RADEON_VPORT_Z_XFORM_ENABLE |
887 RADEON_VTX_PIX_CENTER_OGL |
888 RADEON_ROUND_MODE_TRUNC |
889 RADEON_ROUND_PREC_8TH_PIX);
890
891 rmesa->hw.set.cmd[SET_SE_CNTL_STATUS] =
892 #ifdef MESA_BIG_ENDIAN
893 RADEON_VC_32BIT_SWAP;
894 #else
895 RADEON_VC_NO_SWAP;
896 #endif
897
898 if (!(rmesa->radeon.radeonScreen->chip_flags & RADEON_CHIPSET_TCL)) {
899 rmesa->hw.set.cmd[SET_SE_CNTL_STATUS] |= RADEON_TCL_BYPASS;
900 }
901
902 rmesa->hw.set.cmd[SET_SE_COORDFMT] = (
903 RADEON_VTX_W0_IS_NOT_1_OVER_W0 |
904 RADEON_TEX1_W_ROUTING_USE_Q1);
905
906
907 rmesa->hw.lin.cmd[LIN_RE_LINE_PATTERN] = ((1 << 16) | 0xffff);
908
909 rmesa->hw.lin.cmd[LIN_RE_LINE_STATE] =
910 ((0 << RADEON_LINE_CURRENT_PTR_SHIFT) |
911 (1 << RADEON_LINE_CURRENT_COUNT_SHIFT));
912
913 rmesa->hw.lin.cmd[LIN_SE_LINE_WIDTH] = (1 << 4);
914
915 rmesa->hw.msk.cmd[MSK_RB3D_STENCILREFMASK] =
916 ((0x00 << RADEON_STENCIL_REF_SHIFT) |
917 (0xff << RADEON_STENCIL_MASK_SHIFT) |
918 (0xff << RADEON_STENCIL_WRITEMASK_SHIFT));
919
920 rmesa->hw.msk.cmd[MSK_RB3D_ROPCNTL] = RADEON_ROP_COPY;
921 rmesa->hw.msk.cmd[MSK_RB3D_PLANEMASK] = 0xffffffff;
922
923 rmesa->hw.msc.cmd[MSC_RE_MISC] =
924 ((0 << RADEON_STIPPLE_X_OFFSET_SHIFT) |
925 (0 << RADEON_STIPPLE_Y_OFFSET_SHIFT) |
926 RADEON_STIPPLE_BIG_BIT_ORDER);
927
928 rmesa->hw.vpt.cmd[VPT_SE_VPORT_XSCALE] = 0x00000000;
929 rmesa->hw.vpt.cmd[VPT_SE_VPORT_XOFFSET] = 0x00000000;
930 rmesa->hw.vpt.cmd[VPT_SE_VPORT_YSCALE] = 0x00000000;
931 rmesa->hw.vpt.cmd[VPT_SE_VPORT_YOFFSET] = 0x00000000;
932 rmesa->hw.vpt.cmd[VPT_SE_VPORT_ZSCALE] = 0x00000000;
933 rmesa->hw.vpt.cmd[VPT_SE_VPORT_ZOFFSET] = 0x00000000;
934
935 for ( i = 0 ; i < ctx->Const.MaxTextureUnits ; i++ ) {
936 rmesa->hw.tex[i].cmd[TEX_PP_TXFILTER] = RADEON_BORDER_MODE_OGL;
937 rmesa->hw.tex[i].cmd[TEX_PP_TXFORMAT] =
938 (RADEON_TXFORMAT_ENDIAN_NO_SWAP |
939 RADEON_TXFORMAT_PERSPECTIVE_ENABLE |
940 (i << 24) | /* This is one of RADEON_TXFORMAT_ST_ROUTE_STQ[012] */
941 (2 << RADEON_TXFORMAT_WIDTH_SHIFT) |
942 (2 << RADEON_TXFORMAT_HEIGHT_SHIFT));
943
944 /* Initialize the texture offset to the start of the card texture heap */
945 // rmesa->hw.tex[i].cmd[TEX_PP_TXOFFSET] =
946 // rmesa->radeon.radeonScreen->texOffset[RADEON_LOCAL_TEX_HEAP];
947
948 rmesa->hw.tex[i].cmd[TEX_PP_BORDER_COLOR] = 0;
949 rmesa->hw.tex[i].cmd[TEX_PP_TXCBLEND] =
950 (RADEON_COLOR_ARG_A_ZERO |
951 RADEON_COLOR_ARG_B_ZERO |
952 RADEON_COLOR_ARG_C_CURRENT_COLOR |
953 RADEON_BLEND_CTL_ADD |
954 RADEON_SCALE_1X |
955 RADEON_CLAMP_TX);
956 rmesa->hw.tex[i].cmd[TEX_PP_TXABLEND] =
957 (RADEON_ALPHA_ARG_A_ZERO |
958 RADEON_ALPHA_ARG_B_ZERO |
959 RADEON_ALPHA_ARG_C_CURRENT_ALPHA |
960 RADEON_BLEND_CTL_ADD |
961 RADEON_SCALE_1X |
962 RADEON_CLAMP_TX);
963 rmesa->hw.tex[i].cmd[TEX_PP_TFACTOR] = 0;
964
965 rmesa->hw.cube[i].cmd[CUBE_PP_CUBIC_FACES] = 0;
966 rmesa->hw.cube[i].cmd[CUBE_PP_CUBIC_OFFSET_0] =
967 rmesa->radeon.radeonScreen->texOffset[RADEON_LOCAL_TEX_HEAP];
968 rmesa->hw.cube[i].cmd[CUBE_PP_CUBIC_OFFSET_1] =
969 rmesa->radeon.radeonScreen->texOffset[RADEON_LOCAL_TEX_HEAP];
970 rmesa->hw.cube[i].cmd[CUBE_PP_CUBIC_OFFSET_2] =
971 rmesa->radeon.radeonScreen->texOffset[RADEON_LOCAL_TEX_HEAP];
972 rmesa->hw.cube[i].cmd[CUBE_PP_CUBIC_OFFSET_3] =
973 rmesa->radeon.radeonScreen->texOffset[RADEON_LOCAL_TEX_HEAP];
974 rmesa->hw.cube[i].cmd[CUBE_PP_CUBIC_OFFSET_4] =
975 rmesa->radeon.radeonScreen->texOffset[RADEON_LOCAL_TEX_HEAP];
976 }
977
978 /* Can only add ST1 at the time of doing some multitex but can keep
979 * it after that. Errors if DIFFUSE is missing.
980 */
981 rmesa->hw.tcl.cmd[TCL_OUTPUT_VTXFMT] =
982 (RADEON_TCL_VTX_Z0 |
983 RADEON_TCL_VTX_W0 |
984 RADEON_TCL_VTX_PK_DIFFUSE
985 ); /* need to keep this uptodate */
986
987 rmesa->hw.tcl.cmd[TCL_OUTPUT_VTXSEL] =
988 ( RADEON_TCL_COMPUTE_XYZW |
989 (RADEON_TCL_TEX_INPUT_TEX_0 << RADEON_TCL_TEX_0_OUTPUT_SHIFT) |
990 (RADEON_TCL_TEX_INPUT_TEX_1 << RADEON_TCL_TEX_1_OUTPUT_SHIFT) |
991 (RADEON_TCL_TEX_INPUT_TEX_2 << RADEON_TCL_TEX_2_OUTPUT_SHIFT));
992
993
994 /* XXX */
995 rmesa->hw.tcl.cmd[TCL_MATRIX_SELECT_0] =
996 ((MODEL << RADEON_MODELVIEW_0_SHIFT) |
997 (MODEL_IT << RADEON_IT_MODELVIEW_0_SHIFT));
998
999 rmesa->hw.tcl.cmd[TCL_MATRIX_SELECT_1] =
1000 ((MODEL_PROJ << RADEON_MODELPROJECT_0_SHIFT) |
1001 (TEXMAT_0 << RADEON_TEXMAT_0_SHIFT) |
1002 (TEXMAT_1 << RADEON_TEXMAT_1_SHIFT) |
1003 (TEXMAT_2 << RADEON_TEXMAT_2_SHIFT));
1004
1005 rmesa->hw.tcl.cmd[TCL_UCP_VERT_BLEND_CTL] =
1006 (RADEON_UCP_IN_CLIP_SPACE |
1007 RADEON_CULL_FRONT_IS_CCW);
1008
1009 rmesa->hw.tcl.cmd[TCL_TEXTURE_PROC_CTL] = 0;
1010
1011 rmesa->hw.tcl.cmd[TCL_LIGHT_MODEL_CTL] =
1012 (RADEON_SPECULAR_LIGHTS |
1013 RADEON_DIFFUSE_SPECULAR_COMBINE |
1014 RADEON_LOCAL_LIGHT_VEC_GL |
1015 (RADEON_LM_SOURCE_STATE_MULT << RADEON_EMISSIVE_SOURCE_SHIFT) |
1016 (RADEON_LM_SOURCE_STATE_MULT << RADEON_AMBIENT_SOURCE_SHIFT) |
1017 (RADEON_LM_SOURCE_STATE_MULT << RADEON_DIFFUSE_SOURCE_SHIFT) |
1018 (RADEON_LM_SOURCE_STATE_MULT << RADEON_SPECULAR_SOURCE_SHIFT));
1019
1020 for (i = 0 ; i < 8; i++) {
1021 struct gl_light *l = &ctx->Light.Light[i];
1022 GLenum p = GL_LIGHT0 + i;
1023 *(float *)&(rmesa->hw.lit[i].cmd[LIT_RANGE_CUTOFF]) = FLT_MAX;
1024
1025 ctx->Driver.Lightfv( ctx, p, GL_AMBIENT, l->Ambient );
1026 ctx->Driver.Lightfv( ctx, p, GL_DIFFUSE, l->Diffuse );
1027 ctx->Driver.Lightfv( ctx, p, GL_SPECULAR, l->Specular );
1028 ctx->Driver.Lightfv( ctx, p, GL_POSITION, NULL );
1029 ctx->Driver.Lightfv( ctx, p, GL_SPOT_DIRECTION, NULL );
1030 ctx->Driver.Lightfv( ctx, p, GL_SPOT_EXPONENT, &l->SpotExponent );
1031 ctx->Driver.Lightfv( ctx, p, GL_SPOT_CUTOFF, &l->SpotCutoff );
1032 ctx->Driver.Lightfv( ctx, p, GL_CONSTANT_ATTENUATION,
1033 &l->ConstantAttenuation );
1034 ctx->Driver.Lightfv( ctx, p, GL_LINEAR_ATTENUATION,
1035 &l->LinearAttenuation );
1036 ctx->Driver.Lightfv( ctx, p, GL_QUADRATIC_ATTENUATION,
1037 &l->QuadraticAttenuation );
1038 *(float *)&(rmesa->hw.lit[i].cmd[LIT_ATTEN_XXX]) = 0.0;
1039 }
1040
1041 ctx->Driver.LightModelfv( ctx, GL_LIGHT_MODEL_AMBIENT,
1042 ctx->Light.Model.Ambient );
1043
1044 TNL_CONTEXT(ctx)->Driver.NotifyMaterialChange( ctx );
1045
1046 for (i = 0 ; i < 6; i++) {
1047 ctx->Driver.ClipPlane( ctx, GL_CLIP_PLANE0 + i, NULL );
1048 }
1049
1050 ctx->Driver.Fogfv( ctx, GL_FOG_MODE, NULL );
1051 ctx->Driver.Fogfv( ctx, GL_FOG_DENSITY, &ctx->Fog.Density );
1052 ctx->Driver.Fogfv( ctx, GL_FOG_START, &ctx->Fog.Start );
1053 ctx->Driver.Fogfv( ctx, GL_FOG_END, &ctx->Fog.End );
1054 ctx->Driver.Fogfv( ctx, GL_FOG_COLOR, ctx->Fog.Color );
1055 ctx->Driver.Fogfv( ctx, GL_FOG_COORDINATE_SOURCE_EXT, NULL );
1056
1057 rmesa->hw.grd.cmd[GRD_VERT_GUARD_CLIP_ADJ] = IEEE_ONE;
1058 rmesa->hw.grd.cmd[GRD_VERT_GUARD_DISCARD_ADJ] = IEEE_ONE;
1059 rmesa->hw.grd.cmd[GRD_HORZ_GUARD_CLIP_ADJ] = IEEE_ONE;
1060 rmesa->hw.grd.cmd[GRD_HORZ_GUARD_DISCARD_ADJ] = IEEE_ONE;
1061
1062 rmesa->hw.eye.cmd[EYE_X] = 0;
1063 rmesa->hw.eye.cmd[EYE_Y] = 0;
1064 rmesa->hw.eye.cmd[EYE_Z] = IEEE_ONE;
1065 rmesa->hw.eye.cmd[EYE_RESCALE_FACTOR] = IEEE_ONE;
1066
1067 rmesa->radeon.hw.all_dirty = GL_TRUE;
1068
1069 rcommonInitCmdBuf(&rmesa->radeon);
1070 }