1 # Copyright 2019 Google LLC
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
7 # http://www.apache.org/licenses/LICENSE-2.0
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.
15 # A test for a bug found by GraphicsFuzz.
17 # Short description: A compute shader with an unreachable barrier in a loop nest
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.
24 # Derived from the following GLSL.
26 # Compute shader GLSL:
29 # precision highp float;
31 # layout(set = 0, binding = 2) uniform buf2 {
35 # layout(set = 0, binding = 1) uniform buf1 {
36 # vec2 injectionSwitch;
39 # layout(std430, binding = 0) buffer doesNotMatter {
40 # int _compute_data[];
43 # layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
50 # for(int i = 0; i < 50; i++) {
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)
64 # for(int n = 0; n < 1; n ++) {
65 # if(injectionSwitch.x > injectionSwitch.y)
69 # if(gl_GlobalInvocationID.x < 120u) {
70 # value = vec4(A[0] / resolution.x, A[0] / resolution.y, 0.0, 1.0);
72 # if(injectionSwitch.x > injectionSwitch.y)
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);
83 [compute shader spirv]
86 ; Generator: Khronos Glslang Reference Front End; 7
90 %1 = OpExtInstImport "GLSL.std.450"
91 OpMemoryModel Logical GLSL450
92 OpEntryPoint GLCompute %4 "main" %47
93 OpExecutionMode %4 LocalSize 1 1 1
98 OpName %47 "gl_GlobalInvocationID"
103 OpMemberName %78 0 "injectionSwitch"
107 OpMemberName %122 0 "resolution"
109 OpName %145 "doesNotMatter"
110 OpMemberName %145 0 "_compute_data"
112 OpDecorate %47 BuiltIn GlobalInvocationId
113 OpMemberDecorate %78 0 Offset 0
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
127 %3 = OpTypeFunction %2
131 %9 = OpTypeArray %6 %8
132 %10 = OpTypePointer Function %9
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
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
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
184 OpLoopMerge %21 %22 None
188 %27 = OpSLessThan %26 %24 %25
189 OpBranchConditional %27 %20 %21
192 %29 = OpSGreaterThan %26 %28 %13
193 OpSelectionMerge %31 None
194 OpBranchConditional %29 %30 %31
196 %32 = OpAccessChain %15 %11 %13
198 %34 = OpAccessChain %15 %11 %13
200 %36 = OpFAdd %6 %35 %33
201 %37 = OpAccessChain %15 %11 %13
208 %40 = OpIAdd %12 %38 %39
214 OpLoopMerge %43 %44 None
217 %50 = OpAccessChain %49 %47 %48
219 %53 = OpULessThan %26 %51 %52
220 OpSelectionMerge %55 None
221 OpBranchConditional %53 %54 %113
227 OpLoopMerge %64 %65 None
231 %68 = OpSLessThan %26 %67 %39
232 OpBranchConditional %68 %63 %64
237 OpLoopMerge %72 %73 None
241 %76 = OpSLessThan %26 %75 %39
242 OpBranchConditional %76 %71 %72
244 %82 = OpAccessChain %81 %80 %13 %48
246 %84 = OpAccessChain %81 %80 %13 %8
248 %86 = OpFOrdGreaterThan %26 %83 %85
249 OpSelectionMerge %88 None
250 OpBranchConditional %86 %87 %88
257 %91 = OpIAdd %12 %90 %39
264 %93 = OpIAdd %12 %92 %39
271 OpLoopMerge %97 %98 None
274 %100 = OpLoad %12 %94
275 %101 = OpSLessThan %26 %100 %39
276 OpBranchConditional %101 %96 %97
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
286 OpControlBarrier %109 %109 %110
291 %111 = OpLoad %12 %94
292 %112 = OpIAdd %12 %111 %39
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
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
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
334 OpBranchConditional %143 %41 %43
336 %148 = OpAccessChain %15 %58 %48
337 %149 = OpLoad %6 %148
338 %150 = OpConvertFToS %12 %149
339 %152 = OpAccessChain %151 %147 %13 %13
341 %153 = OpAccessChain %15 %58 %8
342 %154 = OpLoad %6 %153
343 %155 = OpConvertFToS %12 %154
344 %156 = OpAccessChain %151 %147 %13 %39
346 %158 = OpAccessChain %15 %58 %109
347 %159 = OpLoad %6 %158
348 %160 = OpConvertFToS %12 %159
349 %161 = OpAccessChain %151 %147 %13 %157
351 %164 = OpAccessChain %15 %58 %163
352 %165 = OpLoad %6 %164
353 %166 = OpConvertFToS %12 %165
354 %167 = OpAccessChain %151 %147 %13 %162
363 uniform ubo 0:1 vec2 0 0.0 1.0
365 uniform ubo 0:2 vec2 0 256.0 256.0
367 ssbo 0 subdata int 0 0 0 0 0
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