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 <tarceri@itsqueeze.com>
This commit is contained in:
Antia Puentes
2018-08-25 15:15:30 +02:00
committed by Alejandro Piñeiro
parent f239e22813
commit a638971929

View File

@@ -478,11 +478,32 @@ nir_link_uniform(struct gl_context *ctx,
else else
uniform->offset = 0; 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 /* @FIXME: the initialization of the following will be done as we
* implement support for their specific features, like SSBO, atomics, * implement support for their specific features, like SSBO, atomics,
* etc. * etc.
*/ */
uniform->block_index = -1;
uniform->builtin = false; uniform->builtin = false;
uniform->atomic_buffer_index = -1; uniform->atomic_buffer_index = -1;
uniform->top_level_array_size = 0; uniform->top_level_array_size = 0;