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