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