Fix missing dependency on sparse binds
[platform/upstream/VK-GL-CTS.git] / external / vulkancts / data / vulkan / amber / graphicsfuzz / unreachable-barrier-in-loops.amber
1 # Copyright 2019 Google LLC
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 #     http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14
15 # A test for a bug found by GraphicsFuzz.
16
17 # Short description: A compute shader with an unreachable barrier in a loop nest
18
19 # The test passes because the compute shader has a single global invocation that
20 # is guaranteed to set 'value' to (0.0, 0.0, 0.0, 1.0), and that writes the
21 # components of 'value', cast to integers, to '_compute_data' at the end of
22 # execution.  The early return is unreachable.
23
24 # Derived from the following GLSL.
25
26 # Compute shader GLSL:
27 # #version 310 es
28 #
29 # precision highp float;
30 #
31 # layout(set = 0, binding = 2) uniform buf2 {
32 #  vec2 resolution;
33 # };
34 #
35 # layout(set = 0, binding = 1) uniform buf1 {
36 #  vec2 injectionSwitch;
37 # };
38 #
39 # layout(std430, binding = 0) buffer doesNotMatter {
40 #  int _compute_data[];
41 # };
42 #
43 # layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
44 #
45 # void main(void)
46 # {
47 #  vec4 value;
48 #  float A[1];
49 #  A[0] = 0.0;
50 #  for(int i = 0; i < 50; i++) {
51 #    if(i > 0) {
52 #      A[0] += A[0];
53 #    }
54 #  }
55 #  do {
56 #   if(gl_GlobalInvocationID.x < 100u) {
57 #    value = vec4(0.0, 0.0, 0.0, 1.0);
58 #    for(int m = 0; m < 1; m++) {
59 #     for(int l = 0; l < 1; l++) {
60 #      if(injectionSwitch.x > injectionSwitch.y)
61 #       return;
62 #     }
63 #    }
64 #    for(int n = 0; n < 1; n ++) {
65 #     if(injectionSwitch.x > injectionSwitch.y)
66 #      barrier();
67 #    }
68 #   } else {
69 #    if(gl_GlobalInvocationID.x < 120u) {
70 #     value = vec4(A[0] / resolution.x, A[0] / resolution.y, 0.0, 1.0);
71 #    } else {
72 #     if(injectionSwitch.x > injectionSwitch.y)
73 #      continue;
74 #    }
75 #   }
76 #  } while(false);
77 #  _compute_data[0] = int(value.x);
78 #  _compute_data[1] = int(value.y);
79 #  _compute_data[2] = int(value.z);
80 #  _compute_data[3] = int(value.w);
81 # }
82
83 [compute shader spirv]
84 ; SPIR-V
85 ; Version: 1.0
86 ; Generator: Khronos Glslang Reference Front End; 7
87 ; Bound: 168
88 ; Schema: 0
89                OpCapability Shader
90           %1 = OpExtInstImport "GLSL.std.450"
91                OpMemoryModel Logical GLSL450
92                OpEntryPoint GLCompute %4 "main" %47
93                OpExecutionMode %4 LocalSize 1 1 1
94                OpSource ESSL 310
95                OpName %4 "main"
96                OpName %11 "A"
97                OpName %18 "i"
98                OpName %47 "gl_GlobalInvocationID"
99                OpName %58 "value"
100                OpName %61 "m"
101                OpName %69 "l"
102                OpName %78 "buf1"
103                OpMemberName %78 0 "injectionSwitch"
104                OpName %80 ""
105                OpName %94 "n"
106                OpName %122 "buf2"
107                OpMemberName %122 0 "resolution"
108                OpName %124 ""
109                OpName %145 "doesNotMatter"
110                OpMemberName %145 0 "_compute_data"
111                OpName %147 ""
112                OpDecorate %47 BuiltIn GlobalInvocationId
113                OpMemberDecorate %78 0 Offset 0
114                OpDecorate %78 Block
115                OpDecorate %80 DescriptorSet 0
116                OpDecorate %80 Binding 1
117                OpMemberDecorate %122 0 Offset 0
118                OpDecorate %122 Block
119                OpDecorate %124 DescriptorSet 0
120                OpDecorate %124 Binding 2
121                OpDecorate %144 ArrayStride 4
122                OpMemberDecorate %145 0 Offset 0
123                OpDecorate %145 BufferBlock
124                OpDecorate %147 DescriptorSet 0
125                OpDecorate %147 Binding 0
126           %2 = OpTypeVoid
127           %3 = OpTypeFunction %2
128           %6 = OpTypeFloat 32
129           %7 = OpTypeInt 32 0
130           %8 = OpConstant %7 1
131           %9 = OpTypeArray %6 %8
132          %10 = OpTypePointer Function %9
133          %12 = OpTypeInt 32 1
134          %13 = OpConstant %12 0
135          %14 = OpConstant %6 0
136          %15 = OpTypePointer Function %6
137          %17 = OpTypePointer Function %12
138          %25 = OpConstant %12 50
139          %26 = OpTypeBool
140          %39 = OpConstant %12 1
141          %45 = OpTypeVector %7 3
142          %46 = OpTypePointer Input %45
143          %47 = OpVariable %46 Input
144          %48 = OpConstant %7 0
145          %49 = OpTypePointer Input %7
146          %52 = OpConstant %7 100
147          %56 = OpTypeVector %6 4
148          %57 = OpTypePointer Function %56
149          %59 = OpConstant %6 1
150          %60 = OpConstantComposite %56 %14 %14 %14 %59
151          %77 = OpTypeVector %6 2
152          %78 = OpTypeStruct %77
153          %79 = OpTypePointer Uniform %78
154          %80 = OpVariable %79 Uniform
155          %81 = OpTypePointer Uniform %6
156         %109 = OpConstant %7 2
157         %110 = OpConstant %7 264
158         %116 = OpConstant %7 120
159         %122 = OpTypeStruct %77
160         %123 = OpTypePointer Uniform %122
161         %124 = OpVariable %123 Uniform
162         %143 = OpConstantFalse %26
163         %144 = OpTypeRuntimeArray %12
164         %145 = OpTypeStruct %144
165         %146 = OpTypePointer Uniform %145
166         %147 = OpVariable %146 Uniform
167         %151 = OpTypePointer Uniform %12
168         %157 = OpConstant %12 2
169         %162 = OpConstant %12 3
170         %163 = OpConstant %7 3
171           %4 = OpFunction %2 None %3
172           %5 = OpLabel
173          %11 = OpVariable %10 Function
174          %18 = OpVariable %17 Function
175          %58 = OpVariable %57 Function
176          %61 = OpVariable %17 Function
177          %69 = OpVariable %17 Function
178          %94 = OpVariable %17 Function
179          %16 = OpAccessChain %15 %11 %13
180                OpStore %16 %14
181                OpStore %18 %13
182                OpBranch %19
183          %19 = OpLabel
184                OpLoopMerge %21 %22 None
185                OpBranch %23
186          %23 = OpLabel
187          %24 = OpLoad %12 %18
188          %27 = OpSLessThan %26 %24 %25
189                OpBranchConditional %27 %20 %21
190          %20 = OpLabel
191          %28 = OpLoad %12 %18
192          %29 = OpSGreaterThan %26 %28 %13
193                OpSelectionMerge %31 None
194                OpBranchConditional %29 %30 %31
195          %30 = OpLabel
196          %32 = OpAccessChain %15 %11 %13
197          %33 = OpLoad %6 %32
198          %34 = OpAccessChain %15 %11 %13
199          %35 = OpLoad %6 %34
200          %36 = OpFAdd %6 %35 %33
201          %37 = OpAccessChain %15 %11 %13
202                OpStore %37 %36
203                OpBranch %31
204          %31 = OpLabel
205                OpBranch %22
206          %22 = OpLabel
207          %38 = OpLoad %12 %18
208          %40 = OpIAdd %12 %38 %39
209                OpStore %18 %40
210                OpBranch %19
211          %21 = OpLabel
212                OpBranch %41
213          %41 = OpLabel
214                OpLoopMerge %43 %44 None
215                OpBranch %42
216          %42 = OpLabel
217          %50 = OpAccessChain %49 %47 %48
218          %51 = OpLoad %7 %50
219          %53 = OpULessThan %26 %51 %52
220                OpSelectionMerge %55 None
221                OpBranchConditional %53 %54 %113
222          %54 = OpLabel
223                OpStore %58 %60
224                OpStore %61 %13
225                OpBranch %62
226          %62 = OpLabel
227                OpLoopMerge %64 %65 None
228                OpBranch %66
229          %66 = OpLabel
230          %67 = OpLoad %12 %61
231          %68 = OpSLessThan %26 %67 %39
232                OpBranchConditional %68 %63 %64
233          %63 = OpLabel
234                OpStore %69 %13
235                OpBranch %70
236          %70 = OpLabel
237                OpLoopMerge %72 %73 None
238                OpBranch %74
239          %74 = OpLabel
240          %75 = OpLoad %12 %69
241          %76 = OpSLessThan %26 %75 %39
242                OpBranchConditional %76 %71 %72
243          %71 = OpLabel
244          %82 = OpAccessChain %81 %80 %13 %48
245          %83 = OpLoad %6 %82
246          %84 = OpAccessChain %81 %80 %13 %8
247          %85 = OpLoad %6 %84
248          %86 = OpFOrdGreaterThan %26 %83 %85
249                OpSelectionMerge %88 None
250                OpBranchConditional %86 %87 %88
251          %87 = OpLabel
252                OpReturn
253          %88 = OpLabel
254                OpBranch %73
255          %73 = OpLabel
256          %90 = OpLoad %12 %69
257          %91 = OpIAdd %12 %90 %39
258                OpStore %69 %91
259                OpBranch %70
260          %72 = OpLabel
261                OpBranch %65
262          %65 = OpLabel
263          %92 = OpLoad %12 %61
264          %93 = OpIAdd %12 %92 %39
265                OpStore %61 %93
266                OpBranch %62
267          %64 = OpLabel
268                OpStore %94 %13
269                OpBranch %95
270          %95 = OpLabel
271                OpLoopMerge %97 %98 None
272                OpBranch %99
273          %99 = OpLabel
274         %100 = OpLoad %12 %94
275         %101 = OpSLessThan %26 %100 %39
276                OpBranchConditional %101 %96 %97
277          %96 = OpLabel
278         %102 = OpAccessChain %81 %80 %13 %48
279         %103 = OpLoad %6 %102
280         %104 = OpAccessChain %81 %80 %13 %8
281         %105 = OpLoad %6 %104
282         %106 = OpFOrdGreaterThan %26 %103 %105
283                OpSelectionMerge %108 None
284                OpBranchConditional %106 %107 %108
285         %107 = OpLabel
286                OpControlBarrier %109 %109 %110
287                OpBranch %108
288         %108 = OpLabel
289                OpBranch %98
290          %98 = OpLabel
291         %111 = OpLoad %12 %94
292         %112 = OpIAdd %12 %111 %39
293                OpStore %94 %112
294                OpBranch %95
295          %97 = OpLabel
296                OpBranch %55
297         %113 = OpLabel
298         %114 = OpAccessChain %49 %47 %48
299         %115 = OpLoad %7 %114
300         %117 = OpULessThan %26 %115 %116
301                OpSelectionMerge %119 None
302                OpBranchConditional %117 %118 %134
303         %118 = OpLabel
304         %120 = OpAccessChain %15 %11 %13
305         %121 = OpLoad %6 %120
306         %125 = OpAccessChain %81 %124 %13 %48
307         %126 = OpLoad %6 %125
308         %127 = OpFDiv %6 %121 %126
309         %128 = OpAccessChain %15 %11 %13
310         %129 = OpLoad %6 %128
311         %130 = OpAccessChain %81 %124 %13 %8
312         %131 = OpLoad %6 %130
313         %132 = OpFDiv %6 %129 %131
314         %133 = OpCompositeConstruct %56 %127 %132 %14 %59
315                OpStore %58 %133
316                OpBranch %119
317         %134 = OpLabel
318         %135 = OpAccessChain %81 %80 %13 %48
319         %136 = OpLoad %6 %135
320         %137 = OpAccessChain %81 %80 %13 %8
321         %138 = OpLoad %6 %137
322         %139 = OpFOrdGreaterThan %26 %136 %138
323                OpSelectionMerge %141 None
324                OpBranchConditional %139 %140 %141
325         %140 = OpLabel
326                OpBranch %44
327         %141 = OpLabel
328                OpBranch %119
329         %119 = OpLabel
330                OpBranch %55
331          %55 = OpLabel
332                OpBranch %44
333          %44 = OpLabel
334                OpBranchConditional %143 %41 %43
335          %43 = OpLabel
336         %148 = OpAccessChain %15 %58 %48
337         %149 = OpLoad %6 %148
338         %150 = OpConvertFToS %12 %149
339         %152 = OpAccessChain %151 %147 %13 %13
340                OpStore %152 %150
341         %153 = OpAccessChain %15 %58 %8
342         %154 = OpLoad %6 %153
343         %155 = OpConvertFToS %12 %154
344         %156 = OpAccessChain %151 %147 %13 %39
345                OpStore %156 %155
346         %158 = OpAccessChain %15 %58 %109
347         %159 = OpLoad %6 %158
348         %160 = OpConvertFToS %12 %159
349         %161 = OpAccessChain %151 %147 %13 %157
350                OpStore %161 %160
351         %164 = OpAccessChain %15 %58 %163
352         %165 = OpLoad %6 %164
353         %166 = OpConvertFToS %12 %165
354         %167 = OpAccessChain %151 %147 %13 %162
355                OpStore %167 %166
356                OpReturn
357                OpFunctionEnd
358
359
360 [test]
361 ## Uniforms
362 # injectionSwitch
363 uniform ubo 0:1 vec2 0 0.0 1.0
364 # resolution
365 uniform ubo 0:2 vec2 0 256.0 256.0
366 ## SSBO
367 ssbo 0 subdata int 0 0 0 0 0
368
369 compute 3 1 1
370 probe ssbo int 0 0 == 0
371 probe ssbo int 0 4 == 0
372 probe ssbo int 0 8 == 0
373 probe ssbo int 0 12 == 1