[Piglit] [PATCH 06/13] arb_compute_shader: Add test for atomicAdd(int, int)

Ian Romanick idr at freedesktop.org
Fri Jun 1 22:43:11 UTC 2018


From: Ian Romanick <ian.d.romanick at intel.com>

Signed-off-by: Ian Romanick <ian.d.romanick at intel.com>
---
 .../execution/shared-atomicAdd-int.shader_test     | 57 ++++++++++++++++++++++
 1 file changed, 57 insertions(+)
 create mode 100644 tests/spec/arb_compute_shader/execution/shared-atomicAdd-int.shader_test

diff --git a/tests/spec/arb_compute_shader/execution/shared-atomicAdd-int.shader_test b/tests/spec/arb_compute_shader/execution/shared-atomicAdd-int.shader_test
new file mode 100644
index 000000000..d6e3ad9c5
--- /dev/null
+++ b/tests/spec/arb_compute_shader/execution/shared-atomicAdd-int.shader_test
@@ -0,0 +1,57 @@
+[require]
+GL >= 3.3
+GLSL >= 3.30
+GL_ARB_compute_shader
+GL_ARB_shader_atomic_counters
+
+[compute shader]
+#version 330
+#extension GL_ARB_compute_shader: require
+#extension GL_ARB_shader_atomic_counters: require
+
+layout(local_size_x = 32) in;
+
+shared int value;
+shared uint mask;
+
+layout(binding = 0) uniform atomic_uint pass;
+layout(binding = 0) uniform atomic_uint fail;
+
+void main()
+{
+	if (gl_LocalInvocationIndex == 0u) {
+		value = 0;
+		mask = 0u;
+	}
+
+	barrier();
+
+	/* Each local invocation should see a unique value.  Each value
+	 * observed is tracked in "mask."  The test automatically fails if a
+	 * duplicate value is observed.  The test passes once all 32 possible
+	 * values have been observed.
+	 */
+	int f = atomicAdd(value, 4);
+	uint i = uint(f) / 4u;
+	uint bit = i % 32u;
+	uint m = 1u << bit;
+
+	if (i < 32u) {
+		/* If the bit was already set, the test fails. */
+		uint r = atomicOr(mask, m);
+		if ((r & m) != 0u)
+			atomicCounterIncrement(fail);
+
+		/* Once all 32 bits are set, the test passes. */
+		if ((r | m) == 0xffffffffu)
+			atomicCounterIncrement(pass);
+	} else {
+		atomicCounterIncrement(fail);
+	}
+}
+
+[test]
+atomic counters 2
+compute 2 3 4
+probe atomic counter 0 == 24
+probe atomic counter 1 == 0
-- 
2.14.4



More information about the Piglit mailing list