Mesa (master): tgsi_to_nir: Split to smaller functions.
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Tue Mar 5 19:14:04 UTC 2019
Module: Mesa
Branch: master
Commit: 4dba72c4b35eeb312da232b2f30f067885bc9f07
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=4dba72c4b35eeb312da232b2f30f067885bc9f07
Author: Timur Kristóf <timur.kristof at gmail.com>
Date: Fri Feb 8 09:59:58 2019 +0100
tgsi_to_nir: Split to smaller functions.
Previously, tgsi_to_nir was a single big function, and this patch
intends to make the code easier to understand by splitting it up
to multiple smaller pieces.
Signed-Off-By: Timur Kristóf <timur.kristof at gmail.com>
Tested-by: Andre Heider <a.heider at gmail.com>
Tested-by: Rob Clark <robdclark at gmail.com>
Reviewed-by: Timothy Arceri <tarceri at itsqueeze.com>
Acked-By: Tested-by: Rob Clark <robdclark at gmail.com>
---
src/gallium/auxiliary/nir/tgsi_to_nir.c | 82 ++++++++++++++++++++++-----------
1 file changed, 56 insertions(+), 26 deletions(-)
diff --git a/src/gallium/auxiliary/nir/tgsi_to_nir.c b/src/gallium/auxiliary/nir/tgsi_to_nir.c
index bd2aaaed0dc..1260752f0f6 100644
--- a/src/gallium/auxiliary/nir/tgsi_to_nir.c
+++ b/src/gallium/auxiliary/nir/tgsi_to_nir.c
@@ -1779,15 +1779,50 @@ ttn_add_output_stores(struct ttn_compile *c)
}
}
-struct nir_shader *
-tgsi_to_nir(const void *tgsi_tokens,
- const nir_shader_compiler_options *options)
+/**
+ * Parses the given TGSI tokens.
+ */
+static void
+ttn_parse_tgsi(struct ttn_compile *c, const void *tgsi_tokens)
{
struct tgsi_parse_context parser;
- struct tgsi_shader_info scan;
+ int ret;
+
+ ret = tgsi_parse_init(&parser, tgsi_tokens);
+ assert(ret == TGSI_PARSE_OK);
+
+ while (!tgsi_parse_end_of_tokens(&parser)) {
+ tgsi_parse_token(&parser);
+ c->token = &parser.FullToken;
+
+ switch (parser.FullToken.Token.Type) {
+ case TGSI_TOKEN_TYPE_DECLARATION:
+ ttn_emit_declaration(c);
+ break;
+
+ case TGSI_TOKEN_TYPE_INSTRUCTION:
+ ttn_emit_instruction(c);
+ break;
+
+ case TGSI_TOKEN_TYPE_IMMEDIATE:
+ ttn_emit_immediate(c);
+ break;
+ }
+ }
+
+ tgsi_parse_free(&parser);
+}
+
+/**
+ * Initializes a TGSI-to-NIR compiler.
+ */
+static struct ttn_compile *
+ttn_compile_init(const void *tgsi_tokens,
+ const nir_shader_compiler_options *options)
+{
struct ttn_compile *c;
struct nir_shader *s;
- int ret;
+ struct tgsi_shader_info scan;
c = rzalloc(NULL, struct ttn_compile);
@@ -1797,6 +1832,7 @@ tgsi_to_nir(const void *tgsi_tokens,
nir_builder_init_simple_shader(&c->build, NULL,
tgsi_processor_to_shader_stage(scan.processor),
options);
+
s = c->build.shader;
if (s->info.stage == MESA_SHADER_FRAGMENT)
@@ -1827,32 +1863,26 @@ tgsi_to_nir(const void *tgsi_tokens,
c->loop_stack = rzalloc_array(c, nir_cursor,
scan.opcode_count[TGSI_OPCODE_BGNLOOP]);
- ret = tgsi_parse_init(&parser, tgsi_tokens);
- assert(ret == TGSI_PARSE_OK);
-
- while (!tgsi_parse_end_of_tokens(&parser)) {
- tgsi_parse_token(&parser);
- c->token = &parser.FullToken;
-
- switch (parser.FullToken.Token.Type) {
- case TGSI_TOKEN_TYPE_DECLARATION:
- ttn_emit_declaration(c);
- break;
- case TGSI_TOKEN_TYPE_INSTRUCTION:
- ttn_emit_instruction(c);
- break;
+ ttn_parse_tgsi(c, tgsi_tokens);
+ ttn_add_output_stores(c);
- case TGSI_TOKEN_TYPE_IMMEDIATE:
- ttn_emit_immediate(c);
- break;
- }
- }
+ nir_validate_shader(c->build.shader, "TTN: after parsing TGSI and creating the NIR shader");
- tgsi_parse_free(&parser);
+ return c;
+}
- ttn_add_output_stores(c);
+struct nir_shader *
+tgsi_to_nir(const void *tgsi_tokens,
+ const nir_shader_compiler_options *options)
+{
+ struct ttn_compile *c;
+ struct nir_shader *s;
+ c = ttn_compile_init(tgsi_tokens, options);
+ s = c->build.shader;
ralloc_free(c);
+
return s;
}
+
More information about the mesa-commit
mailing list