linker: Refactor intra-stage block compatabililty testing
authorIan Romanick <ian.d.romanick@intel.com>
Thu, 13 Dec 2012 10:25:34 +0000 (02:25 -0800)
committerIan Romanick <ian.d.romanick@intel.com>
Fri, 25 Jan 2013 14:07:33 +0000 (09:07 -0500)
Also slightly change the compatibility test.  Instead of comparing the
offsets of the block variables, compare the packing mode of the blocks.
Ideally we don't want to assign the offsets until a later stage of
linking.

This is put in a new file called link_uniform_blocks.cpp.  Some new
functions related to uniform blocks are going to live in that file as
well.

Signed-off-by: Ian Romanick <ian.d.romanick@intel.com>
Reviewed-by: Carl Worth <cworth@cworth.org>
Reviewed-by: Chad Versace <chad.versace@linux.intel.com>
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
src/glsl/Makefile.sources
src/glsl/link_uniform_blocks.cpp [new file with mode: 0644]
src/glsl/link_uniforms.cpp
src/glsl/linker.h

index 90f30187fd5bcbd2e17a1eed86de56b5e010a420..d9c9af829e418916fe6e59c97ae3504ec8dde2db 100644 (file)
@@ -47,6 +47,7 @@ LIBGLSL_FILES = \
        $(GLSL_SRCDIR)/link_functions.cpp \
        $(GLSL_SRCDIR)/link_uniforms.cpp \
        $(GLSL_SRCDIR)/link_uniform_initializers.cpp \
+       $(GLSL_SRCDIR)/link_uniform_blocks.cpp \
        $(GLSL_SRCDIR)/link_varyings.cpp \
        $(GLSL_SRCDIR)/loop_analysis.cpp \
        $(GLSL_SRCDIR)/loop_controls.cpp \
diff --git a/src/glsl/link_uniform_blocks.cpp b/src/glsl/link_uniform_blocks.cpp
new file mode 100644 (file)
index 0000000..c9cbde9
--- /dev/null
@@ -0,0 +1,65 @@
+/*
+ * Copyright © 2012 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+#include "main/core.h"
+#include "ir.h"
+#include "linker.h"
+#include "ir_uniform.h"
+#include "program.h"
+
+bool
+link_uniform_blocks_are_compatible(const gl_uniform_block *a,
+                                  const gl_uniform_block *b)
+{
+   assert(strcmp(a->Name, b->Name) == 0);
+
+   /* Page 35 (page 42 of the PDF) in section 4.3.7 of the GLSL 1.50 spec says:
+    *
+    *     "Matched block names within an interface (as defined above) must
+    *     match in terms of having the same number of declarations with the
+    *     same sequence of types and the same sequence of member names, as
+    *     well as having the same member-wise layout qualification....if a
+    *     matching block is declared as an array, then the array sizes must
+    *     also match... Any mismatch will generate a link error."
+    *
+    * Arrays are not yet supported, so there is no check for that.
+    */
+   if (a->NumUniforms != b->NumUniforms)
+      return false;
+
+   if (a->_Packing != b->_Packing)
+      return false;
+
+   for (unsigned i = 0; i < a->NumUniforms; i++) {
+      if (strcmp(a->Uniforms[i].Name, b->Uniforms[i].Name) != 0)
+        return false;
+
+      if (a->Uniforms[i].Type != b->Uniforms[i].Type)
+        return false;
+
+      if (a->Uniforms[i].RowMajor != b->Uniforms[i].RowMajor)
+        return false;
+   }
+
+   return true;
+}
index 07d9c18dea0545e7506096cc8ffb57e043bf387f..25bba15bdbe397f5d281badd3221e3b868d2e0b1 100644 (file)
@@ -399,26 +399,10 @@ link_cross_validate_uniform_block(void *mem_ctx,
 {
    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;
-      }
+      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,
index 67c7f34885944b13514ec86eedc83a768f717ca6..c8f38444c820b97713c038f05b4fe6130fb68765 100644 (file)
@@ -49,6 +49,10 @@ link_cross_validate_uniform_block(void *mem_ctx,
 void
 link_assign_uniform_block_offsets(struct gl_shader *shader);
 
+extern bool
+link_uniform_blocks_are_compatible(const gl_uniform_block *a,
+                                  const gl_uniform_block *b);
+
 /**
  * Class for processing all of the leaf fields of an uniform
  *