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:
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_8 _GLF_uniform_int_values[0]
36 # #define _int_2 _GLF_uniform_int_values[1]
37 # #define _int_0 _GLF_uniform_int_values[2]
38 # #define _int_1 _GLF_uniform_int_values[3]
39 # #define _int_3 _GLF_uniform_int_values[4]
40 # #define _float_0_0 _GLF_uniform_float_values[0]
41 # #define _float_2_0 _GLF_uniform_float_values[1]
43 # precision highp float;
44 # precision highp int;
46 # // Contents of _GLF_uniform_int_values: [8, 2, 0, 1, 3]
47 # layout(set = 0, binding = 0) uniform buf0
49 # int _GLF_uniform_int_values[5];
52 # // Contents of _GLF_uniform_float_values: [0.0, 2.0]
53 # layout(set = 0, binding = 1) uniform buf1
55 # float _GLF_uniform_float_values[2];
58 # // Contents of injectionSwitch: [0.0, 1.0]
59 # layout(set = 0, binding = 2) uniform buf2
61 # highp vec2 injectionSwitch;
64 # layout(location = 0) out vec4 _GLF_color;
66 # // Returns true if v.y >= 2.0.
70 # while(injectionSwitch.x < _float_0_0)
75 # if(v.y < _float_2_0)
88 # // Iterates seven times.
89 # for(int i = _int_1; i < _int_8; i++)
91 # if(func0(vec4[8](vec4(_int_1), vec4(_int_1), vec4(_int_3), vec4(_int_1), vec4(_int_1), vec4(_int_1), vec4(_int_1), vec4(_int_1))[i]))
103 # if(func1() == _int_2)
105 # _GLF_color = vec4(_int_1, _int_0, _int_0, _int_1);
109 # _GLF_color = vec4(_int_0);
112 SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0
115 ; Generator: Khronos Glslang Reference Front End; 10
119 %1 = OpExtInstImport "GLSL.std.450"
120 OpMemoryModel Logical GLSL450
121 OpEntryPoint Fragment %4 "main" %139
122 OpExecutionMode %4 OriginUpperLeft
126 OpMemberName %24 0 "injectionSwitch"
129 OpMemberName %35 0 "_GLF_uniform_float_values"
132 OpMemberName %61 0 "_GLF_uniform_int_values"
134 OpName %139 "_GLF_color"
135 OpMemberDecorate %24 0 Offset 0
137 OpDecorate %26 DescriptorSet 0
138 OpDecorate %26 Binding 2
139 OpDecorate %34 ArrayStride 16
140 OpMemberDecorate %35 0 Offset 0
142 OpDecorate %37 DescriptorSet 0
143 OpDecorate %37 Binding 1
144 OpDecorate %60 ArrayStride 16
145 OpMemberDecorate %61 0 Offset 0
147 OpDecorate %63 DescriptorSet 0
148 OpDecorate %63 Binding 0
149 OpDecorate %139 Location 0
151 %3 = OpTypeFunction %2
153 %7 = OpTypeVector %6 4
154 %8 = OpTypePointer Function %7
157 %23 = OpTypeVector %6 2
158 %24 = OpTypeStruct %23
159 %25 = OpTypePointer Uniform %24
160 %26 = OpVariable %25 Uniform
161 %27 = OpConstant %14 0
163 %29 = OpConstant %28 0
164 %30 = OpTypePointer Uniform %6
165 %33 = OpConstant %28 2
166 %34 = OpTypeArray %6 %33
167 %35 = OpTypeStruct %34
168 %36 = OpTypePointer Uniform %35
169 %37 = OpVariable %36 Uniform
170 %41 = OpConstantFalse %9
171 %47 = OpConstant %14 1
172 %54 = OpConstantTrue %9
173 %59 = OpConstant %28 5
174 %60 = OpTypeArray %14 %59
175 %61 = OpTypeStruct %60
176 %62 = OpTypePointer Uniform %61
177 %63 = OpVariable %62 Uniform
178 %64 = OpConstant %14 2
179 %65 = OpTypePointer Uniform %14
180 %69 = OpConstant %14 3
181 %89 = OpConstant %14 4
182 %114 = OpConstant %28 8
183 %115 = OpTypeArray %7 %114
184 %119 = OpTypePointer Function %115
185 %138 = OpTypePointer Output %7
186 %139 = OpVariable %138 Output
188 %4 = OpFunction %2 None %3
190 %169 = OpVariable %119 Function
191 %172 = OpAccessChain %65 %63 %27 %64
192 %173 = OpLoad %14 %172
193 %174 = OpAccessChain %65 %63 %27 %69
194 %175 = OpLoad %14 %174
197 %262 = OpPhi %9 %263 %5 %259 %223
198 %256 = OpPhi %14 %173 %5 %274 %223
199 %255 = OpPhi %14 %175 %5 %225 %223
200 %179 = OpAccessChain %65 %63 %27 %27
201 %180 = OpLoad %14 %179
202 %181 = OpSLessThan %9 %255 %180
203 OpLoopMerge %226 %223 None
204 OpBranchConditional %181 %182 %226
206 %185 = OpConvertSToF %6 %175
207 %186 = OpCompositeConstruct %7 %185 %185 %185 %185
208 %191 = OpAccessChain %65 %63 %27 %89
209 %192 = OpLoad %14 %191
210 %193 = OpConvertSToF %6 %192
211 %194 = OpCompositeConstruct %7 %193 %193 %193 %193
212 %215 = OpCompositeConstruct %115 %186 %186 %194 %186 %186 %186 %186 %186
214 %217 = OpAccessChain %8 %169 %255
215 %218 = OpLoad %7 %217
216 OpSelectionMerge %252 None
221 %235 = OpAccessChain %30 %26 %27 %29
222 %236 = OpLoad %6 %235
223 %237 = OpAccessChain %30 %37 %27 %27
224 %238 = OpLoad %6 %237
225 %239 = OpFOrdLessThan %9 %236 %238
226 OpLoopMerge %242 %241 None
227 OpBranchConditional %239 %240 %242
233 %260 = OpPhi %9 %262 %233 %41 %240
234 %257 = OpPhi %9 %41 %233 %54 %240
235 OpSelectionMerge %244 None
236 OpBranchConditional %257 %252 %244
238 %246 = OpCompositeExtract %6 %218 1
239 %247 = OpAccessChain %30 %37 %27 %47
240 %248 = OpLoad %6 %247
241 %249 = OpFOrdLessThan %9 %246 %248
242 OpSelectionMerge %251 None
243 OpBranchConditional %249 %250 %251
249 %259 = OpPhi %9 %260 %242 %41 %250 %54 %251
250 %274 = OpSelect %14 %259 %255 %256
253 %225 = OpIAdd %14 %255 %47
256 %133 = OpAccessChain %65 %63 %27 %47
257 %134 = OpLoad %14 %133
258 %135 = OpIEqual %9 %256 %134
259 OpSelectionMerge %137 None
260 OpBranchConditional %135 %136 %153
262 %156 = OpConvertSToF %6 %173
263 %157 = OpCompositeConstruct %7 %156 %156 %156 %156
267 %142 = OpConvertSToF %6 %175
268 %145 = OpConvertSToF %6 %173
269 %152 = OpCompositeConstruct %7 %142 %145 %145 %142
277 # uniforms for variant
280 BUFFER variant_injectionSwitch DATA_TYPE vec2<float> STD140 DATA
283 # _GLF_uniform_float_values
284 BUFFER variant__GLF_uniform_float_values DATA_TYPE float[] STD140 DATA
287 # _GLF_uniform_int_values
288 BUFFER variant__GLF_uniform_int_values DATA_TYPE int32[] STD140 DATA
292 BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM
294 PIPELINE graphics variant_pipeline
295 ATTACH variant_vertex_shader
296 ATTACH variant_fragment_shader
297 FRAMEBUFFER_SIZE 32 32
298 BIND BUFFER variant_framebuffer AS color LOCATION 0
299 BIND BUFFER variant_injectionSwitch AS uniform DESCRIPTOR_SET 0 BINDING 2
300 BIND BUFFER variant__GLF_uniform_float_values AS uniform DESCRIPTOR_SET 0 BINDING 1
301 BIND BUFFER variant__GLF_uniform_int_values AS uniform DESCRIPTOR_SET 0 BINDING 0
303 CLEAR_COLOR variant_pipeline 0 0 0 255
305 CLEAR variant_pipeline
306 RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 32 32
308 EXPECT variant_framebuffer IDX 0 0 SIZE 32 32 EQ_RGBA 255 0 0 255