[Mesa-dev] [PATCH] tgsi: replace tgsi_file_names tgsi_file_names[] with tgsi_file_name() function
Brian Paul
brian.e.paul at gmail.com
Thu Jun 6 08:56:05 PDT 2013
From: Brian Paul <brianp at vmware.com>
This change came from the discovery that the STATIC_ASSERT to check that
the number of register file strings didn't actually work.
Similar changes could be make for the other string arrays in tgsi_string.c
---
src/gallium/auxiliary/gallivm/lp_bld_tgsi_info.c | 2 +-
src/gallium/auxiliary/tgsi/tgsi_dump.c | 16 ++++++++--------
src/gallium/auxiliary/tgsi/tgsi_strings.c | 14 ++++++++++++--
src/gallium/auxiliary/tgsi/tgsi_strings.h | 6 ++++--
src/gallium/auxiliary/tgsi/tgsi_text.c | 2 +-
src/gallium/drivers/freedreno/freedreno_compiler.c | 4 ++--
src/gallium/drivers/ilo/shader/toy_tgsi.c | 4 ++--
7 files changed, 30 insertions(+), 18 deletions(-)
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_tgsi_info.c b/src/gallium/auxiliary/gallivm/lp_bld_tgsi_info.c
index b00aa09..184790b 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_tgsi_info.c
+++ b/src/gallium/auxiliary/gallivm/lp_bld_tgsi_info.c
@@ -433,7 +433,7 @@ dump_info(const struct tgsi_token *tokens,
&tex_info->coord[chan];
if (chan_info->file != TGSI_FILE_NULL) {
debug_printf(" %s[%u].%c",
- tgsi_file_names[chan_info->file],
+ tgsi_file_name(chan_info->file),
chan_info->u.index,
"xyzw01"[chan_info->swizzle]);
} else {
diff --git a/src/gallium/auxiliary/tgsi/tgsi_dump.c b/src/gallium/auxiliary/tgsi/tgsi_dump.c
index 77b75b1..7f6a3d8 100644
--- a/src/gallium/auxiliary/tgsi/tgsi_dump.c
+++ b/src/gallium/auxiliary/tgsi/tgsi_dump.c
@@ -99,11 +99,11 @@ _dump_register_src(
struct dump_ctx *ctx,
const struct tgsi_full_src_register *src )
{
- ENM(src->Register.File, tgsi_file_names);
+ TXT(tgsi_file_name(src->Register.File));
if (src->Register.Dimension) {
if (src->Dimension.Indirect) {
CHR( '[' );
- ENM( src->DimIndirect.File, tgsi_file_names );
+ TXT(tgsi_file_name(src->DimIndirect.File));
CHR( '[' );
SID( src->DimIndirect.Index );
TXT( "]." );
@@ -127,7 +127,7 @@ _dump_register_src(
}
if (src->Register.Indirect) {
CHR( '[' );
- ENM( src->Indirect.File, tgsi_file_names );
+ TXT(tgsi_file_name(src->Indirect.File));
CHR( '[' );
SID( src->Indirect.Index );
TXT( "]." );
@@ -156,11 +156,11 @@ _dump_register_dst(
struct dump_ctx *ctx,
const struct tgsi_full_dst_register *dst )
{
- ENM(dst->Register.File, tgsi_file_names);
+ TXT(tgsi_file_name(dst->Register.File));
if (dst->Register.Dimension) {
if (dst->Dimension.Indirect) {
CHR( '[' );
- ENM( dst->DimIndirect.File, tgsi_file_names );
+ TXT(tgsi_file_name(dst->DimIndirect.File));
CHR( '[' );
SID( dst->DimIndirect.Index );
TXT( "]." );
@@ -184,7 +184,7 @@ _dump_register_dst(
}
if (dst->Register.Indirect) {
CHR( '[' );
- ENM( dst->Indirect.File, tgsi_file_names );
+ TXT(tgsi_file_name(dst->Indirect.File));
CHR( '[' );
SID( dst->Indirect.Index );
TXT( "]." );
@@ -266,7 +266,7 @@ iter_declaration(
TXT( "DCL " );
- ENM(decl->Declaration.File, tgsi_file_names);
+ TXT(tgsi_file_name(decl->Declaration.File));
/* all geometry shader inputs are two dimensional */
if (decl->Declaration.File == TGSI_FILE_INPUT &&
@@ -576,7 +576,7 @@ iter_instruction(
ENM( inst->Texture.Texture, tgsi_texture_names );
for (i = 0; i < inst->Texture.NumOffsets; i++) {
TXT( ", " );
- ENM( inst->TexOffsets[i].File, tgsi_file_names);
+ TXT(tgsi_file_name(inst->TexOffsets[i].File));
CHR( '[' );
SID( inst->TexOffsets[i].Index );
CHR( ']' );
diff --git a/src/gallium/auxiliary/tgsi/tgsi_strings.c b/src/gallium/auxiliary/tgsi/tgsi_strings.c
index 6abf927..4dcc723 100644
--- a/src/gallium/auxiliary/tgsi/tgsi_strings.c
+++ b/src/gallium/auxiliary/tgsi/tgsi_strings.c
@@ -40,7 +40,7 @@ const char *tgsi_processor_type_names[4] =
"COMP"
};
-const char *tgsi_file_names[TGSI_FILE_COUNT] =
+static const char *tgsi_file_names[] =
{
"NULL",
"CONST",
@@ -175,7 +175,6 @@ const char *tgsi_immediate_type_names[3] =
static INLINE void
tgsi_strings_check(void)
{
- STATIC_ASSERT(Elements(tgsi_file_names) == TGSI_FILE_COUNT);
STATIC_ASSERT(Elements(tgsi_semantic_names) == TGSI_SEMANTIC_COUNT);
STATIC_ASSERT(Elements(tgsi_texture_names) == TGSI_TEXTURE_COUNT);
STATIC_ASSERT(Elements(tgsi_property_names) == TGSI_PROPERTY_COUNT);
@@ -187,3 +186,14 @@ tgsi_strings_check(void)
(void) tgsi_fs_coord_origin_names;
(void) tgsi_fs_coord_pixel_center_names;
}
+
+
+const char *
+tgsi_file_name(unsigned file)
+{
+ STATIC_ASSERT(Elements(tgsi_file_names) == TGSI_FILE_COUNT);
+ if (file < Elements(tgsi_file_names))
+ return tgsi_file_names[file];
+ else
+ return "invalid file";
+}
diff --git a/src/gallium/auxiliary/tgsi/tgsi_strings.h b/src/gallium/auxiliary/tgsi/tgsi_strings.h
index 5c57e22..4357646 100644
--- a/src/gallium/auxiliary/tgsi/tgsi_strings.h
+++ b/src/gallium/auxiliary/tgsi/tgsi_strings.h
@@ -40,8 +40,6 @@ extern "C" {
extern const char *tgsi_processor_type_names[4];
-extern const char *tgsi_file_names[TGSI_FILE_COUNT];
-
extern const char *tgsi_semantic_names[TGSI_SEMANTIC_COUNT];
extern const char *tgsi_texture_names[TGSI_TEXTURE_COUNT];
@@ -61,6 +59,10 @@ extern const char *tgsi_fs_coord_pixel_center_names[2];
extern const char *tgsi_immediate_type_names[3];
+const char *
+tgsi_file_name(unsigned file);
+
+
#if defined __cplusplus
}
#endif
diff --git a/src/gallium/auxiliary/tgsi/tgsi_text.c b/src/gallium/auxiliary/tgsi/tgsi_text.c
index 187e23e..688c5bc 100644
--- a/src/gallium/auxiliary/tgsi/tgsi_text.c
+++ b/src/gallium/auxiliary/tgsi/tgsi_text.c
@@ -322,7 +322,7 @@ parse_file( const char **pcur, uint *file )
for (i = 0; i < TGSI_FILE_COUNT; i++) {
const char *cur = *pcur;
- if (str_match_nocase_whole( &cur, tgsi_file_names[i] )) {
+ if (str_match_nocase_whole( &cur, tgsi_file_name(i) )) {
*pcur = cur;
*file = i;
return TRUE;
diff --git a/src/gallium/drivers/freedreno/freedreno_compiler.c b/src/gallium/drivers/freedreno/freedreno_compiler.c
index 1a596f5..8d1e266 100644
--- a/src/gallium/drivers/freedreno/freedreno_compiler.c
+++ b/src/gallium/drivers/freedreno/freedreno_compiler.c
@@ -339,7 +339,7 @@ add_dst_reg(struct fd_compile_context *ctx, struct ir2_instruction *alu,
break;
default:
DBG("unsupported dst register file: %s",
- tgsi_file_names[dst->File]);
+ tgsi_file_name(dst->File));
assert(0);
break;
}
@@ -385,7 +385,7 @@ add_src_reg(struct fd_compile_context *ctx, struct ir2_instruction *alu,
break;
default:
DBG("unsupported src register file: %s",
- tgsi_file_names[src->File]);
+ tgsi_file_name(src->File));
assert(0);
break;
}
diff --git a/src/gallium/drivers/ilo/shader/toy_tgsi.c b/src/gallium/drivers/ilo/shader/toy_tgsi.c
index f697d1d..edce997 100644
--- a/src/gallium/drivers/ilo/shader/toy_tgsi.c
+++ b/src/gallium/drivers/ilo/shader/toy_tgsi.c
@@ -2565,11 +2565,11 @@ dump_reg_mapping(void *key, void *val, void *data)
if (tgsi_dim) {
ilo_printf(" v%d:\t%s[%d][%d]\n", vrf,
- tgsi_file_names[tgsi_file], tgsi_dim, tgsi_index);
+ tgsi_file_name(tgsi_file), tgsi_dim, tgsi_index);
}
else {
ilo_printf(" v%d:\t%s[%d]\n", vrf,
- tgsi_file_names[tgsi_file], tgsi_index);
+ tgsi_file_name(tgsi_file), tgsi_index);
}
return PIPE_OK;
--
1.7.4.1
More information about the mesa-dev
mailing list