X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=src%2Fgallium%2Fauxiliary%2Ftgsi%2Ftgsi_dump.c;h=111d95b6665b7c4731d57b69211cdc8e4e2edba8;hb=7549a8397b310acf672f97a08c8e7d866cdf492c;hp=c2a0ac5aff848a7d38783787ba46dae1cfa33e04;hpb=9136c9b29ed5c14bc89a4c4e3a391e0b097092e1;p=mesa.git diff --git a/src/gallium/auxiliary/tgsi/tgsi_dump.c b/src/gallium/auxiliary/tgsi/tgsi_dump.c index c2a0ac5aff8..111d95b6665 100644 --- a/src/gallium/auxiliary/tgsi/tgsi_dump.c +++ b/src/gallium/auxiliary/tgsi/tgsi_dump.c @@ -25,18 +25,28 @@ * **************************************************************************/ -#include "pipe/p_debug.h" +#include "util/u_debug.h" #include "util/u_string.h" +#include "util/u_math.h" +#include "util/u_memory.h" #include "tgsi_dump.h" #include "tgsi_info.h" #include "tgsi_iterate.h" + +/** Number of spaces to indent for IF/LOOP/etc */ +static const int indent_spaces = 3; + + struct dump_ctx { struct tgsi_iterate_context iter; uint instno; + int indent; + uint indentation; + void (*printf)(struct dump_ctx *ctx, const char *format, ...); }; @@ -80,7 +90,7 @@ static const char *processor_type_names[] = "GEOM" }; -static const char *file_names[] = +static const char *file_names[TGSI_FILE_COUNT] = { "NULL", "CONST", @@ -89,7 +99,8 @@ static const char *file_names[] = "TEMP", "SAMP", "ADDR", - "IMM" + "IMM", + "LOOP" }; static const char *interpolate_names[] = @@ -107,7 +118,8 @@ static const char *semantic_names[] = "FOG", "PSIZE", "GENERIC", - "NORMAL" + "NORMAL", + "FACE" }; static const char *immediate_type_names[] = @@ -180,14 +192,16 @@ _dump_register_ind( uint file, int index, uint ind_file, - int ind_index ) + int ind_index, + uint ind_swizzle ) { ENM( file, file_names ); CHR( '[' ); ENM( ind_file, file_names ); CHR( '[' ); SID( ind_index ); - CHR( ']' ); + TXT( "]." ); + ENM( ind_swizzle, swizzle_names ); if (index != 0) { if (index > 0) CHR( '+' ); @@ -221,6 +235,9 @@ iter_declaration( { struct dump_ctx *ctx = (struct dump_ctx *)iter; + assert(Elements(semantic_names) == TGSI_SEMANTIC_COUNT); + assert(Elements(interpolate_names) == TGSI_INTERPOLATE_COUNT); + TXT( "DCL " ); _dump_register( @@ -243,8 +260,12 @@ iter_declaration( } } - TXT( ", " ); - ENM( decl->Declaration.Interpolate, interpolate_names ); + if (iter->processor.Processor == TGSI_PROCESSOR_FRAGMENT && + decl->Declaration.File == TGSI_FILE_INPUT) + { + TXT( ", " ); + ENM( decl->Declaration.Interpolate, interpolate_names ); + } if (decl->Declaration.Centroid) { TXT( ", CENTROID" ); @@ -283,16 +304,18 @@ iter_immediate( ENM( imm->Immediate.DataType, immediate_type_names ); TXT( " { " ); - for (i = 0; i < imm->Immediate.Size - 1; i++) { + + assert( imm->Immediate.NrTokens <= 4 + 1 ); + for (i = 0; i < imm->Immediate.NrTokens - 1; i++) { switch (imm->Immediate.DataType) { case TGSI_IMM_FLOAT32: - FLT( imm->u.ImmediateFloat32[i].Float ); + FLT( imm->u[i].Float ); break; default: assert( 0 ); } - if (i < imm->Immediate.Size - 2) + if (i < imm->Immediate.NrTokens - 2) TXT( ", " ); } TXT( " }" ); @@ -320,13 +343,19 @@ iter_instruction( { struct dump_ctx *ctx = (struct dump_ctx *) iter; uint instno = ctx->instno++; - + const struct tgsi_opcode_info *info = tgsi_get_opcode_info( inst->Instruction.Opcode ); uint i; boolean first_reg = TRUE; INSTID( instno ); TXT( ": " ); - TXT( tgsi_get_opcode_info( inst->Instruction.Opcode )->mnemonic ); + + ctx->indent -= info->pre_dedent; + for(i = 0; (int)i < ctx->indent; ++i) + TXT( " " ); + ctx->indent += info->post_indent; + + TXT( info->mnemonic ); switch (inst->Instruction.Saturate) { case TGSI_SAT_NONE: @@ -348,11 +377,22 @@ iter_instruction( CHR( ',' ); CHR( ' ' ); - _dump_register( - ctx, - dst->DstRegister.File, - dst->DstRegister.Index, - dst->DstRegister.Index ); + if (dst->DstRegister.Indirect) { + _dump_register_ind( + ctx, + dst->DstRegister.File, + dst->DstRegister.Index, + dst->DstRegisterInd.File, + dst->DstRegisterInd.Index, + dst->DstRegisterInd.SwizzleX ); + } + else { + _dump_register( + ctx, + dst->DstRegister.File, + dst->DstRegister.Index, + dst->DstRegister.Index ); + } ENM( dst->DstRegisterExtModulate.Modulate, modulate_names ); _dump_writemask( ctx, dst->DstRegister.WriteMask ); @@ -385,7 +425,8 @@ iter_instruction( src->SrcRegister.File, src->SrcRegister.Index, src->SrcRegisterInd.File, - src->SrcRegisterInd.Index ); + src->SrcRegisterInd.Index, + src->SrcRegisterInd.SwizzleX ); } else { _dump_register( @@ -446,14 +487,22 @@ iter_instruction( switch (inst->Instruction.Opcode) { case TGSI_OPCODE_IF: case TGSI_OPCODE_ELSE: - case TGSI_OPCODE_BGNLOOP2: - case TGSI_OPCODE_ENDLOOP2: + case TGSI_OPCODE_BGNLOOP: + case TGSI_OPCODE_ENDLOOP: case TGSI_OPCODE_CAL: TXT( " :" ); UID( inst->InstructionExtLabel.Label ); break; } + /* update indentation */ + if (inst->Instruction.Opcode == TGSI_OPCODE_IF || + inst->Instruction.Opcode == TGSI_OPCODE_ELSE || + inst->Instruction.Opcode == TGSI_OPCODE_BGNFOR || + inst->Instruction.Opcode == TGSI_OPCODE_BGNLOOP) { + ctx->indentation += indent_spaces; + } + EOL(); return TRUE; @@ -467,7 +516,9 @@ tgsi_dump_instruction( struct dump_ctx ctx; ctx.instno = instno; + ctx.indent = 0; ctx.printf = dump_ctx_printf; + ctx.indentation = 0; iter_instruction( &ctx.iter, (struct tgsi_full_instruction *)inst ); } @@ -499,7 +550,9 @@ tgsi_dump( ctx.iter.epilog = NULL; ctx.instno = 0; + ctx.indent = 0; ctx.printf = dump_ctx_printf; + ctx.indentation = 0; tgsi_iterate_shader( tokens, &ctx.iter ); } @@ -509,7 +562,7 @@ struct str_dump_ctx struct dump_ctx base; char *str; char *ptr; - size_t left; + int left; }; static void @@ -518,13 +571,20 @@ str_dump_ctx_printf(struct dump_ctx *ctx, const char *format, ...) struct str_dump_ctx *sctx = (struct str_dump_ctx *)ctx; if(sctx->left > 1) { - size_t written; + int written; va_list ap; va_start(ap, format); written = util_vsnprintf(sctx->ptr, sctx->left, format, ap); va_end(ap); - sctx->ptr += written; - sctx->left -= written; + + /* Some complicated logic needed to handle the return value of + * vsnprintf: + */ + if (written > 0) { + written = MIN2(sctx->left, written); + sctx->ptr += written; + sctx->left -= written; + } } } @@ -544,12 +604,14 @@ tgsi_dump_str( ctx.base.iter.epilog = NULL; ctx.base.instno = 0; + ctx.base.indent = 0; ctx.base.printf = &str_dump_ctx_printf; + ctx.base.indentation = 0; ctx.str = str; ctx.str[0] = 0; ctx.ptr = str; - ctx.left = size; + ctx.left = (int)size; tgsi_iterate_shader( tokens, &ctx.base.iter ); }