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