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