From a02d8e040fb6cbf43a75932104e2b49807723280 Mon Sep 17 00:00:00 2001 From: Timothy Arceri Date: Tue, 4 Feb 2020 10:00:39 +1100 Subject: [PATCH] glsl: correctly find block index when linking glsl with nir linker MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit The existing code for spirv expects all vars to have explicit bindings set which is not true for glsl. Reviewed-by: Alejandro Piñeiro Part-of: --- src/compiler/glsl/gl_nir_link_uniforms.c | 34 +++++++++++++++++++++--- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/src/compiler/glsl/gl_nir_link_uniforms.c b/src/compiler/glsl/gl_nir_link_uniforms.c index 57a5595b34d..abf6b6e74a5 100644 --- a/src/compiler/glsl/gl_nir_link_uniforms.c +++ b/src/compiler/glsl/gl_nir_link_uniforms.c @@ -768,10 +768,36 @@ nir_link_uniform(struct gl_context *ctx, int num_blocks = nir_variable_is_in_ssbo(state->current_var) ? prog->data->NumShaderStorageBlocks : prog->data->NumUniformBlocks; - for (unsigned i = 0; i < num_blocks; i++) { - if (state->current_var->data.binding == blocks[i].Binding) { - buffer_block_index = i; - break; + if (!prog->data->spirv) { + bool is_interface_array = + glsl_without_array(state->current_var->type) == state->current_var->interface_type && + glsl_type_is_array(state->current_var->type); + + const char *ifc_name = + glsl_get_type_name(state->current_var->interface_type); + if (is_interface_array) { + unsigned l = strlen(ifc_name); + for (unsigned i = 0; i < num_blocks; i++) { + if (strncmp(ifc_name, blocks[i].Name, l) == 0 && + blocks[i].Name[l] == '[') { + buffer_block_index = i; + break; + } + } + } else { + for (unsigned i = 0; i < num_blocks; i++) { + if (strcmp(ifc_name, blocks[i].Name) == 0) { + buffer_block_index = i; + break; + } + } + } + } else { + for (unsigned i = 0; i < num_blocks; i++) { + if (state->current_var->data.binding == blocks[i].Binding) { + buffer_block_index = i; + break; + } } } assert(buffer_block_index >= 0); -- 2.30.2