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