zink: fix handling for ssbos that are just runtime arrays
authorMike Blumenkrantz <michael.blumenkrantz@gmail.com>
Mon, 12 Sep 2022 15:08:20 +0000 (11:08 -0400)
committerMarge Bot <emma+marge@anholt.net>
Mon, 26 Sep 2022 21:58:58 +0000 (21:58 +0000)
this used to correctly calculate runtime array size as zero, but since the
switch to glsl_get_explicit_size(), zero can no longer be returned

Reviewed-by: Dave Airlie <airlied@redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/18784>

src/gallium/drivers/zink/zink_compiler.c

index 5b94903..6004b0f 100644 (file)
@@ -2280,8 +2280,16 @@ unbreak_bos(nir_shader *shader, struct zink_shader *zs, bool needs_size)
       const struct glsl_type *interface_type = var->interface_type ? glsl_without_array(var->interface_type) : NULL;
       if (interface_type) {
          unsigned block_size = glsl_get_explicit_size(interface_type, true);
-         block_size = DIV_ROUND_UP(block_size, sizeof(float) * 4);
-         size = MAX2(size, block_size);
+         if (glsl_get_length(interface_type) == 1) {
+            /* handle bare unsized ssbo arrays: glsl_get_explicit_size always returns type-aligned sizes */
+            const struct glsl_type *f = glsl_get_struct_field(interface_type, 0);
+            if (glsl_type_is_array(f) && !glsl_array_size(f))
+               block_size = 0;
+         }
+         if (block_size) {
+            block_size = DIV_ROUND_UP(block_size, sizeof(float) * 4);
+            size = MAX2(size, block_size);
+         }
       }
       if (var->data.mode == nir_var_mem_ubo) {
          if (var->data.driver_location)