[Piglit] [PATCH 07/13] arb_compute_shader: Add test for atomicExchange(int, int)
Ian Romanick
idr at freedesktop.org
Fri Jun 1 22:43:12 UTC 2018
From: Ian Romanick <ian.d.romanick at intel.com>
Signed-off-by: Ian Romanick <ian.d.romanick at intel.com>
---
.../shared-atomicExchange-int.shader_test | 75 ++++++++++++++++++++++
1 file changed, 75 insertions(+)
create mode 100644 tests/spec/arb_compute_shader/execution/shared-atomicExchange-int.shader_test
diff --git a/tests/spec/arb_compute_shader/execution/shared-atomicExchange-int.shader_test b/tests/spec/arb_compute_shader/execution/shared-atomicExchange-int.shader_test
new file mode 100644
index 000000000..2bd2bf1c1
--- /dev/null
+++ b/tests/spec/arb_compute_shader/execution/shared-atomicExchange-int.shader_test
@@ -0,0 +1,75 @@
+[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) {
+ /* Bootstrapping this with zero is unavoidable, bit it
+ * also causes problems later. Namely it means that
+ * bit 0 will get set twice and invocation 0 can see a
+ * zero value. Note the explicit checks for bit != 0
+ * and gl_LocalInvocationIndex != 0 below.
+ */
+ value = 0;
+ mask = 0u;
+ }
+
+ barrier();
+
+ int f = atomicExchange(value, 2 * int(gl_LocalInvocationIndex));
+ uint i = uint(f) / 2u;
+ 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 (bit != 0u && (r & m) != 0u)
+ atomicCounterIncrement(fail);
+
+ /* Invocation index 0 can read it's own index (due to
+ * bootstrapping with zero), but no other invocation should.
+ */
+ if (gl_LocalInvocationIndex != 0u &&
+ bit == gl_LocalInvocationIndex)
+ atomicCounterIncrement(fail);
+ } else {
+ atomicCounterIncrement(fail);
+ }
+
+ barrier();
+
+ if (gl_LocalInvocationIndex == 0u) {
+ uint i = uint(value / 2);
+ uint bit = i % 32u;
+ uint m = 1u << bit;
+
+ uint final = m | mask;
+
+ /* If all 32 bits are set, the test passes. */
+ if (final == 0xffffffffu)
+ atomicCounterIncrement(pass);
+ }
+}
+
+[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