blob: cf5b3bbe702c95113cecb49dadec4580deccad7b [file] [log] [blame]
Eric Anholt8c4a2c82011-12-20 11:25:20 -08001/*
2 * Copyright © 2009-2011 Intel Corporation
3 *
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:
10 *
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
13 * Software.
14 *
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
21 * IN THE SOFTWARE.
22 */
23
Eric Anholt9695eee2012-01-04 12:00:59 -080024#include <assert.h>
Eric Anholt8c4a2c82011-12-20 11:25:20 -080025#include <stdint.h>
Eric Anholt71066ab2011-12-20 13:06:16 -080026#include <stdlib.h>
Eric Anholt8c4a2c82011-12-20 11:25:20 -080027#include <stdio.h>
Eric Anholt71066ab2011-12-20 13:06:16 -080028#include <stdbool.h>
Eric Anholt8c4a2c82011-12-20 11:25:20 -080029#include <stdarg.h>
30#include <string.h>
31
Eric Anholt8c4a2c82011-12-20 11:25:20 -080032#include "intel_chipset.h"
Eric Anholt71066ab2011-12-20 13:06:16 -080033#include "intel_bufmgr.h"
34
35/* Struct for tracking drm_intel_decode state. */
36struct drm_intel_decode {
Eric Anholtea33a232012-01-03 13:05:57 -080037 /** stdio file where the output should land. Defaults to stdout. */
38 FILE *out;
39
Eric Anholt71066ab2011-12-20 13:06:16 -080040 /** PCI device ID. */
41 uint32_t devid;
42
Eric Anholt9695eee2012-01-04 12:00:59 -080043 /**
44 * Shorthand device identifier: 3 is 915, 4 is 965, 5 is
45 * Ironlake, etc.
46 */
47 int gen;
48
Eric Anholt8fb66a72011-12-20 14:59:38 -080049 /** GPU address of the start of the current packet. */
Eric Anholt71066ab2011-12-20 13:06:16 -080050 uint32_t hw_offset;
Eric Anholt8fb66a72011-12-20 14:59:38 -080051 /** CPU virtual address of the start of the current packet. */
Eric Anholt71066ab2011-12-20 13:06:16 -080052 uint32_t *data;
Eric Anholt8fb66a72011-12-20 14:59:38 -080053 /** DWORDs of remaining batchbuffer data starting from the packet. */
Eric Anholt71066ab2011-12-20 13:06:16 -080054 uint32_t count;
55
Eric Anholt8fb66a72011-12-20 14:59:38 -080056 /** GPU address of the start of the batchbuffer data. */
57 uint32_t base_hw_offset;
58 /** CPU Virtual address of the start of the batchbuffer data. */
59 uint32_t *base_data;
60 /** Number of DWORDs of batchbuffer data. */
61 uint32_t base_count;
62
Eric Anholt71066ab2011-12-20 13:06:16 -080063 /** @{
64 * GPU head and tail pointers, which will be noted in the dump, or ~0.
65 */
66 uint32_t head, tail;
67 /** @} */
68
69 /**
70 * Whether to dump the dwords after MI_BATCHBUFFER_END.
71 *
72 * This sometimes provides clues in corrupted batchbuffers,
73 * and is used by the intel-gpu-tools.
74 */
75 bool dump_past_end;
Eric Anholt028715e2012-01-04 12:31:40 -080076
77 bool overflowed;
Eric Anholt71066ab2011-12-20 13:06:16 -080078};
Eric Anholt8c4a2c82011-12-20 11:25:20 -080079
80static FILE *out;
81static uint32_t saved_s2 = 0, saved_s4 = 0;
82static char saved_s2_set = 0, saved_s4_set = 0;
Eric Anholt193fa132011-12-20 11:36:07 -080083static uint32_t head_offset = 0xffffffff; /* undefined */
84static uint32_t tail_offset = 0xffffffff; /* undefined */
Eric Anholt8c4a2c82011-12-20 11:25:20 -080085
86#ifndef ARRAY_SIZE
87#define ARRAY_SIZE(A) (sizeof(A)/sizeof(A[0]))
88#endif
89
90#define BUFFER_FAIL(_count, _len, _name) do { \
91 fprintf(out, "Buffer size too small in %s (%d < %d)\n", \
92 (_name), (_count), (_len)); \
Eric Anholtc1d29462011-12-20 15:29:03 -080093 return _count; \
Eric Anholt8c4a2c82011-12-20 11:25:20 -080094} while (0)
95
Eric Anholt193fa132011-12-20 11:36:07 -080096static float int_as_float(uint32_t intval)
Eric Anholt8c4a2c82011-12-20 11:25:20 -080097{
Eric Anholt193fa132011-12-20 11:36:07 -080098 union intfloat {
99 uint32_t i;
100 float f;
101 } uval;
Eric Anholt8c4a2c82011-12-20 11:25:20 -0800102
Eric Anholt193fa132011-12-20 11:36:07 -0800103 uval.i = intval;
104 return uval.f;
Eric Anholt8c4a2c82011-12-20 11:25:20 -0800105}
106
107static void
Eric Anholtc1d29462011-12-20 15:29:03 -0800108instr_out(struct drm_intel_decode *ctx, unsigned int index,
109 const char *fmt, ...) __attribute__((format(__printf__, 3, 4)));
Eric Anholt39a06ac2011-12-20 12:01:19 -0800110
111static void
Eric Anholtc1d29462011-12-20 15:29:03 -0800112instr_out(struct drm_intel_decode *ctx, unsigned int index,
Eric Anholt1db55a82011-12-20 12:00:28 -0800113 const char *fmt, ...)
Eric Anholt8c4a2c82011-12-20 11:25:20 -0800114{
Eric Anholt193fa132011-12-20 11:36:07 -0800115 va_list va;
Eric Anholt1db55a82011-12-20 12:00:28 -0800116 const char *parseinfo;
Eric Anholtc1d29462011-12-20 15:29:03 -0800117 uint32_t offset = ctx->hw_offset + index * 4;
Eric Anholt8c4a2c82011-12-20 11:25:20 -0800118
Eric Anholt028715e2012-01-04 12:31:40 -0800119 if (index > ctx->count) {
120 if (!ctx->overflowed) {
121 fprintf(out, "ERROR: Decode attempted to continue beyond end of batchbuffer\n");
122 ctx->overflowed = true;
123 }
124 return;
125 }
126
Eric Anholt193fa132011-12-20 11:36:07 -0800127 if (offset == head_offset)
128 parseinfo = "HEAD";
129 else if (offset == tail_offset)
130 parseinfo = "TAIL";
131 else
132 parseinfo = " ";
Eric Anholt8c4a2c82011-12-20 11:25:20 -0800133
Eric Anholt193fa132011-12-20 11:36:07 -0800134 fprintf(out, "0x%08x: %s 0x%08x: %s", offset, parseinfo,
Eric Anholtc1d29462011-12-20 15:29:03 -0800135 ctx->data[index], index == 0 ? "" : " ");
Eric Anholt193fa132011-12-20 11:36:07 -0800136 va_start(va, fmt);
137 vfprintf(out, fmt, va);
138 va_end(va);
Eric Anholt8c4a2c82011-12-20 11:25:20 -0800139}
140
141static int
Daniel Vetter43704252012-04-02 13:08:09 +0200142decode_MI_WAIT_FOR_EVENT(struct drm_intel_decode *ctx)
143{
144 const char *cc_wait;
145 int cc_shift = 0;
146 uint32_t data = ctx->data[0];
147
148 if (ctx->gen <= 5)
149 cc_shift = 9;
150 else
151 cc_shift = 16;
152
153 switch ((data >> cc_shift) & 0x1f) {
154 case 1:
155 cc_wait = ", cc wait 1";
156 break;
157 case 2:
158 cc_wait = ", cc wait 2";
159 break;
160 case 3:
161 cc_wait = ", cc wait 3";
162 break;
163 case 4:
164 cc_wait = ", cc wait 4";
165 break;
166 case 5:
167 cc_wait = ", cc wait 4";
168 break;
169 default:
170 cc_wait = "";
171 break;
172 }
173
174 if (ctx->gen <= 5) {
175 instr_out(ctx, 0, "MI_WAIT_FOR_EVENT%s%s%s%s%s%s%s%s%s%s%s%s%s%s\n",
176 data & (1<<18)? ", pipe B start vblank wait": "",
177 data & (1<<17)? ", pipe A start vblank wait": "",
178 data & (1<<16)? ", overlay flip pending wait": "",
179 data & (1<<14)? ", pipe B hblank wait": "",
180 data & (1<<13)? ", pipe A hblank wait": "",
181 cc_wait,
182 data & (1<<8)? ", plane C pending flip wait": "",
183 data & (1<<7)? ", pipe B vblank wait": "",
184 data & (1<<6)? ", plane B pending flip wait": "",
185 data & (1<<5)? ", pipe B scan line wait": "",
186 data & (1<<4)? ", fbc idle wait": "",
187 data & (1<<3)? ", pipe A vblank wait": "",
188 data & (1<<2)? ", plane A pending flip wait": "",
189 data & (1<<1)? ", plane A scan line wait": "");
190 } else {
191 instr_out(ctx, 0, "MI_WAIT_FOR_EVENT%s%s%s%s%s%s%s%s%s%s%s%s\n",
192 data & (1<<20)? ", sprite C pending flip wait": "", /* ivb */
193 cc_wait,
194 data & (1<<13)? ", pipe B hblank wait": "",
195 data & (1<<11)? ", pipe B vblank wait": "",
196 data & (1<<10)? ", sprite B pending flip wait": "",
197 data & (1<<9)? ", plane B pending flip wait": "",
198 data & (1<<8)? ", plane B scan line wait": "",
199 data & (1<<5)? ", pipe A hblank wait": "",
200 data & (1<<3)? ", pipe A vblank wait": "",
201 data & (1<<2)? ", sprite A pending flip wait": "",
202 data & (1<<1)? ", plane A pending flip wait": "",
203 data & (1<<0)? ", plane A scan line wait": "");
204 }
205
206 return 1;
207}
208
209static int
Eric Anholtde49fd42011-12-20 15:15:21 -0800210decode_mi(struct drm_intel_decode *ctx)
Eric Anholt8c4a2c82011-12-20 11:25:20 -0800211{
Eric Anholt193fa132011-12-20 11:36:07 -0800212 unsigned int opcode, len = -1;
Eric Anholt1db55a82011-12-20 12:00:28 -0800213 const char *post_sync_op = "";
Eric Anholtde49fd42011-12-20 15:15:21 -0800214 uint32_t *data = ctx->data;
Eric Anholt8c4a2c82011-12-20 11:25:20 -0800215
Eric Anholt193fa132011-12-20 11:36:07 -0800216 struct {
217 uint32_t opcode;
218 int len_mask;
Eric Anholt07768ba2011-12-20 13:46:23 -0800219 unsigned int min_len;
220 unsigned int max_len;
Eric Anholt1db55a82011-12-20 12:00:28 -0800221 const char *name;
Daniel Vetter43704252012-04-02 13:08:09 +0200222 int (*func)(struct drm_intel_decode *ctx);
Eric Anholt193fa132011-12-20 11:36:07 -0800223 } opcodes_mi[] = {
Eric Anholtbbdda922011-12-20 11:44:36 -0800224 { 0x08, 0, 1, 1, "MI_ARB_ON_OFF" },
225 { 0x0a, 0, 1, 1, "MI_BATCH_BUFFER_END" },
226 { 0x30, 0x3f, 3, 3, "MI_BATCH_BUFFER" },
227 { 0x31, 0x3f, 2, 2, "MI_BATCH_BUFFER_START" },
228 { 0x14, 0x3f, 3, 3, "MI_DISPLAY_BUFFER_INFO" },
229 { 0x04, 0, 1, 1, "MI_FLUSH" },
230 { 0x22, 0x1f, 3, 3, "MI_LOAD_REGISTER_IMM" },
231 { 0x13, 0x3f, 2, 2, "MI_LOAD_SCAN_LINES_EXCL" },
232 { 0x12, 0x3f, 2, 2, "MI_LOAD_SCAN_LINES_INCL" },
233 { 0x00, 0, 1, 1, "MI_NOOP" },
234 { 0x11, 0x3f, 2, 2, "MI_OVERLAY_FLIP" },
235 { 0x07, 0, 1, 1, "MI_REPORT_HEAD" },
236 { 0x18, 0x3f, 2, 2, "MI_SET_CONTEXT" },
237 { 0x20, 0x3f, 3, 4, "MI_STORE_DATA_IMM" },
238 { 0x21, 0x3f, 3, 4, "MI_STORE_DATA_INDEX" },
239 { 0x24, 0x3f, 3, 3, "MI_STORE_REGISTER_MEM" },
240 { 0x02, 0, 1, 1, "MI_USER_INTERRUPT" },
Daniel Vetter43704252012-04-02 13:08:09 +0200241 { 0x03, 0, 1, 1, "MI_WAIT_FOR_EVENT", decode_MI_WAIT_FOR_EVENT },
Eric Anholtbbdda922011-12-20 11:44:36 -0800242 { 0x16, 0x7f, 3, 3, "MI_SEMAPHORE_MBOX" },
243 { 0x26, 0x1f, 3, 4, "MI_FLUSH_DW" },
244 { 0x0b, 0, 1, 1, "MI_SUSPEND_FLUSH"},
Daniel Vetter43704252012-04-02 13:08:09 +0200245 }, *opcode_mi = NULL;
Eric Anholt193fa132011-12-20 11:36:07 -0800246
247 /* check instruction length */
248 for (opcode = 0; opcode < sizeof(opcodes_mi) / sizeof(opcodes_mi[0]);
249 opcode++) {
250 if ((data[0] & 0x1f800000) >> 23 == opcodes_mi[opcode].opcode) {
251 len = 1;
252 if (opcodes_mi[opcode].max_len > 1) {
253 len =
254 (data[0] & opcodes_mi[opcode].len_mask) + 2;
255 if (len < opcodes_mi[opcode].min_len
256 || len > opcodes_mi[opcode].max_len) {
257 fprintf(out,
258 "Bad length (%d) in %s, [%d, %d]\n",
259 len, opcodes_mi[opcode].name,
260 opcodes_mi[opcode].min_len,
261 opcodes_mi[opcode].max_len);
262 }
263 }
Daniel Vetter43704252012-04-02 13:08:09 +0200264 opcode_mi = &opcodes_mi[opcode];
Eric Anholt193fa132011-12-20 11:36:07 -0800265 break;
Eric Anholt8c4a2c82011-12-20 11:25:20 -0800266 }
Eric Anholt8c4a2c82011-12-20 11:25:20 -0800267 }
Eric Anholt8c4a2c82011-12-20 11:25:20 -0800268
Daniel Vetter43704252012-04-02 13:08:09 +0200269 if (opcode_mi && opcode_mi->func)
270 return opcode_mi->func(ctx);
271
Eric Anholt193fa132011-12-20 11:36:07 -0800272 switch ((data[0] & 0x1f800000) >> 23) {
273 case 0x0a:
Eric Anholtc1d29462011-12-20 15:29:03 -0800274 instr_out(ctx, 0, "MI_BATCH_BUFFER_END\n");
Eric Anholt193fa132011-12-20 11:36:07 -0800275 return -1;
276 case 0x16:
Eric Anholtc1d29462011-12-20 15:29:03 -0800277 instr_out(ctx, 0, "MI_SEMAPHORE_MBOX%s%s%s%s %u\n",
Eric Anholt193fa132011-12-20 11:36:07 -0800278 data[0] & (1 << 22) ? " global gtt," : "",
279 data[0] & (1 << 21) ? " update semaphore," : "",
280 data[0] & (1 << 20) ? " compare semaphore," : "",
281 data[0] & (1 << 18) ? " use compare reg" : "",
282 (data[0] & (0x3 << 16)) >> 16);
Eric Anholtc1d29462011-12-20 15:29:03 -0800283 instr_out(ctx, 1, "value\n");
284 instr_out(ctx, 2, "address\n");
Eric Anholt193fa132011-12-20 11:36:07 -0800285 return len;
286 case 0x21:
Eric Anholtc1d29462011-12-20 15:29:03 -0800287 instr_out(ctx, 0, "MI_STORE_DATA_INDEX%s\n",
Eric Anholt193fa132011-12-20 11:36:07 -0800288 data[0] & (1 << 21) ? " use per-process HWS," : "");
Eric Anholtc1d29462011-12-20 15:29:03 -0800289 instr_out(ctx, 1, "index\n");
290 instr_out(ctx, 2, "dword\n");
Eric Anholt193fa132011-12-20 11:36:07 -0800291 if (len == 4)
Eric Anholtc1d29462011-12-20 15:29:03 -0800292 instr_out(ctx, 3, "upper dword\n");
Eric Anholt193fa132011-12-20 11:36:07 -0800293 return len;
294 case 0x00:
295 if (data[0] & (1 << 22))
Eric Anholtc1d29462011-12-20 15:29:03 -0800296 instr_out(ctx, 0,
Eric Anholt193fa132011-12-20 11:36:07 -0800297 "MI_NOOP write NOPID reg, val=0x%x\n",
298 data[0] & ((1 << 22) - 1));
299 else
Eric Anholtc1d29462011-12-20 15:29:03 -0800300 instr_out(ctx, 0, "MI_NOOP\n");
Eric Anholt193fa132011-12-20 11:36:07 -0800301 return len;
302 case 0x26:
303 switch (data[0] & (0x3 << 14)) {
304 case (0 << 14):
305 post_sync_op = "no write";
306 break;
307 case (1 << 14):
308 post_sync_op = "write data";
309 break;
310 case (2 << 14):
311 post_sync_op = "reserved";
312 break;
313 case (3 << 14):
314 post_sync_op = "write TIMESTAMP";
315 break;
316 }
Eric Anholtc1d29462011-12-20 15:29:03 -0800317 instr_out(ctx, 0,
Eric Anholt193fa132011-12-20 11:36:07 -0800318 "MI_FLUSH_DW%s%s%s%s post_sync_op='%s' %s%s\n",
319 data[0] & (1 << 22) ?
320 " enable protected mem (BCS-only)," : "",
321 data[0] & (1 << 21) ? " store in hws," : "",
322 data[0] & (1 << 18) ? " invalidate tlb," : "",
323 data[0] & (1 << 17) ? " flush gfdt," : "",
324 post_sync_op,
325 data[0] & (1 << 8) ? " enable notify interrupt," : "",
326 data[0] & (1 << 7) ?
327 " invalidate video state (BCS-only)," : "");
328 if (data[0] & (1 << 21))
Eric Anholtc1d29462011-12-20 15:29:03 -0800329 instr_out(ctx, 1, "hws index\n");
Eric Anholt193fa132011-12-20 11:36:07 -0800330 else
Eric Anholtc1d29462011-12-20 15:29:03 -0800331 instr_out(ctx, 1, "address\n");
332 instr_out(ctx, 2, "dword\n");
Eric Anholt193fa132011-12-20 11:36:07 -0800333 if (len == 4)
Eric Anholtc1d29462011-12-20 15:29:03 -0800334 instr_out(ctx, 3, "upper dword\n");
Eric Anholt193fa132011-12-20 11:36:07 -0800335 return len;
Eric Anholt8c4a2c82011-12-20 11:25:20 -0800336 }
Eric Anholt8c4a2c82011-12-20 11:25:20 -0800337
Eric Anholt193fa132011-12-20 11:36:07 -0800338 for (opcode = 0; opcode < sizeof(opcodes_mi) / sizeof(opcodes_mi[0]);
339 opcode++) {
340 if ((data[0] & 0x1f800000) >> 23 == opcodes_mi[opcode].opcode) {
Eric Anholt07768ba2011-12-20 13:46:23 -0800341 unsigned int i;
Eric Anholt8c4a2c82011-12-20 11:25:20 -0800342
Eric Anholtc1d29462011-12-20 15:29:03 -0800343 instr_out(ctx, 0, "%s\n",
Eric Anholt193fa132011-12-20 11:36:07 -0800344 opcodes_mi[opcode].name);
Eric Anholt07768ba2011-12-20 13:46:23 -0800345 for (i = 1; i < len; i++) {
Eric Anholtc1d29462011-12-20 15:29:03 -0800346 instr_out(ctx, i, "dword %d\n", i);
Eric Anholt193fa132011-12-20 11:36:07 -0800347 }
Eric Anholt8c4a2c82011-12-20 11:25:20 -0800348
Eric Anholt193fa132011-12-20 11:36:07 -0800349 return len;
350 }
Eric Anholt8c4a2c82011-12-20 11:25:20 -0800351 }
Eric Anholt8c4a2c82011-12-20 11:25:20 -0800352
Eric Anholtc1d29462011-12-20 15:29:03 -0800353 instr_out(ctx, 0, "MI UNKNOWN\n");
Eric Anholt193fa132011-12-20 11:36:07 -0800354 return 1;
Eric Anholt8c4a2c82011-12-20 11:25:20 -0800355}
356
357static void
Eric Anholt62b41032011-12-20 15:17:24 -0800358decode_2d_br00(struct drm_intel_decode *ctx, const char *cmd)
Eric Anholt8c4a2c82011-12-20 11:25:20 -0800359{
Eric Anholtc1d29462011-12-20 15:29:03 -0800360 instr_out(ctx, 0,
Eric Anholt193fa132011-12-20 11:36:07 -0800361 "%s (rgb %sabled, alpha %sabled, src tile %d, dst tile %d)\n",
362 cmd,
Eric Anholt62b41032011-12-20 15:17:24 -0800363 (ctx->data[0] & (1 << 20)) ? "en" : "dis",
364 (ctx->data[0] & (1 << 21)) ? "en" : "dis",
365 (ctx->data[0] >> 15) & 1,
366 (ctx->data[0] >> 11) & 1);
Eric Anholt193fa132011-12-20 11:36:07 -0800367}
Eric Anholt8c4a2c82011-12-20 11:25:20 -0800368
Eric Anholtb0371612011-12-20 15:19:24 -0800369static void
370decode_2d_br01(struct drm_intel_decode *ctx)
Eric Anholt193fa132011-12-20 11:36:07 -0800371{
Eric Anholt1db55a82011-12-20 12:00:28 -0800372 const char *format;
Eric Anholtb0371612011-12-20 15:19:24 -0800373 switch ((ctx->data[1] >> 24) & 0x3) {
Eric Anholt193fa132011-12-20 11:36:07 -0800374 case 0:
375 format = "8";
376 break;
377 case 1:
378 format = "565";
379 break;
380 case 2:
381 format = "1555";
382 break;
383 case 3:
384 format = "8888";
385 break;
Eric Anholt8c4a2c82011-12-20 11:25:20 -0800386 }
Eric Anholt8c4a2c82011-12-20 11:25:20 -0800387
Eric Anholtc1d29462011-12-20 15:29:03 -0800388 instr_out(ctx, 1,
Eric Anholtb0371612011-12-20 15:19:24 -0800389 "format %s, pitch %d, rop 0x%02x, "
Eric Anholt193fa132011-12-20 11:36:07 -0800390 "clipping %sabled, %s%s \n",
391 format,
Eric Anholtb0371612011-12-20 15:19:24 -0800392 (short)(ctx->data[1] & 0xffff),
393 (ctx->data[1] >> 16) & 0xff,
394 ctx->data[1] & (1 << 30) ? "en" : "dis",
395 ctx->data[1] & (1 << 31) ? "solid pattern enabled, " : "",
396 ctx->data[1] & (1 << 31) ?
Eric Anholt193fa132011-12-20 11:36:07 -0800397 "mono pattern transparency enabled, " : "");
398
Eric Anholt8c4a2c82011-12-20 11:25:20 -0800399}
400
401static int
Eric Anholtde49fd42011-12-20 15:15:21 -0800402decode_2d(struct drm_intel_decode *ctx)
Eric Anholt8c4a2c82011-12-20 11:25:20 -0800403{
Eric Anholt193fa132011-12-20 11:36:07 -0800404 unsigned int opcode, len;
Eric Anholtde49fd42011-12-20 15:15:21 -0800405 uint32_t *data = ctx->data;
Eric Anholt8c4a2c82011-12-20 11:25:20 -0800406
Eric Anholt193fa132011-12-20 11:36:07 -0800407 struct {
408 uint32_t opcode;
Eric Anholt07768ba2011-12-20 13:46:23 -0800409 unsigned int min_len;
410 unsigned int max_len;
Eric Anholt1db55a82011-12-20 12:00:28 -0800411 const char *name;
Eric Anholt193fa132011-12-20 11:36:07 -0800412 } opcodes_2d[] = {
Eric Anholtbbdda922011-12-20 11:44:36 -0800413 { 0x40, 5, 5, "COLOR_BLT" },
414 { 0x43, 6, 6, "SRC_COPY_BLT" },
415 { 0x01, 8, 8, "XY_SETUP_BLT" },
416 { 0x11, 9, 9, "XY_SETUP_MONO_PATTERN_SL_BLT" },
417 { 0x03, 3, 3, "XY_SETUP_CLIP_BLT" },
418 { 0x24, 2, 2, "XY_PIXEL_BLT" },
419 { 0x25, 3, 3, "XY_SCANLINES_BLT" },
420 { 0x26, 4, 4, "Y_TEXT_BLT" },
421 { 0x31, 5, 134, "XY_TEXT_IMMEDIATE_BLT" },
422 { 0x50, 6, 6, "XY_COLOR_BLT" },
423 { 0x51, 6, 6, "XY_PAT_BLT" },
424 { 0x76, 8, 8, "XY_PAT_CHROMA_BLT" },
425 { 0x72, 7, 135, "XY_PAT_BLT_IMMEDIATE" },
426 { 0x77, 9, 137, "XY_PAT_CHROMA_BLT_IMMEDIATE" },
427 { 0x52, 9, 9, "XY_MONO_PAT_BLT" },
428 { 0x59, 7, 7, "XY_MONO_PAT_FIXED_BLT" },
429 { 0x53, 8, 8, "XY_SRC_COPY_BLT" },
430 { 0x54, 8, 8, "XY_MONO_SRC_COPY_BLT" },
431 { 0x71, 9, 137, "XY_MONO_SRC_COPY_IMMEDIATE_BLT" },
432 { 0x55, 9, 9, "XY_FULL_BLT" },
433 { 0x55, 9, 137, "XY_FULL_IMMEDIATE_PATTERN_BLT" },
434 { 0x56, 9, 9, "XY_FULL_MONO_SRC_BLT" },
435 { 0x75, 10, 138, "XY_FULL_MONO_SRC_IMMEDIATE_PATTERN_BLT" },
436 { 0x57, 12, 12, "XY_FULL_MONO_PATTERN_BLT" },
437 { 0x58, 12, 12, "XY_FULL_MONO_PATTERN_MONO_SRC_BLT"},
438 };
Eric Anholt8c4a2c82011-12-20 11:25:20 -0800439
Eric Anholt193fa132011-12-20 11:36:07 -0800440 switch ((data[0] & 0x1fc00000) >> 22) {
441 case 0x25:
Eric Anholtc1d29462011-12-20 15:29:03 -0800442 instr_out(ctx, 0,
Eric Anholt193fa132011-12-20 11:36:07 -0800443 "XY_SCANLINES_BLT (pattern seed (%d, %d), dst tile %d)\n",
444 (data[0] >> 12) & 0x8,
445 (data[0] >> 8) & 0x8, (data[0] >> 11) & 1);
Eric Anholt8c4a2c82011-12-20 11:25:20 -0800446
Eric Anholt193fa132011-12-20 11:36:07 -0800447 len = (data[0] & 0x000000ff) + 2;
448 if (len != 3)
449 fprintf(out, "Bad count in XY_SCANLINES_BLT\n");
Eric Anholt193fa132011-12-20 11:36:07 -0800450
Eric Anholtc1d29462011-12-20 15:29:03 -0800451 instr_out(ctx, 1, "dest (%d,%d)\n",
Eric Anholt193fa132011-12-20 11:36:07 -0800452 data[1] & 0xffff, data[1] >> 16);
Eric Anholtc1d29462011-12-20 15:29:03 -0800453 instr_out(ctx, 2, "dest (%d,%d)\n",
Eric Anholt193fa132011-12-20 11:36:07 -0800454 data[2] & 0xffff, data[2] >> 16);
455 return len;
456 case 0x01:
Eric Anholt62b41032011-12-20 15:17:24 -0800457 decode_2d_br00(ctx, "XY_SETUP_BLT");
Eric Anholt193fa132011-12-20 11:36:07 -0800458
459 len = (data[0] & 0x000000ff) + 2;
460 if (len != 8)
461 fprintf(out, "Bad count in XY_SETUP_BLT\n");
Eric Anholt193fa132011-12-20 11:36:07 -0800462
Eric Anholtb0371612011-12-20 15:19:24 -0800463 decode_2d_br01(ctx);
Eric Anholtc1d29462011-12-20 15:29:03 -0800464 instr_out(ctx, 2, "cliprect (%d,%d)\n",
Eric Anholt193fa132011-12-20 11:36:07 -0800465 data[2] & 0xffff, data[2] >> 16);
Eric Anholtc1d29462011-12-20 15:29:03 -0800466 instr_out(ctx, 3, "cliprect (%d,%d)\n",
Eric Anholt193fa132011-12-20 11:36:07 -0800467 data[3] & 0xffff, data[3] >> 16);
Eric Anholtc1d29462011-12-20 15:29:03 -0800468 instr_out(ctx, 4, "setup dst offset 0x%08x\n",
Eric Anholt193fa132011-12-20 11:36:07 -0800469 data[4]);
Eric Anholtc1d29462011-12-20 15:29:03 -0800470 instr_out(ctx, 5, "setup background color\n");
471 instr_out(ctx, 6, "setup foreground color\n");
472 instr_out(ctx, 7, "color pattern offset\n");
Eric Anholt193fa132011-12-20 11:36:07 -0800473 return len;
474 case 0x03:
Eric Anholt62b41032011-12-20 15:17:24 -0800475 decode_2d_br00(ctx, "XY_SETUP_CLIP_BLT");
Eric Anholt193fa132011-12-20 11:36:07 -0800476
477 len = (data[0] & 0x000000ff) + 2;
478 if (len != 3)
479 fprintf(out, "Bad count in XY_SETUP_CLIP_BLT\n");
Eric Anholt193fa132011-12-20 11:36:07 -0800480
Eric Anholtc1d29462011-12-20 15:29:03 -0800481 instr_out(ctx, 1, "cliprect (%d,%d)\n",
Eric Anholt193fa132011-12-20 11:36:07 -0800482 data[1] & 0xffff, data[2] >> 16);
Eric Anholtc1d29462011-12-20 15:29:03 -0800483 instr_out(ctx, 2, "cliprect (%d,%d)\n",
Eric Anholt193fa132011-12-20 11:36:07 -0800484 data[2] & 0xffff, data[3] >> 16);
485 return len;
486 case 0x11:
Eric Anholt62b41032011-12-20 15:17:24 -0800487 decode_2d_br00(ctx, "XY_SETUP_MONO_PATTERN_SL_BLT");
Eric Anholt193fa132011-12-20 11:36:07 -0800488
489 len = (data[0] & 0x000000ff) + 2;
490 if (len != 9)
491 fprintf(out,
492 "Bad count in XY_SETUP_MONO_PATTERN_SL_BLT\n");
Eric Anholt193fa132011-12-20 11:36:07 -0800493
Eric Anholtb0371612011-12-20 15:19:24 -0800494 decode_2d_br01(ctx);
Eric Anholtc1d29462011-12-20 15:29:03 -0800495 instr_out(ctx, 2, "cliprect (%d,%d)\n",
Eric Anholt193fa132011-12-20 11:36:07 -0800496 data[2] & 0xffff, data[2] >> 16);
Eric Anholtc1d29462011-12-20 15:29:03 -0800497 instr_out(ctx, 3, "cliprect (%d,%d)\n",
Eric Anholt193fa132011-12-20 11:36:07 -0800498 data[3] & 0xffff, data[3] >> 16);
Eric Anholtc1d29462011-12-20 15:29:03 -0800499 instr_out(ctx, 4, "setup dst offset 0x%08x\n",
Eric Anholt193fa132011-12-20 11:36:07 -0800500 data[4]);
Eric Anholtc1d29462011-12-20 15:29:03 -0800501 instr_out(ctx, 5, "setup background color\n");
502 instr_out(ctx, 6, "setup foreground color\n");
503 instr_out(ctx, 7, "mono pattern dw0\n");
504 instr_out(ctx, 8, "mono pattern dw1\n");
Eric Anholt193fa132011-12-20 11:36:07 -0800505 return len;
506 case 0x50:
Eric Anholt62b41032011-12-20 15:17:24 -0800507 decode_2d_br00(ctx, "XY_COLOR_BLT");
Eric Anholt193fa132011-12-20 11:36:07 -0800508
509 len = (data[0] & 0x000000ff) + 2;
510 if (len != 6)
511 fprintf(out, "Bad count in XY_COLOR_BLT\n");
Eric Anholt193fa132011-12-20 11:36:07 -0800512
Eric Anholtb0371612011-12-20 15:19:24 -0800513 decode_2d_br01(ctx);
Eric Anholtc1d29462011-12-20 15:29:03 -0800514 instr_out(ctx, 2, "(%d,%d)\n",
Eric Anholt193fa132011-12-20 11:36:07 -0800515 data[2] & 0xffff, data[2] >> 16);
Eric Anholtc1d29462011-12-20 15:29:03 -0800516 instr_out(ctx, 3, "(%d,%d)\n",
Eric Anholt193fa132011-12-20 11:36:07 -0800517 data[3] & 0xffff, data[3] >> 16);
Eric Anholtc1d29462011-12-20 15:29:03 -0800518 instr_out(ctx, 4, "offset 0x%08x\n", data[4]);
519 instr_out(ctx, 5, "color\n");
Eric Anholt193fa132011-12-20 11:36:07 -0800520 return len;
521 case 0x53:
Eric Anholt62b41032011-12-20 15:17:24 -0800522 decode_2d_br00(ctx, "XY_SRC_COPY_BLT");
Eric Anholt193fa132011-12-20 11:36:07 -0800523
524 len = (data[0] & 0x000000ff) + 2;
525 if (len != 8)
526 fprintf(out, "Bad count in XY_SRC_COPY_BLT\n");
Eric Anholt193fa132011-12-20 11:36:07 -0800527
Eric Anholtb0371612011-12-20 15:19:24 -0800528 decode_2d_br01(ctx);
Eric Anholtc1d29462011-12-20 15:29:03 -0800529 instr_out(ctx, 2, "dst (%d,%d)\n",
Eric Anholt193fa132011-12-20 11:36:07 -0800530 data[2] & 0xffff, data[2] >> 16);
Eric Anholtc1d29462011-12-20 15:29:03 -0800531 instr_out(ctx, 3, "dst (%d,%d)\n",
Eric Anholt193fa132011-12-20 11:36:07 -0800532 data[3] & 0xffff, data[3] >> 16);
Eric Anholtc1d29462011-12-20 15:29:03 -0800533 instr_out(ctx, 4, "dst offset 0x%08x\n", data[4]);
534 instr_out(ctx, 5, "src (%d,%d)\n",
Eric Anholt193fa132011-12-20 11:36:07 -0800535 data[5] & 0xffff, data[5] >> 16);
Eric Anholtc1d29462011-12-20 15:29:03 -0800536 instr_out(ctx, 6, "src pitch %d\n",
Eric Anholt193fa132011-12-20 11:36:07 -0800537 (short)(data[6] & 0xffff));
Eric Anholtc1d29462011-12-20 15:29:03 -0800538 instr_out(ctx, 7, "src offset 0x%08x\n", data[7]);
Eric Anholt193fa132011-12-20 11:36:07 -0800539 return len;
540 }
541
542 for (opcode = 0; opcode < sizeof(opcodes_2d) / sizeof(opcodes_2d[0]);
543 opcode++) {
544 if ((data[0] & 0x1fc00000) >> 22 == opcodes_2d[opcode].opcode) {
545 unsigned int i;
546
547 len = 1;
Eric Anholtc1d29462011-12-20 15:29:03 -0800548 instr_out(ctx, 0, "%s\n",
Eric Anholt193fa132011-12-20 11:36:07 -0800549 opcodes_2d[opcode].name);
550 if (opcodes_2d[opcode].max_len > 1) {
551 len = (data[0] & 0x000000ff) + 2;
552 if (len < opcodes_2d[opcode].min_len ||
553 len > opcodes_2d[opcode].max_len) {
554 fprintf(out, "Bad count in %s\n",
555 opcodes_2d[opcode].name);
556 }
557 }
558
559 for (i = 1; i < len; i++) {
Eric Anholtc1d29462011-12-20 15:29:03 -0800560 instr_out(ctx, i, "dword %d\n", i);
Eric Anholt193fa132011-12-20 11:36:07 -0800561 }
562
563 return len;
564 }
565 }
566
Eric Anholtc1d29462011-12-20 15:29:03 -0800567 instr_out(ctx, 0, "2D UNKNOWN\n");
Eric Anholt193fa132011-12-20 11:36:07 -0800568 return 1;
569}
570
571static int
Eric Anholtde49fd42011-12-20 15:15:21 -0800572decode_3d_1c(struct drm_intel_decode *ctx)
Eric Anholt193fa132011-12-20 11:36:07 -0800573{
Eric Anholtde49fd42011-12-20 15:15:21 -0800574 uint32_t *data = ctx->data;
Eric Anholt193fa132011-12-20 11:36:07 -0800575 uint32_t opcode;
576
577 opcode = (data[0] & 0x00f80000) >> 19;
578
579 switch (opcode) {
580 case 0x11:
Eric Anholtc1d29462011-12-20 15:29:03 -0800581 instr_out(ctx, 0,
Eric Anholt193fa132011-12-20 11:36:07 -0800582 "3DSTATE_DEPTH_SUBRECTANGLE_DISABLE\n");
583 return 1;
584 case 0x10:
Eric Anholtc1d29462011-12-20 15:29:03 -0800585 instr_out(ctx, 0, "3DSTATE_SCISSOR_ENABLE %s\n",
Eric Anholt193fa132011-12-20 11:36:07 -0800586 data[0] & 1 ? "enabled" : "disabled");
587 return 1;
588 case 0x01:
Eric Anholtc1d29462011-12-20 15:29:03 -0800589 instr_out(ctx, 0, "3DSTATE_MAP_COORD_SET_I830\n");
Eric Anholt193fa132011-12-20 11:36:07 -0800590 return 1;
591 case 0x0a:
Eric Anholtc1d29462011-12-20 15:29:03 -0800592 instr_out(ctx, 0, "3DSTATE_MAP_CUBE_I830\n");
Eric Anholt193fa132011-12-20 11:36:07 -0800593 return 1;
594 case 0x05:
Eric Anholtc1d29462011-12-20 15:29:03 -0800595 instr_out(ctx, 0, "3DSTATE_MAP_TEX_STREAM_I830\n");
Eric Anholt193fa132011-12-20 11:36:07 -0800596 return 1;
597 }
598
Eric Anholtc1d29462011-12-20 15:29:03 -0800599 instr_out(ctx, 0, "3D UNKNOWN: 3d_1c opcode = 0x%x\n",
Eric Anholt193fa132011-12-20 11:36:07 -0800600 opcode);
Eric Anholt193fa132011-12-20 11:36:07 -0800601 return 1;
Eric Anholt8c4a2c82011-12-20 11:25:20 -0800602}
603
604/** Sets the string dstname to describe the destination of the PS instruction */
605static void
Eric Anholtbbdda922011-12-20 11:44:36 -0800606i915_get_instruction_dst(uint32_t *data, int i, char *dstname, int do_mask)
Eric Anholt8c4a2c82011-12-20 11:25:20 -0800607{
Eric Anholt193fa132011-12-20 11:36:07 -0800608 uint32_t a0 = data[i];
609 int dst_nr = (a0 >> 14) & 0xf;
610 char dstmask[8];
Eric Anholt1db55a82011-12-20 12:00:28 -0800611 const char *sat;
Eric Anholt8c4a2c82011-12-20 11:25:20 -0800612
Eric Anholt193fa132011-12-20 11:36:07 -0800613 if (do_mask) {
614 if (((a0 >> 10) & 0xf) == 0xf) {
615 dstmask[0] = 0;
616 } else {
617 int dstmask_index = 0;
618
619 dstmask[dstmask_index++] = '.';
620 if (a0 & (1 << 10))
621 dstmask[dstmask_index++] = 'x';
622 if (a0 & (1 << 11))
623 dstmask[dstmask_index++] = 'y';
624 if (a0 & (1 << 12))
625 dstmask[dstmask_index++] = 'z';
626 if (a0 & (1 << 13))
627 dstmask[dstmask_index++] = 'w';
628 dstmask[dstmask_index++] = 0;
629 }
630
631 if (a0 & (1 << 22))
632 sat = ".sat";
633 else
634 sat = "";
Eric Anholt8c4a2c82011-12-20 11:25:20 -0800635 } else {
Eric Anholt193fa132011-12-20 11:36:07 -0800636 dstmask[0] = 0;
637 sat = "";
Eric Anholt8c4a2c82011-12-20 11:25:20 -0800638 }
639
Eric Anholt193fa132011-12-20 11:36:07 -0800640 switch ((a0 >> 19) & 0x7) {
641 case 0:
642 if (dst_nr > 15)
643 fprintf(out, "bad destination reg R%d\n", dst_nr);
644 sprintf(dstname, "R%d%s%s", dst_nr, dstmask, sat);
645 break;
646 case 4:
647 if (dst_nr > 0)
648 fprintf(out, "bad destination reg oC%d\n", dst_nr);
649 sprintf(dstname, "oC%s%s", dstmask, sat);
650 break;
651 case 5:
652 if (dst_nr > 0)
653 fprintf(out, "bad destination reg oD%d\n", dst_nr);
654 sprintf(dstname, "oD%s%s", dstmask, sat);
655 break;
656 case 6:
657 if (dst_nr > 3)
658 fprintf(out, "bad destination reg U%d\n", dst_nr);
659 sprintf(dstname, "U%d%s%s", dst_nr, dstmask, sat);
660 break;
661 default:
662 sprintf(dstname, "RESERVED");
663 break;
664 }
Eric Anholt8c4a2c82011-12-20 11:25:20 -0800665}
666
Eric Anholt1db55a82011-12-20 12:00:28 -0800667static const char *
668i915_get_channel_swizzle(uint32_t select)
Eric Anholt8c4a2c82011-12-20 11:25:20 -0800669{
Eric Anholt193fa132011-12-20 11:36:07 -0800670 switch (select & 0x7) {
671 case 0:
672 return (select & 8) ? "-x" : "x";
673 case 1:
674 return (select & 8) ? "-y" : "y";
675 case 2:
676 return (select & 8) ? "-z" : "z";
677 case 3:
678 return (select & 8) ? "-w" : "w";
679 case 4:
680 return (select & 8) ? "-0" : "0";
681 case 5:
682 return (select & 8) ? "-1" : "1";
683 default:
684 return (select & 8) ? "-bad" : "bad";
685 }
Eric Anholt8c4a2c82011-12-20 11:25:20 -0800686}
687
688static void
689i915_get_instruction_src_name(uint32_t src_type, uint32_t src_nr, char *name)
690{
Eric Anholt193fa132011-12-20 11:36:07 -0800691 switch (src_type) {
692 case 0:
693 sprintf(name, "R%d", src_nr);
694 if (src_nr > 15)
695 fprintf(out, "bad src reg %s\n", name);
696 break;
697 case 1:
698 if (src_nr < 8)
699 sprintf(name, "T%d", src_nr);
700 else if (src_nr == 8)
701 sprintf(name, "DIFFUSE");
702 else if (src_nr == 9)
703 sprintf(name, "SPECULAR");
704 else if (src_nr == 10)
705 sprintf(name, "FOG");
706 else {
707 fprintf(out, "bad src reg T%d\n", src_nr);
708 sprintf(name, "RESERVED");
709 }
710 break;
711 case 2:
712 sprintf(name, "C%d", src_nr);
713 if (src_nr > 31)
714 fprintf(out, "bad src reg %s\n", name);
715 break;
716 case 4:
717 sprintf(name, "oC");
718 if (src_nr > 0)
719 fprintf(out, "bad src reg oC%d\n", src_nr);
720 break;
721 case 5:
722 sprintf(name, "oD");
723 if (src_nr > 0)
724 fprintf(out, "bad src reg oD%d\n", src_nr);
725 break;
726 case 6:
727 sprintf(name, "U%d", src_nr);
728 if (src_nr > 3)
729 fprintf(out, "bad src reg %s\n", name);
730 break;
731 default:
732 fprintf(out, "bad src reg type %d\n", src_type);
733 sprintf(name, "RESERVED");
734 break;
Eric Anholt8c4a2c82011-12-20 11:25:20 -0800735 }
Eric Anholt8c4a2c82011-12-20 11:25:20 -0800736}
737
Eric Anholtbbdda922011-12-20 11:44:36 -0800738static void i915_get_instruction_src0(uint32_t *data, int i, char *srcname)
Eric Anholt8c4a2c82011-12-20 11:25:20 -0800739{
Eric Anholt193fa132011-12-20 11:36:07 -0800740 uint32_t a0 = data[i];
741 uint32_t a1 = data[i + 1];
742 int src_nr = (a0 >> 2) & 0x1f;
Eric Anholt1db55a82011-12-20 12:00:28 -0800743 const char *swizzle_x = i915_get_channel_swizzle((a1 >> 28) & 0xf);
744 const char *swizzle_y = i915_get_channel_swizzle((a1 >> 24) & 0xf);
745 const char *swizzle_z = i915_get_channel_swizzle((a1 >> 20) & 0xf);
746 const char *swizzle_w = i915_get_channel_swizzle((a1 >> 16) & 0xf);
Eric Anholt193fa132011-12-20 11:36:07 -0800747 char swizzle[100];
Eric Anholt8c4a2c82011-12-20 11:25:20 -0800748
Eric Anholt193fa132011-12-20 11:36:07 -0800749 i915_get_instruction_src_name((a0 >> 7) & 0x7, src_nr, srcname);
750 sprintf(swizzle, ".%s%s%s%s", swizzle_x, swizzle_y, swizzle_z,
751 swizzle_w);
752 if (strcmp(swizzle, ".xyzw") != 0)
753 strcat(srcname, swizzle);
Eric Anholt8c4a2c82011-12-20 11:25:20 -0800754}
755
Eric Anholtbbdda922011-12-20 11:44:36 -0800756static void i915_get_instruction_src1(uint32_t *data, int i, char *srcname)
Eric Anholt8c4a2c82011-12-20 11:25:20 -0800757{
Eric Anholt193fa132011-12-20 11:36:07 -0800758 uint32_t a1 = data[i + 1];
759 uint32_t a2 = data[i + 2];
760 int src_nr = (a1 >> 8) & 0x1f;
Eric Anholt1db55a82011-12-20 12:00:28 -0800761 const char *swizzle_x = i915_get_channel_swizzle((a1 >> 4) & 0xf);
762 const char *swizzle_y = i915_get_channel_swizzle((a1 >> 0) & 0xf);
763 const char *swizzle_z = i915_get_channel_swizzle((a2 >> 28) & 0xf);
764 const char *swizzle_w = i915_get_channel_swizzle((a2 >> 24) & 0xf);
Eric Anholt193fa132011-12-20 11:36:07 -0800765 char swizzle[100];
Eric Anholt8c4a2c82011-12-20 11:25:20 -0800766
Eric Anholt193fa132011-12-20 11:36:07 -0800767 i915_get_instruction_src_name((a1 >> 13) & 0x7, src_nr, srcname);
768 sprintf(swizzle, ".%s%s%s%s", swizzle_x, swizzle_y, swizzle_z,
769 swizzle_w);
770 if (strcmp(swizzle, ".xyzw") != 0)
771 strcat(srcname, swizzle);
Eric Anholt8c4a2c82011-12-20 11:25:20 -0800772}
773
Eric Anholtbbdda922011-12-20 11:44:36 -0800774static void i915_get_instruction_src2(uint32_t *data, int i, char *srcname)
Eric Anholt8c4a2c82011-12-20 11:25:20 -0800775{
Eric Anholt193fa132011-12-20 11:36:07 -0800776 uint32_t a2 = data[i + 2];
777 int src_nr = (a2 >> 16) & 0x1f;
Eric Anholt1db55a82011-12-20 12:00:28 -0800778 const char *swizzle_x = i915_get_channel_swizzle((a2 >> 12) & 0xf);
779 const char *swizzle_y = i915_get_channel_swizzle((a2 >> 8) & 0xf);
780 const char *swizzle_z = i915_get_channel_swizzle((a2 >> 4) & 0xf);
781 const char *swizzle_w = i915_get_channel_swizzle((a2 >> 0) & 0xf);
Eric Anholt193fa132011-12-20 11:36:07 -0800782 char swizzle[100];
Eric Anholt8c4a2c82011-12-20 11:25:20 -0800783
Eric Anholt193fa132011-12-20 11:36:07 -0800784 i915_get_instruction_src_name((a2 >> 21) & 0x7, src_nr, srcname);
785 sprintf(swizzle, ".%s%s%s%s", swizzle_x, swizzle_y, swizzle_z,
786 swizzle_w);
787 if (strcmp(swizzle, ".xyzw") != 0)
788 strcat(srcname, swizzle);
Eric Anholt8c4a2c82011-12-20 11:25:20 -0800789}
790
791static void
792i915_get_instruction_addr(uint32_t src_type, uint32_t src_nr, char *name)
793{
Eric Anholt193fa132011-12-20 11:36:07 -0800794 switch (src_type) {
795 case 0:
796 sprintf(name, "R%d", src_nr);
797 if (src_nr > 15)
798 fprintf(out, "bad src reg %s\n", name);
799 break;
800 case 1:
801 if (src_nr < 8)
802 sprintf(name, "T%d", src_nr);
803 else if (src_nr == 8)
804 sprintf(name, "DIFFUSE");
805 else if (src_nr == 9)
806 sprintf(name, "SPECULAR");
807 else if (src_nr == 10)
808 sprintf(name, "FOG");
809 else {
810 fprintf(out, "bad src reg T%d\n", src_nr);
811 sprintf(name, "RESERVED");
812 }
813 break;
814 case 4:
815 sprintf(name, "oC");
816 if (src_nr > 0)
817 fprintf(out, "bad src reg oC%d\n", src_nr);
818 break;
819 case 5:
820 sprintf(name, "oD");
821 if (src_nr > 0)
822 fprintf(out, "bad src reg oD%d\n", src_nr);
823 break;
824 default:
825 fprintf(out, "bad src reg type %d\n", src_type);
826 sprintf(name, "RESERVED");
827 break;
Eric Anholt8c4a2c82011-12-20 11:25:20 -0800828 }
Eric Anholt8c4a2c82011-12-20 11:25:20 -0800829}
830
831static void
Eric Anholtc1d29462011-12-20 15:29:03 -0800832i915_decode_alu1(struct drm_intel_decode *ctx,
Eric Anholt1db55a82011-12-20 12:00:28 -0800833 int i, char *instr_prefix, const char *op_name)
Eric Anholt8c4a2c82011-12-20 11:25:20 -0800834{
Eric Anholt193fa132011-12-20 11:36:07 -0800835 char dst[100], src0[100];
Eric Anholt8c4a2c82011-12-20 11:25:20 -0800836
Eric Anholtc1d29462011-12-20 15:29:03 -0800837 i915_get_instruction_dst(ctx->data, i, dst, 1);
838 i915_get_instruction_src0(ctx->data, i, src0);
Eric Anholt8c4a2c82011-12-20 11:25:20 -0800839
Eric Anholtc1d29462011-12-20 15:29:03 -0800840 instr_out(ctx, i++, "%s: %s %s, %s\n", instr_prefix,
Eric Anholt193fa132011-12-20 11:36:07 -0800841 op_name, dst, src0);
Eric Anholtc1d29462011-12-20 15:29:03 -0800842 instr_out(ctx, i++, "%s\n", instr_prefix);
843 instr_out(ctx, i++, "%s\n", instr_prefix);
Eric Anholt8c4a2c82011-12-20 11:25:20 -0800844}
845
846static void
Eric Anholtc1d29462011-12-20 15:29:03 -0800847i915_decode_alu2(struct drm_intel_decode *ctx,
Eric Anholt1db55a82011-12-20 12:00:28 -0800848 int i, char *instr_prefix, const char *op_name)
Eric Anholt8c4a2c82011-12-20 11:25:20 -0800849{
Eric Anholt193fa132011-12-20 11:36:07 -0800850 char dst[100], src0[100], src1[100];
Eric Anholt8c4a2c82011-12-20 11:25:20 -0800851
Eric Anholtc1d29462011-12-20 15:29:03 -0800852 i915_get_instruction_dst(ctx->data, i, dst, 1);
853 i915_get_instruction_src0(ctx->data, i, src0);
854 i915_get_instruction_src1(ctx->data, i, src1);
Eric Anholt8c4a2c82011-12-20 11:25:20 -0800855
Eric Anholtc1d29462011-12-20 15:29:03 -0800856 instr_out(ctx, i++, "%s: %s %s, %s, %s\n", instr_prefix,
Eric Anholt193fa132011-12-20 11:36:07 -0800857 op_name, dst, src0, src1);
Eric Anholtc1d29462011-12-20 15:29:03 -0800858 instr_out(ctx, i++, "%s\n", instr_prefix);
859 instr_out(ctx, i++, "%s\n", instr_prefix);
Eric Anholt8c4a2c82011-12-20 11:25:20 -0800860}
861
862static void
Eric Anholtc1d29462011-12-20 15:29:03 -0800863i915_decode_alu3(struct drm_intel_decode *ctx,
Eric Anholt1db55a82011-12-20 12:00:28 -0800864 int i, char *instr_prefix, const char *op_name)
Eric Anholt8c4a2c82011-12-20 11:25:20 -0800865{
Eric Anholt193fa132011-12-20 11:36:07 -0800866 char dst[100], src0[100], src1[100], src2[100];
Eric Anholt8c4a2c82011-12-20 11:25:20 -0800867
Eric Anholtc1d29462011-12-20 15:29:03 -0800868 i915_get_instruction_dst(ctx->data, i, dst, 1);
869 i915_get_instruction_src0(ctx->data, i, src0);
870 i915_get_instruction_src1(ctx->data, i, src1);
871 i915_get_instruction_src2(ctx->data, i, src2);
Eric Anholt8c4a2c82011-12-20 11:25:20 -0800872
Eric Anholtc1d29462011-12-20 15:29:03 -0800873 instr_out(ctx, i++, "%s: %s %s, %s, %s, %s\n", instr_prefix,
Eric Anholt193fa132011-12-20 11:36:07 -0800874 op_name, dst, src0, src1, src2);
Eric Anholtc1d29462011-12-20 15:29:03 -0800875 instr_out(ctx, i++, "%s\n", instr_prefix);
876 instr_out(ctx, i++, "%s\n", instr_prefix);
Eric Anholt8c4a2c82011-12-20 11:25:20 -0800877}
878
879static void
Eric Anholtc1d29462011-12-20 15:29:03 -0800880i915_decode_tex(struct drm_intel_decode *ctx, int i,
Eric Anholt1db55a82011-12-20 12:00:28 -0800881 const char *instr_prefix, const char *tex_name)
Eric Anholt8c4a2c82011-12-20 11:25:20 -0800882{
Eric Anholtc1d29462011-12-20 15:29:03 -0800883 uint32_t t0 = ctx->data[i];
884 uint32_t t1 = ctx->data[i + 1];
Eric Anholt193fa132011-12-20 11:36:07 -0800885 char dst_name[100];
886 char addr_name[100];
887 int sampler_nr;
Eric Anholt8c4a2c82011-12-20 11:25:20 -0800888
Eric Anholtc1d29462011-12-20 15:29:03 -0800889 i915_get_instruction_dst(ctx->data, i, dst_name, 0);
Eric Anholt193fa132011-12-20 11:36:07 -0800890 i915_get_instruction_addr((t1 >> 24) & 0x7,
891 (t1 >> 17) & 0xf, addr_name);
892 sampler_nr = t0 & 0xf;
Eric Anholt8c4a2c82011-12-20 11:25:20 -0800893
Eric Anholtc1d29462011-12-20 15:29:03 -0800894 instr_out(ctx, i++, "%s: %s %s, S%d, %s\n", instr_prefix,
Eric Anholt193fa132011-12-20 11:36:07 -0800895 tex_name, dst_name, sampler_nr, addr_name);
Eric Anholtc1d29462011-12-20 15:29:03 -0800896 instr_out(ctx, i++, "%s\n", instr_prefix);
897 instr_out(ctx, i++, "%s\n", instr_prefix);
Eric Anholt8c4a2c82011-12-20 11:25:20 -0800898}
899
900static void
Eric Anholtc1d29462011-12-20 15:29:03 -0800901i915_decode_dcl(struct drm_intel_decode *ctx, int i, char *instr_prefix)
Eric Anholt8c4a2c82011-12-20 11:25:20 -0800902{
Eric Anholtc1d29462011-12-20 15:29:03 -0800903 uint32_t d0 = ctx->data[i];
Eric Anholt1db55a82011-12-20 12:00:28 -0800904 const char *sampletype;
Eric Anholt193fa132011-12-20 11:36:07 -0800905 int dcl_nr = (d0 >> 14) & 0xf;
Eric Anholt1db55a82011-12-20 12:00:28 -0800906 const char *dcl_x = d0 & (1 << 10) ? "x" : "";
907 const char *dcl_y = d0 & (1 << 11) ? "y" : "";
908 const char *dcl_z = d0 & (1 << 12) ? "z" : "";
909 const char *dcl_w = d0 & (1 << 13) ? "w" : "";
Eric Anholt193fa132011-12-20 11:36:07 -0800910 char dcl_mask[10];
Eric Anholt8c4a2c82011-12-20 11:25:20 -0800911
Eric Anholt193fa132011-12-20 11:36:07 -0800912 switch ((d0 >> 19) & 0x3) {
Eric Anholt8c4a2c82011-12-20 11:25:20 -0800913 case 1:
Eric Anholt193fa132011-12-20 11:36:07 -0800914 sprintf(dcl_mask, ".%s%s%s%s", dcl_x, dcl_y, dcl_z, dcl_w);
915 if (strcmp(dcl_mask, ".") == 0)
916 fprintf(out, "bad (empty) dcl mask\n");
917
918 if (dcl_nr > 10)
919 fprintf(out, "bad T%d dcl register number\n", dcl_nr);
920 if (dcl_nr < 8) {
921 if (strcmp(dcl_mask, ".x") != 0 &&
922 strcmp(dcl_mask, ".xy") != 0 &&
923 strcmp(dcl_mask, ".xz") != 0 &&
924 strcmp(dcl_mask, ".w") != 0 &&
925 strcmp(dcl_mask, ".xyzw") != 0) {
926 fprintf(out, "bad T%d.%s dcl mask\n", dcl_nr,
927 dcl_mask);
928 }
Eric Anholtc1d29462011-12-20 15:29:03 -0800929 instr_out(ctx, i++, "%s: DCL T%d%s\n",
Eric Anholt193fa132011-12-20 11:36:07 -0800930 instr_prefix, dcl_nr, dcl_mask);
931 } else {
932 if (strcmp(dcl_mask, ".xz") == 0)
933 fprintf(out, "errataed bad dcl mask %s\n",
934 dcl_mask);
935 else if (strcmp(dcl_mask, ".xw") == 0)
936 fprintf(out, "errataed bad dcl mask %s\n",
937 dcl_mask);
938 else if (strcmp(dcl_mask, ".xzw") == 0)
939 fprintf(out, "errataed bad dcl mask %s\n",
940 dcl_mask);
941
942 if (dcl_nr == 8) {
Eric Anholtc1d29462011-12-20 15:29:03 -0800943 instr_out(ctx, i++,
Eric Anholt193fa132011-12-20 11:36:07 -0800944 "%s: DCL DIFFUSE%s\n", instr_prefix,
945 dcl_mask);
946 } else if (dcl_nr == 9) {
Eric Anholtc1d29462011-12-20 15:29:03 -0800947 instr_out(ctx, i++,
Eric Anholt193fa132011-12-20 11:36:07 -0800948 "%s: DCL SPECULAR%s\n", instr_prefix,
949 dcl_mask);
950 } else if (dcl_nr == 10) {
Eric Anholtc1d29462011-12-20 15:29:03 -0800951 instr_out(ctx, i++,
Eric Anholt193fa132011-12-20 11:36:07 -0800952 "%s: DCL FOG%s\n", instr_prefix,
953 dcl_mask);
954 }
955 }
Eric Anholtc1d29462011-12-20 15:29:03 -0800956 instr_out(ctx, i++, "%s\n", instr_prefix);
957 instr_out(ctx, i++, "%s\n", instr_prefix);
Eric Anholt193fa132011-12-20 11:36:07 -0800958 break;
959 case 3:
960 switch ((d0 >> 22) & 0x3) {
961 case 0:
962 sampletype = "2D";
963 break;
964 case 1:
965 sampletype = "CUBE";
966 break;
967 case 2:
968 sampletype = "3D";
969 break;
970 default:
971 sampletype = "RESERVED";
972 break;
973 }
974 if (dcl_nr > 15)
975 fprintf(out, "bad S%d dcl register number\n", dcl_nr);
Eric Anholtc1d29462011-12-20 15:29:03 -0800976 instr_out(ctx, i++, "%s: DCL S%d %s\n",
Eric Anholt193fa132011-12-20 11:36:07 -0800977 instr_prefix, dcl_nr, sampletype);
Eric Anholtc1d29462011-12-20 15:29:03 -0800978 instr_out(ctx, i++, "%s\n", instr_prefix);
979 instr_out(ctx, i++, "%s\n", instr_prefix);
Eric Anholt193fa132011-12-20 11:36:07 -0800980 break;
Eric Anholt8c4a2c82011-12-20 11:25:20 -0800981 default:
Eric Anholtc1d29462011-12-20 15:29:03 -0800982 instr_out(ctx, i++, "%s: DCL RESERVED%d\n",
Eric Anholt193fa132011-12-20 11:36:07 -0800983 instr_prefix, dcl_nr);
Eric Anholtc1d29462011-12-20 15:29:03 -0800984 instr_out(ctx, i++, "%s\n", instr_prefix);
985 instr_out(ctx, i++, "%s\n", instr_prefix);
Eric Anholt8c4a2c82011-12-20 11:25:20 -0800986 }
Eric Anholt8c4a2c82011-12-20 11:25:20 -0800987}
988
989static void
Eric Anholtc1d29462011-12-20 15:29:03 -0800990i915_decode_instruction(struct drm_intel_decode *ctx,
Eric Anholt8c4a2c82011-12-20 11:25:20 -0800991 int i, char *instr_prefix)
992{
Eric Anholtc1d29462011-12-20 15:29:03 -0800993 switch ((ctx->data[i] >> 24) & 0x1f) {
Eric Anholt193fa132011-12-20 11:36:07 -0800994 case 0x0:
Eric Anholtc1d29462011-12-20 15:29:03 -0800995 instr_out(ctx, i++, "%s: NOP\n", instr_prefix);
996 instr_out(ctx, i++, "%s\n", instr_prefix);
997 instr_out(ctx, i++, "%s\n", instr_prefix);
Eric Anholt193fa132011-12-20 11:36:07 -0800998 break;
999 case 0x01:
Eric Anholtc1d29462011-12-20 15:29:03 -08001000 i915_decode_alu2(ctx, i, instr_prefix, "ADD");
Eric Anholt193fa132011-12-20 11:36:07 -08001001 break;
1002 case 0x02:
Eric Anholtc1d29462011-12-20 15:29:03 -08001003 i915_decode_alu1(ctx, i, instr_prefix, "MOV");
Eric Anholt193fa132011-12-20 11:36:07 -08001004 break;
1005 case 0x03:
Eric Anholtc1d29462011-12-20 15:29:03 -08001006 i915_decode_alu2(ctx, i, instr_prefix, "MUL");
Eric Anholt193fa132011-12-20 11:36:07 -08001007 break;
1008 case 0x04:
Eric Anholtc1d29462011-12-20 15:29:03 -08001009 i915_decode_alu3(ctx, i, instr_prefix, "MAD");
Eric Anholt193fa132011-12-20 11:36:07 -08001010 break;
1011 case 0x05:
Eric Anholtc1d29462011-12-20 15:29:03 -08001012 i915_decode_alu3(ctx, i, instr_prefix, "DP2ADD");
Eric Anholt193fa132011-12-20 11:36:07 -08001013 break;
1014 case 0x06:
Eric Anholtc1d29462011-12-20 15:29:03 -08001015 i915_decode_alu2(ctx, i, instr_prefix, "DP3");
Eric Anholt193fa132011-12-20 11:36:07 -08001016 break;
1017 case 0x07:
Eric Anholtc1d29462011-12-20 15:29:03 -08001018 i915_decode_alu2(ctx, i, instr_prefix, "DP4");
Eric Anholt193fa132011-12-20 11:36:07 -08001019 break;
1020 case 0x08:
Eric Anholtc1d29462011-12-20 15:29:03 -08001021 i915_decode_alu1(ctx, i, instr_prefix, "FRC");
Eric Anholt193fa132011-12-20 11:36:07 -08001022 break;
1023 case 0x09:
Eric Anholtc1d29462011-12-20 15:29:03 -08001024 i915_decode_alu1(ctx, i, instr_prefix, "RCP");
Eric Anholt193fa132011-12-20 11:36:07 -08001025 break;
1026 case 0x0a:
Eric Anholtc1d29462011-12-20 15:29:03 -08001027 i915_decode_alu1(ctx, i, instr_prefix, "RSQ");
Eric Anholt193fa132011-12-20 11:36:07 -08001028 break;
1029 case 0x0b:
Eric Anholtc1d29462011-12-20 15:29:03 -08001030 i915_decode_alu1(ctx, i, instr_prefix, "EXP");
Eric Anholt193fa132011-12-20 11:36:07 -08001031 break;
1032 case 0x0c:
Eric Anholtc1d29462011-12-20 15:29:03 -08001033 i915_decode_alu1(ctx, i, instr_prefix, "LOG");
Eric Anholt193fa132011-12-20 11:36:07 -08001034 break;
1035 case 0x0d:
Eric Anholtc1d29462011-12-20 15:29:03 -08001036 i915_decode_alu2(ctx, i, instr_prefix, "CMP");
Eric Anholt193fa132011-12-20 11:36:07 -08001037 break;
1038 case 0x0e:
Eric Anholtc1d29462011-12-20 15:29:03 -08001039 i915_decode_alu2(ctx, i, instr_prefix, "MIN");
Eric Anholt193fa132011-12-20 11:36:07 -08001040 break;
1041 case 0x0f:
Eric Anholtc1d29462011-12-20 15:29:03 -08001042 i915_decode_alu2(ctx, i, instr_prefix, "MAX");
Eric Anholt193fa132011-12-20 11:36:07 -08001043 break;
1044 case 0x10:
Eric Anholtc1d29462011-12-20 15:29:03 -08001045 i915_decode_alu1(ctx, i, instr_prefix, "FLR");
Eric Anholt193fa132011-12-20 11:36:07 -08001046 break;
1047 case 0x11:
Eric Anholtc1d29462011-12-20 15:29:03 -08001048 i915_decode_alu1(ctx, i, instr_prefix, "MOD");
Eric Anholt193fa132011-12-20 11:36:07 -08001049 break;
1050 case 0x12:
Eric Anholtc1d29462011-12-20 15:29:03 -08001051 i915_decode_alu1(ctx, i, instr_prefix, "TRC");
Eric Anholt193fa132011-12-20 11:36:07 -08001052 break;
1053 case 0x13:
Eric Anholtc1d29462011-12-20 15:29:03 -08001054 i915_decode_alu2(ctx, i, instr_prefix, "SGE");
Eric Anholt193fa132011-12-20 11:36:07 -08001055 break;
1056 case 0x14:
Eric Anholtc1d29462011-12-20 15:29:03 -08001057 i915_decode_alu2(ctx, i, instr_prefix, "SLT");
Eric Anholt193fa132011-12-20 11:36:07 -08001058 break;
1059 case 0x15:
Eric Anholtc1d29462011-12-20 15:29:03 -08001060 i915_decode_tex(ctx, i, instr_prefix, "TEXLD");
Eric Anholt193fa132011-12-20 11:36:07 -08001061 break;
1062 case 0x16:
Eric Anholtc1d29462011-12-20 15:29:03 -08001063 i915_decode_tex(ctx, i, instr_prefix, "TEXLDP");
Eric Anholt193fa132011-12-20 11:36:07 -08001064 break;
1065 case 0x17:
Eric Anholtc1d29462011-12-20 15:29:03 -08001066 i915_decode_tex(ctx, i, instr_prefix, "TEXLDB");
Eric Anholt193fa132011-12-20 11:36:07 -08001067 break;
1068 case 0x19:
Eric Anholtc1d29462011-12-20 15:29:03 -08001069 i915_decode_dcl(ctx, i, instr_prefix);
Eric Anholt193fa132011-12-20 11:36:07 -08001070 break;
1071 default:
Eric Anholtc1d29462011-12-20 15:29:03 -08001072 instr_out(ctx, i++, "%s: unknown\n", instr_prefix);
1073 instr_out(ctx, i++, "%s\n", instr_prefix);
1074 instr_out(ctx, i++, "%s\n", instr_prefix);
Eric Anholt193fa132011-12-20 11:36:07 -08001075 break;
1076 }
Eric Anholt8c4a2c82011-12-20 11:25:20 -08001077}
1078
Eric Anholt1db55a82011-12-20 12:00:28 -08001079static const char *
1080decode_compare_func(uint32_t op)
Eric Anholt8c4a2c82011-12-20 11:25:20 -08001081{
Eric Anholt193fa132011-12-20 11:36:07 -08001082 switch (op & 0x7) {
1083 case 0:
1084 return "always";
1085 case 1:
1086 return "never";
1087 case 2:
1088 return "less";
1089 case 3:
1090 return "equal";
1091 case 4:
1092 return "lequal";
1093 case 5:
1094 return "greater";
1095 case 6:
1096 return "notequal";
1097 case 7:
1098 return "gequal";
1099 }
1100 return "";
Eric Anholt8c4a2c82011-12-20 11:25:20 -08001101}
1102
Eric Anholt1db55a82011-12-20 12:00:28 -08001103static const char *
1104decode_stencil_op(uint32_t op)
Eric Anholt8c4a2c82011-12-20 11:25:20 -08001105{
Eric Anholt193fa132011-12-20 11:36:07 -08001106 switch (op & 0x7) {
1107 case 0:
1108 return "keep";
1109 case 1:
1110 return "zero";
1111 case 2:
1112 return "replace";
1113 case 3:
1114 return "incr_sat";
1115 case 4:
1116 return "decr_sat";
1117 case 5:
1118 return "greater";
1119 case 6:
1120 return "incr";
1121 case 7:
1122 return "decr";
1123 }
1124 return "";
Eric Anholt8c4a2c82011-12-20 11:25:20 -08001125}
1126
Eric Anholt4149faf2011-12-20 14:32:27 -08001127#if 0
Eric Anholt1db55a82011-12-20 12:00:28 -08001128static const char *
1129decode_logic_op(uint32_t op)
Eric Anholt8c4a2c82011-12-20 11:25:20 -08001130{
Eric Anholt193fa132011-12-20 11:36:07 -08001131 switch (op & 0xf) {
1132 case 0:
1133 return "clear";
1134 case 1:
1135 return "nor";
1136 case 2:
1137 return "and_inv";
1138 case 3:
1139 return "copy_inv";
1140 case 4:
1141 return "and_rvrse";
1142 case 5:
1143 return "inv";
1144 case 6:
1145 return "xor";
1146 case 7:
1147 return "nand";
1148 case 8:
1149 return "and";
1150 case 9:
1151 return "equiv";
1152 case 10:
1153 return "noop";
1154 case 11:
1155 return "or_inv";
1156 case 12:
1157 return "copy";
1158 case 13:
1159 return "or_rvrse";
1160 case 14:
1161 return "or";
1162 case 15:
1163 return "set";
1164 }
1165 return "";
Eric Anholt8c4a2c82011-12-20 11:25:20 -08001166}
Eric Anholt4149faf2011-12-20 14:32:27 -08001167#endif
Eric Anholt8c4a2c82011-12-20 11:25:20 -08001168
Eric Anholt1db55a82011-12-20 12:00:28 -08001169static const char *
1170decode_blend_fact(uint32_t op)
Eric Anholt8c4a2c82011-12-20 11:25:20 -08001171{
Eric Anholt193fa132011-12-20 11:36:07 -08001172 switch (op & 0xf) {
1173 case 1:
1174 return "zero";
1175 case 2:
1176 return "one";
1177 case 3:
1178 return "src_colr";
1179 case 4:
1180 return "inv_src_colr";
1181 case 5:
1182 return "src_alpha";
1183 case 6:
1184 return "inv_src_alpha";
1185 case 7:
1186 return "dst_alpha";
1187 case 8:
1188 return "inv_dst_alpha";
1189 case 9:
1190 return "dst_colr";
1191 case 10:
1192 return "inv_dst_colr";
1193 case 11:
1194 return "src_alpha_sat";
1195 case 12:
1196 return "cnst_colr";
1197 case 13:
1198 return "inv_cnst_colr";
1199 case 14:
1200 return "cnst_alpha";
1201 case 15:
1202 return "inv_const_alpha";
1203 }
1204 return "";
Eric Anholt8c4a2c82011-12-20 11:25:20 -08001205}
1206
Eric Anholt1db55a82011-12-20 12:00:28 -08001207static const char *
1208decode_tex_coord_mode(uint32_t mode)
Eric Anholt8c4a2c82011-12-20 11:25:20 -08001209{
Eric Anholt193fa132011-12-20 11:36:07 -08001210 switch (mode & 0x7) {
1211 case 0:
1212 return "wrap";
1213 case 1:
1214 return "mirror";
1215 case 2:
1216 return "clamp_edge";
1217 case 3:
1218 return "cube";
1219 case 4:
1220 return "clamp_border";
1221 case 5:
1222 return "mirror_once";
1223 }
1224 return "";
Eric Anholt8c4a2c82011-12-20 11:25:20 -08001225}
1226
Eric Anholt1db55a82011-12-20 12:00:28 -08001227static const char *
1228decode_sample_filter(uint32_t mode)
Eric Anholt8c4a2c82011-12-20 11:25:20 -08001229{
Eric Anholt193fa132011-12-20 11:36:07 -08001230 switch (mode & 0x7) {
1231 case 0:
1232 return "nearest";
1233 case 1:
1234 return "linear";
1235 case 2:
1236 return "anisotropic";
1237 case 3:
1238 return "4x4_1";
1239 case 4:
1240 return "4x4_2";
1241 case 5:
1242 return "4x4_flat";
1243 case 6:
1244 return "6x5_mono";
1245 }
1246 return "";
Eric Anholt8c4a2c82011-12-20 11:25:20 -08001247}
1248
1249static int
Eric Anholtde49fd42011-12-20 15:15:21 -08001250decode_3d_1d(struct drm_intel_decode *ctx)
Eric Anholt8c4a2c82011-12-20 11:25:20 -08001251{
Eric Anholt193fa132011-12-20 11:36:07 -08001252 unsigned int len, i, c, idx, word, map, sampler, instr;
Eric Anholt1db55a82011-12-20 12:00:28 -08001253 const char *format, *zformat, *type;
Eric Anholt8c4a2c82011-12-20 11:25:20 -08001254 uint32_t opcode;
Eric Anholtde49fd42011-12-20 15:15:21 -08001255 uint32_t *data = ctx->data;
Eric Anholtde49fd42011-12-20 15:15:21 -08001256 uint32_t devid = ctx->devid;
Eric Anholt8c4a2c82011-12-20 11:25:20 -08001257
Eric Anholt193fa132011-12-20 11:36:07 -08001258 struct {
1259 uint32_t opcode;
1260 int i830_only;
Eric Anholt07768ba2011-12-20 13:46:23 -08001261 unsigned int min_len;
1262 unsigned int max_len;
Eric Anholt1db55a82011-12-20 12:00:28 -08001263 const char *name;
Eric Anholt193fa132011-12-20 11:36:07 -08001264 } opcodes_3d_1d[] = {
Eric Anholtbbdda922011-12-20 11:44:36 -08001265 { 0x86, 0, 4, 4, "3DSTATE_CHROMA_KEY" },
1266 { 0x88, 0, 2, 2, "3DSTATE_CONSTANT_BLEND_COLOR" },
1267 { 0x99, 0, 2, 2, "3DSTATE_DEFAULT_DIFFUSE" },
1268 { 0x9a, 0, 2, 2, "3DSTATE_DEFAULT_SPECULAR" },
1269 { 0x98, 0, 2, 2, "3DSTATE_DEFAULT_Z" },
1270 { 0x97, 0, 2, 2, "3DSTATE_DEPTH_OFFSET_SCALE" },
1271 { 0x9d, 0, 65, 65, "3DSTATE_FILTER_COEFFICIENTS_4X4" },
1272 { 0x9e, 0, 4, 4, "3DSTATE_MONO_FILTER" },
1273 { 0x89, 0, 4, 4, "3DSTATE_FOG_MODE" },
1274 { 0x8f, 0, 2, 16, "3DSTATE_MAP_PALLETE_LOAD_32" },
1275 { 0x83, 0, 2, 2, "3DSTATE_SPAN_STIPPLE" },
1276 { 0x8c, 1, 2, 2, "3DSTATE_MAP_COORD_TRANSFORM_I830" },
1277 { 0x8b, 1, 2, 2, "3DSTATE_MAP_VERTEX_TRANSFORM_I830" },
1278 { 0x8d, 1, 3, 3, "3DSTATE_W_STATE_I830" },
1279 { 0x01, 1, 2, 2, "3DSTATE_COLOR_FACTOR_I830" },
1280 { 0x02, 1, 2, 2, "3DSTATE_MAP_COORD_SETBIND_I830"},
1281 }, *opcode_3d_1d;
Eric Anholt8c4a2c82011-12-20 11:25:20 -08001282
Eric Anholt193fa132011-12-20 11:36:07 -08001283 opcode = (data[0] & 0x00ff0000) >> 16;
Eric Anholt8c4a2c82011-12-20 11:25:20 -08001284
Eric Anholt193fa132011-12-20 11:36:07 -08001285 switch (opcode) {
1286 case 0x07:
Eric Anholtbbdda922011-12-20 11:44:36 -08001287 /* This instruction is unusual. A 0 length means just
1288 * 1 DWORD instead of 2. The 0 length is specified in
1289 * one place to be unsupported, but stated to be
1290 * required in another, and 0 length LOAD_INDIRECTs
1291 * appear to cause no harm at least.
Eric Anholt193fa132011-12-20 11:36:07 -08001292 */
Eric Anholtc1d29462011-12-20 15:29:03 -08001293 instr_out(ctx, 0, "3DSTATE_LOAD_INDIRECT\n");
Eric Anholt193fa132011-12-20 11:36:07 -08001294 len = (data[0] & 0x000000ff) + 1;
1295 i = 1;
1296 if (data[0] & (0x01 << 8)) {
Eric Anholtc1d29462011-12-20 15:29:03 -08001297 instr_out(ctx, i++, "SIS.0\n");
1298 instr_out(ctx, i++, "SIS.1\n");
Eric Anholt193fa132011-12-20 11:36:07 -08001299 }
1300 if (data[0] & (0x02 << 8)) {
Eric Anholtc1d29462011-12-20 15:29:03 -08001301 instr_out(ctx, i++, "DIS.0\n");
Eric Anholt193fa132011-12-20 11:36:07 -08001302 }
1303 if (data[0] & (0x04 << 8)) {
Eric Anholtc1d29462011-12-20 15:29:03 -08001304 instr_out(ctx, i++, "SSB.0\n");
1305 instr_out(ctx, i++, "SSB.1\n");
Eric Anholt193fa132011-12-20 11:36:07 -08001306 }
1307 if (data[0] & (0x08 << 8)) {
Eric Anholtc1d29462011-12-20 15:29:03 -08001308 instr_out(ctx, i++, "MSB.0\n");
1309 instr_out(ctx, i++, "MSB.1\n");
Eric Anholt193fa132011-12-20 11:36:07 -08001310 }
1311 if (data[0] & (0x10 << 8)) {
Eric Anholtc1d29462011-12-20 15:29:03 -08001312 instr_out(ctx, i++, "PSP.0\n");
1313 instr_out(ctx, i++, "PSP.1\n");
Eric Anholt193fa132011-12-20 11:36:07 -08001314 }
1315 if (data[0] & (0x20 << 8)) {
Eric Anholtc1d29462011-12-20 15:29:03 -08001316 instr_out(ctx, i++, "PSC.0\n");
1317 instr_out(ctx, i++, "PSC.1\n");
Eric Anholt193fa132011-12-20 11:36:07 -08001318 }
1319 if (len != i) {
1320 fprintf(out, "Bad count in 3DSTATE_LOAD_INDIRECT\n");
Eric Anholt193fa132011-12-20 11:36:07 -08001321 return len;
1322 }
1323 return len;
1324 case 0x04:
Eric Anholtc1d29462011-12-20 15:29:03 -08001325 instr_out(ctx, 0,
Eric Anholt193fa132011-12-20 11:36:07 -08001326 "3DSTATE_LOAD_STATE_IMMEDIATE_1\n");
1327 len = (data[0] & 0x0000000f) + 2;
1328 i = 1;
1329 for (word = 0; word <= 8; word++) {
1330 if (data[0] & (1 << (4 + word))) {
Eric Anholt193fa132011-12-20 11:36:07 -08001331 /* save vertex state for decode */
1332 if (!IS_GEN2(devid)) {
Eric Anholt7b483182011-12-20 14:27:17 -08001333 int tex_num;
1334
Eric Anholt193fa132011-12-20 11:36:07 -08001335 if (word == 2) {
1336 saved_s2_set = 1;
1337 saved_s2 = data[i];
Eric Anholt8c4a2c82011-12-20 11:25:20 -08001338 }
Eric Anholt193fa132011-12-20 11:36:07 -08001339 if (word == 4) {
1340 saved_s4_set = 1;
1341 saved_s4 = data[i];
1342 }
1343
1344 switch (word) {
1345 case 0:
Eric Anholtc1d29462011-12-20 15:29:03 -08001346 instr_out(ctx, i,
Eric Anholt193fa132011-12-20 11:36:07 -08001347 "S0: vbo offset: 0x%08x%s\n",
1348 data[i] & (~1),
1349 data[i] & 1 ?
1350 ", auto cache invalidate disabled"
1351 : "");
1352 break;
1353 case 1:
Eric Anholtc1d29462011-12-20 15:29:03 -08001354 instr_out(ctx, i,
Eric Anholt193fa132011-12-20 11:36:07 -08001355 "S1: vertex width: %i, vertex pitch: %i\n",
1356 (data[i] >> 24) &
1357 0x3f,
1358 (data[i] >> 16) &
1359 0x3f);
1360 break;
1361 case 2:
Eric Anholtc1d29462011-12-20 15:29:03 -08001362 instr_out(ctx, i,
Eric Anholt193fa132011-12-20 11:36:07 -08001363 "S2: texcoord formats: ");
Eric Anholt7b483182011-12-20 14:27:17 -08001364 for (tex_num = 0;
Eric Anholt193fa132011-12-20 11:36:07 -08001365 tex_num < 8; tex_num++) {
1366 switch ((data[i] >>
1367 tex_num *
1368 4) & 0xf) {
1369 case 0:
1370 fprintf(out,
1371 "%i=2D ",
1372 tex_num);
1373 break;
1374 case 1:
1375 fprintf(out,
1376 "%i=3D ",
1377 tex_num);
1378 break;
1379 case 2:
1380 fprintf(out,
1381 "%i=4D ",
1382 tex_num);
1383 break;
1384 case 3:
1385 fprintf(out,
1386 "%i=1D ",
1387 tex_num);
1388 break;
1389 case 4:
1390 fprintf(out,
1391 "%i=2D_16 ",
1392 tex_num);
1393 break;
1394 case 5:
1395 fprintf(out,
1396 "%i=4D_16 ",
1397 tex_num);
1398 break;
1399 case 0xf:
1400 fprintf(out,
1401 "%i=NP ",
1402 tex_num);
1403 break;
1404 }
1405 }
1406 fprintf(out, "\n");
1407
1408 break;
1409 case 3:
Eric Anholtc1d29462011-12-20 15:29:03 -08001410 instr_out(ctx, i,
Eric Anholt0c46f022011-12-20 14:23:15 -08001411 "S3: not documented\n");
Eric Anholt193fa132011-12-20 11:36:07 -08001412 break;
1413 case 4:
1414 {
Eric Anholt1db55a82011-12-20 12:00:28 -08001415 const char *cullmode = "";
1416 const char *vfmt_xyzw = "";
Eric Anholt193fa132011-12-20 11:36:07 -08001417 switch ((data[i] >> 13)
1418 & 0x3) {
1419 case 0:
1420 cullmode =
1421 "both";
1422 break;
1423 case 1:
1424 cullmode =
1425 "none";
1426 break;
1427 case 2:
1428 cullmode = "cw";
1429 break;
1430 case 3:
1431 cullmode =
1432 "ccw";
1433 break;
1434 }
1435 switch (data[i] &
1436 (7 << 6 | 1 <<
1437 2)) {
1438 case 1 << 6:
1439 vfmt_xyzw =
1440 "XYZ,";
1441 break;
1442 case 2 << 6:
1443 vfmt_xyzw =
1444 "XYZW,";
1445 break;
1446 case 3 << 6:
1447 vfmt_xyzw =
1448 "XY,";
1449 break;
1450 case 4 << 6:
1451 vfmt_xyzw =
1452 "XYW,";
1453 break;
1454 case 1 << 6 | 1 << 2:
1455 vfmt_xyzw =
1456 "XYZF,";
1457 break;
1458 case 2 << 6 | 1 << 2:
1459 vfmt_xyzw =
1460 "XYZWF,";
1461 break;
1462 case 3 << 6 | 1 << 2:
1463 vfmt_xyzw =
1464 "XYF,";
1465 break;
1466 case 4 << 6 | 1 << 2:
1467 vfmt_xyzw =
1468 "XYWF,";
1469 break;
1470 }
Eric Anholtc1d29462011-12-20 15:29:03 -08001471 instr_out(ctx, i,
Eric Anholt193fa132011-12-20 11:36:07 -08001472 "S4: point_width=%i, line_width=%.1f,"
1473 "%s%s%s%s%s cullmode=%s, vfmt=%s%s%s%s%s%s "
Eric Anholt0c46f022011-12-20 14:23:15 -08001474 "%s%s%s%s%s\n",
Eric Anholt193fa132011-12-20 11:36:07 -08001475 (data[i] >>
1476 23) & 0x1ff,
1477 ((data[i] >>
1478 19) & 0xf) /
1479 2.0,
1480 data[i] & (0xf
1481 <<
1482 15)
1483 ?
1484 " flatshade="
1485 : "",
1486 data[i] & (1
1487 <<
1488 18)
1489 ? "Alpha," :
1490 "",
1491 data[i] & (1
1492 <<
1493 17)
1494 ? "Fog," : "",
1495 data[i] & (1
1496 <<
1497 16)
1498 ? "Specular,"
1499 : "",
1500 data[i] & (1
1501 <<
1502 15)
1503 ? "Color," :
1504 "", cullmode,
1505 data[i] & (1
1506 <<
1507 12)
1508 ?
1509 "PointWidth,"
1510 : "",
1511 data[i] & (1
1512 <<
1513 11)
1514 ? "SpecFog," :
1515 "",
1516 data[i] & (1
1517 <<
1518 10)
1519 ? "Color," :
1520 "",
1521 data[i] & (1
1522 <<
1523 9)
1524 ? "DepthOfs,"
1525 : "",
1526 vfmt_xyzw,
1527 data[i] & (1
1528 <<
1529 9)
1530 ? "FogParam,"
1531 : "",
1532 data[i] & (1
1533 <<
1534 5)
1535 ?
1536 "force default diffuse, "
1537 : "",
1538 data[i] & (1
1539 <<
1540 4)
1541 ?
1542 "force default specular, "
1543 : "",
1544 data[i] & (1
1545 <<
1546 3)
1547 ?
1548 "local depth ofs enable, "
1549 : "",
1550 data[i] & (1
1551 <<
1552 1)
1553 ?
1554 "point sprite enable, "
1555 : "",
1556 data[i] & (1
1557 <<
1558 0)
1559 ?
1560 "line AA enable, "
1561 : "");
1562 break;
1563 }
1564 case 5:
1565 {
Eric Anholtc1d29462011-12-20 15:29:03 -08001566 instr_out(ctx, i,
Eric Anholt193fa132011-12-20 11:36:07 -08001567 "S5:%s%s%s%s%s"
1568 "%s%s%s%s stencil_ref=0x%x, stencil_test=%s, "
1569 "stencil_fail=%s, stencil_pass_z_fail=%s, "
1570 "stencil_pass_z_pass=%s, %s%s%s%s\n",
1571 data[i] & (0xf
1572 <<
1573 28)
1574 ?
1575 " write_disable="
1576 : "",
1577 data[i] & (1
1578 <<
1579 31)
1580 ? "Alpha," :
1581 "",
1582 data[i] & (1
1583 <<
1584 30)
1585 ? "Red," : "",
1586 data[i] & (1
1587 <<
1588 29)
1589 ? "Green," :
1590 "",
1591 data[i] & (1
1592 <<
1593 28)
1594 ? "Blue," :
1595 "",
1596 data[i] & (1
1597 <<
1598 27)
1599 ?
1600 " force default point size,"
1601 : "",
1602 data[i] & (1
1603 <<
1604 26)
1605 ?
1606 " last pixel enable,"
1607 : "",
1608 data[i] & (1
1609 <<
1610 25)
1611 ?
1612 " global depth ofs enable,"
1613 : "",
1614 data[i] & (1
1615 <<
1616 24)
1617 ?
1618 " fog enable,"
1619 : "",
1620 (data[i] >>
1621 16) & 0xff,
1622 decode_compare_func
1623 (data[i] >>
1624 13),
1625 decode_stencil_op
1626 (data[i] >>
1627 10),
1628 decode_stencil_op
1629 (data[i] >>
1630 7),
1631 decode_stencil_op
1632 (data[i] >>
1633 4),
1634 data[i] & (1
1635 <<
1636 3)
1637 ?
1638 "stencil write enable, "
1639 : "",
1640 data[i] & (1
1641 <<
1642 2)
1643 ?
1644 "stencil test enable, "
1645 : "",
1646 data[i] & (1
1647 <<
1648 1)
1649 ?
1650 "color dither enable, "
1651 : "",
1652 data[i] & (1
1653 <<
1654 0)
1655 ?
1656 "logicop enable, "
1657 : "");
1658 }
1659 break;
1660 case 6:
Eric Anholtc1d29462011-12-20 15:29:03 -08001661 instr_out(ctx, i,
Eric Anholt193fa132011-12-20 11:36:07 -08001662 "S6: %salpha_test=%s, alpha_ref=0x%x, "
1663 "depth_test=%s, %ssrc_blnd_fct=%s, dst_blnd_fct=%s, "
1664 "%s%stristrip_provoking_vertex=%i\n",
1665 data[i] & (1 << 31) ?
1666 "alpha test enable, "
1667 : "",
1668 decode_compare_func
1669 (data[i] >> 28),
1670 data[i] & (0xff <<
1671 20),
1672 decode_compare_func
1673 (data[i] >> 16),
1674 data[i] & (1 << 15) ?
1675 "cbuf blend enable, "
1676 : "",
1677 decode_blend_fact(data
1678 [i]
1679 >>
1680 8),
1681 decode_blend_fact(data
1682 [i]
1683 >>
1684 4),
1685 data[i] & (1 << 3) ?
1686 "depth write enable, "
1687 : "",
1688 data[i] & (1 << 2) ?
1689 "cbuf write enable, "
1690 : "",
1691 data[i] & (0x3));
1692 break;
1693 case 7:
Eric Anholtc1d29462011-12-20 15:29:03 -08001694 instr_out(ctx, i,
Eric Anholt193fa132011-12-20 11:36:07 -08001695 "S7: depth offset constant: 0x%08x\n",
1696 data[i]);
1697 break;
1698 }
1699 } else {
Eric Anholtc1d29462011-12-20 15:29:03 -08001700 instr_out(ctx, i,
Eric Anholt193fa132011-12-20 11:36:07 -08001701 "S%d: 0x%08x\n", i, data[i]);
Eric Anholt8c4a2c82011-12-20 11:25:20 -08001702 }
Eric Anholt193fa132011-12-20 11:36:07 -08001703 i++;
1704 }
1705 }
1706 if (len != i) {
1707 fprintf(out,
1708 "Bad count in 3DSTATE_LOAD_STATE_IMMEDIATE_1\n");
Eric Anholt193fa132011-12-20 11:36:07 -08001709 }
1710 return len;
1711 case 0x03:
Eric Anholtc1d29462011-12-20 15:29:03 -08001712 instr_out(ctx, 0,
Eric Anholt193fa132011-12-20 11:36:07 -08001713 "3DSTATE_LOAD_STATE_IMMEDIATE_2\n");
1714 len = (data[0] & 0x0000000f) + 2;
1715 i = 1;
1716 for (word = 6; word <= 14; word++) {
1717 if (data[0] & (1 << word)) {
Eric Anholt193fa132011-12-20 11:36:07 -08001718 if (word == 6)
Eric Anholtc1d29462011-12-20 15:29:03 -08001719 instr_out(ctx, i++,
Eric Anholt193fa132011-12-20 11:36:07 -08001720 "TBCF\n");
1721 else if (word >= 7 && word <= 10) {
Eric Anholtc1d29462011-12-20 15:29:03 -08001722 instr_out(ctx, i++,
Eric Anholt193fa132011-12-20 11:36:07 -08001723 "TB%dC\n", word - 7);
Eric Anholtc1d29462011-12-20 15:29:03 -08001724 instr_out(ctx, i++,
Eric Anholt193fa132011-12-20 11:36:07 -08001725 "TB%dA\n", word - 7);
1726 } else if (word >= 11 && word <= 14) {
Eric Anholtc1d29462011-12-20 15:29:03 -08001727 instr_out(ctx, i,
Eric Anholt193fa132011-12-20 11:36:07 -08001728 "TM%dS0: offset=0x%08x, %s\n",
1729 word - 11,
1730 data[i] & 0xfffffffe,
1731 data[i] & 1 ? "use fence" :
1732 "");
1733 i++;
Eric Anholtc1d29462011-12-20 15:29:03 -08001734 instr_out(ctx, i,
Eric Anholt193fa132011-12-20 11:36:07 -08001735 "TM%dS1: height=%i, width=%i, %s\n",
1736 word - 11, data[i] >> 21,
1737 (data[i] >> 10) & 0x3ff,
1738 data[i] & 2 ? (data[i] & 1 ?
1739 "y-tiled" :
1740 "x-tiled") :
1741 "");
1742 i++;
Eric Anholtc1d29462011-12-20 15:29:03 -08001743 instr_out(ctx, i,
Eric Anholt193fa132011-12-20 11:36:07 -08001744 "TM%dS2: pitch=%i, \n",
1745 word - 11,
1746 ((data[i] >> 21) + 1) * 4);
1747 i++;
Eric Anholtc1d29462011-12-20 15:29:03 -08001748 instr_out(ctx, i++,
Eric Anholt193fa132011-12-20 11:36:07 -08001749 "TM%dS3\n", word - 11);
Eric Anholtc1d29462011-12-20 15:29:03 -08001750 instr_out(ctx, i++,
Eric Anholt193fa132011-12-20 11:36:07 -08001751 "TM%dS4: dflt color\n",
1752 word - 11);
1753 }
1754 }
1755 }
1756 if (len != i) {
1757 fprintf(out,
1758 "Bad count in 3DSTATE_LOAD_STATE_IMMEDIATE_2\n");
Eric Anholt193fa132011-12-20 11:36:07 -08001759 }
1760 return len;
1761 case 0x00:
Eric Anholtc1d29462011-12-20 15:29:03 -08001762 instr_out(ctx, 0, "3DSTATE_MAP_STATE\n");
Eric Anholt193fa132011-12-20 11:36:07 -08001763 len = (data[0] & 0x0000003f) + 2;
Eric Anholtc1d29462011-12-20 15:29:03 -08001764 instr_out(ctx, 1, "mask\n");
Eric Anholt193fa132011-12-20 11:36:07 -08001765
1766 i = 2;
1767 for (map = 0; map <= 15; map++) {
1768 if (data[1] & (1 << map)) {
1769 int width, height, pitch, dword;
1770 const char *tiling;
1771
Eric Anholt193fa132011-12-20 11:36:07 -08001772 dword = data[i];
Eric Anholtc1d29462011-12-20 15:29:03 -08001773 instr_out(ctx, i++,
Eric Anholt193fa132011-12-20 11:36:07 -08001774 "map %d MS2 %s%s%s\n", map,
1775 dword & (1 << 31) ?
1776 "untrusted surface, " : "",
1777 dword & (1 << 1) ?
1778 "vertical line stride enable, " : "",
1779 dword & (1 << 0) ?
1780 "vertical ofs enable, " : "");
1781
1782 dword = data[i];
1783 width = ((dword >> 10) & ((1 << 11) - 1)) + 1;
1784 height = ((dword >> 21) & ((1 << 11) - 1)) + 1;
1785
1786 tiling = "none";
1787 if (dword & (1 << 2))
1788 tiling = "fenced";
1789 else if (dword & (1 << 1))
1790 tiling = dword & (1 << 0) ? "Y" : "X";
1791 type = " BAD";
1792 format = "BAD";
1793 switch ((dword >> 7) & 0x7) {
1794 case 1:
1795 type = "8b";
1796 switch ((dword >> 3) & 0xf) {
1797 case 0:
1798 format = "I";
1799 break;
1800 case 1:
1801 format = "L";
1802 break;
1803 case 4:
1804 format = "A";
1805 break;
1806 case 5:
1807 format = " mono";
1808 break;
Eric Anholt8c4a2c82011-12-20 11:25:20 -08001809 }
Eric Anholt193fa132011-12-20 11:36:07 -08001810 break;
1811 case 2:
1812 type = "16b";
1813 switch ((dword >> 3) & 0xf) {
1814 case 0:
1815 format = " rgb565";
1816 break;
1817 case 1:
1818 format = " argb1555";
1819 break;
1820 case 2:
1821 format = " argb4444";
1822 break;
1823 case 5:
1824 format = " ay88";
1825 break;
1826 case 6:
1827 format = " bump655";
1828 break;
1829 case 7:
1830 format = "I";
1831 break;
1832 case 8:
1833 format = "L";
1834 break;
1835 case 9:
1836 format = "A";
1837 break;
Eric Anholt8c4a2c82011-12-20 11:25:20 -08001838 }
Eric Anholt193fa132011-12-20 11:36:07 -08001839 break;
1840 case 3:
1841 type = "32b";
1842 switch ((dword >> 3) & 0xf) {
1843 case 0:
1844 format = " argb8888";
1845 break;
1846 case 1:
1847 format = " abgr8888";
1848 break;
1849 case 2:
1850 format = " xrgb8888";
1851 break;
1852 case 3:
1853 format = " xbgr8888";
1854 break;
1855 case 4:
1856 format = " qwvu8888";
1857 break;
1858 case 5:
1859 format = " axvu8888";
1860 break;
1861 case 6:
1862 format = " lxvu8888";
1863 break;
1864 case 7:
1865 format = " xlvu8888";
1866 break;
1867 case 8:
1868 format = " argb2101010";
1869 break;
1870 case 9:
1871 format = " abgr2101010";
1872 break;
1873 case 10:
1874 format = " awvu2101010";
1875 break;
1876 case 11:
1877 format = " gr1616";
1878 break;
1879 case 12:
1880 format = " vu1616";
1881 break;
1882 case 13:
1883 format = " xI824";
1884 break;
1885 case 14:
1886 format = " xA824";
1887 break;
1888 case 15:
1889 format = " xL824";
1890 break;
1891 }
1892 break;
1893 case 5:
1894 type = "422";
1895 switch ((dword >> 3) & 0xf) {
1896 case 0:
1897 format = " yuv_swapy";
1898 break;
1899 case 1:
1900 format = " yuv";
1901 break;
1902 case 2:
1903 format = " yuv_swapuv";
1904 break;
1905 case 3:
1906 format = " yuv_swapuvy";
1907 break;
1908 }
1909 break;
1910 case 6:
1911 type = "compressed";
1912 switch ((dword >> 3) & 0x7) {
1913 case 0:
1914 format = " dxt1";
1915 break;
1916 case 1:
1917 format = " dxt2_3";
1918 break;
1919 case 2:
1920 format = " dxt4_5";
1921 break;
1922 case 3:
1923 format = " fxt1";
1924 break;
1925 case 4:
1926 format = " dxt1_rb";
1927 break;
1928 }
1929 break;
1930 case 7:
1931 type = "4b indexed";
1932 switch ((dword >> 3) & 0xf) {
1933 case 7:
1934 format = " argb8888";
1935 break;
1936 }
Eric Anholt8c4a2c82011-12-20 11:25:20 -08001937 break;
1938 }
Eric Anholt193fa132011-12-20 11:36:07 -08001939 dword = data[i];
Eric Anholtc1d29462011-12-20 15:29:03 -08001940 instr_out(ctx, i++,
Eric Anholt193fa132011-12-20 11:36:07 -08001941 "map %d MS3 [width=%d, height=%d, format=%s%s, tiling=%s%s]\n",
1942 map, width, height, type, format,
1943 tiling,
1944 dword & (1 << 9) ? " palette select" :
1945 "");
1946
1947 dword = data[i];
1948 pitch =
1949 4 * (((dword >> 21) & ((1 << 11) - 1)) + 1);
Eric Anholtc1d29462011-12-20 15:29:03 -08001950 instr_out(ctx, i++,
Eric Anholt193fa132011-12-20 11:36:07 -08001951 "map %d MS4 [pitch=%d, max_lod=%i, vol_depth=%i, cube_face_ena=%x, %s]\n",
1952 map, pitch, (dword >> 9) & 0x3f,
1953 dword & 0xff, (dword >> 15) & 0x3f,
1954 dword & (1 << 8) ? "miplayout legacy"
1955 : "miplayout right");
1956 }
1957 }
1958 if (len != i) {
1959 fprintf(out, "Bad count in 3DSTATE_MAP_STATE\n");
Eric Anholt193fa132011-12-20 11:36:07 -08001960 return len;
1961 }
1962 return len;
1963 case 0x06:
Eric Anholtc1d29462011-12-20 15:29:03 -08001964 instr_out(ctx, 0,
Eric Anholt193fa132011-12-20 11:36:07 -08001965 "3DSTATE_PIXEL_SHADER_CONSTANTS\n");
1966 len = (data[0] & 0x000000ff) + 2;
1967
1968 i = 2;
1969 for (c = 0; c <= 31; c++) {
1970 if (data[1] & (1 << c)) {
Eric Anholtc1d29462011-12-20 15:29:03 -08001971 instr_out(ctx, i, "C%d.X = %f\n", c,
Eric Anholt193fa132011-12-20 11:36:07 -08001972 int_as_float(data[i]));
1973 i++;
Eric Anholtc1d29462011-12-20 15:29:03 -08001974 instr_out(ctx, i, "C%d.Y = %f\n",
Eric Anholt193fa132011-12-20 11:36:07 -08001975 c, int_as_float(data[i]));
1976 i++;
Eric Anholtc1d29462011-12-20 15:29:03 -08001977 instr_out(ctx, i, "C%d.Z = %f\n",
Eric Anholt193fa132011-12-20 11:36:07 -08001978 c, int_as_float(data[i]));
1979 i++;
Eric Anholtc1d29462011-12-20 15:29:03 -08001980 instr_out(ctx, i, "C%d.W = %f\n",
Eric Anholt193fa132011-12-20 11:36:07 -08001981 c, int_as_float(data[i]));
1982 i++;
1983 }
1984 }
1985 if (len != i) {
1986 fprintf(out,
1987 "Bad count in 3DSTATE_PIXEL_SHADER_CONSTANTS\n");
Eric Anholt193fa132011-12-20 11:36:07 -08001988 }
1989 return len;
1990 case 0x05:
Eric Anholtc1d29462011-12-20 15:29:03 -08001991 instr_out(ctx, 0, "3DSTATE_PIXEL_SHADER_PROGRAM\n");
Eric Anholt193fa132011-12-20 11:36:07 -08001992 len = (data[0] & 0x000000ff) + 2;
1993 if ((len - 1) % 3 != 0 || len > 370) {
1994 fprintf(out,
1995 "Bad count in 3DSTATE_PIXEL_SHADER_PROGRAM\n");
Eric Anholt193fa132011-12-20 11:36:07 -08001996 }
1997 i = 1;
1998 for (instr = 0; instr < (len - 1) / 3; instr++) {
1999 char instr_prefix[10];
2000
Eric Anholt193fa132011-12-20 11:36:07 -08002001 sprintf(instr_prefix, "PS%03d", instr);
Eric Anholtc1d29462011-12-20 15:29:03 -08002002 i915_decode_instruction(ctx, i,
Eric Anholt193fa132011-12-20 11:36:07 -08002003 instr_prefix);
2004 i += 3;
2005 }
2006 return len;
2007 case 0x01:
2008 if (IS_GEN2(devid))
2009 break;
Eric Anholtc1d29462011-12-20 15:29:03 -08002010 instr_out(ctx, 0, "3DSTATE_SAMPLER_STATE\n");
2011 instr_out(ctx, 1, "mask\n");
Eric Anholt193fa132011-12-20 11:36:07 -08002012 len = (data[0] & 0x0000003f) + 2;
2013 i = 2;
2014 for (sampler = 0; sampler <= 15; sampler++) {
2015 if (data[1] & (1 << sampler)) {
2016 uint32_t dword;
Eric Anholt1db55a82011-12-20 12:00:28 -08002017 const char *mip_filter = "";
Eric Anholt028715e2012-01-04 12:31:40 -08002018
Eric Anholt193fa132011-12-20 11:36:07 -08002019 dword = data[i];
2020 switch ((dword >> 20) & 0x3) {
2021 case 0:
2022 mip_filter = "none";
2023 break;
2024 case 1:
2025 mip_filter = "nearest";
2026 break;
2027 case 3:
2028 mip_filter = "linear";
2029 break;
Eric Anholt8c4a2c82011-12-20 11:25:20 -08002030 }
Eric Anholtc1d29462011-12-20 15:29:03 -08002031 instr_out(ctx, i++,
Eric Anholt193fa132011-12-20 11:36:07 -08002032 "sampler %d SS2:%s%s%s "
2033 "base_mip_level=%i, mip_filter=%s, mag_filter=%s, min_filter=%s "
2034 "lod_bias=%.2f,%s max_aniso=%i, shadow_func=%s\n",
2035 sampler,
2036 dword & (1 << 31) ? " reverse gamma,"
2037 : "",
2038 dword & (1 << 30) ? " packed2planar,"
2039 : "",
2040 dword & (1 << 29) ?
2041 " colorspace conversion," : "",
2042 (dword >> 22) & 0x1f, mip_filter,
2043 decode_sample_filter(dword >> 17),
2044 decode_sample_filter(dword >> 14),
2045 ((dword >> 5) & 0x1ff) / (0x10 * 1.0),
2046 dword & (1 << 4) ? " shadow," : "",
2047 dword & (1 << 3) ? 4 : 2,
2048 decode_compare_func(dword));
2049 dword = data[i];
Eric Anholtc1d29462011-12-20 15:29:03 -08002050 instr_out(ctx, i++,
Eric Anholt193fa132011-12-20 11:36:07 -08002051 "sampler %d SS3: min_lod=%.2f,%s "
2052 "tcmode_x=%s, tcmode_y=%s, tcmode_z=%s,%s texmap_idx=%i,%s\n",
2053 sampler,
2054 ((dword >> 24) & 0xff) / (0x10 * 1.0),
2055 dword & (1 << 17) ?
2056 " kill pixel enable," : "",
2057 decode_tex_coord_mode(dword >> 12),
2058 decode_tex_coord_mode(dword >> 9),
2059 decode_tex_coord_mode(dword >> 6),
2060 dword & (1 << 5) ?
2061 " normalized coords," : "",
2062 (dword >> 1) & 0xf,
2063 dword & (1 << 0) ? " deinterlacer," :
2064 "");
2065 dword = data[i];
Eric Anholtc1d29462011-12-20 15:29:03 -08002066 instr_out(ctx, i++,
Eric Anholt193fa132011-12-20 11:36:07 -08002067 "sampler %d SS4: border color\n",
Eric Anholt0c46f022011-12-20 14:23:15 -08002068 sampler);
Eric Anholt193fa132011-12-20 11:36:07 -08002069 }
2070 }
2071 if (len != i) {
2072 fprintf(out, "Bad count in 3DSTATE_SAMPLER_STATE\n");
Eric Anholt193fa132011-12-20 11:36:07 -08002073 }
2074 return len;
2075 case 0x85:
2076 len = (data[0] & 0x0000000f) + 2;
2077
2078 if (len != 2)
2079 fprintf(out,
2080 "Bad count in 3DSTATE_DEST_BUFFER_VARIABLES\n");
Eric Anholt193fa132011-12-20 11:36:07 -08002081
Eric Anholtc1d29462011-12-20 15:29:03 -08002082 instr_out(ctx, 0,
Eric Anholt193fa132011-12-20 11:36:07 -08002083 "3DSTATE_DEST_BUFFER_VARIABLES\n");
2084
2085 switch ((data[1] >> 8) & 0xf) {
2086 case 0x0:
2087 format = "g8";
2088 break;
2089 case 0x1:
2090 format = "x1r5g5b5";
2091 break;
2092 case 0x2:
2093 format = "r5g6b5";
2094 break;
2095 case 0x3:
2096 format = "a8r8g8b8";
2097 break;
2098 case 0x4:
2099 format = "ycrcb_swapy";
2100 break;
2101 case 0x5:
2102 format = "ycrcb_normal";
2103 break;
2104 case 0x6:
2105 format = "ycrcb_swapuv";
2106 break;
2107 case 0x7:
2108 format = "ycrcb_swapuvy";
2109 break;
2110 case 0x8:
2111 format = "a4r4g4b4";
2112 break;
2113 case 0x9:
2114 format = "a1r5g5b5";
2115 break;
2116 case 0xa:
2117 format = "a2r10g10b10";
2118 break;
2119 default:
2120 format = "BAD";
2121 break;
2122 }
2123 switch ((data[1] >> 2) & 0x3) {
2124 case 0x0:
2125 zformat = "u16";
2126 break;
2127 case 0x1:
2128 zformat = "f16";
2129 break;
2130 case 0x2:
2131 zformat = "u24x8";
2132 break;
2133 default:
2134 zformat = "BAD";
2135 break;
2136 }
Eric Anholtc1d29462011-12-20 15:29:03 -08002137 instr_out(ctx, 1,
Eric Anholt193fa132011-12-20 11:36:07 -08002138 "%s format, %s depth format, early Z %sabled\n",
2139 format, zformat,
2140 (data[1] & (1 << 31)) ? "en" : "dis");
2141 return len;
2142
2143 case 0x8e:
2144 {
2145 const char *name, *tiling;
2146
2147 len = (data[0] & 0x0000000f) + 2;
2148 if (len != 3)
2149 fprintf(out,
2150 "Bad count in 3DSTATE_BUFFER_INFO\n");
Eric Anholt193fa132011-12-20 11:36:07 -08002151
2152 switch ((data[1] >> 24) & 0x7) {
2153 case 0x3:
2154 name = "color";
Eric Anholt8c4a2c82011-12-20 11:25:20 -08002155 break;
Eric Anholt193fa132011-12-20 11:36:07 -08002156 case 0x7:
2157 name = "depth";
Eric Anholt8c4a2c82011-12-20 11:25:20 -08002158 break;
Eric Anholt193fa132011-12-20 11:36:07 -08002159 default:
2160 name = "unknown";
Eric Anholt8c4a2c82011-12-20 11:25:20 -08002161 break;
2162 }
Eric Anholt193fa132011-12-20 11:36:07 -08002163
2164 tiling = "none";
2165 if (data[1] & (1 << 23))
2166 tiling = "fenced";
2167 else if (data[1] & (1 << 22))
2168 tiling = data[1] & (1 << 21) ? "Y" : "X";
2169
Eric Anholtc1d29462011-12-20 15:29:03 -08002170 instr_out(ctx, 0, "3DSTATE_BUFFER_INFO\n");
2171 instr_out(ctx, 1,
Eric Anholt193fa132011-12-20 11:36:07 -08002172 "%s, tiling = %s, pitch=%d\n", name, tiling,
2173 data[1] & 0xffff);
2174
Eric Anholtc1d29462011-12-20 15:29:03 -08002175 instr_out(ctx, 2, "address\n");
Eric Anholt193fa132011-12-20 11:36:07 -08002176 return len;
Eric Anholt8c4a2c82011-12-20 11:25:20 -08002177 }
Eric Anholt193fa132011-12-20 11:36:07 -08002178 case 0x81:
2179 len = (data[0] & 0x0000000f) + 2;
Eric Anholt8c4a2c82011-12-20 11:25:20 -08002180
Eric Anholt193fa132011-12-20 11:36:07 -08002181 if (len != 3)
2182 fprintf(out,
2183 "Bad count in 3DSTATE_SCISSOR_RECTANGLE\n");
Eric Anholt193fa132011-12-20 11:36:07 -08002184
Eric Anholtc1d29462011-12-20 15:29:03 -08002185 instr_out(ctx, 0, "3DSTATE_SCISSOR_RECTANGLE\n");
2186 instr_out(ctx, 1, "(%d,%d)\n",
Eric Anholt193fa132011-12-20 11:36:07 -08002187 data[1] & 0xffff, data[1] >> 16);
Eric Anholtc1d29462011-12-20 15:29:03 -08002188 instr_out(ctx, 2, "(%d,%d)\n",
Eric Anholt193fa132011-12-20 11:36:07 -08002189 data[2] & 0xffff, data[2] >> 16);
2190
2191 return len;
2192 case 0x80:
2193 len = (data[0] & 0x0000000f) + 2;
2194
2195 if (len != 5)
2196 fprintf(out,
2197 "Bad count in 3DSTATE_DRAWING_RECTANGLE\n");
Eric Anholt193fa132011-12-20 11:36:07 -08002198
Eric Anholtc1d29462011-12-20 15:29:03 -08002199 instr_out(ctx, 0, "3DSTATE_DRAWING_RECTANGLE\n");
2200 instr_out(ctx, 1, "%s\n",
Eric Anholt193fa132011-12-20 11:36:07 -08002201 data[1] & (1 << 30) ? "depth ofs disabled " : "");
Eric Anholtc1d29462011-12-20 15:29:03 -08002202 instr_out(ctx, 2, "(%d,%d)\n",
Eric Anholt193fa132011-12-20 11:36:07 -08002203 data[2] & 0xffff, data[2] >> 16);
Eric Anholtc1d29462011-12-20 15:29:03 -08002204 instr_out(ctx, 3, "(%d,%d)\n",
Eric Anholt193fa132011-12-20 11:36:07 -08002205 data[3] & 0xffff, data[3] >> 16);
Eric Anholtc1d29462011-12-20 15:29:03 -08002206 instr_out(ctx, 4, "(%d,%d)\n",
Eric Anholt193fa132011-12-20 11:36:07 -08002207 data[4] & 0xffff, data[4] >> 16);
2208
2209 return len;
2210 case 0x9c:
2211 len = (data[0] & 0x0000000f) + 2;
2212
2213 if (len != 7)
2214 fprintf(out, "Bad count in 3DSTATE_CLEAR_PARAMETERS\n");
Eric Anholt193fa132011-12-20 11:36:07 -08002215
Eric Anholtc1d29462011-12-20 15:29:03 -08002216 instr_out(ctx, 0, "3DSTATE_CLEAR_PARAMETERS\n");
2217 instr_out(ctx, 1, "prim_type=%s, clear=%s%s%s\n",
Eric Anholt193fa132011-12-20 11:36:07 -08002218 data[1] & (1 << 16) ? "CLEAR_RECT" : "ZONE_INIT",
2219 data[1] & (1 << 2) ? "color," : "",
2220 data[1] & (1 << 1) ? "depth," : "",
2221 data[1] & (1 << 0) ? "stencil," : "");
Eric Anholtc1d29462011-12-20 15:29:03 -08002222 instr_out(ctx, 2, "clear color\n");
2223 instr_out(ctx, 3, "clear depth/stencil\n");
2224 instr_out(ctx, 4, "color value (rgba8888)\n");
2225 instr_out(ctx, 5, "depth value %f\n",
Eric Anholt193fa132011-12-20 11:36:07 -08002226 int_as_float(data[5]));
Eric Anholtc1d29462011-12-20 15:29:03 -08002227 instr_out(ctx, 6, "clear stencil\n");
Eric Anholt193fa132011-12-20 11:36:07 -08002228 return len;
2229 }
2230
2231 for (idx = 0; idx < ARRAY_SIZE(opcodes_3d_1d); idx++) {
2232 opcode_3d_1d = &opcodes_3d_1d[idx];
2233 if (opcode_3d_1d->i830_only && !IS_GEN2(devid))
2234 continue;
2235
2236 if (((data[0] & 0x00ff0000) >> 16) == opcode_3d_1d->opcode) {
2237 len = 1;
2238
Eric Anholtc1d29462011-12-20 15:29:03 -08002239 instr_out(ctx, 0, "%s\n",
Eric Anholt193fa132011-12-20 11:36:07 -08002240 opcode_3d_1d->name);
2241 if (opcode_3d_1d->max_len > 1) {
2242 len = (data[0] & 0x0000ffff) + 2;
2243 if (len < opcode_3d_1d->min_len ||
2244 len > opcode_3d_1d->max_len) {
2245 fprintf(out, "Bad count in %s\n",
2246 opcode_3d_1d->name);
Eric Anholt193fa132011-12-20 11:36:07 -08002247 }
2248 }
2249
2250 for (i = 1; i < len; i++) {
Eric Anholtc1d29462011-12-20 15:29:03 -08002251 instr_out(ctx, i, "dword %d\n", i);
Eric Anholt193fa132011-12-20 11:36:07 -08002252 }
2253
2254 return len;
Eric Anholt8c4a2c82011-12-20 11:25:20 -08002255 }
Eric Anholt8c4a2c82011-12-20 11:25:20 -08002256 }
Eric Anholt8c4a2c82011-12-20 11:25:20 -08002257
Eric Anholtc1d29462011-12-20 15:29:03 -08002258 instr_out(ctx, 0, "3D UNKNOWN: 3d_1d opcode = 0x%x\n",
Eric Anholt193fa132011-12-20 11:36:07 -08002259 opcode);
Eric Anholt193fa132011-12-20 11:36:07 -08002260 return 1;
Eric Anholt8c4a2c82011-12-20 11:25:20 -08002261}
2262
2263static int
Eric Anholtde49fd42011-12-20 15:15:21 -08002264decode_3d_primitive(struct drm_intel_decode *ctx)
Eric Anholt8c4a2c82011-12-20 11:25:20 -08002265{
Eric Anholtde49fd42011-12-20 15:15:21 -08002266 uint32_t *data = ctx->data;
Eric Anholtde49fd42011-12-20 15:15:21 -08002267 uint32_t count = ctx->count;
Eric Anholt193fa132011-12-20 11:36:07 -08002268 char immediate = (data[0] & (1 << 23)) == 0;
2269 unsigned int len, i, j, ret;
Eric Anholt1db55a82011-12-20 12:00:28 -08002270 const char *primtype;
Eric Anholt193fa132011-12-20 11:36:07 -08002271 int original_s2 = saved_s2;
2272 int original_s4 = saved_s4;
Eric Anholt8c4a2c82011-12-20 11:25:20 -08002273
Eric Anholt193fa132011-12-20 11:36:07 -08002274 switch ((data[0] >> 18) & 0xf) {
2275 case 0x0:
2276 primtype = "TRILIST";
2277 break;
2278 case 0x1:
2279 primtype = "TRISTRIP";
2280 break;
2281 case 0x2:
2282 primtype = "TRISTRIP_REVERSE";
2283 break;
2284 case 0x3:
2285 primtype = "TRIFAN";
2286 break;
2287 case 0x4:
2288 primtype = "POLYGON";
2289 break;
2290 case 0x5:
2291 primtype = "LINELIST";
2292 break;
2293 case 0x6:
2294 primtype = "LINESTRIP";
2295 break;
2296 case 0x7:
2297 primtype = "RECTLIST";
2298 break;
2299 case 0x8:
2300 primtype = "POINTLIST";
2301 break;
2302 case 0x9:
2303 primtype = "DIB";
2304 break;
2305 case 0xa:
2306 primtype = "CLEAR_RECT";
2307 saved_s4 = 3 << 6;
2308 saved_s2 = ~0;
2309 break;
2310 default:
2311 primtype = "unknown";
2312 break;
2313 }
Eric Anholt8c4a2c82011-12-20 11:25:20 -08002314
Eric Anholt193fa132011-12-20 11:36:07 -08002315 /* XXX: 3DPRIM_DIB not supported */
2316 if (immediate) {
2317 len = (data[0] & 0x0003ffff) + 2;
Eric Anholtc1d29462011-12-20 15:29:03 -08002318 instr_out(ctx, 0, "3DPRIMITIVE inline %s\n",
Eric Anholt193fa132011-12-20 11:36:07 -08002319 primtype);
2320 if (count < len)
2321 BUFFER_FAIL(count, len, "3DPRIMITIVE inline");
2322 if (!saved_s2_set || !saved_s4_set) {
2323 fprintf(out, "unknown vertex format\n");
2324 for (i = 1; i < len; i++) {
Eric Anholtc1d29462011-12-20 15:29:03 -08002325 instr_out(ctx, i,
Eric Anholt193fa132011-12-20 11:36:07 -08002326 " vertex data (%f float)\n",
2327 int_as_float(data[i]));
2328 }
2329 } else {
2330 unsigned int vertex = 0;
2331 for (i = 1; i < len;) {
2332 unsigned int tc;
Eric Anholt8c4a2c82011-12-20 11:25:20 -08002333
2334#define VERTEX_OUT(fmt, ...) do { \
2335 if (i < len) \
Eric Anholtc1d29462011-12-20 15:29:03 -08002336 instr_out(ctx, i, " V%d."fmt"\n", vertex, __VA_ARGS__); \
Eric Anholt8c4a2c82011-12-20 11:25:20 -08002337 else \
2338 fprintf(out, " missing data in V%d\n", vertex); \
2339 i++; \
2340} while (0)
2341
Eric Anholt193fa132011-12-20 11:36:07 -08002342 VERTEX_OUT("X = %f", int_as_float(data[i]));
2343 VERTEX_OUT("Y = %f", int_as_float(data[i]));
2344 switch (saved_s4 >> 6 & 0x7) {
2345 case 0x1:
2346 VERTEX_OUT("Z = %f",
2347 int_as_float(data[i]));
2348 break;
2349 case 0x2:
2350 VERTEX_OUT("Z = %f",
2351 int_as_float(data[i]));
2352 VERTEX_OUT("W = %f",
2353 int_as_float(data[i]));
2354 break;
2355 case 0x3:
2356 break;
2357 case 0x4:
2358 VERTEX_OUT("W = %f",
2359 int_as_float(data[i]));
2360 break;
2361 default:
2362 fprintf(out, "bad S4 position mask\n");
2363 }
2364
2365 if (saved_s4 & (1 << 10)) {
2366 VERTEX_OUT
2367 ("color = (A=0x%02x, R=0x%02x, G=0x%02x, "
2368 "B=0x%02x)", data[i] >> 24,
2369 (data[i] >> 16) & 0xff,
2370 (data[i] >> 8) & 0xff,
2371 data[i] & 0xff);
2372 }
2373 if (saved_s4 & (1 << 11)) {
2374 VERTEX_OUT
2375 ("spec = (A=0x%02x, R=0x%02x, G=0x%02x, "
2376 "B=0x%02x)", data[i] >> 24,
2377 (data[i] >> 16) & 0xff,
2378 (data[i] >> 8) & 0xff,
2379 data[i] & 0xff);
2380 }
2381 if (saved_s4 & (1 << 12))
2382 VERTEX_OUT("width = 0x%08x)", data[i]);
2383
2384 for (tc = 0; tc <= 7; tc++) {
2385 switch ((saved_s2 >> (tc * 4)) & 0xf) {
2386 case 0x0:
2387 VERTEX_OUT("T%d.X = %f", tc,
2388 int_as_float(data
2389 [i]));
2390 VERTEX_OUT("T%d.Y = %f", tc,
2391 int_as_float(data
2392 [i]));
2393 break;
2394 case 0x1:
2395 VERTEX_OUT("T%d.X = %f", tc,
2396 int_as_float(data
2397 [i]));
2398 VERTEX_OUT("T%d.Y = %f", tc,
2399 int_as_float(data
2400 [i]));
2401 VERTEX_OUT("T%d.Z = %f", tc,
2402 int_as_float(data
2403 [i]));
2404 break;
2405 case 0x2:
2406 VERTEX_OUT("T%d.X = %f", tc,
2407 int_as_float(data
2408 [i]));
2409 VERTEX_OUT("T%d.Y = %f", tc,
2410 int_as_float(data
2411 [i]));
2412 VERTEX_OUT("T%d.Z = %f", tc,
2413 int_as_float(data
2414 [i]));
2415 VERTEX_OUT("T%d.W = %f", tc,
2416 int_as_float(data
2417 [i]));
2418 break;
2419 case 0x3:
2420 VERTEX_OUT("T%d.X = %f", tc,
2421 int_as_float(data
2422 [i]));
2423 break;
2424 case 0x4:
2425 VERTEX_OUT
2426 ("T%d.XY = 0x%08x half-float",
2427 tc, data[i]);
2428 break;
2429 case 0x5:
2430 VERTEX_OUT
2431 ("T%d.XY = 0x%08x half-float",
2432 tc, data[i]);
2433 VERTEX_OUT
2434 ("T%d.ZW = 0x%08x half-float",
2435 tc, data[i]);
2436 break;
2437 case 0xf:
2438 break;
2439 default:
2440 fprintf(out,
2441 "bad S2.T%d format\n",
2442 tc);
2443 }
2444 }
2445 vertex++;
2446 }
Eric Anholt8c4a2c82011-12-20 11:25:20 -08002447 }
2448
Eric Anholt193fa132011-12-20 11:36:07 -08002449 ret = len;
Eric Anholt8c4a2c82011-12-20 11:25:20 -08002450 } else {
Eric Anholt193fa132011-12-20 11:36:07 -08002451 /* indirect vertices */
2452 len = data[0] & 0x0000ffff; /* index count */
2453 if (data[0] & (1 << 17)) {
2454 /* random vertex access */
2455 if (count < (len + 1) / 2 + 1) {
2456 BUFFER_FAIL(count, (len + 1) / 2 + 1,
2457 "3DPRIMITIVE random indirect");
2458 }
Eric Anholtc1d29462011-12-20 15:29:03 -08002459 instr_out(ctx, 0,
Eric Anholt193fa132011-12-20 11:36:07 -08002460 "3DPRIMITIVE random indirect %s (%d)\n",
2461 primtype, len);
2462 if (len == 0) {
Eric Anholtbbdda922011-12-20 11:44:36 -08002463 /* vertex indices continue until 0xffff is
2464 * found
2465 */
Eric Anholt193fa132011-12-20 11:36:07 -08002466 for (i = 1; i < count; i++) {
2467 if ((data[i] & 0xffff) == 0xffff) {
Eric Anholtc1d29462011-12-20 15:29:03 -08002468 instr_out(ctx, i,
Eric Anholt193fa132011-12-20 11:36:07 -08002469 " indices: (terminator)\n");
2470 ret = i;
2471 goto out;
2472 } else if ((data[i] >> 16) == 0xffff) {
Eric Anholtc1d29462011-12-20 15:29:03 -08002473 instr_out(ctx, i,
Eric Anholt193fa132011-12-20 11:36:07 -08002474 " indices: 0x%04x, (terminator)\n",
2475 data[i] & 0xffff);
2476 ret = i;
2477 goto out;
2478 } else {
Eric Anholtc1d29462011-12-20 15:29:03 -08002479 instr_out(ctx, i,
Eric Anholt193fa132011-12-20 11:36:07 -08002480 " indices: 0x%04x, 0x%04x\n",
2481 data[i] & 0xffff,
2482 data[i] >> 16);
2483 }
2484 }
2485 fprintf(out,
2486 "3DPRIMITIVE: no terminator found in index buffer\n");
Eric Anholt193fa132011-12-20 11:36:07 -08002487 ret = count;
2488 goto out;
2489 } else {
2490 /* fixed size vertex index buffer */
2491 for (j = 1, i = 0; i < len; i += 2, j++) {
2492 if (i * 2 == len - 1) {
Eric Anholtc1d29462011-12-20 15:29:03 -08002493 instr_out(ctx, j,
Eric Anholt193fa132011-12-20 11:36:07 -08002494 " indices: 0x%04x\n",
2495 data[j] & 0xffff);
2496 } else {
Eric Anholtc1d29462011-12-20 15:29:03 -08002497 instr_out(ctx, j,
Eric Anholt193fa132011-12-20 11:36:07 -08002498 " indices: 0x%04x, 0x%04x\n",
2499 data[j] & 0xffff,
2500 data[j] >> 16);
2501 }
2502 }
2503 }
2504 ret = (len + 1) / 2 + 1;
2505 goto out;
2506 } else {
2507 /* sequential vertex access */
Eric Anholtc1d29462011-12-20 15:29:03 -08002508 instr_out(ctx, 0,
Eric Anholt193fa132011-12-20 11:36:07 -08002509 "3DPRIMITIVE sequential indirect %s, %d starting from "
2510 "%d\n", primtype, len, data[1] & 0xffff);
Eric Anholtc1d29462011-12-20 15:29:03 -08002511 instr_out(ctx, 1, " start\n");
Eric Anholt193fa132011-12-20 11:36:07 -08002512 ret = 2;
2513 goto out;
2514 }
Eric Anholt8c4a2c82011-12-20 11:25:20 -08002515 }
Eric Anholt8c4a2c82011-12-20 11:25:20 -08002516
2517out:
Eric Anholt193fa132011-12-20 11:36:07 -08002518 saved_s2 = original_s2;
2519 saved_s4 = original_s4;
2520 return ret;
Eric Anholt8c4a2c82011-12-20 11:25:20 -08002521}
2522
2523static int
Eric Anholtde49fd42011-12-20 15:15:21 -08002524decode_3d(struct drm_intel_decode *ctx)
Eric Anholt8c4a2c82011-12-20 11:25:20 -08002525{
Eric Anholt8c4a2c82011-12-20 11:25:20 -08002526 uint32_t opcode;
Eric Anholt193fa132011-12-20 11:36:07 -08002527 unsigned int idx;
Eric Anholtde49fd42011-12-20 15:15:21 -08002528 uint32_t *data = ctx->data;
Eric Anholt8c4a2c82011-12-20 11:25:20 -08002529
Eric Anholt193fa132011-12-20 11:36:07 -08002530 struct {
2531 uint32_t opcode;
Eric Anholt07768ba2011-12-20 13:46:23 -08002532 unsigned int min_len;
2533 unsigned int max_len;
Eric Anholt1db55a82011-12-20 12:00:28 -08002534 const char *name;
Eric Anholt193fa132011-12-20 11:36:07 -08002535 } opcodes_3d[] = {
Eric Anholtbbdda922011-12-20 11:44:36 -08002536 { 0x06, 1, 1, "3DSTATE_ANTI_ALIASING" },
2537 { 0x08, 1, 1, "3DSTATE_BACKFACE_STENCIL_OPS" },
2538 { 0x09, 1, 1, "3DSTATE_BACKFACE_STENCIL_MASKS" },
2539 { 0x16, 1, 1, "3DSTATE_COORD_SET_BINDINGS" },
2540 { 0x15, 1, 1, "3DSTATE_FOG_COLOR" },
2541 { 0x0b, 1, 1, "3DSTATE_INDEPENDENT_ALPHA_BLEND" },
2542 { 0x0d, 1, 1, "3DSTATE_MODES_4" },
2543 { 0x0c, 1, 1, "3DSTATE_MODES_5" },
2544 { 0x07, 1, 1, "3DSTATE_RASTERIZATION_RULES"},
2545 }, *opcode_3d;
Eric Anholt193fa132011-12-20 11:36:07 -08002546
2547 opcode = (data[0] & 0x1f000000) >> 24;
2548
2549 switch (opcode) {
2550 case 0x1f:
Eric Anholtde49fd42011-12-20 15:15:21 -08002551 return decode_3d_primitive(ctx);
Eric Anholt193fa132011-12-20 11:36:07 -08002552 case 0x1d:
Eric Anholtde49fd42011-12-20 15:15:21 -08002553 return decode_3d_1d(ctx);
Eric Anholt193fa132011-12-20 11:36:07 -08002554 case 0x1c:
Eric Anholtde49fd42011-12-20 15:15:21 -08002555 return decode_3d_1c(ctx);
Eric Anholt193fa132011-12-20 11:36:07 -08002556 }
2557
2558 for (idx = 0; idx < ARRAY_SIZE(opcodes_3d); idx++) {
2559 opcode_3d = &opcodes_3d[idx];
2560 if (opcode == opcode_3d->opcode) {
2561 unsigned int len = 1, i;
2562
Eric Anholtc1d29462011-12-20 15:29:03 -08002563 instr_out(ctx, 0, "%s\n", opcode_3d->name);
Eric Anholt193fa132011-12-20 11:36:07 -08002564 if (opcode_3d->max_len > 1) {
2565 len = (data[0] & 0xff) + 2;
2566 if (len < opcode_3d->min_len ||
2567 len > opcode_3d->max_len) {
2568 fprintf(out, "Bad count in %s\n",
2569 opcode_3d->name);
2570 }
2571 }
2572
2573 for (i = 1; i < len; i++) {
Eric Anholtc1d29462011-12-20 15:29:03 -08002574 instr_out(ctx, i, "dword %d\n", i);
Eric Anholt193fa132011-12-20 11:36:07 -08002575 }
2576 return len;
Eric Anholt8c4a2c82011-12-20 11:25:20 -08002577 }
Eric Anholt8c4a2c82011-12-20 11:25:20 -08002578 }
Eric Anholt8c4a2c82011-12-20 11:25:20 -08002579
Eric Anholtc1d29462011-12-20 15:29:03 -08002580 instr_out(ctx, 0, "3D UNKNOWN: 3d opcode = 0x%x\n", opcode);
Eric Anholt193fa132011-12-20 11:36:07 -08002581 return 1;
Eric Anholt8c4a2c82011-12-20 11:25:20 -08002582}
2583
Eric Anholt193fa132011-12-20 11:36:07 -08002584static const char *get_965_surfacetype(unsigned int surfacetype)
Eric Anholt8c4a2c82011-12-20 11:25:20 -08002585{
Eric Anholt193fa132011-12-20 11:36:07 -08002586 switch (surfacetype) {
2587 case 0:
2588 return "1D";
2589 case 1:
2590 return "2D";
2591 case 2:
2592 return "3D";
2593 case 3:
2594 return "CUBE";
2595 case 4:
2596 return "BUFFER";
2597 case 7:
2598 return "NULL";
2599 default:
2600 return "unknown";
Eric Anholt8c4a2c82011-12-20 11:25:20 -08002601 }
Eric Anholt8c4a2c82011-12-20 11:25:20 -08002602}
2603
Eric Anholt193fa132011-12-20 11:36:07 -08002604static const char *get_965_depthformat(unsigned int depthformat)
Eric Anholt8c4a2c82011-12-20 11:25:20 -08002605{
Eric Anholt193fa132011-12-20 11:36:07 -08002606 switch (depthformat) {
2607 case 0:
2608 return "s8_z24float";
2609 case 1:
2610 return "z32float";
2611 case 2:
2612 return "z24s8";
2613 case 5:
2614 return "z16";
2615 default:
2616 return "unknown";
2617 }
2618}
Eric Anholt8c4a2c82011-12-20 11:25:20 -08002619
Eric Anholt193fa132011-12-20 11:36:07 -08002620static const char *get_965_element_component(uint32_t data, int component)
2621{
2622 uint32_t component_control = (data >> (16 + (3 - component) * 4)) & 0x7;
2623
2624 switch (component_control) {
2625 case 0:
2626 return "nostore";
2627 case 1:
2628 switch (component) {
2629 case 0:
2630 return "X";
2631 case 1:
2632 return "Y";
2633 case 2:
2634 return "Z";
2635 case 3:
2636 return "W";
2637 default:
2638 return "fail";
2639 }
2640 case 2:
2641 return "0.0";
2642 case 3:
2643 return "1.0";
2644 case 4:
2645 return "0x1";
2646 case 5:
2647 return "VID";
2648 default:
2649 return "fail";
2650 }
2651}
2652
Eric Anholt9d18ad22012-03-02 10:27:55 -08002653static const char *get_965_prim_type(uint32_t primtype)
Eric Anholt193fa132011-12-20 11:36:07 -08002654{
Eric Anholt193fa132011-12-20 11:36:07 -08002655 switch (primtype) {
2656 case 0x01:
2657 return "point list";
2658 case 0x02:
2659 return "line list";
2660 case 0x03:
2661 return "line strip";
2662 case 0x04:
2663 return "tri list";
2664 case 0x05:
2665 return "tri strip";
2666 case 0x06:
2667 return "tri fan";
2668 case 0x07:
2669 return "quad list";
2670 case 0x08:
2671 return "quad strip";
2672 case 0x09:
2673 return "line list adj";
2674 case 0x0a:
2675 return "line strip adj";
2676 case 0x0b:
2677 return "tri list adj";
2678 case 0x0c:
2679 return "tri strip adj";
2680 case 0x0d:
2681 return "tri strip reverse";
2682 case 0x0e:
2683 return "polygon";
2684 case 0x0f:
2685 return "rect list";
2686 case 0x10:
2687 return "line loop";
2688 case 0x11:
2689 return "point list bf";
2690 case 0x12:
2691 return "line strip cont";
2692 case 0x13:
2693 return "line strip bf";
2694 case 0x14:
2695 return "line strip cont bf";
2696 case 0x15:
2697 return "tri fan no stipple";
2698 default:
2699 return "fail";
2700 }
Eric Anholt8c4a2c82011-12-20 11:25:20 -08002701}
2702
2703static int
Eric Anholtc1d29462011-12-20 15:29:03 -08002704i965_decode_urb_fence(struct drm_intel_decode *ctx, int len)
Eric Anholt8c4a2c82011-12-20 11:25:20 -08002705{
2706 uint32_t vs_fence, clip_fence, gs_fence, sf_fence, vfe_fence, cs_fence;
Eric Anholtc1d29462011-12-20 15:29:03 -08002707 uint32_t *data = ctx->data;
Eric Anholt8c4a2c82011-12-20 11:25:20 -08002708
2709 if (len != 3)
Eric Anholt193fa132011-12-20 11:36:07 -08002710 fprintf(out, "Bad count in URB_FENCE\n");
Eric Anholt8c4a2c82011-12-20 11:25:20 -08002711
2712 vs_fence = data[1] & 0x3ff;
2713 gs_fence = (data[1] >> 10) & 0x3ff;
2714 clip_fence = (data[1] >> 20) & 0x3ff;
2715 sf_fence = data[2] & 0x3ff;
2716 vfe_fence = (data[2] >> 10) & 0x3ff;
2717 cs_fence = (data[2] >> 20) & 0x7ff;
2718
Eric Anholtc1d29462011-12-20 15:29:03 -08002719 instr_out(ctx, 0, "URB_FENCE: %s%s%s%s%s%s\n",
Eric Anholt193fa132011-12-20 11:36:07 -08002720 (data[0] >> 13) & 1 ? "cs " : "",
2721 (data[0] >> 12) & 1 ? "vfe " : "",
2722 (data[0] >> 11) & 1 ? "sf " : "",
2723 (data[0] >> 10) & 1 ? "clip " : "",
2724 (data[0] >> 9) & 1 ? "gs " : "",
2725 (data[0] >> 8) & 1 ? "vs " : "");
Eric Anholtc1d29462011-12-20 15:29:03 -08002726 instr_out(ctx, 1,
Eric Anholt8c4a2c82011-12-20 11:25:20 -08002727 "vs fence: %d, clip_fence: %d, gs_fence: %d\n",
2728 vs_fence, clip_fence, gs_fence);
Eric Anholtc1d29462011-12-20 15:29:03 -08002729 instr_out(ctx, 2,
Eric Anholt8c4a2c82011-12-20 11:25:20 -08002730 "sf fence: %d, vfe_fence: %d, cs_fence: %d\n",
2731 sf_fence, vfe_fence, cs_fence);
2732 if (gs_fence < vs_fence)
Eric Anholt193fa132011-12-20 11:36:07 -08002733 fprintf(out, "gs fence < vs fence!\n");
Eric Anholt8c4a2c82011-12-20 11:25:20 -08002734 if (clip_fence < gs_fence)
Eric Anholt193fa132011-12-20 11:36:07 -08002735 fprintf(out, "clip fence < gs fence!\n");
Eric Anholt8c4a2c82011-12-20 11:25:20 -08002736 if (sf_fence < clip_fence)
Eric Anholt193fa132011-12-20 11:36:07 -08002737 fprintf(out, "sf fence < clip fence!\n");
Eric Anholt8c4a2c82011-12-20 11:25:20 -08002738 if (cs_fence < sf_fence)
Eric Anholt193fa132011-12-20 11:36:07 -08002739 fprintf(out, "cs fence < sf fence!\n");
Eric Anholt8c4a2c82011-12-20 11:25:20 -08002740
2741 return len;
2742}
2743
2744static void
Eric Anholtc1d29462011-12-20 15:29:03 -08002745state_base_out(struct drm_intel_decode *ctx, unsigned int index,
Eric Anholt1db55a82011-12-20 12:00:28 -08002746 const char *name)
Eric Anholt8c4a2c82011-12-20 11:25:20 -08002747{
Eric Anholtc1d29462011-12-20 15:29:03 -08002748 if (ctx->data[index] & 1) {
2749 instr_out(ctx, index,
Eric Anholt193fa132011-12-20 11:36:07 -08002750 "%s state base address 0x%08x\n", name,
Eric Anholtc1d29462011-12-20 15:29:03 -08002751 ctx->data[index] & ~1);
Eric Anholt193fa132011-12-20 11:36:07 -08002752 } else {
Eric Anholtc1d29462011-12-20 15:29:03 -08002753 instr_out(ctx, index, "%s state base not updated\n",
Eric Anholt193fa132011-12-20 11:36:07 -08002754 name);
2755 }
Eric Anholt8c4a2c82011-12-20 11:25:20 -08002756}
2757
2758static void
Eric Anholtc1d29462011-12-20 15:29:03 -08002759state_max_out(struct drm_intel_decode *ctx, unsigned int index,
Eric Anholt1db55a82011-12-20 12:00:28 -08002760 const char *name)
Eric Anholt8c4a2c82011-12-20 11:25:20 -08002761{
Eric Anholtc1d29462011-12-20 15:29:03 -08002762 if (ctx->data[index] & 1) {
2763 if (ctx->data[index] == 1) {
2764 instr_out(ctx, index,
Eric Anholt193fa132011-12-20 11:36:07 -08002765 "%s state upper bound disabled\n", name);
2766 } else {
Eric Anholtc1d29462011-12-20 15:29:03 -08002767 instr_out(ctx, index,
Eric Anholt193fa132011-12-20 11:36:07 -08002768 "%s state upper bound 0x%08x\n", name,
Eric Anholtc1d29462011-12-20 15:29:03 -08002769 ctx->data[index] & ~1);
Eric Anholt193fa132011-12-20 11:36:07 -08002770 }
Eric Anholt8c4a2c82011-12-20 11:25:20 -08002771 } else {
Eric Anholtc1d29462011-12-20 15:29:03 -08002772 instr_out(ctx, index,
Eric Anholt193fa132011-12-20 11:36:07 -08002773 "%s state upper bound not updated\n", name);
Eric Anholt8c4a2c82011-12-20 11:25:20 -08002774 }
Eric Anholt8c4a2c82011-12-20 11:25:20 -08002775}
2776
2777static int
Eric Anholt938df6b2012-01-04 12:23:42 -08002778gen7_3DSTATE_VIEWPORT_STATE_POINTERS_CC(struct drm_intel_decode *ctx)
2779{
2780 instr_out(ctx, 0, "3DSTATE_VIEWPORT_STATE_POINTERS_CC\n");
2781 instr_out(ctx, 1, "pointer to CC viewport\n");
2782
2783 return 2;
2784}
2785
2786static int
2787gen7_3DSTATE_VIEWPORT_STATE_POINTERS_SF_CLIP(struct drm_intel_decode *ctx)
2788{
2789 instr_out(ctx, 0, "3DSTATE_VIEWPORT_STATE_POINTERS_SF_CLIP\n");
2790 instr_out(ctx, 1, "pointer to SF_CLIP viewport\n");
2791
2792 return 2;
2793}
2794
2795static int
2796gen7_3DSTATE_BLEND_STATE_POINTERS(struct drm_intel_decode *ctx)
2797{
2798 instr_out(ctx, 0, "3DSTATE_BLEND_STATE_POINTERS\n");
2799 instr_out(ctx, 1, "pointer to BLEND_STATE at 0x%08x (%s)\n",
2800 ctx->data[1] & ~1,
2801 (ctx->data[1] & 1) ? "changed" : "unchanged");
2802
2803 return 2;
2804}
2805
2806static int
2807gen7_3DSTATE_DEPTH_STENCIL_STATE_POINTERS(struct drm_intel_decode *ctx)
2808{
2809 instr_out(ctx, 0, "3DSTATE_DEPTH_STENCIL_STATE_POINTERS\n");
2810 instr_out(ctx, 1,
2811 "pointer to DEPTH_STENCIL_STATE at 0x%08x (%s)\n",
2812 ctx->data[1] & ~1,
2813 (ctx->data[1] & 1) ? "changed" : "unchanged");
2814
2815 return 2;
2816}
2817
2818static int
Eric Anholtb395af02012-01-30 15:13:32 -08002819gen7_3DSTATE_HIER_DEPTH_BUFFER(struct drm_intel_decode *ctx)
2820{
2821 instr_out(ctx, 0, "3DSTATE_HIER_DEPTH_BUFFER\n");
2822 instr_out(ctx, 1, "pitch %db\n",
2823 (ctx->data[1] & 0x1ffff) + 1);
2824 instr_out(ctx, 2, "pointer to HiZ buffer\n");
2825
2826 return 3;
2827}
2828
2829static int
Eric Anholt938df6b2012-01-04 12:23:42 -08002830gen6_3DSTATE_CC_STATE_POINTERS(struct drm_intel_decode *ctx)
2831{
2832 instr_out(ctx, 0, "3DSTATE_CC_STATE_POINTERS\n");
2833 instr_out(ctx, 1, "blend change %d\n", ctx->data[1] & 1);
2834 instr_out(ctx, 2, "depth stencil change %d\n",
2835 ctx->data[2] & 1);
2836 instr_out(ctx, 3, "cc change %d\n", ctx->data[3] & 1);
2837
2838 return 4;
2839}
2840
2841static int
2842gen7_3DSTATE_CC_STATE_POINTERS(struct drm_intel_decode *ctx)
2843{
2844 instr_out(ctx, 0, "3DSTATE_CC_STATE_POINTERS\n");
2845 instr_out(ctx, 1, "pointer to COLOR_CALC_STATE at 0x%08x "
2846 "(%s)\n",
2847 ctx->data[1] & ~1,
2848 (ctx->data[1] & 1) ? "changed" : "unchanged");
2849
2850 return 2;
2851}
2852
2853static int
Eric Anholt6a0b25e2012-01-04 12:12:41 -08002854gen7_3DSTATE_URB_unit(struct drm_intel_decode *ctx, const char *unit)
2855{
2856 int start_kb = ((ctx->data[1] >> 25) & 0x3f) * 8;
2857 /* the field is # of 512-bit rows - 1, we print bytes */
2858 int entry_size = (((ctx->data[1] >> 16) & 0x1ff) + 1);
2859 int nr_entries = ctx->data[1] & 0xffff;
2860
2861 instr_out(ctx, 0, "3DSTATE_URB_%s\n", unit);
2862 instr_out(ctx, 1,
2863 "%dKB start, size=%d 64B rows, nr_entries=%d, total size %dB\n",
2864 start_kb, entry_size, nr_entries, nr_entries * 64 * entry_size);
2865
2866 return 2;
2867}
2868
2869static int
2870gen7_3DSTATE_URB_VS(struct drm_intel_decode *ctx)
2871{
2872 return gen7_3DSTATE_URB_unit(ctx, "VS");
2873}
2874
2875static int
2876gen7_3DSTATE_URB_HS(struct drm_intel_decode *ctx)
2877{
2878 return gen7_3DSTATE_URB_unit(ctx, "HS");
2879}
2880
2881static int
2882gen7_3DSTATE_URB_DS(struct drm_intel_decode *ctx)
2883{
2884 return gen7_3DSTATE_URB_unit(ctx, "DS");
2885}
2886
2887static int
2888gen7_3DSTATE_URB_GS(struct drm_intel_decode *ctx)
2889{
2890 return gen7_3DSTATE_URB_unit(ctx, "GS");
2891}
2892
2893static int
Eric Anholt54b12a02012-01-04 13:41:55 -08002894gen7_3DSTATE_CONSTANT(struct drm_intel_decode *ctx, const char *unit)
2895{
2896 int rlen[4];
2897
2898 rlen[0] = (ctx->data[1] >> 0) & 0xffff;
2899 rlen[1] = (ctx->data[1] >> 16) & 0xffff;
2900 rlen[2] = (ctx->data[2] >> 0) & 0xffff;
2901 rlen[3] = (ctx->data[2] >> 16) & 0xffff;
2902
2903 instr_out(ctx, 0, "3DSTATE_CONSTANT_%s\n", unit);
2904 instr_out(ctx, 1, "len 0 = %d, len 1 = %d\n", rlen[0], rlen[1]);
2905 instr_out(ctx, 2, "len 2 = %d, len 3 = %d\n", rlen[2], rlen[3]);
2906 instr_out(ctx, 3, "pointer to constbuf 0\n");
2907 instr_out(ctx, 4, "pointer to constbuf 1\n");
2908 instr_out(ctx, 5, "pointer to constbuf 2\n");
2909 instr_out(ctx, 6, "pointer to constbuf 3\n");
2910
2911 return 7;
2912}
2913
2914static int
2915gen7_3DSTATE_CONSTANT_VS(struct drm_intel_decode *ctx)
2916{
2917 return gen7_3DSTATE_CONSTANT(ctx, "VS");
2918}
2919
2920static int
2921gen7_3DSTATE_CONSTANT_GS(struct drm_intel_decode *ctx)
2922{
2923 return gen7_3DSTATE_CONSTANT(ctx, "GS");
2924}
2925
2926static int
2927gen7_3DSTATE_CONSTANT_PS(struct drm_intel_decode *ctx)
2928{
2929 return gen7_3DSTATE_CONSTANT(ctx, "PS");
2930}
2931
2932static int
2933gen7_3DSTATE_CONSTANT_DS(struct drm_intel_decode *ctx)
2934{
2935 return gen7_3DSTATE_CONSTANT(ctx, "DS");
2936}
2937
2938static int
2939gen7_3DSTATE_CONSTANT_HS(struct drm_intel_decode *ctx)
2940{
2941 return gen7_3DSTATE_CONSTANT(ctx, "HS");
2942}
2943
Eric Anholte6beaf82012-01-30 15:04:10 -08002944
2945static int
2946gen6_3DSTATE_WM(struct drm_intel_decode *ctx)
2947{
2948 instr_out(ctx, 0, "3DSTATE_WM\n");
2949 instr_out(ctx, 1, "kernel start pointer 0\n");
2950 instr_out(ctx, 2,
2951 "SPF=%d, VME=%d, Sampler Count %d, "
2952 "Binding table count %d\n",
2953 (ctx->data[2] >> 31) & 1,
2954 (ctx->data[2] >> 30) & 1,
2955 (ctx->data[2] >> 27) & 7,
2956 (ctx->data[2] >> 18) & 0xff);
2957 instr_out(ctx, 3, "scratch offset\n");
2958 instr_out(ctx, 4,
2959 "Depth Clear %d, Depth Resolve %d, HiZ Resolve %d, "
2960 "Dispatch GRF start[0] %d, start[1] %d, start[2] %d\n",
2961 (ctx->data[4] & (1 << 30)) != 0,
2962 (ctx->data[4] & (1 << 28)) != 0,
2963 (ctx->data[4] & (1 << 27)) != 0,
2964 (ctx->data[4] >> 16) & 0x7f,
2965 (ctx->data[4] >> 8) & 0x7f,
2966 (ctx->data[4] & 0x7f));
2967 instr_out(ctx, 5,
2968 "MaxThreads %d, PS KillPixel %d, PS computed Z %d, "
2969 "PS use sourceZ %d, Thread Dispatch %d, PS use sourceW %d, "
2970 "Dispatch32 %d, Dispatch16 %d, Dispatch8 %d\n",
2971 ((ctx->data[5] >> 25) & 0x7f) + 1,
2972 (ctx->data[5] & (1 << 22)) != 0,
2973 (ctx->data[5] & (1 << 21)) != 0,
2974 (ctx->data[5] & (1 << 20)) != 0,
2975 (ctx->data[5] & (1 << 19)) != 0,
2976 (ctx->data[5] & (1 << 8)) != 0,
2977 (ctx->data[5] & (1 << 2)) != 0,
2978 (ctx->data[5] & (1 << 1)) != 0,
2979 (ctx->data[5] & (1 << 0)) != 0);
2980 instr_out(ctx, 6,
2981 "Num SF output %d, Pos XY offset %d, ZW interp mode %d , "
2982 "Barycentric interp mode 0x%x, Point raster rule %d, "
2983 "Multisample mode %d, "
2984 "Multisample Dispatch mode %d\n",
2985 (ctx->data[6] >> 20) & 0x3f,
2986 (ctx->data[6] >> 18) & 3,
2987 (ctx->data[6] >> 16) & 3,
2988 (ctx->data[6] >> 10) & 0x3f,
2989 (ctx->data[6] & (1 << 9)) != 0,
2990 (ctx->data[6] >> 1) & 3,
2991 (ctx->data[6] & 1));
2992 instr_out(ctx, 7, "kernel start pointer 1\n");
2993 instr_out(ctx, 8, "kernel start pointer 2\n");
2994
2995 return 9;
2996}
2997
2998static int
2999gen7_3DSTATE_WM(struct drm_intel_decode *ctx)
3000{
3001 const char *computed_depth = "";
3002 const char *early_depth = "";
3003 const char *zw_interp = "";
3004
3005 switch ((ctx->data[1] >> 23) & 0x3) {
3006 case 0:
3007 computed_depth = "";
3008 break;
3009 case 1:
3010 computed_depth = "computed depth";
3011 break;
3012 case 2:
3013 computed_depth = "computed depth >=";
3014 break;
3015 case 3:
3016 computed_depth = "computed depth <=";
3017 break;
3018 }
3019
3020 switch ((ctx->data[1] >> 21) & 0x3) {
3021 case 0:
3022 early_depth = "";
3023 break;
3024 case 1:
3025 early_depth = ", EDSC_PSEXEC";
3026 break;
3027 case 2:
3028 early_depth = ", EDSC_PREPS";
3029 break;
3030 case 3:
3031 early_depth = ", BAD EDSC";
3032 break;
3033 }
3034
3035 switch ((ctx->data[1] >> 17) & 0x3) {
3036 case 0:
3037 early_depth = "";
3038 break;
3039 case 1:
3040 early_depth = ", BAD ZW interp";
3041 break;
3042 case 2:
3043 early_depth = ", ZW centroid";
3044 break;
3045 case 3:
3046 early_depth = ", ZW sample";
3047 break;
3048 }
3049
3050 instr_out(ctx, 0, "3DSTATE_WM\n");
3051 instr_out(ctx, 1, "(%s%s%s%s%s%s)%s%s%s%s%s%s%s%s%s%s%s%s%s%s\n",
3052 (ctx->data[1] & (1 << 11)) ? "PP " : "",
3053 (ctx->data[1] & (1 << 12)) ? "PC " : "",
3054 (ctx->data[1] & (1 << 13)) ? "PS " : "",
3055 (ctx->data[1] & (1 << 14)) ? "NPP " : "",
3056 (ctx->data[1] & (1 << 15)) ? "NPC " : "",
3057 (ctx->data[1] & (1 << 16)) ? "NPS " : "",
3058 (ctx->data[1] & (1 << 30)) ? ", depth clear" : "",
3059 (ctx->data[1] & (1 << 29)) ? "" : ", disabled",
3060 (ctx->data[1] & (1 << 28)) ? ", depth resolve" : "",
3061 (ctx->data[1] & (1 << 27)) ? ", hiz resolve" : "",
3062 (ctx->data[1] & (1 << 25)) ? ", kill" : "",
3063 computed_depth,
3064 early_depth,
3065 zw_interp,
3066 (ctx->data[1] & (1 << 20)) ? ", source depth" : "",
3067 (ctx->data[1] & (1 << 19)) ? ", source W" : "",
3068 (ctx->data[1] & (1 << 10)) ? ", coverage" : "",
3069 (ctx->data[1] & (1 << 4)) ? ", poly stipple" : "",
3070 (ctx->data[1] & (1 << 3)) ? ", line stipple" : "",
3071 (ctx->data[1] & (1 << 2)) ? ", point UL" : ", point UR"
3072 );
3073 instr_out(ctx, 2, "MS\n");
3074
3075 return 3;
3076}
3077
Eric Anholt54b12a02012-01-04 13:41:55 -08003078static int
Eric Anholt9b87fd92012-03-02 10:18:51 -08003079gen4_3DPRIMITIVE(struct drm_intel_decode *ctx)
3080{
3081 instr_out(ctx, 0,
3082 "3DPRIMITIVE: %s %s\n",
Eric Anholt9d18ad22012-03-02 10:27:55 -08003083 get_965_prim_type((ctx->data[0] >> 10) & 0x1f),
Eric Anholt9b87fd92012-03-02 10:18:51 -08003084 (ctx->data[0] & (1 << 15)) ? "random" : "sequential");
3085 instr_out(ctx, 1, "vertex count\n");
3086 instr_out(ctx, 2, "start vertex\n");
3087 instr_out(ctx, 3, "instance count\n");
3088 instr_out(ctx, 4, "start instance\n");
3089 instr_out(ctx, 5, "index bias\n");
3090
3091 return 6;
3092}
3093
3094static int
Eric Anholt9d18ad22012-03-02 10:27:55 -08003095gen7_3DPRIMITIVE(struct drm_intel_decode *ctx)
3096{
3097 bool indirect = !!(ctx->data[0] & (1 << 10));
3098
3099 instr_out(ctx, 0,
3100 "3DPRIMITIVE: %s%s\n",
3101 indirect ? " indirect" : "",
3102 (ctx->data[0] & (1 << 8)) ? " predicated" : "");
3103 instr_out(ctx, 1, "%s %s\n",
3104 get_965_prim_type(ctx->data[1] & 0x3f),
3105 (ctx->data[1] & (1 << 8)) ? "random" : "sequential");
3106 instr_out(ctx, 2, indirect ? "ignored" : "vertex count\n");
3107 instr_out(ctx, 3, indirect ? "ignored" : "start vertex\n");
3108 instr_out(ctx, 4, indirect ? "ignored" : "instance count\n");
3109 instr_out(ctx, 5, indirect ? "ignored" : "start instance\n");
3110 instr_out(ctx, 6, indirect ? "ignored" : "index bias\n");
3111
3112 return 7;
3113}
3114
3115static int
Eric Anholtde49fd42011-12-20 15:15:21 -08003116decode_3d_965(struct drm_intel_decode *ctx)
Eric Anholt8c4a2c82011-12-20 11:25:20 -08003117{
Eric Anholt8c4a2c82011-12-20 11:25:20 -08003118 uint32_t opcode;
Eric Anholtb129e102012-01-04 13:00:29 -08003119 unsigned int len;
Eric Anholt7b483182011-12-20 14:27:17 -08003120 unsigned int i, j, sba_len;
Eric Anholt1db55a82011-12-20 12:00:28 -08003121 const char *desc1 = NULL;
Eric Anholtde49fd42011-12-20 15:15:21 -08003122 uint32_t *data = ctx->data;
Eric Anholtde49fd42011-12-20 15:15:21 -08003123 uint32_t devid = ctx->devid;
Eric Anholt8c4a2c82011-12-20 11:25:20 -08003124
Eric Anholt193fa132011-12-20 11:36:07 -08003125 struct {
3126 uint32_t opcode;
Eric Anholtb129e102012-01-04 13:00:29 -08003127 uint32_t len_mask;
Eric Anholt07768ba2011-12-20 13:46:23 -08003128 int unsigned min_len;
3129 int unsigned max_len;
Eric Anholt1db55a82011-12-20 12:00:28 -08003130 const char *name;
Eric Anholt9695eee2012-01-04 12:00:59 -08003131 int gen;
Eric Anholt3dcb2d42012-01-04 12:06:44 -08003132 int (*func)(struct drm_intel_decode *ctx);
Eric Anholt193fa132011-12-20 11:36:07 -08003133 } opcodes_3d[] = {
Eric Anholtb129e102012-01-04 13:00:29 -08003134 { 0x6000, 0x00ff, 3, 3, "URB_FENCE" },
3135 { 0x6001, 0xffff, 2, 2, "CS_URB_STATE" },
3136 { 0x6002, 0x00ff, 2, 2, "CONSTANT_BUFFER" },
Eric Anholtba8ce2d2012-01-04 13:18:42 -08003137 { 0x6101, 0xffff, 6, 10, "STATE_BASE_ADDRESS" },
Eric Anholtb129e102012-01-04 13:00:29 -08003138 { 0x6102, 0xffff, 2, 2, "STATE_SIP" },
3139 { 0x6104, 0xffff, 1, 1, "3DSTATE_PIPELINE_SELECT" },
3140 { 0x680b, 0xffff, 1, 1, "3DSTATE_VF_STATISTICS" },
3141 { 0x6904, 0xffff, 1, 1, "3DSTATE_PIPELINE_SELECT" },
3142 { 0x7800, 0xffff, 7, 7, "3DSTATE_PIPELINED_POINTERS" },
Eric Anholtba8ce2d2012-01-04 13:18:42 -08003143 { 0x7801, 0x00ff, 4, 6, "3DSTATE_BINDING_TABLE_POINTERS" },
Eric Anholtb129e102012-01-04 13:00:29 -08003144 { 0x7802, 0x00ff, 4, 4, "3DSTATE_SAMPLER_STATE_POINTERS" },
Eric Anholtb643b072012-01-04 14:36:13 -08003145 { 0x7805, 0x00ff, 7, 7, "3DSTATE_DEPTH_BUFFER", 7 },
Eric Anholtb129e102012-01-04 13:00:29 -08003146 { 0x7805, 0x00ff, 3, 3, "3DSTATE_URB" },
Eric Anholtb643b072012-01-04 14:36:13 -08003147 { 0x7804, 0x00ff, 3, 3, "3DSTATE_CLEAR_PARAMS" },
3148 { 0x7806, 0x00ff, 3, 3, "3DSTATE_STENCIL_BUFFER" },
Eric Anholtb395af02012-01-30 15:13:32 -08003149 { 0x7807, 0x00ff, 4, 4, "3DSTATE_HIER_DEPTH_BUFFER", 6 },
3150 { 0x7807, 0x00ff, 3, 3, "3DSTATE_HIER_DEPTH_BUFFER", 7, gen7_3DSTATE_HIER_DEPTH_BUFFER },
Eric Anholtb129e102012-01-04 13:00:29 -08003151 { 0x7808, 0x00ff, 5, 257, "3DSTATE_VERTEX_BUFFERS" },
3152 { 0x7809, 0x00ff, 3, 256, "3DSTATE_VERTEX_ELEMENTS" },
3153 { 0x780a, 0x00ff, 3, 3, "3DSTATE_INDEX_BUFFER" },
3154 { 0x780b, 0xffff, 1, 1, "3DSTATE_VF_STATISTICS" },
3155 { 0x780d, 0x00ff, 4, 4, "3DSTATE_VIEWPORT_STATE_POINTERS" },
Eric Anholt938df6b2012-01-04 12:23:42 -08003156 { 0x780e, 0xffff, 4, 4, NULL, 6, gen6_3DSTATE_CC_STATE_POINTERS },
3157 { 0x780e, 0x00ff, 2, 2, NULL, 7, gen7_3DSTATE_CC_STATE_POINTERS },
Eric Anholtb129e102012-01-04 13:00:29 -08003158 { 0x780f, 0x00ff, 2, 2, "3DSTATE_SCISSOR_POINTERS" },
3159 { 0x7810, 0x00ff, 6, 6, "3DSTATE_VS" },
3160 { 0x7811, 0x00ff, 7, 7, "3DSTATE_GS" },
3161 { 0x7812, 0x00ff, 4, 4, "3DSTATE_CLIP" },
Eric Anholtb643b072012-01-04 14:36:13 -08003162 { 0x7813, 0x00ff, 20, 20, "3DSTATE_SF", 6 },
3163 { 0x7813, 0x00ff, 7, 7, "3DSTATE_SF", 7 },
Eric Anholte6beaf82012-01-30 15:04:10 -08003164 { 0x7814, 0x00ff, 3, 3, "3DSTATE_WM", 7, gen7_3DSTATE_WM },
3165 { 0x7814, 0x00ff, 9, 9, "3DSTATE_WM", 6, gen6_3DSTATE_WM },
Eric Anholt54b12a02012-01-04 13:41:55 -08003166 { 0x7815, 0x00ff, 5, 5, "3DSTATE_CONSTANT_VS_STATE", 6 },
3167 { 0x7815, 0x00ff, 7, 7, "3DSTATE_CONSTANT_VS", 7, gen7_3DSTATE_CONSTANT_VS },
3168 { 0x7816, 0x00ff, 5, 5, "3DSTATE_CONSTANT_GS_STATE", 6 },
3169 { 0x7816, 0x00ff, 7, 7, "3DSTATE_CONSTANT_GS", 7, gen7_3DSTATE_CONSTANT_GS },
3170 { 0x7817, 0x00ff, 5, 5, "3DSTATE_CONSTANT_PS_STATE", 6 },
3171 { 0x7817, 0x00ff, 7, 7, "3DSTATE_CONSTANT_PS", 7, gen7_3DSTATE_CONSTANT_PS },
Eric Anholtb129e102012-01-04 13:00:29 -08003172 { 0x7818, 0xffff, 2, 2, "3DSTATE_SAMPLE_MASK" },
Eric Anholt54b12a02012-01-04 13:41:55 -08003173 { 0x7819, 0x00ff, 7, 7, "3DSTATE_CONSTANT_HS", 7, gen7_3DSTATE_CONSTANT_HS },
3174 { 0x781a, 0x00ff, 7, 7, "3DSTATE_CONSTANT_DS", 7, gen7_3DSTATE_CONSTANT_DS },
Eric Anholtb643b072012-01-04 14:36:13 -08003175 { 0x781b, 0x00ff, 7, 7, "3DSTATE_HS" },
3176 { 0x781c, 0x00ff, 4, 4, "3DSTATE_TE" },
3177 { 0x781d, 0x00ff, 6, 6, "3DSTATE_DS" },
3178 { 0x781e, 0x00ff, 3, 3, "3DSTATE_STREAMOUT" },
3179 { 0x781f, 0x00ff, 14, 14, "3DSTATE_SBE" },
3180 { 0x7820, 0x00ff, 8, 8, "3DSTATE_PS" },
Eric Anholt938df6b2012-01-04 12:23:42 -08003181 { 0x7821, 0x00ff, 2, 2, NULL, 7, gen7_3DSTATE_VIEWPORT_STATE_POINTERS_SF_CLIP },
3182 { 0x7823, 0x00ff, 2, 2, NULL, 7, gen7_3DSTATE_VIEWPORT_STATE_POINTERS_CC },
3183 { 0x7824, 0x00ff, 2, 2, NULL, 7, gen7_3DSTATE_BLEND_STATE_POINTERS },
3184 { 0x7825, 0x00ff, 2, 2, NULL, 7, gen7_3DSTATE_DEPTH_STENCIL_STATE_POINTERS },
Eric Anholtb643b072012-01-04 14:36:13 -08003185 { 0x7826, 0x00ff, 2, 2, "3DSTATE_BINDING_TABLE_POINTERS_VS" },
3186 { 0x7827, 0x00ff, 2, 2, "3DSTATE_BINDING_TABLE_POINTERS_HS" },
3187 { 0x7828, 0x00ff, 2, 2, "3DSTATE_BINDING_TABLE_POINTERS_DS" },
3188 { 0x7829, 0x00ff, 2, 2, "3DSTATE_BINDING_TABLE_POINTERS_GS" },
3189 { 0x782a, 0x00ff, 2, 2, "3DSTATE_BINDING_TABLE_POINTERS_PS" },
3190 { 0x782b, 0x00ff, 2, 2, "3DSTATE_SAMPLER_STATE_POINTERS_VS" },
Ben Widawskyeeedb0d2012-06-24 21:53:50 -07003191 { 0x782c, 0x00ff, 2, 2, "3DSTATE_SAMPLER_STATE_POINTERS_HS" },
3192 { 0x782d, 0x00ff, 2, 2, "3DSTATE_SAMPLER_STATE_POINTERS_DS" },
Eric Anholtb643b072012-01-04 14:36:13 -08003193 { 0x782e, 0x00ff, 2, 2, "3DSTATE_SAMPLER_STATE_POINTERS_GS" },
3194 { 0x782f, 0x00ff, 2, 2, "3DSTATE_SAMPLER_STATE_POINTERS_PS" },
Eric Anholt6a0b25e2012-01-04 12:12:41 -08003195 { 0x7830, 0x00ff, 2, 2, NULL, 7, gen7_3DSTATE_URB_VS },
3196 { 0x7831, 0x00ff, 2, 2, NULL, 7, gen7_3DSTATE_URB_HS },
3197 { 0x7832, 0x00ff, 2, 2, NULL, 7, gen7_3DSTATE_URB_DS },
3198 { 0x7833, 0x00ff, 2, 2, NULL, 7, gen7_3DSTATE_URB_GS },
Eric Anholtb129e102012-01-04 13:00:29 -08003199 { 0x7900, 0xffff, 4, 4, "3DSTATE_DRAWING_RECTANGLE" },
3200 { 0x7901, 0xffff, 5, 5, "3DSTATE_CONSTANT_COLOR" },
3201 { 0x7905, 0xffff, 5, 7, "3DSTATE_DEPTH_BUFFER" },
3202 { 0x7906, 0xffff, 2, 2, "3DSTATE_POLY_STIPPLE_OFFSET" },
3203 { 0x7907, 0xffff, 33, 33, "3DSTATE_POLY_STIPPLE_PATTERN" },
3204 { 0x7908, 0xffff, 3, 3, "3DSTATE_LINE_STIPPLE" },
3205 { 0x7909, 0xffff, 2, 2, "3DSTATE_GLOBAL_DEPTH_OFFSET_CLAMP" },
3206 { 0x7909, 0xffff, 2, 2, "3DSTATE_CLEAR_PARAMS" },
3207 { 0x790a, 0xffff, 3, 3, "3DSTATE_AA_LINE_PARAMETERS" },
3208 { 0x790b, 0xffff, 4, 4, "3DSTATE_GS_SVB_INDEX" },
3209 { 0x790d, 0xffff, 3, 3, "3DSTATE_MULTISAMPLE", 6 },
3210 { 0x790d, 0xffff, 4, 4, "3DSTATE_MULTISAMPLE", 7 },
3211 { 0x7910, 0xffff, 2, 2, "3DSTATE_CLEAR_PARAMS" },
Eric Anholtb643b072012-01-04 14:36:13 -08003212 { 0x7912, 0x00ff, 2, 2, "3DSTATE_PUSH_CONSTANT_ALLOC_VS" },
Ben Widawskyae137f42012-06-24 17:12:24 -07003213 { 0x7913, 0x00ff, 2, 2, "3DSTATE_PUSH_CONSTANT_ALLOC_HS" },
3214 { 0x7914, 0x00ff, 2, 2, "3DSTATE_PUSH_CONSTANT_ALLOC_DS" },
3215 { 0x7915, 0x00ff, 2, 2, "3DSTATE_PUSH_CONSTANT_ALLOC_GS" },
Eric Anholtb643b072012-01-04 14:36:13 -08003216 { 0x7916, 0x00ff, 2, 2, "3DSTATE_PUSH_CONSTANT_ALLOC_PS" },
3217 { 0x7917, 0x00ff, 2, 2+128*2, "3DSTATE_SO_DECL_LIST" },
3218 { 0x7918, 0x00ff, 4, 4, "3DSTATE_SO_BUFFER" },
Eric Anholtb129e102012-01-04 13:00:29 -08003219 { 0x7a00, 0x00ff, 4, 6, "PIPE_CONTROL" },
Eric Anholt9d18ad22012-03-02 10:27:55 -08003220 { 0x7b00, 0x00ff, 7, 7, NULL, 7, gen7_3DPRIMITIVE },
Eric Anholt9b87fd92012-03-02 10:18:51 -08003221 { 0x7b00, 0x00ff, 6, 6, NULL, 0, gen4_3DPRIMITIVE },
Eric Anholtb129e102012-01-04 13:00:29 -08003222 }, *opcode_3d = NULL;
Eric Anholt8c4a2c82011-12-20 11:25:20 -08003223
Eric Anholt193fa132011-12-20 11:36:07 -08003224 opcode = (data[0] & 0xffff0000) >> 16;
Eric Anholtb129e102012-01-04 13:00:29 -08003225
3226 for (i = 0; i < ARRAY_SIZE(opcodes_3d); i++) {
3227 if (opcode != opcodes_3d[i].opcode)
3228 continue;
3229
3230 /* If it's marked as not our gen, skip. */
3231 if (opcodes_3d[i].gen && opcodes_3d[i].gen != ctx->gen)
3232 continue;
3233
3234 opcode_3d = &opcodes_3d[i];
3235 break;
3236 }
3237
3238 if (opcode_3d) {
3239 if (opcode_3d->max_len == 1)
3240 len = 1;
3241 else
3242 len = (data[0] & opcode_3d->len_mask) + 2;
Eric Anholtba8ce2d2012-01-04 13:18:42 -08003243
3244 if (len < opcode_3d->min_len ||
3245 len > opcode_3d->max_len) {
Eric Anholt259e7b62012-01-27 13:27:56 -08003246 fprintf(out, "Bad length %d in %s, expected %d-%d\n",
Eric Anholtba8ce2d2012-01-04 13:18:42 -08003247 len, opcode_3d->name,
3248 opcode_3d->min_len, opcode_3d->max_len);
3249 }
Eric Anholtb129e102012-01-04 13:00:29 -08003250 } else {
3251 len = (data[0] & 0x0000ffff) + 2;
3252 }
3253
Eric Anholt193fa132011-12-20 11:36:07 -08003254 switch (opcode) {
3255 case 0x6000:
Eric Anholtc1d29462011-12-20 15:29:03 -08003256 return i965_decode_urb_fence(ctx, len);
Eric Anholt193fa132011-12-20 11:36:07 -08003257 case 0x6001:
Eric Anholtc1d29462011-12-20 15:29:03 -08003258 instr_out(ctx, 0, "CS_URB_STATE\n");
3259 instr_out(ctx, 1,
Eric Anholt193fa132011-12-20 11:36:07 -08003260 "entry_size: %d [%d bytes], n_entries: %d\n",
3261 (data[1] >> 4) & 0x1f,
3262 (((data[1] >> 4) & 0x1f) + 1) * 64, data[1] & 0x7);
Eric Anholt8c4a2c82011-12-20 11:25:20 -08003263 return len;
Eric Anholt193fa132011-12-20 11:36:07 -08003264 case 0x6002:
Eric Anholtc1d29462011-12-20 15:29:03 -08003265 instr_out(ctx, 0, "CONSTANT_BUFFER: %s\n",
Eric Anholt193fa132011-12-20 11:36:07 -08003266 (data[0] >> 8) & 1 ? "valid" : "invalid");
Eric Anholtc1d29462011-12-20 15:29:03 -08003267 instr_out(ctx, 1,
Eric Anholt193fa132011-12-20 11:36:07 -08003268 "offset: 0x%08x, length: %d bytes\n", data[1] & ~0x3f,
3269 ((data[1] & 0x3f) + 1) * 64);
3270 return len;
3271 case 0x6101:
3272 i = 0;
Eric Anholtc1d29462011-12-20 15:29:03 -08003273 instr_out(ctx, 0, "STATE_BASE_ADDRESS\n");
Eric Anholt193fa132011-12-20 11:36:07 -08003274 i++;
3275
3276 if (IS_GEN6(devid) || IS_GEN7(devid))
3277 sba_len = 10;
3278 else if (IS_GEN5(devid))
3279 sba_len = 8;
3280 else
3281 sba_len = 6;
3282 if (len != sba_len)
3283 fprintf(out, "Bad count in STATE_BASE_ADDRESS\n");
Eric Anholt193fa132011-12-20 11:36:07 -08003284
Eric Anholtc1d29462011-12-20 15:29:03 -08003285 state_base_out(ctx, i++, "general");
3286 state_base_out(ctx, i++, "surface");
Eric Anholt193fa132011-12-20 11:36:07 -08003287 if (IS_GEN6(devid) || IS_GEN7(devid))
Eric Anholtc1d29462011-12-20 15:29:03 -08003288 state_base_out(ctx, i++, "dynamic");
3289 state_base_out(ctx, i++, "indirect");
Eric Anholt193fa132011-12-20 11:36:07 -08003290 if (IS_GEN5(devid) || IS_GEN6(devid) || IS_GEN7(devid))
Eric Anholtc1d29462011-12-20 15:29:03 -08003291 state_base_out(ctx, i++, "instruction");
Eric Anholt193fa132011-12-20 11:36:07 -08003292
Eric Anholtc1d29462011-12-20 15:29:03 -08003293 state_max_out(ctx, i++, "general");
Eric Anholt193fa132011-12-20 11:36:07 -08003294 if (IS_GEN6(devid) || IS_GEN7(devid))
Eric Anholtc1d29462011-12-20 15:29:03 -08003295 state_max_out(ctx, i++, "dynamic");
3296 state_max_out(ctx, i++, "indirect");
Eric Anholt193fa132011-12-20 11:36:07 -08003297 if (IS_GEN5(devid) || IS_GEN6(devid) || IS_GEN7(devid))
Eric Anholtc1d29462011-12-20 15:29:03 -08003298 state_max_out(ctx, i++, "instruction");
Eric Anholt193fa132011-12-20 11:36:07 -08003299
3300 return len;
3301 case 0x7800:
Eric Anholtc1d29462011-12-20 15:29:03 -08003302 instr_out(ctx, 0, "3DSTATE_PIPELINED_POINTERS\n");
3303 instr_out(ctx, 1, "VS state\n");
3304 instr_out(ctx, 2, "GS state\n");
3305 instr_out(ctx, 3, "Clip state\n");
3306 instr_out(ctx, 4, "SF state\n");
3307 instr_out(ctx, 5, "WM state\n");
3308 instr_out(ctx, 6, "CC state\n");
Eric Anholt193fa132011-12-20 11:36:07 -08003309 return len;
3310 case 0x7801:
Eric Anholt193fa132011-12-20 11:36:07 -08003311 if (len != 6 && len != 4)
3312 fprintf(out,
3313 "Bad count in 3DSTATE_BINDING_TABLE_POINTERS\n");
3314 if (len == 6) {
Eric Anholtc1d29462011-12-20 15:29:03 -08003315 instr_out(ctx, 0,
Eric Anholt193fa132011-12-20 11:36:07 -08003316 "3DSTATE_BINDING_TABLE_POINTERS\n");
Eric Anholtc1d29462011-12-20 15:29:03 -08003317 instr_out(ctx, 1, "VS binding table\n");
3318 instr_out(ctx, 2, "GS binding table\n");
3319 instr_out(ctx, 3, "Clip binding table\n");
3320 instr_out(ctx, 4, "SF binding table\n");
3321 instr_out(ctx, 5, "WM binding table\n");
Eric Anholt193fa132011-12-20 11:36:07 -08003322 } else {
Eric Anholtc1d29462011-12-20 15:29:03 -08003323 instr_out(ctx, 0,
Eric Anholt193fa132011-12-20 11:36:07 -08003324 "3DSTATE_BINDING_TABLE_POINTERS: VS mod %d, "
3325 "GS mod %d, PS mod %d\n",
3326 (data[0] & (1 << 8)) != 0,
3327 (data[0] & (1 << 9)) != 0,
3328 (data[0] & (1 << 12)) != 0);
Eric Anholtc1d29462011-12-20 15:29:03 -08003329 instr_out(ctx, 1, "VS binding table\n");
3330 instr_out(ctx, 2, "GS binding table\n");
3331 instr_out(ctx, 3, "WM binding table\n");
Eric Anholt193fa132011-12-20 11:36:07 -08003332 }
3333
3334 return len;
3335 case 0x7802:
Eric Anholtc1d29462011-12-20 15:29:03 -08003336 instr_out(ctx, 0,
Eric Anholt193fa132011-12-20 11:36:07 -08003337 "3DSTATE_SAMPLER_STATE_POINTERS: VS mod %d, "
3338 "GS mod %d, PS mod %d\n", (data[0] & (1 << 8)) != 0,
3339 (data[0] & (1 << 9)) != 0,
3340 (data[0] & (1 << 12)) != 0);
Eric Anholtc1d29462011-12-20 15:29:03 -08003341 instr_out(ctx, 1, "VS sampler state\n");
3342 instr_out(ctx, 2, "GS sampler state\n");
3343 instr_out(ctx, 3, "WM sampler state\n");
Eric Anholt193fa132011-12-20 11:36:07 -08003344 return len;
3345 case 0x7805:
Eric Anholtb643b072012-01-04 14:36:13 -08003346 /* Actually 3DSTATE_DEPTH_BUFFER on gen7. */
3347 if (ctx->gen == 7)
3348 break;
3349
Eric Anholtc1d29462011-12-20 15:29:03 -08003350 instr_out(ctx, 0, "3DSTATE_URB\n");
3351 instr_out(ctx, 1,
Eric Anholt193fa132011-12-20 11:36:07 -08003352 "VS entries %d, alloc size %d (1024bit row)\n",
3353 data[1] & 0xffff, ((data[1] >> 16) & 0x07f) + 1);
Eric Anholtc1d29462011-12-20 15:29:03 -08003354 instr_out(ctx, 2,
Eric Anholt193fa132011-12-20 11:36:07 -08003355 "GS entries %d, alloc size %d (1024bit row)\n",
3356 (data[2] >> 8) & 0x3ff, (data[2] & 7) + 1);
3357 return len;
3358
3359 case 0x7808:
Eric Anholt193fa132011-12-20 11:36:07 -08003360 if ((len - 1) % 4 != 0)
3361 fprintf(out, "Bad count in 3DSTATE_VERTEX_BUFFERS\n");
Eric Anholtc1d29462011-12-20 15:29:03 -08003362 instr_out(ctx, 0, "3DSTATE_VERTEX_BUFFERS\n");
Eric Anholt193fa132011-12-20 11:36:07 -08003363
3364 for (i = 1; i < len;) {
3365 int idx, access;
3366 if (IS_GEN6(devid)) {
3367 idx = 26;
3368 access = 20;
3369 } else {
3370 idx = 27;
3371 access = 26;
3372 }
Eric Anholtc1d29462011-12-20 15:29:03 -08003373 instr_out(ctx, i,
Eric Anholt193fa132011-12-20 11:36:07 -08003374 "buffer %d: %s, pitch %db\n", data[i] >> idx,
3375 data[i] & (1 << access) ? "random" :
3376 "sequential", data[i] & 0x07ff);
3377 i++;
Eric Anholtc1d29462011-12-20 15:29:03 -08003378 instr_out(ctx, i++, "buffer address\n");
3379 instr_out(ctx, i++, "max index\n");
3380 instr_out(ctx, i++, "mbz\n");
Eric Anholt193fa132011-12-20 11:36:07 -08003381 }
3382 return len;
3383
3384 case 0x7809:
Eric Anholt193fa132011-12-20 11:36:07 -08003385 if ((len + 1) % 2 != 0)
3386 fprintf(out, "Bad count in 3DSTATE_VERTEX_ELEMENTS\n");
Eric Anholtc1d29462011-12-20 15:29:03 -08003387 instr_out(ctx, 0, "3DSTATE_VERTEX_ELEMENTS\n");
Eric Anholt193fa132011-12-20 11:36:07 -08003388
3389 for (i = 1; i < len;) {
Eric Anholtc1d29462011-12-20 15:29:03 -08003390 instr_out(ctx, i,
Eric Anholt193fa132011-12-20 11:36:07 -08003391 "buffer %d: %svalid, type 0x%04x, "
3392 "src offset 0x%04x bytes\n",
3393 data[i] >> (IS_GEN6(devid) ? 26 : 27),
3394 data[i] & (1 << (IS_GEN6(devid) ? 25 : 26)) ?
3395 "" : "in", (data[i] >> 16) & 0x1ff,
3396 data[i] & 0x07ff);
3397 i++;
Eric Anholtc1d29462011-12-20 15:29:03 -08003398 instr_out(ctx, i, "(%s, %s, %s, %s), "
Eric Anholt193fa132011-12-20 11:36:07 -08003399 "dst offset 0x%02x bytes\n",
3400 get_965_element_component(data[i], 0),
3401 get_965_element_component(data[i], 1),
3402 get_965_element_component(data[i], 2),
3403 get_965_element_component(data[i], 3),
3404 (data[i] & 0xff) * 4);
3405 i++;
3406 }
3407 return len;
3408
3409 case 0x780d:
Eric Anholtc1d29462011-12-20 15:29:03 -08003410 instr_out(ctx, 0,
Eric Anholt193fa132011-12-20 11:36:07 -08003411 "3DSTATE_VIEWPORT_STATE_POINTERS\n");
Eric Anholtc1d29462011-12-20 15:29:03 -08003412 instr_out(ctx, 1, "clip\n");
3413 instr_out(ctx, 2, "sf\n");
3414 instr_out(ctx, 3, "cc\n");
Eric Anholt193fa132011-12-20 11:36:07 -08003415 return len;
3416
3417 case 0x780a:
Eric Anholtc1d29462011-12-20 15:29:03 -08003418 instr_out(ctx, 0, "3DSTATE_INDEX_BUFFER\n");
3419 instr_out(ctx, 1, "beginning buffer address\n");
3420 instr_out(ctx, 2, "ending buffer address\n");
Eric Anholt193fa132011-12-20 11:36:07 -08003421 return len;
3422
Eric Anholt193fa132011-12-20 11:36:07 -08003423 case 0x780f:
Eric Anholtc1d29462011-12-20 15:29:03 -08003424 instr_out(ctx, 0, "3DSTATE_SCISSOR_POINTERS\n");
3425 instr_out(ctx, 1, "scissor rect offset\n");
Eric Anholt193fa132011-12-20 11:36:07 -08003426 return len;
3427
3428 case 0x7810:
Eric Anholtc1d29462011-12-20 15:29:03 -08003429 instr_out(ctx, 0, "3DSTATE_VS\n");
3430 instr_out(ctx, 1, "kernel pointer\n");
3431 instr_out(ctx, 2,
Eric Anholt193fa132011-12-20 11:36:07 -08003432 "SPF=%d, VME=%d, Sampler Count %d, "
3433 "Binding table count %d\n", (data[2] >> 31) & 1,
3434 (data[2] >> 30) & 1, (data[2] >> 27) & 7,
3435 (data[2] >> 18) & 0xff);
Eric Anholtc1d29462011-12-20 15:29:03 -08003436 instr_out(ctx, 3, "scratch offset\n");
3437 instr_out(ctx, 4,
Eric Anholt193fa132011-12-20 11:36:07 -08003438 "Dispatch GRF start %d, VUE read length %d, "
3439 "VUE read offset %d\n", (data[4] >> 20) & 0x1f,
3440 (data[4] >> 11) & 0x3f, (data[4] >> 4) & 0x3f);
Eric Anholtc1d29462011-12-20 15:29:03 -08003441 instr_out(ctx, 5,
Eric Anholt193fa132011-12-20 11:36:07 -08003442 "Max Threads %d, Vertex Cache %sable, "
3443 "VS func %sable\n", ((data[5] >> 25) & 0x7f) + 1,
3444 (data[5] & (1 << 1)) != 0 ? "dis" : "en",
3445 (data[5] & 1) != 0 ? "en" : "dis");
3446 return len;
3447
3448 case 0x7811:
Eric Anholtc1d29462011-12-20 15:29:03 -08003449 instr_out(ctx, 0, "3DSTATE_GS\n");
3450 instr_out(ctx, 1, "kernel pointer\n");
3451 instr_out(ctx, 2,
Eric Anholt193fa132011-12-20 11:36:07 -08003452 "SPF=%d, VME=%d, Sampler Count %d, "
3453 "Binding table count %d\n", (data[2] >> 31) & 1,
3454 (data[2] >> 30) & 1, (data[2] >> 27) & 7,
3455 (data[2] >> 18) & 0xff);
Eric Anholtc1d29462011-12-20 15:29:03 -08003456 instr_out(ctx, 3, "scratch offset\n");
3457 instr_out(ctx, 4,
Eric Anholt193fa132011-12-20 11:36:07 -08003458 "Dispatch GRF start %d, VUE read length %d, "
3459 "VUE read offset %d\n", (data[4] & 0xf),
3460 (data[4] >> 11) & 0x3f, (data[4] >> 4) & 0x3f);
Eric Anholtc1d29462011-12-20 15:29:03 -08003461 instr_out(ctx, 5,
Eric Anholt193fa132011-12-20 11:36:07 -08003462 "Max Threads %d, Rendering %sable\n",
3463 ((data[5] >> 25) & 0x7f) + 1,
3464 (data[5] & (1 << 8)) != 0 ? "en" : "dis");
Eric Anholtc1d29462011-12-20 15:29:03 -08003465 instr_out(ctx, 6,
Eric Anholt193fa132011-12-20 11:36:07 -08003466 "Reorder %sable, Discard Adjaceny %sable, "
3467 "GS %sable\n",
3468 (data[6] & (1 << 30)) != 0 ? "en" : "dis",
3469 (data[6] & (1 << 29)) != 0 ? "en" : "dis",
3470 (data[6] & (1 << 15)) != 0 ? "en" : "dis");
3471 return len;
3472
3473 case 0x7812:
Eric Anholtc1d29462011-12-20 15:29:03 -08003474 instr_out(ctx, 0, "3DSTATE_CLIP\n");
3475 instr_out(ctx, 1,
Eric Anholt193fa132011-12-20 11:36:07 -08003476 "UserClip distance cull test mask 0x%x\n",
3477 data[1] & 0xff);
Eric Anholtc1d29462011-12-20 15:29:03 -08003478 instr_out(ctx, 2,
Eric Anholt193fa132011-12-20 11:36:07 -08003479 "Clip %sable, API mode %s, Viewport XY test %sable, "
3480 "Viewport Z test %sable, Guardband test %sable, Clip mode %d, "
3481 "Perspective Divide %sable, Non-Perspective Barycentric %sable, "
3482 "Tri Provoking %d, Line Provoking %d, Trifan Provoking %d\n",
3483 (data[2] & (1 << 31)) != 0 ? "en" : "dis",
3484 (data[2] & (1 << 30)) != 0 ? "D3D" : "OGL",
3485 (data[2] & (1 << 28)) != 0 ? "en" : "dis",
3486 (data[2] & (1 << 27)) != 0 ? "en" : "dis",
3487 (data[2] & (1 << 26)) != 0 ? "en" : "dis",
3488 (data[2] >> 13) & 7,
3489 (data[2] & (1 << 9)) != 0 ? "dis" : "en",
3490 (data[2] & (1 << 8)) != 0 ? "en" : "dis",
3491 (data[2] >> 4) & 3, (data[2] >> 2) & 3,
3492 (data[2] & 3));
Eric Anholtc1d29462011-12-20 15:29:03 -08003493 instr_out(ctx, 3,
Eric Anholt193fa132011-12-20 11:36:07 -08003494 "Min PointWidth %d, Max PointWidth %d, "
3495 "Force Zero RTAIndex %sable, Max VPIndex %d\n",
3496 (data[3] >> 17) & 0x7ff, (data[3] >> 6) & 0x7ff,
3497 (data[3] & (1 << 5)) != 0 ? "en" : "dis",
3498 (data[3] & 0xf));
3499 return len;
3500
3501 case 0x7813:
Eric Anholtb643b072012-01-04 14:36:13 -08003502 if (ctx->gen == 7)
3503 break;
3504
Eric Anholtc1d29462011-12-20 15:29:03 -08003505 instr_out(ctx, 0, "3DSTATE_SF\n");
3506 instr_out(ctx, 1,
Eric Anholt193fa132011-12-20 11:36:07 -08003507 "Attrib Out %d, Attrib Swizzle %sable, VUE read length %d, "
3508 "VUE read offset %d\n", (data[1] >> 22) & 0x3f,
3509 (data[1] & (1 << 21)) != 0 ? "en" : "dis",
3510 (data[1] >> 11) & 0x1f, (data[1] >> 4) & 0x3f);
Eric Anholtc1d29462011-12-20 15:29:03 -08003511 instr_out(ctx, 2,
Eric Anholt193fa132011-12-20 11:36:07 -08003512 "Legacy Global DepthBias %sable, FrontFace fill %d, BF fill %d, "
3513 "VP transform %sable, FrontWinding_%s\n",
3514 (data[2] & (1 << 11)) != 0 ? "en" : "dis",
3515 (data[2] >> 5) & 3, (data[2] >> 3) & 3,
3516 (data[2] & (1 << 1)) != 0 ? "en" : "dis",
3517 (data[2] & 1) != 0 ? "CCW" : "CW");
Eric Anholtc1d29462011-12-20 15:29:03 -08003518 instr_out(ctx, 3,
Eric Anholt193fa132011-12-20 11:36:07 -08003519 "AA %sable, CullMode %d, Scissor %sable, Multisample m ode %d\n",
3520 (data[3] & (1 << 31)) != 0 ? "en" : "dis",
3521 (data[3] >> 29) & 3,
3522 (data[3] & (1 << 11)) != 0 ? "en" : "dis",
3523 (data[3] >> 8) & 3);
Eric Anholtc1d29462011-12-20 15:29:03 -08003524 instr_out(ctx, 4,
Eric Anholt193fa132011-12-20 11:36:07 -08003525 "Last Pixel %sable, SubPixel Precision %d, Use PixelWidth %d\n",
3526 (data[4] & (1 << 31)) != 0 ? "en" : "dis",
3527 (data[4] & (1 << 12)) != 0 ? 4 : 8,
3528 (data[4] & (1 << 11)) != 0);
Eric Anholtc1d29462011-12-20 15:29:03 -08003529 instr_out(ctx, 5,
Eric Anholt0c46f022011-12-20 14:23:15 -08003530 "Global Depth Offset Constant %f\n",
3531 *(float *)(&data[5]));
Eric Anholtc1d29462011-12-20 15:29:03 -08003532 instr_out(ctx, 6, "Global Depth Offset Scale %f\n",
Eric Anholt0c46f022011-12-20 14:23:15 -08003533 *(float *)(&data[6]));
Eric Anholtc1d29462011-12-20 15:29:03 -08003534 instr_out(ctx, 7, "Global Depth Offset Clamp %f\n",
Eric Anholt0c46f022011-12-20 14:23:15 -08003535 *(float *)(&data[7]));
Eric Anholt7b483182011-12-20 14:27:17 -08003536
Eric Anholt193fa132011-12-20 11:36:07 -08003537 for (i = 0, j = 0; i < 8; i++, j += 2)
Eric Anholtc1d29462011-12-20 15:29:03 -08003538 instr_out(ctx, i + 8,
Eric Anholt193fa132011-12-20 11:36:07 -08003539 "Attrib %d (Override %s%s%s%s, Const Source %d, Swizzle Select %d, "
3540 "Source %d); Attrib %d (Override %s%s%s%s, Const Source %d, Swizzle Select %d, Source %d)\n",
3541 j + 1,
3542 (data[8 + i] & (1 << 31)) != 0 ? "W" : "",
3543 (data[8 + i] & (1 << 30)) != 0 ? "Z" : "",
3544 (data[8 + i] & (1 << 29)) != 0 ? "Y" : "",
3545 (data[8 + i] & (1 << 28)) != 0 ? "X" : "",
3546 (data[8 + i] >> 25) & 3,
3547 (data[8 + i] >> 22) & 3,
3548 (data[8 + i] >> 16) & 0x1f, j,
3549 (data[8 + i] & (1 << 15)) != 0 ? "W" : "",
3550 (data[8 + i] & (1 << 14)) != 0 ? "Z" : "",
3551 (data[8 + i] & (1 << 13)) != 0 ? "Y" : "",
3552 (data[8 + i] & (1 << 12)) != 0 ? "X" : "",
3553 (data[8 + i] >> 9) & 3,
3554 (data[8 + i] >> 6) & 3, (data[8 + i] & 0x1f));
Eric Anholtc1d29462011-12-20 15:29:03 -08003555 instr_out(ctx, 16,
Eric Anholt193fa132011-12-20 11:36:07 -08003556 "Point Sprite TexCoord Enable\n");
Eric Anholtc1d29462011-12-20 15:29:03 -08003557 instr_out(ctx, 17, "Const Interp Enable\n");
3558 instr_out(ctx, 18,
Eric Anholt193fa132011-12-20 11:36:07 -08003559 "Attrib 7-0 WrapShortest Enable\n");
Eric Anholtc1d29462011-12-20 15:29:03 -08003560 instr_out(ctx, 19,
Eric Anholt193fa132011-12-20 11:36:07 -08003561 "Attrib 15-8 WrapShortest Enable\n");
3562
3563 return len;
3564
Eric Anholt193fa132011-12-20 11:36:07 -08003565 case 0x7900:
Eric Anholtc1d29462011-12-20 15:29:03 -08003566 instr_out(ctx, 0, "3DSTATE_DRAWING_RECTANGLE\n");
3567 instr_out(ctx, 1, "top left: %d,%d\n",
Eric Anholt193fa132011-12-20 11:36:07 -08003568 data[1] & 0xffff, (data[1] >> 16) & 0xffff);
Eric Anholtc1d29462011-12-20 15:29:03 -08003569 instr_out(ctx, 2, "bottom right: %d,%d\n",
Eric Anholt193fa132011-12-20 11:36:07 -08003570 data[2] & 0xffff, (data[2] >> 16) & 0xffff);
Eric Anholtc1d29462011-12-20 15:29:03 -08003571 instr_out(ctx, 3, "origin: %d,%d\n",
Eric Anholt193fa132011-12-20 11:36:07 -08003572 (int)data[3] & 0xffff, ((int)data[3] >> 16) & 0xffff);
3573
3574 return len;
3575
3576 case 0x7905:
Eric Anholtc1d29462011-12-20 15:29:03 -08003577 instr_out(ctx, 0, "3DSTATE_DEPTH_BUFFER\n");
Eric Anholt193fa132011-12-20 11:36:07 -08003578 if (IS_GEN5(devid) || IS_GEN6(devid))
Eric Anholtc1d29462011-12-20 15:29:03 -08003579 instr_out(ctx, 1,
Eric Anholt193fa132011-12-20 11:36:07 -08003580 "%s, %s, pitch = %d bytes, %stiled, HiZ %d, Seperate Stencil %d\n",
3581 get_965_surfacetype(data[1] >> 29),
3582 get_965_depthformat((data[1] >> 18) & 0x7),
3583 (data[1] & 0x0001ffff) + 1,
3584 data[1] & (1 << 27) ? "" : "not ",
3585 (data[1] & (1 << 22)) != 0,
3586 (data[1] & (1 << 21)) != 0);
3587 else
Eric Anholtc1d29462011-12-20 15:29:03 -08003588 instr_out(ctx, 1,
Eric Anholt193fa132011-12-20 11:36:07 -08003589 "%s, %s, pitch = %d bytes, %stiled\n",
3590 get_965_surfacetype(data[1] >> 29),
3591 get_965_depthformat((data[1] >> 18) & 0x7),
3592 (data[1] & 0x0001ffff) + 1,
3593 data[1] & (1 << 27) ? "" : "not ");
Eric Anholtc1d29462011-12-20 15:29:03 -08003594 instr_out(ctx, 2, "depth offset\n");
3595 instr_out(ctx, 3, "%dx%d\n",
Eric Anholt193fa132011-12-20 11:36:07 -08003596 ((data[3] & 0x0007ffc0) >> 6) + 1,
3597 ((data[3] & 0xfff80000) >> 19) + 1);
Eric Anholtc1d29462011-12-20 15:29:03 -08003598 instr_out(ctx, 4, "volume depth\n");
Eric Anholt193fa132011-12-20 11:36:07 -08003599 if (len >= 6)
Eric Anholtc1d29462011-12-20 15:29:03 -08003600 instr_out(ctx, 5, "\n");
Eric Anholt193fa132011-12-20 11:36:07 -08003601 if (len >= 7) {
3602 if (IS_GEN6(devid))
Eric Anholtc1d29462011-12-20 15:29:03 -08003603 instr_out(ctx, 6, "\n");
Eric Anholt193fa132011-12-20 11:36:07 -08003604 else
Eric Anholtc1d29462011-12-20 15:29:03 -08003605 instr_out(ctx, 6,
Eric Anholt193fa132011-12-20 11:36:07 -08003606 "render target view extent\n");
3607 }
3608
3609 return len;
3610
3611 case 0x7a00:
Eric Anholt71066ab2011-12-20 13:06:16 -08003612 if (IS_GEN6(devid) || IS_GEN7(devid)) {
Eric Anholt07768ba2011-12-20 13:46:23 -08003613 unsigned int i;
Eric Anholt193fa132011-12-20 11:36:07 -08003614 if (len != 4 && len != 5)
3615 fprintf(out, "Bad count in PIPE_CONTROL\n");
Eric Anholt193fa132011-12-20 11:36:07 -08003616
3617 switch ((data[1] >> 14) & 0x3) {
3618 case 0:
3619 desc1 = "no write";
3620 break;
3621 case 1:
3622 desc1 = "qword write";
3623 break;
3624 case 2:
3625 desc1 = "PS_DEPTH_COUNT write";
3626 break;
3627 case 3:
3628 desc1 = "TIMESTAMP write";
3629 break;
3630 }
Eric Anholtc1d29462011-12-20 15:29:03 -08003631 instr_out(ctx, 0, "PIPE_CONTROL\n");
3632 instr_out(ctx, 1,
Eric Anholt193fa132011-12-20 11:36:07 -08003633 "%s, %s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s\n",
3634 desc1,
3635 data[1] & (1 << 20) ? "cs stall, " : "",
3636 data[1] & (1 << 19) ?
3637 "global snapshot count reset, " : "",
3638 data[1] & (1 << 18) ? "tlb invalidate, " : "",
3639 data[1] & (1 << 17) ? "gfdt flush, " : "",
3640 data[1] & (1 << 17) ? "media state clear, " :
3641 "",
3642 data[1] & (1 << 13) ? "depth stall, " : "",
3643 data[1] & (1 << 12) ?
3644 "render target cache flush, " : "",
3645 data[1] & (1 << 11) ?
3646 "instruction cache invalidate, " : "",
3647 data[1] & (1 << 10) ?
3648 "texture cache invalidate, " : "",
3649 data[1] & (1 << 9) ?
3650 "indirect state invalidate, " : "",
3651 data[1] & (1 << 8) ? "notify irq, " : "",
3652 data[1] & (1 << 7) ? "PIPE_CONTROL flush, " :
3653 "",
3654 data[1] & (1 << 6) ? "protect mem app_id, " :
3655 "", data[1] & (1 << 5) ? "DC flush, " : "",
3656 data[1] & (1 << 4) ? "vf fetch invalidate, " :
3657 "",
3658 data[1] & (1 << 3) ?
3659 "constant cache invalidate, " : "",
3660 data[1] & (1 << 2) ?
3661 "state cache invalidate, " : "",
3662 data[1] & (1 << 1) ? "stall at scoreboard, " :
3663 "",
3664 data[1] & (1 << 0) ? "depth cache flush, " :
3665 "");
3666 if (len == 5) {
Eric Anholtc1d29462011-12-20 15:29:03 -08003667 instr_out(ctx, 2,
Eric Anholt193fa132011-12-20 11:36:07 -08003668 "destination address\n");
Eric Anholtc1d29462011-12-20 15:29:03 -08003669 instr_out(ctx, 3,
Eric Anholt193fa132011-12-20 11:36:07 -08003670 "immediate dword low\n");
Eric Anholtc1d29462011-12-20 15:29:03 -08003671 instr_out(ctx, 4,
Eric Anholt193fa132011-12-20 11:36:07 -08003672 "immediate dword high\n");
3673 } else {
3674 for (i = 2; i < len; i++) {
Eric Anholtc1d29462011-12-20 15:29:03 -08003675 instr_out(ctx, i, "\n");
Eric Anholt193fa132011-12-20 11:36:07 -08003676 }
3677 }
3678 return len;
3679 } else {
Eric Anholt193fa132011-12-20 11:36:07 -08003680 if (len != 4)
3681 fprintf(out, "Bad count in PIPE_CONTROL\n");
Eric Anholt193fa132011-12-20 11:36:07 -08003682
3683 switch ((data[0] >> 14) & 0x3) {
3684 case 0:
3685 desc1 = "no write";
3686 break;
3687 case 1:
3688 desc1 = "qword write";
3689 break;
3690 case 2:
3691 desc1 = "PS_DEPTH_COUNT write";
3692 break;
3693 case 3:
3694 desc1 = "TIMESTAMP write";
3695 break;
3696 }
Eric Anholtc1d29462011-12-20 15:29:03 -08003697 instr_out(ctx, 0,
Eric Anholt193fa132011-12-20 11:36:07 -08003698 "PIPE_CONTROL: %s, %sdepth stall, %sRC write flush, "
3699 "%sinst flush\n",
3700 desc1,
3701 data[0] & (1 << 13) ? "" : "no ",
3702 data[0] & (1 << 12) ? "" : "no ",
3703 data[0] & (1 << 11) ? "" : "no ");
Eric Anholtc1d29462011-12-20 15:29:03 -08003704 instr_out(ctx, 1, "destination address\n");
3705 instr_out(ctx, 2, "immediate dword low\n");
3706 instr_out(ctx, 3, "immediate dword high\n");
Eric Anholt193fa132011-12-20 11:36:07 -08003707 return len;
3708 }
Eric Anholt8c4a2c82011-12-20 11:25:20 -08003709 }
Eric Anholt8c4a2c82011-12-20 11:25:20 -08003710
Eric Anholtb129e102012-01-04 13:00:29 -08003711 if (opcode_3d) {
Eric Anholt3dcb2d42012-01-04 12:06:44 -08003712 if (opcode_3d->func) {
3713 return opcode_3d->func(ctx);
3714 } else {
Eric Anholt193fa132011-12-20 11:36:07 -08003715 unsigned int i;
Eric Anholt8c4a2c82011-12-20 11:25:20 -08003716
Eric Anholtc1d29462011-12-20 15:29:03 -08003717 instr_out(ctx, 0, "%s\n", opcode_3d->name);
Eric Anholt8c4a2c82011-12-20 11:25:20 -08003718
Eric Anholt193fa132011-12-20 11:36:07 -08003719 for (i = 1; i < len; i++) {
Eric Anholtc1d29462011-12-20 15:29:03 -08003720 instr_out(ctx, i, "dword %d\n", i);
Eric Anholt193fa132011-12-20 11:36:07 -08003721 }
3722 return len;
Eric Anholt8c4a2c82011-12-20 11:25:20 -08003723 }
Eric Anholt8c4a2c82011-12-20 11:25:20 -08003724 }
Eric Anholt8c4a2c82011-12-20 11:25:20 -08003725
Eric Anholtc1d29462011-12-20 15:29:03 -08003726 instr_out(ctx, 0, "3D UNKNOWN: 3d_965 opcode = 0x%x\n",
Eric Anholt193fa132011-12-20 11:36:07 -08003727 opcode);
Eric Anholt193fa132011-12-20 11:36:07 -08003728 return 1;
Eric Anholt8c4a2c82011-12-20 11:25:20 -08003729}
3730
3731static int
Eric Anholtde49fd42011-12-20 15:15:21 -08003732decode_3d_i830(struct drm_intel_decode *ctx)
Eric Anholt8c4a2c82011-12-20 11:25:20 -08003733{
Eric Anholt193fa132011-12-20 11:36:07 -08003734 unsigned int idx;
Eric Anholt8c4a2c82011-12-20 11:25:20 -08003735 uint32_t opcode;
Eric Anholtde49fd42011-12-20 15:15:21 -08003736 uint32_t *data = ctx->data;
Eric Anholt8c4a2c82011-12-20 11:25:20 -08003737
Eric Anholt193fa132011-12-20 11:36:07 -08003738 struct {
3739 uint32_t opcode;
Eric Anholt07768ba2011-12-20 13:46:23 -08003740 unsigned int min_len;
3741 unsigned int max_len;
Eric Anholt1db55a82011-12-20 12:00:28 -08003742 const char *name;
Eric Anholt193fa132011-12-20 11:36:07 -08003743 } opcodes_3d[] = {
Eric Anholtbbdda922011-12-20 11:44:36 -08003744 { 0x02, 1, 1, "3DSTATE_MODES_3" },
3745 { 0x03, 1, 1, "3DSTATE_ENABLES_1" },
3746 { 0x04, 1, 1, "3DSTATE_ENABLES_2" },
3747 { 0x05, 1, 1, "3DSTATE_VFT0" },
3748 { 0x06, 1, 1, "3DSTATE_AA" },
3749 { 0x07, 1, 1, "3DSTATE_RASTERIZATION_RULES" },
3750 { 0x08, 1, 1, "3DSTATE_MODES_1" },
3751 { 0x09, 1, 1, "3DSTATE_STENCIL_TEST" },
3752 { 0x0a, 1, 1, "3DSTATE_VFT1" },
3753 { 0x0b, 1, 1, "3DSTATE_INDPT_ALPHA_BLEND" },
3754 { 0x0c, 1, 1, "3DSTATE_MODES_5" },
3755 { 0x0d, 1, 1, "3DSTATE_MAP_BLEND_OP" },
3756 { 0x0e, 1, 1, "3DSTATE_MAP_BLEND_ARG" },
3757 { 0x0f, 1, 1, "3DSTATE_MODES_2" },
3758 { 0x15, 1, 1, "3DSTATE_FOG_COLOR" },
3759 { 0x16, 1, 1, "3DSTATE_MODES_4"},
3760 }, *opcode_3d;
Eric Anholt8c4a2c82011-12-20 11:25:20 -08003761
Eric Anholt193fa132011-12-20 11:36:07 -08003762 opcode = (data[0] & 0x1f000000) >> 24;
3763
3764 switch (opcode) {
3765 case 0x1f:
Eric Anholtde49fd42011-12-20 15:15:21 -08003766 return decode_3d_primitive(ctx);
Eric Anholt193fa132011-12-20 11:36:07 -08003767 case 0x1d:
Eric Anholtde49fd42011-12-20 15:15:21 -08003768 return decode_3d_1d(ctx);
Eric Anholt193fa132011-12-20 11:36:07 -08003769 case 0x1c:
Eric Anholtde49fd42011-12-20 15:15:21 -08003770 return decode_3d_1c(ctx);
Eric Anholt8c4a2c82011-12-20 11:25:20 -08003771 }
Eric Anholt8c4a2c82011-12-20 11:25:20 -08003772
Eric Anholt193fa132011-12-20 11:36:07 -08003773 for (idx = 0; idx < ARRAY_SIZE(opcodes_3d); idx++) {
3774 opcode_3d = &opcodes_3d[idx];
3775 if ((data[0] & 0x1f000000) >> 24 == opcode_3d->opcode) {
3776 unsigned int len = 1, i;
3777
Eric Anholtc1d29462011-12-20 15:29:03 -08003778 instr_out(ctx, 0, "%s\n", opcode_3d->name);
Eric Anholt193fa132011-12-20 11:36:07 -08003779 if (opcode_3d->max_len > 1) {
3780 len = (data[0] & 0xff) + 2;
3781 if (len < opcode_3d->min_len ||
3782 len > opcode_3d->max_len) {
3783 fprintf(out, "Bad count in %s\n",
3784 opcode_3d->name);
3785 }
3786 }
3787
3788 for (i = 1; i < len; i++) {
Eric Anholtc1d29462011-12-20 15:29:03 -08003789 instr_out(ctx, i, "dword %d\n", i);
Eric Anholt193fa132011-12-20 11:36:07 -08003790 }
3791 return len;
3792 }
3793 }
3794
Eric Anholtc1d29462011-12-20 15:29:03 -08003795 instr_out(ctx, 0, "3D UNKNOWN: 3d_i830 opcode = 0x%x\n",
Eric Anholt193fa132011-12-20 11:36:07 -08003796 opcode);
Eric Anholt193fa132011-12-20 11:36:07 -08003797 return 1;
Eric Anholt8c4a2c82011-12-20 11:25:20 -08003798}
3799
Eric Anholt71066ab2011-12-20 13:06:16 -08003800struct drm_intel_decode *
3801drm_intel_decode_context_alloc(uint32_t devid)
3802{
3803 struct drm_intel_decode *ctx;
3804
3805 ctx = calloc(1, sizeof(struct drm_intel_decode));
3806 if (!ctx)
3807 return NULL;
3808
3809 ctx->devid = devid;
Eric Anholtea33a232012-01-03 13:05:57 -08003810 ctx->out = stdout;
Eric Anholt71066ab2011-12-20 13:06:16 -08003811
Eric Anholt9695eee2012-01-04 12:00:59 -08003812 if (IS_GEN7(devid))
3813 ctx->gen = 7;
3814 else if (IS_GEN6(devid))
3815 ctx->gen = 6;
3816 else if (IS_GEN5(devid))
3817 ctx->gen = 5;
3818 else if (IS_GEN4(devid))
3819 ctx->gen = 4;
3820 else if (IS_9XX(devid))
3821 ctx->gen = 3;
3822 else {
3823 assert(IS_GEN2(devid));
3824 ctx->gen = 2;
3825 }
3826
Eric Anholt71066ab2011-12-20 13:06:16 -08003827 return ctx;
3828}
3829
3830void
3831drm_intel_decode_context_free(struct drm_intel_decode *ctx)
3832{
3833 free(ctx);
3834}
3835
3836void
3837drm_intel_decode_set_dump_past_end(struct drm_intel_decode *ctx,
3838 int dump_past_end)
3839{
3840 ctx->dump_past_end = !!dump_past_end;
3841}
3842
3843void
3844drm_intel_decode_set_batch_pointer(struct drm_intel_decode *ctx,
3845 void *data, uint32_t hw_offset, int count)
3846{
Eric Anholt8fb66a72011-12-20 14:59:38 -08003847 ctx->base_data = data;
3848 ctx->base_hw_offset = hw_offset;
3849 ctx->base_count = count;
Eric Anholt71066ab2011-12-20 13:06:16 -08003850}
3851
3852void
3853drm_intel_decode_set_head_tail(struct drm_intel_decode *ctx,
3854 uint32_t head, uint32_t tail)
3855{
3856 ctx->head = head;
3857 ctx->tail = tail;
3858}
3859
Eric Anholtea33a232012-01-03 13:05:57 -08003860void
3861drm_intel_decode_set_output_file(struct drm_intel_decode *ctx,
3862 FILE *out)
3863{
3864 ctx->out = out;
3865}
3866
Eric Anholt8c4a2c82011-12-20 11:25:20 -08003867/**
3868 * Decodes an i830-i915 batch buffer, writing the output to stdout.
3869 *
3870 * \param data batch buffer contents
3871 * \param count number of DWORDs to decode in the batch buffer
3872 * \param hw_offset hardware address for the buffer
3873 */
Eric Anholt71066ab2011-12-20 13:06:16 -08003874void
3875drm_intel_decode(struct drm_intel_decode *ctx)
Eric Anholt8c4a2c82011-12-20 11:25:20 -08003876{
Eric Anholt193fa132011-12-20 11:36:07 -08003877 int ret;
Eric Anholt07768ba2011-12-20 13:46:23 -08003878 unsigned int index = 0;
Eric Anholt71066ab2011-12-20 13:06:16 -08003879 uint32_t devid;
Eric Anholt028715e2012-01-04 12:31:40 -08003880 int size = ctx->base_count * 4;
3881 void *temp;
Eric Anholt71066ab2011-12-20 13:06:16 -08003882
3883 if (!ctx)
3884 return;
3885
Eric Anholt028715e2012-01-04 12:31:40 -08003886 /* Put a scratch page full of obviously undefined data after
3887 * the batchbuffer. This lets us avoid a bunch of length
3888 * checking in statically sized packets.
3889 */
3890 temp = malloc(size + 4096);
3891 memcpy(temp, ctx->base_data, size);
3892 memset((char *)temp + size, 0xd0, 4096);
3893 ctx->data = temp;
3894
Eric Anholt8fb66a72011-12-20 14:59:38 -08003895 ctx->hw_offset = ctx->base_hw_offset;
3896 ctx->count = ctx->base_count;
3897
Eric Anholt71066ab2011-12-20 13:06:16 -08003898 devid = ctx->devid;
3899 head_offset = ctx->head;
3900 tail_offset = ctx->tail;
Eric Anholtea33a232012-01-03 13:05:57 -08003901 out = ctx->out;
Eric Anholt71066ab2011-12-20 13:06:16 -08003902
3903 saved_s2_set = 0;
3904 saved_s4_set = 1;
Eric Anholt8c4a2c82011-12-20 11:25:20 -08003905
Eric Anholt8fb66a72011-12-20 14:59:38 -08003906 while (ctx->count > 0) {
3907 index = 0;
3908
3909 switch ((ctx->data[index] & 0xe0000000) >> 29) {
Eric Anholt193fa132011-12-20 11:36:07 -08003910 case 0x0:
Eric Anholtde49fd42011-12-20 15:15:21 -08003911 ret = decode_mi(ctx);
Eric Anholt8c4a2c82011-12-20 11:25:20 -08003912
Eric Anholtbbdda922011-12-20 11:44:36 -08003913 /* If MI_BATCHBUFFER_END happened, then dump
3914 * the rest of the output in case we some day
3915 * want it in debugging, but don't decode it
3916 * since it'll just confuse in the common
3917 * case.
Eric Anholt193fa132011-12-20 11:36:07 -08003918 */
3919 if (ret == -1) {
Eric Anholt71066ab2011-12-20 13:06:16 -08003920 if (ctx->dump_past_end) {
Eric Anholt193fa132011-12-20 11:36:07 -08003921 index++;
3922 } else {
Eric Anholt8fb66a72011-12-20 14:59:38 -08003923 for (index = index + 1; index < ctx->count;
Eric Anholt193fa132011-12-20 11:36:07 -08003924 index++) {
Eric Anholtc1d29462011-12-20 15:29:03 -08003925 instr_out(ctx, index, "\n");
Eric Anholt193fa132011-12-20 11:36:07 -08003926 }
3927 }
3928 } else
3929 index += ret;
3930 break;
3931 case 0x2:
Eric Anholtde49fd42011-12-20 15:15:21 -08003932 index += decode_2d(ctx);
Eric Anholt193fa132011-12-20 11:36:07 -08003933 break;
3934 case 0x3:
Eric Anholt71066ab2011-12-20 13:06:16 -08003935 if (IS_9XX(devid) && !IS_GEN3(devid)) {
Eric Anholt193fa132011-12-20 11:36:07 -08003936 index +=
Eric Anholtde49fd42011-12-20 15:15:21 -08003937 decode_3d_965(ctx);
Eric Anholt193fa132011-12-20 11:36:07 -08003938 } else if (IS_GEN3(devid)) {
Eric Anholtde49fd42011-12-20 15:15:21 -08003939 index += decode_3d(ctx);
Eric Anholt193fa132011-12-20 11:36:07 -08003940 } else {
3941 index +=
Eric Anholtde49fd42011-12-20 15:15:21 -08003942 decode_3d_i830(ctx);
Eric Anholt193fa132011-12-20 11:36:07 -08003943 }
3944 break;
3945 default:
Eric Anholtc1d29462011-12-20 15:29:03 -08003946 instr_out(ctx, index, "UNKNOWN\n");
Eric Anholt193fa132011-12-20 11:36:07 -08003947 index++;
3948 break;
Eric Anholt8c4a2c82011-12-20 11:25:20 -08003949 }
Eric Anholt193fa132011-12-20 11:36:07 -08003950 fflush(out);
Eric Anholt8fb66a72011-12-20 14:59:38 -08003951
3952 if (ctx->count < index)
3953 break;
3954
3955 ctx->count -= index;
3956 ctx->data += index;
3957 ctx->hw_offset += 4 * index;
Eric Anholt8c4a2c82011-12-20 11:25:20 -08003958 }
Eric Anholt028715e2012-01-04 12:31:40 -08003959
3960 free(temp);
Eric Anholt8c4a2c82011-12-20 11:25:20 -08003961}