Mesa (staging/21.3): pan/bi: Fix load_const of 1-bit booleans
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Mon Jan 3 19:00:45 UTC 2022
Module: Mesa
Branch: staging/21.3
Commit: 2406855cfb17fbe8b3b51b81cb585fd6174c598e
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=2406855cfb17fbe8b3b51b81cb585fd6174c598e
Author: Alyssa Rosenzweig <alyssa at collabora.com>
Date: Sat Jan 1 20:38:46 2022 -0500
pan/bi: Fix load_const of 1-bit booleans
For historical reasons, we ingest 1-bit booleans in NIR but expand them
to 16/32-bit booleans in the backend IR. We need to handle this case
when loading boolean constants, extending from 1-bit to 16/32-bit as
required. This issue is masked by effective constant folding for
booleans, but is visible in a shader from Firefox WebRender.
Fixes: 646e03c4519 ("pan/bi: Temporarily switch back to 0/~0 bools")
Signed-off-by: Alyssa Rosenzweig <alyssa at collabora.com>
Reported-by: Icecream95
Closes: #5797
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/14371>
(cherry picked from commit 29d319c767394b685e2b421a89a7e8e7103e2688)
---
.pick_status.json | 2 +-
src/panfrost/bifrost/bifrost_compile.c | 4 +++-
src/panfrost/bifrost/compiler.h | 23 +++++++++++++++++++----
3 files changed, 23 insertions(+), 6 deletions(-)
diff --git a/.pick_status.json b/.pick_status.json
index 7ac929737c2..e3cbb0a65eb 100644
--- a/.pick_status.json
+++ b/.pick_status.json
@@ -67,7 +67,7 @@
"description": "pan/bi: Fix load_const of 1-bit booleans",
"nominated": true,
"nomination_type": 1,
- "resolution": 0,
+ "resolution": 1,
"main_sha": null,
"because_sha": "646e03c451980c7082a139ba4a6c7eb370822cc7"
},
diff --git a/src/panfrost/bifrost/bifrost_compile.c b/src/panfrost/bifrost/bifrost_compile.c
index 44bf2334565..fabdb2bd618 100644
--- a/src/panfrost/bifrost/bifrost_compile.c
+++ b/src/panfrost/bifrost/bifrost_compile.c
@@ -1420,7 +1420,9 @@ bi_emit_load_const(bi_builder *b, nir_load_const_instr *instr)
uint32_t acc = 0;
for (unsigned i = 0; i < instr->def.num_components; ++i) {
- unsigned v = nir_const_value_as_uint(instr->value[i], instr->def.bit_size);
+ uint32_t v = nir_const_value_as_uint(instr->value[i], instr->def.bit_size);
+
+ v = bi_extend_constant(v, instr->def.bit_size);
acc |= (v << (i * instr->def.bit_size));
}
diff --git a/src/panfrost/bifrost/compiler.h b/src/panfrost/bifrost/compiler.h
index 72a878f13b8..e5dbbe628b3 100644
--- a/src/panfrost/bifrost/compiler.h
+++ b/src/panfrost/bifrost/compiler.h
@@ -701,6 +701,19 @@ bi_temp_reg(bi_context *ctx)
return bi_get_index(ctx->reg_alloc++, true, 0);
}
+/* NIR booleans are 1-bit (0/1). For now, backend IR booleans are N-bit
+ * (0/~0) where N depends on the context. This requires us to sign-extend
+ * when converting constants from NIR to the backend IR.
+ */
+static inline uint32_t
+bi_extend_constant(uint32_t constant, unsigned bit_size)
+{
+ if (bit_size == 1 && constant != 0)
+ return ~0;
+ else
+ return constant;
+}
+
/* Inline constants automatically, will be lowered out by bi_lower_fau where a
* constant is not allowed. load_const_to_scalar gaurantees that this makes
* sense */
@@ -708,11 +721,13 @@ bi_temp_reg(bi_context *ctx)
static inline bi_index
bi_src_index(nir_src *src)
{
- if (nir_src_is_const(*src) && nir_src_bit_size(*src) <= 32)
- return bi_imm_u32(nir_src_as_uint(*src));
- else if (src->is_ssa)
+ if (nir_src_is_const(*src) && nir_src_bit_size(*src) <= 32) {
+ uint32_t v = nir_src_as_uint(*src);
+
+ return bi_imm_u32(bi_extend_constant(v, nir_src_bit_size(*src)));
+ } else if (src->is_ssa) {
return bi_get_index(src->ssa->index, false, 0);
- else {
+ } else {
assert(!src->reg.indirect);
return bi_get_index(src->reg.reg->index, true, 0);
}
More information about the mesa-commit
mailing list