From 2644952bd4dfa3b75112dee8dfd287a12d770705 Mon Sep 17 00:00:00 2001 From: Francisco Jerez Date: Sun, 18 Mar 2012 19:21:36 +0100 Subject: [PATCH] gallium/tgsi: Introduce the "LOCAL" register declaration modifier. This change will be useful to implement function parameter passing on top of TGSI. As we don't have a proper stack, a register-based calling convention will be used instead, which isn't necessarily a bad thing given that GPUs often have plenty of registers to spare. Using the same register space for local temporaries and inter-procedural communication caused some inefficiencies, because in some cases the register allocator would lose the freedom to merge temporary values together into the same physical register, leading to suboptimal register (and sometimes, as a side effect, instruction) usage. The LOCAL declaration modifier specifies that the value isn't intended for parameter passing and as a result the compiler doesn't have to give any guarantees of it being preserved across function boundaries. Ignoring the LOCAL flag doesn't change the semantics of a valid program in any way, because local variables are just supposed to get a more relaxed treatment. IOW, this should be a backwards-compatible change. --- src/gallium/auxiliary/tgsi/tgsi_build.c | 4 ++ src/gallium/auxiliary/tgsi/tgsi_dump.c | 3 ++ src/gallium/auxiliary/tgsi/tgsi_text.c | 65 ++++++++++++++++++------------ src/gallium/docs/source/tgsi.rst | 6 +++ src/gallium/include/pipe/p_shader_tokens.h | 3 +- 5 files changed, 54 insertions(+), 27 deletions(-) diff --git a/src/gallium/auxiliary/tgsi/tgsi_build.c b/src/gallium/auxiliary/tgsi/tgsi_build.c index 8378075b3e9..ed725c53966 100644 --- a/src/gallium/auxiliary/tgsi/tgsi_build.c +++ b/src/gallium/auxiliary/tgsi/tgsi_build.c @@ -108,6 +108,7 @@ tgsi_default_declaration( void ) declaration.Dimension = 0; declaration.Semantic = 0; declaration.Invariant = 0; + declaration.Local = 0; return declaration; } @@ -120,6 +121,7 @@ tgsi_build_declaration( unsigned dimension, unsigned semantic, unsigned invariant, + unsigned local, struct tgsi_header *header ) { struct tgsi_declaration declaration; @@ -134,6 +136,7 @@ tgsi_build_declaration( declaration.Dimension = dimension; declaration.Semantic = semantic; declaration.Invariant = invariant; + declaration.Local = local; header_bodysize_grow( header ); @@ -359,6 +362,7 @@ tgsi_build_full_declaration( full_decl->Declaration.Dimension, full_decl->Declaration.Semantic, full_decl->Declaration.Invariant, + full_decl->Declaration.Local, header ); if (maxsize <= size) diff --git a/src/gallium/auxiliary/tgsi/tgsi_dump.c b/src/gallium/auxiliary/tgsi/tgsi_dump.c index 36859466877..383c54590af 100644 --- a/src/gallium/auxiliary/tgsi/tgsi_dump.c +++ b/src/gallium/auxiliary/tgsi/tgsi_dump.c @@ -271,6 +271,9 @@ iter_declaration( ctx, decl->Declaration.UsageMask ); + if (decl->Declaration.Local) + TXT( ", LOCAL" ); + if (decl->Declaration.Semantic) { TXT( ", " ); ENM( decl->Semantic.Name, tgsi_semantic_names ); diff --git a/src/gallium/auxiliary/tgsi/tgsi_text.c b/src/gallium/auxiliary/tgsi/tgsi_text.c index 52e30b40169..c87313a3c16 100644 --- a/src/gallium/auxiliary/tgsi/tgsi_text.c +++ b/src/gallium/auxiliary/tgsi/tgsi_text.c @@ -1161,38 +1161,51 @@ static boolean parse_declaration( struct translate_ctx *ctx ) } ctx->cur = cur; } else { - for (i = 0; i < TGSI_SEMANTIC_COUNT; i++) { - if (str_match_no_case( &cur, tgsi_semantic_names[i] )) { - const char *cur2 = cur; - uint index; + if (str_match_no_case(&cur, "LOCAL") && + !is_digit_alpha_underscore(cur)) { + decl.Declaration.Local = 1; + ctx->cur = cur; + } - if (is_digit_alpha_underscore( cur )) - continue; - eat_opt_white( &cur2 ); - if (*cur2 == '[') { - cur2++; - eat_opt_white( &cur2 ); - if (!parse_uint( &cur2, &index )) { - report_error( ctx, "Expected literal integer" ); - return FALSE; - } + cur = ctx->cur; + eat_opt_white( &cur ); + if (*cur == ',') { + cur++; + eat_opt_white( &cur ); + + for (i = 0; i < TGSI_SEMANTIC_COUNT; i++) { + if (str_match_no_case( &cur, tgsi_semantic_names[i] )) { + uint index; + + if (is_digit_alpha_underscore( cur )) + continue; + cur2 = cur; eat_opt_white( &cur2 ); - if (*cur2 != ']') { - report_error( ctx, "Expected `]'" ); - return FALSE; - } - cur2++; + if (*cur2 == '[') { + cur2++; + eat_opt_white( &cur2 ); + if (!parse_uint( &cur2, &index )) { + report_error( ctx, "Expected literal integer" ); + return FALSE; + } + eat_opt_white( &cur2 ); + if (*cur2 != ']') { + report_error( ctx, "Expected `]'" ); + return FALSE; + } + cur2++; - decl.Semantic.Index = index; + decl.Semantic.Index = index; - cur = cur2; - } + cur = cur2; + } - decl.Declaration.Semantic = 1; - decl.Semantic.Name = i; + decl.Declaration.Semantic = 1; + decl.Semantic.Name = i; - ctx->cur = cur; - break; + ctx->cur = cur; + break; + } } } } diff --git a/src/gallium/docs/source/tgsi.rst b/src/gallium/docs/source/tgsi.rst index 1155ff391c1..548a9a39855 100644 --- a/src/gallium/docs/source/tgsi.rst +++ b/src/gallium/docs/source/tgsi.rst @@ -1795,6 +1795,12 @@ of TGSI_FILE. UsageMask field specifies which of the register components can be accessed and is one of TGSI_WRITEMASK. +The Local flag specifies that a given value isn't intended for +subroutine parameter passing and, as a result, the implementation +isn't required to give any guarantees of it being preserved across +subroutine boundaries. As it's merely a compiler hint, the +implementation is free to ignore it. + If Dimension flag is set to 1, a Declaration Dimension token follows. If Semantic flag is set to 1, a Declaration Semantic token follows. diff --git a/src/gallium/include/pipe/p_shader_tokens.h b/src/gallium/include/pipe/p_shader_tokens.h index 2579112a25b..5325e43896c 100644 --- a/src/gallium/include/pipe/p_shader_tokens.h +++ b/src/gallium/include/pipe/p_shader_tokens.h @@ -120,7 +120,8 @@ struct tgsi_declaration unsigned Semantic : 1; /**< BOOL, any semantic info? */ unsigned Interpolate : 1; /**< any interpolation info? */ unsigned Invariant : 1; /**< invariant optimization? */ - unsigned Padding : 8; + unsigned Local : 1; /**< optimize as subroutine local variable? */ + unsigned Padding : 7; }; struct tgsi_declaration_range -- 2.11.0