aboutsummaryrefslogtreecommitdiffstats
path: root/src/glsl/link_uniforms.cpp
diff options
context:
space:
mode:
authorEric Anholt <[email protected]>2012-04-27 13:52:56 -0700
committerEric Anholt <[email protected]>2012-07-20 10:43:28 -0700
commitf609cf782ab5e90ddf045dc4b0da8cebf99be0d1 (patch)
tree7f54da76e408a733a9bb82e8242ada78fb6063f4 /src/glsl/link_uniforms.cpp
parentb3c093c79c2ec49c36af37aa290d5ae452149f6e (diff)
glsl: Merge the lists of uniform blocks into the linked shader program.
This attempts error-checking, but the layout isn't done yet. Reviewed-by: Ian Romanick <[email protected]>
Diffstat (limited to 'src/glsl/link_uniforms.cpp')
-rw-r--r--src/glsl/link_uniforms.cpp61
1 files changed, 61 insertions, 0 deletions
diff --git a/src/glsl/link_uniforms.cpp b/src/glsl/link_uniforms.cpp
index 92e2a1fa548..dddac43c316 100644
--- a/src/glsl/link_uniforms.cpp
+++ b/src/glsl/link_uniforms.cpp
@@ -316,6 +316,67 @@ public:
unsigned shader_shadow_samplers;
};
+/**
+ * Merges a uniform block into an array of uniform blocks that may or
+ * may not already contain a copy of it.
+ *
+ * Returns the index of the new block in the array.
+ */
+int
+link_cross_validate_uniform_block(void *mem_ctx,
+ struct gl_uniform_block **linked_blocks,
+ unsigned int *num_linked_blocks,
+ struct gl_uniform_block *new_block)
+{
+ for (unsigned int i = 0; i < *num_linked_blocks; i++) {
+ struct gl_uniform_block *old_block = &(*linked_blocks)[i];
+ if (strcmp(old_block->Name, new_block->Name) == 0) {
+ if (old_block->NumUniforms != new_block->NumUniforms) {
+ return -1;
+ }
+
+ for (unsigned j = 0; j < old_block->NumUniforms; j++) {
+ if (strcmp(old_block->Uniforms[j].Name,
+ new_block->Uniforms[j].Name) != 0)
+ return -1;
+
+ if (old_block->Uniforms[j].Offset !=
+ new_block->Uniforms[j].Offset)
+ return -1;
+
+ if (old_block->Uniforms[j].RowMajor !=
+ new_block->Uniforms[j].RowMajor)
+ return -1;
+ }
+ return i;
+ }
+ }
+
+ *linked_blocks = reralloc(mem_ctx, *linked_blocks,
+ struct gl_uniform_block,
+ *num_linked_blocks + 1);
+ int linked_block_index = (*num_linked_blocks)++;
+ struct gl_uniform_block *linked_block = &(*linked_blocks)[linked_block_index];
+
+ memcpy(linked_block, new_block, sizeof(*new_block));
+ linked_block->Uniforms = ralloc_array(*linked_blocks,
+ struct gl_uniform_buffer_variable,
+ linked_block->NumUniforms);
+
+ memcpy(linked_block->Uniforms,
+ new_block->Uniforms,
+ sizeof(*linked_block->Uniforms) * linked_block->NumUniforms);
+
+ for (unsigned int i = 0; i < linked_block->NumUniforms; i++) {
+ struct gl_uniform_buffer_variable *ubo_var =
+ &linked_block->Uniforms[i];
+
+ ubo_var->Name = ralloc_strdup(*linked_blocks, ubo_var->Name);
+ }
+
+ return linked_block_index;
+}
+
void
link_assign_uniform_locations(struct gl_shader_program *prog)
{