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 "util/u_debug.h"
29 #include "util/u_string.h"
30 #include "util/u_math.h"
31 #include "tgsi_dump.h"
32 #include "tgsi_info.h"
33 #include "tgsi_iterate.h"
37 struct tgsi_iterate_context iter
;
41 void (*printf
)(struct dump_ctx
*ctx
, const char *format
, ...);
45 dump_ctx_printf(struct dump_ctx
*ctx
, const char *format
, ...)
50 debug_vprintf(format
, ap
);
62 ctx
->printf( ctx
, "%u", e
);
64 ctx
->printf( ctx
, "%s", enums
[e
] );
67 #define EOL() ctx->printf( ctx, "\n" )
68 #define TXT(S) ctx->printf( ctx, "%s", S )
69 #define CHR(C) ctx->printf( ctx, "%c", C )
70 #define UIX(I) ctx->printf( ctx, "0x%x", I )
71 #define UID(I) ctx->printf( ctx, "%u", I )
72 #define INSTID(I) ctx->printf( ctx, "% 3u", I )
73 #define SID(I) ctx->printf( ctx, "%d", I )
74 #define FLT(F) ctx->printf( ctx, "%10.4f", F )
75 #define ENM(E,ENUMS) dump_enum( ctx, E, ENUMS, sizeof( ENUMS ) / sizeof( *ENUMS ) )
77 static const char *processor_type_names
[] =
84 static const char *file_names
[] =
96 static const char *interpolate_names
[] =
103 static const char *semantic_names
[] =
114 static const char *immediate_type_names
[] =
119 static const char *swizzle_names
[] =
127 static const char *texture_names
[] =
140 static const char *extswizzle_names
[] =
150 static const char *modulate_names
[TGSI_MODULATE_COUNT
] =
163 struct dump_ctx
*ctx
,
168 ENM( file
, file_names
);
180 struct dump_ctx
*ctx
,
187 ENM( file
, file_names
);
189 ENM( ind_file
, file_names
);
193 ENM( ind_swizzle
, swizzle_names
);
204 struct dump_ctx
*ctx
,
207 if (writemask
!= TGSI_WRITEMASK_XYZW
) {
209 if (writemask
& TGSI_WRITEMASK_X
)
211 if (writemask
& TGSI_WRITEMASK_Y
)
213 if (writemask
& TGSI_WRITEMASK_Z
)
215 if (writemask
& TGSI_WRITEMASK_W
)
222 struct tgsi_iterate_context
*iter
,
223 struct tgsi_full_declaration
*decl
)
225 struct dump_ctx
*ctx
= (struct dump_ctx
*)iter
;
231 decl
->Declaration
.File
,
232 decl
->DeclarationRange
.First
,
233 decl
->DeclarationRange
.Last
);
236 decl
->Declaration
.UsageMask
);
238 if (decl
->Declaration
.Semantic
) {
240 ENM( decl
->Semantic
.SemanticName
, semantic_names
);
241 if (decl
->Semantic
.SemanticIndex
!= 0 ||
242 decl
->Semantic
.SemanticName
== TGSI_SEMANTIC_GENERIC
) {
244 UID( decl
->Semantic
.SemanticIndex
);
249 if (iter
->processor
.Processor
== TGSI_PROCESSOR_FRAGMENT
&&
250 decl
->Declaration
.File
== TGSI_FILE_INPUT
)
253 ENM( decl
->Declaration
.Interpolate
, interpolate_names
);
256 if (decl
->Declaration
.Centroid
) {
260 if (decl
->Declaration
.Invariant
) {
261 TXT( ", INVARIANT" );
270 tgsi_dump_declaration(
271 const struct tgsi_full_declaration
*decl
)
275 ctx
.printf
= dump_ctx_printf
;
277 iter_declaration( &ctx
.iter
, (struct tgsi_full_declaration
*)decl
);
282 struct tgsi_iterate_context
*iter
,
283 struct tgsi_full_immediate
*imm
)
285 struct dump_ctx
*ctx
= (struct dump_ctx
*) iter
;
290 ENM( imm
->Immediate
.DataType
, immediate_type_names
);
293 for (i
= 0; i
< imm
->Immediate
.NrTokens
- 1; i
++) {
294 switch (imm
->Immediate
.DataType
) {
295 case TGSI_IMM_FLOAT32
:
296 FLT( imm
->u
.ImmediateFloat32
[i
].Float
);
302 if (i
< imm
->Immediate
.NrTokens
- 2)
314 const struct tgsi_full_immediate
*imm
)
318 ctx
.printf
= dump_ctx_printf
;
320 iter_immediate( &ctx
.iter
, (struct tgsi_full_immediate
*)imm
);
325 struct tgsi_iterate_context
*iter
,
326 struct tgsi_full_instruction
*inst
)
328 struct dump_ctx
*ctx
= (struct dump_ctx
*) iter
;
329 uint instno
= ctx
->instno
++;
332 boolean first_reg
= TRUE
;
336 TXT( tgsi_get_opcode_info( inst
->Instruction
.Opcode
)->mnemonic
);
338 switch (inst
->Instruction
.Saturate
) {
341 case TGSI_SAT_ZERO_ONE
:
344 case TGSI_SAT_MINUS_PLUS_ONE
:
351 for (i
= 0; i
< inst
->Instruction
.NumDstRegs
; i
++) {
352 const struct tgsi_full_dst_register
*dst
= &inst
->FullDstRegisters
[i
];
360 dst
->DstRegister
.File
,
361 dst
->DstRegister
.Index
,
362 dst
->DstRegister
.Index
);
363 ENM( dst
->DstRegisterExtModulate
.Modulate
, modulate_names
);
364 _dump_writemask( ctx
, dst
->DstRegister
.WriteMask
);
369 for (i
= 0; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
370 const struct tgsi_full_src_register
*src
= &inst
->FullSrcRegisters
[i
];
376 if (src
->SrcRegisterExtMod
.Negate
)
378 if (src
->SrcRegisterExtMod
.Absolute
)
380 if (src
->SrcRegisterExtMod
.Scale2X
)
382 if (src
->SrcRegisterExtMod
.Bias
)
384 if (src
->SrcRegisterExtMod
.Complement
)
386 if (src
->SrcRegister
.Negate
)
389 if (src
->SrcRegister
.Indirect
) {
392 src
->SrcRegister
.File
,
393 src
->SrcRegister
.Index
,
394 src
->SrcRegisterInd
.File
,
395 src
->SrcRegisterInd
.Index
,
396 src
->SrcRegisterInd
.SwizzleX
);
401 src
->SrcRegister
.File
,
402 src
->SrcRegister
.Index
,
403 src
->SrcRegister
.Index
);
406 if (src
->SrcRegister
.SwizzleX
!= TGSI_SWIZZLE_X
||
407 src
->SrcRegister
.SwizzleY
!= TGSI_SWIZZLE_Y
||
408 src
->SrcRegister
.SwizzleZ
!= TGSI_SWIZZLE_Z
||
409 src
->SrcRegister
.SwizzleW
!= TGSI_SWIZZLE_W
) {
411 ENM( src
->SrcRegister
.SwizzleX
, swizzle_names
);
412 ENM( src
->SrcRegister
.SwizzleY
, swizzle_names
);
413 ENM( src
->SrcRegister
.SwizzleZ
, swizzle_names
);
414 ENM( src
->SrcRegister
.SwizzleW
, swizzle_names
);
416 if (src
->SrcRegisterExtSwz
.ExtSwizzleX
!= TGSI_EXTSWIZZLE_X
||
417 src
->SrcRegisterExtSwz
.ExtSwizzleY
!= TGSI_EXTSWIZZLE_Y
||
418 src
->SrcRegisterExtSwz
.ExtSwizzleZ
!= TGSI_EXTSWIZZLE_Z
||
419 src
->SrcRegisterExtSwz
.ExtSwizzleW
!= TGSI_EXTSWIZZLE_W
) {
421 if (src
->SrcRegisterExtSwz
.NegateX
)
423 ENM( src
->SrcRegisterExtSwz
.ExtSwizzleX
, extswizzle_names
);
424 if (src
->SrcRegisterExtSwz
.NegateY
)
426 ENM( src
->SrcRegisterExtSwz
.ExtSwizzleY
, extswizzle_names
);
427 if (src
->SrcRegisterExtSwz
.NegateZ
)
429 ENM( src
->SrcRegisterExtSwz
.ExtSwizzleZ
, extswizzle_names
);
430 if (src
->SrcRegisterExtSwz
.NegateW
)
432 ENM( src
->SrcRegisterExtSwz
.ExtSwizzleW
, extswizzle_names
);
435 if (src
->SrcRegisterExtMod
.Complement
)
437 if (src
->SrcRegisterExtMod
.Bias
)
439 if (src
->SrcRegisterExtMod
.Scale2X
)
441 if (src
->SrcRegisterExtMod
.Absolute
)
443 if (src
->SrcRegisterExtMod
.Negate
)
449 if (inst
->InstructionExtTexture
.Texture
!= TGSI_TEXTURE_UNKNOWN
) {
451 ENM( inst
->InstructionExtTexture
.Texture
, texture_names
);
454 switch (inst
->Instruction
.Opcode
) {
456 case TGSI_OPCODE_ELSE
:
457 case TGSI_OPCODE_BGNLOOP2
:
458 case TGSI_OPCODE_ENDLOOP2
:
459 case TGSI_OPCODE_CAL
:
461 UID( inst
->InstructionExtLabel
.Label
);
471 tgsi_dump_instruction(
472 const struct tgsi_full_instruction
*inst
,
478 ctx
.printf
= dump_ctx_printf
;
480 iter_instruction( &ctx
.iter
, (struct tgsi_full_instruction
*)inst
);
485 struct tgsi_iterate_context
*iter
)
487 struct dump_ctx
*ctx
= (struct dump_ctx
*) iter
;
488 ENM( iter
->processor
.Processor
, processor_type_names
);
489 UID( iter
->version
.MajorVersion
);
491 UID( iter
->version
.MinorVersion
);
498 const struct tgsi_token
*tokens
,
503 ctx
.iter
.prolog
= prolog
;
504 ctx
.iter
.iterate_instruction
= iter_instruction
;
505 ctx
.iter
.iterate_declaration
= iter_declaration
;
506 ctx
.iter
.iterate_immediate
= iter_immediate
;
507 ctx
.iter
.epilog
= NULL
;
510 ctx
.printf
= dump_ctx_printf
;
512 tgsi_iterate_shader( tokens
, &ctx
.iter
);
517 struct dump_ctx base
;
524 str_dump_ctx_printf(struct dump_ctx
*ctx
, const char *format
, ...)
526 struct str_dump_ctx
*sctx
= (struct str_dump_ctx
*)ctx
;
531 va_start(ap
, format
);
532 written
= util_vsnprintf(sctx
->ptr
, sctx
->left
, format
, ap
);
535 /* Some complicated logic needed to handle the return value of
539 written
= MIN2(sctx
->left
, written
);
540 sctx
->ptr
+= written
;
541 sctx
->left
-= written
;
548 const struct tgsi_token
*tokens
,
553 struct str_dump_ctx ctx
;
555 ctx
.base
.iter
.prolog
= prolog
;
556 ctx
.base
.iter
.iterate_instruction
= iter_instruction
;
557 ctx
.base
.iter
.iterate_declaration
= iter_declaration
;
558 ctx
.base
.iter
.iterate_immediate
= iter_immediate
;
559 ctx
.base
.iter
.epilog
= NULL
;
562 ctx
.base
.printf
= &str_dump_ctx_printf
;
567 ctx
.left
= (int)size
;
569 tgsi_iterate_shader( tokens
, &ctx
.base
.iter
);