Test has a structure with explicit location, all its elements should get sequential locations as specified.
Signed-off-by: Tapani Pälli <[email protected]> --- tests/all.py | 1 + .../CMakeLists.gl.txt | 1 + .../struct-elements.c | 111 +++++++++++++++++++++ 3 files changed, 113 insertions(+) create mode 100644 tests/spec/arb_explicit_uniform_location/struct-elements.c diff --git a/tests/all.py b/tests/all.py index a34f4ea..71490b2 100644 --- a/tests/all.py +++ b/tests/all.py @@ -1937,6 +1937,7 @@ add_plain_test(arb_explicit_uniform_location, 'arb_explicit_uniform_location-min 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-inactive-uniform') +add_plain_test(arb_explicit_uniform_location, 'arb_explicit_uniform_location-struct-elements') arb_texture_buffer_object = Group() spec['ARB_texture_buffer_object'] = arb_texture_buffer_object 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..e0fa70e --- /dev/null +++ b/tests/spec/arb_explicit_uniform_location/struct-elements.c @@ -0,0 +1,111 @@ +/* + * 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" + "layout(location = 7) uniform struct foo {\n" + "vec4 a;\n" + "float b[3];\n" + "float inactive;\n" + "float c;\n" + "} s;\n" + "void main() {\n" + "float o = s.a.r + s.b[2] + s.c;\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); + + /* float after array */ + if (glGetUniformLocation(prog, "s.c") != 12) + piglit_report_result(PIGLIT_FAIL); + + glDeleteProgram(prog); + piglit_report_result(PIGLIT_PASS); +} -- 1.8.3.1 _______________________________________________ Piglit mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/piglit
