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 "tgsi_dump_c.h"
31 #include "tgsi_build.h"
32 #include "tgsi_info.h"
33 #include "tgsi_parse.h"
39 const unsigned enums_count
)
41 if (e
>= enums_count
) {
42 debug_printf( "%u", e
);
45 debug_printf( "%s", enums
[e
] );
49 #define EOL() debug_printf( "\n" )
50 #define TXT(S) debug_printf( "%s", S )
51 #define CHR(C) debug_printf( "%c", C )
52 #define UIX(I) debug_printf( "0x%x", I )
53 #define UID(I) debug_printf( "%u", I )
54 #define SID(I) debug_printf( "%d", I )
55 #define FLT(F) debug_printf( "%10.4f", F )
56 #define ENM(E,ENUMS) dump_enum( E, ENUMS, sizeof( ENUMS ) / sizeof( *ENUMS ) )
58 static const char *TGSI_PROCESSOR_TYPES
[] =
65 static const char *TGSI_TOKEN_TYPES
[] =
67 "TOKEN_TYPE_DECLARATION",
68 "TOKEN_TYPE_IMMEDIATE",
69 "TOKEN_TYPE_INSTRUCTION"
72 static const char *TGSI_FILES
[TGSI_FILE_COUNT
] =
86 static const char *TGSI_INTERPOLATES
[] =
88 "INTERPOLATE_CONSTANT",
90 "INTERPOLATE_PERSPECTIVE"
93 static const char *TGSI_SEMANTICS
[] =
104 static const char *TGSI_IMMS
[] =
109 static const char *TGSI_SATS
[] =
116 static const char *TGSI_SWIZZLES
[] =
124 static const char *TGSI_TEXTURES
[] =
137 static const char *TGSI_WRITEMASKS
[] =
158 dump_declaration_verbose(
159 struct tgsi_full_declaration
*decl
,
162 struct tgsi_full_declaration
*fd
)
165 ENM( decl
->Declaration
.File
, TGSI_FILES
);
166 if( deflt
|| fd
->Declaration
.UsageMask
!= decl
->Declaration
.UsageMask
) {
167 TXT( "\nUsageMask : " );
168 if( decl
->Declaration
.UsageMask
& TGSI_WRITEMASK_X
) {
171 if( decl
->Declaration
.UsageMask
& TGSI_WRITEMASK_Y
) {
174 if( decl
->Declaration
.UsageMask
& TGSI_WRITEMASK_Z
) {
177 if( decl
->Declaration
.UsageMask
& TGSI_WRITEMASK_W
) {
181 if( deflt
|| fd
->Declaration
.Interpolate
!= decl
->Declaration
.Interpolate
) {
182 TXT( "\nInterpolate: " );
183 ENM( decl
->Declaration
.Interpolate
, TGSI_INTERPOLATES
);
185 if( deflt
|| fd
->Declaration
.Semantic
!= decl
->Declaration
.Semantic
) {
186 TXT( "\nSemantic : " );
187 UID( decl
->Declaration
.Semantic
);
189 if (deflt
|| fd
->Declaration
.Centroid
!= decl
->Declaration
.Centroid
) {
190 TXT("\nCentroid : ");
191 UID(decl
->Declaration
.Centroid
);
193 if (deflt
|| fd
->Declaration
.Invariant
!= decl
->Declaration
.Invariant
) {
194 TXT("\nInvariant : ");
195 UID(decl
->Declaration
.Invariant
);
198 TXT( "\nPadding : " );
199 UIX( decl
->Declaration
.Padding
);
204 UID( decl
->Range
.First
);
206 UID( decl
->Range
.Last
);
208 if( decl
->Declaration
.Semantic
) {
211 ENM( decl
->Semantic
.Name
, TGSI_SEMANTICS
);
213 UID( decl
->Semantic
.Index
);
215 TXT( "\nPadding : " );
216 UIX( decl
->Semantic
.Padding
);
222 dump_immediate_verbose(
223 struct tgsi_full_immediate
*imm
,
228 TXT( "\nDataType : " );
229 ENM( imm
->Immediate
.DataType
, TGSI_IMMS
);
231 TXT( "\nPadding : " );
232 UIX( imm
->Immediate
.Padding
);
235 assert( imm
->Immediate
.NrTokens
<= 4 + 1 );
236 for( i
= 0; i
< imm
->Immediate
.NrTokens
- 1; i
++ ) {
238 switch( imm
->Immediate
.DataType
) {
239 case TGSI_IMM_FLOAT32
:
241 FLT( imm
->u
[i
].Float
);
251 dump_instruction_verbose(
252 struct tgsi_full_instruction
*inst
,
255 struct tgsi_full_instruction
*fi
)
259 TXT( "\nOpcode : OPCODE_" );
260 TXT( tgsi_get_opcode_info( inst
->Instruction
.Opcode
)->mnemonic
);
261 if( deflt
|| fi
->Instruction
.Saturate
!= inst
->Instruction
.Saturate
) {
262 TXT( "\nSaturate : " );
263 ENM( inst
->Instruction
.Saturate
, TGSI_SATS
);
265 if( deflt
|| fi
->Instruction
.NumDstRegs
!= inst
->Instruction
.NumDstRegs
) {
266 TXT( "\nNumDstRegs : " );
267 UID( inst
->Instruction
.NumDstRegs
);
269 if( deflt
|| fi
->Instruction
.NumSrcRegs
!= inst
->Instruction
.NumSrcRegs
) {
270 TXT( "\nNumSrcRegs : " );
271 UID( inst
->Instruction
.NumSrcRegs
);
273 if (deflt
|| fi
->Instruction
.Predicate
!= inst
->Instruction
.Predicate
) {
274 TXT("\nPredicate : ");
275 UID(inst
->Instruction
.Predicate
);
277 if (deflt
|| fi
->Instruction
.Label
!= inst
->Instruction
.Label
) {
279 UID(inst
->Instruction
.Label
);
281 if (deflt
|| fi
->Instruction
.Texture
!= inst
->Instruction
.Texture
) {
283 UID(inst
->Instruction
.Texture
);
286 TXT( "\nPadding : " );
287 UIX( inst
->Instruction
.Padding
);
290 if (deflt
|| inst
->Instruction
.Label
) {
292 if (deflt
|| fi
->Label
.Label
!= inst
->Label
.Label
) {
294 UID(inst
->Label
.Label
);
297 TXT( "\nPadding : " );
298 UIX(inst
->Label
.Padding
);
302 if (deflt
|| inst
->Instruction
.Texture
) {
304 if (deflt
|| fi
->Texture
.Texture
!= inst
->Texture
.Texture
) {
305 TXT( "\nTexture : " );
306 ENM(inst
->Texture
.Texture
, TGSI_TEXTURES
);
309 TXT( "\nPadding : " );
310 UIX(inst
->Texture
.Padding
);
314 for( i
= 0; i
< inst
->Instruction
.NumDstRegs
; i
++ ) {
315 struct tgsi_full_dst_register
*dst
= &inst
->Dst
[i
];
316 struct tgsi_full_dst_register
*fd
= &fi
->Dst
[i
];
320 ENM( dst
->Register
.File
, TGSI_FILES
);
321 if( deflt
|| fd
->Register
.WriteMask
!= dst
->Register
.WriteMask
) {
322 TXT( "\nWriteMask: " );
323 ENM( dst
->Register
.WriteMask
, TGSI_WRITEMASKS
);
326 if( deflt
|| fd
->Register
.Indirect
!= dst
->Register
.Indirect
) {
327 TXT( "\nIndirect : " );
328 UID( dst
->Register
.Indirect
);
330 if( deflt
|| fd
->Register
.Dimension
!= dst
->Register
.Dimension
) {
331 TXT( "\nDimension: " );
332 UID( dst
->Register
.Dimension
);
335 if( deflt
|| fd
->Register
.Index
!= dst
->Register
.Index
) {
337 SID( dst
->Register
.Index
);
340 TXT( "\nPadding : " );
341 UIX( dst
->Register
.Padding
);
345 for( i
= 0; i
< inst
->Instruction
.NumSrcRegs
; i
++ ) {
346 struct tgsi_full_src_register
*src
= &inst
->Src
[i
];
347 struct tgsi_full_src_register
*fs
= &fi
->Src
[i
];
351 ENM( src
->Register
.File
, TGSI_FILES
);
352 if( deflt
|| fs
->Register
.SwizzleX
!= src
->Register
.SwizzleX
) {
353 TXT( "\nSwizzleX : " );
354 ENM( src
->Register
.SwizzleX
, TGSI_SWIZZLES
);
356 if( deflt
|| fs
->Register
.SwizzleY
!= src
->Register
.SwizzleY
) {
357 TXT( "\nSwizzleY : " );
358 ENM( src
->Register
.SwizzleY
, TGSI_SWIZZLES
);
360 if( deflt
|| fs
->Register
.SwizzleZ
!= src
->Register
.SwizzleZ
) {
361 TXT( "\nSwizzleZ : " );
362 ENM( src
->Register
.SwizzleZ
, TGSI_SWIZZLES
);
364 if( deflt
|| fs
->Register
.SwizzleW
!= src
->Register
.SwizzleW
) {
365 TXT( "\nSwizzleW : " );
366 ENM( src
->Register
.SwizzleW
, TGSI_SWIZZLES
);
368 if (deflt
|| fs
->Register
.Absolute
!= src
->Register
.Absolute
) {
369 TXT("\nAbsolute : ");
370 UID(src
->Register
.Absolute
);
372 if( deflt
|| fs
->Register
.Negate
!= src
->Register
.Negate
) {
373 TXT( "\nNegate : " );
374 UID( src
->Register
.Negate
);
377 if( deflt
|| fs
->Register
.Indirect
!= src
->Register
.Indirect
) {
378 TXT( "\nIndirect : " );
379 UID( src
->Register
.Indirect
);
381 if( deflt
|| fs
->Register
.Dimension
!= src
->Register
.Dimension
) {
382 TXT( "\nDimension: " );
383 UID( src
->Register
.Dimension
);
386 if( deflt
|| fs
->Register
.Index
!= src
->Register
.Index
) {
388 SID( src
->Register
.Index
);
395 const struct tgsi_token
*tokens
,
398 struct tgsi_parse_context parse
;
399 struct tgsi_full_instruction fi
;
400 struct tgsi_full_declaration fd
;
401 uint ignored
= flags
& TGSI_DUMP_C_IGNORED
;
402 uint deflt
= flags
& TGSI_DUMP_C_DEFAULT
;
404 tgsi_parse_init( &parse
, tokens
);
406 TXT( "tgsi-dump begin -----------------" );
408 TXT( "\nHeaderSize: " );
409 UID( parse
.FullHeader
.Header
.HeaderSize
);
410 TXT( "\nBodySize : " );
411 UID( parse
.FullHeader
.Header
.BodySize
);
412 TXT( "\nProcessor : " );
413 ENM( parse
.FullHeader
.Processor
.Processor
, TGSI_PROCESSOR_TYPES
);
416 fi
= tgsi_default_full_instruction();
417 fd
= tgsi_default_full_declaration();
419 while( !tgsi_parse_end_of_tokens( &parse
) ) {
420 tgsi_parse_token( &parse
);
423 ENM( parse
.FullToken
.Token
.Type
, TGSI_TOKEN_TYPES
);
426 UID( parse
.FullToken
.Token
.NrTokens
);
429 switch( parse
.FullToken
.Token
.Type
) {
430 case TGSI_TOKEN_TYPE_DECLARATION
:
431 dump_declaration_verbose(
432 &parse
.FullToken
.FullDeclaration
,
438 case TGSI_TOKEN_TYPE_IMMEDIATE
:
439 dump_immediate_verbose(
440 &parse
.FullToken
.FullImmediate
,
444 case TGSI_TOKEN_TYPE_INSTRUCTION
:
445 dump_instruction_verbose(
446 &parse
.FullToken
.FullInstruction
,
459 TXT( "\ntgsi-dump end -------------------\n" );
461 tgsi_parse_free( &parse
);