From 56a9aad4010ff9f2c0afcadec0ac61a6274de0a3 Mon Sep 17 00:00:00 2001 From: Karol Herbst Date: Wed, 22 Feb 2023 04:40:24 +0100 Subject: [PATCH] nir/deref: don't replace casts with deref_struct if we'd lose the stride The result might be used in a deref_ptr_as_array, which requires a proper stride within lower_explicit_io. If we'd lose that information or end up with a different stride don't execute this optimization. Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/8289 Fixes: b779baa9bf95 ("nir/deref: fix struct wrapper casts. (v3)") Signed-off-by: Karol Herbst Reviewed-by: Faith Ekstrand Part-of: --- src/compiler/nir/nir_deref.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/compiler/nir/nir_deref.c b/src/compiler/nir/nir_deref.c index 3de401d9853..9289b23f6a2 100644 --- a/src/compiler/nir/nir_deref.c +++ b/src/compiler/nir/nir_deref.c @@ -1143,7 +1143,12 @@ opt_replace_struct_wrapper_cast(nir_builder *b, nir_deref_instr *cast) if (glsl_get_struct_field_offset(parent->type, 0) != 0) return false; - if (cast->type != glsl_get_struct_field(parent->type, 0)) + const struct glsl_type *field_type = glsl_get_struct_field(parent->type, 0); + if (cast->type != field_type) + return false; + + /* we can't drop the stride information */ + if (cast->cast.ptr_stride != glsl_get_explicit_stride(field_type)) return false; nir_deref_instr *replace = nir_build_deref_struct(b, parent, 0);