From 90a8fb03556eb9330c082a8fd696f40d707ec822 Mon Sep 17 00:00:00 2001 From: Georg Lehmann Date: Mon, 11 Jul 2022 20:43:52 +0200 Subject: [PATCH] nir/lower_io: Fix array length of buffers larger than INT32_MAX. Before, if the ssbo is too large this would always return 0. Also, this code is easier to optimize, so the common case of offset 0 and pot stride results in one ushr instead of 5+ instructions. Signed-off-by: Georg Lehmann Reviewed-by: Emma Anholt Reviewed-by: Jason Ekstrand Part-of: --- src/compiler/nir/nir_lower_io.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/compiler/nir/nir_lower_io.c b/src/compiler/nir/nir_lower_io.c index 9cb400b5a6e..57eb3003618 100644 --- a/src/compiler/nir/nir_lower_io.c +++ b/src/compiler/nir/nir_lower_io.c @@ -2128,8 +2128,8 @@ lower_explicit_io_array_length(nir_builder *b, nir_intrinsic_instr *intrin, unsigned access = nir_intrinsic_access(intrin); nir_ssa_def *arr_size = nir_get_ssbo_size(b, index, .access=access); - 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)); + arr_size = nir_usub_sat(b, arr_size, offset); + arr_size = nir_udiv_imm(b, arr_size, stride); nir_ssa_def_rewrite_uses(&intrin->dest.ssa, arr_size); nir_instr_remove(&intrin->instr);