[Piglit] [PATCH v2] ARB_explicit_uniform_location: test struct with explicit location
Tapani Pälli
tapani.palli at intel.com
Tue Mar 25 00:57:07 PDT 2014
Test has a structure with explicit locations, all elements should get
sequential locations as specified.
v2: fixed some style issues, added a struct inside struct
Signed-off-by: Tapani Pälli <tapani.palli at intel.com>
---
tests/all.py | 1 +
.../CMakeLists.gl.txt | 1 +
.../struct-elements.c | 120 +++++++++++++++++++++
3 files changed, 122 insertions(+)
create mode 100644 tests/spec/arb_explicit_uniform_location/struct-elements.c
diff --git a/tests/all.py b/tests/all.py
index d4431fe..7def27b 100644
--- a/tests/all.py
+++ b/tests/all.py
@@ -1959,6 +1959,7 @@ add_shader_test_dir(arb_explicit_uniform_location,
add_plain_test(arb_explicit_uniform_location, 'arb_explicit_uniform_location-minmax')
add_plain_test(arb_explicit_uniform_location, 'arb_explicit_uniform_location-boundaries')
add_plain_test(arb_explicit_uniform_location, 'arb_explicit_uniform_location-array-elements')
+add_plain_test(arb_explicit_uniform_location, 'arb_explicit_uniform_location-struct-elements')
add_plain_test(arb_explicit_uniform_location, 'arb_explicit_uniform_location-inactive-uniform')
arb_texture_buffer_object = Group()
diff --git a/tests/spec/arb_explicit_uniform_location/CMakeLists.gl.txt b/tests/spec/arb_explicit_uniform_location/CMakeLists.gl.txt
index 1a8488c..87f3af5 100644
--- a/tests/spec/arb_explicit_uniform_location/CMakeLists.gl.txt
+++ b/tests/spec/arb_explicit_uniform_location/CMakeLists.gl.txt
@@ -13,3 +13,4 @@ piglit_add_executable (arb_explicit_uniform_location-minmax minmax.c)
piglit_add_executable (arb_explicit_uniform_location-boundaries loc-boundaries.c)
piglit_add_executable (arb_explicit_uniform_location-array-elements array-elements.c)
piglit_add_executable (arb_explicit_uniform_location-inactive-uniform inactive-uniform.c)
+piglit_add_executable (arb_explicit_uniform_location-struct-elements struct-elements.c)
diff --git a/tests/spec/arb_explicit_uniform_location/struct-elements.c b/tests/spec/arb_explicit_uniform_location/struct-elements.c
new file mode 100644
index 0000000..1796e59
--- /dev/null
+++ b/tests/spec/arb_explicit_uniform_location/struct-elements.c
@@ -0,0 +1,120 @@
+/*
+ * Copyright © 2014 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.
+ */
+
+/**
+ * \file struct-elements.c
+ *
+ * Tests that struct elements get sequential locations. Test has shader with a
+ * structure that has array and one inactive element inside.
+ *
+ * The GL_ARB_explicit_uniform_location spec says:
+ *
+ * "Locations can be assigned to default-block uniform arrays and
+ * structures. The first inner-most scalar, vector or matrix member or
+ * element takes the specified <location> and the compiler assigns the
+ * next inner-most member or element the next incremental location value.
+ * Each subsequent inner-most member or element gets incremental locations
+ * for the entire structure or array. This rule applies to nested structures
+ * and arrays and gives each inner-most scalar, vector, or matrix type a
+ * unique location. For arrays without an explicit size, the size is
+ * calculated based on its static usage. When the linker generates locations
+ * for uniforms without an explicit location, it assumes for all uniforms
+ * with an explicit location all their array elements and structure members
+ * are used and the linker will not generate a conflicting location, even
+ * if that element of member is deemed unused."
+ */
+#include "piglit-util-gl-common.h"
+
+PIGLIT_GL_TEST_CONFIG_BEGIN
+
+ config.supports_gl_compat_version = 20;
+ config.window_visual = PIGLIT_GL_VISUAL_RGB;
+
+PIGLIT_GL_TEST_CONFIG_END
+
+enum piglit_result
+piglit_display(void)
+{
+ return PIGLIT_FAIL;
+}
+
+static const char vs_text[] =
+ "vec4 vertex;\n"
+ "void main() {\n"
+ "gl_Position = vertex;\n"
+ "}";
+
+static const char fs_text[] =
+ "#extension GL_ARB_explicit_uniform_location: require\n"
+ "struct bar {\n"
+ "float a;\n"
+ "float b[3];\n"
+ "};\n"
+ "layout(location = 7) uniform struct foo {\n"
+ "vec4 a;\n"
+ "float b[3];\n"
+ "float inactive;\n"
+ "bar c;\n"
+ "float d;\n"
+ "} s;\n"
+ "void main() {\n"
+ "float o = s.a.r + s.b[2] + s.d;\n"
+ "gl_FragColor = vec4(1.0, 0.0, 1.0, o);\n"
+ "}";
+
+void
+piglit_init(int argc, char **argv)
+{
+ GLuint prog;
+
+ piglit_require_extension("GL_ARB_explicit_uniform_location");
+
+ prog = piglit_build_simple_program(vs_text, fs_text);
+
+ /* verify locations */
+ if (glGetUniformLocation(prog, "s.a") != 7)
+ piglit_report_result(PIGLIT_FAIL);
+
+ /* 3 array slots */
+ if (glGetUniformLocation(prog, "s.b[0]") != 8)
+ piglit_report_result(PIGLIT_FAIL);
+ if (glGetUniformLocation(prog, "s.b[1]") != 9)
+ piglit_report_result(PIGLIT_FAIL);
+ if (glGetUniformLocation(prog, "s.b[2]") != 10)
+ piglit_report_result(PIGLIT_FAIL);
+
+ /* inactive element */
+ if (glGetUniformLocation(prog, "s.inactive") != 11)
+ piglit_report_result(PIGLIT_FAIL);
+
+ /* inactive array element in a struct inside struct */
+ if (glGetUniformLocation(prog, "s.c.b[2]") != 15)
+ piglit_report_result(PIGLIT_FAIL);
+
+ /* float after array */
+ if (glGetUniformLocation(prog, "s.d") != 16)
+ piglit_report_result(PIGLIT_FAIL);
+
+ glDeleteProgram(prog);
+ piglit_report_result(PIGLIT_PASS);
+}
--
1.8.5.3
More information about the Piglit
mailing list