summaryrefslogtreecommitdiff
path: root/tests/spec/arb_arrays_of_arrays/execution/atomic_counters/vs-simple-inc-dec-read.shader_test
blob: c0f319c011aa7557e99821f23387145a63f4da00 (plain)
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# Simple test of atomicCounterIncrement, atomicCounterDecrement and
# atomicCounter being used in the VS.

[require]
GLSL >= 1.40
GL_ARB_shader_atomic_counters
GL_ARB_arrays_of_arrays
INT GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS >= 1

[vertex shader]
#version 140
#extension GL_ARB_shader_atomic_counters: require
#extension GL_ARB_arrays_of_arrays: require

layout(binding = 0) uniform atomic_uint a0[2][4];
layout(binding = 0) uniform atomic_uint a1[3][2][2];

in vec4 piglit_vertex;
out vec4 vcolor;

void main()
{
	bool passed = true;
	uint v0[12];
	uint v1[12];

	/* Get all initail values of a0 */
	v0[0] = atomicCounter(a0[0][0]);
	v0[1] = atomicCounter(a0[0][1]);
	v0[2] = atomicCounter(a0[0][2]);
	v0[3] = atomicCounter(a0[0][3]);
	v0[4] = atomicCounter(a0[1][0]);
	v0[5] = atomicCounter(a0[1][1]);
	v0[6] = atomicCounter(a0[1][2]);
	v0[7] = atomicCounter(a0[1][3]);

	/* Test that incrementing, followed by a read of an atomic
	 * counter results in a larger value.
	 * Also test that all other array elements are unaffected. */
	atomicCounterIncrement(a0[0][0]);
	atomicCounterIncrement(a0[1][2]);
	v1[0] = atomicCounter(a0[0][0]);
	v1[1] = atomicCounter(a0[0][1]);
	v1[2] = atomicCounter(a0[0][2]);
	v1[3] = atomicCounter(a0[0][3]);
	v1[4] = atomicCounter(a0[1][0]);
	v1[5] = atomicCounter(a0[1][1]);
	v1[6] = atomicCounter(a0[1][2]);
	v1[7] = atomicCounter(a0[1][3]);
	if(v1[0] <= v0[0] || v1[1] != v0[1] || v1[2] != v0[2] ||
	   v1[3] != v0[3] || v1[4] != v0[4] || v1[5] != v0[5] ||
	   v1[6] <= v0[6] || v1[7] != v0[7])
		passed = false;

	/* Skip one decrement since it may be the 0 => 0xffffffff
	 * transition.
	 */
	atomicCounterDecrement(a1[0][1][1]);
	atomicCounterDecrement(a1[2][0][1]);

	/* Get all initail values of a1 */
	v0[0] = atomicCounter(a1[0][0][0]);
	v0[1] = atomicCounter(a1[0][0][1]);
	v0[2] = atomicCounter(a1[0][1][0]);
	v0[3] = atomicCounter(a1[0][1][1]);
	v0[4] = atomicCounter(a1[1][0][0]);
	v0[5] = atomicCounter(a1[1][0][1]);
	v0[6] = atomicCounter(a1[1][1][0]);
	v0[7] = atomicCounter(a1[1][1][1]);
	v0[8] = atomicCounter(a1[2][0][0]);
	v0[9] = atomicCounter(a1[2][0][1]);
	v0[10] = atomicCounter(a1[2][1][0]);
	v0[11] = atomicCounter(a1[2][1][1]);

	/* Test that a decrement of an atomic
	 * counter results in a smaller value.
	 * Also test that all other array elements are unaffected.
	 */
	v1[0] = atomicCounter(a1[0][0][0]);
	v1[1] = atomicCounter(a1[0][0][1]);
	v1[2] = atomicCounter(a1[0][1][0]);
	v1[3] = atomicCounterDecrement(a1[0][1][1]);
	v1[4] = atomicCounter(a1[1][0][0]);
	v1[5] = atomicCounter(a1[1][0][1]);
	v1[6] = atomicCounter(a1[1][1][0]);
	v1[7] = atomicCounter(a1[1][1][1]);
	v1[8] = atomicCounter(a1[2][0][0]);
	v1[9] = atomicCounterDecrement(a1[2][0][1]);
	v1[10] = atomicCounter(a1[2][1][0]);
	v1[11] = atomicCounter(a1[2][1][1]);

	if(v1[0] != v0[0] || v1[1] != v0[1] || v1[2] != v0[2] ||
	   v1[3] >= v0[3] || v1[4] != v0[4] || v1[5] != v0[5] ||
	   v1[6] != v0[6] || v1[7] != v0[7] || v1[8] != v0[8] ||
	   v1[9] >= v0[9] || v1[10] != v0[10] || v1[11] != v0[11])
		passed = false;

	if (passed)
		vcolor = vec4(0.0, 1.0, 0.0, 1.0);
	else
		vcolor = vec4(1.0, 0.0, 0.0, 1.0);

	gl_Position = piglit_vertex;
}

[fragment shader]
#version 140
in vec4 vcolor;
out vec4 fcolor;

void main()
{
	fcolor = vcolor;
}

[test]
atomic counters 20

draw rect -1 -1 2 2
probe all rgba 0.0 1.0 0.0 1.0