nir/linker: Fill the uniform's BLOCK_INDEX
authorAntia Puentes <apuentes@igalia.com>
Sat, 25 Aug 2018 13:15:30 +0000 (15:15 +0200)
committerAlejandro Piñeiro <apinheiro@igalia.com>
Fri, 12 Jul 2019 21:42:41 +0000 (23:42 +0200)
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>
src/compiler/glsl/gl_nir_link_uniforms.c

index 24fcd3db41dd262ad69e57c5a36090c242bd4d20..a17d13639d765ee514d3ea7387b1ffb3e5ac34ae 100644 (file)
@@ -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;