i915: Drop old checks for the settexoffset hack.
[mesa.git] / src / mesa / drivers / dri / i915 / i915_debug.c
1 /**************************************************************************
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
28 #include "main/imports.h"
29
30 #include "i915_reg.h"
31 #include "i915_context.h"
32 #include "i915_debug.h"
33
34 static GLboolean debug( struct debug_stream *stream, const char *name, GLuint len )
35 {
36 GLuint i;
37 GLuint *ptr = (GLuint *)(stream->ptr + stream->offset);
38
39 if (len == 0) {
40 printf("Error - zero length packet (0x%08x)\n", stream->ptr[0]);
41 assert(0);
42 return GL_FALSE;
43 }
44
45 if (stream->print_addresses)
46 printf("%08x: ", stream->offset);
47
48
49 printf("%s (%d dwords):\n", name, len);
50 for (i = 0; i < len; i++)
51 printf("\t0x%08x\n", ptr[i]);
52 printf("\n");
53
54 stream->offset += len * sizeof(GLuint);
55
56 return GL_TRUE;
57 }
58
59
60 static const char *get_prim_name( GLuint val )
61 {
62 switch (val & PRIM3D_MASK) {
63 case PRIM3D_TRILIST: return "TRILIST"; break;
64 case PRIM3D_TRISTRIP: return "TRISTRIP"; break;
65 case PRIM3D_TRISTRIP_RVRSE: return "TRISTRIP_RVRSE"; break;
66 case PRIM3D_TRIFAN: return "TRIFAN"; break;
67 case PRIM3D_POLY: return "POLY"; break;
68 case PRIM3D_LINELIST: return "LINELIST"; break;
69 case PRIM3D_LINESTRIP: return "LINESTRIP"; break;
70 case PRIM3D_RECTLIST: return "RECTLIST"; break;
71 case PRIM3D_POINTLIST: return "POINTLIST"; break;
72 case PRIM3D_DIB: return "DIB"; break;
73 case PRIM3D_CLEAR_RECT: return "CLEAR_RECT"; break;
74 case PRIM3D_ZONE_INIT: return "ZONE_INIT"; break;
75 default: return "????"; break;
76 }
77 }
78
79 static GLboolean debug_prim( struct debug_stream *stream, const char *name,
80 GLboolean dump_floats,
81 GLuint len )
82 {
83 GLuint *ptr = (GLuint *)(stream->ptr + stream->offset);
84 const char *prim = get_prim_name( ptr[0] );
85 GLuint i;
86
87
88
89 printf("%s %s (%d dwords):\n", name, prim, len);
90 printf("\t0x%08x\n", ptr[0]);
91 for (i = 1; i < len; i++) {
92 if (dump_floats)
93 printf("\t0x%08x // %f\n", ptr[i], *(GLfloat *)&ptr[i]);
94 else
95 printf("\t0x%08x\n", ptr[i]);
96 }
97
98
99 printf("\n");
100
101 stream->offset += len * sizeof(GLuint);
102
103 return GL_TRUE;
104 }
105
106
107
108
109 static GLboolean debug_program( struct debug_stream *stream, const char *name, GLuint len )
110 {
111 GLuint *ptr = (GLuint *)(stream->ptr + stream->offset);
112
113 if (len == 0) {
114 printf("Error - zero length packet (0x%08x)\n", stream->ptr[0]);
115 assert(0);
116 return GL_FALSE;
117 }
118
119 if (stream->print_addresses)
120 printf("%08x: ", stream->offset);
121
122 printf("%s (%d dwords):\n", name, len);
123 i915_disassemble_program( ptr, len );
124
125 stream->offset += len * sizeof(GLuint);
126 return GL_TRUE;
127 }
128
129
130 static GLboolean debug_chain( struct debug_stream *stream, const char *name, GLuint len )
131 {
132 GLuint *ptr = (GLuint *)(stream->ptr + stream->offset);
133 GLuint old_offset = stream->offset + len * sizeof(GLuint);
134 GLuint i;
135
136 printf("%s (%d dwords):\n", name, len);
137 for (i = 0; i < len; i++)
138 printf("\t0x%08x\n", ptr[i]);
139
140 stream->offset = ptr[1] & ~0x3;
141
142 if (stream->offset < old_offset)
143 printf("\n... skipping backwards from 0x%x --> 0x%x ...\n\n",
144 old_offset, stream->offset );
145 else
146 printf("\n... skipping from 0x%x --> 0x%x ...\n\n",
147 old_offset, stream->offset );
148
149
150 return GL_TRUE;
151 }
152
153
154 static GLboolean debug_variable_length_prim( struct debug_stream *stream )
155 {
156 GLuint *ptr = (GLuint *)(stream->ptr + stream->offset);
157 const char *prim = get_prim_name( ptr[0] );
158 GLuint i, len;
159
160 GLushort *idx = (GLushort *)(ptr+1);
161 for (i = 0; idx[i] != 0xffff; i++)
162 ;
163
164 len = 1+(i+2)/2;
165
166 printf("3DPRIM, %s variable length %d indicies (%d dwords):\n", prim, i, len);
167 for (i = 0; i < len; i++)
168 printf("\t0x%08x\n", ptr[i]);
169 printf("\n");
170
171 stream->offset += len * sizeof(GLuint);
172 return GL_TRUE;
173 }
174
175
176 #define BITS( dw, hi, lo, ... ) \
177 do { \
178 unsigned himask = 0xffffffffU >> (31 - (hi)); \
179 printf("\t\t "); \
180 printf(__VA_ARGS__); \
181 printf(": 0x%x\n", ((dw) & himask) >> (lo)); \
182 } while (0)
183
184 #define MBZ( dw, hi, lo) do { \
185 unsigned x = (dw) >> (lo); \
186 unsigned lomask = (1 << (lo)) - 1; \
187 unsigned himask; \
188 himask = (1UL << (hi)) - 1; \
189 assert ((x & himask & ~lomask) == 0); \
190 } while (0)
191
192 #define FLAG( dw, bit, ... ) \
193 do { \
194 if (((dw) >> (bit)) & 1) { \
195 printf("\t\t "); \
196 printf(__VA_ARGS__); \
197 printf("\n"); \
198 } \
199 } while (0)
200
201 static GLboolean debug_load_immediate( struct debug_stream *stream,
202 const char *name,
203 GLuint len )
204 {
205 GLuint *ptr = (GLuint *)(stream->ptr + stream->offset);
206 GLuint bits = (ptr[0] >> 4) & 0xff;
207 GLuint j = 0;
208
209 printf("%s (%d dwords, flags: %x):\n", name, len, bits);
210 printf("\t0x%08x\n", ptr[j++]);
211
212 if (bits & (1<<0)) {
213 printf("\t LIS0: 0x%08x\n", ptr[j]);
214 printf("\t vb address: 0x%08x\n", (ptr[j] & ~0x3));
215 BITS(ptr[j], 0, 0, "vb invalidate disable");
216 j++;
217 }
218 if (bits & (1<<1)) {
219 printf("\t LIS1: 0x%08x\n", ptr[j]);
220 BITS(ptr[j], 29, 24, "vb dword width");
221 BITS(ptr[j], 21, 16, "vb dword pitch");
222 BITS(ptr[j], 15, 0, "vb max index");
223 j++;
224 }
225 if (bits & (1<<2)) {
226 int i;
227 printf("\t LIS2: 0x%08x\n", ptr[j]);
228 for (i = 0; i < 8; i++) {
229 unsigned tc = (ptr[j] >> (i * 4)) & 0xf;
230 if (tc != 0xf)
231 BITS(tc, 3, 0, "tex coord %d", i);
232 }
233 j++;
234 }
235 if (bits & (1<<3)) {
236 printf("\t LIS3: 0x%08x\n", ptr[j]);
237 j++;
238 }
239 if (bits & (1<<4)) {
240 printf("\t LIS4: 0x%08x\n", ptr[j]);
241 BITS(ptr[j], 31, 23, "point width");
242 BITS(ptr[j], 22, 19, "line width");
243 FLAG(ptr[j], 18, "alpha flatshade");
244 FLAG(ptr[j], 17, "fog flatshade");
245 FLAG(ptr[j], 16, "spec flatshade");
246 FLAG(ptr[j], 15, "rgb flatshade");
247 BITS(ptr[j], 14, 13, "cull mode");
248 FLAG(ptr[j], 12, "vfmt: point width");
249 FLAG(ptr[j], 11, "vfmt: specular/fog");
250 FLAG(ptr[j], 10, "vfmt: rgba");
251 FLAG(ptr[j], 9, "vfmt: depth offset");
252 BITS(ptr[j], 8, 6, "vfmt: position (2==xyzw)");
253 FLAG(ptr[j], 5, "force dflt diffuse");
254 FLAG(ptr[j], 4, "force dflt specular");
255 FLAG(ptr[j], 3, "local depth offset enable");
256 FLAG(ptr[j], 2, "vfmt: fp32 fog coord");
257 FLAG(ptr[j], 1, "sprite point");
258 FLAG(ptr[j], 0, "antialiasing");
259 j++;
260 }
261 if (bits & (1<<5)) {
262 printf("\t LIS5: 0x%08x\n", ptr[j]);
263 BITS(ptr[j], 31, 28, "rgba write disables");
264 FLAG(ptr[j], 27, "force dflt point width");
265 FLAG(ptr[j], 26, "last pixel enable");
266 FLAG(ptr[j], 25, "global z offset enable");
267 FLAG(ptr[j], 24, "fog enable");
268 BITS(ptr[j], 23, 16, "stencil ref");
269 BITS(ptr[j], 15, 13, "stencil test");
270 BITS(ptr[j], 12, 10, "stencil fail op");
271 BITS(ptr[j], 9, 7, "stencil pass z fail op");
272 BITS(ptr[j], 6, 4, "stencil pass z pass op");
273 FLAG(ptr[j], 3, "stencil write enable");
274 FLAG(ptr[j], 2, "stencil test enable");
275 FLAG(ptr[j], 1, "color dither enable");
276 FLAG(ptr[j], 0, "logiop enable");
277 j++;
278 }
279 if (bits & (1<<6)) {
280 printf("\t LIS6: 0x%08x\n", ptr[j]);
281 FLAG(ptr[j], 31, "alpha test enable");
282 BITS(ptr[j], 30, 28, "alpha func");
283 BITS(ptr[j], 27, 20, "alpha ref");
284 FLAG(ptr[j], 19, "depth test enable");
285 BITS(ptr[j], 18, 16, "depth func");
286 FLAG(ptr[j], 15, "blend enable");
287 BITS(ptr[j], 14, 12, "blend func");
288 BITS(ptr[j], 11, 8, "blend src factor");
289 BITS(ptr[j], 7, 4, "blend dst factor");
290 FLAG(ptr[j], 3, "depth write enable");
291 FLAG(ptr[j], 2, "color write enable");
292 BITS(ptr[j], 1, 0, "provoking vertex");
293 j++;
294 }
295
296
297 printf("\n");
298
299 assert(j == len);
300
301 stream->offset += len * sizeof(GLuint);
302
303 return GL_TRUE;
304 }
305
306
307
308 static GLboolean debug_load_indirect( struct debug_stream *stream,
309 const char *name,
310 GLuint len )
311 {
312 GLuint *ptr = (GLuint *)(stream->ptr + stream->offset);
313 GLuint bits = (ptr[0] >> 8) & 0x3f;
314 GLuint i, j = 0;
315
316 printf("%s (%d dwords):\n", name, len);
317 printf("\t0x%08x\n", ptr[j++]);
318
319 for (i = 0; i < 6; i++) {
320 if (bits & (1<<i)) {
321 switch (1<<(8+i)) {
322 case LI0_STATE_STATIC_INDIRECT:
323 printf(" STATIC: 0x%08x | %x\n", ptr[j]&~3, ptr[j]&3); j++;
324 printf(" 0x%08x\n", ptr[j++]);
325 break;
326 case LI0_STATE_DYNAMIC_INDIRECT:
327 printf(" DYNAMIC: 0x%08x | %x\n", ptr[j]&~3, ptr[j]&3); j++;
328 break;
329 case LI0_STATE_SAMPLER:
330 printf(" SAMPLER: 0x%08x | %x\n", ptr[j]&~3, ptr[j]&3); j++;
331 printf(" 0x%08x\n", ptr[j++]);
332 break;
333 case LI0_STATE_MAP:
334 printf(" MAP: 0x%08x | %x\n", ptr[j]&~3, ptr[j]&3); j++;
335 printf(" 0x%08x\n", ptr[j++]);
336 break;
337 case LI0_STATE_PROGRAM:
338 printf(" PROGRAM: 0x%08x | %x\n", ptr[j]&~3, ptr[j]&3); j++;
339 printf(" 0x%08x\n", ptr[j++]);
340 break;
341 case LI0_STATE_CONSTANTS:
342 printf(" CONSTANTS: 0x%08x | %x\n", ptr[j]&~3, ptr[j]&3); j++;
343 printf(" 0x%08x\n", ptr[j++]);
344 break;
345 default:
346 assert(0);
347 break;
348 }
349 }
350 }
351
352 if (bits == 0) {
353 printf("\t DUMMY: 0x%08x\n", ptr[j++]);
354 }
355
356 printf("\n");
357
358
359 assert(j == len);
360
361 stream->offset += len * sizeof(GLuint);
362
363 return GL_TRUE;
364 }
365
366 static void BR13( struct debug_stream *stream,
367 GLuint val )
368 {
369 printf("\t0x%08x\n", val);
370 FLAG(val, 30, "clipping enable");
371 BITS(val, 25, 24, "color depth (3==32bpp)");
372 BITS(val, 23, 16, "raster op");
373 BITS(val, 15, 0, "dest pitch");
374 }
375
376
377 static void BR2223( struct debug_stream *stream,
378 GLuint val22, GLuint val23 )
379 {
380 union { GLuint val; short field[2]; } BR22, BR23;
381
382 BR22.val = val22;
383 BR23.val = val23;
384
385 printf("\t0x%08x\n", val22);
386 BITS(val22, 31, 16, "dest y1");
387 BITS(val22, 15, 0, "dest x1");
388
389 printf("\t0x%08x\n", val23);
390 BITS(val23, 31, 16, "dest y2");
391 BITS(val23, 15, 0, "dest x2");
392
393 /* The blit engine may produce unexpected results when these aren't met */
394 assert(BR22.field[0] < BR23.field[0]);
395 assert(BR22.field[1] < BR23.field[1]);
396 }
397
398 static void BR09( struct debug_stream *stream,
399 GLuint val )
400 {
401 printf("\t0x%08x -- dest address\n", val);
402 }
403
404 static void BR26( struct debug_stream *stream,
405 GLuint val )
406 {
407 printf("\t0x%08x\n", val);
408 BITS(val, 31, 16, "src y1");
409 BITS(val, 15, 0, "src x1");
410 }
411
412 static void BR11( struct debug_stream *stream,
413 GLuint val )
414 {
415 printf("\t0x%08x\n", val);
416 BITS(val, 15, 0, "src pitch");
417 }
418
419 static void BR12( struct debug_stream *stream,
420 GLuint val )
421 {
422 printf("\t0x%08x -- src address\n", val);
423 }
424
425 static void BR16( struct debug_stream *stream,
426 GLuint val )
427 {
428 printf("\t0x%08x -- color\n", val);
429 }
430
431 static GLboolean debug_copy_blit( struct debug_stream *stream,
432 const char *name,
433 GLuint len )
434 {
435 GLuint *ptr = (GLuint *)(stream->ptr + stream->offset);
436 int j = 0;
437
438 printf("%s (%d dwords):\n", name, len);
439 printf("\t0x%08x\n", ptr[j++]);
440
441 BR13(stream, ptr[j++]);
442 BR2223(stream, ptr[j], ptr[j+1]);
443 j += 2;
444 BR09(stream, ptr[j++]);
445 BR26(stream, ptr[j++]);
446 BR11(stream, ptr[j++]);
447 BR12(stream, ptr[j++]);
448
449 stream->offset += len * sizeof(GLuint);
450 assert(j == len);
451 return GL_TRUE;
452 }
453
454 static GLboolean debug_color_blit( struct debug_stream *stream,
455 const char *name,
456 GLuint len )
457 {
458 GLuint *ptr = (GLuint *)(stream->ptr + stream->offset);
459 int j = 0;
460
461 printf("%s (%d dwords):\n", name, len);
462 printf("\t0x%08x\n", ptr[j++]);
463
464 BR13(stream, ptr[j++]);
465 BR2223(stream, ptr[j], ptr[j+1]);
466 j += 2;
467 BR09(stream, ptr[j++]);
468 BR16(stream, ptr[j++]);
469
470 stream->offset += len * sizeof(GLuint);
471 assert(j == len);
472 return GL_TRUE;
473 }
474
475 static GLboolean debug_modes4( struct debug_stream *stream,
476 const char *name,
477 GLuint len )
478 {
479 GLuint *ptr = (GLuint *)(stream->ptr + stream->offset);
480 int j = 0;
481
482 printf("%s (%d dwords):\n", name, len);
483 printf("\t0x%08x\n", ptr[j]);
484 BITS(ptr[j], 21, 18, "logicop func");
485 FLAG(ptr[j], 17, "stencil test mask modify-enable");
486 FLAG(ptr[j], 16, "stencil write mask modify-enable");
487 BITS(ptr[j], 15, 8, "stencil test mask");
488 BITS(ptr[j], 7, 0, "stencil write mask");
489 j++;
490
491 stream->offset += len * sizeof(GLuint);
492 assert(j == len);
493 return GL_TRUE;
494 }
495
496 static GLboolean debug_map_state( struct debug_stream *stream,
497 const char *name,
498 GLuint len )
499 {
500 GLuint *ptr = (GLuint *)(stream->ptr + stream->offset);
501 int j = 0;
502
503 printf("%s (%d dwords):\n", name, len);
504 printf("\t0x%08x\n", ptr[j++]);
505
506 {
507 printf("\t0x%08x\n", ptr[j]);
508 BITS(ptr[j], 15, 0, "map mask");
509 j++;
510 }
511
512 while (j < len) {
513 {
514 printf("\t TMn.0: 0x%08x\n", ptr[j]);
515 printf("\t map address: 0x%08x\n", (ptr[j] & ~0x3));
516 FLAG(ptr[j], 1, "vertical line stride");
517 FLAG(ptr[j], 0, "vertical line stride offset");
518 j++;
519 }
520
521 {
522 printf("\t TMn.1: 0x%08x\n", ptr[j]);
523 BITS(ptr[j], 31, 21, "height");
524 BITS(ptr[j], 20, 10, "width");
525 BITS(ptr[j], 9, 7, "surface format");
526 BITS(ptr[j], 6, 3, "texel format");
527 FLAG(ptr[j], 2, "use fence regs");
528 FLAG(ptr[j], 1, "tiled surface");
529 FLAG(ptr[j], 0, "tile walk ymajor");
530 j++;
531 }
532 {
533 printf("\t TMn.2: 0x%08x\n", ptr[j]);
534 BITS(ptr[j], 31, 21, "dword pitch");
535 BITS(ptr[j], 20, 15, "cube face enables");
536 BITS(ptr[j], 14, 9, "max lod");
537 FLAG(ptr[j], 8, "mip layout right");
538 BITS(ptr[j], 7, 0, "depth");
539 j++;
540 }
541 }
542
543 stream->offset += len * sizeof(GLuint);
544 assert(j == len);
545 return GL_TRUE;
546 }
547
548 static GLboolean debug_sampler_state( struct debug_stream *stream,
549 const char *name,
550 GLuint len )
551 {
552 GLuint *ptr = (GLuint *)(stream->ptr + stream->offset);
553 int j = 0;
554
555 printf("%s (%d dwords):\n", name, len);
556 printf("\t0x%08x\n", ptr[j++]);
557
558 {
559 printf("\t0x%08x\n", ptr[j]);
560 BITS(ptr[j], 15, 0, "sampler mask");
561 j++;
562 }
563
564 while (j < len) {
565 {
566 printf("\t TSn.0: 0x%08x\n", ptr[j]);
567 FLAG(ptr[j], 31, "reverse gamma");
568 FLAG(ptr[j], 30, "planar to packed");
569 FLAG(ptr[j], 29, "yuv->rgb");
570 BITS(ptr[j], 28, 27, "chromakey index");
571 BITS(ptr[j], 26, 22, "base mip level");
572 BITS(ptr[j], 21, 20, "mip mode filter");
573 BITS(ptr[j], 19, 17, "mag mode filter");
574 BITS(ptr[j], 16, 14, "min mode filter");
575 BITS(ptr[j], 13, 5, "lod bias (s4.4)");
576 FLAG(ptr[j], 4, "shadow enable");
577 FLAG(ptr[j], 3, "max-aniso-4");
578 BITS(ptr[j], 2, 0, "shadow func");
579 j++;
580 }
581
582 {
583 printf("\t TSn.1: 0x%08x\n", ptr[j]);
584 BITS(ptr[j], 31, 24, "min lod");
585 MBZ( ptr[j], 23, 18 );
586 FLAG(ptr[j], 17, "kill pixel enable");
587 FLAG(ptr[j], 16, "keyed tex filter mode");
588 FLAG(ptr[j], 15, "chromakey enable");
589 BITS(ptr[j], 14, 12, "tcx wrap mode");
590 BITS(ptr[j], 11, 9, "tcy wrap mode");
591 BITS(ptr[j], 8, 6, "tcz wrap mode");
592 FLAG(ptr[j], 5, "normalized coords");
593 BITS(ptr[j], 4, 1, "map (surface) index");
594 FLAG(ptr[j], 0, "EAST deinterlacer enable");
595 j++;
596 }
597 {
598 printf("\t TSn.2: 0x%08x (default color)\n", ptr[j]);
599 j++;
600 }
601 }
602
603 stream->offset += len * sizeof(GLuint);
604 assert(j == len);
605 return GL_TRUE;
606 }
607
608 static GLboolean debug_dest_vars( struct debug_stream *stream,
609 const char *name,
610 GLuint len )
611 {
612 GLuint *ptr = (GLuint *)(stream->ptr + stream->offset);
613 int j = 0;
614
615 printf("%s (%d dwords):\n", name, len);
616 printf("\t0x%08x\n", ptr[j++]);
617
618 {
619 printf("\t0x%08x\n", ptr[j]);
620 FLAG(ptr[j], 31, "early classic ztest");
621 FLAG(ptr[j], 30, "opengl tex default color");
622 FLAG(ptr[j], 29, "bypass iz");
623 FLAG(ptr[j], 28, "lod preclamp");
624 BITS(ptr[j], 27, 26, "dither pattern");
625 FLAG(ptr[j], 25, "linear gamma blend");
626 FLAG(ptr[j], 24, "debug dither");
627 BITS(ptr[j], 23, 20, "dstorg x");
628 BITS(ptr[j], 19, 16, "dstorg y");
629 MBZ (ptr[j], 15, 15 );
630 BITS(ptr[j], 14, 12, "422 write select");
631 BITS(ptr[j], 11, 8, "cbuf format");
632 BITS(ptr[j], 3, 2, "zbuf format");
633 FLAG(ptr[j], 1, "vert line stride");
634 FLAG(ptr[j], 1, "vert line stride offset");
635 j++;
636 }
637
638 stream->offset += len * sizeof(GLuint);
639 assert(j == len);
640 return GL_TRUE;
641 }
642
643 static GLboolean debug_buf_info( struct debug_stream *stream,
644 const char *name,
645 GLuint len )
646 {
647 GLuint *ptr = (GLuint *)(stream->ptr + stream->offset);
648 int j = 0;
649
650 printf("%s (%d dwords):\n", name, len);
651 printf("\t0x%08x\n", ptr[j++]);
652
653 {
654 printf("\t0x%08x\n", ptr[j]);
655 BITS(ptr[j], 28, 28, "aux buffer id");
656 BITS(ptr[j], 27, 24, "buffer id (7=depth, 3=back)");
657 FLAG(ptr[j], 23, "use fence regs");
658 FLAG(ptr[j], 22, "tiled surface");
659 FLAG(ptr[j], 21, "tile walk ymajor");
660 MBZ (ptr[j], 20, 14);
661 BITS(ptr[j], 13, 2, "dword pitch");
662 MBZ (ptr[j], 2, 0);
663 j++;
664 }
665
666 printf("\t0x%08x -- buffer base address\n", ptr[j++]);
667
668 stream->offset += len * sizeof(GLuint);
669 assert(j == len);
670 return GL_TRUE;
671 }
672
673 static GLboolean i915_debug_packet( struct debug_stream *stream )
674 {
675 GLuint *ptr = (GLuint *)(stream->ptr + stream->offset);
676 GLuint cmd = *ptr;
677
678 switch (((cmd >> 29) & 0x7)) {
679 case 0x0:
680 switch ((cmd >> 23) & 0x3f) {
681 case 0x0:
682 return debug(stream, "MI_NOOP", 1);
683 case 0x3:
684 return debug(stream, "MI_WAIT_FOR_EVENT", 1);
685 case 0x4:
686 return debug(stream, "MI_FLUSH", 1);
687 case 0xA:
688 debug(stream, "MI_BATCH_BUFFER_END", 1);
689 return GL_FALSE;
690 case 0x22:
691 return debug(stream, "MI_LOAD_REGISTER_IMM", 3);
692 case 0x31:
693 return debug_chain(stream, "MI_BATCH_BUFFER_START", 2);
694 default:
695 break;
696 }
697 break;
698 case 0x1:
699 break;
700 case 0x2:
701 switch ((cmd >> 22) & 0xff) {
702 case 0x50:
703 return debug_color_blit(stream, "XY_COLOR_BLT", (cmd & 0xff) + 2);
704 case 0x53:
705 return debug_copy_blit(stream, "XY_SRC_COPY_BLT", (cmd & 0xff) + 2);
706 default:
707 return debug(stream, "blit command", (cmd & 0xff) + 2);
708 }
709 break;
710 case 0x3:
711 switch ((cmd >> 24) & 0x1f) {
712 case 0x6:
713 return debug(stream, "3DSTATE_ANTI_ALIASING", 1);
714 case 0x7:
715 return debug(stream, "3DSTATE_RASTERIZATION_RULES", 1);
716 case 0x8:
717 return debug(stream, "3DSTATE_BACKFACE_STENCIL_OPS", 2);
718 case 0x9:
719 return debug(stream, "3DSTATE_BACKFACE_STENCIL_MASKS", 1);
720 case 0xb:
721 return debug(stream, "3DSTATE_INDEPENDENT_ALPHA_BLEND", 1);
722 case 0xc:
723 return debug(stream, "3DSTATE_MODES5", 1);
724 case 0xd:
725 return debug_modes4(stream, "3DSTATE_MODES4", 1);
726 case 0x15:
727 return debug(stream, "3DSTATE_FOG_COLOR", 1);
728 case 0x16:
729 return debug(stream, "3DSTATE_COORD_SET_BINDINGS", 1);
730 case 0x1c:
731 /* 3DState16NP */
732 switch((cmd >> 19) & 0x1f) {
733 case 0x10:
734 return debug(stream, "3DSTATE_SCISSOR_ENABLE", 1);
735 case 0x11:
736 return debug(stream, "3DSTATE_DEPTH_SUBRECTANGLE_DISABLE", 1);
737 default:
738 break;
739 }
740 break;
741 case 0x1d:
742 /* 3DStateMW */
743 switch ((cmd >> 16) & 0xff) {
744 case 0x0:
745 return debug_map_state(stream, "3DSTATE_MAP_STATE", (cmd & 0x1f) + 2);
746 case 0x1:
747 return debug_sampler_state(stream, "3DSTATE_SAMPLER_STATE", (cmd & 0x1f) + 2);
748 case 0x4:
749 return debug_load_immediate(stream, "3DSTATE_LOAD_STATE_IMMEDIATE", (cmd & 0xf) + 2);
750 case 0x5:
751 return debug_program(stream, "3DSTATE_PIXEL_SHADER_PROGRAM", (cmd & 0x1ff) + 2);
752 case 0x6:
753 return debug(stream, "3DSTATE_PIXEL_SHADER_CONSTANTS", (cmd & 0xff) + 2);
754 case 0x7:
755 return debug_load_indirect(stream, "3DSTATE_LOAD_INDIRECT", (cmd & 0xff) + 2);
756 case 0x80:
757 return debug(stream, "3DSTATE_DRAWING_RECTANGLE", (cmd & 0xffff) + 2);
758 case 0x81:
759 return debug(stream, "3DSTATE_SCISSOR_RECTANGLE", (cmd & 0xffff) + 2);
760 case 0x83:
761 return debug(stream, "3DSTATE_SPAN_STIPPLE", (cmd & 0xffff) + 2);
762 case 0x85:
763 return debug_dest_vars(stream, "3DSTATE_DEST_BUFFER_VARS", (cmd & 0xffff) + 2);
764 case 0x88:
765 return debug(stream, "3DSTATE_CONSTANT_BLEND_COLOR", (cmd & 0xffff) + 2);
766 case 0x89:
767 return debug(stream, "3DSTATE_FOG_MODE", (cmd & 0xffff) + 2);
768 case 0x8e:
769 return debug_buf_info(stream, "3DSTATE_BUFFER_INFO", (cmd & 0xffff) + 2);
770 case 0x97:
771 return debug(stream, "3DSTATE_DEPTH_OFFSET_SCALE", (cmd & 0xffff) + 2);
772 case 0x98:
773 return debug(stream, "3DSTATE_DEFAULT_Z", (cmd & 0xffff) + 2);
774 case 0x99:
775 return debug(stream, "3DSTATE_DEFAULT_DIFFUSE", (cmd & 0xffff) + 2);
776 case 0x9a:
777 return debug(stream, "3DSTATE_DEFAULT_SPECULAR", (cmd & 0xffff) + 2);
778 case 0x9c:
779 return debug(stream, "3DSTATE_CLEAR_PARAMETERS", (cmd & 0xffff) + 2);
780 default:
781 assert(0);
782 return 0;
783 }
784 break;
785 case 0x1e:
786 if (cmd & (1 << 23))
787 return debug(stream, "???", (cmd & 0xffff) + 1);
788 else
789 return debug(stream, "", 1);
790 break;
791 case 0x1f:
792 if ((cmd & (1 << 23)) == 0)
793 return debug_prim(stream, "3DPRIM (inline)", 1, (cmd & 0x1ffff) + 2);
794 else if (cmd & (1 << 17))
795 {
796 if ((cmd & 0xffff) == 0)
797 return debug_variable_length_prim(stream);
798 else
799 return debug_prim(stream, "3DPRIM (indexed)", 0, (((cmd & 0xffff) + 1) / 2) + 1);
800 }
801 else
802 return debug_prim(stream, "3DPRIM (indirect sequential)", 0, 2);
803 break;
804 default:
805 return debug(stream, "", 0);
806 }
807 break;
808 default:
809 assert(0);
810 return 0;
811 }
812
813 assert(0);
814 return 0;
815 }
816
817
818
819 void
820 i915_dump_batchbuffer( GLuint *start,
821 GLuint *end )
822 {
823 struct debug_stream stream;
824 GLuint bytes = (end - start) * 4;
825 GLboolean done = GL_FALSE;
826
827 printf("\n\nBATCH: (%d)\n", bytes / 4);
828
829 stream.offset = 0;
830 stream.ptr = (char *)start;
831 stream.print_addresses = 0;
832
833 while (!done &&
834 stream.offset < bytes &&
835 stream.offset >= 0)
836 {
837 if (!i915_debug_packet( &stream ))
838 break;
839
840 assert(stream.offset <= bytes &&
841 stream.offset >= 0);
842 }
843
844 printf("END-BATCH\n\n\n");
845 }
846
847