[Piglit] [PATCH 1/2] arb_program_interface_query: GetProgramResourceIndex test
Tapani Pälli
tapani.palli at intel.com
Fri Feb 27 01:32:56 PST 2015
Test passes on Nvidia GTX 660 (binary driver version 331.38).
Signed-off-by: Tapani Pälli <tapani.palli at intel.com>
---
tests/all.py | 1 +
.../arb_program_interface_query/CMakeLists.gl.txt | 1 +
.../arb_program_interface_query/resource-index.c | 210 +++++++++++++++++++++
3 files changed, 212 insertions(+)
create mode 100644 tests/spec/arb_program_interface_query/resource-index.c
diff --git a/tests/all.py b/tests/all.py
index 8b9426a..d19b20a 100644
--- a/tests/all.py
+++ b/tests/all.py
@@ -2049,6 +2049,7 @@ for test_type in ('shader', 'api'):
arb_program_interface_query = spec['ARB_program_interface_query']
add_plain_test(arb_program_interface_query, ['arb_program_interface_query-resource-location'])
+add_plain_test(arb_program_interface_query, ['arb_program_interface_query-resource-index'])
# Group ARB_explicit_uniform_location
arb_explicit_uniform_location = spec['ARB_explicit_uniform_location']
diff --git a/tests/spec/arb_program_interface_query/CMakeLists.gl.txt b/tests/spec/arb_program_interface_query/CMakeLists.gl.txt
index 6fb7eaf..2028553 100644
--- a/tests/spec/arb_program_interface_query/CMakeLists.gl.txt
+++ b/tests/spec/arb_program_interface_query/CMakeLists.gl.txt
@@ -10,3 +10,4 @@ link_libraries (
)
piglit_add_executable (arb_program_interface_query-resource-location resource-location.c)
+piglit_add_executable (arb_program_interface_query-resource-index resource-index.c)
diff --git a/tests/spec/arb_program_interface_query/resource-index.c b/tests/spec/arb_program_interface_query/resource-index.c
new file mode 100644
index 0000000..a496c65
--- /dev/null
+++ b/tests/spec/arb_program_interface_query/resource-index.c
@@ -0,0 +1,210 @@
+/*
+ * Copyright © 2015 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 resource-index.c
+ *
+ * Tests GetProgramResourceIndex interface.
+ *
+ * From the GL_ARB_program_interface_query spec:
+ * "The command returns the unsigned integer index assigned to a
+ * resource named <name> in the interface type <programInterface> of
+ * program object <program>. The error INVALID_ENUM is generated if
+ * <programInterface> is ATOMIC_COUNTER_BUFFER, since active atomic
+ * counter buffer resources are not assigned name strings.
+ *
+ * If <name> exactly matches the name string of one of the active
+ * resources for <programInterface>, the index of the matched
+ * resource is returned. Additionally, if <name> would exactly match
+ * the name string of an active resource if "[0]" were appended to <name>,
+ * the index of the matched resource is returned. Otherwise, <name> is
+ * considered not to be the name of an active resource, and INVALID_INDEX
+ * is returned. Note that if an interface enumerates a single active
+ * resource list entry for an array variable (e.g., "a[0]"), a <name>
+ * identifying any array element other than the first (e.g., "a[1]")
+ * is not considered to match.
+ *
+ * For the interface TRANSFORM_FEEDBACK_VARYING, the value INVALID_INDEX
+ * should be returned when querying the index assigned to the special
+ * names "gl_NextBuffer", "gl_SkipComponents1", "gl_SkipComponents2",
+ * "gl_SkipComponents3", and "gl_SkipComponents4".
+ */
+
+#include "piglit-util-gl.h"
+
+PIGLIT_GL_TEST_CONFIG_BEGIN
+
+ config.supports_gl_compat_version = 32;
+ config.supports_gl_core_version = 32;
+ config.window_visual = PIGLIT_GL_VISUAL_RGB;
+
+PIGLIT_GL_TEST_CONFIG_END
+
+static const GLenum valid_enums[] = {
+ GL_UNIFORM,
+ GL_PROGRAM_INPUT,
+ GL_PROGRAM_OUTPUT,
+};
+
+const char *xfb_markers[] = {
+ "gl_NextBuffer",
+ "gl_SkipComponents1",
+ "gl_SkipComponents2",
+ "gl_SkipComponents3",
+ "gl_SkipComponents4",
+ NULL
+};
+
+static const char vs_text[] =
+ "#version 150\n"
+ "#extension GL_ARB_explicit_attrib_location : require\n"
+ "#extension GL_ARB_shader_atomic_counters : require\n"
+ "in vec4 input0;\n"
+ "in vec4 input1;\n"
+ "uniform ubo { vec4 mod; };\n"
+ "layout(binding = 0, offset = 4) uniform atomic_uint atom[3];\n"
+ "void main() {\n"
+ "atomicCounterIncrement(atom[1]);\n"
+ "gl_Position = input0 * input1 * mod;\n"
+ "}";
+
+static const char fs_text[] =
+ "#version 150\n"
+ "#extension GL_ARB_explicit_attrib_location : require\n"
+ "#extension GL_ARB_explicit_uniform_location : require\n"
+ "uniform vec4 color;\n"
+ "uniform float array[8];\n"
+ "out vec4 output0;\n"
+ "out vec4 output1;\n"
+ "void main() {\n"
+ "output0 = color * array[0];\n"
+ "output1 = color * array[7];\n"
+ "}";
+
+enum piglit_result
+piglit_display(void)
+{
+ return PIGLIT_FAIL;
+}
+
+static void
+validate_index(GLuint prog, GLenum iface, const char *name)
+{
+ GLuint idx = glGetProgramResourceIndex(prog, iface, name);
+ const GLchar *names[] = { name };
+ GLuint indices;
+
+ /* Validate result against old API. */
+ switch (iface) {
+ case GL_UNIFORM:
+ glGetUniformIndices(prog, 1, names, &indices);
+ if (idx != indices)
+ piglit_report_result(PIGLIT_FAIL);
+ break;
+ case GL_UNIFORM_BLOCK:
+ if (glGetUniformBlockIndex(prog, name) != idx)
+ piglit_report_result(PIGLIT_FAIL);
+ break;
+ }
+
+ /* No errors should have happened. */
+ if (!piglit_check_gl_error(GL_NO_ERROR))
+ piglit_report_result(PIGLIT_FAIL);
+}
+
+void
+piglit_init(int argc, char **argv)
+{
+ GLuint prog, shader;
+ bool pass = true;
+ const char **marker = xfb_markers;
+
+ piglit_require_extension("GL_ARB_program_interface_query");
+ piglit_require_extension("GL_ARB_explicit_attrib_location");
+ piglit_require_extension("GL_ARB_explicit_uniform_location");
+ piglit_require_extension("GL_ARB_shader_atomic_counters");
+
+ /* Test invalid program. */
+ glGetProgramResourceIndex(42, GL_UNIFORM, "name");
+ if (!piglit_check_gl_error(GL_INVALID_VALUE)) {
+ piglit_report_subtest_result(PIGLIT_FAIL,
+ "invalid program test 1");
+ pass = false;
+ }
+
+ /* Test passing a shader, not program. */
+ shader = piglit_compile_shader_text(GL_VERTEX_SHADER, vs_text);
+ glGetProgramResourceIndex(shader, GL_UNIFORM, "name");
+ if (!piglit_check_gl_error(GL_INVALID_OPERATION)) {
+ piglit_report_subtest_result(PIGLIT_FAIL,
+ "invalid program test 2");
+ pass = false;
+ }
+
+ prog = piglit_build_simple_program(vs_text, fs_text);
+
+ if (!piglit_check_gl_error(GL_NO_ERROR))
+ piglit_report_result(PIGLIT_FAIL);
+
+ /* Iterate transform feedback marker strings. */
+ for (; *marker; marker++) {
+ GLuint index = glGetProgramResourceIndex(prog,
+ GL_TRANSFORM_FEEDBACK_VARYING, *marker);
+ if (index == GL_INVALID_INDEX)
+ continue;
+ piglit_report_subtest_result(PIGLIT_FAIL,
+ "xfb marker string test (%s)", *marker);
+ pass = false;
+ }
+
+ /* Test GL_ATOMIC_COUNTER_BUFFER. */
+ glGetProgramResourceIndex(prog, GL_ATOMIC_COUNTER_BUFFER, "atom");
+ if (!piglit_check_gl_error(GL_INVALID_ENUM))
+ piglit_report_result(PIGLIT_FAIL);
+
+ /* Check valid but missing program resource. */
+ if (glGetProgramResourceIndex(prog, GL_TRANSFORM_FEEDBACK_VARYING,
+ "sandwich") != GL_INVALID_INDEX)
+ piglit_report_result(PIGLIT_FAIL);
+
+ /* Check invalid index with array resource (> 0) */
+ if (glGetProgramResourceIndex(prog, GL_UNIFORM, "array[7]") !=
+ GL_INVALID_INDEX)
+ piglit_report_result(PIGLIT_FAIL);
+
+ /* Valid inputs. */
+ validate_index(prog, GL_PROGRAM_INPUT, "input0");
+ validate_index(prog, GL_PROGRAM_INPUT, "input1");
+ validate_index(prog, GL_PROGRAM_OUTPUT, "gl_Position");
+ validate_index(prog, GL_PROGRAM_OUTPUT, "output0");
+ validate_index(prog, GL_PROGRAM_OUTPUT, "output1");
+ validate_index(prog, GL_UNIFORM, "color");
+ validate_index(prog, GL_UNIFORM_BLOCK, "ubo");
+ validate_index(prog, GL_UNIFORM, "array");
+ validate_index(prog, GL_UNIFORM, "array[0]");
+
+ if (!piglit_check_gl_error(GL_NO_ERROR))
+ piglit_report_result(PIGLIT_FAIL);
+
+ piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL);
+}
--
2.1.0
More information about the Piglit
mailing list