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