glsl: move uniform block validation to link_uniform_blocks.cpp
authorTimothy Arceri <timothy.arceri@collabora.com>
Wed, 27 Apr 2016 03:20:45 +0000 (13:20 +1000)
committerTimothy Arceri <timothy.arceri@collabora.com>
Wed, 27 Apr 2016 06:17:47 +0000 (16:17 +1000)
Reviewed-by: Eduardo Lima Mitev <elima@igalia.com>
src/compiler/glsl/link_uniform_blocks.cpp
src/compiler/glsl/link_uniforms.cpp

index 58f22fd61c5d3d582f5a00c629edebdb37e8cd61..ac415b54f033d90002d9743d0fa580d09be36ed7 100644 (file)
@@ -500,3 +500,56 @@ link_uniform_blocks_are_compatible(const gl_uniform_block *a,
 
    return true;
 }
+
+/**
+ * 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)
+         return link_uniform_blocks_are_compatible(old_block, new_block)
+            ? i : -1;
+   }
+
+   *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);
+
+   linked_block->Name = ralloc_strdup(*linked_blocks, linked_block->Name);
+
+   for (unsigned int i = 0; i < linked_block->NumUniforms; i++) {
+      struct gl_uniform_buffer_variable *ubo_var =
+         &linked_block->Uniforms[i];
+
+      if (ubo_var->Name == ubo_var->IndexName) {
+         ubo_var->Name = ralloc_strdup(*linked_blocks, ubo_var->Name);
+         ubo_var->IndexName = ubo_var->Name;
+      } else {
+         ubo_var->Name = ralloc_strdup(*linked_blocks, ubo_var->Name);
+         ubo_var->IndexName = ralloc_strdup(*linked_blocks, ubo_var->IndexName);
+      }
+   }
+
+   return linked_block_index;
+}
index 8db60a36f160a79749e5d95a28ed33dcc56aad73..92f1095849069ac24aadda3ccab8888b4f1b8bd4 100644 (file)
@@ -874,59 +874,6 @@ 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)
-         return link_uniform_blocks_are_compatible(old_block, new_block)
-            ? i : -1;
-   }
-
-   *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);
-
-   linked_block->Name = ralloc_strdup(*linked_blocks, linked_block->Name);
-
-   for (unsigned int i = 0; i < linked_block->NumUniforms; i++) {
-      struct gl_uniform_buffer_variable *ubo_var =
-         &linked_block->Uniforms[i];
-
-      if (ubo_var->Name == ubo_var->IndexName) {
-         ubo_var->Name = ralloc_strdup(*linked_blocks, ubo_var->Name);
-         ubo_var->IndexName = ubo_var->Name;
-      } else {
-         ubo_var->Name = ralloc_strdup(*linked_blocks, ubo_var->Name);
-         ubo_var->IndexName = ralloc_strdup(*linked_blocks, ubo_var->IndexName);
-      }
-   }
-
-   return linked_block_index;
-}
-
 /**
  * Walks the IR and update the references to uniform blocks in the
  * ir_variables to point at linked shader's list (previously, they