3 # Copyright 2019 Google LLC
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
18 # A test for a bug found by GraphicsFuzz.
20 # Short description: A compute shader with two barrier functions
22 # The test passes because main always outputs 42.
24 # variant_compute_shader is derived from the following GLSL:
26 # precision highp float;
28 # layout(std430, binding = 0) buffer doesNotMatter
30 # uint _compute_data[];
32 # layout(local_size_x = 1, local_size_y = 18, local_size_z = 6) in;
33 # mediump vec4 GLF_live2gl_FragCoord;
34 # layout(set = 0, binding = 1) uniform buf0 {
35 # vec2 injectionSwitch;
40 # int GLF_live2_looplimiter1 = 0;
46 # if (GLF_live2_looplimiter1 >= 3) //always false
53 # if (int(GLF_live2gl_FragCoord.x) < 120)
64 # float GLF_dead3x = (injectionSwitch.x > injectionSwitch.y ? GLF_live2gl_FragCoord.x : 0.0); // always 0.0
70 # if (GLF_dead3x > 4.0) //always false
74 # GLF_dead3x = GLF_live2gl_FragCoord.x;
78 # _compute_data[0] = 42u;
80 SHADER compute variant_compute_shader SPIRV-ASM TARGET_ENV spv1.0
83 ; Generator: Khronos Glslang Reference Front End; 7
87 %1 = OpExtInstImport "GLSL.std.450"
88 OpMemoryModel Logical GLSL450
89 OpEntryPoint GLCompute %4 "main"
90 OpExecutionMode %4 LocalSize 1 18 6
93 OpName %8 "GLF_live2_looplimiter1"
96 OpName %36 "GLF_live2gl_FragCoord"
97 OpName %56 "GLF_dead3x"
99 OpMemberName %58 0 "injectionSwitch"
101 OpName %76 "GLF_dead3k"
102 OpName %96 "doesNotMatter"
103 OpMemberName %96 0 "_compute_data"
105 OpDecorate %36 RelaxedPrecision
106 OpDecorate %41 RelaxedPrecision
107 OpMemberDecorate %58 0 Offset 0
109 OpDecorate %60 DescriptorSet 0
110 OpDecorate %60 Binding 1
111 OpDecorate %72 RelaxedPrecision
112 OpDecorate %75 RelaxedPrecision
113 OpDecorate %92 RelaxedPrecision
114 OpDecorate %95 ArrayStride 4
115 OpMemberDecorate %96 0 Offset 0
116 OpDecorate %96 BufferBlock
117 OpDecorate %98 DescriptorSet 0
118 OpDecorate %98 Binding 0
119 OpDecorate %105 BuiltIn WorkgroupSize
121 %3 = OpTypeFunction %2
123 %7 = OpTypePointer Function %6
125 %17 = OpConstant %6 1
127 %21 = OpConstant %6 3
129 %34 = OpTypeVector %33 4
130 %35 = OpTypePointer Private %34
131 %36 = OpVariable %35 Private
133 %38 = OpConstant %37 0
134 %39 = OpTypePointer Private %33
135 %43 = OpConstant %6 120
136 %48 = OpConstant %37 2
137 %49 = OpConstant %37 264
138 %55 = OpTypePointer Function %33
139 %57 = OpTypeVector %33 2
140 %58 = OpTypeStruct %57
141 %59 = OpTypePointer Uniform %58
142 %60 = OpVariable %59 Uniform
143 %61 = OpTypePointer Uniform %33
144 %64 = OpConstant %37 1
145 %74 = OpConstant %33 0
146 %83 = OpConstant %6 2
147 %86 = OpConstant %33 4
148 %95 = OpTypeRuntimeArray %37
149 %96 = OpTypeStruct %95
150 %97 = OpTypePointer Uniform %96
151 %98 = OpVariable %97 Uniform
152 %99 = OpConstant %37 42
153 %100 = OpTypePointer Uniform %37
154 %102 = OpTypeVector %37 3
155 %103 = OpConstant %37 18
156 %104 = OpConstant %37 6
157 %105 = OpConstantComposite %102 %64 %103 %104
158 %4 = OpFunction %2 None %3
160 %8 = OpVariable %7 Function
161 %10 = OpVariable %7 Function
162 %25 = OpVariable %7 Function
163 %56 = OpVariable %55 Function
164 %68 = OpVariable %55 Function
165 %76 = OpVariable %7 Function
170 OpLoopMerge %13 %14 None
174 %19 = OpSLessThan %18 %16 %17
175 OpBranchConditional %19 %12 %13
178 %22 = OpSGreaterThanEqual %18 %20 %21
179 OpSelectionMerge %24 None
180 OpBranchConditional %22 %23 %24
185 OpLoopMerge %28 %29 None
189 %32 = OpSLessThan %18 %31 %17
190 OpBranchConditional %32 %27 %28
192 %40 = OpAccessChain %39 %36 %38
194 %42 = OpConvertFToS %6 %41
195 %44 = OpSLessThan %18 %42 %43
196 OpSelectionMerge %46 None
197 OpBranchConditional %44 %45 %47
201 OpControlBarrier %48 %48 %49
207 %51 = OpIAdd %6 %50 %17
216 %54 = OpIAdd %6 %53 %17
220 %62 = OpAccessChain %61 %60 %9 %38
222 %65 = OpAccessChain %61 %60 %9 %64
224 %67 = OpFOrdGreaterThan %18 %63 %66
225 OpSelectionMerge %70 None
226 OpBranchConditional %67 %69 %73
228 %71 = OpAccessChain %39 %36 %38
241 OpLoopMerge %79 %80 None
245 %84 = OpSLessThan %18 %82 %83
246 OpBranchConditional %84 %78 %79
249 %87 = OpFOrdGreaterThan %18 %85 %86
250 OpSelectionMerge %89 None
251 OpBranchConditional %87 %88 %89
255 %91 = OpAccessChain %39 %36 %38
258 OpControlBarrier %48 %48 %49
262 %94 = OpIAdd %6 %93 %17
266 %101 = OpAccessChain %100 %98 %9 %9
272 # uniforms for variant
275 BUFFER variant_injectionSwitch DATA_TYPE vec2<float> DATA
279 BUFFER variant_ssbo DATA_TYPE uint32 DATA
283 PIPELINE compute variant_pipeline
284 ATTACH variant_compute_shader
285 BIND BUFFER variant_ssbo AS storage DESCRIPTOR_SET 0 BINDING 0
286 BIND BUFFER variant_injectionSwitch AS uniform DESCRIPTOR_SET 0 BINDING 1
289 RUN variant_pipeline 1 6 2
291 EXPECT variant_ssbo IDX 0 EQ 42