[Piglit] [PATCH 08/11] arb_uniform_buffer_object: Add test for padding between UBO structs

Ian Romanick idr at freedesktop.org
Mon Sep 8 14:34:53 PDT 2014


From: Ian Romanick <ian.d.romanick at intel.com>

This test also comes from layout-std140.  Verify that the base alignment
of a structure is that of a vec4, per std140 rule #9.

This test fails on NVIDIA's closed source driver (version 331.89 on
GTX260).

Signed-off-by: Ian Romanick <ian.d.romanick at intel.com>
---
 .../struct_base_alignment.shader_test              | 100 +++++++++++++++++++++
 1 file changed, 100 insertions(+)
 create mode 100644 tests/spec/arb_uniform_buffer_object/struct_base_alignment.shader_test

diff --git a/tests/spec/arb_uniform_buffer_object/struct_base_alignment.shader_test b/tests/spec/arb_uniform_buffer_object/struct_base_alignment.shader_test
new file mode 100644
index 0000000..4239b6d
--- /dev/null
+++ b/tests/spec/arb_uniform_buffer_object/struct_base_alignment.shader_test
@@ -0,0 +1,100 @@
+[require]
+GLSL >= 1.30
+GL_ARB_uniform_buffer_object
+
+[vertex shader]
+#extension GL_ARB_uniform_buffer_object : require
+
+struct S1 {
+	float r;
+};
+
+struct S2 {
+	float g;
+	float b;
+	float a;
+};
+
+/* Section 2.11.4 (Uniform Variables), subsection Standard Uniform
+ * Block Layout, of the OpenGL 3.1 spec says (emphasis mine):
+ *
+ *     "(9) If the member is a structure, the base alignment of the
+ *     structure is <N>, where <N> is the largest base alignment value
+ *     of any of its members, and *rounded up to the base alignment of
+ *     a vec4*. The individual members of this sub-structure are then
+ *     assigned offsets by applying this set of rules recursively,
+ *     where the base offset of the first member of the sub-structure
+ *     is equal to the aligned offset of the structure. The structure
+ *     may have padding at the end; the base offset of the member
+ *     following the sub-structure is rounded up to the next multiple
+ *     of the base alignment of the structure."
+ */
+struct S {
+       S1 s1;
+       S2 s2;
+};
+
+layout(std140) uniform ubo1 {
+	S s;
+};
+
+in vec4 piglit_vertex;
+flat out int pass;
+
+void main()
+{
+	/* std140 (or shared) layout prevents any fields or blocks from being
+	 * eliminted.  Section 2.11.6 of the OpenGL ES 3.0 spec makes this
+	 * explicit, but desktop GL specs only say it implicitly.  Either way,
+	 * there is no need to reference any field of the std140 block.
+	 */
+	gl_Position = piglit_vertex;
+
+	pass = int(s.s2.g == 3.3);
+
+}
+
+[fragment shader]
+out vec4 piglit_fragcolor;
+flat in int pass;
+
+void main()
+{
+	piglit_fragcolor = bool(pass) ? vec4(0, 1, 0, 1) : vec4(1, 0, 0, 1);
+}
+
+[test]
+link success
+
+active uniform s.s1.r GL_UNIFORM_TYPE GL_FLOAT
+active uniform s.s1.r GL_UNIFORM_SIZE 1
+active uniform s.s1.r GL_UNIFORM_OFFSET 0
+active uniform s.s1.r GL_UNIFORM_ARRAY_STRIDE 0
+active uniform s.s1.r GL_UNIFORM_MATRIX_STRIDE 0
+active uniform s.s1.r GL_UNIFORM_IS_ROW_MAJOR 0
+
+active uniform s.s2.g GL_UNIFORM_TYPE GL_FLOAT
+active uniform s.s2.g GL_UNIFORM_SIZE 1
+active uniform s.s2.g GL_UNIFORM_OFFSET 16
+active uniform s.s2.g GL_UNIFORM_ARRAY_STRIDE 0
+active uniform s.s2.g GL_UNIFORM_MATRIX_STRIDE 0
+active uniform s.s2.g GL_UNIFORM_IS_ROW_MAJOR 0
+
+active uniform s.s2.b GL_UNIFORM_TYPE GL_FLOAT
+active uniform s.s2.b GL_UNIFORM_SIZE 1
+active uniform s.s2.b GL_UNIFORM_OFFSET 20
+active uniform s.s2.b GL_UNIFORM_ARRAY_STRIDE 0
+active uniform s.s2.b GL_UNIFORM_MATRIX_STRIDE 0
+active uniform s.s2.b GL_UNIFORM_IS_ROW_MAJOR 0
+
+active uniform s.s2.a GL_UNIFORM_TYPE GL_FLOAT
+active uniform s.s2.a GL_UNIFORM_SIZE 1
+active uniform s.s2.a GL_UNIFORM_OFFSET 24
+active uniform s.s2.a GL_UNIFORM_ARRAY_STRIDE 0
+active uniform s.s2.a GL_UNIFORM_MATRIX_STRIDE 0
+active uniform s.s2.a GL_UNIFORM_IS_ROW_MAJOR 0
+
+uniform float s.s2.g 3.3
+
+draw rect -1 -1 2 2
+probe all rgba 0.0 1.0 0.0 1.0
-- 
1.8.1.4



More information about the Piglit mailing list