1 /**************************************************************************
3 * Copyright 2007-2008 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 **************************************************************************/
28 #include "pipe/p_debug.h"
29 #include "util/u_string.h"
30 #include "tgsi_dump.h"
31 #include "tgsi_info.h"
32 #include "tgsi_iterate.h"
36 struct tgsi_iterate_context iter
;
40 void (*printf
)(struct dump_ctx
*ctx
, const char *format
, ...);
44 dump_ctx_printf(struct dump_ctx
*ctx
, const char *format
, ...)
49 debug_vprintf(format
, ap
);
61 ctx
->printf( ctx
, "%u", e
);
63 ctx
->printf( ctx
, "%s", enums
[e
] );
66 #define EOL() ctx->printf( ctx, "\n" )
67 #define TXT(S) ctx->printf( ctx, "%s", S )
68 #define CHR(C) ctx->printf( ctx, "%c", C )
69 #define UIX(I) ctx->printf( ctx, "0x%x", I )
70 #define UID(I) ctx->printf( ctx, "%u", I )
71 #define INSTID(I) ctx->printf( ctx, "% 3u", I )
72 #define SID(I) ctx->printf( ctx, "%d", I )
73 #define FLT(F) ctx->printf( ctx, "%10.4f", F )
74 #define ENM(E,ENUMS) dump_enum( ctx, E, ENUMS, sizeof( ENUMS ) / sizeof( *ENUMS ) )
76 static const char *processor_type_names
[] =
83 static const char *file_names
[] =
95 static const char *interpolate_names
[] =
102 static const char *semantic_names
[] =
113 static const char *immediate_type_names
[] =
118 static const char *swizzle_names
[] =
126 static const char *texture_names
[] =
139 static const char *extswizzle_names
[] =
149 static const char *modulate_names
[TGSI_MODULATE_COUNT
] =
162 struct dump_ctx
*ctx
,
167 ENM( file
, file_names
);
179 struct dump_ctx
*ctx
,
185 ENM( file
, file_names
);
187 ENM( ind_file
, file_names
);
201 struct dump_ctx
*ctx
,
204 if (writemask
!= TGSI_WRITEMASK_XYZW
) {
206 if (writemask
& TGSI_WRITEMASK_X
)
208 if (writemask
& TGSI_WRITEMASK_Y
)
210 if (writemask
& TGSI_WRITEMASK_Z
)
212 if (writemask
& TGSI_WRITEMASK_W
)
219 struct tgsi_iterate_context
*iter
,
220 struct tgsi_full_declaration
*decl
)
222 struct dump_ctx
*ctx
= (struct dump_ctx
*)iter
;
228 decl
->Declaration
.File
,
229 decl
->DeclarationRange
.First
,
230 decl
->DeclarationRange
.Last
);
233 decl
->Declaration
.UsageMask
);
235 if (decl
->Declaration
.Semantic
) {
237 ENM( decl
->Semantic
.SemanticName
, semantic_names
);
238 if (decl
->Semantic
.SemanticIndex
!= 0 ||
239 decl
->Semantic
.SemanticName
== TGSI_SEMANTIC_GENERIC
) {
241 UID( decl
->Semantic
.SemanticIndex
);
247 ENM( decl
->Declaration
.Interpolate
, interpolate_names
);
255 tgsi_dump_declaration(
256 const struct tgsi_full_declaration
*decl
)
260 ctx
.printf
= dump_ctx_printf
;
262 iter_declaration( &ctx
.iter
, (struct tgsi_full_declaration
*)decl
);
267 struct tgsi_iterate_context
*iter
,
268 struct tgsi_full_immediate
*imm
)
270 struct dump_ctx
*ctx
= (struct dump_ctx
*) iter
;
275 ENM( imm
->Immediate
.DataType
, immediate_type_names
);
278 for (i
= 0; i
< imm
->Immediate
.Size
- 1; i
++) {
279 switch (imm
->Immediate
.DataType
) {
280 case TGSI_IMM_FLOAT32
:
281 FLT( imm
->u
.ImmediateFloat32
[i
].Float
);
287 if (i
< imm
->Immediate
.Size
- 2)
299 const struct tgsi_full_immediate
*imm
)
303 ctx
.printf
= dump_ctx_printf
;
305 iter_immediate( &ctx
.iter
, (struct tgsi_full_immediate
*)imm
);
310 struct tgsi_iterate_context
*iter
,
311 struct tgsi_full_instruction
*inst
)
313 struct dump_ctx
*ctx
= (struct dump_ctx
*) iter
;
314 uint instno
= ctx
->instno
++;
317 boolean first_reg
= TRUE
;
321 TXT( tgsi_get_opcode_info( inst
->Instruction
.Opcode
)->mnemonic
);
323 switch (inst
->Instruction
.Saturate
) {
326 case TGSI_SAT_ZERO_ONE
:
329 case TGSI_SAT_MINUS_PLUS_ONE
:
336 for (i
= 0; i
< inst
->Instruction
.NumDstRegs
; i
++) {
337 const struct tgsi_full_dst_register
*dst
= &inst
->FullDstRegisters
[i
];
345 dst
->DstRegister
.File
,
346 dst
->DstRegister
.Index
,
347 dst
->DstRegister
.Index
);
348 ENM( dst
->DstRegisterExtModulate
.Modulate
, modulate_names
);
349 _dump_writemask( ctx
, dst
->DstRegister
.WriteMask
);
354 for (i
= 0; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
355 const struct tgsi_full_src_register
*src
= &inst
->FullSrcRegisters
[i
];
361 if (src
->SrcRegisterExtMod
.Negate
)
363 if (src
->SrcRegisterExtMod
.Absolute
)
365 if (src
->SrcRegisterExtMod
.Scale2X
)
367 if (src
->SrcRegisterExtMod
.Bias
)
369 if (src
->SrcRegisterExtMod
.Complement
)
371 if (src
->SrcRegister
.Negate
)
374 if (src
->SrcRegister
.Indirect
) {
377 src
->SrcRegister
.File
,
378 src
->SrcRegister
.Index
,
379 src
->SrcRegisterInd
.File
,
380 src
->SrcRegisterInd
.Index
);
385 src
->SrcRegister
.File
,
386 src
->SrcRegister
.Index
,
387 src
->SrcRegister
.Index
);
390 if (src
->SrcRegister
.SwizzleX
!= TGSI_SWIZZLE_X
||
391 src
->SrcRegister
.SwizzleY
!= TGSI_SWIZZLE_Y
||
392 src
->SrcRegister
.SwizzleZ
!= TGSI_SWIZZLE_Z
||
393 src
->SrcRegister
.SwizzleW
!= TGSI_SWIZZLE_W
) {
395 ENM( src
->SrcRegister
.SwizzleX
, swizzle_names
);
396 ENM( src
->SrcRegister
.SwizzleY
, swizzle_names
);
397 ENM( src
->SrcRegister
.SwizzleZ
, swizzle_names
);
398 ENM( src
->SrcRegister
.SwizzleW
, swizzle_names
);
400 if (src
->SrcRegisterExtSwz
.ExtSwizzleX
!= TGSI_EXTSWIZZLE_X
||
401 src
->SrcRegisterExtSwz
.ExtSwizzleY
!= TGSI_EXTSWIZZLE_Y
||
402 src
->SrcRegisterExtSwz
.ExtSwizzleZ
!= TGSI_EXTSWIZZLE_Z
||
403 src
->SrcRegisterExtSwz
.ExtSwizzleW
!= TGSI_EXTSWIZZLE_W
) {
405 if (src
->SrcRegisterExtSwz
.NegateX
)
407 ENM( src
->SrcRegisterExtSwz
.ExtSwizzleX
, extswizzle_names
);
408 if (src
->SrcRegisterExtSwz
.NegateY
)
410 ENM( src
->SrcRegisterExtSwz
.ExtSwizzleY
, extswizzle_names
);
411 if (src
->SrcRegisterExtSwz
.NegateZ
)
413 ENM( src
->SrcRegisterExtSwz
.ExtSwizzleZ
, extswizzle_names
);
414 if (src
->SrcRegisterExtSwz
.NegateW
)
416 ENM( src
->SrcRegisterExtSwz
.ExtSwizzleW
, extswizzle_names
);
419 if (src
->SrcRegisterExtMod
.Complement
)
421 if (src
->SrcRegisterExtMod
.Bias
)
423 if (src
->SrcRegisterExtMod
.Scale2X
)
425 if (src
->SrcRegisterExtMod
.Absolute
)
427 if (src
->SrcRegisterExtMod
.Negate
)
433 if (inst
->InstructionExtTexture
.Texture
!= TGSI_TEXTURE_UNKNOWN
) {
435 ENM( inst
->InstructionExtTexture
.Texture
, texture_names
);
438 switch (inst
->Instruction
.Opcode
) {
440 case TGSI_OPCODE_ELSE
:
441 case TGSI_OPCODE_BGNLOOP2
:
442 case TGSI_OPCODE_ENDLOOP2
:
443 case TGSI_OPCODE_CAL
:
445 UID( inst
->InstructionExtLabel
.Label
);
455 tgsi_dump_instruction(
456 const struct tgsi_full_instruction
*inst
,
462 ctx
.printf
= dump_ctx_printf
;
464 iter_instruction( &ctx
.iter
, (struct tgsi_full_instruction
*)inst
);
469 struct tgsi_iterate_context
*iter
)
471 struct dump_ctx
*ctx
= (struct dump_ctx
*) iter
;
472 ENM( iter
->processor
.Processor
, processor_type_names
);
473 UID( iter
->version
.MajorVersion
);
475 UID( iter
->version
.MinorVersion
);
482 const struct tgsi_token
*tokens
,
487 ctx
.iter
.prolog
= prolog
;
488 ctx
.iter
.iterate_instruction
= iter_instruction
;
489 ctx
.iter
.iterate_declaration
= iter_declaration
;
490 ctx
.iter
.iterate_immediate
= iter_immediate
;
491 ctx
.iter
.epilog
= NULL
;
494 ctx
.printf
= dump_ctx_printf
;
496 tgsi_iterate_shader( tokens
, &ctx
.iter
);
501 struct dump_ctx base
;
508 str_dump_ctx_printf(struct dump_ctx
*ctx
, const char *format
, ...)
510 struct str_dump_ctx
*sctx
= (struct str_dump_ctx
*)ctx
;
515 va_start(ap
, format
);
516 written
= util_vsnprintf(sctx
->ptr
, sctx
->left
, format
, ap
);
518 sctx
->ptr
+= written
;
519 sctx
->left
-= written
;
525 const struct tgsi_token
*tokens
,
530 struct str_dump_ctx ctx
;
532 ctx
.base
.iter
.prolog
= prolog
;
533 ctx
.base
.iter
.iterate_instruction
= iter_instruction
;
534 ctx
.base
.iter
.iterate_declaration
= iter_declaration
;
535 ctx
.base
.iter
.iterate_immediate
= iter_immediate
;
536 ctx
.base
.iter
.epilog
= NULL
;
539 ctx
.base
.printf
= &str_dump_ctx_printf
;
546 tgsi_iterate_shader( tokens
, &ctx
.base
.iter
);