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