(Stephane Marchesin, me) add hyperz support to radeon and r200 drivers. Only fast...
[mesa.git] / src / mesa / drivers / dri / i830 / i830_debug.c
1 /**************************************************************************
2
3 Copyright 2001 2d3d Inc., Delray Beach, FL
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 ATI, VA LINUX SYSTEMS AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
22 DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
23 OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
24 USE OR OTHER DEALINGS IN THE SOFTWARE.
25
26 **************************************************************************/
27
28 /* $XFree86: xc/lib/GL/mesa/src/drv/i830/i830_debug.c,v 1.3 2002/12/10 01:26:53 dawes Exp $ */
29
30 /*
31 * Author:
32 * Jeff Hartmann <jhartmann@2d3d.com>
33 */
34
35 #include "glheader.h"
36 #include "context.h"
37 #include "macros.h"
38 #include "enums.h"
39 #include "dd.h"
40
41 #include "mm.h"
42
43 #include "i830_screen.h"
44 #include "i830_dri.h"
45
46 #include "i830_context.h"
47 #include "i830_state.h"
48 #include "i830_tex.h"
49 #include "i830_tris.h"
50 #include "i830_ioctl.h"
51 #include "i830_debug.h"
52
53 #include "swrast/swrast.h"
54 #include "array_cache/acache.h"
55 #include "tnl/tnl.h"
56 #include "swrast_setup/swrast_setup.h"
57
58 #include "tnl/t_pipeline.h"
59
60
61 #define TINY_VERTEX_FORMAT (STATE3D_VERTEX_FORMAT_CMD | \
62 VRTX_TEX_COORD_COUNT(0) | \
63 VRTX_HAS_DIFFUSE | \
64 VRTX_HAS_XYZ)
65
66 #define NOTEX_VERTEX_FORMAT (STATE3D_VERTEX_FORMAT_CMD | \
67 VRTX_TEX_COORD_COUNT(0) | \
68 VRTX_HAS_DIFFUSE | \
69 VRTX_HAS_SPEC | \
70 VRTX_HAS_XYZW)
71
72 #define TEX0_VERTEX_FORMAT (STATE3D_VERTEX_FORMAT_CMD | \
73 VRTX_TEX_COORD_COUNT(1) | \
74 VRTX_HAS_DIFFUSE | \
75 VRTX_HAS_SPEC | \
76 VRTX_HAS_XYZW)
77
78 #define TEX1_VERTEX_FORMAT (STATE3D_VERTEX_FORMAT_CMD | \
79 VRTX_TEX_COORD_COUNT(2) | \
80 VRTX_HAS_DIFFUSE | \
81 VRTX_HAS_SPEC | \
82 VRTX_HAS_XYZW)
83
84 #define PROJ_VF2 (STATE3D_VERTEX_FORMAT_2_CMD | \
85 VRTX_TEX_SET_0_FMT(TEXCOORDFMT_3D) | \
86 VRTX_TEX_SET_1_FMT(TEXCOORDFMT_3D) | \
87 VRTX_TEX_SET_2_FMT(TEXCOORDFMT_3D) | \
88 VRTX_TEX_SET_3_FMT(TEXCOORDFMT_3D))
89
90 #define NON_PROJ_VF2 (STATE3D_VERTEX_FORMAT_2_CMD | \
91 VRTX_TEX_SET_0_FMT(TEXCOORDFMT_2D) | \
92 VRTX_TEX_SET_1_FMT(TEXCOORDFMT_2D) | \
93 VRTX_TEX_SET_2_FMT(TEXCOORDFMT_2D) | \
94 VRTX_TEX_SET_3_FMT(TEXCOORDFMT_2D))
95
96 void i830DumpContextState( i830ContextPtr imesa )
97 {
98 GLuint *Context = imesa->Setup;
99
100 fprintf(stderr, "%s\n", __FUNCTION__);
101 fprintf(stderr, "STATE1 : 0x%08x\n", Context[I830_CTXREG_STATE1]);
102 fprintf(stderr, "STATE2 : 0x%08x\n", Context[I830_CTXREG_STATE2]);
103 fprintf(stderr, "STATE3 : 0x%08x\n", Context[I830_CTXREG_STATE3]);
104 fprintf(stderr, "STATE4 : 0x%08x\n", Context[I830_CTXREG_STATE4]);
105 fprintf(stderr, "STATE5 : 0x%08x\n", Context[I830_CTXREG_STATE5]);
106 fprintf(stderr, "IALPHAB : 0x%08x\n", Context[I830_CTXREG_IALPHAB]);
107 fprintf(stderr, "STENCILTST : 0x%08x\n", Context[I830_CTXREG_STENCILTST]);
108 fprintf(stderr, "ENABLES_1 : 0x%08x\n", Context[I830_CTXREG_ENABLES_1]);
109 fprintf(stderr, "ENABLES_2 : 0x%08x\n", Context[I830_CTXREG_ENABLES_2]);
110 fprintf(stderr, "AA : 0x%08x\n", Context[I830_CTXREG_AA]);
111 fprintf(stderr, "FOGCOLOR : 0x%08x\n", Context[I830_CTXREG_FOGCOLOR]);
112 fprintf(stderr, "BCOLOR0 : 0x%08x\n", Context[I830_CTXREG_BLENDCOLR0]);
113 fprintf(stderr, "BCOLOR : 0x%08x\n", Context[I830_CTXREG_BLENDCOLR]);
114 fprintf(stderr, "VF : 0x%08x\n", Context[I830_CTXREG_VF]);
115 fprintf(stderr, "VF2 : 0x%08x\n", Context[I830_CTXREG_VF2]);
116 fprintf(stderr, "MCSB0 : 0x%08x\n", Context[I830_CTXREG_MCSB0]);
117 fprintf(stderr, "MCSB1 : 0x%08x\n", Context[I830_CTXREG_MCSB1]);
118 }
119
120 void i830DumpBufferState( i830ContextPtr imesa )
121 {
122 GLuint *Buffer = imesa->BufferSetup;
123
124 fprintf(stderr, "%s\n", __FUNCTION__);
125 fprintf(stderr, "CBUFADDR : 0x%08x\n", Buffer[I830_DESTREG_CBUFADDR]);
126 fprintf(stderr, "DBUFADDR : 0x%08x\n", Buffer[I830_DESTREG_DBUFADDR]);
127 fprintf(stderr, "DV0 : 0x%08x\n", Buffer[I830_DESTREG_DV0]);
128 fprintf(stderr, "DV1 : 0x%08x\n", Buffer[I830_DESTREG_DV1]);
129 fprintf(stderr, "SENABLE : 0x%08x\n", Buffer[I830_DESTREG_SENABLE]);
130 fprintf(stderr, "SR0 : 0x%08x\n", Buffer[I830_DESTREG_SR0]);
131 fprintf(stderr, "SR1 : 0x%08x\n", Buffer[I830_DESTREG_SR1]);
132 fprintf(stderr, "SR2 : 0x%08x\n", Buffer[I830_DESTREG_SR2]);
133 fprintf(stderr, "DR0 : 0x%08x\n", Buffer[I830_DESTREG_DR0]);
134 fprintf(stderr, "DR1 : 0x%08x\n", Buffer[I830_DESTREG_DR1]);
135 fprintf(stderr, "DR2 : 0x%08x\n", Buffer[I830_DESTREG_DR2]);
136 fprintf(stderr, "DR3 : 0x%08x\n", Buffer[I830_DESTREG_DR3]);
137 fprintf(stderr, "DR4 : 0x%08x\n", Buffer[I830_DESTREG_DR4]);
138 }
139
140 void i830DumpStippleState( i830ContextPtr imesa )
141 {
142 GLuint *Buffer = imesa->BufferSetup;
143
144 fprintf(stderr, "%s\n", __FUNCTION__);
145 fprintf(stderr, "ST1 : 0x%08x\n", Buffer[I830_STPREG_ST1]);
146 }
147
148 void i830DumpTextureState( i830ContextPtr imesa, int unit )
149 {
150 i830TextureObjectPtr t = imesa->CurrentTexObj[unit];
151
152 if(t) {
153 fprintf(stderr, "%s : unit %d\n", __FUNCTION__, unit);
154 fprintf(stderr, "TM0LI : 0x%08x\n", t->Setup[I830_TEXREG_TM0LI]);
155 fprintf(stderr, "TM0S0 : 0x%08x\n", t->Setup[I830_TEXREG_TM0S0]);
156 fprintf(stderr, "TM0S1 : 0x%08x\n", t->Setup[I830_TEXREG_TM0S1]);
157 fprintf(stderr, "TM0S2 : 0x%08x\n", t->Setup[I830_TEXREG_TM0S2]);
158 fprintf(stderr, "TM0S3 : 0x%08x\n", t->Setup[I830_TEXREG_TM0S3]);
159 fprintf(stderr, "TM0S4 : 0x%08x\n", t->Setup[I830_TEXREG_TM0S4]);
160 fprintf(stderr, "NOP0 : 0x%08x\n", t->Setup[I830_TEXREG_NOP0]);
161 fprintf(stderr, "NOP1 : 0x%08x\n", t->Setup[I830_TEXREG_NOP1]);
162 fprintf(stderr, "NOP2 : 0x%08x\n", t->Setup[I830_TEXREG_NOP2]);
163 fprintf(stderr, "MCS : 0x%08x\n", t->Setup[I830_TEXREG_MCS]);
164 }
165 }
166
167 void i830DumpTextureBlendState( i830ContextPtr imesa, int unit )
168 {
169 GLuint *TexBlend = imesa->TexBlend[unit];
170 GLuint length = imesa->TexBlendWordsUsed[unit];
171 int i;
172
173 fprintf(stderr, "%s : unit %d : length %d\n", __FUNCTION__, unit, length);
174 for(i = 0; i < length; i++) {
175 fprintf(stderr, "[%d] : 0x%08x\n", i, TexBlend[i]);
176 }
177 }
178
179 void i830VertexSanity( i830ContextPtr imesa, drmI830Vertex vertex )
180 {
181 I830SAREAPtr sarea = imesa->sarea;
182 char *prim_name;
183 int size = 0;
184 int vfmt_size = 0;
185 int hw_nr_vertex = 0;
186 int hw_start_vertex = 0;
187
188 /* Do a bunch of sanity checks on the vertices sent to the hardware */
189
190 size = vertex.used - 4;
191 if(imesa->vertex_size && (size % imesa->vertex_size) != 0) {
192 fprintf(stderr, "\n\nVertex size does not match imesa "
193 "internal state\n");
194 fprintf(stderr, "Buffer size : %d\n", size);
195 fprintf(stderr, "Vertex size : %d\n", imesa->vertex_size);
196 }
197
198 /* Check to see if the vertex format is good, and get its size */
199 if (sarea->ContextState[I830_CTXREG_VF] == TINY_VERTEX_FORMAT) {
200 vfmt_size = 16; /* 4 dwords */
201 } else if (sarea->ContextState[I830_CTXREG_VF] ==
202 NOTEX_VERTEX_FORMAT) {
203 vfmt_size = 24; /* 6 dwords */
204 } else if (sarea->ContextState[I830_CTXREG_VF] ==
205 TEX0_VERTEX_FORMAT) {
206 vfmt_size = 32; /* 8 dwords */
207 if (sarea->ContextState[I830_CTXREG_VF2] != NON_PROJ_VF2) {
208 fprintf(stderr, "\n\nTex 0 vertex format, but proj "
209 "texturing\n");
210 }
211 } else if(sarea->ContextState[I830_CTXREG_VF] ==
212 TEX1_VERTEX_FORMAT) {
213 if (sarea->ContextState[I830_CTXREG_VF2] == NON_PROJ_VF2)
214 vfmt_size = 40; /* 10 dwords */
215 else
216 vfmt_size = 48; /* 12 dwords */
217 } else {
218 fprintf(stderr, "\n\nUnknown vertex format : vf : %08x "
219 "vf2 : %08x\n",
220 sarea->ContextState[I830_CTXREG_VF],
221 sarea->ContextState[I830_CTXREG_VF2]);
222 }
223
224 if(vfmt_size && (size % vfmt_size) != 0) {
225 fprintf(stderr, "\n\nVertex size does not match hardware "
226 "internal state\n");
227 fprintf(stderr, "Buffer size : %d\n", size);
228 fprintf(stderr, "Vertex size : %d\n", vfmt_size);
229 }
230
231 switch(sarea->vertex_prim) {
232 case PRIM3D_POINTLIST:
233 hw_start_vertex = 0;
234 hw_nr_vertex = 1;
235 prim_name = "PointList";
236 break;
237
238 case PRIM3D_LINELIST:
239 hw_start_vertex = 0;
240 hw_nr_vertex = 2;
241 prim_name = "LineList";
242 break;
243
244 case PRIM3D_LINESTRIP:
245 hw_start_vertex = 2;
246 hw_nr_vertex = 1;
247 prim_name = "LineStrip";
248 break;
249
250 case PRIM3D_TRILIST:
251 hw_start_vertex = 0;
252 hw_nr_vertex = 3;
253 prim_name = "TriList";
254 break;
255
256 case PRIM3D_TRISTRIP:
257 hw_start_vertex = 3;
258 hw_nr_vertex = 1;
259 prim_name = "TriStrip";
260 break;
261
262 case PRIM3D_TRIFAN:
263 hw_start_vertex = 3;
264 hw_nr_vertex = 1;
265 prim_name = "TriFan";
266 break;
267
268 case PRIM3D_POLY:
269 hw_start_vertex = 3;
270 hw_nr_vertex = 1;
271 prim_name = "Polygons";
272 break;
273 default:
274 prim_name = "Unknown";
275 fprintf(stderr, "\n\nUnknown primitive type : %08x\n",
276 sarea->vertex_prim);
277 }
278
279 if (hw_nr_vertex && vfmt_size) {
280 int temp_size = size - (hw_start_vertex * vfmt_size);
281 int remaining = (temp_size % (hw_nr_vertex * vfmt_size));
282
283 if (remaining != 0) {
284 fprintf(stderr, "\n\nThis buffer contains an improper"
285 " multiple of vertices for this primitive : %s\n",
286 prim_name);
287 fprintf(stderr, "Number of vertices in buffer : %d\n",
288 size / vfmt_size);
289 fprintf(stderr, "temp_size : %d\n", temp_size);
290 fprintf(stderr, "remaining vertices : %d",
291 remaining / vfmt_size);
292 }
293 }
294 if (vfmt_size) {
295 fprintf(stderr, "\n\nPrim name (%s), vertices (%d)\n",
296 prim_name,
297 size / vfmt_size);
298 }
299 }
300
301 void i830EmitHwStateLockedDebug( i830ContextPtr imesa )
302 {
303 int i;
304
305 if ((imesa->dirty & I830_UPLOAD_TEX0_IMAGE) && imesa->CurrentTexObj[0]) {
306 i830UploadTexImagesLocked(imesa, imesa->CurrentTexObj[0]);
307 }
308
309 if ((imesa->dirty & I830_UPLOAD_TEX1_IMAGE) && imesa->CurrentTexObj[1]) {
310 i830UploadTexImagesLocked(imesa, imesa->CurrentTexObj[1]);
311 }
312
313 if (imesa->dirty & I830_UPLOAD_CTX) {
314 memcpy( imesa->sarea->ContextState,
315 imesa->Setup, sizeof(imesa->Setup) );
316 i830DumpContextState(imesa);
317 }
318
319 for(i = 0; i < I830_TEXTURE_COUNT; i++) {
320 if ((imesa->dirty & I830_UPLOAD_TEX_N(i)) && imesa->CurrentTexObj[i]) {
321 unsigned * TexState;
322
323 imesa->sarea->dirty |= I830_UPLOAD_TEX_N(i);
324
325 switch( i ) {
326 case 0:
327 case 1:
328 TexState = imesa->sarea->TexState[i];
329 break;
330
331 case 2:
332 TexState = imesa->sarea->TexState2;
333 break;
334
335 case 3:
336 TexState = imesa->sarea->TexState3;
337 break;
338 }
339
340 memcpy(TexState, imesa->CurrentTexObj[i]->Setup,
341 sizeof(imesa->sarea->TexState[i]));
342 i830DumpTextureState(imesa, i);
343 }
344 }
345 /* Need to figure out if texturing state, or enable changed. */
346
347 for(i = 0; i < I830_TEXBLEND_COUNT; i++) {
348 if (imesa->dirty & I830_UPLOAD_TEXBLEND_N(i)) {
349 unsigned * TexBlendState;
350 unsigned * words_used;
351
352 imesa->sarea->dirty |= I830_UPLOAD_TEXBLEND_N(i);
353
354 switch( i ) {
355 case 0:
356 case 1:
357 TexBlendState = imesa->sarea->TexBlendState[i];
358 words_used = & imesa->sarea->TexBlendStateWordsUsed[i];
359 break;
360
361 case 2:
362 TexBlendState = imesa->sarea->TexBlendState2;
363 words_used = & imesa->sarea->TexBlendStateWordsUsed2;
364 break;
365
366 case 3:
367 TexBlendState = imesa->sarea->TexBlendState3;
368 words_used = & imesa->sarea->TexBlendStateWordsUsed3;
369 break;
370 }
371
372 memcpy(TexBlendState, imesa->TexBlend[i],
373 imesa->TexBlendWordsUsed[i] * 4);
374 *words_used = imesa->TexBlendWordsUsed[i];
375
376 i830DumpTextureBlendState(imesa, i);
377 }
378 }
379
380 if (imesa->dirty & I830_UPLOAD_BUFFERS) {
381 memcpy( imesa->sarea->BufferState,imesa->BufferSetup,
382 sizeof(imesa->BufferSetup) );
383 i830DumpBufferState(imesa);
384 }
385
386 if (imesa->dirty & I830_UPLOAD_STIPPLE) {
387 fprintf(stderr, "UPLOAD_STIPPLE\n");
388 memcpy( imesa->sarea->StippleState,imesa->StippleSetup,
389 sizeof(imesa->StippleSetup) );
390 i830DumpStippleState(imesa);
391 }
392
393 if (imesa->dirty & I830_UPLOAD_TEX_PALETTE_SHARED) {
394 memcpy( imesa->sarea->Palette[0],imesa->palette,
395 sizeof(imesa->sarea->Palette[0]));
396 } else {
397 i830TextureObjectPtr p;
398 if (imesa->dirty & I830_UPLOAD_TEX_PALETTE_N(0)) {
399 p = imesa->CurrentTexObj[0];
400 memcpy( imesa->sarea->Palette[0],p->palette,
401 sizeof(imesa->sarea->Palette[0]));
402 }
403 if (imesa->dirty & I830_UPLOAD_TEX_PALETTE_N(1)) {
404 p = imesa->CurrentTexObj[1];
405 memcpy( imesa->sarea->Palette[1],
406 p->palette,
407 sizeof(imesa->sarea->Palette[1]));
408 }
409 }
410 imesa->sarea->dirty |= (imesa->dirty & ~(I830_UPLOAD_TEX_MASK |
411 I830_UPLOAD_TEXBLEND_MASK));
412
413 imesa->upload_cliprects = GL_TRUE;
414 imesa->dirty = 0;
415 }