1 /**************************************************************************
3 * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 **************************************************************************/
30 #include "i915_debug.h"
31 #include "pipe/p_winsys.h"
32 #include "pipe/p_util.h"
37 struct debug_stream
*stream
,
44 va_start( args
, fmt
);
45 vsprintf( buffer
, fmt
, args
);
46 stream
->winsys
->printf( stream
->winsys
, buffer
);
51 static const char *opcodes
[0x20] = {
87 static const int args
[0x20] = {
123 static const char *regname
[0x8] = {
135 print_reg_type_nr(struct debug_stream
*stream
, unsigned type
, unsigned nr
)
141 PRINTF(stream
, "T_DIFFUSE");
144 PRINTF(stream
, "T_SPECULAR");
147 PRINTF(stream
, "T_FOG_W");
150 PRINTF(stream
, "T_TEX%d", nr
);
155 PRINTF(stream
, "oC");
161 PRINTF(stream
, "oD");
169 PRINTF(stream
, "%s[%d]", regname
[type
], nr
);
172 #define REG_SWIZZLE_MASK 0x7777
173 #define REG_NEGATE_MASK 0x8888
175 #define REG_SWIZZLE_XYZW ((SRC_X << A2_SRC2_CHANNEL_X_SHIFT) | \
176 (SRC_Y << A2_SRC2_CHANNEL_Y_SHIFT) | \
177 (SRC_Z << A2_SRC2_CHANNEL_Z_SHIFT) | \
178 (SRC_W << A2_SRC2_CHANNEL_W_SHIFT))
182 print_reg_neg_swizzle(struct debug_stream
*stream
, unsigned reg
)
186 if ((reg
& REG_SWIZZLE_MASK
) == REG_SWIZZLE_XYZW
&&
187 (reg
& REG_NEGATE_MASK
) == 0)
192 for (i
= 3; i
>= 0; i
--) {
193 if (reg
& (1 << ((i
* 4) + 3)))
196 switch ((reg
>> (i
* 4)) & 0x7) {
224 print_src_reg(struct debug_stream
*stream
, unsigned dword
)
226 unsigned nr
= (dword
>> A2_SRC2_NR_SHIFT
) & REG_NR_MASK
;
227 unsigned type
= (dword
>> A2_SRC2_TYPE_SHIFT
) & REG_TYPE_MASK
;
228 print_reg_type_nr(stream
, type
, nr
);
229 print_reg_neg_swizzle(stream
, dword
);
234 print_dest_reg(struct debug_stream
*stream
, unsigned dword
)
236 unsigned nr
= (dword
>> A0_DEST_NR_SHIFT
) & REG_NR_MASK
;
237 unsigned type
= (dword
>> A0_DEST_TYPE_SHIFT
) & REG_TYPE_MASK
;
238 print_reg_type_nr(stream
, type
, nr
);
239 if ((dword
& A0_DEST_CHANNEL_ALL
) == A0_DEST_CHANNEL_ALL
)
242 if (dword
& A0_DEST_CHANNEL_X
)
244 if (dword
& A0_DEST_CHANNEL_Y
)
246 if (dword
& A0_DEST_CHANNEL_Z
)
248 if (dword
& A0_DEST_CHANNEL_W
)
253 #define GET_SRC0_REG(r0, r1) ((r0<<14)|(r1>>A1_SRC0_CHANNEL_W_SHIFT))
254 #define GET_SRC1_REG(r0, r1) ((r0<<8)|(r1>>A2_SRC1_CHANNEL_W_SHIFT))
255 #define GET_SRC2_REG(r) (r)
259 print_arith_op(struct debug_stream
*stream
,
260 unsigned opcode
, const unsigned * program
)
262 if (opcode
!= A0_NOP
) {
263 print_dest_reg(stream
, program
[0]);
264 if (program
[0] & A0_DEST_SATURATE
)
265 PRINTF(stream
, " = SATURATE ");
267 PRINTF(stream
, " = ");
270 PRINTF(stream
, "%s ", opcodes
[opcode
]);
272 print_src_reg(stream
, GET_SRC0_REG(program
[0], program
[1]));
273 if (args
[opcode
] == 1) {
274 PRINTF(stream
, "\n");
278 PRINTF(stream
, ", ");
279 print_src_reg(stream
, GET_SRC1_REG(program
[1], program
[2]));
280 if (args
[opcode
] == 2) {
281 PRINTF(stream
, "\n");
285 PRINTF(stream
, ", ");
286 print_src_reg(stream
, GET_SRC2_REG(program
[2]));
287 PRINTF(stream
, "\n");
293 print_tex_op(struct debug_stream
*stream
,
294 unsigned opcode
, const unsigned * program
)
296 print_dest_reg(stream
, program
[0] | A0_DEST_CHANNEL_ALL
);
297 PRINTF(stream
, " = ");
299 PRINTF(stream
, "%s ", opcodes
[opcode
]);
301 PRINTF(stream
, "S[%d],", program
[0] & T0_SAMPLER_NR_MASK
);
303 print_reg_type_nr(stream
,
304 (program
[1] >> T1_ADDRESS_REG_TYPE_SHIFT
) &
306 (program
[1] >> T1_ADDRESS_REG_NR_SHIFT
) & REG_NR_MASK
);
307 PRINTF(stream
, "\n");
311 print_texkil_op(struct debug_stream
*stream
,
312 unsigned opcode
, const unsigned * program
)
314 PRINTF(stream
, "TEXKIL ");
316 print_reg_type_nr(stream
,
317 (program
[1] >> T1_ADDRESS_REG_TYPE_SHIFT
) &
319 (program
[1] >> T1_ADDRESS_REG_NR_SHIFT
) & REG_NR_MASK
);
320 PRINTF(stream
, "\n");
324 print_dcl_op(struct debug_stream
*stream
,
325 unsigned opcode
, const unsigned * program
)
327 PRINTF(stream
, "%s ", opcodes
[opcode
]);
328 print_dest_reg(stream
,
329 program
[0] | A0_DEST_CHANNEL_ALL
);
330 PRINTF(stream
, "\n");
335 i915_disassemble_program(struct debug_stream
*stream
,
336 const unsigned * program
, unsigned sz
)
338 unsigned size
= program
[0] & 0x1ff;
341 PRINTF(stream
, "\t\tBEGIN\n");
343 assert(size
+ 2 == sz
);
346 for (i
= 1; i
< sz
; i
+= 3, program
+= 3) {
347 unsigned opcode
= program
[0] & (0x1f << 24);
349 PRINTF(stream
, "\t\t");
351 if ((int) opcode
>= A0_NOP
&& opcode
<= A0_SLT
)
352 print_arith_op(stream
, opcode
>> 24, program
);
353 else if (opcode
>= T0_TEXLD
&& opcode
< T0_TEXKILL
)
354 print_tex_op(stream
, opcode
>> 24, program
);
355 else if (opcode
== T0_TEXKILL
)
356 print_texkil_op(stream
, opcode
>> 24, program
);
357 else if (opcode
== D0_DCL
)
358 print_dcl_op(stream
, opcode
>> 24, program
);
360 PRINTF(stream
, "Unknown opcode 0x%x\n", opcode
);
363 PRINTF(stream
, "\t\tEND\n\n");