Mesa (main): spirv: Fix array length of buffers larger than INT32_MAX.

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Fri Jul 22 18:19:43 UTC 2022


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

Author: Ian Romanick <ian.d.romanick at intel.com>
Date:   Tue Feb  9 11:18:48 2021 -0800

spirv: Fix array length of buffers larger than INT32_MAX.

Like 90a8fb03556e.

fossil-db results:

All Skylake and newer Intel platforms had similar results. (Ice Lake shown)
Instructions in all programs: 141442369 -> 141442363 (-0.0%)
Instructions helped: 1

Cycles in all programs: 9099270231 -> 9099270187 (-0.0%)
Cycles helped: 1

Reviewed-by: Emma Anholt <emma at anholt.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/17637>

---

 src/compiler/spirv/vtn_variables.c | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)

diff --git a/src/compiler/spirv/vtn_variables.c b/src/compiler/spirv/vtn_variables.c
index 0eb7f60b24c..89e39963086 100644
--- a/src/compiler/spirv/vtn_variables.c
+++ b/src/compiler/spirv/vtn_variables.c
@@ -2647,13 +2647,11 @@ vtn_handle_variables(struct vtn_builder *b, SpvOp opcode,
 
          /* array_length = max(buffer_size - offset, 0) / stride */
          nir_ssa_def *array_length =
-            nir_idiv(&b->nb,
-                     nir_imax(&b->nb,
-                              nir_isub(&b->nb,
-                                       buf_size,
-                                       nir_imm_int(&b->nb, offset)),
-                              nir_imm_int(&b->nb, 0u)),
-                     nir_imm_int(&b->nb, stride));
+            nir_udiv_imm(&b->nb,
+                         nir_usub_sat(&b->nb,
+                                      buf_size,
+                                      nir_imm_int(&b->nb, offset)),
+                         stride);
 
          vtn_push_nir_ssa(b, w[2], array_length);
       }



More information about the mesa-commit mailing list