Module: Mesa
Branch: staging/22.2
Commit: c837ae50278d0550e306080fad2655bca4544558
URL:    
http://cgit.freedesktop.org/mesa/mesa/commit/?id=c837ae50278d0550e306080fad2655bca4544558

Author: Jessica Clarke <[email protected]>
Date:   Wed Nov 30 00:11:45 2022 +0000

panfrost/blend: Fix invalid const values leading to NIR validation errors

Using a designated initializer like this leaves padding bits, which form
part of the aliasing u64/f64 member of the union, uninitialised, but a
nir_const_value must always have the unused bits zeroed out. Thus, use
the nir_const_value_for_float helper instead like everywhere else which
will do a memset 0 for us first.

Without this, using the pan_blend shader in a build with validation
enabled fails with:

  NIR validation failed after nir_lower_vars_to_ssa
  ...
            vec4 32 ssa_58 = load_const (0x3f7cfcfd /* 0.988235 */, 0x3f7cfcfd 
/* 0.988235 */, 0x3f7cfcfd /* 0.988235 */, 0x3f800000 /* 1.000000 */)
  error: memcmp(val, &cmp_val, sizeof(cmp_val)) == 0 
(../src/compiler/nir/nir_validate.c:976)

Fixes: 1378c67bcf9e ("panfrost/blend: Inline blend constants")
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/20071>
(cherry picked from commit 750325730bb84981f68d78b205fb0cec1e165100)

---

 .pick_status.json            | 2 +-
 src/panfrost/lib/pan_blend.c | 8 ++++----
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/.pick_status.json b/.pick_status.json
index a1d7e2e7813..eafae483fe4 100644
--- a/.pick_status.json
+++ b/.pick_status.json
@@ -157,7 +157,7 @@
         "description": "panfrost/blend: Fix invalid const values leading to 
NIR validation errors",
         "nominated": true,
         "nomination_type": 1,
-        "resolution": 0,
+        "resolution": 1,
         "main_sha": null,
         "because_sha": "1378c67bcf9e16aea98ddb8cb6bd37b9ed4e3a81"
     },
diff --git a/src/panfrost/lib/pan_blend.c b/src/panfrost/lib/pan_blend.c
index 0ffcd0162db..611c1a74597 100644
--- a/src/panfrost/lib/pan_blend.c
+++ b/src/panfrost/lib/pan_blend.c
@@ -583,10 +583,10 @@ pan_inline_blend_constants(nir_builder *b, nir_instr 
*instr, void *data)
 
         float *floats = data;
         const nir_const_value constants[4] = {
-                { .f32 = floats[0] },
-                { .f32 = floats[1] },
-                { .f32 = floats[2] },
-                { .f32 = floats[3] }
+                nir_const_value_for_float(floats[0], 32),
+                nir_const_value_for_float(floats[1], 32),
+                nir_const_value_for_float(floats[2], 32),
+                nir_const_value_for_float(floats[3], 32)
         };
 
         b->cursor = nir_after_instr(instr);

Reply via email to