File: shared-atomicAdd-float.shader_test

package info (click to toggle)
piglit 0~git20200212-f4710c51b-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 106,972 kB
  • sloc: ansic: 263,763; xml: 48,941; python: 29,918; lisp: 19,789; cpp: 12,142; sh: 22; makefile: 20; pascal: 5
file content (59 lines) | stat: -rw-r--r-- 1,295 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
[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) {
		value = 0.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.
	 */
	float f = atomicAdd(value, .5);
	uint i = uint(f * 2.0);
	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