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