From a638971929a4f7a3f3f4796f92c4edec8ec4c8ae Mon Sep 17 00:00:00 2001 From: Antia Puentes Date: Sat, 25 Aug 2018 15:15:30 +0200 Subject: [PATCH] nir/linker: Fill the uniform's BLOCK_INDEX Binding comparison is used to determine the block the uniform is part of. Note that to do the binding comparison we need the information in UniformBlocks[] and ShaderStorageBlocks[] to be available, so we have to call gl_nir_link_uniform_blocks() before linking the uniforms. v2: add missing break (Timothy) Reviewed-by: Timothy Arceri --- src/compiler/glsl/gl_nir_link_uniforms.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/compiler/glsl/gl_nir_link_uniforms.c b/src/compiler/glsl/gl_nir_link_uniforms.c index 24fcd3d..a17d136 100644 --- a/src/compiler/glsl/gl_nir_link_uniforms.c +++ b/src/compiler/glsl/gl_nir_link_uniforms.c @@ -478,11 +478,32 @@ nir_link_uniform(struct gl_context *ctx, else uniform->offset = 0; + int buffer_block_index = -1; + /* If the uniform is inside a uniform block determine its block index by + * comparing the bindings, we can not use names. + */ + if (nir_variable_is_in_block(state->current_var)) { + struct gl_uniform_block *blocks = nir_variable_is_in_ssbo(state->current_var) ? + prog->data->ShaderStorageBlocks : prog->data->UniformBlocks; + + 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; + } + } + assert(buffer_block_index >= 0); + } + + uniform->block_index = buffer_block_index; + /* @FIXME: the initialization of the following will be done as we * implement support for their specific features, like SSBO, atomics, * etc. */ - uniform->block_index = -1; uniform->builtin = false; uniform->atomic_buffer_index = -1; uniform->top_level_array_size = 0; -- 2.7.4