Mesa (main): panfrost: Refactor variant selection code
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Mon May 2 14:14:35 UTC 2022
Module: Mesa
Branch: main
Commit: 39788ac703bdf69c93d236f98e0ac81988dcb034
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=39788ac703bdf69c93d236f98e0ac81988dcb034
Author: Alyssa Rosenzweig <alyssa at collabora.com>
Date: Tue Apr 26 14:29:55 2022 -0400
panfrost: Refactor variant selection code
Extract the "compile a new variant" routine from the "select and bind a variant"
routine. This allows us to simplify the control flow, eliminating the `compiled`
boolean on the shader structure.
Signed-off-by: Alyssa Rosenzweig <alyssa at collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/16173>
---
src/gallium/drivers/panfrost/pan_context.c | 91 +++++++++++++++---------------
src/gallium/drivers/panfrost/pan_context.h | 3 -
2 files changed, 47 insertions(+), 47 deletions(-)
diff --git a/src/gallium/drivers/panfrost/pan_context.c b/src/gallium/drivers/panfrost/pan_context.c
index 0ede262299e..59c3f9bed4e 100644
--- a/src/gallium/drivers/panfrost/pan_context.c
+++ b/src/gallium/drivers/panfrost/pan_context.c
@@ -428,6 +428,51 @@ update_so_info(struct pipe_stream_output_info *so_info,
return so_outputs;
}
+static unsigned
+panfrost_new_variant_locked(
+ struct panfrost_context *ctx,
+ struct panfrost_shader_variants *variants,
+ struct panfrost_shader_key *key)
+{
+ unsigned variant = variants->variant_count++;
+
+ if (variants->variant_count > variants->variant_space) {
+ unsigned old_space = variants->variant_space;
+
+ variants->variant_space *= 2;
+ if (variants->variant_space == 0)
+ variants->variant_space = 1;
+
+ /* Arbitrary limit to stop runaway programs from
+ * creating an unbounded number of shader variants. */
+ assert(variants->variant_space < 1024);
+
+ unsigned msize = sizeof(struct panfrost_shader_state);
+ variants->variants = realloc(variants->variants,
+ variants->variant_space * msize);
+
+ memset(&variants->variants[old_space], 0,
+ (variants->variant_space - old_space) * msize);
+ }
+
+ variants->variants[variant].key = *key;
+
+ struct panfrost_shader_state *shader_state = &variants->variants[variant];
+
+ /* We finally have a variant, so compile it */
+ panfrost_shader_compile(ctx->base.screen,
+ &ctx->shaders, &ctx->descs,
+ variants->nir, shader_state);
+
+ /* Fixup the stream out information */
+ shader_state->stream_output = variants->stream_output;
+ shader_state->so_mask =
+ update_so_info(&shader_state->stream_output,
+ shader_state->info.outputs_written);
+
+ return variant;
+}
+
static void
panfrost_bind_shader_state(
struct pipe_context *pctx,
@@ -459,53 +504,11 @@ panfrost_bind_shader_state(
}
}
- if (variant == -1) {
- /* No variant matched, so create a new one */
- variant = variants->variant_count++;
-
- if (variants->variant_count > variants->variant_space) {
- unsigned old_space = variants->variant_space;
+ if (variant == -1)
+ variant = panfrost_new_variant_locked(ctx, variants, &key);
- variants->variant_space *= 2;
- if (variants->variant_space == 0)
- variants->variant_space = 1;
-
- /* Arbitrary limit to stop runaway programs from
- * creating an unbounded number of shader variants. */
- assert(variants->variant_space < 1024);
-
- unsigned msize = sizeof(struct panfrost_shader_state);
- variants->variants = realloc(variants->variants,
- variants->variant_space * msize);
-
- memset(&variants->variants[old_space], 0,
- (variants->variant_space - old_space) * msize);
- }
-
- variants->variants[variant].key = key;
- }
-
- /* Select this variant */
variants->active_variant = variant;
- struct panfrost_shader_state *shader_state = &variants->variants[variant];
-
- /* We finally have a variant, so compile it */
-
- if (!shader_state->compiled) {
- panfrost_shader_compile(ctx->base.screen,
- &ctx->shaders, &ctx->descs,
- variants->nir, shader_state);
-
- shader_state->compiled = true;
-
- /* Fixup the stream out information */
- shader_state->stream_output = variants->stream_output;
- shader_state->so_mask =
- update_so_info(&shader_state->stream_output,
- shader_state->info.outputs_written);
- }
-
/* TODO: it would be more efficient to release the lock before
* compiling instead of after, but that can race if thread A compiles a
* variant while thread B searches for that same variant */
diff --git a/src/gallium/drivers/panfrost/pan_context.h b/src/gallium/drivers/panfrost/pan_context.h
index b4ad06dbd14..a1791452786 100644
--- a/src/gallium/drivers/panfrost/pan_context.h
+++ b/src/gallium/drivers/panfrost/pan_context.h
@@ -271,9 +271,6 @@ struct panfrost_shader_key {
/* A shader state corresponds to the actual, current variant of the shader */
struct panfrost_shader_state {
- /* Compiled, mapped descriptor, ready for the hardware */
- bool compiled;
-
/* Respectively, shader binary and Renderer State Descriptor */
struct panfrost_pool_ref bin, state;
More information about the mesa-commit
mailing list