[Mesa-dev] [PATCH 10/11] gallium/tgsi: Introduce the "LOCAL" register declaration modifier.
Francisco Jerez
currojerez at riseup.net
Thu Mar 22 17:40:39 PDT 2012
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 | 67 +++++++++++++++++-----------
src/gallium/docs/source/tgsi.rst | 6 +++
src/gallium/include/pipe/p_shader_tokens.h | 3 +-
5 files changed, 55 insertions(+), 28 deletions(-)
diff --git a/src/gallium/auxiliary/tgsi/tgsi_build.c b/src/gallium/auxiliary/tgsi/tgsi_build.c
index 1239ce4..a607f9f 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 );
@@ -334,6 +337,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 a8d5148..b25f11a 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 a0b45d4..56a90f7 100644
--- a/src/gallium/auxiliary/tgsi/tgsi_text.c
+++ b/src/gallium/auxiliary/tgsi/tgsi_text.c
@@ -1149,38 +1149,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 (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;
- }
+ if (str_match_no_case(&cur, "LOCAL") &&
+ !is_digit_alpha_underscore(cur)) {
+ decl.Declaration.Local = 1;
+ ctx->cur = cur;
+ }
+
+ 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 03fc40d..c1e6bb8 100644
--- a/src/gallium/docs/source/tgsi.rst
+++ b/src/gallium/docs/source/tgsi.rst
@@ -1768,6 +1768,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 eea2601..a7011b2 100644
--- a/src/gallium/include/pipe/p_shader_tokens.h
+++ b/src/gallium/include/pipe/p_shader_tokens.h
@@ -119,7 +119,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
--
1.7.9.2
More information about the mesa-dev
mailing list