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
,
186 ENM( file
, file_names
);
188 ENM( ind_file
, file_names
);
192 ENM( ind_swizzle
, swizzle_names
);
203 struct dump_ctx
*ctx
,
206 if (writemask
!= TGSI_WRITEMASK_XYZW
) {
208 if (writemask
& TGSI_WRITEMASK_X
)
210 if (writemask
& TGSI_WRITEMASK_Y
)
212 if (writemask
& TGSI_WRITEMASK_Z
)
214 if (writemask
& TGSI_WRITEMASK_W
)
221 struct tgsi_iterate_context
*iter
,
222 struct tgsi_full_declaration
*decl
)
224 struct dump_ctx
*ctx
= (struct dump_ctx
*)iter
;
230 decl
->Declaration
.File
,
231 decl
->DeclarationRange
.First
,
232 decl
->DeclarationRange
.Last
);
235 decl
->Declaration
.UsageMask
);
237 if (decl
->Declaration
.Semantic
) {
239 ENM( decl
->Semantic
.SemanticName
, semantic_names
);
240 if (decl
->Semantic
.SemanticIndex
!= 0 ||
241 decl
->Semantic
.SemanticName
== TGSI_SEMANTIC_GENERIC
) {
243 UID( decl
->Semantic
.SemanticIndex
);
249 ENM( decl
->Declaration
.Interpolate
, interpolate_names
);
251 if (decl
->Declaration
.Centroid
) {
255 if (decl
->Declaration
.Invariant
) {
256 TXT( ", INVARIANT" );
265 tgsi_dump_declaration(
266 const struct tgsi_full_declaration
*decl
)
270 ctx
.printf
= dump_ctx_printf
;
272 iter_declaration( &ctx
.iter
, (struct tgsi_full_declaration
*)decl
);
277 struct tgsi_iterate_context
*iter
,
278 struct tgsi_full_immediate
*imm
)
280 struct dump_ctx
*ctx
= (struct dump_ctx
*) iter
;
285 ENM( imm
->Immediate
.DataType
, immediate_type_names
);
288 for (i
= 0; i
< imm
->Immediate
.Size
- 1; i
++) {
289 switch (imm
->Immediate
.DataType
) {
290 case TGSI_IMM_FLOAT32
:
291 FLT( imm
->u
.ImmediateFloat32
[i
].Float
);
297 if (i
< imm
->Immediate
.Size
- 2)
309 const struct tgsi_full_immediate
*imm
)
313 ctx
.printf
= dump_ctx_printf
;
315 iter_immediate( &ctx
.iter
, (struct tgsi_full_immediate
*)imm
);
320 struct tgsi_iterate_context
*iter
,
321 struct tgsi_full_instruction
*inst
)
323 struct dump_ctx
*ctx
= (struct dump_ctx
*) iter
;
324 uint instno
= ctx
->instno
++;
327 boolean first_reg
= TRUE
;
331 TXT( tgsi_get_opcode_info( inst
->Instruction
.Opcode
)->mnemonic
);
333 switch (inst
->Instruction
.Saturate
) {
336 case TGSI_SAT_ZERO_ONE
:
339 case TGSI_SAT_MINUS_PLUS_ONE
:
346 for (i
= 0; i
< inst
->Instruction
.NumDstRegs
; i
++) {
347 const struct tgsi_full_dst_register
*dst
= &inst
->FullDstRegisters
[i
];
355 dst
->DstRegister
.File
,
356 dst
->DstRegister
.Index
,
357 dst
->DstRegister
.Index
);
358 ENM( dst
->DstRegisterExtModulate
.Modulate
, modulate_names
);
359 _dump_writemask( ctx
, dst
->DstRegister
.WriteMask
);
364 for (i
= 0; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
365 const struct tgsi_full_src_register
*src
= &inst
->FullSrcRegisters
[i
];
371 if (src
->SrcRegisterExtMod
.Negate
)
373 if (src
->SrcRegisterExtMod
.Absolute
)
375 if (src
->SrcRegisterExtMod
.Scale2X
)
377 if (src
->SrcRegisterExtMod
.Bias
)
379 if (src
->SrcRegisterExtMod
.Complement
)
381 if (src
->SrcRegister
.Negate
)
384 if (src
->SrcRegister
.Indirect
) {
387 src
->SrcRegister
.File
,
388 src
->SrcRegister
.Index
,
389 src
->SrcRegisterInd
.File
,
390 src
->SrcRegisterInd
.Index
,
391 src
->SrcRegisterInd
.SwizzleX
);
396 src
->SrcRegister
.File
,
397 src
->SrcRegister
.Index
,
398 src
->SrcRegister
.Index
);
401 if (src
->SrcRegister
.SwizzleX
!= TGSI_SWIZZLE_X
||
402 src
->SrcRegister
.SwizzleY
!= TGSI_SWIZZLE_Y
||
403 src
->SrcRegister
.SwizzleZ
!= TGSI_SWIZZLE_Z
||
404 src
->SrcRegister
.SwizzleW
!= TGSI_SWIZZLE_W
) {
406 ENM( src
->SrcRegister
.SwizzleX
, swizzle_names
);
407 ENM( src
->SrcRegister
.SwizzleY
, swizzle_names
);
408 ENM( src
->SrcRegister
.SwizzleZ
, swizzle_names
);
409 ENM( src
->SrcRegister
.SwizzleW
, swizzle_names
);
411 if (src
->SrcRegisterExtSwz
.ExtSwizzleX
!= TGSI_EXTSWIZZLE_X
||
412 src
->SrcRegisterExtSwz
.ExtSwizzleY
!= TGSI_EXTSWIZZLE_Y
||
413 src
->SrcRegisterExtSwz
.ExtSwizzleZ
!= TGSI_EXTSWIZZLE_Z
||
414 src
->SrcRegisterExtSwz
.ExtSwizzleW
!= TGSI_EXTSWIZZLE_W
) {
416 if (src
->SrcRegisterExtSwz
.NegateX
)
418 ENM( src
->SrcRegisterExtSwz
.ExtSwizzleX
, extswizzle_names
);
419 if (src
->SrcRegisterExtSwz
.NegateY
)
421 ENM( src
->SrcRegisterExtSwz
.ExtSwizzleY
, extswizzle_names
);
422 if (src
->SrcRegisterExtSwz
.NegateZ
)
424 ENM( src
->SrcRegisterExtSwz
.ExtSwizzleZ
, extswizzle_names
);
425 if (src
->SrcRegisterExtSwz
.NegateW
)
427 ENM( src
->SrcRegisterExtSwz
.ExtSwizzleW
, extswizzle_names
);
430 if (src
->SrcRegisterExtMod
.Complement
)
432 if (src
->SrcRegisterExtMod
.Bias
)
434 if (src
->SrcRegisterExtMod
.Scale2X
)
436 if (src
->SrcRegisterExtMod
.Absolute
)
438 if (src
->SrcRegisterExtMod
.Negate
)
444 if (inst
->InstructionExtTexture
.Texture
!= TGSI_TEXTURE_UNKNOWN
) {
446 ENM( inst
->InstructionExtTexture
.Texture
, texture_names
);
449 switch (inst
->Instruction
.Opcode
) {
451 case TGSI_OPCODE_ELSE
:
452 case TGSI_OPCODE_BGNLOOP2
:
453 case TGSI_OPCODE_ENDLOOP2
:
454 case TGSI_OPCODE_CAL
:
456 UID( inst
->InstructionExtLabel
.Label
);
466 tgsi_dump_instruction(
467 const struct tgsi_full_instruction
*inst
,
473 ctx
.printf
= dump_ctx_printf
;
475 iter_instruction( &ctx
.iter
, (struct tgsi_full_instruction
*)inst
);
480 struct tgsi_iterate_context
*iter
)
482 struct dump_ctx
*ctx
= (struct dump_ctx
*) iter
;
483 ENM( iter
->processor
.Processor
, processor_type_names
);
484 UID( iter
->version
.MajorVersion
);
486 UID( iter
->version
.MinorVersion
);
493 const struct tgsi_token
*tokens
,
498 ctx
.iter
.prolog
= prolog
;
499 ctx
.iter
.iterate_instruction
= iter_instruction
;
500 ctx
.iter
.iterate_declaration
= iter_declaration
;
501 ctx
.iter
.iterate_immediate
= iter_immediate
;
502 ctx
.iter
.epilog
= NULL
;
505 ctx
.printf
= dump_ctx_printf
;
507 tgsi_iterate_shader( tokens
, &ctx
.iter
);
512 struct dump_ctx base
;
519 str_dump_ctx_printf(struct dump_ctx
*ctx
, const char *format
, ...)
521 struct str_dump_ctx
*sctx
= (struct str_dump_ctx
*)ctx
;
526 va_start(ap
, format
);
527 written
= util_vsnprintf(sctx
->ptr
, sctx
->left
, format
, ap
);
529 sctx
->ptr
+= written
;
530 sctx
->left
-= written
;
536 const struct tgsi_token
*tokens
,
541 struct str_dump_ctx ctx
;
543 ctx
.base
.iter
.prolog
= prolog
;
544 ctx
.base
.iter
.iterate_instruction
= iter_instruction
;
545 ctx
.base
.iter
.iterate_declaration
= iter_declaration
;
546 ctx
.base
.iter
.iterate_immediate
= iter_immediate
;
547 ctx
.base
.iter
.epilog
= NULL
;
550 ctx
.base
.printf
= &str_dump_ctx_printf
;
557 tgsi_iterate_shader( tokens
, &ctx
.base
.iter
);