summaryrefslogtreecommitdiffstats
path: root/src/glsl
diff options
context:
space:
mode:
authorIan Romanick <[email protected]>2014-04-04 13:42:04 -0700
committerIan Romanick <[email protected]>2014-04-11 12:26:01 -0700
commit25a66568750c5826a077cbf549de92546c5fc6cf (patch)
tree2b4d481f3c243f923875f462ec0e1221a81bb05d /src/glsl
parentcc42717b50bd46c82ac7925c397cd105ac82d091 (diff)
linker: Set binding for all elements of UBO array
Previously, a UBO like layout(binding=2) uniform U { ... } my_constants[4]; wouldn't get any bindings set. The code would try to set the binding of U, but that would fail. It should instead set the bindings for U[0], U[1], ... Signed-off-by: Ian Romanick <[email protected]> Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=76323 Reviewed-by: Kenneth Graunke <[email protected]> Cc: "10.1" <[email protected]> Cc: [email protected]
Diffstat (limited to 'src/glsl')
-rw-r--r--src/glsl/link_uniform_initializers.cpp36
1 files changed, 34 insertions, 2 deletions
diff --git a/src/glsl/link_uniform_initializers.cpp b/src/glsl/link_uniform_initializers.cpp
index 491eb693f6b..e60bb64bcdc 100644
--- a/src/glsl/link_uniform_initializers.cpp
+++ b/src/glsl/link_uniform_initializers.cpp
@@ -262,8 +262,40 @@ link_set_uniform_initializers(struct gl_shader_program *prog)
} else if (var->is_in_uniform_block()) {
const glsl_type *const iface_type = var->get_interface_type();
- linker::set_block_binding(prog, iface_type->name,
- var->data.binding);
+ /* If the variable is an array and it is an interface instance,
+ * we need to set the binding for each array element. Just
+ * checking that the variable is an array is not sufficient.
+ * The variable could be an array element of a uniform block
+ * that lacks an instance name. For example:
+ *
+ * uniform U {
+ * float f[4];
+ * };
+ *
+ * In this case "f" would pass is_in_uniform_block (above) and
+ * type->is_array(), but it will fail is_interface_instance().
+ */
+ if (var->is_interface_instance() && var->type->is_array()) {
+ for (unsigned i = 0; i < var->type->length; i++) {
+ const char *name =
+ ralloc_asprintf(mem_ctx, "%s[%u]", iface_type->name, i);
+
+ /* Section 4.4.3 (Uniform Block Layout Qualifiers) of the
+ * GLSL 4.20 spec says:
+ *
+ * "If the binding identifier is used with a uniform
+ * block instanced as an array then the first element
+ * of the array takes the specified block binding and
+ * each subsequent element takes the next consecutive
+ * uniform block binding point."
+ */
+ linker::set_block_binding(prog, name,
+ var->data.binding + i);
+ }
+ } else {
+ linker::set_block_binding(prog, iface_type->name,
+ var->data.binding);
+ }
} else {
assert(!"Explicit binding not on a sampler or UBO.");
}