Mesa (master): nir/lower_io: fix array_length lowering if buffer is smaller than offset

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Thu Jan 21 12:44:36 UTC 2021


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

Author: Rhys Perry <pendingchaos02 at gmail.com>
Date:   Mon Dec  7 14:44:15 2020 +0000

nir/lower_io: fix array_length lowering if buffer is smaller than offset

Matches SPIR-V -> NIR implementation of OpArrayLength.

Signed-off-by: Rhys Perry <pendingchaos02 at gmail.com>
Reviewed-by: Daniel Schürmann <daniel at schuermann.dev>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/8163>

---

 src/compiler/nir/nir_lower_io.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/compiler/nir/nir_lower_io.c b/src/compiler/nir/nir_lower_io.c
index 2a0d98d8af4..22d319f74c3 100644
--- a/src/compiler/nir/nir_lower_io.c
+++ b/src/compiler/nir/nir_lower_io.c
@@ -1986,9 +1986,9 @@ lower_explicit_io_array_length(nir_builder *b, nir_intrinsic_instr *intrin,
    nir_ssa_def *index = addr_to_index(b, addr, addr_format);
    nir_ssa_def *offset = addr_to_offset(b, addr, addr_format);
 
-   nir_ssa_def *arr_size =
-      nir_idiv(b, nir_isub(b, nir_get_ssbo_size(b, index), offset),
-                  nir_imm_int(b, stride));
+   nir_ssa_def *arr_size = nir_get_ssbo_size(b, index);
+   arr_size = nir_imax(b, nir_isub(b, arr_size, offset), nir_imm_int(b, 0u));
+   arr_size = nir_idiv(b, arr_size, nir_imm_int(b, stride));
 
    nir_ssa_def_rewrite_uses(&intrin->dest.ssa, nir_src_for_ssa(arr_size));
    nir_instr_remove(&intrin->instr);



More information about the mesa-commit mailing list