From: Ian Romanick <ian.d.roman...@intel.com>

Signed-off-by: Ian Romanick <ian.d.roman...@intel.com>
---
 .../shared-atomicExchange-float.shader_test        | 77 +++++++++++++++++++++
 .../ssbo-atomicExchange-float.shader_test          | 78 ++++++++++++++++++++++
 2 files changed, 155 insertions(+)
 create mode 100644 
tests/spec/nv_shader_atomic_float/execution/shared-atomicExchange-float.shader_test
 create mode 100644 
tests/spec/nv_shader_atomic_float/execution/ssbo-atomicExchange-float.shader_test

diff --git 
a/tests/spec/nv_shader_atomic_float/execution/shared-atomicExchange-float.shader_test
 
b/tests/spec/nv_shader_atomic_float/execution/shared-atomicExchange-float.shader_test
new file mode 100644
index 000000000..1ae6e1a65
--- /dev/null
+++ 
b/tests/spec/nv_shader_atomic_float/execution/shared-atomicExchange-float.shader_test
@@ -0,0 +1,77 @@
+[require]
+GL >= 3.3
+GLSL >= 3.30
+GL_ARB_compute_shader
+GL_ARB_shader_atomic_counters
+GL_NV_shader_atomic_float
+
+[compute shader]
+#version 330
+#extension GL_ARB_compute_shader: require
+#extension GL_ARB_shader_atomic_counters: require
+#extension GL_NV_shader_atomic_float: require
+
+layout(local_size_x = 32) in;
+
+shared float 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.0;
+               mask = 0u;
+       }
+
+       barrier();
+
+       float f = atomicExchange(value, .5 * float(gl_LocalInvocationIndex));
+       uint i = uint(f * 2.);
+       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
diff --git 
a/tests/spec/nv_shader_atomic_float/execution/ssbo-atomicExchange-float.shader_test
 
b/tests/spec/nv_shader_atomic_float/execution/ssbo-atomicExchange-float.shader_test
new file mode 100644
index 000000000..6267c89ec
--- /dev/null
+++ 
b/tests/spec/nv_shader_atomic_float/execution/ssbo-atomicExchange-float.shader_test
@@ -0,0 +1,78 @@
+[require]
+GL >= 3.3
+GLSL >= 3.30
+GL_ARB_shader_storage_buffer_object
+GL_ARB_shader_atomic_counters
+GL_ARB_shader_atomic_counter_ops
+GL_NV_shader_atomic_float
+
+[vertex shader passthrough]
+
+[fragment shader]
+#version 330
+#extension GL_ARB_shader_storage_buffer_object: require
+#extension GL_ARB_shader_atomic_counters: require
+#extension GL_ARB_shader_atomic_counter_ops: require
+#extension GL_NV_shader_atomic_float: require
+
+layout(binding = 0) buffer bufblock {
+       float value;
+};
+
+/* GL_ARB_shader_atomic_counters requires at least 8 total counters. */
+layout(binding = 0) uniform atomic_uint mask[7];
+layout(binding = 0) uniform atomic_uint fail;
+
+out vec4 color;
+
+const uint max_index = uint(mask.length()) * 32u + 31u;
+
+void main()
+{
+       uint x = uint(gl_FragCoord.x);
+       uint y = uint(gl_FragCoord.y);
+       uint local_index = y * 32u + x;
+
+       float new_value = (x < 32u && y < uint(mask.length()))
+               ? 0.5 * float(local_index) : 3e10;
+
+       float f = atomicExchange(value, new_value);
+       uint i = uint(f * 2.);
+       uint bit = i % 32u;
+       int c = int(i / 32u);
+       uint m = 1u << bit;
+
+       if (i <= max_index) {
+               /* If the bit was already set, the test fails. */
+               uint r = atomicCounterOrARB(mask[c], m);
+               if ((r & m) != 0u)
+                       atomicCounterIncrement(fail);
+
+               if (bit == local_index)
+                       atomicCounterIncrement(fail);
+
+               color = vec4(0.0, 1.0, 0.0, 1.0);
+       } else {
+               color = vec4(0.0, 0.0, 1.0, 1.0);
+       }
+}
+
+[test]
+atomic counters 8
+
+ssbo 0 32
+ssbo 0 subdata float 0 3e10
+
+clear color 0.5 0.5 0.5 0.5
+clear
+
+draw rect -1 -1 2 2
+
+probe atomic counter 0 == 4294967295
+probe atomic counter 1 == 4294967295
+probe atomic counter 2 == 4294967295
+probe atomic counter 3 == 4294967295
+probe atomic counter 4 == 4294967295
+probe atomic counter 5 == 4294967295
+probe atomic counter 6 == 4294967295
+probe atomic counter 7 == 0
-- 
2.14.4

_______________________________________________
Piglit mailing list
Piglit@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/piglit

Reply via email to