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 # '--scalar-replacement=100'
26 # '--copy-propagate-arrays'
27 # '--convert-local-access-chains'
28 # '--eliminate-dead-branches'
30 # '--eliminate-local-single-store'
31 # '--eliminate-local-single-store'
33 # '--eliminate-dead-code-aggressive'
34 # '--copy-propagate-arrays'
35 # '--eliminate-dead-branches'
36 # '--inline-entry-points-exhaustive'
37 # '--copy-propagate-arrays'
38 # '--eliminate-dead-branches'
39 # '--redundancy-elimination'
41 # '--reduce-load-size'
42 # '--eliminate-local-single-block'
43 # '--copy-propagate-arrays'
45 # spirv-opt commit hash: a0370efd589be33d5d9a85cfde2f85841b3755af
49 SHADER vertex variant_vertex_shader PASSTHROUGH
51 # variant_fragment_shader is derived from the following GLSL:
53 # #define _int_5 _GLF_uniform_int_values[0]
54 # #define _int_1 _GLF_uniform_int_values[1]
55 # #define _int_0 _GLF_uniform_int_values[2]
56 # #define _float_0_0 _GLF_uniform_float_values[0]
57 # #define _float_3_9 _GLF_uniform_float_values[1]
58 # #define _float_4_1 _GLF_uniform_float_values[2]
59 # #define _float_1_0 _GLF_uniform_float_values[3]
61 # precision highp float;
62 # precision highp int;
64 # // Contents of _GLF_uniform_float_values: [0.0, 3.9, 4.1, 1.0]
65 # layout(set = 0, binding = 0) uniform buf0
67 # float _GLF_uniform_float_values[4];
70 # // Contents of _GLF_uniform_int_values: [5, 1, 0]
71 # layout(set = 0, binding = 1) uniform buf1
73 # int _GLF_uniform_int_values[3];
76 # layout(location = 0) out vec4 _GLF_color;
80 # _GLF_color = vec4(_int_1);
81 # float f = _float_0_0;
83 # // Iterates four times increasing f by one per each iteration.
84 # for(int i = _int_1; i < _int_5; i++)
87 # for(int j = _int_0; j < _int_1; j++)
89 # for(int k = _int_0; k < i; k++)
91 # // Increases f by one when k = 0.
92 # f += mat2(_float_1_0)[j][clamp(k, _int_0, _int_1)];
94 # // Copy output color to a temporary vector and back.
95 # // This will be overwritten later.
97 # for(int l = _int_0; l < _int_1; l++)
104 # if(gl_FragCoord.y < _float_0_0)
109 # _GLF_color = vec4(_int_0);
115 # if(f > _float_3_9 && f < _float_4_1)
117 # _GLF_color = vec4(_int_1, _int_0, _int_0, _int_1);
121 # _GLF_color = vec4(_int_0);
124 SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0
127 ; Generator: Khronos Glslang Reference Front End; 10
131 %1 = OpExtInstImport "GLSL.std.450"
132 OpMemoryModel Logical GLSL450
133 OpEntryPoint Fragment %4 "main" %9 %114
134 OpExecutionMode %4 OriginUpperLeft
137 OpName %9 "_GLF_color"
139 OpMemberName %14 0 "_GLF_uniform_int_values"
143 OpMemberName %28 0 "_GLF_uniform_float_values"
148 OpName %90 "indexable"
151 OpName %114 "gl_FragCoord"
152 OpDecorate %9 Location 0
153 OpDecorate %13 ArrayStride 16
154 OpMemberDecorate %14 0 Offset 0
156 OpDecorate %16 DescriptorSet 0
157 OpDecorate %16 Binding 1
158 OpDecorate %27 ArrayStride 16
159 OpMemberDecorate %28 0 Offset 0
161 OpDecorate %30 DescriptorSet 0
162 OpDecorate %30 Binding 0
163 OpDecorate %114 BuiltIn FragCoord
165 %3 = OpTypeFunction %2
167 %7 = OpTypeVector %6 4
168 %8 = OpTypePointer Output %7
169 %9 = OpVariable %8 Output
172 %12 = OpConstant %11 3
173 %13 = OpTypeArray %10 %12
174 %14 = OpTypeStruct %13
175 %15 = OpTypePointer Uniform %14
176 %16 = OpVariable %15 Uniform
177 %17 = OpConstant %10 0
178 %18 = OpConstant %10 1
179 %19 = OpTypePointer Uniform %10
180 %24 = OpTypePointer Function %6
181 %26 = OpConstant %11 4
182 %27 = OpTypeArray %6 %26
183 %28 = OpTypeStruct %27
184 %29 = OpTypePointer Uniform %28
185 %30 = OpVariable %29 Uniform
186 %31 = OpTypePointer Uniform %6
187 %34 = OpTypePointer Function %10
189 %49 = OpConstant %10 2
190 %72 = OpConstant %10 3
191 %75 = OpTypeVector %6 2
192 %76 = OpTypeMatrix %75 2
193 %78 = OpConstant %6 0
194 %89 = OpTypePointer Function %76
195 %107 = OpTypePointer Function %7
196 %113 = OpTypePointer Input %7
197 %114 = OpVariable %113 Input
198 %115 = OpConstant %11 1
199 %116 = OpTypePointer Input %6
200 %168 = OpConstant %11 0
201 %169 = OpConstantFalse %46
202 %170 = OpTypePointer Function %46
203 %172 = OpConstantTrue %46
204 %4 = OpFunction %2 None %3
206 %171 = OpVariable %170 Function %169
207 %25 = OpVariable %24 Function
208 %35 = OpVariable %34 Function
209 %48 = OpVariable %34 Function
210 %61 = OpVariable %34 Function
211 %90 = OpVariable %89 Function
212 %95 = OpVariable %34 Function
213 %108 = OpVariable %107 Function
214 OpSelectionMerge %166 None
217 %20 = OpAccessChain %19 %16 %17 %18
219 %22 = OpConvertSToF %6 %21
220 %23 = OpCompositeConstruct %7 %22 %22 %22 %22
222 %32 = OpAccessChain %31 %30 %17 %17
228 OpLoopMerge %40 %41 None
232 %44 = OpAccessChain %19 %16 %17 %17
234 %47 = OpSLessThan %46 %43 %45
235 OpBranchConditional %47 %39 %40
237 %50 = OpAccessChain %19 %16 %17 %49
242 OpLoopMerge %54 %55 None
246 %60 = OpSLessThan %46 %57 %21
247 OpBranchConditional %60 %53 %54
252 OpLoopMerge %66 %67 None
257 %71 = OpSLessThan %46 %69 %70
258 OpBranchConditional %71 %65 %66
260 %73 = OpAccessChain %31 %30 %17 %72
262 %79 = OpCompositeConstruct %75 %74 %78
263 %80 = OpCompositeConstruct %75 %78 %74
264 %81 = OpCompositeConstruct %76 %79 %80
267 %88 = OpExtInst %10 %1 SClamp %83 %51 %21
269 %91 = OpAccessChain %24 %90 %82 %88
272 %94 = OpFAdd %6 %93 %92
277 OpLoopMerge %100 %101 None
280 %103 = OpLoad %10 %95
281 %106 = OpSLessThan %46 %103 %21
282 OpBranchConditional %106 %99 %100
288 %110 = OpLoad %10 %95
289 %111 = OpIAdd %10 %110 %18
293 %112 = OpLoad %7 %108
295 %117 = OpAccessChain %116 %114 %115
296 %118 = OpLoad %6 %117
297 %121 = OpFOrdLessThan %46 %118 %33
298 OpSelectionMerge %123 None
299 OpBranchConditional %121 %122 %123
304 %127 = OpConvertSToF %6 %51
305 %128 = OpCompositeConstruct %7 %127 %127 %127 %127
309 %129 = OpLoad %10 %61
310 %130 = OpIAdd %10 %129 %18
314 %174 = OpLoad %46 %171
315 OpSelectionMerge %173 None
316 OpBranchConditional %174 %54 %173
320 %131 = OpLoad %10 %48
321 %132 = OpIAdd %10 %131 %18
325 %176 = OpLoad %46 %171
326 OpSelectionMerge %175 None
327 OpBranchConditional %176 %40 %175
331 %133 = OpLoad %10 %35
332 %134 = OpIAdd %10 %133 %18
336 %178 = OpLoad %46 %171
337 OpSelectionMerge %177 None
338 OpBranchConditional %178 %166 %177
341 %136 = OpAccessChain %31 %30 %17 %18
342 %137 = OpLoad %6 %136
343 %138 = OpFOrdGreaterThan %46 %135 %137
344 OpSelectionMerge %140 None
345 OpBranchConditional %138 %139 %140
348 %142 = OpAccessChain %31 %30 %17 %49
349 %143 = OpLoad %6 %142
350 %144 = OpFOrdLessThan %46 %141 %143
353 %145 = OpPhi %46 %138 %177 %144 %139
354 OpSelectionMerge %147 None
355 OpBranchConditional %145 %146 %161
357 %151 = OpAccessChain %19 %16 %17 %49
358 %152 = OpLoad %10 %151
359 %153 = OpConvertSToF %6 %152
360 %160 = OpCompositeConstruct %7 %22 %153 %153 %22
364 %162 = OpAccessChain %19 %16 %17 %49
365 %163 = OpLoad %10 %162
366 %164 = OpConvertSToF %6 %163
367 %165 = OpCompositeConstruct %7 %164 %164 %164 %164
378 # uniforms for variant
380 # _GLF_uniform_int_values
381 BUFFER variant__GLF_uniform_int_values DATA_TYPE int32[] STD140 DATA
384 # _GLF_uniform_float_values
385 BUFFER variant__GLF_uniform_float_values DATA_TYPE float[] STD140 DATA
389 BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM
391 PIPELINE graphics variant_pipeline
392 ATTACH variant_vertex_shader
393 ATTACH variant_fragment_shader
394 FRAMEBUFFER_SIZE 32 32
395 BIND BUFFER variant_framebuffer AS color LOCATION 0
396 BIND BUFFER variant__GLF_uniform_int_values AS uniform DESCRIPTOR_SET 0 BINDING 1
397 BIND BUFFER variant__GLF_uniform_float_values AS uniform DESCRIPTOR_SET 0 BINDING 0
399 CLEAR_COLOR variant_pipeline 0 0 0 255
401 CLEAR variant_pipeline
402 RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 32 32
404 EXPECT variant_framebuffer IDX 0 0 SIZE 32 32 EQ_RGBA 255 0 0 255