Module: Mesa
Branch: main
Commit: f8966598940ad46fb1ff2cbd9c23013289ef0736
URL:    
http://cgit.freedesktop.org/mesa/mesa/commit/?id=f8966598940ad46fb1ff2cbd9c23013289ef0736

Author: Karol Herbst <kher...@redhat.com>
Date:   Mon Jan 15 12:37:02 2024 +0100

rusticl/kernel: run opt/lower_memcpy later to fix a crash

nir_opt_memcpy requires explicit types to function properly. So run them
after lowering vars to explicit types.

Cc: mesa-stable
Signed-off-by: Karol Herbst <kher...@redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/27068>

---

 src/gallium/frontends/rusticl/core/kernel.rs | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/src/gallium/frontends/rusticl/core/kernel.rs 
b/src/gallium/frontends/rusticl/core/kernel.rs
index a73638fdb54..05296c0cd0e 100644
--- a/src/gallium/frontends/rusticl/core/kernel.rs
+++ b/src/gallium/frontends/rusticl/core/kernel.rs
@@ -317,7 +317,7 @@ where
     res
 }
 
-fn opt_nir(nir: &mut NirShader, dev: &Device) {
+fn opt_nir(nir: &mut NirShader, dev: &Device, has_explicit_types: bool) {
     let nir_options = unsafe {
         &*dev
             .screen
@@ -342,7 +342,9 @@ fn opt_nir(nir: &mut NirShader, dev: &Device) {
         }
 
         progress |= nir_pass!(nir, nir_opt_deref);
-        progress |= nir_pass!(nir, nir_opt_memcpy);
+        if has_explicit_types {
+            progress |= nir_pass!(nir, nir_opt_memcpy);
+        }
         progress |= nir_pass!(nir, nir_opt_dce);
         progress |= nir_pass!(nir, nir_opt_undef);
         progress |= nir_pass!(nir, nir_opt_constant_folding);
@@ -451,11 +453,10 @@ fn lower_and_optimize_nir(
     printf_opts.max_buffer_size = dev.printf_buffer_size() as u32;
     nir_pass!(nir, nir_lower_printf, &printf_opts);
 
-    opt_nir(nir, dev);
+    opt_nir(nir, dev, false);
 
     let mut args = KernelArg::from_spirv_nir(args, nir);
     let mut internal_args = Vec::new();
-    nir_pass!(nir, nir_lower_memcpy);
 
     let dv_opts = nir_remove_dead_variables_options {
         can_remove_var: Some(can_remove_var),
@@ -626,7 +627,8 @@ fn lower_and_optimize_nir(
         Some(glsl_get_cl_type_size_align),
     );
 
-    opt_nir(nir, dev);
+    opt_nir(nir, dev, true);
+    nir_pass!(nir, nir_lower_memcpy);
 
     nir_pass!(
         nir,
@@ -655,7 +657,7 @@ fn lower_and_optimize_nir(
 
     nir_pass!(nir, nir_lower_convert_alu_types, None);
 
-    opt_nir(nir, dev);
+    opt_nir(nir, dev, true);
 
     /* before passing it into drivers, assign locations as drivers might 
remove nir_variables or
      * other things we depend on

Reply via email to