blob: f7bb7ea44c9338ae4933d4551efb7d894142e8b3 [file] [log] [blame]
Keith Whitwell6b9e31f2006-11-01 12:03:11 +00001/**************************************************************************
2 *
3 * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
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
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 *
26 **************************************************************************/
27
Brian Paulecadb512008-09-18 15:17:05 -060028#include "main/imports.h"
Keith Whitwell4a789e42007-08-10 19:17:35 +010029
Keith Whitwell6b9e31f2006-11-01 12:03:11 +000030#include "i915_reg.h"
31#include "i915_context.h"
Keith Whitwell4a789e42007-08-10 19:17:35 +010032#include "i915_debug.h"
Keith Whitwell6b9e31f2006-11-01 12:03:11 +000033
Keith Whitwell6ea55d32007-08-11 13:48:19 +010034#define PRINTF( ... ) _mesa_printf( __VA_ARGS__ )
Keith Whitwell6b9e31f2006-11-01 12:03:11 +000035
Keith Whitwell4a789e42007-08-10 19:17:35 +010036static GLboolean debug( struct debug_stream *stream, const char *name, GLuint len )
Keith Whitwell6b9e31f2006-11-01 12:03:11 +000037{
Keith Whitwell4a789e42007-08-10 19:17:35 +010038 GLuint i;
39 GLuint *ptr = (GLuint *)(stream->ptr + stream->offset);
40
41 if (len == 0) {
Keith Whitwell6ea55d32007-08-11 13:48:19 +010042 PRINTF("Error - zero length packet (0x%08x)\n", stream->ptr[0]);
Keith Whitwell4a789e42007-08-10 19:17:35 +010043 assert(0);
44 return GL_FALSE;
45 }
46
47 if (stream->print_addresses)
Keith Whitwell6ea55d32007-08-11 13:48:19 +010048 PRINTF("%08x: ", stream->offset);
Keith Whitwell4a789e42007-08-10 19:17:35 +010049
50
Keith Whitwell6ea55d32007-08-11 13:48:19 +010051 PRINTF("%s (%d dwords):\n", name, len);
Keith Whitwell4a789e42007-08-10 19:17:35 +010052 for (i = 0; i < len; i++)
Keith Whitwell6ea55d32007-08-11 13:48:19 +010053 PRINTF("\t0x%08x\n", ptr[i]);
54 PRINTF("\n");
Keith Whitwell4a789e42007-08-10 19:17:35 +010055
56 stream->offset += len * sizeof(GLuint);
57
58 return GL_TRUE;
59}
60
61
62static const char *get_prim_name( GLuint val )
63{
64 switch (val & PRIM3D_MASK) {
65 case PRIM3D_TRILIST: return "TRILIST"; break;
66 case PRIM3D_TRISTRIP: return "TRISTRIP"; break;
67 case PRIM3D_TRISTRIP_RVRSE: return "TRISTRIP_RVRSE"; break;
68 case PRIM3D_TRIFAN: return "TRIFAN"; break;
69 case PRIM3D_POLY: return "POLY"; break;
70 case PRIM3D_LINELIST: return "LINELIST"; break;
71 case PRIM3D_LINESTRIP: return "LINESTRIP"; break;
72 case PRIM3D_RECTLIST: return "RECTLIST"; break;
73 case PRIM3D_POINTLIST: return "POINTLIST"; break;
74 case PRIM3D_DIB: return "DIB"; break;
75 case PRIM3D_CLEAR_RECT: return "CLEAR_RECT"; break;
76 case PRIM3D_ZONE_INIT: return "ZONE_INIT"; break;
77 default: return "????"; break;
78 }
79}
80
81static GLboolean debug_prim( struct debug_stream *stream, const char *name,
82 GLboolean dump_floats,
83 GLuint len )
84{
85 GLuint *ptr = (GLuint *)(stream->ptr + stream->offset);
86 const char *prim = get_prim_name( ptr[0] );
87 GLuint i;
88
89
90
Keith Whitwell6ea55d32007-08-11 13:48:19 +010091 PRINTF("%s %s (%d dwords):\n", name, prim, len);
92 PRINTF("\t0x%08x\n", ptr[0]);
Keith Whitwell4a789e42007-08-10 19:17:35 +010093 for (i = 1; i < len; i++) {
94 if (dump_floats)
Keith Whitwell6ea55d32007-08-11 13:48:19 +010095 PRINTF("\t0x%08x // %f\n", ptr[i], *(GLfloat *)&ptr[i]);
Keith Whitwell4a789e42007-08-10 19:17:35 +010096 else
Keith Whitwell6ea55d32007-08-11 13:48:19 +010097 PRINTF("\t0x%08x\n", ptr[i]);
Keith Whitwell4a789e42007-08-10 19:17:35 +010098 }
99
100
Keith Whitwell6ea55d32007-08-11 13:48:19 +0100101 PRINTF("\n");
Keith Whitwell4a789e42007-08-10 19:17:35 +0100102
103 stream->offset += len * sizeof(GLuint);
104
105 return GL_TRUE;
106}
107
108
109
110
111static GLboolean debug_program( struct debug_stream *stream, const char *name, GLuint len )
112{
113 GLuint *ptr = (GLuint *)(stream->ptr + stream->offset);
114
115 if (len == 0) {
Keith Whitwell6ea55d32007-08-11 13:48:19 +0100116 PRINTF("Error - zero length packet (0x%08x)\n", stream->ptr[0]);
Keith Whitwell4a789e42007-08-10 19:17:35 +0100117 assert(0);
118 return GL_FALSE;
119 }
120
121 if (stream->print_addresses)
Keith Whitwell6ea55d32007-08-11 13:48:19 +0100122 PRINTF("%08x: ", stream->offset);
Keith Whitwell4a789e42007-08-10 19:17:35 +0100123
Keith Whitwell6ea55d32007-08-11 13:48:19 +0100124 PRINTF("%s (%d dwords):\n", name, len);
Keith Whitwell4a789e42007-08-10 19:17:35 +0100125 i915_disassemble_program( ptr, len );
126
127 stream->offset += len * sizeof(GLuint);
128 return GL_TRUE;
129}
130
131
132static GLboolean debug_chain( struct debug_stream *stream, const char *name, GLuint len )
133{
134 GLuint *ptr = (GLuint *)(stream->ptr + stream->offset);
135 GLuint old_offset = stream->offset + len * sizeof(GLuint);
136 GLuint i;
137
Keith Whitwell6ea55d32007-08-11 13:48:19 +0100138 PRINTF("%s (%d dwords):\n", name, len);
Keith Whitwell4a789e42007-08-10 19:17:35 +0100139 for (i = 0; i < len; i++)
Keith Whitwell6ea55d32007-08-11 13:48:19 +0100140 PRINTF("\t0x%08x\n", ptr[i]);
Keith Whitwell4a789e42007-08-10 19:17:35 +0100141
142 stream->offset = ptr[1] & ~0x3;
143
144 if (stream->offset < old_offset)
Keith Whitwell6ea55d32007-08-11 13:48:19 +0100145 PRINTF("\n... skipping backwards from 0x%x --> 0x%x ...\n\n",
Keith Whitwell4a789e42007-08-10 19:17:35 +0100146 old_offset, stream->offset );
147 else
Keith Whitwell6ea55d32007-08-11 13:48:19 +0100148 PRINTF("\n... skipping from 0x%x --> 0x%x ...\n\n",
Keith Whitwell4a789e42007-08-10 19:17:35 +0100149 old_offset, stream->offset );
150
151
152 return GL_TRUE;
153}
154
155
156static GLboolean debug_variable_length_prim( struct debug_stream *stream )
157{
158 GLuint *ptr = (GLuint *)(stream->ptr + stream->offset);
159 const char *prim = get_prim_name( ptr[0] );
160 GLuint i, len;
161
162 GLushort *idx = (GLushort *)(ptr+1);
163 for (i = 0; idx[i] != 0xffff; i++)
164 ;
165
166 len = 1+(i+2)/2;
167
Keith Whitwell6ea55d32007-08-11 13:48:19 +0100168 PRINTF("3DPRIM, %s variable length %d indicies (%d dwords):\n", prim, i, len);
Keith Whitwell4a789e42007-08-10 19:17:35 +0100169 for (i = 0; i < len; i++)
Keith Whitwell6ea55d32007-08-11 13:48:19 +0100170 PRINTF("\t0x%08x\n", ptr[i]);
171 PRINTF("\n");
Keith Whitwell4a789e42007-08-10 19:17:35 +0100172
173 stream->offset += len * sizeof(GLuint);
174 return GL_TRUE;
175}
176
177
Keith Whitwellc60113c2007-08-11 13:40:22 +0100178#define BITS( dw, hi, lo, ... ) \
179do { \
Guillaume Melquiond87ccb952008-09-13 14:25:02 -0600180 unsigned himask = 0xffffffffU >> (31 - (hi)); \
Keith Whitwell6ea55d32007-08-11 13:48:19 +0100181 PRINTF("\t\t "); \
182 PRINTF(__VA_ARGS__); \
183 PRINTF(": 0x%x\n", ((dw) & himask) >> (lo)); \
Keith Whitwellc60113c2007-08-11 13:40:22 +0100184} while (0)
185
186#define MBZ( dw, hi, lo) do { \
187 unsigned x = (dw) >> (lo); \
188 unsigned lomask = (1 << (lo)) - 1; \
189 unsigned himask; \
190 himask = (1UL << (hi)) - 1; \
191 assert ((x & himask & ~lomask) == 0); \
192} while (0)
193
194#define FLAG( dw, bit, ... ) \
195do { \
196 if (((dw) >> (bit)) & 1) { \
Keith Whitwell6ea55d32007-08-11 13:48:19 +0100197 PRINTF("\t\t "); \
198 PRINTF(__VA_ARGS__); \
199 PRINTF("\n"); \
Keith Whitwellc60113c2007-08-11 13:40:22 +0100200 } \
201} while (0)
202
Keith Whitwell4a789e42007-08-10 19:17:35 +0100203static GLboolean debug_load_immediate( struct debug_stream *stream,
204 const char *name,
205 GLuint len )
206{
207 GLuint *ptr = (GLuint *)(stream->ptr + stream->offset);
208 GLuint bits = (ptr[0] >> 4) & 0xff;
Keith Whitwellc60113c2007-08-11 13:40:22 +0100209 GLuint j = 0;
Keith Whitwell4a789e42007-08-10 19:17:35 +0100210
Keith Whitwell6ea55d32007-08-11 13:48:19 +0100211 PRINTF("%s (%d dwords, flags: %x):\n", name, len, bits);
212 PRINTF("\t0x%08x\n", ptr[j++]);
Keith Whitwell4a789e42007-08-10 19:17:35 +0100213
Keith Whitwellc60113c2007-08-11 13:40:22 +0100214 if (bits & (1<<0)) {
Keith Whitwell6ea55d32007-08-11 13:48:19 +0100215 PRINTF("\t LIS0: 0x%08x\n", ptr[j]);
216 PRINTF("\t vb address: 0x%08x\n", (ptr[j] & ~0x3));
Keith Whitwellc60113c2007-08-11 13:40:22 +0100217 BITS(ptr[j], 0, 0, "vb invalidate disable");
218 j++;
Keith Whitwell4a789e42007-08-10 19:17:35 +0100219 }
Keith Whitwellc60113c2007-08-11 13:40:22 +0100220 if (bits & (1<<1)) {
Keith Whitwell6ea55d32007-08-11 13:48:19 +0100221 PRINTF("\t LIS1: 0x%08x\n", ptr[j]);
Keith Whitwellc60113c2007-08-11 13:40:22 +0100222 BITS(ptr[j], 29, 24, "vb dword width");
223 BITS(ptr[j], 21, 16, "vb dword pitch");
224 BITS(ptr[j], 15, 0, "vb max index");
225 j++;
226 }
227 if (bits & (1<<2)) {
228 int i;
Keith Whitwell6ea55d32007-08-11 13:48:19 +0100229 PRINTF("\t LIS2: 0x%08x\n", ptr[j]);
Keith Whitwellc60113c2007-08-11 13:40:22 +0100230 for (i = 0; i < 8; i++) {
231 unsigned tc = (ptr[j] >> (i * 4)) & 0xf;
Keith Whitwell6ea55d32007-08-11 13:48:19 +0100232 if (tc != 0xf)
Keith Whitwellc60113c2007-08-11 13:40:22 +0100233 BITS(tc, 3, 0, "tex coord %d", i);
234 }
235 j++;
236 }
237 if (bits & (1<<3)) {
Keith Whitwell6ea55d32007-08-11 13:48:19 +0100238 PRINTF("\t LIS3: 0x%08x\n", ptr[j]);
Keith Whitwellc60113c2007-08-11 13:40:22 +0100239 j++;
240 }
241 if (bits & (1<<4)) {
Keith Whitwell6ea55d32007-08-11 13:48:19 +0100242 PRINTF("\t LIS4: 0x%08x\n", ptr[j]);
Keith Whitwellc60113c2007-08-11 13:40:22 +0100243 BITS(ptr[j], 31, 23, "point width");
244 BITS(ptr[j], 22, 19, "line width");
245 FLAG(ptr[j], 18, "alpha flatshade");
246 FLAG(ptr[j], 17, "fog flatshade");
247 FLAG(ptr[j], 16, "spec flatshade");
248 FLAG(ptr[j], 15, "rgb flatshade");
249 BITS(ptr[j], 14, 13, "cull mode");
250 FLAG(ptr[j], 12, "vfmt: point width");
251 FLAG(ptr[j], 11, "vfmt: specular/fog");
252 FLAG(ptr[j], 10, "vfmt: rgba");
253 FLAG(ptr[j], 9, "vfmt: depth offset");
254 BITS(ptr[j], 8, 6, "vfmt: position (2==xyzw)");
255 FLAG(ptr[j], 5, "force dflt diffuse");
256 FLAG(ptr[j], 4, "force dflt specular");
257 FLAG(ptr[j], 3, "local depth offset enable");
258 FLAG(ptr[j], 2, "vfmt: fp32 fog coord");
259 FLAG(ptr[j], 1, "sprite point");
260 FLAG(ptr[j], 0, "antialiasing");
261 j++;
262 }
263 if (bits & (1<<5)) {
Keith Whitwell6ea55d32007-08-11 13:48:19 +0100264 PRINTF("\t LIS5: 0x%08x\n", ptr[j]);
Keith Whitwellc60113c2007-08-11 13:40:22 +0100265 BITS(ptr[j], 31, 28, "rgba write disables");
266 FLAG(ptr[j], 27, "force dflt point width");
267 FLAG(ptr[j], 26, "last pixel enable");
268 FLAG(ptr[j], 25, "global z offset enable");
269 FLAG(ptr[j], 24, "fog enable");
270 BITS(ptr[j], 23, 16, "stencil ref");
271 BITS(ptr[j], 15, 13, "stencil test");
272 BITS(ptr[j], 12, 10, "stencil fail op");
273 BITS(ptr[j], 9, 7, "stencil pass z fail op");
274 BITS(ptr[j], 6, 4, "stencil pass z pass op");
275 FLAG(ptr[j], 3, "stencil write enable");
276 FLAG(ptr[j], 2, "stencil test enable");
277 FLAG(ptr[j], 1, "color dither enable");
278 FLAG(ptr[j], 0, "logiop enable");
279 j++;
280 }
281 if (bits & (1<<6)) {
Keith Whitwell6ea55d32007-08-11 13:48:19 +0100282 PRINTF("\t LIS6: 0x%08x\n", ptr[j]);
Keith Whitwellc60113c2007-08-11 13:40:22 +0100283 FLAG(ptr[j], 31, "alpha test enable");
284 BITS(ptr[j], 30, 28, "alpha func");
285 BITS(ptr[j], 27, 20, "alpha ref");
286 FLAG(ptr[j], 19, "depth test enable");
287 BITS(ptr[j], 18, 16, "depth func");
288 FLAG(ptr[j], 15, "blend enable");
289 BITS(ptr[j], 14, 12, "blend func");
290 BITS(ptr[j], 11, 8, "blend src factor");
291 BITS(ptr[j], 7, 4, "blend dst factor");
292 FLAG(ptr[j], 3, "depth write enable");
293 FLAG(ptr[j], 2, "color write enable");
294 BITS(ptr[j], 1, 0, "provoking vertex");
295 j++;
296 }
297
Keith Whitwell4a789e42007-08-10 19:17:35 +0100298
Keith Whitwell6ea55d32007-08-11 13:48:19 +0100299 PRINTF("\n");
Keith Whitwell4a789e42007-08-10 19:17:35 +0100300
301 assert(j == len);
302
303 stream->offset += len * sizeof(GLuint);
304
305 return GL_TRUE;
306}
307
308
309
310static GLboolean debug_load_indirect( struct debug_stream *stream,
311 const char *name,
312 GLuint len )
313{
314 GLuint *ptr = (GLuint *)(stream->ptr + stream->offset);
315 GLuint bits = (ptr[0] >> 8) & 0x3f;
316 GLuint i, j = 0;
317
Keith Whitwell6ea55d32007-08-11 13:48:19 +0100318 PRINTF("%s (%d dwords):\n", name, len);
319 PRINTF("\t0x%08x\n", ptr[j++]);
Keith Whitwell4a789e42007-08-10 19:17:35 +0100320
321 for (i = 0; i < 6; i++) {
322 if (bits & (1<<i)) {
323 switch (1<<(8+i)) {
324 case LI0_STATE_STATIC_INDIRECT:
Keith Whitwell6ea55d32007-08-11 13:48:19 +0100325 PRINTF(" STATIC: 0x%08x | %x\n", ptr[j]&~3, ptr[j]&3); j++;
326 PRINTF(" 0x%08x\n", ptr[j++]);
Keith Whitwell4a789e42007-08-10 19:17:35 +0100327 break;
328 case LI0_STATE_DYNAMIC_INDIRECT:
Keith Whitwell6ea55d32007-08-11 13:48:19 +0100329 PRINTF(" DYNAMIC: 0x%08x | %x\n", ptr[j]&~3, ptr[j]&3); j++;
Keith Whitwell4a789e42007-08-10 19:17:35 +0100330 break;
331 case LI0_STATE_SAMPLER:
Keith Whitwell6ea55d32007-08-11 13:48:19 +0100332 PRINTF(" SAMPLER: 0x%08x | %x\n", ptr[j]&~3, ptr[j]&3); j++;
333 PRINTF(" 0x%08x\n", ptr[j++]);
Keith Whitwell4a789e42007-08-10 19:17:35 +0100334 break;
335 case LI0_STATE_MAP:
Keith Whitwell6ea55d32007-08-11 13:48:19 +0100336 PRINTF(" MAP: 0x%08x | %x\n", ptr[j]&~3, ptr[j]&3); j++;
337 PRINTF(" 0x%08x\n", ptr[j++]);
Keith Whitwell4a789e42007-08-10 19:17:35 +0100338 break;
339 case LI0_STATE_PROGRAM:
Keith Whitwell6ea55d32007-08-11 13:48:19 +0100340 PRINTF(" PROGRAM: 0x%08x | %x\n", ptr[j]&~3, ptr[j]&3); j++;
341 PRINTF(" 0x%08x\n", ptr[j++]);
Keith Whitwell4a789e42007-08-10 19:17:35 +0100342 break;
343 case LI0_STATE_CONSTANTS:
Keith Whitwell6ea55d32007-08-11 13:48:19 +0100344 PRINTF(" CONSTANTS: 0x%08x | %x\n", ptr[j]&~3, ptr[j]&3); j++;
345 PRINTF(" 0x%08x\n", ptr[j++]);
Keith Whitwell4a789e42007-08-10 19:17:35 +0100346 break;
347 default:
348 assert(0);
349 break;
350 }
351 }
352 }
353
354 if (bits == 0) {
Keith Whitwell6ea55d32007-08-11 13:48:19 +0100355 PRINTF("\t DUMMY: 0x%08x\n", ptr[j++]);
Keith Whitwell4a789e42007-08-10 19:17:35 +0100356 }
357
Keith Whitwell6ea55d32007-08-11 13:48:19 +0100358 PRINTF("\n");
Keith Whitwell4a789e42007-08-10 19:17:35 +0100359
360
361 assert(j == len);
362
363 stream->offset += len * sizeof(GLuint);
364
365 return GL_TRUE;
366}
Keith Whitwellc60113c2007-08-11 13:40:22 +0100367
368static void BR13( struct debug_stream *stream,
369 GLuint val )
370{
Keith Whitwell6ea55d32007-08-11 13:48:19 +0100371 PRINTF("\t0x%08x\n", val);
Keith Whitwellc60113c2007-08-11 13:40:22 +0100372 FLAG(val, 30, "clipping enable");
373 BITS(val, 25, 24, "color depth (3==32bpp)");
374 BITS(val, 23, 16, "raster op");
375 BITS(val, 15, 0, "dest pitch");
376}
377
378
Michel Dänzer950fff02007-10-18 18:30:15 +0200379static void BR2223( struct debug_stream *stream,
380 GLuint val22, GLuint val23 )
Keith Whitwellc60113c2007-08-11 13:40:22 +0100381{
Michel Dänzer950fff02007-10-18 18:30:15 +0200382 union { GLuint val; short field[2]; } BR22, BR23;
Keith Whitwellc60113c2007-08-11 13:40:22 +0100383
Michel Dänzer950fff02007-10-18 18:30:15 +0200384 BR22.val = val22;
385 BR23.val = val23;
386
387 PRINTF("\t0x%08x\n", val22);
388 BITS(val22, 31, 16, "dest y1");
389 BITS(val22, 15, 0, "dest x1");
390
391 PRINTF("\t0x%08x\n", val23);
392 BITS(val23, 31, 16, "dest y2");
393 BITS(val23, 15, 0, "dest x2");
394
395 /* The blit engine may produce unexpected results when these aren't met */
396 assert(BR22.field[0] < BR23.field[0]);
397 assert(BR22.field[1] < BR23.field[1]);
Keith Whitwellc60113c2007-08-11 13:40:22 +0100398}
399
400static void BR09( struct debug_stream *stream,
401 GLuint val )
402{
Keith Whitwell6ea55d32007-08-11 13:48:19 +0100403 PRINTF("\t0x%08x -- dest address\n", val);
Keith Whitwellc60113c2007-08-11 13:40:22 +0100404}
405
406static void BR26( struct debug_stream *stream,
407 GLuint val )
408{
Keith Whitwell6ea55d32007-08-11 13:48:19 +0100409 PRINTF("\t0x%08x\n", val);
Keith Whitwellc60113c2007-08-11 13:40:22 +0100410 BITS(val, 31, 16, "src y1");
411 BITS(val, 15, 0, "src x1");
412}
413
414static void BR11( struct debug_stream *stream,
415 GLuint val )
416{
Keith Whitwell6ea55d32007-08-11 13:48:19 +0100417 PRINTF("\t0x%08x\n", val);
Keith Whitwellc60113c2007-08-11 13:40:22 +0100418 BITS(val, 15, 0, "src pitch");
419}
420
421static void BR12( struct debug_stream *stream,
422 GLuint val )
423{
Keith Whitwell6ea55d32007-08-11 13:48:19 +0100424 PRINTF("\t0x%08x -- src address\n", val);
Keith Whitwellc60113c2007-08-11 13:40:22 +0100425}
426
427static void BR16( struct debug_stream *stream,
428 GLuint val )
429{
Keith Whitwell6ea55d32007-08-11 13:48:19 +0100430 PRINTF("\t0x%08x -- color\n", val);
Keith Whitwellc60113c2007-08-11 13:40:22 +0100431}
432
433static GLboolean debug_copy_blit( struct debug_stream *stream,
434 const char *name,
435 GLuint len )
436{
437 GLuint *ptr = (GLuint *)(stream->ptr + stream->offset);
438 int j = 0;
439
Keith Whitwell6ea55d32007-08-11 13:48:19 +0100440 PRINTF("%s (%d dwords):\n", name, len);
441 PRINTF("\t0x%08x\n", ptr[j++]);
Keith Whitwellc60113c2007-08-11 13:40:22 +0100442
443 BR13(stream, ptr[j++]);
Michel Dänzer950fff02007-10-18 18:30:15 +0200444 BR2223(stream, ptr[j], ptr[j+1]);
445 j += 2;
Keith Whitwellc60113c2007-08-11 13:40:22 +0100446 BR09(stream, ptr[j++]);
447 BR26(stream, ptr[j++]);
448 BR11(stream, ptr[j++]);
449 BR12(stream, ptr[j++]);
450
451 stream->offset += len * sizeof(GLuint);
452 assert(j == len);
453 return GL_TRUE;
454}
455
456static GLboolean debug_color_blit( struct debug_stream *stream,
457 const char *name,
458 GLuint len )
459{
460 GLuint *ptr = (GLuint *)(stream->ptr + stream->offset);
461 int j = 0;
462
Keith Whitwell6ea55d32007-08-11 13:48:19 +0100463 PRINTF("%s (%d dwords):\n", name, len);
464 PRINTF("\t0x%08x\n", ptr[j++]);
Keith Whitwellc60113c2007-08-11 13:40:22 +0100465
466 BR13(stream, ptr[j++]);
Michel Dänzer950fff02007-10-18 18:30:15 +0200467 BR2223(stream, ptr[j], ptr[j+1]);
468 j += 2;
Keith Whitwellc60113c2007-08-11 13:40:22 +0100469 BR09(stream, ptr[j++]);
470 BR16(stream, ptr[j++]);
471
472 stream->offset += len * sizeof(GLuint);
473 assert(j == len);
474 return GL_TRUE;
475}
476
477static GLboolean debug_modes4( struct debug_stream *stream,
478 const char *name,
479 GLuint len )
480{
481 GLuint *ptr = (GLuint *)(stream->ptr + stream->offset);
482 int j = 0;
483
Keith Whitwell6ea55d32007-08-11 13:48:19 +0100484 PRINTF("%s (%d dwords):\n", name, len);
485 PRINTF("\t0x%08x\n", ptr[j]);
Keith Whitwellc60113c2007-08-11 13:40:22 +0100486 BITS(ptr[j], 21, 18, "logicop func");
487 FLAG(ptr[j], 17, "stencil test mask modify-enable");
488 FLAG(ptr[j], 16, "stencil write mask modify-enable");
489 BITS(ptr[j], 15, 8, "stencil test mask");
490 BITS(ptr[j], 7, 0, "stencil write mask");
491 j++;
492
493 stream->offset += len * sizeof(GLuint);
494 assert(j == len);
495 return GL_TRUE;
496}
497
498static GLboolean debug_map_state( struct debug_stream *stream,
499 const char *name,
500 GLuint len )
501{
502 GLuint *ptr = (GLuint *)(stream->ptr + stream->offset);
503 int j = 0;
504
Keith Whitwell6ea55d32007-08-11 13:48:19 +0100505 PRINTF("%s (%d dwords):\n", name, len);
506 PRINTF("\t0x%08x\n", ptr[j++]);
Keith Whitwellc60113c2007-08-11 13:40:22 +0100507
508 {
Keith Whitwell6ea55d32007-08-11 13:48:19 +0100509 PRINTF("\t0x%08x\n", ptr[j]);
Keith Whitwellc60113c2007-08-11 13:40:22 +0100510 BITS(ptr[j], 15, 0, "map mask");
511 j++;
512 }
513
514 while (j < len) {
515 {
Keith Whitwell6ea55d32007-08-11 13:48:19 +0100516 PRINTF("\t TMn.0: 0x%08x\n", ptr[j]);
517 PRINTF("\t map address: 0x%08x\n", (ptr[j] & ~0x3));
Keith Whitwellc60113c2007-08-11 13:40:22 +0100518 FLAG(ptr[j], 1, "vertical line stride");
519 FLAG(ptr[j], 0, "vertical line stride offset");
520 j++;
521 }
522
523 {
Keith Whitwell6ea55d32007-08-11 13:48:19 +0100524 PRINTF("\t TMn.1: 0x%08x\n", ptr[j]);
Keith Whitwellc60113c2007-08-11 13:40:22 +0100525 BITS(ptr[j], 31, 21, "height");
526 BITS(ptr[j], 20, 10, "width");
527 BITS(ptr[j], 9, 7, "surface format");
528 BITS(ptr[j], 6, 3, "texel format");
529 FLAG(ptr[j], 2, "use fence regs");
530 FLAG(ptr[j], 1, "tiled surface");
531 FLAG(ptr[j], 0, "tile walk ymajor");
532 j++;
533 }
534 {
Keith Whitwell6ea55d32007-08-11 13:48:19 +0100535 PRINTF("\t TMn.2: 0x%08x\n", ptr[j]);
Keith Whitwellc60113c2007-08-11 13:40:22 +0100536 BITS(ptr[j], 31, 21, "dword pitch");
537 BITS(ptr[j], 20, 15, "cube face enables");
538 BITS(ptr[j], 14, 9, "max lod");
539 FLAG(ptr[j], 8, "mip layout right");
540 BITS(ptr[j], 7, 0, "depth");
541 j++;
542 }
543 }
544
545 stream->offset += len * sizeof(GLuint);
546 assert(j == len);
547 return GL_TRUE;
548}
549
550static GLboolean debug_sampler_state( struct debug_stream *stream,
551 const char *name,
552 GLuint len )
553{
554 GLuint *ptr = (GLuint *)(stream->ptr + stream->offset);
555 int j = 0;
556
Keith Whitwell6ea55d32007-08-11 13:48:19 +0100557 PRINTF("%s (%d dwords):\n", name, len);
558 PRINTF("\t0x%08x\n", ptr[j++]);
Keith Whitwellc60113c2007-08-11 13:40:22 +0100559
560 {
Keith Whitwell6ea55d32007-08-11 13:48:19 +0100561 PRINTF("\t0x%08x\n", ptr[j]);
Keith Whitwellc60113c2007-08-11 13:40:22 +0100562 BITS(ptr[j], 15, 0, "sampler mask");
563 j++;
564 }
565
566 while (j < len) {
567 {
Keith Whitwell6ea55d32007-08-11 13:48:19 +0100568 PRINTF("\t TSn.0: 0x%08x\n", ptr[j]);
Keith Whitwellc60113c2007-08-11 13:40:22 +0100569 FLAG(ptr[j], 31, "reverse gamma");
570 FLAG(ptr[j], 30, "planar to packed");
571 FLAG(ptr[j], 29, "yuv->rgb");
572 BITS(ptr[j], 28, 27, "chromakey index");
573 BITS(ptr[j], 26, 22, "base mip level");
574 BITS(ptr[j], 21, 20, "mip mode filter");
575 BITS(ptr[j], 19, 17, "mag mode filter");
576 BITS(ptr[j], 16, 14, "min mode filter");
577 BITS(ptr[j], 13, 5, "lod bias (s4.4)");
578 FLAG(ptr[j], 4, "shadow enable");
579 FLAG(ptr[j], 3, "max-aniso-4");
580 BITS(ptr[j], 2, 0, "shadow func");
581 j++;
582 }
583
584 {
Keith Whitwell6ea55d32007-08-11 13:48:19 +0100585 PRINTF("\t TSn.1: 0x%08x\n", ptr[j]);
Keith Whitwellc60113c2007-08-11 13:40:22 +0100586 BITS(ptr[j], 31, 24, "min lod");
587 MBZ( ptr[j], 23, 18 );
588 FLAG(ptr[j], 17, "kill pixel enable");
589 FLAG(ptr[j], 16, "keyed tex filter mode");
590 FLAG(ptr[j], 15, "chromakey enable");
591 BITS(ptr[j], 14, 12, "tcx wrap mode");
592 BITS(ptr[j], 11, 9, "tcy wrap mode");
593 BITS(ptr[j], 8, 6, "tcz wrap mode");
594 FLAG(ptr[j], 5, "normalized coords");
595 BITS(ptr[j], 4, 1, "map (surface) index");
596 FLAG(ptr[j], 0, "EAST deinterlacer enable");
597 j++;
598 }
599 {
Keith Whitwell6ea55d32007-08-11 13:48:19 +0100600 PRINTF("\t TSn.2: 0x%08x (default color)\n", ptr[j]);
Keith Whitwellc60113c2007-08-11 13:40:22 +0100601 j++;
602 }
603 }
604
605 stream->offset += len * sizeof(GLuint);
606 assert(j == len);
607 return GL_TRUE;
608}
609
610static GLboolean debug_dest_vars( struct debug_stream *stream,
611 const char *name,
612 GLuint len )
613{
614 GLuint *ptr = (GLuint *)(stream->ptr + stream->offset);
615 int j = 0;
616
Keith Whitwell6ea55d32007-08-11 13:48:19 +0100617 PRINTF("%s (%d dwords):\n", name, len);
618 PRINTF("\t0x%08x\n", ptr[j++]);
Keith Whitwellc60113c2007-08-11 13:40:22 +0100619
620 {
Keith Whitwell6ea55d32007-08-11 13:48:19 +0100621 PRINTF("\t0x%08x\n", ptr[j]);
Keith Whitwellc60113c2007-08-11 13:40:22 +0100622 FLAG(ptr[j], 31, "early classic ztest");
623 FLAG(ptr[j], 30, "opengl tex default color");
624 FLAG(ptr[j], 29, "bypass iz");
625 FLAG(ptr[j], 28, "lod preclamp");
626 BITS(ptr[j], 27, 26, "dither pattern");
627 FLAG(ptr[j], 25, "linear gamma blend");
628 FLAG(ptr[j], 24, "debug dither");
629 BITS(ptr[j], 23, 20, "dstorg x");
630 BITS(ptr[j], 19, 16, "dstorg y");
631 MBZ (ptr[j], 15, 15 );
632 BITS(ptr[j], 14, 12, "422 write select");
633 BITS(ptr[j], 11, 8, "cbuf format");
634 BITS(ptr[j], 3, 2, "zbuf format");
635 FLAG(ptr[j], 1, "vert line stride");
636 FLAG(ptr[j], 1, "vert line stride offset");
637 j++;
638 }
639
640 stream->offset += len * sizeof(GLuint);
641 assert(j == len);
642 return GL_TRUE;
643}
644
645static GLboolean debug_buf_info( struct debug_stream *stream,
646 const char *name,
647 GLuint len )
648{
649 GLuint *ptr = (GLuint *)(stream->ptr + stream->offset);
650 int j = 0;
651
Keith Whitwell6ea55d32007-08-11 13:48:19 +0100652 PRINTF("%s (%d dwords):\n", name, len);
653 PRINTF("\t0x%08x\n", ptr[j++]);
Keith Whitwellc60113c2007-08-11 13:40:22 +0100654
655 {
Keith Whitwell6ea55d32007-08-11 13:48:19 +0100656 PRINTF("\t0x%08x\n", ptr[j]);
Keith Whitwellc60113c2007-08-11 13:40:22 +0100657 BITS(ptr[j], 28, 28, "aux buffer id");
658 BITS(ptr[j], 27, 24, "buffer id (7=depth, 3=back)");
659 FLAG(ptr[j], 23, "use fence regs");
660 FLAG(ptr[j], 22, "tiled surface");
661 FLAG(ptr[j], 21, "tile walk ymajor");
662 MBZ (ptr[j], 20, 14);
663 BITS(ptr[j], 13, 2, "dword pitch");
664 MBZ (ptr[j], 2, 0);
665 j++;
666 }
667
Keith Whitwell6ea55d32007-08-11 13:48:19 +0100668 PRINTF("\t0x%08x -- buffer base address\n", ptr[j++]);
Keith Whitwellc60113c2007-08-11 13:40:22 +0100669
670 stream->offset += len * sizeof(GLuint);
671 assert(j == len);
672 return GL_TRUE;
673}
Keith Whitwell4a789e42007-08-10 19:17:35 +0100674
675static GLboolean i915_debug_packet( struct debug_stream *stream )
676{
677 GLuint *ptr = (GLuint *)(stream->ptr + stream->offset);
678 GLuint cmd = *ptr;
679
680 switch (((cmd >> 29) & 0x7)) {
681 case 0x0:
682 switch ((cmd >> 23) & 0x3f) {
683 case 0x0:
684 return debug(stream, "MI_NOOP", 1);
685 case 0x3:
686 return debug(stream, "MI_WAIT_FOR_EVENT", 1);
687 case 0x4:
688 return debug(stream, "MI_FLUSH", 1);
689 case 0xA:
690 debug(stream, "MI_BATCH_BUFFER_END", 1);
691 return GL_FALSE;
692 case 0x22:
693 return debug(stream, "MI_LOAD_REGISTER_IMM", 3);
694 case 0x31:
695 return debug_chain(stream, "MI_BATCH_BUFFER_START", 2);
Keith Whitwell6b9e31f2006-11-01 12:03:11 +0000696 default:
Keith Whitwell4a789e42007-08-10 19:17:35 +0100697 break;
Keith Whitwell6b9e31f2006-11-01 12:03:11 +0000698 }
699 break;
Keith Whitwell4a789e42007-08-10 19:17:35 +0100700 case 0x1:
701 break;
702 case 0x2:
703 switch ((cmd >> 22) & 0xff) {
704 case 0x50:
Keith Whitwellc60113c2007-08-11 13:40:22 +0100705 return debug_color_blit(stream, "XY_COLOR_BLT", (cmd & 0xff) + 2);
Keith Whitwell4a789e42007-08-10 19:17:35 +0100706 case 0x53:
Keith Whitwellc60113c2007-08-11 13:40:22 +0100707 return debug_copy_blit(stream, "XY_SRC_COPY_BLT", (cmd & 0xff) + 2);
Keith Whitwell4a789e42007-08-10 19:17:35 +0100708 default:
709 return debug(stream, "blit command", (cmd & 0xff) + 2);
Keith Whitwell6b9e31f2006-11-01 12:03:11 +0000710 }
711 break;
Keith Whitwell4a789e42007-08-10 19:17:35 +0100712 case 0x3:
713 switch ((cmd >> 24) & 0x1f) {
714 case 0x6:
715 return debug(stream, "3DSTATE_ANTI_ALIASING", 1);
716 case 0x7:
717 return debug(stream, "3DSTATE_RASTERIZATION_RULES", 1);
718 case 0x8:
719 return debug(stream, "3DSTATE_BACKFACE_STENCIL_OPS", 2);
720 case 0x9:
721 return debug(stream, "3DSTATE_BACKFACE_STENCIL_MASKS", 1);
722 case 0xb:
723 return debug(stream, "3DSTATE_INDEPENDENT_ALPHA_BLEND", 1);
724 case 0xc:
725 return debug(stream, "3DSTATE_MODES5", 1);
726 case 0xd:
Keith Whitwellc60113c2007-08-11 13:40:22 +0100727 return debug_modes4(stream, "3DSTATE_MODES4", 1);
Keith Whitwell4a789e42007-08-10 19:17:35 +0100728 case 0x15:
729 return debug(stream, "3DSTATE_FOG_COLOR", 1);
730 case 0x16:
731 return debug(stream, "3DSTATE_COORD_SET_BINDINGS", 1);
732 case 0x1c:
733 /* 3DState16NP */
734 switch((cmd >> 19) & 0x1f) {
735 case 0x10:
736 return debug(stream, "3DSTATE_SCISSOR_ENABLE", 1);
737 case 0x11:
738 return debug(stream, "3DSTATE_DEPTH_SUBRECTANGLE_DISABLE", 1);
739 default:
740 break;
741 }
742 break;
743 case 0x1d:
744 /* 3DStateMW */
745 switch ((cmd >> 16) & 0xff) {
746 case 0x0:
Keith Whitwellc60113c2007-08-11 13:40:22 +0100747 return debug_map_state(stream, "3DSTATE_MAP_STATE", (cmd & 0x1f) + 2);
Keith Whitwell4a789e42007-08-10 19:17:35 +0100748 case 0x1:
Keith Whitwellc60113c2007-08-11 13:40:22 +0100749 return debug_sampler_state(stream, "3DSTATE_SAMPLER_STATE", (cmd & 0x1f) + 2);
Keith Whitwell4a789e42007-08-10 19:17:35 +0100750 case 0x4:
751 return debug_load_immediate(stream, "3DSTATE_LOAD_STATE_IMMEDIATE", (cmd & 0xf) + 2);
752 case 0x5:
753 return debug_program(stream, "3DSTATE_PIXEL_SHADER_PROGRAM", (cmd & 0x1ff) + 2);
754 case 0x6:
755 return debug(stream, "3DSTATE_PIXEL_SHADER_CONSTANTS", (cmd & 0xff) + 2);
756 case 0x7:
757 return debug_load_indirect(stream, "3DSTATE_LOAD_INDIRECT", (cmd & 0xff) + 2);
758 case 0x80:
759 return debug(stream, "3DSTATE_DRAWING_RECTANGLE", (cmd & 0xffff) + 2);
760 case 0x81:
761 return debug(stream, "3DSTATE_SCISSOR_RECTANGLE", (cmd & 0xffff) + 2);
762 case 0x83:
763 return debug(stream, "3DSTATE_SPAN_STIPPLE", (cmd & 0xffff) + 2);
764 case 0x85:
Keith Whitwellc60113c2007-08-11 13:40:22 +0100765 return debug_dest_vars(stream, "3DSTATE_DEST_BUFFER_VARS", (cmd & 0xffff) + 2);
Keith Whitwell4a789e42007-08-10 19:17:35 +0100766 case 0x88:
767 return debug(stream, "3DSTATE_CONSTANT_BLEND_COLOR", (cmd & 0xffff) + 2);
768 case 0x89:
769 return debug(stream, "3DSTATE_FOG_MODE", (cmd & 0xffff) + 2);
770 case 0x8e:
Keith Whitwellc60113c2007-08-11 13:40:22 +0100771 return debug_buf_info(stream, "3DSTATE_BUFFER_INFO", (cmd & 0xffff) + 2);
Keith Whitwell4a789e42007-08-10 19:17:35 +0100772 case 0x97:
773 return debug(stream, "3DSTATE_DEPTH_OFFSET_SCALE", (cmd & 0xffff) + 2);
774 case 0x98:
775 return debug(stream, "3DSTATE_DEFAULT_Z", (cmd & 0xffff) + 2);
776 case 0x99:
777 return debug(stream, "3DSTATE_DEFAULT_DIFFUSE", (cmd & 0xffff) + 2);
778 case 0x9a:
779 return debug(stream, "3DSTATE_DEFAULT_SPECULAR", (cmd & 0xffff) + 2);
780 case 0x9c:
781 return debug(stream, "3DSTATE_CLEAR_PARAMETERS", (cmd & 0xffff) + 2);
782 default:
783 assert(0);
784 return 0;
785 }
786 break;
787 case 0x1e:
788 if (cmd & (1 << 23))
789 return debug(stream, "???", (cmd & 0xffff) + 1);
790 else
791 return debug(stream, "", 1);
792 break;
793 case 0x1f:
794 if ((cmd & (1 << 23)) == 0)
795 return debug_prim(stream, "3DPRIM (inline)", 1, (cmd & 0x1ffff) + 2);
796 else if (cmd & (1 << 17))
797 {
798 if ((cmd & 0xffff) == 0)
799 return debug_variable_length_prim(stream);
800 else
801 return debug_prim(stream, "3DPRIM (indexed)", 0, (((cmd & 0xffff) + 1) / 2) + 1);
802 }
803 else
804 return debug_prim(stream, "3DPRIM (indirect sequential)", 0, 2);
805 break;
806 default:
807 return debug(stream, "", 0);
808 }
Keith Whitwell6b9e31f2006-11-01 12:03:11 +0000809 default:
Keith Whitwell4a789e42007-08-10 19:17:35 +0100810 assert(0);
811 return 0;
Keith Whitwell6b9e31f2006-11-01 12:03:11 +0000812 }
813
Keith Whitwell4a789e42007-08-10 19:17:35 +0100814 assert(0);
815 return 0;
Keith Whitwell6b9e31f2006-11-01 12:03:11 +0000816}
817
Keith Whitwell6b9e31f2006-11-01 12:03:11 +0000818
819
820void
Keith Whitwell4a789e42007-08-10 19:17:35 +0100821i915_dump_batchbuffer( GLuint *start,
822 GLuint *end )
Keith Whitwell6b9e31f2006-11-01 12:03:11 +0000823{
Keith Whitwell4a789e42007-08-10 19:17:35 +0100824 struct debug_stream stream;
825 GLuint bytes = (end - start) * 4;
826 GLboolean done = GL_FALSE;
Keith Whitwell6b9e31f2006-11-01 12:03:11 +0000827
Keith Whitwell6ea55d32007-08-11 13:48:19 +0100828 PRINTF("\n\nBATCH: (%d)\n", bytes / 4);
Keith Whitwell6b9e31f2006-11-01 12:03:11 +0000829
Keith Whitwell4a789e42007-08-10 19:17:35 +0100830 stream.offset = 0;
831 stream.ptr = (char *)start;
832 stream.print_addresses = 0;
833
834 while (!done &&
835 stream.offset < bytes &&
836 stream.offset >= 0)
837 {
838 if (!i915_debug_packet( &stream ))
839 break;
840
841 assert(stream.offset <= bytes &&
842 stream.offset >= 0);
Keith Whitwell6b9e31f2006-11-01 12:03:11 +0000843 }
844
Keith Whitwell6ea55d32007-08-11 13:48:19 +0100845 PRINTF("END-BATCH\n\n\n");
Keith Whitwell6b9e31f2006-11-01 12:03:11 +0000846}
Keith Whitwell4a789e42007-08-10 19:17:35 +0100847
848