lavapipe, nir: Fix wrong array index scaling in nir_collect_src_uniforms
authorRoland Scheidegger <sroland@vmware.com>
Thu, 23 Feb 2023 22:08:10 +0000 (23:08 +0100)
committerMarge Bot <emma+marge@anholt.net>
Fri, 24 Feb 2023 16:13:55 +0000 (16:13 +0000)
The scaling needs to be ubo * MAX_INLINABLE_UNIFORMS, not
ubo * PIPE_MAX_CONSTANT_BUFFERS, otherwise accesses beyond buffer size
will result for ubo >= 4 (and we'd also access the wrong values later
for other non-zero ubo indices).

Fixes: a7696a4d98bc ("lavapipe: Fix bad array index scale factor in lvp_inline_uniforms pass")
Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/21506>

src/compiler/nir/nir_inline_uniforms.c

index 9194c20..10dcc23 100644 (file)
@@ -148,7 +148,7 @@ nir_collect_src_uniforms(const nir_src *src, int component,
 
          /* Already recorded by other one */
          for (int i = 0; i < num_offsets[ubo]; i++) {
-            if (uni_offsets[ubo * MAX_NUM_BO + i] == offset)
+            if (uni_offsets[ubo * MAX_INLINABLE_UNIFORMS + i] == offset)
                return true;
          }
 
@@ -157,7 +157,7 @@ nir_collect_src_uniforms(const nir_src *src, int component,
             return false;
 
          /* Record the uniform offset. */
-         uni_offsets[ubo * MAX_NUM_BO + num_offsets[ubo]++] = offset;
+         uni_offsets[ubo * MAX_INLINABLE_UNIFORMS + num_offsets[ubo]++] = offset;
          return true;
       }
       return false;