nir/lower_amul: Use num_ubos/ssbos instead of recomputing it.
authorEric Anholt <eric@anholt.net>
Wed, 8 Jul 2020 19:43:16 +0000 (12:43 -0700)
committerMarge Bot <eric+marge@anholt.net>
Wed, 5 Aug 2020 04:35:05 +0000 (04:35 +0000)
Now that num_ubos is correctly maintained, we can just trust it.  Fixes an
assertion failure in freedreno I triggered on
dEQP-GLES31.functional.ubo.random.all_per_block_buffers.1 for reasons I
don't really understand.

Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Reviewed-by: Rob Clark <robdclark@chromium.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6179>

src/compiler/nir/nir_lower_amul.c

index 52a7d8a23023002f1a9da511680201fe5a85b5d9..7b2108cbc78b77a41d91fc78651c1d57c18c109d 100644 (file)
@@ -48,6 +48,8 @@
  */
 
 typedef struct {
+   nir_shader *shader;
+
    int (*type_size)(const struct glsl_type *, bool);
 
    /* Tables of UBOs and SSBOs mapping driver_location/base whether
@@ -102,7 +104,7 @@ large_ubo(lower_state *state, nir_src src)
    if (!nir_src_is_const(src))
       return state->has_large_ubo;
    unsigned idx = nir_src_as_uint(src);
-   assert(idx < state->max_slot);
+   assert(idx < state->shader->info.num_ubos);
    return state->large_ubos[idx];
 }
 
@@ -112,7 +114,7 @@ large_ssbo(lower_state *state, nir_src src)
    if (!nir_src_is_const(src))
       return state->has_large_ssbo;
    unsigned idx = nir_src_as_uint(src);
-   assert(idx < state->max_slot);
+   assert(idx < state->shader->info.num_ssbos);
    return state->large_ssbos[idx];
 }
 
@@ -232,25 +234,14 @@ nir_lower_amul(nir_shader *shader,
    assert(shader->options->has_imul24);
    assert(type_size);
 
-   /* uniforms list actually includes ubo's and ssbo's: */
-   int max_slot = 0;
-
-   nir_foreach_variable_with_modes (var, shader,
-                                    nir_var_mem_ubo | nir_var_mem_ssbo) {
-      int base = var->data.binding;
-      int size = MAX2(1, glsl_array_size(var->type));
-
-      max_slot = MAX2(max_slot, base + size);
-   }
-
-   NIR_VLA_FILL(bool, large_ubos, max_slot, 0);
-   NIR_VLA_FILL(bool, large_ssbos, max_slot, 0);
+   NIR_VLA_FILL(bool, large_ubos, shader->info.num_ubos, 0);
+   NIR_VLA_FILL(bool, large_ssbos, shader->info.num_ssbos, 0);
 
    lower_state state = {
-         .type_size = type_size,
-         .large_ubos = large_ubos,
-         .large_ssbos = large_ssbos,
-         .max_slot = max_slot,
+      .shader = shader,
+      .type_size = type_size,
+      .large_ubos = large_ubos,
+      .large_ssbos = large_ssbos,
    };
 
    /* Figure out which UBOs or SSBOs are large enough to be