Module: Mesa Branch: staging/23.0 Commit: 8b9b246a2f835638af2c5e33ba4cb716a5f3ac8c URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=8b9b246a2f835638af2c5e33ba4cb716a5f3ac8c
Author: Karol Herbst <[email protected]> Date: Wed Feb 22 04:40:24 2023 +0100 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 <[email protected]> Reviewed-by: Faith Ekstrand <[email protected]> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/21458> (cherry picked from commit 56a9aad4010ff9f2c0afcadec0ac61a6274de0a3) --- .pick_status.json | 2 +- src/compiler/nir/nir_deref.c | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/.pick_status.json b/.pick_status.json index 8ef17915875..8254455f9ae 100644 --- a/.pick_status.json +++ b/.pick_status.json @@ -4,7 +4,7 @@ "description": "nir/deref: don't replace casts with deref_struct if we'd lose the stride", "nominated": true, "nomination_type": 1, - "resolution": 0, + "resolution": 1, "main_sha": null, "because_sha": "b779baa9bf95ca259779fa028a7b822bf8a17f46" }, 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);
