[Piglit] [PATCH 1/3] arb_compute_shader: Test conditional rendering with dispatches.

Bas Nieuwenhuizen bas at basnieuwenhuizen.nl
Mon Apr 11 13:45:28 UTC 2016


Signed-off-by: Bas Nieuwenhuizen <bas at basnieuwenhuizen.nl>
---
 tests/all.py                                       |   1 +
 tests/spec/arb_compute_shader/CMakeLists.gl.txt    |   1 +
 .../spec/arb_compute_shader/conditional-dispatch.c | 130 +++++++++++++++++++++
 3 files changed, 132 insertions(+)
 create mode 100644 tests/spec/arb_compute_shader/conditional-dispatch.c

diff --git a/tests/all.py b/tests/all.py
index c7088ca..da1c257 100644
--- a/tests/all.py
+++ b/tests/all.py
@@ -4254,6 +4254,7 @@ with profile.group_manager(
     g(['arb_compute_shader-local-id'], 'local-id' + '-explosion')
     g(['arb_compute_shader-render-and-compute'], 'render-and-compute')
     g(['arb_compute_shader-zero-dispatch-size'], 'zero-dispatch-size')
+    g(['arb_compute_shader-conditional-dispatch'], 'conditional-dispatch')
 
 with profile.group_manager(
         PiglitGLTest,
diff --git a/tests/spec/arb_compute_shader/CMakeLists.gl.txt b/tests/spec/arb_compute_shader/CMakeLists.gl.txt
index d7b9812..02ede80 100644
--- a/tests/spec/arb_compute_shader/CMakeLists.gl.txt
+++ b/tests/spec/arb_compute_shader/CMakeLists.gl.txt
@@ -18,5 +18,6 @@ piglit_add_executable (arb_compute_shader-indirect-compute indirect-compute.c ${
 piglit_add_executable (arb_compute_shader-local-id local-id.c ${depends})
 piglit_add_executable (arb_compute_shader-render-and-compute render-and-compute.c ${depends})
 piglit_add_executable (arb_compute_shader-zero-dispatch-size zero-dispatch-size.c ${depends})
+piglit_add_executable (arb_compute_shader-conditional-dispatch conditional-dispatch.c)
 
 # vim: ft=cmake:
diff --git a/tests/spec/arb_compute_shader/conditional-dispatch.c b/tests/spec/arb_compute_shader/conditional-dispatch.c
new file mode 100644
index 0000000..29396f7
--- /dev/null
+++ b/tests/spec/arb_compute_shader/conditional-dispatch.c
@@ -0,0 +1,130 @@
+/*
+ * Copyright 2016 Bas Nieuwenhuizen
+ *
+ * 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.
+ */
+
+#include "piglit-util-gl.h"
+
+PIGLIT_GL_TEST_CONFIG_BEGIN
+
+	config.supports_gl_core_version = 42;
+
+	config.window_width = 320;
+	config.window_height = 320;
+	config.window_visual = PIGLIT_GL_VISUAL_RGB;
+
+PIGLIT_GL_TEST_CONFIG_END
+
+const char *vs_source =
+	"#version 140\n"
+	"in vec4 piglit_vertex;\n"
+	"void main() {\n"
+	"	gl_Position = piglit_vertex;\n"
+	"}\n";
+
+const char *fs_source =
+	"#version 140\n"
+	"out vec4 color;\n"
+	"void main() {\n"
+	"	color = vec4(1.0);\n"
+	"}\n";
+
+const char *cs_source =
+	"#version 420\n"
+	"#extension GL_ARB_compute_shader : require\n"
+	"layout (local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
+	"layout(binding = 0, offset = 0) uniform atomic_uint counter;\n"
+	"void main() {\n"
+	"	atomicCounterIncrement(counter);\n"
+	"}\n";
+
+bool single_test(bool enabled)
+{
+	GLuint graphics_prog, vao, buffer, query;
+	GLuint compute_shader, compute_prog;
+	uint32_t initial_counter = 0;
+	uint32_t *ptr;
+	bool result = true;
+
+	graphics_prog = piglit_build_simple_program(vs_source, fs_source);
+	compute_shader = piglit_compile_shader_text(GL_COMPUTE_SHADER, cs_source);
+	compute_prog = piglit_link_simple_program_multiple_shaders(compute_shader,
+	                                                              0);
+	glUseProgram(graphics_prog);
+
+	glGenVertexArrays(1, &vao);
+	glBindVertexArray(vao);
+
+	glGenQueries(1, &query);
+
+	glViewport(0, 0, piglit_width, piglit_height);
+
+	glBeginQuery(GL_SAMPLES_PASSED, query);
+	if (enabled)
+		piglit_draw_rect(-1, -1, 2, 2);
+
+	glEndQuery(GL_SAMPLES_PASSED);
+
+	glGenBuffers(1, &buffer);
+	glBindBufferBase(GL_ATOMIC_COUNTER_BUFFER, 0, buffer);
+	glBufferData(GL_ATOMIC_COUNTER_BUFFER,
+		sizeof(uint32_t), &initial_counter, GL_DYNAMIC_DRAW);
+
+	glUseProgram(compute_prog);
+
+	glBeginConditionalRender(query,GL_QUERY_WAIT);
+
+	glDispatchCompute(1, 1, 1);
+
+	glEndConditionalRender();
+
+	ptr = (uint32_t *) glMapBufferRange(GL_ATOMIC_COUNTER_BUFFER, 0,
+	                                    sizeof(uint32_t), GL_MAP_READ_BIT);
+	result = *ptr == (enabled ? 1 : 0);
+	glUnmapBuffer(GL_ATOMIC_COUNTER_BUFFER);
+	piglit_report_subtest_result(result ? PIGLIT_PASS : PIGLIT_FAIL,
+	                             enabled ? "enabled" : "disabled");
+
+	glDeleteVertexArrays(1, &vao);
+	glDeleteProgram(graphics_prog);
+	glDeleteProgram(compute_prog);
+	glDeleteBuffers(1, &buffer);
+	glDeleteQueries(1, &query);
+	piglit_present_results();
+	return result;
+}
+
+enum piglit_result
+piglit_display(void)
+{
+	bool result = true;
+	result &= single_test(false);
+	result &= single_test(true);
+	return result ? PIGLIT_PASS : PIGLIT_FAIL;
+}
+
+void
+piglit_init(int argc, char **argv)
+{
+	piglit_require_gl_version(42);
+	piglit_require_extension("GL_ARB_compute_shader");
+
+}
-- 
2.8.0



More information about the Piglit mailing list