1 /* -*- c-basic-offset: 4 -*- */
3 * Copyright © 2007 Intel Corporation
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
25 * Eric Anholt <eric@anholt.net>
29 /** @file intel_decode.c
30 * This file contains code to print out batchbuffer contents in a
31 * human-readable format.
33 * The current version only supports i915 packets, and only pretty-prints a
34 * subset of them. The intention is for it to make just a best attempt to
35 * decode, but never crash in the process.
42 #include "intel_decode.h"
43 #include "intel_chipset.h"
45 #define BUFFER_FAIL(_count, _len, _name) do { \
46 fprintf(out, "Buffer size too small in %s (%d < %d)\n", \
47 (_name), (_count), (_len)); \
53 static uint32_t saved_s2
= 0, saved_s4
= 0;
54 static char saved_s2_set
= 0, saved_s4_set
= 0;
57 int_as_float(uint32_t intval
)
69 instr_out(uint32_t *data
, uint32_t hw_offset
, unsigned int index
,
74 fprintf(out
, "0x%08x: 0x%08x:%s ", hw_offset
+ index
* 4, data
[index
],
75 index
== 0 ? "" : " ");
77 vfprintf(out
, fmt
, va
);
83 decode_mi(uint32_t *data
, int count
, uint32_t hw_offset
, int *failures
)
93 { 0x08, 1, 1, "MI_ARB_ON_OFF" },
94 { 0x0a, 1, 1, "MI_BATCH_BUFFER_END" },
95 { 0x31, 2, 2, "MI_BATCH_BUFFER_START" },
96 { 0x14, 3, 3, "MI_DISPLAY_BUFFER_INFO" },
97 { 0x04, 1, 1, "MI_FLUSH" },
98 { 0x22, 3, 3, "MI_LOAD_REGISTER_IMM" },
99 { 0x13, 2, 2, "MI_LOAD_SCAN_LINES_EXCL" },
100 { 0x12, 2, 2, "MI_LOAD_SCAN_LINES_INCL" },
101 { 0x00, 1, 1, "MI_NOOP" },
102 { 0x11, 2, 2, "MI_OVERLAY_FLIP" },
103 { 0x07, 1, 1, "MI_REPORT_HEAD" },
104 { 0x18, 2, 2, "MI_SET_CONTEXT" },
105 { 0x20, 3, 4, "MI_STORE_DATA_IMM" },
106 { 0x21, 3, 4, "MI_STORE_DATA_INDEX" },
107 { 0x24, 3, 3, "MI_STORE_REGISTER_MEM" },
108 { 0x02, 1, 1, "MI_USER_INTERRUPT" },
109 { 0x03, 1, 1, "MI_WAIT_FOR_EVENT" },
113 for (opcode
= 0; opcode
< sizeof(opcodes_mi
) / sizeof(opcodes_mi
[0]);
115 if ((data
[0] & 0x1f800000) >> 23 == opcodes_mi
[opcode
].opcode
) {
116 unsigned int len
= 1, i
;
118 instr_out(data
, hw_offset
, 0, "%s\n", opcodes_mi
[opcode
].name
);
119 if (opcodes_mi
[opcode
].max_len
> 1) {
120 len
= (data
[0] & 0x000000ff) + 2;
121 if (len
< opcodes_mi
[opcode
].min_len
||
122 len
> opcodes_mi
[opcode
].max_len
)
124 fprintf(out
, "Bad length in %s\n",
125 opcodes_mi
[opcode
].name
);
129 for (i
= 1; i
< len
; i
++) {
131 BUFFER_FAIL(count
, len
, opcodes_mi
[opcode
].name
);
132 instr_out(data
, hw_offset
, i
, "dword %d\n", i
);
139 instr_out(data
, hw_offset
, 0, "MI UNKNOWN\n");
145 decode_2d(uint32_t *data
, int count
, uint32_t hw_offset
, int *failures
)
147 unsigned int opcode
, len
;
156 { 0x40, 5, 5, "COLOR_BLT" },
157 { 0x43, 6, 6, "SRC_COPY_BLT" },
158 { 0x01, 8, 8, "XY_SETUP_BLT" },
159 { 0x11, 9, 9, "XY_SETUP_MONO_PATTERN_SL_BLT" },
160 { 0x03, 3, 3, "XY_SETUP_CLIP_BLT" },
161 { 0x24, 2, 2, "XY_PIXEL_BLT" },
162 { 0x25, 3, 3, "XY_SCANLINES_BLT" },
163 { 0x26, 4, 4, "Y_TEXT_BLT" },
164 { 0x31, 5, 134, "XY_TEXT_IMMEDIATE_BLT" },
165 { 0x50, 6, 6, "XY_COLOR_BLT" },
166 { 0x51, 6, 6, "XY_PAT_BLT" },
167 { 0x76, 8, 8, "XY_PAT_CHROMA_BLT" },
168 { 0x72, 7, 135, "XY_PAT_BLT_IMMEDIATE" },
169 { 0x77, 9, 137, "XY_PAT_CHROMA_BLT_IMMEDIATE" },
170 { 0x52, 9, 9, "XY_MONO_PAT_BLT" },
171 { 0x59, 7, 7, "XY_MONO_PAT_FIXED_BLT" },
172 { 0x53, 8, 8, "XY_SRC_COPY_BLT" },
173 { 0x54, 8, 8, "XY_MONO_SRC_COPY_BLT" },
174 { 0x71, 9, 137, "XY_MONO_SRC_COPY_IMMEDIATE_BLT" },
175 { 0x55, 9, 9, "XY_FULL_BLT" },
176 { 0x55, 9, 137, "XY_FULL_IMMEDIATE_PATTERN_BLT" },
177 { 0x56, 9, 9, "XY_FULL_MONO_SRC_BLT" },
178 { 0x75, 10, 138, "XY_FULL_MONO_SRC_IMMEDIATE_PATTERN_BLT" },
179 { 0x57, 12, 12, "XY_FULL_MONO_PATTERN_BLT" },
180 { 0x58, 12, 12, "XY_FULL_MONO_PATTERN_MONO_SRC_BLT" },
183 switch ((data
[0] & 0x1fc00000) >> 22) {
185 instr_out(data
, hw_offset
, 0,
186 "XY_COLOR_BLT (rgb %sabled, alpha %sabled, dst tile %d)\n",
187 (data
[0] & (1 << 20)) ? "en" : "dis",
188 (data
[0] & (1 << 21)) ? "en" : "dis",
189 (data
[0] >> 11) & 1);
191 len
= (data
[0] & 0x000000ff) + 2;
193 fprintf(out
, "Bad count in XY_COLOR_BLT\n");
195 BUFFER_FAIL(count
, len
, "XY_COLOR_BLT");
197 switch ((data
[1] >> 24) & 0x3) {
212 instr_out(data
, hw_offset
, 1, "format %s, pitch %d, "
213 "clipping %sabled\n", format
,
214 (short)(data
[1] & 0xffff),
215 data
[1] & (1 << 30) ? "en" : "dis");
216 instr_out(data
, hw_offset
, 2, "(%d,%d)\n",
217 data
[2] & 0xffff, data
[2] >> 16);
218 instr_out(data
, hw_offset
, 3, "(%d,%d)\n",
219 data
[3] & 0xffff, data
[3] >> 16);
220 instr_out(data
, hw_offset
, 4, "offset 0x%08x\n", data
[4]);
221 instr_out(data
, hw_offset
, 5, "color\n");
224 instr_out(data
, hw_offset
, 0,
225 "XY_SRC_COPY_BLT (rgb %sabled, alpha %sabled, "
226 "src tile %d, dst tile %d)\n",
227 (data
[0] & (1 << 20)) ? "en" : "dis",
228 (data
[0] & (1 << 21)) ? "en" : "dis",
230 (data
[0] >> 11) & 1);
232 len
= (data
[0] & 0x000000ff) + 2;
234 fprintf(out
, "Bad count in XY_SRC_COPY_BLT\n");
236 BUFFER_FAIL(count
, len
, "XY_SRC_COPY_BLT");
238 switch ((data
[1] >> 24) & 0x3) {
253 instr_out(data
, hw_offset
, 1, "format %s, dst pitch %d, "
254 "clipping %sabled\n", format
,
255 (short)(data
[1] & 0xffff),
256 data
[1] & (1 << 30) ? "en" : "dis");
257 instr_out(data
, hw_offset
, 2, "dst (%d,%d)\n",
258 data
[2] & 0xffff, data
[2] >> 16);
259 instr_out(data
, hw_offset
, 3, "dst (%d,%d)\n",
260 data
[3] & 0xffff, data
[3] >> 16);
261 instr_out(data
, hw_offset
, 4, "dst offset 0x%08x\n", data
[4]);
262 instr_out(data
, hw_offset
, 5, "src (%d,%d)\n",
263 data
[5] & 0xffff, data
[5] >> 16);
264 instr_out(data
, hw_offset
, 6, "src pitch %d\n",
265 (short)(data
[6] & 0xffff));
266 instr_out(data
, hw_offset
, 7, "src offset 0x%08x\n", data
[7]);
270 for (opcode
= 0; opcode
< sizeof(opcodes_2d
) / sizeof(opcodes_2d
[0]);
272 if ((data
[0] & 0x1fc00000) >> 22 == opcodes_2d
[opcode
].opcode
) {
276 instr_out(data
, hw_offset
, 0, "%s\n", opcodes_2d
[opcode
].name
);
277 if (opcodes_2d
[opcode
].max_len
> 1) {
278 len
= (data
[0] & 0x000000ff) + 2;
279 if (len
< opcodes_2d
[opcode
].min_len
||
280 len
> opcodes_2d
[opcode
].max_len
)
282 fprintf(out
, "Bad count in %s\n", opcodes_2d
[opcode
].name
);
286 for (i
= 1; i
< len
; i
++) {
288 BUFFER_FAIL(count
, len
, opcodes_2d
[opcode
].name
);
289 instr_out(data
, hw_offset
, i
, "dword %d\n", i
);
296 instr_out(data
, hw_offset
, 0, "2D UNKNOWN\n");
302 decode_3d_1c(uint32_t *data
, int count
, uint32_t hw_offset
, int *failures
)
304 switch ((data
[0] & 0x00f80000) >> 19) {
306 instr_out(data
, hw_offset
, 0, "3DSTATE_DEPTH_SUBRECTANGLE_DISALBE\n");
309 instr_out(data
, hw_offset
, 0, "3DSTATE_SCISSOR_ENABLE\n");
313 instr_out(data
, hw_offset
, 0, "3D UNKNOWN\n");
319 decode_3d_1d(uint32_t *data
, int count
, uint32_t hw_offset
, int *failures
)
321 unsigned int len
, i
, c
, opcode
, word
, map
, sampler
, instr
;
328 } opcodes_3d_1d
[] = {
329 { 0x8e, 3, 3, "3DSTATE_BUFFER_INFO" },
330 { 0x86, 4, 4, "3DSTATE_CHROMA_KEY" },
331 { 0x9c, 1, 1, "3DSTATE_CLEAR_PARAMETERS" },
332 { 0x88, 2, 2, "3DSTATE_CONSTANT_BLEND_COLOR" },
333 { 0x99, 2, 2, "3DSTATE_DEFAULT_DIFFUSE" },
334 { 0x9a, 2, 2, "3DSTATE_DEFAULT_SPECULAR" },
335 { 0x98, 2, 2, "3DSTATE_DEFAULT_Z" },
336 { 0x97, 2, 2, "3DSTATE_DEPTH_OFFSET_SCALE" },
337 { 0x85, 2, 2, "3DSTATE_DEST_BUFFER_VARIABLES" },
338 { 0x80, 5, 5, "3DSTATE_DRAWING_RECTANGLE" },
339 { 0x8e, 3, 3, "3DSTATE_BUFFER_INFO" },
340 { 0x9d, 65, 65, "3DSTATE_FILTER_COEFFICIENTS_4X4" },
341 { 0x9e, 4, 4, "3DSTATE_MONO_FILTER" },
342 { 0x89, 4, 4, "3DSTATE_FOG_MODE" },
343 { 0x8f, 2, 16, "3DSTATE_MAP_PALLETE_LOAD_32" },
344 { 0x81, 3, 3, "3DSTATE_SCISSOR_RECTANGLE" },
345 { 0x83, 2, 2, "3DSTATE_SPAN_STIPPLE" },
348 switch ((data
[0] & 0x00ff0000) >> 16) {
350 /* This instruction is unusual. A 0 length means just 1 DWORD instead of
351 * 2. The 0 length is specified in one place to be unsupported, but
352 * stated to be required in another, and 0 length LOAD_INDIRECTs appear
353 * to cause no harm at least.
355 instr_out(data
, hw_offset
, 0, "3DSTATE_LOAD_INDIRECT\n");
356 len
= (data
[0] & 0x000000ff) + 1;
358 if (data
[0] & (0x01 << 8)) {
360 BUFFER_FAIL(count
, len
, "3DSTATE_LOAD_INDIRECT");
361 instr_out(data
, hw_offset
, i
++, "SIS.0\n");
362 instr_out(data
, hw_offset
, i
++, "SIS.1\n");
364 if (data
[0] & (0x02 << 8)) {
366 BUFFER_FAIL(count
, len
, "3DSTATE_LOAD_INDIRECT");
367 instr_out(data
, hw_offset
, i
++, "DIS.0\n");
369 if (data
[0] & (0x04 << 8)) {
371 BUFFER_FAIL(count
, len
, "3DSTATE_LOAD_INDIRECT");
372 instr_out(data
, hw_offset
, i
++, "SSB.0\n");
373 instr_out(data
, hw_offset
, i
++, "SSB.1\n");
375 if (data
[0] & (0x08 << 8)) {
377 BUFFER_FAIL(count
, len
, "3DSTATE_LOAD_INDIRECT");
378 instr_out(data
, hw_offset
, i
++, "MSB.0\n");
379 instr_out(data
, hw_offset
, i
++, "MSB.1\n");
381 if (data
[0] & (0x10 << 8)) {
383 BUFFER_FAIL(count
, len
, "3DSTATE_LOAD_INDIRECT");
384 instr_out(data
, hw_offset
, i
++, "PSP.0\n");
385 instr_out(data
, hw_offset
, i
++, "PSP.1\n");
387 if (data
[0] & (0x20 << 8)) {
389 BUFFER_FAIL(count
, len
, "3DSTATE_LOAD_INDIRECT");
390 instr_out(data
, hw_offset
, i
++, "PSC.0\n");
391 instr_out(data
, hw_offset
, i
++, "PSC.1\n");
394 fprintf(out
, "Bad count in 3DSTATE_LOAD_INDIRECT\n");
400 instr_out(data
, hw_offset
, 0, "3DSTATE_LOAD_STATE_IMMEDIATE_1\n");
401 len
= (data
[0] & 0x0000000f) + 2;
403 for (word
= 0; word
<= 7; word
++) {
404 if (data
[0] & (1 << (4 + word
))) {
406 BUFFER_FAIL(count
, len
, "3DSTATE_LOAD_STATE_IMMEDIATE_1");
408 /* save vertex state for decode */
418 instr_out(data
, hw_offset
, i
++, "S%d\n", word
);
422 fprintf(out
, "Bad count in 3DSTATE_LOAD_INDIRECT\n");
427 instr_out(data
, hw_offset
, 0, "3DSTATE_MAP_STATE\n");
428 len
= (data
[0] & 0x0000003f) + 2;
431 for (map
= 0; map
<= 15; map
++) {
432 if (data
[1] & (1 << map
)) {
434 BUFFER_FAIL(count
, len
, "3DSTATE_MAP_STATE");
435 instr_out(data
, hw_offset
, i
++, "map %d MS2\n", map
);
436 instr_out(data
, hw_offset
, i
++, "map %d MS3\n", map
);
437 instr_out(data
, hw_offset
, i
++, "map %d MS4\n", map
);
441 fprintf(out
, "Bad count in 3DSTATE_MAP_STATE\n");
447 instr_out(data
, hw_offset
, 0, "3DSTATE_PIXEL_SHADER_CONSTANTS\n");
448 len
= (data
[0] & 0x000000ff) + 2;
451 for (c
= 0; c
<= 31; c
++) {
452 if (data
[1] & (1 << c
)) {
454 BUFFER_FAIL(count
, len
, "3DSTATE_PIXEL_SHADER_CONSTANTS");
455 instr_out(data
, hw_offset
, i
, "C%d.X = %f\n",
456 c
, int_as_float(data
[i
]));
458 instr_out(data
, hw_offset
, i
, "C%d.Y = %f\n",
459 c
, int_as_float(data
[i
]));
461 instr_out(data
, hw_offset
, i
, "C%d.Z = %f\n",
462 c
, int_as_float(data
[i
]));
464 instr_out(data
, hw_offset
, i
, "C%d.W = %f\n",
465 c
, int_as_float(data
[i
]));
470 fprintf(out
, "Bad count in 3DSTATE_MAP_STATE\n");
475 instr_out(data
, hw_offset
, 0, "3DSTATE_PIXEL_SHADER_PROGRAM\n");
476 len
= (data
[0] & 0x000000ff) + 2;
477 if ((len
- 1) % 3 != 0 || len
> 370) {
478 fprintf(out
, "Bad count in 3DSTATE_PIXEL_SHADER_PROGRAM\n");
482 for (instr
= 0; instr
< (len
- 1) / 3; instr
++) {
484 BUFFER_FAIL(count
, len
, "3DSTATE_MAP_STATE");
485 instr_out(data
, hw_offset
, i
++, "PS%03x\n", instr
);
486 instr_out(data
, hw_offset
, i
++, "PS%03x\n", instr
);
487 instr_out(data
, hw_offset
, i
++, "PS%03x\n", instr
);
491 instr_out(data
, hw_offset
, 0, "3DSTATE_SAMPLER_STATE\n");
492 len
= (data
[0] & 0x0000003f) + 2;
494 for (sampler
= 0; sampler
<= 15; sampler
++) {
495 if (data
[1] & (1 << sampler
)) {
497 BUFFER_FAIL(count
, len
, "3DSTATE_SAMPLER_STATE");
498 instr_out(data
, hw_offset
, i
++, "sampler %d SS2\n",
500 instr_out(data
, hw_offset
, i
++, "sampler %d SS3\n",
502 instr_out(data
, hw_offset
, i
++, "sampler %d SS4\n",
507 fprintf(out
, "Bad count in 3DSTATE_SAMPLER_STATE\n");
513 for (opcode
= 0; opcode
< sizeof(opcodes_3d_1d
) / sizeof(opcodes_3d_1d
[0]);
516 if (((data
[0] & 0x00ff0000) >> 16) == opcodes_3d_1d
[opcode
].opcode
) {
519 instr_out(data
, hw_offset
, 0, "%s\n", opcodes_3d_1d
[opcode
].name
);
520 if (opcodes_3d_1d
[opcode
].max_len
> 1) {
521 len
= (data
[0] & 0x0000ffff) + 2;
522 if (len
< opcodes_3d_1d
[opcode
].min_len
||
523 len
> opcodes_3d_1d
[opcode
].max_len
)
525 fprintf(out
, "Bad count in %s\n",
526 opcodes_3d_1d
[opcode
].name
);
531 for (i
= 1; i
< len
; i
++) {
533 BUFFER_FAIL(count
, len
, opcodes_3d_1d
[opcode
].name
);
534 instr_out(data
, hw_offset
, i
, "dword %d\n", i
);
541 instr_out(data
, hw_offset
, 0, "3D UNKNOWN\n");
547 decode_3d_primitive(uint32_t *data
, int count
, uint32_t hw_offset
,
550 char immediate
= (data
[0] & (1 << 23)) == 0;
554 switch ((data
[0] >> 18) & 0xf) {
555 case 0x0: primtype
= "TRILIST"; break;
556 case 0x1: primtype
= "TRISTRIP"; break;
557 case 0x2: primtype
= "TRISTRIP_REVERSE"; break;
558 case 0x3: primtype
= "TRIFAN"; break;
559 case 0x4: primtype
= "POLYGON"; break;
560 case 0x5: primtype
= "LINELIST"; break;
561 case 0x6: primtype
= "LINESTRIP"; break;
562 case 0x7: primtype
= "RECTLIST"; break;
563 case 0x8: primtype
= "POINTLIST"; break;
564 case 0x9: primtype
= "DIB"; break;
565 case 0xa: primtype
= "CLEAR_RECT"; break;
566 default: primtype
= "unknown"; break;
569 /* XXX: 3DPRIM_DIB not supported */
571 len
= (data
[0] & 0x0003ffff) + 2;
572 instr_out(data
, hw_offset
, 0, "3DPRIMITIVE inline %s\n", primtype
);
574 BUFFER_FAIL(count
, len
, "3DPRIMITIVE inline");
575 if (!saved_s2_set
|| !saved_s4_set
) {
576 fprintf(out
, "unknown vertex format\n");
577 for (i
= 1; i
< len
; i
++) {
578 instr_out(data
, hw_offset
, i
,
579 " vertex data (%f float)\n",
580 int_as_float(data
[i
]));
583 unsigned int vertex
= 0;
584 for (i
= 1; i
< len
;) {
587 #define VERTEX_OUT(fmt, ...) do { \
589 instr_out(data, hw_offset, i, " V%d."fmt"\n", vertex, __VA_ARGS__); \
591 fprintf(out, " missing data in V%d\n", vertex); \
595 VERTEX_OUT("X = %f", int_as_float(data
[i
]));
596 VERTEX_OUT("Y = %f", int_as_float(data
[i
]));
597 switch (saved_s4
>> 6 & 0x7) {
599 VERTEX_OUT("Z = %f", int_as_float(data
[i
]));
602 VERTEX_OUT("Z = %f", int_as_float(data
[i
]));
603 VERTEX_OUT("W = %f", int_as_float(data
[i
]));
608 VERTEX_OUT("W = %f", int_as_float(data
[i
]));
611 fprintf(out
, "bad S4 position mask\n");
614 if (saved_s4
& (1 << 10)) {
615 VERTEX_OUT("color = (A=0x%02x, R=0x%02x, G=0x%02x, "
618 (data
[i
] >> 16) & 0xff,
619 (data
[i
] >> 8) & 0xff,
622 if (saved_s4
& (1 << 11)) {
623 VERTEX_OUT("spec = (A=0x%02x, R=0x%02x, G=0x%02x, "
626 (data
[i
] >> 16) & 0xff,
627 (data
[i
] >> 8) & 0xff,
630 if (saved_s4
& (1 << 12))
631 VERTEX_OUT("width = 0x%08x)", data
[i
]);
633 for (tc
= 0; tc
<= 7; tc
++) {
634 switch ((saved_s2
>> (tc
* 4)) & 0xf) {
636 VERTEX_OUT("T%d.X = %f", tc
, int_as_float(data
[i
]));
637 VERTEX_OUT("T%d.Y = %f", tc
, int_as_float(data
[i
]));
640 VERTEX_OUT("T%d.X = %f", tc
, int_as_float(data
[i
]));
641 VERTEX_OUT("T%d.Y = %f", tc
, int_as_float(data
[i
]));
642 VERTEX_OUT("T%d.Z = %f", tc
, int_as_float(data
[i
]));
645 VERTEX_OUT("T%d.X = %f", tc
, int_as_float(data
[i
]));
646 VERTEX_OUT("T%d.Y = %f", tc
, int_as_float(data
[i
]));
647 VERTEX_OUT("T%d.Z = %f", tc
, int_as_float(data
[i
]));
648 VERTEX_OUT("T%d.W = %f", tc
, int_as_float(data
[i
]));
651 VERTEX_OUT("T%d.X = %f", tc
, int_as_float(data
[i
]));
654 VERTEX_OUT("T%d.XY = 0x%08x half-float", tc
, data
[i
]);
657 VERTEX_OUT("T%d.XY = 0x%08x half-float", tc
, data
[i
]);
658 VERTEX_OUT("T%d.ZW = 0x%08x half-float", tc
, data
[i
]);
663 fprintf(out
, "bad S2.T%d format\n", tc
);
670 /* indirect vertices */
671 len
= data
[0] & 0x0000ffff; /* index count */
672 if (data
[0] & (1 << 17)) {
673 /* random vertex access */
674 if (count
< (len
+ 1) / 2 + 1) {
675 BUFFER_FAIL(count
, (len
+ 1) / 2 + 1,
676 "3DPRIMITIVE random indirect");
678 instr_out(data
, hw_offset
, 0,
679 "3DPRIMITIVE random indirect %s (%d)\n", primtype
, len
);
681 /* vertex indices continue until 0xffff is found */
682 for (i
= 1; i
< count
; i
++) {
683 if ((data
[i
] & 0xffff) == 0xffff) {
684 instr_out(data
, hw_offset
, i
,
685 " indices: (terminator)\n");
687 } else if ((data
[i
] >> 16) == 0xffff) {
688 instr_out(data
, hw_offset
, i
,
694 instr_out(data
, hw_offset
, i
,
695 " indices: 0x%04x, 0x%04x\n",
696 data
[i
] & 0xffff, data
[i
] >> 16);
700 "3DPRIMITIVE: no terminator found in index buffer\n");
704 /* fixed size vertex index buffer */
705 for (i
= 0; i
< len
; i
+= 2) {
706 if (i
* 2 == len
- 1) {
707 instr_out(data
, hw_offset
, i
,
708 " indices: 0x%04x\n",
711 instr_out(data
, hw_offset
, i
,
712 " indices: 0x%04x, 0x%04x\n",
713 data
[i
] & 0xffff, data
[i
] >> 16);
717 return (len
+ 1) / 2 + 1;
719 /* sequential vertex access */
721 BUFFER_FAIL(count
, 2, "3DPRIMITIVE seq indirect");
722 instr_out(data
, hw_offset
, 0,
723 "3DPRIMITIVE sequential indirect %s, %d starting from "
724 "%d\n", primtype
, len
, data
[1] & 0xffff);
725 instr_out(data
, hw_offset
, 1, " start\n");
734 decode_3d(uint32_t *data
, int count
, uint32_t hw_offset
, int *failures
)
744 { 0x06, 1, 1, "3DSTATE_ANTI_ALIASING" },
745 { 0x08, 1, 1, "3DSTATE_BACKFACE_STENCIL_OPS" },
746 { 0x09, 1, 1, "3DSTATE_BACKFACE_STENCIL_MASKS" },
747 { 0x16, 1, 1, "3DSTATE_COORD_SET_BINDINGS" },
748 { 0x15, 1, 1, "3DSTATE_FOG_COLOR" },
749 { 0x0b, 1, 1, "3DSTATE_INDEPENDENT_ALPHA_BLEND" },
750 { 0x0d, 1, 1, "3DSTATE_MODES_4" },
751 { 0x0c, 1, 1, "3DSTATE_MODES_5" },
752 { 0x07, 1, 1, "3DSTATE_RASTERIZATION_RULES" },
755 switch ((data
[0] & 0x1f000000) >> 24) {
757 return decode_3d_primitive(data
, count
, hw_offset
, failures
);
759 return decode_3d_1d(data
, count
, hw_offset
, failures
);
761 return decode_3d_1c(data
, count
, hw_offset
, failures
);
764 for (opcode
= 0; opcode
< sizeof(opcodes_3d
) / sizeof(opcodes_3d
[0]);
766 if ((data
[0] & 0x1f000000) >> 24 == opcodes_3d
[opcode
].opcode
) {
767 unsigned int len
= 1, i
;
769 instr_out(data
, hw_offset
, 0, "%s\n", opcodes_3d
[opcode
].name
);
770 if (opcodes_3d
[opcode
].max_len
> 1) {
771 len
= (data
[0] & 0xff) + 2;
772 if (len
< opcodes_3d
[opcode
].min_len
||
773 len
> opcodes_3d
[opcode
].max_len
)
775 fprintf(out
, "Bad count in %s\n", opcodes_3d
[opcode
].name
);
779 for (i
= 1; i
< len
; i
++) {
781 BUFFER_FAIL(count
, len
, opcodes_3d
[opcode
].name
);
782 instr_out(data
, hw_offset
, i
, "dword %d\n", i
);
788 instr_out(data
, hw_offset
, 0, "3D UNKNOWN\n");
794 get_965_surfacetype(unsigned int surfacetype
)
796 switch (surfacetype
) {
800 case 3: return "CUBE";
801 case 4: return "BUFFER";
802 case 7: return "NULL";
803 default: return "unknown";
808 get_965_depthformat(unsigned int depthformat
)
810 switch (depthformat
) {
811 case 0: return "s8_z24float";
812 case 1: return "z32float";
813 case 2: return "z24s8";
814 case 5: return "z16";
815 default: return "unknown";
820 decode_3d_965(uint32_t *data
, int count
, uint32_t hw_offset
, int *failures
)
822 unsigned int opcode
, len
;
830 { 0x6000, 3, 3, "URB_FENCE" },
831 { 0x6001, 2, 2, "CS_URB_STATE" },
832 { 0x6002, 2, 2, "CONSTANT_BUFFER" },
833 { 0x6101, 6, 6, "STATE_BASE_ADDRESS" },
834 { 0x6102, 2, 2 , "STATE_SIP" },
835 { 0x6104, 1, 1, "3DSTATE_PIPELINE_SELECT" },
836 { 0x680b, 1, 1, "3DSTATE_VF_STATISTICS" },
837 { 0x6904, 1, 1, "3DSTATE_PIPELINE_SELECT" },
838 { 0x7800, 7, 7, "3DSTATE_PIPELINED_POINTERS" },
839 { 0x7801, 6, 6, "3DSTATE_BINDING_TABLE_POINTERS" },
840 { 0x780b, 1, 1, "3DSTATE_VF_STATISTICS" },
841 { 0x7808, 5, 257, "3DSTATE_VERTEX_BUFFERS" },
842 { 0x7809, 3, 256, "3DSTATE_VERTEX_ELEMENTS" },
843 /* 0x7808: 3DSTATE_VERTEX_BUFFERS */
844 /* 0x7809: 3DSTATE_VERTEX_ELEMENTS */
845 { 0x7900, 4, 4, "3DSTATE_DRAWING_RECTANGLE" },
846 { 0x7901, 5, 5, "3DSTATE_CONSTANT_COLOR" },
847 { 0x7905, 5, 7, "3DSTATE_DEPTH_BUFFER" },
848 { 0x7906, 2, 2, "3DSTATE_POLY_STIPPLE_OFFSET" },
849 { 0x7907, 33, 33, "3DSTATE_POLY_STIPPLE_PATTERN" },
850 { 0x7908, 3, 3, "3DSTATE_LINE_STIPPLE" },
851 { 0x7909, 2, 2, "3DSTATE_GLOBAL_DEPTH_OFFSET_CLAMP" },
852 { 0x790a, 3, 3, "3DSTATE_AA_LINE_PARAMETERS" },
853 { 0x7b00, 6, 6, "3DPRIMITIVE" },
856 len
= (data
[0] & 0x0000ffff) + 2;
858 switch ((data
[0] & 0xffff0000) >> 16) {
861 fprintf(out
, "Bad count in STATE_BASE_ADDRESS\n");
863 BUFFER_FAIL(count
, len
, "STATE_BASE_ADDRESS");
865 instr_out(data
, hw_offset
, 0,
866 "STATE_BASE_ADDRESS\n");
869 instr_out(data
, hw_offset
, 1, "General state at 0x%08x\n",
872 instr_out(data
, hw_offset
, 1, "General state not updated\n");
875 instr_out(data
, hw_offset
, 2, "Surface state at 0x%08x\n",
878 instr_out(data
, hw_offset
, 2, "Surface state not updated\n");
881 instr_out(data
, hw_offset
, 3, "Indirect state at 0x%08x\n",
884 instr_out(data
, hw_offset
, 3, "Indirect state not updated\n");
887 instr_out(data
, hw_offset
, 4, "General state upper bound 0x%08x\n",
890 instr_out(data
, hw_offset
, 4, "General state not updated\n");
893 instr_out(data
, hw_offset
, 5, "Indirect state upper bound 0x%08x\n",
896 instr_out(data
, hw_offset
, 5, "Indirect state not updated\n");
901 fprintf(out
, "Bad count in 3DSTATE_PIPELINED_POINTERS\n");
903 BUFFER_FAIL(count
, len
, "3DSTATE_PIPELINED_POINTERS");
905 instr_out(data
, hw_offset
, 0,
906 "3DSTATE_PIPELINED_POINTERS\n");
907 instr_out(data
, hw_offset
, 1, "VS state\n");
908 instr_out(data
, hw_offset
, 2, "GS state\n");
909 instr_out(data
, hw_offset
, 3, "Clip state\n");
910 instr_out(data
, hw_offset
, 4, "SF state\n");
911 instr_out(data
, hw_offset
, 5, "WM state\n");
912 instr_out(data
, hw_offset
, 6, "CC state\n");
916 fprintf(out
, "Bad count in 3DSTATE_BINDING_TABLE_POINTERS\n");
918 BUFFER_FAIL(count
, len
, "3DSTATE_BINDING_TABLE_POINTERS");
920 instr_out(data
, hw_offset
, 0,
921 "3DSTATE_BINDING_TABLE_POINTERS\n");
922 instr_out(data
, hw_offset
, 1, "VS binding table\n");
923 instr_out(data
, hw_offset
, 2, "GS binding table\n");
924 instr_out(data
, hw_offset
, 3, "Clip binding table\n");
925 instr_out(data
, hw_offset
, 4, "SF binding table\n");
926 instr_out(data
, hw_offset
, 5, "WM binding table\n");
932 fprintf(out
, "Bad count in 3DSTATE_DRAWING_RECTANGLE\n");
934 BUFFER_FAIL(count
, len
, "3DSTATE_DRAWING_RECTANGLE");
936 instr_out(data
, hw_offset
, 0,
937 "3DSTATE_DRAWING_RECTANGLE\n");
938 instr_out(data
, hw_offset
, 1, "top left: %d,%d\n",
940 (data
[1] >> 16) & 0xffff);
941 instr_out(data
, hw_offset
, 2, "bottom right: %d,%d\n",
943 (data
[2] >> 16) & 0xffff);
944 instr_out(data
, hw_offset
, 3, "origin: %d,%d\n",
945 (int)data
[3] & 0xffff,
946 ((int)data
[3] >> 16) & 0xffff);
952 fprintf(out
, "Bad count in 3DSTATE_DEPTH_BUFFER\n");
954 BUFFER_FAIL(count
, len
, "3DSTATE_DEPTH_BUFFER");
956 instr_out(data
, hw_offset
, 0,
957 "3DSTATE_DEPTH_BUFFER\n");
958 instr_out(data
, hw_offset
, 1, "%s, %s, pitch = %d bytes, %stiled\n",
959 get_965_surfacetype(data
[1] >> 29),
960 get_965_depthformat((data
[1] >> 18) & 0x7),
961 (data
[1] & 0x0001ffff) + 1,
962 data
[1] & (1 << 27) ? "" : "not ");
963 instr_out(data
, hw_offset
, 2, "depth offset\n");
964 instr_out(data
, hw_offset
, 3, "%dx%d\n",
965 ((data
[3] & 0x0007ffc0) >> 6) + 1,
966 ((data
[3] & 0xfff80000) >> 19) + 1);
967 instr_out(data
, hw_offset
, 4, "volume depth\n");
972 for (opcode
= 0; opcode
< sizeof(opcodes_3d
) / sizeof(opcodes_3d
[0]);
974 if ((data
[0] & 0xffff0000) >> 16 == opcodes_3d
[opcode
].opcode
) {
978 instr_out(data
, hw_offset
, 0, "%s\n", opcodes_3d
[opcode
].name
);
979 if (opcodes_3d
[opcode
].max_len
> 1) {
980 len
= (data
[0] & 0xff) + 2;
981 if (len
< opcodes_3d
[opcode
].min_len
||
982 len
> opcodes_3d
[opcode
].max_len
)
984 fprintf(out
, "Bad count in %s\n", opcodes_3d
[opcode
].name
);
988 for (i
= 1; i
< len
; i
++) {
990 BUFFER_FAIL(count
, len
, opcodes_3d
[opcode
].name
);
991 instr_out(data
, hw_offset
, i
, "dword %d\n", i
);
997 instr_out(data
, hw_offset
, 0, "3D UNKNOWN\n");
1003 * Decodes an i830-i915 batch buffer, writing the output to stdout.
1005 * \param data batch buffer contents
1006 * \param count number of DWORDs to decode in the batch buffer
1007 * \param hw_offset hardware address for the buffer
1010 intel_decode(uint32_t *data
, int count
, uint32_t hw_offset
, uint32_t devid
)
1017 while (index
< count
) {
1018 switch ((data
[index
] & 0xe0000000) >> 29) {
1020 index
+= decode_mi(data
+ index
, count
- index
,
1021 hw_offset
+ index
* 4, &failures
);
1024 index
+= decode_2d(data
+ index
, count
- index
,
1025 hw_offset
+ index
* 4, &failures
);
1028 if (IS_965(devid
)) {
1029 index
+= decode_3d_965(data
+ index
, count
- index
,
1030 hw_offset
+ index
* 4, &failures
);
1032 index
+= decode_3d(data
+ index
, count
- index
,
1033 hw_offset
+ index
* 4, &failures
);
1037 instr_out(data
, hw_offset
, index
, "UNKNOWN\n");
1048 void intel_decode_context_reset(void)