From ffbec55072ed952db034779e3d0505a61c833397 Mon Sep 17 00:00:00 2001 From: Timothy Arceri Date: Thu, 23 Apr 2020 15:55:14 +1000 Subject: [PATCH] glsl: some nir uniform linker fixes MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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 Part-of: --- src/compiler/glsl/gl_nir_link_uniforms.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/compiler/glsl/gl_nir_link_uniforms.c b/src/compiler/glsl/gl_nir_link_uniforms.c index 175af7c7edb..6e24647d586 100644 --- a/src/compiler/glsl/gl_nir_link_uniforms.c +++ b/src/compiler/glsl/gl_nir_link_uniforms.c @@ -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 = -- 2.30.2