glsl: some nir uniform linker fixes
authorTimothy Arceri <tarceri@itsqueeze.com>
Thu, 23 Apr 2020 05:55:14 +0000 (15:55 +1000)
committerMarge Bot <eric+marge@anholt.net>
Fri, 24 Apr 2020 08:31:01 +0000 (08:31 +0000)
This fixes find_and_update_named_uniform_storage() for subroutines
and also updates num_shader_uniform_components for non opaque
uniforms.

The following patch will ensure this type of bug won't happen again.

Reviewed-by: Alejandro PiƱeiro <apinheiro@igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4721>

src/compiler/glsl/gl_nir_link_uniforms.c

index 175af7c7edb5cc6d0e2f99318874ffd4d6d88310..6e24647d58658037d1e4c93ccb28d03122d95336 100644 (file)
@@ -466,13 +466,13 @@ struct nir_link_uniforms_state {
    unsigned num_hidden_uniforms;
    unsigned num_values;
    unsigned max_uniform_location;
-   unsigned next_subroutine;
 
    /* per-shader stage */
    unsigned next_bindless_image_index;
    unsigned next_bindless_sampler_index;
    unsigned next_image_index;
    unsigned next_sampler_index;
+   unsigned next_subroutine;
    unsigned num_shader_samplers;
    unsigned num_shader_images;
    unsigned num_shader_uniform_components;
@@ -770,6 +770,23 @@ find_and_update_named_uniform_storage(struct gl_context *ctx,
 
             if (!uniform->is_shader_storage)
                state->num_shader_uniform_components += values;
+         } else {
+            if (glsl_get_base_type(type_no_array) == GLSL_TYPE_SUBROUTINE) {
+               struct gl_linked_shader *sh = prog->_LinkedShaders[stage];
+
+               uniform->opaque[stage].index = state->next_subroutine;
+               uniform->opaque[stage].active = true;
+
+               sh->Program->sh.NumSubroutineUniforms++;
+
+               /* Increment the subroutine index by 1 for non-arrays and by the
+                * number of array elements for arrays.
+                */
+               state->next_subroutine += MAX2(1, uniform->array_elements);
+            }
+
+            if (!state->var_is_in_block)
+               state->num_shader_uniform_components += values;
          }
 
          struct hash_entry *entry =