2 * Copyright © 2009-2011 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
31 #include "intel_chipset.h"
32 #include "intel_bufmgr.h"
34 /* Struct for tracking drm_intel_decode state. */
35 struct drm_intel_decode {
36 /** stdio file where the output should land. Defaults to stdout. */
42 /** GPU address of the start of the current packet. */
44 /** CPU virtual address of the start of the current packet. */
46 /** DWORDs of remaining batchbuffer data starting from the packet. */
49 /** GPU address of the start of the batchbuffer data. */
50 uint32_t base_hw_offset;
51 /** CPU Virtual address of the start of the batchbuffer data. */
53 /** Number of DWORDs of batchbuffer data. */
57 * GPU head and tail pointers, which will be noted in the dump, or ~0.
63 * Whether to dump the dwords after MI_BATCHBUFFER_END.
65 * This sometimes provides clues in corrupted batchbuffers,
66 * and is used by the intel-gpu-tools.
74 static uint32_t saved_s2 = 0, saved_s4 = 0;
75 static char saved_s2_set = 0, saved_s4_set = 0;
76 static uint32_t head_offset = 0xffffffff; /* undefined */
77 static uint32_t tail_offset = 0xffffffff; /* undefined */
80 #define ARRAY_SIZE(A) (sizeof(A)/sizeof(A[0]))
83 #define BUFFER_FAIL(_count, _len, _name) do { \
84 fprintf(out, "Buffer size too small in %s (%d < %d)\n", \
85 (_name), (_count), (_len)); \
89 static float int_as_float(uint32_t intval)
101 instr_out(struct drm_intel_decode *ctx, unsigned int index,
102 const char *fmt, ...) __attribute__((format(__printf__, 3, 4)));
105 instr_out(struct drm_intel_decode *ctx, unsigned int index,
106 const char *fmt, ...)
109 const char *parseinfo;
110 uint32_t offset = ctx->hw_offset + index * 4;
112 if (index > ctx->count) {
113 if (!ctx->overflowed) {
114 fprintf(out, "ERROR: Decode attempted to continue beyond end of batchbuffer\n");
115 ctx->overflowed = true;
120 if (offset == head_offset)
122 else if (offset == tail_offset)
127 fprintf(out, "0x%08x: %s 0x%08x: %s", offset, parseinfo,
128 ctx->data[index], index == 0 ? "" : " ");
130 vfprintf(out, fmt, va);
135 decode_mi(struct drm_intel_decode *ctx)
137 unsigned int opcode, len = -1;
138 const char *post_sync_op = "";
139 uint32_t *data = ctx->data;
144 unsigned int min_len;
145 unsigned int max_len;
148 { 0x08, 0, 1, 1, "MI_ARB_ON_OFF" },
149 { 0x0a, 0, 1, 1, "MI_BATCH_BUFFER_END" },
150 { 0x30, 0x3f, 3, 3, "MI_BATCH_BUFFER" },
151 { 0x31, 0x3f, 2, 2, "MI_BATCH_BUFFER_START" },
152 { 0x14, 0x3f, 3, 3, "MI_DISPLAY_BUFFER_INFO" },
153 { 0x04, 0, 1, 1, "MI_FLUSH" },
154 { 0x22, 0x1f, 3, 3, "MI_LOAD_REGISTER_IMM" },
155 { 0x13, 0x3f, 2, 2, "MI_LOAD_SCAN_LINES_EXCL" },
156 { 0x12, 0x3f, 2, 2, "MI_LOAD_SCAN_LINES_INCL" },
157 { 0x00, 0, 1, 1, "MI_NOOP" },
158 { 0x11, 0x3f, 2, 2, "MI_OVERLAY_FLIP" },
159 { 0x07, 0, 1, 1, "MI_REPORT_HEAD" },
160 { 0x18, 0x3f, 2, 2, "MI_SET_CONTEXT" },
161 { 0x20, 0x3f, 3, 4, "MI_STORE_DATA_IMM" },
162 { 0x21, 0x3f, 3, 4, "MI_STORE_DATA_INDEX" },
163 { 0x24, 0x3f, 3, 3, "MI_STORE_REGISTER_MEM" },
164 { 0x02, 0, 1, 1, "MI_USER_INTERRUPT" },
165 { 0x03, 0, 1, 1, "MI_WAIT_FOR_EVENT" },
166 { 0x16, 0x7f, 3, 3, "MI_SEMAPHORE_MBOX" },
167 { 0x26, 0x1f, 3, 4, "MI_FLUSH_DW" },
168 { 0x0b, 0, 1, 1, "MI_SUSPEND_FLUSH"},
171 /* check instruction length */
172 for (opcode = 0; opcode < sizeof(opcodes_mi) / sizeof(opcodes_mi[0]);
174 if ((data[0] & 0x1f800000) >> 23 == opcodes_mi[opcode].opcode) {
176 if (opcodes_mi[opcode].max_len > 1) {
178 (data[0] & opcodes_mi[opcode].len_mask) + 2;
179 if (len < opcodes_mi[opcode].min_len
180 || len > opcodes_mi[opcode].max_len) {
182 "Bad length (%d) in %s, [%d, %d]\n",
183 len, opcodes_mi[opcode].name,
184 opcodes_mi[opcode].min_len,
185 opcodes_mi[opcode].max_len);
192 switch ((data[0] & 0x1f800000) >> 23) {
194 instr_out(ctx, 0, "MI_BATCH_BUFFER_END\n");
197 instr_out(ctx, 0, "MI_SEMAPHORE_MBOX%s%s%s%s %u\n",
198 data[0] & (1 << 22) ? " global gtt," : "",
199 data[0] & (1 << 21) ? " update semaphore," : "",
200 data[0] & (1 << 20) ? " compare semaphore," : "",
201 data[0] & (1 << 18) ? " use compare reg" : "",
202 (data[0] & (0x3 << 16)) >> 16);
203 instr_out(ctx, 1, "value\n");
204 instr_out(ctx, 2, "address\n");
207 instr_out(ctx, 0, "MI_STORE_DATA_INDEX%s\n",
208 data[0] & (1 << 21) ? " use per-process HWS," : "");
209 instr_out(ctx, 1, "index\n");
210 instr_out(ctx, 2, "dword\n");
212 instr_out(ctx, 3, "upper dword\n");
215 if (data[0] & (1 << 22))
217 "MI_NOOP write NOPID reg, val=0x%x\n",
218 data[0] & ((1 << 22) - 1));
220 instr_out(ctx, 0, "MI_NOOP\n");
223 switch (data[0] & (0x3 << 14)) {
225 post_sync_op = "no write";
228 post_sync_op = "write data";
231 post_sync_op = "reserved";
234 post_sync_op = "write TIMESTAMP";
238 "MI_FLUSH_DW%s%s%s%s post_sync_op='%s' %s%s\n",
239 data[0] & (1 << 22) ?
240 " enable protected mem (BCS-only)," : "",
241 data[0] & (1 << 21) ? " store in hws," : "",
242 data[0] & (1 << 18) ? " invalidate tlb," : "",
243 data[0] & (1 << 17) ? " flush gfdt," : "",
245 data[0] & (1 << 8) ? " enable notify interrupt," : "",
247 " invalidate video state (BCS-only)," : "");
248 if (data[0] & (1 << 21))
249 instr_out(ctx, 1, "hws index\n");
251 instr_out(ctx, 1, "address\n");
252 instr_out(ctx, 2, "dword\n");
254 instr_out(ctx, 3, "upper dword\n");
258 for (opcode = 0; opcode < sizeof(opcodes_mi) / sizeof(opcodes_mi[0]);
260 if ((data[0] & 0x1f800000) >> 23 == opcodes_mi[opcode].opcode) {
263 instr_out(ctx, 0, "%s\n",
264 opcodes_mi[opcode].name);
265 for (i = 1; i < len; i++) {
266 instr_out(ctx, i, "dword %d\n", i);
273 instr_out(ctx, 0, "MI UNKNOWN\n");
278 decode_2d_br00(struct drm_intel_decode *ctx, const char *cmd)
281 "%s (rgb %sabled, alpha %sabled, src tile %d, dst tile %d)\n",
283 (ctx->data[0] & (1 << 20)) ? "en" : "dis",
284 (ctx->data[0] & (1 << 21)) ? "en" : "dis",
285 (ctx->data[0] >> 15) & 1,
286 (ctx->data[0] >> 11) & 1);
290 decode_2d_br01(struct drm_intel_decode *ctx)
293 switch ((ctx->data[1] >> 24) & 0x3) {
309 "format %s, pitch %d, rop 0x%02x, "
310 "clipping %sabled, %s%s \n",
312 (short)(ctx->data[1] & 0xffff),
313 (ctx->data[1] >> 16) & 0xff,
314 ctx->data[1] & (1 << 30) ? "en" : "dis",
315 ctx->data[1] & (1 << 31) ? "solid pattern enabled, " : "",
316 ctx->data[1] & (1 << 31) ?
317 "mono pattern transparency enabled, " : "");
322 decode_2d(struct drm_intel_decode *ctx)
324 unsigned int opcode, len;
325 uint32_t *data = ctx->data;
329 unsigned int min_len;
330 unsigned int max_len;
333 { 0x40, 5, 5, "COLOR_BLT" },
334 { 0x43, 6, 6, "SRC_COPY_BLT" },
335 { 0x01, 8, 8, "XY_SETUP_BLT" },
336 { 0x11, 9, 9, "XY_SETUP_MONO_PATTERN_SL_BLT" },
337 { 0x03, 3, 3, "XY_SETUP_CLIP_BLT" },
338 { 0x24, 2, 2, "XY_PIXEL_BLT" },
339 { 0x25, 3, 3, "XY_SCANLINES_BLT" },
340 { 0x26, 4, 4, "Y_TEXT_BLT" },
341 { 0x31, 5, 134, "XY_TEXT_IMMEDIATE_BLT" },
342 { 0x50, 6, 6, "XY_COLOR_BLT" },
343 { 0x51, 6, 6, "XY_PAT_BLT" },
344 { 0x76, 8, 8, "XY_PAT_CHROMA_BLT" },
345 { 0x72, 7, 135, "XY_PAT_BLT_IMMEDIATE" },
346 { 0x77, 9, 137, "XY_PAT_CHROMA_BLT_IMMEDIATE" },
347 { 0x52, 9, 9, "XY_MONO_PAT_BLT" },
348 { 0x59, 7, 7, "XY_MONO_PAT_FIXED_BLT" },
349 { 0x53, 8, 8, "XY_SRC_COPY_BLT" },
350 { 0x54, 8, 8, "XY_MONO_SRC_COPY_BLT" },
351 { 0x71, 9, 137, "XY_MONO_SRC_COPY_IMMEDIATE_BLT" },
352 { 0x55, 9, 9, "XY_FULL_BLT" },
353 { 0x55, 9, 137, "XY_FULL_IMMEDIATE_PATTERN_BLT" },
354 { 0x56, 9, 9, "XY_FULL_MONO_SRC_BLT" },
355 { 0x75, 10, 138, "XY_FULL_MONO_SRC_IMMEDIATE_PATTERN_BLT" },
356 { 0x57, 12, 12, "XY_FULL_MONO_PATTERN_BLT" },
357 { 0x58, 12, 12, "XY_FULL_MONO_PATTERN_MONO_SRC_BLT"},
360 switch ((data[0] & 0x1fc00000) >> 22) {
363 "XY_SCANLINES_BLT (pattern seed (%d, %d), dst tile %d)\n",
364 (data[0] >> 12) & 0x8,
365 (data[0] >> 8) & 0x8, (data[0] >> 11) & 1);
367 len = (data[0] & 0x000000ff) + 2;
369 fprintf(out, "Bad count in XY_SCANLINES_BLT\n");
371 instr_out(ctx, 1, "dest (%d,%d)\n",
372 data[1] & 0xffff, data[1] >> 16);
373 instr_out(ctx, 2, "dest (%d,%d)\n",
374 data[2] & 0xffff, data[2] >> 16);
377 decode_2d_br00(ctx, "XY_SETUP_BLT");
379 len = (data[0] & 0x000000ff) + 2;
381 fprintf(out, "Bad count in XY_SETUP_BLT\n");
384 instr_out(ctx, 2, "cliprect (%d,%d)\n",
385 data[2] & 0xffff, data[2] >> 16);
386 instr_out(ctx, 3, "cliprect (%d,%d)\n",
387 data[3] & 0xffff, data[3] >> 16);
388 instr_out(ctx, 4, "setup dst offset 0x%08x\n",
390 instr_out(ctx, 5, "setup background color\n");
391 instr_out(ctx, 6, "setup foreground color\n");
392 instr_out(ctx, 7, "color pattern offset\n");
395 decode_2d_br00(ctx, "XY_SETUP_CLIP_BLT");
397 len = (data[0] & 0x000000ff) + 2;
399 fprintf(out, "Bad count in XY_SETUP_CLIP_BLT\n");
401 instr_out(ctx, 1, "cliprect (%d,%d)\n",
402 data[1] & 0xffff, data[2] >> 16);
403 instr_out(ctx, 2, "cliprect (%d,%d)\n",
404 data[2] & 0xffff, data[3] >> 16);
407 decode_2d_br00(ctx, "XY_SETUP_MONO_PATTERN_SL_BLT");
409 len = (data[0] & 0x000000ff) + 2;
412 "Bad count in XY_SETUP_MONO_PATTERN_SL_BLT\n");
415 instr_out(ctx, 2, "cliprect (%d,%d)\n",
416 data[2] & 0xffff, data[2] >> 16);
417 instr_out(ctx, 3, "cliprect (%d,%d)\n",
418 data[3] & 0xffff, data[3] >> 16);
419 instr_out(ctx, 4, "setup dst offset 0x%08x\n",
421 instr_out(ctx, 5, "setup background color\n");
422 instr_out(ctx, 6, "setup foreground color\n");
423 instr_out(ctx, 7, "mono pattern dw0\n");
424 instr_out(ctx, 8, "mono pattern dw1\n");
427 decode_2d_br00(ctx, "XY_COLOR_BLT");
429 len = (data[0] & 0x000000ff) + 2;
431 fprintf(out, "Bad count in XY_COLOR_BLT\n");
434 instr_out(ctx, 2, "(%d,%d)\n",
435 data[2] & 0xffff, data[2] >> 16);
436 instr_out(ctx, 3, "(%d,%d)\n",
437 data[3] & 0xffff, data[3] >> 16);
438 instr_out(ctx, 4, "offset 0x%08x\n", data[4]);
439 instr_out(ctx, 5, "color\n");
442 decode_2d_br00(ctx, "XY_SRC_COPY_BLT");
444 len = (data[0] & 0x000000ff) + 2;
446 fprintf(out, "Bad count in XY_SRC_COPY_BLT\n");
449 instr_out(ctx, 2, "dst (%d,%d)\n",
450 data[2] & 0xffff, data[2] >> 16);
451 instr_out(ctx, 3, "dst (%d,%d)\n",
452 data[3] & 0xffff, data[3] >> 16);
453 instr_out(ctx, 4, "dst offset 0x%08x\n", data[4]);
454 instr_out(ctx, 5, "src (%d,%d)\n",
455 data[5] & 0xffff, data[5] >> 16);
456 instr_out(ctx, 6, "src pitch %d\n",
457 (short)(data[6] & 0xffff));
458 instr_out(ctx, 7, "src offset 0x%08x\n", data[7]);
462 for (opcode = 0; opcode < sizeof(opcodes_2d) / sizeof(opcodes_2d[0]);
464 if ((data[0] & 0x1fc00000) >> 22 == opcodes_2d[opcode].opcode) {
468 instr_out(ctx, 0, "%s\n",
469 opcodes_2d[opcode].name);
470 if (opcodes_2d[opcode].max_len > 1) {
471 len = (data[0] & 0x000000ff) + 2;
472 if (len < opcodes_2d[opcode].min_len ||
473 len > opcodes_2d[opcode].max_len) {
474 fprintf(out, "Bad count in %s\n",
475 opcodes_2d[opcode].name);
479 for (i = 1; i < len; i++) {
480 instr_out(ctx, i, "dword %d\n", i);
487 instr_out(ctx, 0, "2D UNKNOWN\n");
492 decode_3d_1c(struct drm_intel_decode *ctx)
494 uint32_t *data = ctx->data;
497 opcode = (data[0] & 0x00f80000) >> 19;
502 "3DSTATE_DEPTH_SUBRECTANGLE_DISABLE\n");
505 instr_out(ctx, 0, "3DSTATE_SCISSOR_ENABLE %s\n",
506 data[0] & 1 ? "enabled" : "disabled");
509 instr_out(ctx, 0, "3DSTATE_MAP_COORD_SET_I830\n");
512 instr_out(ctx, 0, "3DSTATE_MAP_CUBE_I830\n");
515 instr_out(ctx, 0, "3DSTATE_MAP_TEX_STREAM_I830\n");
519 instr_out(ctx, 0, "3D UNKNOWN: 3d_1c opcode = 0x%x\n",
524 /** Sets the string dstname to describe the destination of the PS instruction */
526 i915_get_instruction_dst(uint32_t *data, int i, char *dstname, int do_mask)
528 uint32_t a0 = data[i];
529 int dst_nr = (a0 >> 14) & 0xf;
534 if (((a0 >> 10) & 0xf) == 0xf) {
537 int dstmask_index = 0;
539 dstmask[dstmask_index++] = '.';
541 dstmask[dstmask_index++] = 'x';
543 dstmask[dstmask_index++] = 'y';
545 dstmask[dstmask_index++] = 'z';
547 dstmask[dstmask_index++] = 'w';
548 dstmask[dstmask_index++] = 0;
560 switch ((a0 >> 19) & 0x7) {
563 fprintf(out, "bad destination reg R%d\n", dst_nr);
564 sprintf(dstname, "R%d%s%s", dst_nr, dstmask, sat);
568 fprintf(out, "bad destination reg oC%d\n", dst_nr);
569 sprintf(dstname, "oC%s%s", dstmask, sat);
573 fprintf(out, "bad destination reg oD%d\n", dst_nr);
574 sprintf(dstname, "oD%s%s", dstmask, sat);
578 fprintf(out, "bad destination reg U%d\n", dst_nr);
579 sprintf(dstname, "U%d%s%s", dst_nr, dstmask, sat);
582 sprintf(dstname, "RESERVED");
588 i915_get_channel_swizzle(uint32_t select)
590 switch (select & 0x7) {
592 return (select & 8) ? "-x" : "x";
594 return (select & 8) ? "-y" : "y";
596 return (select & 8) ? "-z" : "z";
598 return (select & 8) ? "-w" : "w";
600 return (select & 8) ? "-0" : "0";
602 return (select & 8) ? "-1" : "1";
604 return (select & 8) ? "-bad" : "bad";
609 i915_get_instruction_src_name(uint32_t src_type, uint32_t src_nr, char *name)
613 sprintf(name, "R%d", src_nr);
615 fprintf(out, "bad src reg %s\n", name);
619 sprintf(name, "T%d", src_nr);
620 else if (src_nr == 8)
621 sprintf(name, "DIFFUSE");
622 else if (src_nr == 9)
623 sprintf(name, "SPECULAR");
624 else if (src_nr == 10)
625 sprintf(name, "FOG");
627 fprintf(out, "bad src reg T%d\n", src_nr);
628 sprintf(name, "RESERVED");
632 sprintf(name, "C%d", src_nr);
634 fprintf(out, "bad src reg %s\n", name);
639 fprintf(out, "bad src reg oC%d\n", src_nr);
644 fprintf(out, "bad src reg oD%d\n", src_nr);
647 sprintf(name, "U%d", src_nr);
649 fprintf(out, "bad src reg %s\n", name);
652 fprintf(out, "bad src reg type %d\n", src_type);
653 sprintf(name, "RESERVED");
658 static void i915_get_instruction_src0(uint32_t *data, int i, char *srcname)
660 uint32_t a0 = data[i];
661 uint32_t a1 = data[i + 1];
662 int src_nr = (a0 >> 2) & 0x1f;
663 const char *swizzle_x = i915_get_channel_swizzle((a1 >> 28) & 0xf);
664 const char *swizzle_y = i915_get_channel_swizzle((a1 >> 24) & 0xf);
665 const char *swizzle_z = i915_get_channel_swizzle((a1 >> 20) & 0xf);
666 const char *swizzle_w = i915_get_channel_swizzle((a1 >> 16) & 0xf);
669 i915_get_instruction_src_name((a0 >> 7) & 0x7, src_nr, srcname);
670 sprintf(swizzle, ".%s%s%s%s", swizzle_x, swizzle_y, swizzle_z,
672 if (strcmp(swizzle, ".xyzw") != 0)
673 strcat(srcname, swizzle);
676 static void i915_get_instruction_src1(uint32_t *data, int i, char *srcname)
678 uint32_t a1 = data[i + 1];
679 uint32_t a2 = data[i + 2];
680 int src_nr = (a1 >> 8) & 0x1f;
681 const char *swizzle_x = i915_get_channel_swizzle((a1 >> 4) & 0xf);
682 const char *swizzle_y = i915_get_channel_swizzle((a1 >> 0) & 0xf);
683 const char *swizzle_z = i915_get_channel_swizzle((a2 >> 28) & 0xf);
684 const char *swizzle_w = i915_get_channel_swizzle((a2 >> 24) & 0xf);
687 i915_get_instruction_src_name((a1 >> 13) & 0x7, src_nr, srcname);
688 sprintf(swizzle, ".%s%s%s%s", swizzle_x, swizzle_y, swizzle_z,
690 if (strcmp(swizzle, ".xyzw") != 0)
691 strcat(srcname, swizzle);
694 static void i915_get_instruction_src2(uint32_t *data, int i, char *srcname)
696 uint32_t a2 = data[i + 2];
697 int src_nr = (a2 >> 16) & 0x1f;
698 const char *swizzle_x = i915_get_channel_swizzle((a2 >> 12) & 0xf);
699 const char *swizzle_y = i915_get_channel_swizzle((a2 >> 8) & 0xf);
700 const char *swizzle_z = i915_get_channel_swizzle((a2 >> 4) & 0xf);
701 const char *swizzle_w = i915_get_channel_swizzle((a2 >> 0) & 0xf);
704 i915_get_instruction_src_name((a2 >> 21) & 0x7, src_nr, srcname);
705 sprintf(swizzle, ".%s%s%s%s", swizzle_x, swizzle_y, swizzle_z,
707 if (strcmp(swizzle, ".xyzw") != 0)
708 strcat(srcname, swizzle);
712 i915_get_instruction_addr(uint32_t src_type, uint32_t src_nr, char *name)
716 sprintf(name, "R%d", src_nr);
718 fprintf(out, "bad src reg %s\n", name);
722 sprintf(name, "T%d", src_nr);
723 else if (src_nr == 8)
724 sprintf(name, "DIFFUSE");
725 else if (src_nr == 9)
726 sprintf(name, "SPECULAR");
727 else if (src_nr == 10)
728 sprintf(name, "FOG");
730 fprintf(out, "bad src reg T%d\n", src_nr);
731 sprintf(name, "RESERVED");
737 fprintf(out, "bad src reg oC%d\n", src_nr);
742 fprintf(out, "bad src reg oD%d\n", src_nr);
745 fprintf(out, "bad src reg type %d\n", src_type);
746 sprintf(name, "RESERVED");
752 i915_decode_alu1(struct drm_intel_decode *ctx,
753 int i, char *instr_prefix, const char *op_name)
755 char dst[100], src0[100];
757 i915_get_instruction_dst(ctx->data, i, dst, 1);
758 i915_get_instruction_src0(ctx->data, i, src0);
760 instr_out(ctx, i++, "%s: %s %s, %s\n", instr_prefix,
762 instr_out(ctx, i++, "%s\n", instr_prefix);
763 instr_out(ctx, i++, "%s\n", instr_prefix);
767 i915_decode_alu2(struct drm_intel_decode *ctx,
768 int i, char *instr_prefix, const char *op_name)
770 char dst[100], src0[100], src1[100];
772 i915_get_instruction_dst(ctx->data, i, dst, 1);
773 i915_get_instruction_src0(ctx->data, i, src0);
774 i915_get_instruction_src1(ctx->data, i, src1);
776 instr_out(ctx, i++, "%s: %s %s, %s, %s\n", instr_prefix,
777 op_name, dst, src0, src1);
778 instr_out(ctx, i++, "%s\n", instr_prefix);
779 instr_out(ctx, i++, "%s\n", instr_prefix);
783 i915_decode_alu3(struct drm_intel_decode *ctx,
784 int i, char *instr_prefix, const char *op_name)
786 char dst[100], src0[100], src1[100], src2[100];
788 i915_get_instruction_dst(ctx->data, i, dst, 1);
789 i915_get_instruction_src0(ctx->data, i, src0);
790 i915_get_instruction_src1(ctx->data, i, src1);
791 i915_get_instruction_src2(ctx->data, i, src2);
793 instr_out(ctx, i++, "%s: %s %s, %s, %s, %s\n", instr_prefix,
794 op_name, dst, src0, src1, src2);
795 instr_out(ctx, i++, "%s\n", instr_prefix);
796 instr_out(ctx, i++, "%s\n", instr_prefix);
800 i915_decode_tex(struct drm_intel_decode *ctx, int i,
801 const char *instr_prefix, const char *tex_name)
803 uint32_t t0 = ctx->data[i];
804 uint32_t t1 = ctx->data[i + 1];
809 i915_get_instruction_dst(ctx->data, i, dst_name, 0);
810 i915_get_instruction_addr((t1 >> 24) & 0x7,
811 (t1 >> 17) & 0xf, addr_name);
812 sampler_nr = t0 & 0xf;
814 instr_out(ctx, i++, "%s: %s %s, S%d, %s\n", instr_prefix,
815 tex_name, dst_name, sampler_nr, addr_name);
816 instr_out(ctx, i++, "%s\n", instr_prefix);
817 instr_out(ctx, i++, "%s\n", instr_prefix);
821 i915_decode_dcl(struct drm_intel_decode *ctx, int i, char *instr_prefix)
823 uint32_t d0 = ctx->data[i];
824 const char *sampletype;
825 int dcl_nr = (d0 >> 14) & 0xf;
826 const char *dcl_x = d0 & (1 << 10) ? "x" : "";
827 const char *dcl_y = d0 & (1 << 11) ? "y" : "";
828 const char *dcl_z = d0 & (1 << 12) ? "z" : "";
829 const char *dcl_w = d0 & (1 << 13) ? "w" : "";
832 switch ((d0 >> 19) & 0x3) {
834 sprintf(dcl_mask, ".%s%s%s%s", dcl_x, dcl_y, dcl_z, dcl_w);
835 if (strcmp(dcl_mask, ".") == 0)
836 fprintf(out, "bad (empty) dcl mask\n");
839 fprintf(out, "bad T%d dcl register number\n", dcl_nr);
841 if (strcmp(dcl_mask, ".x") != 0 &&
842 strcmp(dcl_mask, ".xy") != 0 &&
843 strcmp(dcl_mask, ".xz") != 0 &&
844 strcmp(dcl_mask, ".w") != 0 &&
845 strcmp(dcl_mask, ".xyzw") != 0) {
846 fprintf(out, "bad T%d.%s dcl mask\n", dcl_nr,
849 instr_out(ctx, i++, "%s: DCL T%d%s\n",
850 instr_prefix, dcl_nr, dcl_mask);
852 if (strcmp(dcl_mask, ".xz") == 0)
853 fprintf(out, "errataed bad dcl mask %s\n",
855 else if (strcmp(dcl_mask, ".xw") == 0)
856 fprintf(out, "errataed bad dcl mask %s\n",
858 else if (strcmp(dcl_mask, ".xzw") == 0)
859 fprintf(out, "errataed bad dcl mask %s\n",
864 "%s: DCL DIFFUSE%s\n", instr_prefix,
866 } else if (dcl_nr == 9) {
868 "%s: DCL SPECULAR%s\n", instr_prefix,
870 } else if (dcl_nr == 10) {
872 "%s: DCL FOG%s\n", instr_prefix,
876 instr_out(ctx, i++, "%s\n", instr_prefix);
877 instr_out(ctx, i++, "%s\n", instr_prefix);
880 switch ((d0 >> 22) & 0x3) {
891 sampletype = "RESERVED";
895 fprintf(out, "bad S%d dcl register number\n", dcl_nr);
896 instr_out(ctx, i++, "%s: DCL S%d %s\n",
897 instr_prefix, dcl_nr, sampletype);
898 instr_out(ctx, i++, "%s\n", instr_prefix);
899 instr_out(ctx, i++, "%s\n", instr_prefix);
902 instr_out(ctx, i++, "%s: DCL RESERVED%d\n",
903 instr_prefix, dcl_nr);
904 instr_out(ctx, i++, "%s\n", instr_prefix);
905 instr_out(ctx, i++, "%s\n", instr_prefix);
910 i915_decode_instruction(struct drm_intel_decode *ctx,
911 int i, char *instr_prefix)
913 switch ((ctx->data[i] >> 24) & 0x1f) {
915 instr_out(ctx, i++, "%s: NOP\n", instr_prefix);
916 instr_out(ctx, i++, "%s\n", instr_prefix);
917 instr_out(ctx, i++, "%s\n", instr_prefix);
920 i915_decode_alu2(ctx, i, instr_prefix, "ADD");
923 i915_decode_alu1(ctx, i, instr_prefix, "MOV");
926 i915_decode_alu2(ctx, i, instr_prefix, "MUL");
929 i915_decode_alu3(ctx, i, instr_prefix, "MAD");
932 i915_decode_alu3(ctx, i, instr_prefix, "DP2ADD");
935 i915_decode_alu2(ctx, i, instr_prefix, "DP3");
938 i915_decode_alu2(ctx, i, instr_prefix, "DP4");
941 i915_decode_alu1(ctx, i, instr_prefix, "FRC");
944 i915_decode_alu1(ctx, i, instr_prefix, "RCP");
947 i915_decode_alu1(ctx, i, instr_prefix, "RSQ");
950 i915_decode_alu1(ctx, i, instr_prefix, "EXP");
953 i915_decode_alu1(ctx, i, instr_prefix, "LOG");
956 i915_decode_alu2(ctx, i, instr_prefix, "CMP");
959 i915_decode_alu2(ctx, i, instr_prefix, "MIN");
962 i915_decode_alu2(ctx, i, instr_prefix, "MAX");
965 i915_decode_alu1(ctx, i, instr_prefix, "FLR");
968 i915_decode_alu1(ctx, i, instr_prefix, "MOD");
971 i915_decode_alu1(ctx, i, instr_prefix, "TRC");
974 i915_decode_alu2(ctx, i, instr_prefix, "SGE");
977 i915_decode_alu2(ctx, i, instr_prefix, "SLT");
980 i915_decode_tex(ctx, i, instr_prefix, "TEXLD");
983 i915_decode_tex(ctx, i, instr_prefix, "TEXLDP");
986 i915_decode_tex(ctx, i, instr_prefix, "TEXLDB");
989 i915_decode_dcl(ctx, i, instr_prefix);
992 instr_out(ctx, i++, "%s: unknown\n", instr_prefix);
993 instr_out(ctx, i++, "%s\n", instr_prefix);
994 instr_out(ctx, i++, "%s\n", instr_prefix);
1000 decode_compare_func(uint32_t op)
1024 decode_stencil_op(uint32_t op)
1049 decode_logic_op(uint32_t op)
1090 decode_blend_fact(uint32_t op)
1100 return "inv_src_colr";
1104 return "inv_src_alpha";
1108 return "inv_dst_alpha";
1112 return "inv_dst_colr";
1114 return "src_alpha_sat";
1118 return "inv_cnst_colr";
1120 return "cnst_alpha";
1122 return "inv_const_alpha";
1128 decode_tex_coord_mode(uint32_t mode)
1130 switch (mode & 0x7) {
1136 return "clamp_edge";
1140 return "clamp_border";
1142 return "mirror_once";
1148 decode_sample_filter(uint32_t mode)
1150 switch (mode & 0x7) {
1156 return "anisotropic";
1170 decode_3d_1d(struct drm_intel_decode *ctx)
1172 unsigned int len, i, c, idx, word, map, sampler, instr;
1173 const char *format, *zformat, *type;
1175 uint32_t *data = ctx->data;
1176 uint32_t devid = ctx->devid;
1181 unsigned int min_len;
1182 unsigned int max_len;
1184 } opcodes_3d_1d[] = {
1185 { 0x86, 0, 4, 4, "3DSTATE_CHROMA_KEY" },
1186 { 0x88, 0, 2, 2, "3DSTATE_CONSTANT_BLEND_COLOR" },
1187 { 0x99, 0, 2, 2, "3DSTATE_DEFAULT_DIFFUSE" },
1188 { 0x9a, 0, 2, 2, "3DSTATE_DEFAULT_SPECULAR" },
1189 { 0x98, 0, 2, 2, "3DSTATE_DEFAULT_Z" },
1190 { 0x97, 0, 2, 2, "3DSTATE_DEPTH_OFFSET_SCALE" },
1191 { 0x9d, 0, 65, 65, "3DSTATE_FILTER_COEFFICIENTS_4X4" },
1192 { 0x9e, 0, 4, 4, "3DSTATE_MONO_FILTER" },
1193 { 0x89, 0, 4, 4, "3DSTATE_FOG_MODE" },
1194 { 0x8f, 0, 2, 16, "3DSTATE_MAP_PALLETE_LOAD_32" },
1195 { 0x83, 0, 2, 2, "3DSTATE_SPAN_STIPPLE" },
1196 { 0x8c, 1, 2, 2, "3DSTATE_MAP_COORD_TRANSFORM_I830" },
1197 { 0x8b, 1, 2, 2, "3DSTATE_MAP_VERTEX_TRANSFORM_I830" },
1198 { 0x8d, 1, 3, 3, "3DSTATE_W_STATE_I830" },
1199 { 0x01, 1, 2, 2, "3DSTATE_COLOR_FACTOR_I830" },
1200 { 0x02, 1, 2, 2, "3DSTATE_MAP_COORD_SETBIND_I830"},
1203 opcode = (data[0] & 0x00ff0000) >> 16;
1207 /* This instruction is unusual. A 0 length means just
1208 * 1 DWORD instead of 2. The 0 length is specified in
1209 * one place to be unsupported, but stated to be
1210 * required in another, and 0 length LOAD_INDIRECTs
1211 * appear to cause no harm at least.
1213 instr_out(ctx, 0, "3DSTATE_LOAD_INDIRECT\n");
1214 len = (data[0] & 0x000000ff) + 1;
1216 if (data[0] & (0x01 << 8)) {
1217 instr_out(ctx, i++, "SIS.0\n");
1218 instr_out(ctx, i++, "SIS.1\n");
1220 if (data[0] & (0x02 << 8)) {
1221 instr_out(ctx, i++, "DIS.0\n");
1223 if (data[0] & (0x04 << 8)) {
1224 instr_out(ctx, i++, "SSB.0\n");
1225 instr_out(ctx, i++, "SSB.1\n");
1227 if (data[0] & (0x08 << 8)) {
1228 instr_out(ctx, i++, "MSB.0\n");
1229 instr_out(ctx, i++, "MSB.1\n");
1231 if (data[0] & (0x10 << 8)) {
1232 instr_out(ctx, i++, "PSP.0\n");
1233 instr_out(ctx, i++, "PSP.1\n");
1235 if (data[0] & (0x20 << 8)) {
1236 instr_out(ctx, i++, "PSC.0\n");
1237 instr_out(ctx, i++, "PSC.1\n");
1240 fprintf(out, "Bad count in 3DSTATE_LOAD_INDIRECT\n");
1246 "3DSTATE_LOAD_STATE_IMMEDIATE_1\n");
1247 len = (data[0] & 0x0000000f) + 2;
1249 for (word = 0; word <= 8; word++) {
1250 if (data[0] & (1 << (4 + word))) {
1251 /* save vertex state for decode */
1252 if (!IS_GEN2(devid)) {
1267 "S0: vbo offset: 0x%08x%s\n",
1270 ", auto cache invalidate disabled"
1275 "S1: vertex width: %i, vertex pitch: %i\n",
1283 "S2: texcoord formats: ");
1285 tex_num < 8; tex_num++) {
1331 "S3: not documented\n");
1335 const char *cullmode = "";
1336 const char *vfmt_xyzw = "";
1337 switch ((data[i] >> 13)
1374 case 1 << 6 | 1 << 2:
1378 case 2 << 6 | 1 << 2:
1382 case 3 << 6 | 1 << 2:
1386 case 4 << 6 | 1 << 2:
1392 "S4: point_width=%i, line_width=%.1f,"
1393 "%s%s%s%s%s cullmode=%s, vfmt=%s%s%s%s%s%s "
1456 "force default diffuse, "
1462 "force default specular, "
1468 "local depth ofs enable, "
1474 "point sprite enable, "
1488 "%s%s%s%s stencil_ref=0x%x, stencil_test=%s, "
1489 "stencil_fail=%s, stencil_pass_z_fail=%s, "
1490 "stencil_pass_z_pass=%s, %s%s%s%s\n",
1520 " force default point size,"
1526 " last pixel enable,"
1532 " global depth ofs enable,"
1558 "stencil write enable, "
1564 "stencil test enable, "
1570 "color dither enable, "
1582 "S6: %salpha_test=%s, alpha_ref=0x%x, "
1583 "depth_test=%s, %ssrc_blnd_fct=%s, dst_blnd_fct=%s, "
1584 "%s%stristrip_provoking_vertex=%i\n",
1585 data[i] & (1 << 31) ?
1586 "alpha test enable, "
1594 data[i] & (1 << 15) ?
1595 "cbuf blend enable, "
1597 decode_blend_fact(data
1601 decode_blend_fact(data
1605 data[i] & (1 << 3) ?
1606 "depth write enable, "
1608 data[i] & (1 << 2) ?
1609 "cbuf write enable, "
1615 "S7: depth offset constant: 0x%08x\n",
1621 "S%d: 0x%08x\n", i, data[i]);
1628 "Bad count in 3DSTATE_LOAD_STATE_IMMEDIATE_1\n");
1633 "3DSTATE_LOAD_STATE_IMMEDIATE_2\n");
1634 len = (data[0] & 0x0000000f) + 2;
1636 for (word = 6; word <= 14; word++) {
1637 if (data[0] & (1 << word)) {
1641 else if (word >= 7 && word <= 10) {
1643 "TB%dC\n", word - 7);
1645 "TB%dA\n", word - 7);
1646 } else if (word >= 11 && word <= 14) {
1648 "TM%dS0: offset=0x%08x, %s\n",
1650 data[i] & 0xfffffffe,
1651 data[i] & 1 ? "use fence" :
1655 "TM%dS1: height=%i, width=%i, %s\n",
1656 word - 11, data[i] >> 21,
1657 (data[i] >> 10) & 0x3ff,
1658 data[i] & 2 ? (data[i] & 1 ?
1664 "TM%dS2: pitch=%i, \n",
1666 ((data[i] >> 21) + 1) * 4);
1669 "TM%dS3\n", word - 11);
1671 "TM%dS4: dflt color\n",
1678 "Bad count in 3DSTATE_LOAD_STATE_IMMEDIATE_2\n");
1682 instr_out(ctx, 0, "3DSTATE_MAP_STATE\n");
1683 len = (data[0] & 0x0000003f) + 2;
1684 instr_out(ctx, 1, "mask\n");
1687 for (map = 0; map <= 15; map++) {
1688 if (data[1] & (1 << map)) {
1689 int width, height, pitch, dword;
1694 "map %d MS2 %s%s%s\n", map,
1696 "untrusted surface, " : "",
1698 "vertical line stride enable, " : "",
1700 "vertical ofs enable, " : "");
1703 width = ((dword >> 10) & ((1 << 11) - 1)) + 1;
1704 height = ((dword >> 21) & ((1 << 11) - 1)) + 1;
1707 if (dword & (1 << 2))
1709 else if (dword & (1 << 1))
1710 tiling = dword & (1 << 0) ? "Y" : "X";
1713 switch ((dword >> 7) & 0x7) {
1716 switch ((dword >> 3) & 0xf) {
1733 switch ((dword >> 3) & 0xf) {
1738 format = " argb1555";
1741 format = " argb4444";
1747 format = " bump655";
1762 switch ((dword >> 3) & 0xf) {
1764 format = " argb8888";
1767 format = " abgr8888";
1770 format = " xrgb8888";
1773 format = " xbgr8888";
1776 format = " qwvu8888";
1779 format = " axvu8888";
1782 format = " lxvu8888";
1785 format = " xlvu8888";
1788 format = " argb2101010";
1791 format = " abgr2101010";
1794 format = " awvu2101010";
1815 switch ((dword >> 3) & 0xf) {
1817 format = " yuv_swapy";
1823 format = " yuv_swapuv";
1826 format = " yuv_swapuvy";
1831 type = "compressed";
1832 switch ((dword >> 3) & 0x7) {
1846 format = " dxt1_rb";
1851 type = "4b indexed";
1852 switch ((dword >> 3) & 0xf) {
1854 format = " argb8888";
1861 "map %d MS3 [width=%d, height=%d, format=%s%s, tiling=%s%s]\n",
1862 map, width, height, type, format,
1864 dword & (1 << 9) ? " palette select" :
1869 4 * (((dword >> 21) & ((1 << 11) - 1)) + 1);
1871 "map %d MS4 [pitch=%d, max_lod=%i, vol_depth=%i, cube_face_ena=%x, %s]\n",
1872 map, pitch, (dword >> 9) & 0x3f,
1873 dword & 0xff, (dword >> 15) & 0x3f,
1874 dword & (1 << 8) ? "miplayout legacy"
1875 : "miplayout right");
1879 fprintf(out, "Bad count in 3DSTATE_MAP_STATE\n");
1885 "3DSTATE_PIXEL_SHADER_CONSTANTS\n");
1886 len = (data[0] & 0x000000ff) + 2;
1889 for (c = 0; c <= 31; c++) {
1890 if (data[1] & (1 << c)) {
1891 instr_out(ctx, i, "C%d.X = %f\n", c,
1892 int_as_float(data[i]));
1894 instr_out(ctx, i, "C%d.Y = %f\n",
1895 c, int_as_float(data[i]));
1897 instr_out(ctx, i, "C%d.Z = %f\n",
1898 c, int_as_float(data[i]));
1900 instr_out(ctx, i, "C%d.W = %f\n",
1901 c, int_as_float(data[i]));
1907 "Bad count in 3DSTATE_PIXEL_SHADER_CONSTANTS\n");
1911 instr_out(ctx, 0, "3DSTATE_PIXEL_SHADER_PROGRAM\n");
1912 len = (data[0] & 0x000000ff) + 2;
1913 if ((len - 1) % 3 != 0 || len > 370) {
1915 "Bad count in 3DSTATE_PIXEL_SHADER_PROGRAM\n");
1918 for (instr = 0; instr < (len - 1) / 3; instr++) {
1919 char instr_prefix[10];
1921 sprintf(instr_prefix, "PS%03d", instr);
1922 i915_decode_instruction(ctx, i,
1930 instr_out(ctx, 0, "3DSTATE_SAMPLER_STATE\n");
1931 instr_out(ctx, 1, "mask\n");
1932 len = (data[0] & 0x0000003f) + 2;
1934 for (sampler = 0; sampler <= 15; sampler++) {
1935 if (data[1] & (1 << sampler)) {
1937 const char *mip_filter = "";
1940 switch ((dword >> 20) & 0x3) {
1942 mip_filter = "none";
1945 mip_filter = "nearest";
1948 mip_filter = "linear";
1952 "sampler %d SS2:%s%s%s "
1953 "base_mip_level=%i, mip_filter=%s, mag_filter=%s, min_filter=%s "
1954 "lod_bias=%.2f,%s max_aniso=%i, shadow_func=%s\n",
1956 dword & (1 << 31) ? " reverse gamma,"
1958 dword & (1 << 30) ? " packed2planar,"
1961 " colorspace conversion," : "",
1962 (dword >> 22) & 0x1f, mip_filter,
1963 decode_sample_filter(dword >> 17),
1964 decode_sample_filter(dword >> 14),
1965 ((dword >> 5) & 0x1ff) / (0x10 * 1.0),
1966 dword & (1 << 4) ? " shadow," : "",
1967 dword & (1 << 3) ? 4 : 2,
1968 decode_compare_func(dword));
1971 "sampler %d SS3: min_lod=%.2f,%s "
1972 "tcmode_x=%s, tcmode_y=%s, tcmode_z=%s,%s texmap_idx=%i,%s\n",
1974 ((dword >> 24) & 0xff) / (0x10 * 1.0),
1976 " kill pixel enable," : "",
1977 decode_tex_coord_mode(dword >> 12),
1978 decode_tex_coord_mode(dword >> 9),
1979 decode_tex_coord_mode(dword >> 6),
1981 " normalized coords," : "",
1983 dword & (1 << 0) ? " deinterlacer," :
1987 "sampler %d SS4: border color\n",
1992 fprintf(out, "Bad count in 3DSTATE_SAMPLER_STATE\n");
1996 len = (data[0] & 0x0000000f) + 2;
2000 "Bad count in 3DSTATE_DEST_BUFFER_VARIABLES\n");
2003 "3DSTATE_DEST_BUFFER_VARIABLES\n");
2005 switch ((data[1] >> 8) & 0xf) {
2010 format = "x1r5g5b5";
2016 format = "a8r8g8b8";
2019 format = "ycrcb_swapy";
2022 format = "ycrcb_normal";
2025 format = "ycrcb_swapuv";
2028 format = "ycrcb_swapuvy";
2031 format = "a4r4g4b4";
2034 format = "a1r5g5b5";
2037 format = "a2r10g10b10";
2043 switch ((data[1] >> 2) & 0x3) {
2058 "%s format, %s depth format, early Z %sabled\n",
2060 (data[1] & (1 << 31)) ? "en" : "dis");
2065 const char *name, *tiling;
2067 len = (data[0] & 0x0000000f) + 2;
2070 "Bad count in 3DSTATE_BUFFER_INFO\n");
2072 switch ((data[1] >> 24) & 0x7) {
2085 if (data[1] & (1 << 23))
2087 else if (data[1] & (1 << 22))
2088 tiling = data[1] & (1 << 21) ? "Y" : "X";
2090 instr_out(ctx, 0, "3DSTATE_BUFFER_INFO\n");
2092 "%s, tiling = %s, pitch=%d\n", name, tiling,
2095 instr_out(ctx, 2, "address\n");
2099 len = (data[0] & 0x0000000f) + 2;
2103 "Bad count in 3DSTATE_SCISSOR_RECTANGLE\n");
2105 instr_out(ctx, 0, "3DSTATE_SCISSOR_RECTANGLE\n");
2106 instr_out(ctx, 1, "(%d,%d)\n",
2107 data[1] & 0xffff, data[1] >> 16);
2108 instr_out(ctx, 2, "(%d,%d)\n",
2109 data[2] & 0xffff, data[2] >> 16);
2113 len = (data[0] & 0x0000000f) + 2;
2117 "Bad count in 3DSTATE_DRAWING_RECTANGLE\n");
2119 instr_out(ctx, 0, "3DSTATE_DRAWING_RECTANGLE\n");
2120 instr_out(ctx, 1, "%s\n",
2121 data[1] & (1 << 30) ? "depth ofs disabled " : "");
2122 instr_out(ctx, 2, "(%d,%d)\n",
2123 data[2] & 0xffff, data[2] >> 16);
2124 instr_out(ctx, 3, "(%d,%d)\n",
2125 data[3] & 0xffff, data[3] >> 16);
2126 instr_out(ctx, 4, "(%d,%d)\n",
2127 data[4] & 0xffff, data[4] >> 16);
2131 len = (data[0] & 0x0000000f) + 2;
2134 fprintf(out, "Bad count in 3DSTATE_CLEAR_PARAMETERS\n");
2136 instr_out(ctx, 0, "3DSTATE_CLEAR_PARAMETERS\n");
2137 instr_out(ctx, 1, "prim_type=%s, clear=%s%s%s\n",
2138 data[1] & (1 << 16) ? "CLEAR_RECT" : "ZONE_INIT",
2139 data[1] & (1 << 2) ? "color," : "",
2140 data[1] & (1 << 1) ? "depth," : "",
2141 data[1] & (1 << 0) ? "stencil," : "");
2142 instr_out(ctx, 2, "clear color\n");
2143 instr_out(ctx, 3, "clear depth/stencil\n");
2144 instr_out(ctx, 4, "color value (rgba8888)\n");
2145 instr_out(ctx, 5, "depth value %f\n",
2146 int_as_float(data[5]));
2147 instr_out(ctx, 6, "clear stencil\n");
2151 for (idx = 0; idx < ARRAY_SIZE(opcodes_3d_1d); idx++) {
2152 opcode_3d_1d = &opcodes_3d_1d[idx];
2153 if (opcode_3d_1d->i830_only && !IS_GEN2(devid))
2156 if (((data[0] & 0x00ff0000) >> 16) == opcode_3d_1d->opcode) {
2159 instr_out(ctx, 0, "%s\n",
2160 opcode_3d_1d->name);
2161 if (opcode_3d_1d->max_len > 1) {
2162 len = (data[0] & 0x0000ffff) + 2;
2163 if (len < opcode_3d_1d->min_len ||
2164 len > opcode_3d_1d->max_len) {
2165 fprintf(out, "Bad count in %s\n",
2166 opcode_3d_1d->name);
2170 for (i = 1; i < len; i++) {
2171 instr_out(ctx, i, "dword %d\n", i);
2178 instr_out(ctx, 0, "3D UNKNOWN: 3d_1d opcode = 0x%x\n",
2184 decode_3d_primitive(struct drm_intel_decode *ctx)
2186 uint32_t *data = ctx->data;
2187 uint32_t count = ctx->count;
2188 char immediate = (data[0] & (1 << 23)) == 0;
2189 unsigned int len, i, j, ret;
2190 const char *primtype;
2191 int original_s2 = saved_s2;
2192 int original_s4 = saved_s4;
2194 switch ((data[0] >> 18) & 0xf) {
2196 primtype = "TRILIST";
2199 primtype = "TRISTRIP";
2202 primtype = "TRISTRIP_REVERSE";
2205 primtype = "TRIFAN";
2208 primtype = "POLYGON";
2211 primtype = "LINELIST";
2214 primtype = "LINESTRIP";
2217 primtype = "RECTLIST";
2220 primtype = "POINTLIST";
2226 primtype = "CLEAR_RECT";
2231 primtype = "unknown";
2235 /* XXX: 3DPRIM_DIB not supported */
2237 len = (data[0] & 0x0003ffff) + 2;
2238 instr_out(ctx, 0, "3DPRIMITIVE inline %s\n",
2241 BUFFER_FAIL(count, len, "3DPRIMITIVE inline");
2242 if (!saved_s2_set || !saved_s4_set) {
2243 fprintf(out, "unknown vertex format\n");
2244 for (i = 1; i < len; i++) {
2246 " vertex data (%f float)\n",
2247 int_as_float(data[i]));
2250 unsigned int vertex = 0;
2251 for (i = 1; i < len;) {
2254 #define VERTEX_OUT(fmt, ...) do { \
2256 instr_out(ctx, i, " V%d."fmt"\n", vertex, __VA_ARGS__); \
2258 fprintf(out, " missing data in V%d\n", vertex); \
2262 VERTEX_OUT("X = %f", int_as_float(data[i]));
2263 VERTEX_OUT("Y = %f", int_as_float(data[i]));
2264 switch (saved_s4 >> 6 & 0x7) {
2266 VERTEX_OUT("Z = %f",
2267 int_as_float(data[i]));
2270 VERTEX_OUT("Z = %f",
2271 int_as_float(data[i]));
2272 VERTEX_OUT("W = %f",
2273 int_as_float(data[i]));
2278 VERTEX_OUT("W = %f",
2279 int_as_float(data[i]));
2282 fprintf(out, "bad S4 position mask\n");
2285 if (saved_s4 & (1 << 10)) {
2287 ("color = (A=0x%02x, R=0x%02x, G=0x%02x, "
2288 "B=0x%02x)", data[i] >> 24,
2289 (data[i] >> 16) & 0xff,
2290 (data[i] >> 8) & 0xff,
2293 if (saved_s4 & (1 << 11)) {
2295 ("spec = (A=0x%02x, R=0x%02x, G=0x%02x, "
2296 "B=0x%02x)", data[i] >> 24,
2297 (data[i] >> 16) & 0xff,
2298 (data[i] >> 8) & 0xff,
2301 if (saved_s4 & (1 << 12))
2302 VERTEX_OUT("width = 0x%08x)", data[i]);
2304 for (tc = 0; tc <= 7; tc++) {
2305 switch ((saved_s2 >> (tc * 4)) & 0xf) {
2307 VERTEX_OUT("T%d.X = %f", tc,
2310 VERTEX_OUT("T%d.Y = %f", tc,
2315 VERTEX_OUT("T%d.X = %f", tc,
2318 VERTEX_OUT("T%d.Y = %f", tc,
2321 VERTEX_OUT("T%d.Z = %f", tc,
2326 VERTEX_OUT("T%d.X = %f", tc,
2329 VERTEX_OUT("T%d.Y = %f", tc,
2332 VERTEX_OUT("T%d.Z = %f", tc,
2335 VERTEX_OUT("T%d.W = %f", tc,
2340 VERTEX_OUT("T%d.X = %f", tc,
2346 ("T%d.XY = 0x%08x half-float",
2351 ("T%d.XY = 0x%08x half-float",
2354 ("T%d.ZW = 0x%08x half-float",
2361 "bad S2.T%d format\n",
2371 /* indirect vertices */
2372 len = data[0] & 0x0000ffff; /* index count */
2373 if (data[0] & (1 << 17)) {
2374 /* random vertex access */
2375 if (count < (len + 1) / 2 + 1) {
2376 BUFFER_FAIL(count, (len + 1) / 2 + 1,
2377 "3DPRIMITIVE random indirect");
2380 "3DPRIMITIVE random indirect %s (%d)\n",
2383 /* vertex indices continue until 0xffff is
2386 for (i = 1; i < count; i++) {
2387 if ((data[i] & 0xffff) == 0xffff) {
2389 " indices: (terminator)\n");
2392 } else if ((data[i] >> 16) == 0xffff) {
2394 " indices: 0x%04x, (terminator)\n",
2400 " indices: 0x%04x, 0x%04x\n",
2406 "3DPRIMITIVE: no terminator found in index buffer\n");
2410 /* fixed size vertex index buffer */
2411 for (j = 1, i = 0; i < len; i += 2, j++) {
2412 if (i * 2 == len - 1) {
2414 " indices: 0x%04x\n",
2418 " indices: 0x%04x, 0x%04x\n",
2424 ret = (len + 1) / 2 + 1;
2427 /* sequential vertex access */
2429 "3DPRIMITIVE sequential indirect %s, %d starting from "
2430 "%d\n", primtype, len, data[1] & 0xffff);
2431 instr_out(ctx, 1, " start\n");
2438 saved_s2 = original_s2;
2439 saved_s4 = original_s4;
2444 decode_3d(struct drm_intel_decode *ctx)
2448 uint32_t *data = ctx->data;
2452 unsigned int min_len;
2453 unsigned int max_len;
2456 { 0x06, 1, 1, "3DSTATE_ANTI_ALIASING" },
2457 { 0x08, 1, 1, "3DSTATE_BACKFACE_STENCIL_OPS" },
2458 { 0x09, 1, 1, "3DSTATE_BACKFACE_STENCIL_MASKS" },
2459 { 0x16, 1, 1, "3DSTATE_COORD_SET_BINDINGS" },
2460 { 0x15, 1, 1, "3DSTATE_FOG_COLOR" },
2461 { 0x0b, 1, 1, "3DSTATE_INDEPENDENT_ALPHA_BLEND" },
2462 { 0x0d, 1, 1, "3DSTATE_MODES_4" },
2463 { 0x0c, 1, 1, "3DSTATE_MODES_5" },
2464 { 0x07, 1, 1, "3DSTATE_RASTERIZATION_RULES"},
2467 opcode = (data[0] & 0x1f000000) >> 24;
2471 return decode_3d_primitive(ctx);
2473 return decode_3d_1d(ctx);
2475 return decode_3d_1c(ctx);
2478 for (idx = 0; idx < ARRAY_SIZE(opcodes_3d); idx++) {
2479 opcode_3d = &opcodes_3d[idx];
2480 if (opcode == opcode_3d->opcode) {
2481 unsigned int len = 1, i;
2483 instr_out(ctx, 0, "%s\n", opcode_3d->name);
2484 if (opcode_3d->max_len > 1) {
2485 len = (data[0] & 0xff) + 2;
2486 if (len < opcode_3d->min_len ||
2487 len > opcode_3d->max_len) {
2488 fprintf(out, "Bad count in %s\n",
2493 for (i = 1; i < len; i++) {
2494 instr_out(ctx, i, "dword %d\n", i);
2500 instr_out(ctx, 0, "3D UNKNOWN: 3d opcode = 0x%x\n", opcode);
2504 static const char *get_965_surfacetype(unsigned int surfacetype)
2506 switch (surfacetype) {
2524 static const char *get_965_depthformat(unsigned int depthformat)
2526 switch (depthformat) {
2528 return "s8_z24float";
2540 static const char *get_965_element_component(uint32_t data, int component)
2542 uint32_t component_control = (data >> (16 + (3 - component) * 4)) & 0x7;
2544 switch (component_control) {
2548 switch (component) {
2573 static const char *get_965_prim_type(uint32_t data)
2575 uint32_t primtype = (data >> 10) & 0x1f;
2579 return "point list";
2583 return "line strip";
2593 return "quad strip";
2595 return "line list adj";
2597 return "line strip adj";
2599 return "tri list adj";
2601 return "tri strip adj";
2603 return "tri strip reverse";
2611 return "point list bf";
2613 return "line strip cont";
2615 return "line strip bf";
2617 return "line strip cont bf";
2619 return "tri fan no stipple";
2626 i965_decode_urb_fence(struct drm_intel_decode *ctx, int len)
2628 uint32_t vs_fence, clip_fence, gs_fence, sf_fence, vfe_fence, cs_fence;
2629 uint32_t *data = ctx->data;
2632 fprintf(out, "Bad count in URB_FENCE\n");
2634 vs_fence = data[1] & 0x3ff;
2635 gs_fence = (data[1] >> 10) & 0x3ff;
2636 clip_fence = (data[1] >> 20) & 0x3ff;
2637 sf_fence = data[2] & 0x3ff;
2638 vfe_fence = (data[2] >> 10) & 0x3ff;
2639 cs_fence = (data[2] >> 20) & 0x7ff;
2641 instr_out(ctx, 0, "URB_FENCE: %s%s%s%s%s%s\n",
2642 (data[0] >> 13) & 1 ? "cs " : "",
2643 (data[0] >> 12) & 1 ? "vfe " : "",
2644 (data[0] >> 11) & 1 ? "sf " : "",
2645 (data[0] >> 10) & 1 ? "clip " : "",
2646 (data[0] >> 9) & 1 ? "gs " : "",
2647 (data[0] >> 8) & 1 ? "vs " : "");
2649 "vs fence: %d, clip_fence: %d, gs_fence: %d\n",
2650 vs_fence, clip_fence, gs_fence);
2652 "sf fence: %d, vfe_fence: %d, cs_fence: %d\n",
2653 sf_fence, vfe_fence, cs_fence);
2654 if (gs_fence < vs_fence)
2655 fprintf(out, "gs fence < vs fence!\n");
2656 if (clip_fence < gs_fence)
2657 fprintf(out, "clip fence < gs fence!\n");
2658 if (sf_fence < clip_fence)
2659 fprintf(out, "sf fence < clip fence!\n");
2660 if (cs_fence < sf_fence)
2661 fprintf(out, "cs fence < sf fence!\n");
2667 state_base_out(struct drm_intel_decode *ctx, unsigned int index,
2670 if (ctx->data[index] & 1) {
2671 instr_out(ctx, index,
2672 "%s state base address 0x%08x\n", name,
2673 ctx->data[index] & ~1);
2675 instr_out(ctx, index, "%s state base not updated\n",
2681 state_max_out(struct drm_intel_decode *ctx, unsigned int index,
2684 if (ctx->data[index] & 1) {
2685 if (ctx->data[index] == 1) {
2686 instr_out(ctx, index,
2687 "%s state upper bound disabled\n", name);
2689 instr_out(ctx, index,
2690 "%s state upper bound 0x%08x\n", name,
2691 ctx->data[index] & ~1);
2694 instr_out(ctx, index,
2695 "%s state upper bound not updated\n", name);
2700 decode_3d_965(struct drm_intel_decode *ctx)
2703 unsigned int idx, len;
2704 unsigned int i, j, sba_len;
2705 const char *desc1 = NULL;
2706 uint32_t *data = ctx->data;
2707 uint32_t devid = ctx->devid;
2711 int unsigned min_len;
2712 int unsigned max_len;
2715 { 0x6000, 3, 3, "URB_FENCE" },
2716 { 0x6001, 2, 2, "CS_URB_STATE" },
2717 { 0x6002, 2, 2, "CONSTANT_BUFFER" },
2718 { 0x6101, 6, 6, "STATE_BASE_ADDRESS" },
2719 { 0x6102, 2, 2, "STATE_SIP" },
2720 { 0x6104, 1, 1, "3DSTATE_PIPELINE_SELECT" },
2721 { 0x680b, 1, 1, "3DSTATE_VF_STATISTICS" },
2722 { 0x6904, 1, 1, "3DSTATE_PIPELINE_SELECT" },
2723 { 0x7800, 7, 7, "3DSTATE_PIPELINED_POINTERS" },
2724 { 0x7801, 6, 6, "3DSTATE_BINDING_TABLE_POINTERS" },
2725 { 0x7808, 5, 257, "3DSTATE_VERTEX_BUFFERS" },
2726 { 0x7809, 3, 256, "3DSTATE_VERTEX_ELEMENTS" },
2727 { 0x780a, 3, 3, "3DSTATE_INDEX_BUFFER" },
2728 { 0x780b, 1, 1, "3DSTATE_VF_STATISTICS" },
2729 { 0x7900, 4, 4, "3DSTATE_DRAWING_RECTANGLE" },
2730 { 0x7901, 5, 5, "3DSTATE_CONSTANT_COLOR" },
2731 { 0x7905, 5, 7, "3DSTATE_DEPTH_BUFFER" },
2732 { 0x7906, 2, 2, "3DSTATE_POLY_STIPPLE_OFFSET" },
2733 { 0x7907, 33, 33, "3DSTATE_POLY_STIPPLE_PATTERN" },
2734 { 0x7908, 3, 3, "3DSTATE_LINE_STIPPLE" },
2735 { 0x7909, 2, 2, "3DSTATE_GLOBAL_DEPTH_OFFSET_CLAMP" },
2736 { 0x7909, 2, 2, "3DSTATE_CLEAR_PARAMS" },
2737 { 0x790a, 3, 3, "3DSTATE_AA_LINE_PARAMETERS" },
2738 { 0x790b, 4, 4, "3DSTATE_GS_SVB_INDEX" },
2739 { 0x790d, 3, 3, "3DSTATE_MULTISAMPLE" },
2740 { 0x7910, 2, 2, "3DSTATE_CLEAR_PARAMS" },
2741 { 0x7b00, 6, 6, "3DPRIMITIVE" },
2742 { 0x7802, 4, 4, "3DSTATE_SAMPLER_STATE_POINTERS" },
2743 { 0x7805, 3, 3, "3DSTATE_URB" },
2744 { 0x780d, 4, 4, "3DSTATE_VIEWPORT_STATE_POINTERS" },
2745 { 0x780e, 4, 4, "3DSTATE_CC_STATE_POINTERS" },
2746 { 0x780f, 2, 2, "3DSTATE_SCISSOR_STATE_POINTERS" },
2747 { 0x7810, 6, 6, "3DSTATE_VS_STATE" },
2748 { 0x7811, 7, 7, "3DSTATE_GS_STATE" },
2749 { 0x7812, 4, 4, "3DSTATE_CLIP_STATE" },
2750 { 0x7813, 20, 20, "3DSTATE_SF_STATE" },
2751 { 0x7814, 9, 9, "3DSTATE_WM_STATE" },
2752 { 0x7815, 5, 5, "3DSTATE_CONSTANT_VS_STATE" },
2753 { 0x7816, 5, 5, "3DSTATE_CONSTANT_GS_STATE" },
2754 { 0x7817, 5, 5, "3DSTATE_CONSTANT_PS_STATE" },
2755 { 0x7818, 2, 2, "3DSTATE_SAMPLE_MASK"},
2758 len = (data[0] & 0x0000ffff) + 2;
2760 opcode = (data[0] & 0xffff0000) >> 16;
2763 len = (data[0] & 0x000000ff) + 2;
2764 return i965_decode_urb_fence(ctx, len);
2766 instr_out(ctx, 0, "CS_URB_STATE\n");
2768 "entry_size: %d [%d bytes], n_entries: %d\n",
2769 (data[1] >> 4) & 0x1f,
2770 (((data[1] >> 4) & 0x1f) + 1) * 64, data[1] & 0x7);
2773 len = (data[0] & 0x000000ff) + 2;
2774 instr_out(ctx, 0, "CONSTANT_BUFFER: %s\n",
2775 (data[0] >> 8) & 1 ? "valid" : "invalid");
2777 "offset: 0x%08x, length: %d bytes\n", data[1] & ~0x3f,
2778 ((data[1] & 0x3f) + 1) * 64);
2782 instr_out(ctx, 0, "STATE_BASE_ADDRESS\n");
2785 if (IS_GEN6(devid) || IS_GEN7(devid))
2787 else if (IS_GEN5(devid))
2792 fprintf(out, "Bad count in STATE_BASE_ADDRESS\n");
2794 state_base_out(ctx, i++, "general");
2795 state_base_out(ctx, i++, "surface");
2796 if (IS_GEN6(devid) || IS_GEN7(devid))
2797 state_base_out(ctx, i++, "dynamic");
2798 state_base_out(ctx, i++, "indirect");
2799 if (IS_GEN5(devid) || IS_GEN6(devid) || IS_GEN7(devid))
2800 state_base_out(ctx, i++, "instruction");
2802 state_max_out(ctx, i++, "general");
2803 if (IS_GEN6(devid) || IS_GEN7(devid))
2804 state_max_out(ctx, i++, "dynamic");
2805 state_max_out(ctx, i++, "indirect");
2806 if (IS_GEN5(devid) || IS_GEN6(devid) || IS_GEN7(devid))
2807 state_max_out(ctx, i++, "instruction");
2813 "Bad count in 3DSTATE_PIPELINED_POINTERS\n");
2815 instr_out(ctx, 0, "3DSTATE_PIPELINED_POINTERS\n");
2816 instr_out(ctx, 1, "VS state\n");
2817 instr_out(ctx, 2, "GS state\n");
2818 instr_out(ctx, 3, "Clip state\n");
2819 instr_out(ctx, 4, "SF state\n");
2820 instr_out(ctx, 5, "WM state\n");
2821 instr_out(ctx, 6, "CC state\n");
2824 len = (data[0] & 0x000000ff) + 2;
2825 if (len != 6 && len != 4)
2827 "Bad count in 3DSTATE_BINDING_TABLE_POINTERS\n");
2830 "3DSTATE_BINDING_TABLE_POINTERS\n");
2831 instr_out(ctx, 1, "VS binding table\n");
2832 instr_out(ctx, 2, "GS binding table\n");
2833 instr_out(ctx, 3, "Clip binding table\n");
2834 instr_out(ctx, 4, "SF binding table\n");
2835 instr_out(ctx, 5, "WM binding table\n");
2838 "3DSTATE_BINDING_TABLE_POINTERS: VS mod %d, "
2839 "GS mod %d, PS mod %d\n",
2840 (data[0] & (1 << 8)) != 0,
2841 (data[0] & (1 << 9)) != 0,
2842 (data[0] & (1 << 12)) != 0);
2843 instr_out(ctx, 1, "VS binding table\n");
2844 instr_out(ctx, 2, "GS binding table\n");
2845 instr_out(ctx, 3, "WM binding table\n");
2850 len = (data[0] & 0xff) + 2;
2853 "Bad count in 3DSTATE_SAMPLER_STATE_POINTERS\n");
2855 "3DSTATE_SAMPLER_STATE_POINTERS: VS mod %d, "
2856 "GS mod %d, PS mod %d\n", (data[0] & (1 << 8)) != 0,
2857 (data[0] & (1 << 9)) != 0,
2858 (data[0] & (1 << 12)) != 0);
2859 instr_out(ctx, 1, "VS sampler state\n");
2860 instr_out(ctx, 2, "GS sampler state\n");
2861 instr_out(ctx, 3, "WM sampler state\n");
2864 len = (data[0] & 0xff) + 2;
2866 fprintf(out, "Bad count in 3DSTATE_URB\n");
2867 instr_out(ctx, 0, "3DSTATE_URB\n");
2869 "VS entries %d, alloc size %d (1024bit row)\n",
2870 data[1] & 0xffff, ((data[1] >> 16) & 0x07f) + 1);
2872 "GS entries %d, alloc size %d (1024bit row)\n",
2873 (data[2] >> 8) & 0x3ff, (data[2] & 7) + 1);
2877 len = (data[0] & 0xff) + 2;
2878 if ((len - 1) % 4 != 0)
2879 fprintf(out, "Bad count in 3DSTATE_VERTEX_BUFFERS\n");
2880 instr_out(ctx, 0, "3DSTATE_VERTEX_BUFFERS\n");
2882 for (i = 1; i < len;) {
2884 if (IS_GEN6(devid)) {
2892 "buffer %d: %s, pitch %db\n", data[i] >> idx,
2893 data[i] & (1 << access) ? "random" :
2894 "sequential", data[i] & 0x07ff);
2896 instr_out(ctx, i++, "buffer address\n");
2897 instr_out(ctx, i++, "max index\n");
2898 instr_out(ctx, i++, "mbz\n");
2903 len = (data[0] & 0xff) + 2;
2904 if ((len + 1) % 2 != 0)
2905 fprintf(out, "Bad count in 3DSTATE_VERTEX_ELEMENTS\n");
2906 instr_out(ctx, 0, "3DSTATE_VERTEX_ELEMENTS\n");
2908 for (i = 1; i < len;) {
2910 "buffer %d: %svalid, type 0x%04x, "
2911 "src offset 0x%04x bytes\n",
2912 data[i] >> (IS_GEN6(devid) ? 26 : 27),
2913 data[i] & (1 << (IS_GEN6(devid) ? 25 : 26)) ?
2914 "" : "in", (data[i] >> 16) & 0x1ff,
2917 instr_out(ctx, i, "(%s, %s, %s, %s), "
2918 "dst offset 0x%02x bytes\n",
2919 get_965_element_component(data[i], 0),
2920 get_965_element_component(data[i], 1),
2921 get_965_element_component(data[i], 2),
2922 get_965_element_component(data[i], 3),
2923 (data[i] & 0xff) * 4);
2929 len = (data[0] & 0xff) + 2;
2932 "Bad count in 3DSTATE_VIEWPORT_STATE_POINTERS\n");
2934 "3DSTATE_VIEWPORT_STATE_POINTERS\n");
2935 instr_out(ctx, 1, "clip\n");
2936 instr_out(ctx, 2, "sf\n");
2937 instr_out(ctx, 3, "cc\n");
2941 len = (data[0] & 0xff) + 2;
2943 fprintf(out, "Bad count in 3DSTATE_INDEX_BUFFER\n");
2944 instr_out(ctx, 0, "3DSTATE_INDEX_BUFFER\n");
2945 instr_out(ctx, 1, "beginning buffer address\n");
2946 instr_out(ctx, 2, "ending buffer address\n");
2950 len = (data[0] & 0xff) + 2;
2953 "Bad count in 3DSTATE_CC_STATE_POINTERS\n");
2954 instr_out(ctx, 0, "3DSTATE_CC_STATE_POINTERS\n");
2955 instr_out(ctx, 1, "blend change %d\n", data[1] & 1);
2956 instr_out(ctx, 2, "depth stencil change %d\n",
2958 instr_out(ctx, 3, "cc change %d\n", data[3] & 1);
2962 len = (data[0] & 0xff) + 2;
2964 fprintf(out, "Bad count in 3DSTATE_SCISSOR_POINTERS\n");
2965 instr_out(ctx, 0, "3DSTATE_SCISSOR_POINTERS\n");
2966 instr_out(ctx, 1, "scissor rect offset\n");
2970 len = (data[0] & 0xff) + 2;
2972 fprintf(out, "Bad count in 3DSTATE_VS\n");
2973 instr_out(ctx, 0, "3DSTATE_VS\n");
2974 instr_out(ctx, 1, "kernel pointer\n");
2976 "SPF=%d, VME=%d, Sampler Count %d, "
2977 "Binding table count %d\n", (data[2] >> 31) & 1,
2978 (data[2] >> 30) & 1, (data[2] >> 27) & 7,
2979 (data[2] >> 18) & 0xff);
2980 instr_out(ctx, 3, "scratch offset\n");
2982 "Dispatch GRF start %d, VUE read length %d, "
2983 "VUE read offset %d\n", (data[4] >> 20) & 0x1f,
2984 (data[4] >> 11) & 0x3f, (data[4] >> 4) & 0x3f);
2986 "Max Threads %d, Vertex Cache %sable, "
2987 "VS func %sable\n", ((data[5] >> 25) & 0x7f) + 1,
2988 (data[5] & (1 << 1)) != 0 ? "dis" : "en",
2989 (data[5] & 1) != 0 ? "en" : "dis");
2993 len = (data[0] & 0xff) + 2;
2995 fprintf(out, "Bad count in 3DSTATE_GS\n");
2996 instr_out(ctx, 0, "3DSTATE_GS\n");
2997 instr_out(ctx, 1, "kernel pointer\n");
2999 "SPF=%d, VME=%d, Sampler Count %d, "
3000 "Binding table count %d\n", (data[2] >> 31) & 1,
3001 (data[2] >> 30) & 1, (data[2] >> 27) & 7,
3002 (data[2] >> 18) & 0xff);
3003 instr_out(ctx, 3, "scratch offset\n");
3005 "Dispatch GRF start %d, VUE read length %d, "
3006 "VUE read offset %d\n", (data[4] & 0xf),
3007 (data[4] >> 11) & 0x3f, (data[4] >> 4) & 0x3f);
3009 "Max Threads %d, Rendering %sable\n",
3010 ((data[5] >> 25) & 0x7f) + 1,
3011 (data[5] & (1 << 8)) != 0 ? "en" : "dis");
3013 "Reorder %sable, Discard Adjaceny %sable, "
3015 (data[6] & (1 << 30)) != 0 ? "en" : "dis",
3016 (data[6] & (1 << 29)) != 0 ? "en" : "dis",
3017 (data[6] & (1 << 15)) != 0 ? "en" : "dis");
3021 len = (data[0] & 0xff) + 2;
3023 fprintf(out, "Bad count in 3DSTATE_CLIP\n");
3024 instr_out(ctx, 0, "3DSTATE_CLIP\n");
3026 "UserClip distance cull test mask 0x%x\n",
3029 "Clip %sable, API mode %s, Viewport XY test %sable, "
3030 "Viewport Z test %sable, Guardband test %sable, Clip mode %d, "
3031 "Perspective Divide %sable, Non-Perspective Barycentric %sable, "
3032 "Tri Provoking %d, Line Provoking %d, Trifan Provoking %d\n",
3033 (data[2] & (1 << 31)) != 0 ? "en" : "dis",
3034 (data[2] & (1 << 30)) != 0 ? "D3D" : "OGL",
3035 (data[2] & (1 << 28)) != 0 ? "en" : "dis",
3036 (data[2] & (1 << 27)) != 0 ? "en" : "dis",
3037 (data[2] & (1 << 26)) != 0 ? "en" : "dis",
3038 (data[2] >> 13) & 7,
3039 (data[2] & (1 << 9)) != 0 ? "dis" : "en",
3040 (data[2] & (1 << 8)) != 0 ? "en" : "dis",
3041 (data[2] >> 4) & 3, (data[2] >> 2) & 3,
3044 "Min PointWidth %d, Max PointWidth %d, "
3045 "Force Zero RTAIndex %sable, Max VPIndex %d\n",
3046 (data[3] >> 17) & 0x7ff, (data[3] >> 6) & 0x7ff,
3047 (data[3] & (1 << 5)) != 0 ? "en" : "dis",
3052 len = (data[0] & 0xff) + 2;
3054 fprintf(out, "Bad count in 3DSTATE_SF\n");
3055 instr_out(ctx, 0, "3DSTATE_SF\n");
3057 "Attrib Out %d, Attrib Swizzle %sable, VUE read length %d, "
3058 "VUE read offset %d\n", (data[1] >> 22) & 0x3f,
3059 (data[1] & (1 << 21)) != 0 ? "en" : "dis",
3060 (data[1] >> 11) & 0x1f, (data[1] >> 4) & 0x3f);
3062 "Legacy Global DepthBias %sable, FrontFace fill %d, BF fill %d, "
3063 "VP transform %sable, FrontWinding_%s\n",
3064 (data[2] & (1 << 11)) != 0 ? "en" : "dis",
3065 (data[2] >> 5) & 3, (data[2] >> 3) & 3,
3066 (data[2] & (1 << 1)) != 0 ? "en" : "dis",
3067 (data[2] & 1) != 0 ? "CCW" : "CW");
3069 "AA %sable, CullMode %d, Scissor %sable, Multisample m ode %d\n",
3070 (data[3] & (1 << 31)) != 0 ? "en" : "dis",
3071 (data[3] >> 29) & 3,
3072 (data[3] & (1 << 11)) != 0 ? "en" : "dis",
3073 (data[3] >> 8) & 3);
3075 "Last Pixel %sable, SubPixel Precision %d, Use PixelWidth %d\n",
3076 (data[4] & (1 << 31)) != 0 ? "en" : "dis",
3077 (data[4] & (1 << 12)) != 0 ? 4 : 8,
3078 (data[4] & (1 << 11)) != 0);
3080 "Global Depth Offset Constant %f\n",
3081 *(float *)(&data[5]));
3082 instr_out(ctx, 6, "Global Depth Offset Scale %f\n",
3083 *(float *)(&data[6]));
3084 instr_out(ctx, 7, "Global Depth Offset Clamp %f\n",
3085 *(float *)(&data[7]));
3087 for (i = 0, j = 0; i < 8; i++, j += 2)
3088 instr_out(ctx, i + 8,
3089 "Attrib %d (Override %s%s%s%s, Const Source %d, Swizzle Select %d, "
3090 "Source %d); Attrib %d (Override %s%s%s%s, Const Source %d, Swizzle Select %d, Source %d)\n",
3092 (data[8 + i] & (1 << 31)) != 0 ? "W" : "",
3093 (data[8 + i] & (1 << 30)) != 0 ? "Z" : "",
3094 (data[8 + i] & (1 << 29)) != 0 ? "Y" : "",
3095 (data[8 + i] & (1 << 28)) != 0 ? "X" : "",
3096 (data[8 + i] >> 25) & 3,
3097 (data[8 + i] >> 22) & 3,
3098 (data[8 + i] >> 16) & 0x1f, j,
3099 (data[8 + i] & (1 << 15)) != 0 ? "W" : "",
3100 (data[8 + i] & (1 << 14)) != 0 ? "Z" : "",
3101 (data[8 + i] & (1 << 13)) != 0 ? "Y" : "",
3102 (data[8 + i] & (1 << 12)) != 0 ? "X" : "",
3103 (data[8 + i] >> 9) & 3,
3104 (data[8 + i] >> 6) & 3, (data[8 + i] & 0x1f));
3106 "Point Sprite TexCoord Enable\n");
3107 instr_out(ctx, 17, "Const Interp Enable\n");
3109 "Attrib 7-0 WrapShortest Enable\n");
3111 "Attrib 15-8 WrapShortest Enable\n");
3116 len = (data[0] & 0xff) + 2;
3118 fprintf(out, "Bad count in 3DSTATE_WM\n");
3119 instr_out(ctx, 0, "3DSTATE_WM\n");
3120 instr_out(ctx, 1, "kernel start pointer 0\n");
3122 "SPF=%d, VME=%d, Sampler Count %d, "
3123 "Binding table count %d\n", (data[2] >> 31) & 1,
3124 (data[2] >> 30) & 1, (data[2] >> 27) & 7,
3125 (data[2] >> 18) & 0xff);
3126 instr_out(ctx, 3, "scratch offset\n");
3128 "Depth Clear %d, Depth Resolve %d, HiZ Resolve %d, "
3129 "Dispatch GRF start[0] %d, start[1] %d, start[2] %d\n",
3130 (data[4] & (1 << 30)) != 0,
3131 (data[4] & (1 << 28)) != 0,
3132 (data[4] & (1 << 27)) != 0, (data[4] >> 16) & 0x7f,
3133 (data[4] >> 8) & 0x7f, (data[4] & 0x7f));
3135 "MaxThreads %d, PS KillPixel %d, PS computed Z %d, "
3136 "PS use sourceZ %d, Thread Dispatch %d, PS use sourceW %d, Dispatch32 %d, "
3137 "Dispatch16 %d, Dispatch8 %d\n",
3138 ((data[5] >> 25) & 0x7f) + 1,
3139 (data[5] & (1 << 22)) != 0,
3140 (data[5] & (1 << 21)) != 0,
3141 (data[5] & (1 << 20)) != 0,
3142 (data[5] & (1 << 19)) != 0, (data[5] & (1 << 8)) != 0,
3143 (data[5] & (1 << 2)) != 0, (data[5] & (1 << 1)) != 0,
3144 (data[5] & (1 << 0)) != 0);
3146 "Num SF output %d, Pos XY offset %d, ZW interp mode %d , "
3147 "Barycentric interp mode 0x%x, Point raster rule %d, Multisample mode %d, "
3148 "Multisample Dispatch mode %d\n",
3149 (data[6] >> 20) & 0x3f, (data[6] >> 18) & 3,
3150 (data[6] >> 16) & 3, (data[6] >> 10) & 0x3f,
3151 (data[6] & (1 << 9)) != 0, (data[6] >> 1) & 3,
3153 instr_out(ctx, 7, "kernel start pointer 1\n");
3154 instr_out(ctx, 8, "kernel start pointer 2\n");
3161 "Bad count in 3DSTATE_DRAWING_RECTANGLE\n");
3163 instr_out(ctx, 0, "3DSTATE_DRAWING_RECTANGLE\n");
3164 instr_out(ctx, 1, "top left: %d,%d\n",
3165 data[1] & 0xffff, (data[1] >> 16) & 0xffff);
3166 instr_out(ctx, 2, "bottom right: %d,%d\n",
3167 data[2] & 0xffff, (data[2] >> 16) & 0xffff);
3168 instr_out(ctx, 3, "origin: %d,%d\n",
3169 (int)data[3] & 0xffff, ((int)data[3] >> 16) & 0xffff);
3174 if (len < 5 || len > 7)
3175 fprintf(out, "Bad count in 3DSTATE_DEPTH_BUFFER\n");
3177 instr_out(ctx, 0, "3DSTATE_DEPTH_BUFFER\n");
3178 if (IS_GEN5(devid) || IS_GEN6(devid))
3180 "%s, %s, pitch = %d bytes, %stiled, HiZ %d, Seperate Stencil %d\n",
3181 get_965_surfacetype(data[1] >> 29),
3182 get_965_depthformat((data[1] >> 18) & 0x7),
3183 (data[1] & 0x0001ffff) + 1,
3184 data[1] & (1 << 27) ? "" : "not ",
3185 (data[1] & (1 << 22)) != 0,
3186 (data[1] & (1 << 21)) != 0);
3189 "%s, %s, pitch = %d bytes, %stiled\n",
3190 get_965_surfacetype(data[1] >> 29),
3191 get_965_depthformat((data[1] >> 18) & 0x7),
3192 (data[1] & 0x0001ffff) + 1,
3193 data[1] & (1 << 27) ? "" : "not ");
3194 instr_out(ctx, 2, "depth offset\n");
3195 instr_out(ctx, 3, "%dx%d\n",
3196 ((data[3] & 0x0007ffc0) >> 6) + 1,
3197 ((data[3] & 0xfff80000) >> 19) + 1);
3198 instr_out(ctx, 4, "volume depth\n");
3200 instr_out(ctx, 5, "\n");
3203 instr_out(ctx, 6, "\n");
3206 "render target view extent\n");
3212 if (IS_GEN6(devid) || IS_GEN7(devid)) {
3214 len = (data[0] & 0xff) + 2;
3215 if (len != 4 && len != 5)
3216 fprintf(out, "Bad count in PIPE_CONTROL\n");
3218 switch ((data[1] >> 14) & 0x3) {
3223 desc1 = "qword write";
3226 desc1 = "PS_DEPTH_COUNT write";
3229 desc1 = "TIMESTAMP write";
3232 instr_out(ctx, 0, "PIPE_CONTROL\n");
3234 "%s, %s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s\n",
3236 data[1] & (1 << 20) ? "cs stall, " : "",
3237 data[1] & (1 << 19) ?
3238 "global snapshot count reset, " : "",
3239 data[1] & (1 << 18) ? "tlb invalidate, " : "",
3240 data[1] & (1 << 17) ? "gfdt flush, " : "",
3241 data[1] & (1 << 17) ? "media state clear, " :
3243 data[1] & (1 << 13) ? "depth stall, " : "",
3244 data[1] & (1 << 12) ?
3245 "render target cache flush, " : "",
3246 data[1] & (1 << 11) ?
3247 "instruction cache invalidate, " : "",
3248 data[1] & (1 << 10) ?
3249 "texture cache invalidate, " : "",
3250 data[1] & (1 << 9) ?
3251 "indirect state invalidate, " : "",
3252 data[1] & (1 << 8) ? "notify irq, " : "",
3253 data[1] & (1 << 7) ? "PIPE_CONTROL flush, " :
3255 data[1] & (1 << 6) ? "protect mem app_id, " :
3256 "", data[1] & (1 << 5) ? "DC flush, " : "",
3257 data[1] & (1 << 4) ? "vf fetch invalidate, " :
3259 data[1] & (1 << 3) ?
3260 "constant cache invalidate, " : "",
3261 data[1] & (1 << 2) ?
3262 "state cache invalidate, " : "",
3263 data[1] & (1 << 1) ? "stall at scoreboard, " :
3265 data[1] & (1 << 0) ? "depth cache flush, " :
3269 "destination address\n");
3271 "immediate dword low\n");
3273 "immediate dword high\n");
3275 for (i = 2; i < len; i++) {
3276 instr_out(ctx, i, "\n");
3281 len = (data[0] & 0xff) + 2;
3283 fprintf(out, "Bad count in PIPE_CONTROL\n");
3285 switch ((data[0] >> 14) & 0x3) {
3290 desc1 = "qword write";
3293 desc1 = "PS_DEPTH_COUNT write";
3296 desc1 = "TIMESTAMP write";
3300 "PIPE_CONTROL: %s, %sdepth stall, %sRC write flush, "
3303 data[0] & (1 << 13) ? "" : "no ",
3304 data[0] & (1 << 12) ? "" : "no ",
3305 data[0] & (1 << 11) ? "" : "no ");
3306 instr_out(ctx, 1, "destination address\n");
3307 instr_out(ctx, 2, "immediate dword low\n");
3308 instr_out(ctx, 3, "immediate dword high\n");
3312 len = (data[0] & 0xff) + 2;
3314 fprintf(out, "Bad count in 3DPRIMITIVE\n");
3317 "3DPRIMITIVE: %s %s\n",
3318 get_965_prim_type(data[0]),
3319 (data[0] & (1 << 15)) ? "random" : "sequential");
3320 instr_out(ctx, 1, "vertex count\n");
3321 instr_out(ctx, 2, "start vertex\n");
3322 instr_out(ctx, 3, "instance count\n");
3323 instr_out(ctx, 4, "start instance\n");
3324 instr_out(ctx, 5, "index bias\n");
3328 for (idx = 0; idx < ARRAY_SIZE(opcodes_3d); idx++) {
3329 opcode_3d = &opcodes_3d[idx];
3330 if ((data[0] & 0xffff0000) >> 16 == opcode_3d->opcode) {
3334 instr_out(ctx, 0, "%s\n", opcode_3d->name);
3335 if (opcode_3d->max_len > 1) {
3336 len = (data[0] & 0xff) + 2;
3337 if (len < opcode_3d->min_len ||
3338 len > opcode_3d->max_len) {
3339 fprintf(out, "Bad count in %s\n",
3344 for (i = 1; i < len; i++) {
3345 instr_out(ctx, i, "dword %d\n", i);
3351 instr_out(ctx, 0, "3D UNKNOWN: 3d_965 opcode = 0x%x\n",
3357 decode_3d_i830(struct drm_intel_decode *ctx)
3361 uint32_t *data = ctx->data;
3365 unsigned int min_len;
3366 unsigned int max_len;
3369 { 0x02, 1, 1, "3DSTATE_MODES_3" },
3370 { 0x03, 1, 1, "3DSTATE_ENABLES_1" },
3371 { 0x04, 1, 1, "3DSTATE_ENABLES_2" },
3372 { 0x05, 1, 1, "3DSTATE_VFT0" },
3373 { 0x06, 1, 1, "3DSTATE_AA" },
3374 { 0x07, 1, 1, "3DSTATE_RASTERIZATION_RULES" },
3375 { 0x08, 1, 1, "3DSTATE_MODES_1" },
3376 { 0x09, 1, 1, "3DSTATE_STENCIL_TEST" },
3377 { 0x0a, 1, 1, "3DSTATE_VFT1" },
3378 { 0x0b, 1, 1, "3DSTATE_INDPT_ALPHA_BLEND" },
3379 { 0x0c, 1, 1, "3DSTATE_MODES_5" },
3380 { 0x0d, 1, 1, "3DSTATE_MAP_BLEND_OP" },
3381 { 0x0e, 1, 1, "3DSTATE_MAP_BLEND_ARG" },
3382 { 0x0f, 1, 1, "3DSTATE_MODES_2" },
3383 { 0x15, 1, 1, "3DSTATE_FOG_COLOR" },
3384 { 0x16, 1, 1, "3DSTATE_MODES_4"},
3387 opcode = (data[0] & 0x1f000000) >> 24;
3391 return decode_3d_primitive(ctx);
3393 return decode_3d_1d(ctx);
3395 return decode_3d_1c(ctx);
3398 for (idx = 0; idx < ARRAY_SIZE(opcodes_3d); idx++) {
3399 opcode_3d = &opcodes_3d[idx];
3400 if ((data[0] & 0x1f000000) >> 24 == opcode_3d->opcode) {
3401 unsigned int len = 1, i;
3403 instr_out(ctx, 0, "%s\n", opcode_3d->name);
3404 if (opcode_3d->max_len > 1) {
3405 len = (data[0] & 0xff) + 2;
3406 if (len < opcode_3d->min_len ||
3407 len > opcode_3d->max_len) {
3408 fprintf(out, "Bad count in %s\n",
3413 for (i = 1; i < len; i++) {
3414 instr_out(ctx, i, "dword %d\n", i);
3420 instr_out(ctx, 0, "3D UNKNOWN: 3d_i830 opcode = 0x%x\n",
3425 struct drm_intel_decode *
3426 drm_intel_decode_context_alloc(uint32_t devid)
3428 struct drm_intel_decode *ctx;
3430 ctx = calloc(1, sizeof(struct drm_intel_decode));
3441 drm_intel_decode_context_free(struct drm_intel_decode *ctx)
3447 drm_intel_decode_set_dump_past_end(struct drm_intel_decode *ctx,
3450 ctx->dump_past_end = !!dump_past_end;
3454 drm_intel_decode_set_batch_pointer(struct drm_intel_decode *ctx,
3455 void *data, uint32_t hw_offset, int count)
3457 ctx->base_data = data;
3458 ctx->base_hw_offset = hw_offset;
3459 ctx->base_count = count;
3463 drm_intel_decode_set_head_tail(struct drm_intel_decode *ctx,
3464 uint32_t head, uint32_t tail)
3471 drm_intel_decode_set_output_file(struct drm_intel_decode *ctx,
3478 * Decodes an i830-i915 batch buffer, writing the output to stdout.
3480 * \param data batch buffer contents
3481 * \param count number of DWORDs to decode in the batch buffer
3482 * \param hw_offset hardware address for the buffer
3485 drm_intel_decode(struct drm_intel_decode *ctx)
3488 unsigned int index = 0;
3490 int size = ctx->base_count * 4;
3496 /* Put a scratch page full of obviously undefined data after
3497 * the batchbuffer. This lets us avoid a bunch of length
3498 * checking in statically sized packets.
3500 temp = malloc(size + 4096);
3501 memcpy(temp, ctx->base_data, size);
3502 memset((char *)temp + size, 0xd0, 4096);
3505 ctx->hw_offset = ctx->base_hw_offset;
3506 ctx->count = ctx->base_count;
3509 head_offset = ctx->head;
3510 tail_offset = ctx->tail;
3516 while (ctx->count > 0) {
3519 switch ((ctx->data[index] & 0xe0000000) >> 29) {
3521 ret = decode_mi(ctx);
3523 /* If MI_BATCHBUFFER_END happened, then dump
3524 * the rest of the output in case we some day
3525 * want it in debugging, but don't decode it
3526 * since it'll just confuse in the common
3530 if (ctx->dump_past_end) {
3533 for (index = index + 1; index < ctx->count;
3535 instr_out(ctx, index, "\n");
3542 index += decode_2d(ctx);
3545 if (IS_9XX(devid) && !IS_GEN3(devid)) {
3548 } else if (IS_GEN3(devid)) {
3549 index += decode_3d(ctx);
3552 decode_3d_i830(ctx);
3556 instr_out(ctx, index, "UNKNOWN\n");
3562 if (ctx->count < index)
3565 ctx->count -= index;
3567 ctx->hw_offset += 4 * index;