3 # Copyright 2021 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 coverage-gap found by the GraphicsFuzz project.
20 # Short description: A fragment shader that covers specific LLVM code paths
22 # The test passes because the shader always writes red.
24 # Optimized using spirv-opt with the following arguments:
26 # spirv-opt commit hash: a0370efd589be33d5d9a85cfde2f85841b3755af
30 SHADER vertex variant_vertex_shader PASSTHROUGH
32 # variant_fragment_shader is derived from the following GLSL:
35 # #define _int_5 _GLF_uniform_int_values[0]
36 # #define _int_0 _GLF_uniform_int_values[1]
37 # #define _int_11 _GLF_uniform_int_values[2]
38 # #define _int_1 _GLF_uniform_int_values[3]
39 # #define _float_0_0 _GLF_uniform_float_values[0]
41 # precision highp float;
42 # precision highp int;
44 # // Contents of _GLF_uniform_float_values: 0.0
45 # layout(set = 0, binding = 0) uniform buf0
47 # float _GLF_uniform_float_values[1];
50 # // Contents of _GLF_uniform_int_values: [5, 0, 11, 1]
51 # layout(set = 0, binding = 1) uniform buf1
53 # int _GLF_uniform_int_values[4];
56 # // Contents of injectionSwitch: [0.0, 1.0]
57 # layout(push_constant) uniform buf_push
59 # highp vec2 injectionSwitch;
62 # layout(location = 0) out vec4 _GLF_color;
69 # S arr[10] = S[10](S(1), S(2), S(3), S(4), S(5), S(6), S(7), S(8), S(9), S(10));
71 # void func0(inout S s)
79 # // Each iteration increases a by one.
80 # for(int i = _int_0; i < _int_5; i++)
82 # // s.data is always a + 1.
86 # if(gl_FragCoord.x < _float_0_0)
92 # if(injectionSwitch.x > injectionSwitch.y)
98 # if(s.data == _int_11)
104 # if(injectionSwitch.x > injectionSwitch.y)
110 # if(gl_FragCoord.x < _float_0_0)
123 # // An empty function does nothing.
124 # func0(arr[_int_1]);
127 # if(func1() == _int_5)
129 # _GLF_color = vec4(_int_1, _int_0, _int_0, _int_1);
133 # _GLF_color = vec4(_int_0);
136 SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0
139 ; Generator: Khronos Glslang Reference Front End; 10
143 %1 = OpExtInstImport "GLSL.std.450"
144 OpMemoryModel Logical GLSL450
145 OpEntryPoint Fragment %4 "main" %74 %151
146 OpExecutionMode %4 OriginUpperLeft
150 OpMemberName %7 0 "data"
153 OpMemberName %46 0 "_GLF_uniform_int_values"
155 OpName %74 "gl_FragCoord"
157 OpMemberName %81 0 "_GLF_uniform_float_values"
159 OpName %92 "buf_push"
160 OpMemberName %92 0 "injectionSwitch"
162 OpName %151 "_GLF_color"
163 OpDecorate %45 ArrayStride 16
164 OpMemberDecorate %46 0 Offset 0
166 OpDecorate %48 DescriptorSet 0
167 OpDecorate %48 Binding 1
168 OpDecorate %74 BuiltIn FragCoord
169 OpDecorate %80 ArrayStride 16
170 OpMemberDecorate %81 0 Offset 0
172 OpDecorate %83 DescriptorSet 0
173 OpDecorate %83 Binding 0
174 OpMemberDecorate %92 0 Offset 0
176 OpDecorate %151 Location 0
178 %3 = OpTypeFunction %2
181 %8 = OpTypePointer Function %7
183 %17 = OpConstant %16 10
184 %18 = OpTypeArray %7 %17
185 %21 = OpConstant %6 1
186 %22 = OpConstantComposite %7 %21
187 %23 = OpConstant %6 2
188 %24 = OpConstantComposite %7 %23
189 %25 = OpConstant %6 3
190 %26 = OpConstantComposite %7 %25
191 %27 = OpConstant %6 4
192 %28 = OpConstantComposite %7 %27
193 %29 = OpConstant %6 5
194 %30 = OpConstantComposite %7 %29
195 %31 = OpConstant %6 6
196 %32 = OpConstantComposite %7 %31
197 %33 = OpConstant %6 7
198 %34 = OpConstantComposite %7 %33
199 %35 = OpConstant %6 8
200 %36 = OpConstantComposite %7 %35
201 %37 = OpConstant %6 9
202 %38 = OpConstantComposite %7 %37
203 %39 = OpConstant %6 10
204 %40 = OpConstantComposite %7 %39
205 %41 = OpConstantComposite %18 %22 %24 %26 %28 %30 %32 %34 %36 %38 %40
206 %44 = OpConstant %16 4
207 %45 = OpTypeArray %6 %44
208 %46 = OpTypeStruct %45
209 %47 = OpTypePointer Uniform %46
210 %48 = OpVariable %47 Uniform
211 %49 = OpConstant %6 0
212 %50 = OpTypePointer Uniform %6
215 %72 = OpTypeVector %71 4
216 %73 = OpTypePointer Input %72
217 %74 = OpVariable %73 Input
218 %75 = OpConstant %16 0
219 %76 = OpTypePointer Input %71
220 %79 = OpConstant %16 1
221 %80 = OpTypeArray %71 %79
222 %81 = OpTypeStruct %80
223 %82 = OpTypePointer Uniform %81
224 %83 = OpVariable %82 Uniform
225 %84 = OpTypePointer Uniform %71
226 %91 = OpTypeVector %71 2
227 %92 = OpTypeStruct %91
228 %93 = OpTypePointer PushConstant %92
229 %94 = OpVariable %93 PushConstant
230 %95 = OpTypePointer PushConstant %71
231 %111 = OpConstant %6 -1
232 %150 = OpTypePointer Output %72
233 %151 = OpVariable %150 Output
234 %174 = OpConstantFalse %64
235 %177 = OpConstantTrue %64
236 %249 = OpTypePointer Function %18
238 %4 = OpFunction %2 None %3
240 %20 = OpVariable %249 Function
242 %136 = OpAccessChain %50 %48 %49 %25
243 %137 = OpLoad %6 %136
244 %139 = OpAccessChain %8 %20 %137
245 %140 = OpLoad %7 %139
247 OpSelectionMerge %247 None
250 %189 = OpAccessChain %50 %48 %49 %21
251 %190 = OpLoad %6 %189
254 %253 = OpPhi %6 %190 %188 %262 %240
255 %252 = OpPhi %6 %190 %188 %242 %240
256 %196 = OpAccessChain %50 %48 %49 %49
257 %197 = OpLoad %6 %196
258 %198 = OpSLessThan %64 %252 %197
259 OpLoopMerge %243 %240 None
260 OpBranchConditional %198 %199 %243
262 %201 = OpAccessChain %8 %20 %253
263 %202 = OpLoad %7 %201
264 %251 = OpCompositeExtract %6 %202 0
265 %203 = OpAccessChain %76 %74 %75
266 %204 = OpLoad %71 %203
267 %205 = OpAccessChain %84 %83 %49 %49
268 %206 = OpLoad %71 %205
269 %207 = OpFOrdLessThan %64 %204 %206
270 OpSelectionMerge %209 None
271 OpBranchConditional %207 %208 %209
275 %210 = OpAccessChain %95 %94 %49 %75
276 %211 = OpLoad %71 %210
277 %212 = OpAccessChain %95 %94 %49 %79
278 %213 = OpLoad %71 %212
279 %214 = OpFOrdGreaterThan %64 %211 %213
280 OpSelectionMerge %216 None
281 OpBranchConditional %214 %215 %216
285 %219 = OpAccessChain %50 %48 %49 %23
286 %220 = OpLoad %6 %219
287 %221 = OpIEqual %64 %251 %220
288 OpSelectionMerge %223 None
289 OpBranchConditional %221 %222 %223
293 OpSelectionMerge %230 None
294 OpBranchConditional %214 %229 %230
298 OpSelectionMerge %237 None
299 OpBranchConditional %207 %236 %237
305 %262 = OpPhi %6 %253 %208 %253 %215 %251 %237
306 %242 = OpIAdd %6 %252 %21
309 %258 = OpPhi %6 %260 %193 %111 %222 %260 %229 %111 %236
310 %254 = OpPhi %64 %174 %193 %177 %222 %174 %229 %177 %236
311 OpSelectionMerge %245 None
312 OpBranchConditional %254 %247 %245
316 %257 = OpPhi %6 %258 %243 %253 %245
317 %147 = OpIEqual %64 %257 %197
318 OpSelectionMerge %149 None
319 OpBranchConditional %147 %148 %165
321 %154 = OpConvertSToF %71 %137
322 %157 = OpConvertSToF %71 %190
323 %164 = OpCompositeConstruct %72 %154 %157 %157 %154
327 %168 = OpConvertSToF %71 %190
328 %169 = OpCompositeConstruct %72 %168 %168 %168 %168
336 # uniforms for variant
339 BUFFER variant_injectionSwitch DATA_TYPE vec2<float> STD140 DATA
342 # _GLF_uniform_int_values
343 BUFFER variant__GLF_uniform_int_values DATA_TYPE int32[] STD140 DATA
346 # _GLF_uniform_float_values
347 BUFFER variant__GLF_uniform_float_values DATA_TYPE float[] STD140 DATA
351 BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM
353 PIPELINE graphics variant_pipeline
354 ATTACH variant_vertex_shader
355 ATTACH variant_fragment_shader
356 FRAMEBUFFER_SIZE 256 256
357 BIND BUFFER variant_framebuffer AS color LOCATION 0
358 BIND BUFFER variant_injectionSwitch AS push_constant
359 BIND BUFFER variant__GLF_uniform_int_values AS uniform DESCRIPTOR_SET 0 BINDING 1
360 BIND BUFFER variant__GLF_uniform_float_values AS uniform DESCRIPTOR_SET 0 BINDING 0
362 CLEAR_COLOR variant_pipeline 0 0 0 255
364 CLEAR variant_pipeline
365 RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 256 256
367 EXPECT variant_framebuffer IDX 0 0 SIZE 256 256 EQ_RGBA 255 0 0 255