[Piglit] [PATCH v2 2/2] add ARB_compute_variable_group_size tests

Samuel Pitoiset samuel.pitoiset at gmail.com
Sat Sep 10 15:19:18 UTC 2016


v1: - update formatting spec quotations (Nicolai)
    - use shader_runner for the basic test (Ian)
    - add a new test which checks various local sizes (Nicolai)

Signed-off-by: Samuel Pitoiset <samuel.pitoiset at gmail.com>
---
 tests/all.py                                       |   8 +
 tests/spec/CMakeLists.txt                          |   1 +
 .../CMakeLists.gl.txt                              |  16 ++
 .../arb_compute_variable_group_size/CMakeLists.txt |   1 +
 .../compiler/do_nothing.comp                       |  14 +
 .../compiler/gl_LocalGroupSizeARB_illegal_use.comp |  28 ++
 .../compiler/gl_LocalGroupSizeARB_layout.comp      |  27 ++
 .../mixed_fixed_variable_local_work_size.comp      |  23 ++
 .../spec/arb_compute_variable_group_size/errors.c  | 249 ++++++++++++++++++
 .../execution/basic-local-size.shader_test         |  31 +++
 ...ixed_fixed_variable_local_work_size.shader_test |  36 +++
 .../linker/no_local_size_specified.shader_test     |  32 +++
 .../arb_compute_variable_group_size/local-size.c   | 283 +++++++++++++++++++++
 .../spec/arb_compute_variable_group_size/minmax.c  |  65 +++++
 14 files changed, 814 insertions(+)
 create mode 100644 tests/spec/arb_compute_variable_group_size/CMakeLists.gl.txt
 create mode 100644 tests/spec/arb_compute_variable_group_size/CMakeLists.txt
 create mode 100644 tests/spec/arb_compute_variable_group_size/compiler/do_nothing.comp
 create mode 100644 tests/spec/arb_compute_variable_group_size/compiler/gl_LocalGroupSizeARB_illegal_use.comp
 create mode 100644 tests/spec/arb_compute_variable_group_size/compiler/gl_LocalGroupSizeARB_layout.comp
 create mode 100644 tests/spec/arb_compute_variable_group_size/compiler/mixed_fixed_variable_local_work_size.comp
 create mode 100644 tests/spec/arb_compute_variable_group_size/errors.c
 create mode 100644 tests/spec/arb_compute_variable_group_size/execution/basic-local-size.shader_test
 create mode 100644 tests/spec/arb_compute_variable_group_size/linker/mixed_fixed_variable_local_work_size.shader_test
 create mode 100644 tests/spec/arb_compute_variable_group_size/linker/no_local_size_specified.shader_test
 create mode 100644 tests/spec/arb_compute_variable_group_size/local-size.c
 create mode 100644 tests/spec/arb_compute_variable_group_size/minmax.c

diff --git a/tests/all.py b/tests/all.py
index 3961656..67793ba 100644
--- a/tests/all.py
+++ b/tests/all.py
@@ -4797,5 +4797,13 @@ with profile.group_manager(
     g(['ext_window_rectangles-errors_gles3'], 'errors_gles3')
     g(['ext_window_rectangles-render_gles3'], 'render_gles3')
 
+# Group ARB_compute_variable_group_size
+with profile.group_manager(
+	PiglitGLTest,
+	grouptools.join('spec', 'ARB_compute_variable_group_size')) as g:
+    g(['arb_compute_variable_group_size-errors'], 'errors')
+    g(['arb_compute_variable_group_size-local-size'], 'local-size')
+    g(['arb_compute_variable_group_size-minmax'], 'minmax')
+
 if platform.system() is 'Windows':
     profile.filter_tests(lambda p, _: not p.startswith('glx'))
diff --git a/tests/spec/CMakeLists.txt b/tests/spec/CMakeLists.txt
index 9b0f73e..3449a2b 100644
--- a/tests/spec/CMakeLists.txt
+++ b/tests/spec/CMakeLists.txt
@@ -9,6 +9,7 @@ add_subdirectory (arb_clip_control)
 add_subdirectory (arb_color_buffer_float)
 add_subdirectory (arb_copy_image)
 add_subdirectory (arb_compute_shader)
+add_subdirectory (arb_compute_variable_group_size)
 add_subdirectory (arb_cull_distance)
 add_subdirectory (arb_debug_output)
 add_subdirectory (khr_debug)
diff --git a/tests/spec/arb_compute_variable_group_size/CMakeLists.gl.txt b/tests/spec/arb_compute_variable_group_size/CMakeLists.gl.txt
new file mode 100644
index 0000000..a696271
--- /dev/null
+++ b/tests/spec/arb_compute_variable_group_size/CMakeLists.gl.txt
@@ -0,0 +1,16 @@
+include_directories(
+	${GLEXT_INCLUDE_DIR}
+	${OPENGL_INCLUDE_PATH}
+	${piglit_SOURCE_DIR}/tests/util
+)
+
+link_libraries (
+	piglitutil_${piglit_target_api}
+	${OPENGL_gl_LIBRARY}
+)
+
+piglit_add_executable (arb_compute_variable_group_size-errors errors.c)
+piglit_add_executable (arb_compute_variable_group_size-local-size local-size.c)
+piglit_add_executable (arb_compute_variable_group_size-minmax minmax.c)
+
+# vim: ft=cmake:
diff --git a/tests/spec/arb_compute_variable_group_size/CMakeLists.txt b/tests/spec/arb_compute_variable_group_size/CMakeLists.txt
new file mode 100644
index 0000000..144a306
--- /dev/null
+++ b/tests/spec/arb_compute_variable_group_size/CMakeLists.txt
@@ -0,0 +1 @@
+piglit_include_target_api()
diff --git a/tests/spec/arb_compute_variable_group_size/compiler/do_nothing.comp b/tests/spec/arb_compute_variable_group_size/compiler/do_nothing.comp
new file mode 100644
index 0000000..95c061b
--- /dev/null
+++ b/tests/spec/arb_compute_variable_group_size/compiler/do_nothing.comp
@@ -0,0 +1,14 @@
+// [config]
+// expect_result: pass
+// glsl_version: 3.30
+// require_extensions: GL_ARB_compute_variable_group_size
+// [end config]
+
+#version 330
+#extension GL_ARB_compute_variable_group_size: enable
+
+layout(local_size_variable) in;
+
+void main()
+{
+}
diff --git a/tests/spec/arb_compute_variable_group_size/compiler/gl_LocalGroupSizeARB_illegal_use.comp b/tests/spec/arb_compute_variable_group_size/compiler/gl_LocalGroupSizeARB_illegal_use.comp
new file mode 100644
index 0000000..f8fcf92
--- /dev/null
+++ b/tests/spec/arb_compute_variable_group_size/compiler/gl_LocalGroupSizeARB_illegal_use.comp
@@ -0,0 +1,28 @@
+// [config]
+// expect_result: fail
+// glsl_version: 3.30
+// require_extensions: GL_ARB_compute_variable_group_size
+// [end config]
+//
+// The ARB_compute_variable_group_size spec says:
+//
+//     However, the constant "gl_WorkGroupSize" would still be useful for
+//     sizing built-in arrays for shaders with a fixed work group size. For
+//     example, a shader might want to declare a shared variable with one
+//     instance per work group invocation, such as:
+//
+//     shared float shared_values[gl_WorkGroupSize.x *
+//                                gl_WorkGroupSize.y * gl_WorkGroupSize.z];
+//
+//     Such declarations would be illegal using the input
+//     "gl_LocalGroupSizeARB".
+
+#version 330
+#extension GL_ARB_compute_variable_group_size: enable
+
+layout(local_size_variable) in;
+
+void main()
+{
+	uint v[gl_LocalGroupSizeARB.x];
+}
diff --git a/tests/spec/arb_compute_variable_group_size/compiler/gl_LocalGroupSizeARB_layout.comp b/tests/spec/arb_compute_variable_group_size/compiler/gl_LocalGroupSizeARB_layout.comp
new file mode 100644
index 0000000..953856e
--- /dev/null
+++ b/tests/spec/arb_compute_variable_group_size/compiler/gl_LocalGroupSizeARB_layout.comp
@@ -0,0 +1,27 @@
+// [config]
+// expect_result: pass
+// glsl_version: 3.30
+// require_extensions: GL_ARB_compute_variable_group_size
+// [end config]
+//
+// The ARB_compute_variable_group_size spec says:
+//
+//     The built-in variable /gl_LocalGroupSizeARB/ is a compute-shader input
+//     variable containing the local work group size for the current compute-
+//     shader work group. For compute shaders with a fixed local group size
+//     (using *local_size_x*, *local_size_y*, or *local_size_z* layout
+//     qualifiers), its value will be the same as the constant
+//     /gl_WorkGroupSize/. For compute shaders with a variable local group size
+//     (using *local_size_variable*), the value of /gl_LocalGroupSizeARB/ will
+//     be the work group size specified in the OpenGL API command dispatching
+//     the current compute shader work.
+
+#version 330
+#extension GL_ARB_compute_variable_group_size: enable
+
+layout(local_size_variable) in;
+
+void main()
+{
+	uvec3 size = gl_LocalGroupSizeARB;
+}
diff --git a/tests/spec/arb_compute_variable_group_size/compiler/mixed_fixed_variable_local_work_size.comp b/tests/spec/arb_compute_variable_group_size/compiler/mixed_fixed_variable_local_work_size.comp
new file mode 100644
index 0000000..7bcfb4e
--- /dev/null
+++ b/tests/spec/arb_compute_variable_group_size/compiler/mixed_fixed_variable_local_work_size.comp
@@ -0,0 +1,23 @@
+// [config]
+// expect_result: fail
+// glsl_version: 3.30
+// require_extensions: GL_ARB_compute_variable_group_size
+// [end config]
+//
+// From the ARB_compute_variable_group_size spec:
+//
+//     If a compute shader including a *local_size_variable* qualifier also
+//     declares a fixed local group size using the *local_size_x*,
+//     *local_size_y*, or *local_size_z* qualifiers, a compile-time error
+//     results.
+
+#version 330
+#extension GL_ARB_compute_variable_group_size: enable
+#extension GL_ARB_compute_shader: enable
+
+layout(local_size_x = 2) in;
+layout(local_size_variable) in;
+
+void main()
+{
+}
diff --git a/tests/spec/arb_compute_variable_group_size/errors.c b/tests/spec/arb_compute_variable_group_size/errors.c
new file mode 100644
index 0000000..f020120
--- /dev/null
+++ b/tests/spec/arb_compute_variable_group_size/errors.c
@@ -0,0 +1,249 @@
+/*
+ * Copyright (C) 2016 Samuel Pitoiset
+ *
+ * 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
+ *
+ * Test cases in which the ARB_compute_variable_group_size API is expected to
+ * generate an error.
+ */
+
+#include "piglit-util-gl.h"
+#include "piglit-shader.h"
+
+static struct piglit_gl_test_config *piglit_config;
+
+PIGLIT_GL_TEST_CONFIG_BEGIN
+
+	piglit_config = &config;
+	config.supports_gl_compat_version = 33;
+	config.supports_gl_core_version = 33;
+
+PIGLIT_GL_TEST_CONFIG_END
+
+static const char *variable_work_group_size_shader =
+	"#version 330\n"
+	"#extension GL_ARB_compute_variable_group_size: enable\n"
+	"\n"
+	"layout(local_size_variable) in;\n"
+	"\n"
+	"void main()\n"
+	"{\n"
+	"}\n";
+
+static const char *fixed_work_group_size_shader =
+	"#version 330\n"
+	"#extension GL_ARB_compute_shader: enable\n"
+	"\n"
+	"layout(local_size_x = 1) in;\n"
+	"\n"
+	"void main()\n"
+	"{\n"
+	"}\n";
+
+static enum piglit_result
+use_variable_work_group_size_normal()
+{
+	/* The ARB_compute_variable_group_size spec says:
+	 *
+	 *    An INVALID_OPERATION error is generated by DispatchCompute or
+	 *    DispatchComputeIndirect if the active program for the compute
+	 *    shader stage has a variable work group size.
+	 */
+	GLint prog = piglit_build_simple_program_multiple_shaders(
+		GL_COMPUTE_SHADER, variable_work_group_size_shader, 0);
+	glUseProgram(prog);
+	glDispatchCompute(1, 1, 1);
+	if (!piglit_check_gl_error(GL_INVALID_OPERATION))
+		return PIGLIT_FAIL;
+	return PIGLIT_PASS;
+}
+
+static enum piglit_result
+use_variable_work_group_size_indirect()
+{
+	/* The ARB_compute_variable_group_size spec says:
+	 *
+	 *    An INVALID_OPERATION error is generated by DispatchCompute or
+	 *    DispatchComputeIndirect if the active program for the compute
+	 *    shader stage has a variable work group size.
+	 */
+	GLuint indirect_buf[3] = { 1, 1, 1 };
+	GLuint indirect_bo = 0;
+	GLint prog;
+
+	glGenBuffers(1, &indirect_bo);
+	if (!piglit_check_gl_error(GL_NO_ERROR))
+		return PIGLIT_FAIL;
+
+	glBindBuffer(GL_DISPATCH_INDIRECT_BUFFER, indirect_bo);
+	glBufferData(GL_DISPATCH_INDIRECT_BUFFER, sizeof(indirect_buf),
+		     indirect_buf, GL_STREAM_READ);
+
+	prog = piglit_build_simple_program_multiple_shaders(
+		GL_COMPUTE_SHADER, variable_work_group_size_shader, 0);
+	glUseProgram(prog);
+
+	glBindBuffer(GL_DISPATCH_INDIRECT_BUFFER, indirect_bo);
+	glDispatchComputeIndirect(0);
+	if (!piglit_check_gl_error(GL_INVALID_OPERATION))
+		return PIGLIT_FAIL;
+
+	glDeleteBuffers(1, &indirect_bo);
+	return PIGLIT_PASS;
+}
+
+static enum piglit_result
+use_fixed_work_group_size()
+{
+	/* The ARB_compute_variable_group_size spec says:
+	 *
+	 *     An INVALID_OPERATION error is generated by
+	 *     DispatchComputeGroupSizeARB if the active program for the
+	 *     compute shader stage has a fixed work group size.
+	 */
+	GLint prog = piglit_build_simple_program_multiple_shaders(
+		GL_COMPUTE_SHADER, fixed_work_group_size_shader, 0);
+	glUseProgram(prog);
+	glDispatchComputeGroupSizeARB(1, 1, 1, 1, 1, 1);
+	if (!piglit_check_gl_error(GL_INVALID_OPERATION))
+		return PIGLIT_FAIL;
+	return PIGLIT_PASS;
+}
+
+static enum piglit_result
+use_invalid_variable_work_group_size_values()
+{
+	/* The ARB_compute_variable_group_size spec says:
+	 *
+	 *     An INVALID_VALUE error is generated by
+	 *     DispatchComputeGroupSizeARB if any of <group_size_x>,
+	 *     <group_size_y>, or <group_size_z> is less than or equal to zero
+	 *     or greater than the maximum local work group size for compute
+	 *     shaders with variable group size
+	 *     (MAX_COMPUTE_VARIABLE_GROUP_SIZE_ARB) in the corresponding
+	 *     dimension.
+	 */
+	GLint prog, v[3];
+
+	prog = piglit_build_simple_program_multiple_shaders(
+		GL_COMPUTE_SHADER, variable_work_group_size_shader, 0);
+	glUseProgram(prog);
+
+	/* Use values equal to zero (because "less than" is a spec bug). */
+	glDispatchComputeGroupSizeARB(1, 1, 1, 0, 0, 0);
+	if (!piglit_check_gl_error(GL_INVALID_VALUE))
+		return PIGLIT_FAIL;
+
+	/* Use values greater than the maximum local work group size. */
+	glGetIntegeri_v(GL_MAX_COMPUTE_VARIABLE_GROUP_SIZE_ARB, 0, &v[0]);
+	glGetIntegeri_v(GL_MAX_COMPUTE_VARIABLE_GROUP_SIZE_ARB, 1, &v[1]);
+	glGetIntegeri_v(GL_MAX_COMPUTE_VARIABLE_GROUP_SIZE_ARB, 2, &v[2]);
+	glDispatchComputeGroupSizeARB(1, 1, 1, v[0] + 1, v[1] + 1, v[0] + 1);
+	if (!piglit_check_gl_error(GL_INVALID_VALUE))
+		return PIGLIT_FAIL;
+	return PIGLIT_PASS;
+}
+
+static enum piglit_result
+use_invalid_variable_group_invocations_values()
+{
+	/* The ARB_compute_variable_group_size spec says:
+	 *
+	 *    An INVALID_VALUE error is generated by
+	 *    DispatchComputeGroupSizeARB if the product of <group_size_x>,
+	 *    <group_size_y>, and <group_size_z> exceeds the
+	 *    implementation-dependent maximum local work group invocation
+	 *    count for compute shaders with variable group size
+	 *    (MAX_COMPUTE_VARIABLE_GROUP_INVOCATIONS_ARB).
+	 */
+	GLint prog, v;
+
+	prog = piglit_build_simple_program_multiple_shaders(
+		GL_COMPUTE_SHADER, variable_work_group_size_shader, 0);
+	glUseProgram(prog);
+
+	glGetIntegerv(GL_MAX_COMPUTE_VARIABLE_GROUP_INVOCATIONS_ARB, &v);
+	glDispatchComputeGroupSizeARB(1, 1, 1, v, v, v);
+	if (!piglit_check_gl_error(GL_INVALID_VALUE))
+		return PIGLIT_FAIL;
+	return PIGLIT_PASS;
+}
+
+static const struct piglit_subtest subtests[] = {
+	{
+		"Use a variable work group size with DispatchCompute",
+		"use_variable_work_group_size_normal",
+		use_variable_work_group_size_normal,
+		NULL
+	},
+	{
+		"Use a variable work group size with DispatchComputeIndirect",
+		"use_variable_work_group_size_indirect",
+		use_variable_work_group_size_indirect,
+		NULL
+	},
+
+	{
+		"Use a fixed work group size with DispatchComputeGroupSizeARB",
+		"use_fixed_work_group_size",
+		use_fixed_work_group_size,
+		NULL
+	},
+	{
+		"Use invalid variable work group size values",
+		"use_invalid_variable_work_group_size_values",
+		use_invalid_variable_work_group_size_values,
+		NULL
+	},
+	{
+		"Use invalid variable group invocations values",
+		"use_invalid_variable_group_invocations_values",
+		use_invalid_variable_group_invocations_values,
+		NULL
+	},
+	{
+		NULL,
+		NULL,
+		NULL,
+		NULL
+	}
+};
+
+enum piglit_result
+piglit_display(void)
+{
+	return PIGLIT_FAIL;
+}
+
+void
+piglit_init(int argc, char **argv)
+{
+	enum piglit_result result;
+
+	piglit_require_extension("GL_ARB_compute_variable_group_size");
+	result = piglit_run_selected_subtests(subtests,
+					      piglit_config->selected_subtests,
+					      piglit_config->num_selected_subtests,
+					      PIGLIT_SKIP);
+	piglit_report_result(result);
+}
diff --git a/tests/spec/arb_compute_variable_group_size/execution/basic-local-size.shader_test b/tests/spec/arb_compute_variable_group_size/execution/basic-local-size.shader_test
new file mode 100644
index 0000000..108ebd5
--- /dev/null
+++ b/tests/spec/arb_compute_variable_group_size/execution/basic-local-size.shader_test
@@ -0,0 +1,31 @@
+# Simple test that verifies gl_LocalGroupSizeARB values are
+# functioning. Atomic counters are used as outputs.
+
+[require]
+GL >= 3.3
+GLSL >= 3.30
+GL_ARB_compute_variable_group_size
+GL_ARB_shader_atomic_counters
+
+[compute shader]
+#version 330
+#extension GL_ARB_compute_variable_group_size: enable
+#extension GL_ARB_shader_atomic_counters: require
+
+layout(binding = 0) uniform atomic_uint a;
+
+layout(local_size_variable) in;
+
+void main()
+{
+	if (gl_LocalGroupSizeARB.x == 8u &&
+	    gl_LocalGroupSizeARB.y == 4u &&
+	    gl_LocalGroupSizeARB.z == 2u)
+	atomicCounterIncrement(a);
+}
+
+[test]
+atomic counters 1
+
+compute group size 1 1 1 8 4 2
+probe atomic counter 0 == 64
diff --git a/tests/spec/arb_compute_variable_group_size/linker/mixed_fixed_variable_local_work_size.shader_test b/tests/spec/arb_compute_variable_group_size/linker/mixed_fixed_variable_local_work_size.shader_test
new file mode 100644
index 0000000..d660d56
--- /dev/null
+++ b/tests/spec/arb_compute_variable_group_size/linker/mixed_fixed_variable_local_work_size.shader_test
@@ -0,0 +1,36 @@
+# The ARB_compute_variable_group_size spec says:
+#
+#     If one compute shader attached to a program declares a variable local
+#     group size and a second compute shader attached to the same program
+#     declares a fixed local group size, a link-time error results.
+
+[require]
+GL >= 3.3
+GLSL >= 3.30
+GL_ARB_compute_shader
+
+[compute shader]
+#version 330
+#extension GL_ARB_compute_shader: enable
+
+layout(local_size_x = 2) in;
+
+void foo();
+
+void main()
+{
+	foo();
+}
+
+[compute shader]
+#version 330
+#extension GL_ARB_compute_variable_group_size: enable
+
+layout(local_size_variable) in;
+
+void foo()
+{
+}
+
+[test]
+link error
diff --git a/tests/spec/arb_compute_variable_group_size/linker/no_local_size_specified.shader_test b/tests/spec/arb_compute_variable_group_size/linker/no_local_size_specified.shader_test
new file mode 100644
index 0000000..6371c29
--- /dev/null
+++ b/tests/spec/arb_compute_variable_group_size/linker/no_local_size_specified.shader_test
@@ -0,0 +1,32 @@
+# The ARB_compute_variable_group_size spec says:
+#
+#     Furthermore, if a program object contains any compute shaders, at least
+#     one must contain an input layout qualifier specifying a fixed or variable
+#     local group size for the program, or a link-time error will occur.
+
+[require]
+GL >= 3.3
+GLSL >= 3.30
+GL_ARB_compute_shader
+
+[compute shader]
+#version 330
+#extension GL_ARB_compute_shader: enable
+
+void foo();
+
+void main()
+{
+	foo();
+}
+
+[compute shader]
+#version 330
+#extension GL_ARB_compute_variable_group_size: enable
+
+void foo()
+{
+}
+
+[test]
+link error
diff --git a/tests/spec/arb_compute_variable_group_size/local-size.c b/tests/spec/arb_compute_variable_group_size/local-size.c
new file mode 100644
index 0000000..301a920
--- /dev/null
+++ b/tests/spec/arb_compute_variable_group_size/local-size.c
@@ -0,0 +1,283 @@
+/*
+ * Copyright (c) 2016 Samuel Pitoiset
+ *
+ * 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
+ *
+ * Checks gl_LocalGroupSizeARB at various sizes up to the implementation
+ * maximums using atomic counters.
+ */
+
+#include "piglit-util-gl.h"
+
+PIGLIT_GL_TEST_CONFIG_BEGIN
+
+	config.supports_gl_compat_version = 33;
+	config.supports_gl_core_version = 33;
+
+PIGLIT_GL_TEST_CONFIG_END
+
+static GLuint atomics_bo = 0;
+static GLint prog = 0;
+
+static uint32_t global_x = 1, global_y = 1, global_z = 1;
+static uint32_t local_x = 0, local_y = 0, local_z = 0;
+static int32_t max_local_x = 0, max_local_y = 0, max_local_z = 0;
+
+static uint32_t 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 const char *compute_shader_source =
+	"#version 330\n"
+	"#extension GL_ARB_compute_variable_group_size: enable\n"
+	"#extension GL_ARB_shader_atomic_counters: require\n"
+	"\n"
+	"layout(binding = 0) uniform atomic_uint a;\n"
+	"layout(local_size_variable) in;\n"
+	"\n"
+	"void main()\n"
+	"{\n"
+	"	if (gl_LocalGroupSizeARB.x == %du &&\n"
+	"	    gl_LocalGroupSizeARB.y == %du &&\n"
+	"	    gl_LocalGroupSizeARB.z == %du)\n"
+	"		atomicCounterIncrement(a);\n"
+	"}\n";
+
+static GLuint
+generate_cs_prog(uint32_t x, uint32_t y, uint32_t z, char *src)
+{
+	char *source = NULL;
+
+	(void)!asprintf(&source, src, x, y, z);
+	free(src);
+
+	GLuint prog = glCreateProgram();
+
+	GLuint shader =
+		piglit_compile_shader_text_nothrow(GL_COMPUTE_SHADER, source);
+
+	if (!shader) {
+		glDeleteProgram(prog);
+		return 0;
+	}
+
+	glAttachShader(prog, shader);
+
+	glLinkProgram(prog);
+
+	glDeleteShader(shader);
+
+	if (!piglit_link_check_status(prog)) {
+		glDeleteProgram(prog);
+		return 0;
+	}
+
+	return prog;
+}
+
+static enum piglit_result
+check_result()
+{
+	uint32_t expected = local_x * local_y * local_z;
+	bool pass = true;
+	uint32_t *p;
+
+	glBindBufferBase(GL_ATOMIC_COUNTER_BUFFER, 0, atomics_bo);
+	p = glMapBufferRange(GL_ATOMIC_COUNTER_BUFFER, 0, sizeof(uint32_t),
+			     GL_MAP_READ_BIT);
+	if (!p) {
+		printf("Couldn't map atomic counter to verify expected value.\n");
+		return PIGLIT_FAIL;
+	}
+
+	if (p[0] != expected) {
+		printf("Atomic counter test failed for (%d, %d, %d)\n",
+		       local_x, local_y, local_z);
+		printf("  Reference: %u\n", expected);
+		printf("  Observed: %u\n", p[0]);
+		pass = false;
+	}
+
+	glUnmapBuffer(GL_ATOMIC_COUNTER_BUFFER);
+
+	return pass ? PIGLIT_PASS : PIGLIT_FAIL;
+}
+
+static enum piglit_result
+run_test()
+{
+	enum piglit_result result;
+	uint32_t atomics_init = 0;
+
+	if (local_x == 0 || local_y == 0 || local_z == 0)
+		return PIGLIT_FAIL;
+
+	glBindBufferBase(GL_ATOMIC_COUNTER_BUFFER, 0, atomics_bo);
+	glBufferData(GL_ATOMIC_COUNTER_BUFFER, sizeof(uint32_t), &atomics_init,
+		     GL_STATIC_DRAW);
+
+	glUseProgram(prog);
+
+	glMemoryBarrier(GL_ALL_BARRIER_BITS);
+	glDispatchComputeGroupSizeARB(global_x, global_y, global_z,
+				      local_x, local_y, local_z);
+	if (!piglit_check_gl_error(GL_NO_ERROR))
+		return PIGLIT_FAIL;
+	glMemoryBarrier(GL_ALL_BARRIER_BITS);
+
+	result = check_result();
+	if (result != PIGLIT_PASS)
+		piglit_report_result(result);
+
+	return result;
+}
+
+static void
+clear_program()
+{
+	if (prog != 0) {
+		local_x = 0;
+		local_y = 0;
+		local_z = 0;
+		glDeleteProgram(prog);
+		prog = 0;
+	}
+}
+
+static enum piglit_result
+build_program_for_size(uint32_t x, uint32_t y, uint32_t z)
+{
+	if (local_x == x && local_y == y &&
+	    local_z == z && prog != 0) {
+		return PIGLIT_PASS;
+	}
+
+	clear_program();
+
+	prog = generate_cs_prog(x, y, z, strdup(compute_shader_source));
+
+	if (!prog)
+		return PIGLIT_FAIL;
+
+	local_x = x;
+	local_y = y;
+	local_z = z;
+
+	return PIGLIT_PASS;
+}
+
+enum piglit_result
+set_local_size(uint32_t x, uint32_t y, uint32_t z)
+{
+	enum piglit_result result = PIGLIT_PASS;
+
+	if (x == 0 || y == 0 || z == 0) {
+		clear_program();
+		return PIGLIT_FAIL;
+	}
+
+	result = build_program_for_size(x, y, z);
+	if (result != PIGLIT_PASS)
+		piglit_report_result(result);
+
+	return result;
+}
+
+static enum piglit_result
+test_size(uint32_t x, uint32_t y, uint32_t z)
+{
+	enum piglit_result result;
+
+	result = set_local_size(x, y, z);
+	if (result != PIGLIT_PASS)
+		piglit_report_result(result);
+
+	result = run_test();
+	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 > max_local_z)
+			break;
+		for (yi = 0; yi < ARRAY_SIZE(sizes); yi++) {
+			y = sizes[yi];
+			if ((y * z) > max_local_y)
+				break;
+			for (xi = 0; xi < ARRAY_SIZE(sizes); xi++) {
+				x = sizes[xi];
+				if ((x * y * z) > max_local_x)
+					break;
+				result = test_size(x, y, z);
+				if (result != PIGLIT_PASS)
+					return result;
+			}
+		}
+	}
+
+	return result;
+}
+
+enum piglit_result
+piglit_display(void)
+{
+	return PIGLIT_FAIL;
+}
+
+void
+piglit_init(int argc, char **argv)
+{
+	enum piglit_result result;
+
+	piglit_require_extension("GL_ARB_compute_variable_group_size");
+	piglit_require_extension("GL_ARB_shader_atomic_counters");
+
+	glGenBuffers(1, &atomics_bo);
+	if (!piglit_check_gl_error(GL_NO_ERROR))
+		piglit_report_result(PIGLIT_FAIL);
+
+	glGetIntegeri_v(GL_MAX_COMPUTE_VARIABLE_GROUP_SIZE_ARB,
+			0, &max_local_x);
+	glGetIntegeri_v(GL_MAX_COMPUTE_VARIABLE_GROUP_SIZE_ARB,
+			1, &max_local_y);
+	glGetIntegeri_v(GL_MAX_COMPUTE_VARIABLE_GROUP_SIZE_ARB,
+			2, &max_local_z);
+
+	result = test_all_sizes();
+
+	glDeleteBuffers(1, &atomics_bo);
+
+	piglit_report_result(result);
+}
diff --git a/tests/spec/arb_compute_variable_group_size/minmax.c b/tests/spec/arb_compute_variable_group_size/minmax.c
new file mode 100644
index 0000000..cd8f1ea
--- /dev/null
+++ b/tests/spec/arb_compute_variable_group_size/minmax.c
@@ -0,0 +1,65 @@
+/*
+ * Copyright © 2016 Samuel Pitoiset
+ *
+ * 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
+ *
+ * Test for the minimum maximum values specified in the
+ * ARB_compute_variable_group_size extension.
+ */
+
+#include "piglit-util-gl.h"
+#include "minmax-test.h"
+
+PIGLIT_GL_TEST_CONFIG_BEGIN
+
+	config.supports_gl_compat_version = 33;
+	config.supports_gl_core_version = 33;
+
+PIGLIT_GL_TEST_CONFIG_END
+
+enum piglit_result
+piglit_display(void)
+{
+	/* UNREACHED */
+	return PIGLIT_FAIL;
+}
+
+void
+piglit_init(int argc, char **argv)
+{
+	piglit_require_extension("GL_ARB_compute_variable_group_size");
+	piglit_print_minmax_header();
+
+	piglit_test_min_int_v(GL_MAX_COMPUTE_VARIABLE_GROUP_SIZE_ARB, 0, 512);
+	piglit_test_min_int_v(GL_MAX_COMPUTE_VARIABLE_GROUP_SIZE_ARB, 1, 512);
+	piglit_test_min_int_v(GL_MAX_COMPUTE_VARIABLE_GROUP_SIZE_ARB, 2, 64);
+	piglit_test_min_int(GL_MAX_COMPUTE_VARIABLE_GROUP_INVOCATIONS_ARB, 512);
+	piglit_test_min_int_v(GL_MAX_COMPUTE_FIXED_GROUP_SIZE_ARB, 0, 1024);
+	piglit_test_min_int_v(GL_MAX_COMPUTE_FIXED_GROUP_SIZE_ARB, 1, 1024);
+	piglit_test_min_int_v(GL_MAX_COMPUTE_FIXED_GROUP_SIZE_ARB, 2, 64);
+	piglit_test_min_int(GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS, 1024);
+
+	if (!piglit_check_gl_error(GL_NO_ERROR))
+		piglit_report_result(PIGLIT_FAIL);
+	piglit_report_result(piglit_minmax_pass ? PIGLIT_PASS : PIGLIT_FAIL);
+}
-- 
2.9.3



More information about the Piglit mailing list