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 "tgsi_dump.h"
30 #include "tgsi_iterate.h"
34 struct tgsi_iterate_context iter
;
46 debug_printf( "%u", e
);
48 debug_printf( "%s", enums
[e
] );
51 #define EOL() debug_printf( "\n" )
52 #define TXT(S) debug_printf( "%s", S )
53 #define CHR(C) debug_printf( "%c", C )
54 #define UIX(I) debug_printf( "0x%x", I )
55 #define UID(I) debug_printf( "%u", I )
56 #define SID(I) debug_printf( "%d", I )
57 #define FLT(F) debug_printf( "%10.4f", F )
58 #define ENM(E,ENUMS) dump_enum( E, ENUMS, sizeof( ENUMS ) / sizeof( *ENUMS ) )
60 static const char *processor_type_names
[] =
67 static const char *file_names
[] =
79 static const char *interpolate_names
[] =
86 static const char *semantic_names
[] =
97 static const char *immediate_type_names
[] =
102 static const char *opcode_names
[TGSI_OPCODE_LAST
] =
225 static const char *swizzle_names
[] =
233 static const char *texture_names
[] =
246 static const char *extswizzle_names
[] =
256 static const char *modulate_names
[TGSI_MODULATE_COUNT
] =
268 _dump_register_prefix(
283 ENM( file
, file_names
);
300 ENM( file
, file_names
);
302 ENM( ind_file
, file_names
);
318 if (writemask
!= TGSI_WRITEMASK_XYZW
) {
320 if (writemask
& TGSI_WRITEMASK_X
)
322 if (writemask
& TGSI_WRITEMASK_Y
)
324 if (writemask
& TGSI_WRITEMASK_Z
)
326 if (writemask
& TGSI_WRITEMASK_W
)
332 tgsi_dump_declaration(
333 const struct tgsi_full_declaration
*decl
)
338 decl
->Declaration
.File
,
339 decl
->DeclarationRange
.First
,
340 decl
->DeclarationRange
.Last
);
342 decl
->Declaration
.UsageMask
);
344 if (decl
->Declaration
.Semantic
) {
346 ENM( decl
->Semantic
.SemanticName
, semantic_names
);
347 if (decl
->Semantic
.SemanticIndex
!= 0 ||
348 decl
->Semantic
.SemanticName
== TGSI_SEMANTIC_GENERIC
) {
350 UID( decl
->Semantic
.SemanticIndex
);
356 ENM( decl
->Declaration
.Interpolate
, interpolate_names
);
361 struct tgsi_iterate_context
*iter
,
362 struct tgsi_full_declaration
*decl
)
364 tgsi_dump_declaration( decl
);
370 const struct tgsi_full_immediate
*imm
)
375 ENM( imm
->Immediate
.DataType
, immediate_type_names
);
378 for (i
= 0; i
< imm
->Immediate
.Size
- 1; i
++) {
379 switch (imm
->Immediate
.DataType
) {
380 case TGSI_IMM_FLOAT32
:
381 FLT( imm
->u
.ImmediateFloat32
[i
].Float
);
387 if (i
< imm
->Immediate
.Size
- 2)
395 struct tgsi_iterate_context
*iter
,
396 struct tgsi_full_immediate
*imm
)
398 tgsi_dump_immediate( imm
);
403 tgsi_dump_instruction(
404 const struct tgsi_full_instruction
*inst
,
408 boolean first_reg
= TRUE
;
413 ENM( inst
->Instruction
.Opcode
, opcode_names
);
415 switch (inst
->Instruction
.Saturate
) {
418 case TGSI_SAT_ZERO_ONE
:
421 case TGSI_SAT_MINUS_PLUS_ONE
:
428 for (i
= 0; i
< inst
->Instruction
.NumDstRegs
; i
++) {
429 const struct tgsi_full_dst_register
*dst
= &inst
->FullDstRegisters
[i
];
436 dst
->DstRegister
.File
,
437 dst
->DstRegister
.Index
,
438 dst
->DstRegister
.Index
);
439 ENM( dst
->DstRegisterExtModulate
.Modulate
, modulate_names
);
440 _dump_writemask( dst
->DstRegister
.WriteMask
);
445 for (i
= 0; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
446 const struct tgsi_full_src_register
*src
= &inst
->FullSrcRegisters
[i
];
452 if (src
->SrcRegisterExtMod
.Negate
)
454 if (src
->SrcRegisterExtMod
.Absolute
)
456 if (src
->SrcRegisterExtMod
.Scale2X
)
458 if (src
->SrcRegisterExtMod
.Bias
)
460 if (src
->SrcRegisterExtMod
.Complement
)
462 if (src
->SrcRegister
.Negate
)
465 if (src
->SrcRegister
.Indirect
) {
467 src
->SrcRegister
.File
,
468 src
->SrcRegister
.Index
,
469 src
->SrcRegisterInd
.File
,
470 src
->SrcRegisterInd
.Index
);
474 src
->SrcRegister
.File
,
475 src
->SrcRegister
.Index
,
476 src
->SrcRegister
.Index
);
479 if (src
->SrcRegister
.SwizzleX
!= TGSI_SWIZZLE_X
||
480 src
->SrcRegister
.SwizzleY
!= TGSI_SWIZZLE_Y
||
481 src
->SrcRegister
.SwizzleZ
!= TGSI_SWIZZLE_Z
||
482 src
->SrcRegister
.SwizzleW
!= TGSI_SWIZZLE_W
) {
484 ENM( src
->SrcRegister
.SwizzleX
, swizzle_names
);
485 ENM( src
->SrcRegister
.SwizzleY
, swizzle_names
);
486 ENM( src
->SrcRegister
.SwizzleZ
, swizzle_names
);
487 ENM( src
->SrcRegister
.SwizzleW
, swizzle_names
);
489 if (src
->SrcRegisterExtSwz
.ExtSwizzleX
!= TGSI_EXTSWIZZLE_X
||
490 src
->SrcRegisterExtSwz
.ExtSwizzleY
!= TGSI_EXTSWIZZLE_Y
||
491 src
->SrcRegisterExtSwz
.ExtSwizzleZ
!= TGSI_EXTSWIZZLE_Z
||
492 src
->SrcRegisterExtSwz
.ExtSwizzleW
!= TGSI_EXTSWIZZLE_W
) {
494 ENM( src
->SrcRegisterExtSwz
.ExtSwizzleX
, extswizzle_names
);
495 ENM( src
->SrcRegisterExtSwz
.ExtSwizzleY
, extswizzle_names
);
496 ENM( src
->SrcRegisterExtSwz
.ExtSwizzleZ
, extswizzle_names
);
497 ENM( src
->SrcRegisterExtSwz
.ExtSwizzleW
, extswizzle_names
);
500 if (src
->SrcRegisterExtMod
.Complement
)
502 if (src
->SrcRegisterExtMod
.Bias
)
504 if (src
->SrcRegisterExtMod
.Scale2X
)
506 if (src
->SrcRegisterExtMod
.Absolute
)
508 if (src
->SrcRegisterExtMod
.Negate
)
514 if (inst
->InstructionExtTexture
.Texture
!= TGSI_TEXTURE_UNKNOWN
) {
516 ENM( inst
->InstructionExtTexture
.Texture
, texture_names
);
519 switch (inst
->Instruction
.Opcode
) {
521 case TGSI_OPCODE_ELSE
:
522 case TGSI_OPCODE_BGNLOOP2
:
523 case TGSI_OPCODE_ENDLOOP2
:
524 case TGSI_OPCODE_CAL
:
526 UID( inst
->InstructionExtLabel
.Label
);
533 struct tgsi_iterate_context
*iter
,
534 struct tgsi_full_instruction
*inst
)
536 struct dump_ctx
*ctx
= (struct dump_ctx
*) iter
;
538 tgsi_dump_instruction( inst
, ctx
->instno
++ );
544 struct tgsi_iterate_context
*ctx
)
547 ENM( ctx
->processor
.Processor
, processor_type_names
);
548 UID( ctx
->version
.MajorVersion
);
550 UID( ctx
->version
.MinorVersion
);
556 const struct tgsi_token
*tokens
,
562 assert( strcmp( opcode_names
[TGSI_OPCODE_CONT
], "CONT" ) == 0 );
563 assert( strcmp( opcode_names
[TGSI_OPCODE_END
], "END" ) == 0 );
565 ctx
.iter
.prolog
= prolog
;
566 ctx
.iter
.iterate_instruction
= iter_instruction
;
567 ctx
.iter
.iterate_declaration
= iter_declaration
;
568 ctx
.iter
.iterate_immediate
= iter_immediate
;
569 ctx
.iter
.epilog
= NULL
;
573 tgsi_iterate_shader( tokens
, &ctx
.iter
);