anv: Fix UBO range detection in anv_nir_compute_push_layout
authorJason Ekstrand <jason@jlekstrand.net>
Fri, 3 Apr 2020 17:38:32 +0000 (12:38 -0500)
committerMarge Bot <eric+marge@anholt.net>
Wed, 15 Apr 2020 21:51:55 +0000 (21:51 +0000)
This fixes two bugs:  First, if the same block index showed up twice, we
only pick the first one.  Second, we weren't multiplying by 32.  This
didn't show up in tests because RBA testing is garbage.  Found while
looking at shaders from the UE4 Shooter demo.

Fixes: e03f9652 "anv: Bounds-check pushed UBOs when..."
Reviewed-by: Caio Marcelo de Oliveira Filho <caio.oliveira@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4578>

src/intel/vulkan/anv_nir_compute_push_layout.c

index 3f9572644df18d8522f1e8591a1ccf9973b7f728..960fb1ca4a3a7fd7dc15bcbf12ea09fcb60ccebd 100644 (file)
@@ -208,8 +208,11 @@ anv_nir_compute_push_layout(const struct anv_physical_device *pdevice,
 
                   int ubo_range_idx = -1;
                   for (unsigned i = 0; i < 4; i++) {
-                     if (prog_data->ubo_ranges[i].length > 0 &&
-                         prog_data->ubo_ranges[i].block == index) {
+                     const struct brw_ubo_range *range =
+                        &prog_data->ubo_ranges[i];
+                     if (range->block == index &&
+                         offset + size > range->start * 32 &&
+                         offset < (range->start + range->length) * 32) {
                         ubo_range_idx = i;
                         break;
                      }
@@ -218,14 +221,6 @@ anv_nir_compute_push_layout(const struct anv_physical_device *pdevice,
                   if (ubo_range_idx < 0)
                      break;
 
-                  const struct brw_ubo_range *range =
-                     &prog_data->ubo_ranges[ubo_range_idx];
-                  const uint32_t range_end =
-                     (range->start + range->length) * 32;
-
-                  if (range_end < offset || offset + size <= range->start)
-                     break;
-
                   b.cursor = nir_after_instr(&intrin->instr);
 
                   assert(push_range_idx_map[ubo_range_idx] >= 0);