aboutsummaryrefslogtreecommitdiff
path: root/mesalib/src/glsl/link_uniform_initializers.cpp
diff options
context:
space:
mode:
authormarha <marha@users.sourceforge.net>2013-07-19 08:33:43 +0200
committermarha <marha@users.sourceforge.net>2013-07-19 08:33:43 +0200
commit45b71fd5b777a968310c537ace5efcd1443085a0 (patch)
treea3ef2b449659c3ba6c885d169c7796b3ef948867 /mesalib/src/glsl/link_uniform_initializers.cpp
parent08bafbbe05abefabdb0c3238c3d9ecdcce1b692f (diff)
parent89bc3ee988b62eb5e10284bac32a176955546410 (diff)
downloadvcxsrv-45b71fd5b777a968310c537ace5efcd1443085a0.tar.gz
vcxsrv-45b71fd5b777a968310c537ace5efcd1443085a0.tar.bz2
vcxsrv-45b71fd5b777a968310c537ace5efcd1443085a0.zip
Merge remote-tracking branch 'origin/released'
* origin/released: mesa xkbcomp git update 19 Jul 2013
Diffstat (limited to 'mesalib/src/glsl/link_uniform_initializers.cpp')
-rw-r--r--mesalib/src/glsl/link_uniform_initializers.cpp75
1 files changed, 58 insertions, 17 deletions
diff --git a/mesalib/src/glsl/link_uniform_initializers.cpp b/mesalib/src/glsl/link_uniform_initializers.cpp
index 54d9bf1f5..3f6671047 100644
--- a/mesalib/src/glsl/link_uniform_initializers.cpp
+++ b/mesalib/src/glsl/link_uniform_initializers.cpp
@@ -82,6 +82,56 @@ copy_constant_to_storage(union gl_constant_value *storage,
}
void
+set_uniform_binding(void *mem_ctx, gl_shader_program *prog,
+ const char *name, const glsl_type *type, int binding)
+{
+ struct gl_uniform_storage *const storage =
+ get_storage(prog->UniformStorage, prog->NumUserUniformStorage, name);
+
+ if (storage == NULL) {
+ assert(storage != NULL);
+ return;
+ }
+
+ if (storage->type->is_sampler()) {
+ unsigned elements = MAX2(storage->array_elements, 1);
+
+ /* From section 4.4.4 of the GLSL 4.20 specification:
+ * "If the binding identifier is used with an array, the first element
+ * of the array takes the specified unit and each subsequent element
+ * takes the next consecutive unit."
+ */
+ for (unsigned int i = 0; i < elements; i++) {
+ storage->storage[i].i = binding + i;
+ }
+
+ for (int sh = 0; sh < MESA_SHADER_TYPES; sh++) {
+ gl_shader *shader = prog->_LinkedShaders[sh];
+
+ if (shader && storage->sampler[sh].active) {
+ for (unsigned i = 0; i < elements; i++) {
+ unsigned index = storage->sampler[sh].index + i;
+
+ shader->SamplerUnits[index] = storage->storage[i].i;
+ }
+ }
+ }
+ } else if (storage->block_index != -1) {
+ /* This is a field of a UBO. val is the binding index. */
+ for (int i = 0; i < MESA_SHADER_TYPES; i++) {
+ int stage_index = prog->UniformBlockStageIndex[i][storage->block_index];
+
+ if (stage_index != -1) {
+ struct gl_shader *sh = prog->_LinkedShaders[i];
+ sh->UniformBlocks[stage_index].Binding = binding;
+ }
+ }
+ }
+
+ storage->initialized = true;
+}
+
+void
set_uniform_initializer(void *mem_ctx, gl_shader_program *prog,
const char *name, const glsl_type *type,
ir_constant *val)
@@ -136,20 +186,6 @@ set_uniform_initializer(void *mem_ctx, gl_shader_program *prog,
idx += elements;
}
-
- if (base_type == GLSL_TYPE_SAMPLER) {
- for (int sh = 0; sh < MESA_SHADER_TYPES; sh++) {
- gl_shader *shader = prog->_LinkedShaders[sh];
-
- if (shader && storage->sampler[sh].active) {
- for (unsigned i = 0; i < storage->array_elements; i++) {
- unsigned index = storage->sampler[sh].index + i;
-
- shader->SamplerUnits[index] = storage->storage[i].i;
- }
- }
- }
- }
} else {
copy_constant_to_storage(storage->storage,
val,
@@ -187,14 +223,19 @@ link_set_uniform_initializers(struct gl_shader_program *prog)
foreach_list(node, shader->ir) {
ir_variable *const var = ((ir_instruction *) node)->as_variable();
- if (!var || var->mode != ir_var_uniform || !var->constant_value)
+ if (!var || var->mode != ir_var_uniform)
continue;
if (!mem_ctx)
mem_ctx = ralloc_context(NULL);
- linker::set_uniform_initializer(mem_ctx, prog, var->name,
- var->type, var->constant_value);
+ if (var->explicit_binding) {
+ linker::set_uniform_binding(mem_ctx, prog, var->name,
+ var->type, var->binding);
+ } else if (var->constant_value) {
+ linker::set_uniform_initializer(mem_ctx, prog, var->name,
+ var->type, var->constant_value);
+ }
}
}