Mesa (staging/21.1): radeonsi: don't create an infinite number of variants
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Mon Aug 9 21:30:00 UTC 2021
Module: Mesa
Branch: staging/21.1
Commit: e6c725a44be73e3b168cd5a475de104fcbbaf476
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=e6c725a44be73e3b168cd5a475de104fcbbaf476
Author: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer at amd.com>
Date: Fri Jul 30 11:48:28 2021 +0200
radeonsi: don't create an infinite number of variants
If a shader has code like this:
uniform float timestamp;
...
if (timestamp > 0.0)
do_something()
And timestamp is modified each frame, we'll end up generating a new
variant per frame.
This commit introduces a hard limit on the number of variants we generate
for a single shader.
Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/5121
Fixes: b7501184b90 ("radeonsi: implement inlinable uniforms")
Reviewed-by: Marek Olšák <marek.olsak at amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12138>
(cherry picked from commit 9fe8ae3fcde8d7608d5b03ace51a4a3cebf18fee)
---
.pick_status.json | 2 +-
src/gallium/drivers/radeonsi/si_shader.h | 3 +++
src/gallium/drivers/radeonsi/si_state_shaders.c | 25 +++++++++++++++++++++++--
3 files changed, 27 insertions(+), 3 deletions(-)
diff --git a/.pick_status.json b/.pick_status.json
index eec1cba2f3a..2714a799e7e 100644
--- a/.pick_status.json
+++ b/.pick_status.json
@@ -400,7 +400,7 @@
"description": "radeonsi: don't create an infinite number of variants",
"nominated": true,
"nomination_type": 1,
- "resolution": 0,
+ "resolution": 1,
"main_sha": null,
"because_sha": "b7501184b90a20015885b3f2276a7a5ceaef31a7"
},
diff --git a/src/gallium/drivers/radeonsi/si_shader.h b/src/gallium/drivers/radeonsi/si_shader.h
index c58388ee325..ab11a185216 100644
--- a/src/gallium/drivers/radeonsi/si_shader.h
+++ b/src/gallium/drivers/radeonsi/si_shader.h
@@ -694,6 +694,9 @@ struct si_shader_key {
unsigned inline_uniforms:1;
+ /* This must be kept last to limit the number of variants
+ * depending only on the uniform values.
+ */
uint32_t inlined_uniform_values[MAX_INLINABLE_UNIFORMS];
} opt;
};
diff --git a/src/gallium/drivers/radeonsi/si_state_shaders.c b/src/gallium/drivers/radeonsi/si_state_shaders.c
index addea7a61d0..e5e5f1a6546 100644
--- a/src/gallium/drivers/radeonsi/si_state_shaders.c
+++ b/src/gallium/drivers/radeonsi/si_state_shaders.c
@@ -2232,10 +2232,31 @@ current_not_ready:
simple_mtx_lock(&sel->mutex);
+ /* Compute the size of the key without the uniform values. */
+ size_t s = (void*)&key->opt.inlined_uniform_values - (void*)key;
+ int variant_count = 0;
+ const int max_inline_uniforms_variants = 5;
+
/* Find the shader variant. */
for (iter = sel->first_variant; iter; iter = iter->next_variant) {
- /* Don't check the "current" shader. We checked it above. */
- if (current != iter && memcmp(&iter->key, key, sizeof(*key)) == 0) {
+ if (memcmp(&iter->key, key, s) == 0) {
+ /* Check the inlined uniform values separatly, and count
+ * the number of variants based on them.
+ */
+ if (key->opt.inline_uniforms &&
+ memcmp(iter->key.opt.inlined_uniform_values,
+ key->opt.inlined_uniform_values,
+ MAX_INLINABLE_UNIFORMS * 4) != 0) {
+ if (variant_count++ > max_inline_uniforms_variants) {
+ /* Too many variants. Disable inlining for this shader. */
+ key->opt.inline_uniforms = 0;
+ memset(key->opt.inlined_uniform_values, 0, MAX_INLINABLE_UNIFORMS * 4);
+ simple_mtx_unlock(&sel->mutex);
+ goto again;
+ }
+ continue;
+ }
+
simple_mtx_unlock(&sel->mutex);
if (unlikely(!util_queue_fence_is_signalled(&iter->ready))) {
More information about the mesa-commit
mailing list