[Mesa-dev] [PATCH 21/26] nir/linker: update already processed uniforms search for UBOs/SSBOs
Alejandro PiƱeiro
apinheiro at igalia.com
Sat Sep 15 16:18:44 UTC 2018
Until now, we were using the uniform explicit location to check if the
current nir variable already was processed, and entries on the uniform
storage added. But for UBOs/SSBOs, entries are added but we lack a
explicit location.
For those we need to rely on the UBO/SSBO binding (to the nir variable
binding, and the uniform storage block_index). In that case several
uniforms would need to be updated at once.
---
src/compiler/glsl/gl_nir_link_uniforms.c | 78 ++++++++++++++++++++++++++++----
1 file changed, 68 insertions(+), 10 deletions(-)
diff --git a/src/compiler/glsl/gl_nir_link_uniforms.c b/src/compiler/glsl/gl_nir_link_uniforms.c
index 5a5431433e9..5297e7b0557 100644
--- a/src/compiler/glsl/gl_nir_link_uniforms.c
+++ b/src/compiler/glsl/gl_nir_link_uniforms.c
@@ -130,20 +130,79 @@ nir_setup_uniform_remap_tables(struct gl_context *ctx,
}
}
+static void
+update_uniform_storage(struct gl_uniform_storage *uniform,
+ unsigned stage)
+{
+ uniform->active_shader_mask |= 1 << stage;
+}
+
+/**
+ * Finds, return, and update the stage infor for any uniform at the
+ * UniformStorage any uniform defined by @var. In general this is done using
+ * the explicit location, except:
+ *
+ * * UBOs/SSBOs: as they lack explicit location, binding is used to locate
+ * them. That means that more that one entry at the uniform storage can be
+ * found. In that case all of them are updated, and the first entry is
+ * returned, in order to update the location of nir variable.
+ *
+ * * Expecial uniforms: like atomic counters. They lack a explicit location,
+ * so they are skipped, handled in any case, and assign a location later.
+ *
+ */
static struct gl_uniform_storage *
-find_previous_uniform_storage(struct gl_shader_program *prog,
- int location)
+find_and_update_previous_uniform_storage(struct gl_shader_program *prog,
+ nir_variable *var,
+ unsigned stage)
{
- /* This would only work for uniform with explicit location, as all the
- * uniforms without location (ie: atomic counters) would have a initial
- * location equal to -1. We early return in that case.
+ if (nir_variable_is_in_block(var)) {
+ struct gl_uniform_storage *uniform = NULL;
+
+ unsigned num_blks = nir_variable_is_in_ubo(var) ?
+ prog->data->NumUniformBlocks :
+ prog->data->NumShaderStorageBlocks;
+
+ struct gl_uniform_block *blks = nir_variable_is_in_ubo(var) ?
+ prog->data->UniformBlocks : prog->data->ShaderStorageBlocks;
+
+ for (unsigned i = 0; i < prog->data->NumUniformStorage; i++) {
+ /* UniformStorage contains both variables from ubos and ssbos */
+ if ( prog->data->UniformStorage[i].is_shader_storage !=
+ nir_variable_is_in_ssbo(var))
+ continue;
+
+ int block_index = prog->data->UniformStorage[i].block_index;
+ if (block_index != -1) {
+ assert(block_index < num_blks);
+
+ if (var->data.binding == blks[block_index].Binding) {
+ if (!uniform)
+ uniform = &prog->data->UniformStorage[i];
+ update_uniform_storage(&prog->data->UniformStorage[i],
+ stage);
+ }
+ }
+ }
+
+ return uniform;
+ }
+
+ /* Beyond blocks, there are still some corner cases of uniforms without
+ * location (ie: atomic counters) that would have a initial location equal
+ * to -1. We just return on that case. Those uniforms will be handled
+ * later.
*/
- if (location == -1)
+ if (var->data.location == -1)
return NULL;
- for (unsigned i = 0; i < prog->data->NumUniformStorage; i++)
- if (prog->data->UniformStorage[i].remap_location == location)
+ for (unsigned i = 0; i < prog->data->NumUniformStorage; i++) {
+ if (prog->data->UniformStorage[i].remap_location == var->data.location) {
+ update_uniform_storage(&prog->data->UniformStorage[i], stage);
+
return &prog->data->UniformStorage[i];
+ }
+ }
return NULL;
}
@@ -504,9 +563,8 @@ gl_nir_link_uniforms(struct gl_context *ctx,
* other stage. If so, validate they are compatible and update
* the active stage mask.
*/
- uniform = find_previous_uniform_storage(prog, var->data.location);
+ uniform = find_and_update_previous_uniform_storage(prog, var, shader_type);
if (uniform) {
- uniform->active_shader_mask |= 1 << shader_type;
var->data.location = uniform - prog->data->UniformStorage;
continue;
--
2.14.1
More information about the mesa-dev
mailing list