[Piglit] [PATCH] ARB_pipeline_statistics_query (comp): basic test
Jordan Justen
jordan.l.justen at intel.com
Thu Dec 11 13:37:10 PST 2014
Signed-off-by: Jordan Justen <jordan.l.justen at intel.com>
Cc: Ben Widawsky <ben at bwidawsk.net>
---
Requires Ben's ARB_pipeline_statistics_query series.
tests/all.py | 2 +
.../spec/arb_pipeline_statistics/CMakeLists.gl.txt | 2 +
.../arb_pipeline_statistics/pipeline_stats_comp.c | 242 +++++++++++++++++++++
3 files changed, 246 insertions(+)
create mode 100644 tests/spec/arb_pipeline_statistics/pipeline_stats_comp.c
diff --git a/tests/all.py b/tests/all.py
index a0c560b..c57d452 100644
--- a/tests/all.py
+++ b/tests/all.py
@@ -3658,6 +3658,8 @@ arb_pipeline_statistics['arb_pipeline_stats_fs_basic_stats'] = \
PiglitGLTest('arb_pipeline_stats_frag', run_concurrent=True)
arb_pipeline_statistics['arb_pipeline_stats_gs_basic_stats'] = \
PiglitGLTest('arb_pipeline_stats_geom', run_concurrent=True)
+arb_pipeline_statistics['arb_pipeline_stats_cs_basic_stats'] = \
+ PiglitGLTest('arb_pipeline_stats_comp', run_concurrent=True)
# group glslparsertest ------------------------------------------------------
glslparsertest = {}
diff --git a/tests/spec/arb_pipeline_statistics/CMakeLists.gl.txt b/tests/spec/arb_pipeline_statistics/CMakeLists.gl.txt
index 0c80a31..9f5072e 100644
--- a/tests/spec/arb_pipeline_statistics/CMakeLists.gl.txt
+++ b/tests/spec/arb_pipeline_statistics/CMakeLists.gl.txt
@@ -26,5 +26,7 @@ piglit_add_executable (arb_pipeline_stats_clip pipeline_stats_clip.c)
target_link_libraries (arb_pipeline_stats_clip pipestat_help)
piglit_add_executable (arb_pipeline_stats_frag pipeline_stats_frag.c)
target_link_libraries (arb_pipeline_stats_frag pipestat_help)
+piglit_add_executable (arb_pipeline_stats_comp pipeline_stats_comp.c)
+target_link_libraries (arb_pipeline_stats_comp pipestat_help)
# vim: ft=cmake
diff --git a/tests/spec/arb_pipeline_statistics/pipeline_stats_comp.c b/tests/spec/arb_pipeline_statistics/pipeline_stats_comp.c
new file mode 100644
index 0000000..6b7005b
--- /dev/null
+++ b/tests/spec/arb_pipeline_statistics/pipeline_stats_comp.c
@@ -0,0 +1,242 @@
+/*
+ * 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 pipeline_stats_comp.c
+ *
+ * This test verifies that the vertex shader related tokens of
+ * ARB_pipeline_statistics_query() work as expected. OpenGL 4.4 Specification,
+ * Core Profile.
+ *
+ * When BeginQuery is called with a target of COMPUTE_SHADER_INVOCATIONS,
+ * the compute shader invocations count maintained by the GL is set to zero.
+ * When a compute shader invocations query is active, the counter is
+ * incremented every time the compute shader is invoked (see section 11.3).
+ * In case of instanced compute shaders (see section 11.3.4.2) the compute
+ * shader invocations count is incremented for each separate instanced
+ * invocation.
+ *
+ * When BeginQuery is called with a target of COMPUTE_SHADER_PRIMITIVES_-
+ * EMITTED_ARB, the compute shader output primitives count maintained by the
+ * GL is set to zero. When a compute shader primitives emitted query is
+ * active, the counter is incremented every time the compute shader emits
+ * a primitive to a vertex stream that is further processed by the GL (see
+ * section 11.3.2). Restarting primitive topology using the shading language
+ * built-in functions EndPrimitive or EndStreamPrimitive does not increment
+ * the compute shader output primitives count.
+ */
+
+#include "piglit-util-gl.h"
+#include "pipestat_help.h"
+
+PIGLIT_GL_TEST_CONFIG_BEGIN
+ config.supports_gl_core_version = 32;
+ config.supports_gl_compat_version = 32;
+ config.window_visual = PIGLIT_GL_VISUAL_DOUBLE | PIGLIT_GL_VISUAL_RGBA;
+PIGLIT_GL_TEST_CONFIG_END
+
+#define NUM_ATOMIC_COUNTERS 1
+
+static GLuint atomics_bo = 0;
+
+static int sizes[] = {
+ 1, 2, 3, 4, 5, 7, 8, 9, 15, 16, 17, 31, 32, 33, 63, 64, 65,
+ 127, 128, 129, 255, 256, 257, 511, 512, 513, 1023, 1024
+};
+
+static struct query queries[] = {
+ {
+ .query = GL_COMPUTE_SHADER_INVOCATIONS_ARB,
+ .name = "GL_COMPUTE_SHADER_INVOCATIONS_ARB",
+ .expected = 0 /* Adjusted by confirm_size */},
+};
+
+static const char *compute_shader_template =
+ "#version 330\n"
+ "#extension GL_ARB_compute_shader: enable\n"
+ "#extension GL_ARB_shader_atomic_counters: require\n"
+ "\n"
+ "layout(binding = 0) uniform atomic_uint atc;\n"
+ "\n"
+ "layout(local_size_x = %d, local_size_y = %d, local_size_z = %d) in;\n"
+ "\n"
+ "void main()\n"
+ "{\n"
+ " atomicCounterIncrement(atc);\n"
+ "}\n";
+
+
+static enum piglit_result
+confirm_size(uint32_t xs, uint32_t ys, uint32_t zs)
+{
+ uint32_t *p;
+ uint32_t expected;
+
+ expected = xs * ys * zs;
+
+ glBindBufferBase(GL_ATOMIC_COUNTER_BUFFER, 0, atomics_bo);
+ p = glMapBufferRange(GL_ATOMIC_COUNTER_BUFFER,
+ 0,
+ NUM_ATOMIC_COUNTERS * sizeof(uint32_t),
+ GL_MAP_READ_BIT | GL_MAP_WRITE_BIT);
+
+ if (!p) {
+ printf("Couldn't map atomic counter to verify expected value.\n");
+ return PIGLIT_FAIL;
+ }
+
+ /* Adjust the expected thread count */
+ queries[0].expected += expected;
+
+ if (expected != p[0]) {
+ printf("Atomic counter test failed for (%d, %d, %d)\n",
+ xs, ys, zs);
+ printf(" Reference: %u\n", expected);
+ printf(" Observed: %u\n", p[0]);
+ glUnmapBuffer(GL_ATOMIC_COUNTER_BUFFER);
+ return PIGLIT_FAIL;
+ }
+
+ memset(p, 0, sizeof (uint32_t) * NUM_ATOMIC_COUNTERS);
+
+ glUnmapBuffer(GL_ATOMIC_COUNTER_BUFFER);
+
+ return PIGLIT_PASS;
+}
+
+
+static enum piglit_result
+test_size(uint32_t x, uint32_t y, uint32_t z)
+{
+ enum piglit_result result = PIGLIT_PASS;
+ char *compute_shader;
+ GLint shader_string_size;
+ GLuint shader = glCreateShader(GL_COMPUTE_SHADER);
+ GLint ok;
+ static GLint prog = 0;
+
+ if (prog != 0) {
+ glDeleteProgram(prog);
+ }
+
+ asprintf(&compute_shader, compute_shader_template, x, y, z);
+
+ glShaderSource(shader, 1,
+ (const GLchar **) &compute_shader,
+ &shader_string_size);
+
+ glCompileShader(shader);
+
+ glGetShaderiv(shader, GL_COMPILE_STATUS, &ok);
+ assert(ok);
+
+ prog = glCreateProgram();
+
+ glAttachShader(prog, shader);
+
+ glLinkProgram(prog);
+
+ glGetProgramiv(prog, GL_LINK_STATUS, &ok);
+ assert(ok);
+
+ glUseProgram(prog);
+
+ glMemoryBarrier(GL_ALL_BARRIER_BITS);
+ glDispatchCompute(1, 1, 1);
+ glMemoryBarrier(GL_ALL_BARRIER_BITS);
+
+ result = confirm_size(x, y, z);
+ if (result != PIGLIT_PASS)
+ piglit_report_result(result);
+ return result;
+}
+
+
+static enum piglit_result
+test_all_sizes()
+{
+ enum piglit_result result = PIGLIT_PASS;
+ uint32_t xi, yi, zi;
+ uint32_t x, y, z;
+
+
+ for (zi = 0; zi <= ARRAY_SIZE(sizes); zi++) {
+ z = sizes[zi];
+ if (z > 64)
+ break;
+ for (yi = 0; yi <= ARRAY_SIZE(sizes); yi++) {
+ y = sizes[yi];
+ if ((y * z) > 1024)
+ break;
+ for (xi = 0; xi <= ARRAY_SIZE(sizes); xi++) {
+ x = sizes[xi];
+ if ((x * y * z) > 1024)
+ break;
+ result = test_size(x, y, z);
+ if (result != PIGLIT_PASS)
+ return result;
+ }
+ }
+ }
+
+ return result;
+}
+
+
+static void
+test_all_sizes_for_query(void)
+{
+ test_all_sizes();
+}
+
+
+enum piglit_result
+piglit_display(void)
+{
+ return PIGLIT_FAIL;
+}
+
+
+void
+piglit_init(int argc, char **argv)
+{
+ enum piglit_result result;
+ GLuint *atomics_buf;
+
+ piglit_require_extension("GL_ARB_compute_shader");
+ piglit_require_extension("GL_ARB_shader_atomic_counters");
+
+ do_query_init(queries, ARRAY_SIZE(queries));
+
+ atomics_buf = calloc(NUM_ATOMIC_COUNTERS, sizeof(GLuint));
+ glGenBuffers(1, &atomics_bo);
+ glBindBufferBase(GL_ATOMIC_COUNTER_BUFFER, 0, atomics_bo);
+ glBufferData(GL_ATOMIC_COUNTER_BUFFER,
+ sizeof(GLuint) * NUM_ATOMIC_COUNTERS,
+ atomics_buf, GL_STATIC_DRAW);
+ free(atomics_buf);
+
+ result = do_query_func(queries, ARRAY_SIZE(queries),
+ test_all_sizes_for_query);
+
+ piglit_report_result(result);
+}
--
2.1.3
More information about the Piglit
mailing list