3 # Copyright 2022 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:
25 # '--eliminate-dead-branches'
27 # '--eliminate-local-single-store'
28 # '--eliminate-local-single-store'
29 # '--eliminate-local-single-store'
30 # '--eliminate-local-multi-store'
31 # '--scalar-replacement=100'
32 # '--redundancy-elimination'
33 # '--eliminate-local-single-store'
34 # '--eliminate-dead-inserts'
35 # '--simplify-instructions'
36 # '--eliminate-local-multi-store'
37 # '--redundancy-elimination'
39 # '--eliminate-local-single-block'
40 # '--eliminate-dead-code-aggressive'
41 # '--eliminate-dead-branches'
43 # '--eliminate-dead-branches'
45 # '--scalar-replacement=100'
46 # '--simplify-instructions'
47 # '--eliminate-dead-branches'
49 # '--eliminate-dead-inserts'
50 # '--simplify-instructions'
51 # '--eliminate-dead-branches'
55 # spirv-opt commit hash: a0370efd589be33d5d9a85cfde2f85841b3755af
59 SHADER vertex variant_vertex_shader PASSTHROUGH
61 # variant_fragment_shader is derived from the following GLSL:
63 # #define _int_0 _GLF_uniform_int_values[0]
64 # #define _int_1 _GLF_uniform_int_values[1]
65 # #define _int_2 _GLF_uniform_int_values[2]
66 # #define _float_0_0 _GLF_uniform_float_values[0]
68 # precision highp float;
69 # precision highp int;
71 # // Contents of _GLF_uniform_float_values: 0.0
72 # layout(set = 0, binding = 0) uniform buf0
74 # float _GLF_uniform_float_values[1];
77 # // Contents of _GLF_uniform_int_values: [0, 1, 2]
78 # layout(set = 0, binding = 1) uniform buf1
80 # int _GLF_uniform_int_values[3];
83 # const int _GLF_global_loop_bound = 10;
84 # int _GLF_global_loop_count = 0;
86 # layout(location = 0) out vec4 _GLF_color;
93 # while(_GLF_global_loop_count < _GLF_global_loop_bound)
95 # _GLF_global_loop_count++;
97 # // Iterates nine times.
98 # while(_GLF_global_loop_count < _GLF_global_loop_bound)
100 # _GLF_global_loop_count++;
103 # if(gl_FragCoord.y < _float_0_0)
111 # // Never iterated because the global loop bound has been reached.
112 # for(int i = 4; i >= 0 && _GLF_global_loop_count < _GLF_global_loop_bound; i--)
114 # _GLF_global_loop_count++;
122 # _GLF_color = vec4(_int_1, _int_0, _int_0, _int_1);
126 # _GLF_color = vec4(_int_0);
129 SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0
132 ; Generator: Khronos Glslang Reference Front End; 10
136 %1 = OpExtInstImport "GLSL.std.450"
137 OpMemoryModel Logical GLSL450
138 OpEntryPoint Fragment %4 "main" %45 %89
139 OpExecutionMode %4 OriginUpperLeft
142 OpName %8 "_GLF_global_loop_count"
144 OpMemberName %15 0 "_GLF_uniform_int_values"
146 OpName %45 "gl_FragCoord"
148 OpMemberName %51 0 "_GLF_uniform_float_values"
150 OpName %89 "_GLF_color"
151 OpDecorate %14 ArrayStride 16
152 OpMemberDecorate %15 0 Offset 0
154 OpDecorate %17 DescriptorSet 0
155 OpDecorate %17 Binding 1
156 OpDecorate %45 BuiltIn FragCoord
157 OpDecorate %50 ArrayStride 16
158 OpMemberDecorate %51 0 Offset 0
160 OpDecorate %53 DescriptorSet 0
161 OpDecorate %53 Binding 0
162 OpDecorate %89 Location 0
164 %3 = OpTypeFunction %2
166 %7 = OpTypePointer Private %6
167 %8 = OpVariable %7 Private
170 %13 = OpConstant %12 3
171 %14 = OpTypeArray %6 %13
172 %15 = OpTypeStruct %14
173 %16 = OpTypePointer Uniform %15
174 %17 = OpVariable %16 Uniform
175 %18 = OpTypePointer Uniform %6
176 %27 = OpConstant %6 10
178 %31 = OpConstant %6 1
180 %43 = OpTypeVector %42 4
181 %44 = OpTypePointer Input %43
182 %45 = OpVariable %44 Input
183 %46 = OpConstant %12 1
184 %47 = OpTypePointer Input %42
185 %50 = OpTypeArray %42 %46
186 %51 = OpTypeStruct %50
187 %52 = OpTypePointer Uniform %51
188 %53 = OpVariable %52 Uniform
189 %54 = OpTypePointer Uniform %42
190 %64 = OpConstant %6 4
191 %77 = OpConstant %6 2
192 %88 = OpTypePointer Output %43
193 %89 = OpVariable %88 Output
194 %114 = OpConstant %12 0
195 %115 = OpConstantFalse %28
196 %116 = OpTypePointer Function %28
197 %118 = OpConstantTrue %28
198 %4 = OpFunction %2 None %3
200 %117 = OpVariable %116 Function %115
201 OpSelectionMerge %112 None
205 %19 = OpAccessChain %18 %17 %9 %9
209 %108 = OpPhi %6 %20 %113 %110 %24
211 %29 = OpSLessThan %28 %26 %27
212 OpLoopMerge %23 %24 None
213 OpBranchConditional %29 %22 %23
216 %32 = OpIAdd %6 %30 %31
220 %111 = OpPhi %6 %108 %22 %62 %36
222 %39 = OpSLessThan %28 %38 %27
223 OpLoopMerge %35 %36 None
224 OpBranchConditional %39 %34 %35
227 %41 = OpIAdd %6 %40 %31
229 %48 = OpAccessChain %47 %45 %46
231 %55 = OpAccessChain %54 %53 %9 %9
233 %57 = OpFOrdLessThan %28 %49 %56
234 OpSelectionMerge %59 None
235 OpBranchConditional %57 %58 %59
240 %61 = OpAccessChain %18 %17 %9 %31
246 %120 = OpLoad %28 %117
247 OpSelectionMerge %119 None
248 OpBranchConditional %120 %23 %119
252 %109 = OpPhi %6 %64 %119 %81 %66
253 %110 = OpPhi %6 %111 %119 %79 %66
254 %71 = OpSGreaterThanEqual %28 %109 %9
256 %73 = OpSLessThan %28 %72 %27
257 %74 = OpLogicalAnd %28 %71 %73
258 OpLoopMerge %67 %66 None
259 OpBranchConditional %74 %66 %67
262 %76 = OpIAdd %6 %75 %31
264 %78 = OpAccessChain %18 %17 %9 %77
266 %81 = OpISub %6 %109 %31
273 %122 = OpLoad %28 %117
274 OpSelectionMerge %121 None
275 OpBranchConditional %122 %112 %121
277 %83 = OpAccessChain %18 %17 %9 %31
279 %85 = OpIEqual %28 %108 %84
280 OpSelectionMerge %87 None
281 OpBranchConditional %85 %86 %103
283 %92 = OpConvertSToF %42 %84
284 %95 = OpConvertSToF %42 %20
285 %102 = OpCompositeConstruct %43 %92 %95 %95 %92
289 %106 = OpConvertSToF %42 %20
290 %107 = OpCompositeConstruct %43 %106 %106 %106 %106
301 # uniforms for variant
303 # _GLF_uniform_int_values
304 BUFFER variant__GLF_uniform_int_values DATA_TYPE int32[] STD140 DATA
307 # _GLF_uniform_float_values
308 BUFFER variant__GLF_uniform_float_values DATA_TYPE float[] STD140 DATA
312 BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM
314 PIPELINE graphics variant_pipeline
315 ATTACH variant_vertex_shader
316 ATTACH variant_fragment_shader
317 FRAMEBUFFER_SIZE 32 32
318 BIND BUFFER variant_framebuffer AS color LOCATION 0
319 BIND BUFFER variant__GLF_uniform_int_values AS uniform DESCRIPTOR_SET 0 BINDING 1
320 BIND BUFFER variant__GLF_uniform_float_values AS uniform DESCRIPTOR_SET 0 BINDING 0
322 CLEAR_COLOR variant_pipeline 0 0 0 255
324 CLEAR variant_pipeline
325 RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 32 32
327 EXPECT variant_framebuffer IDX 0 0 SIZE 32 32 EQ_RGBA 255 0 0 255