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