1#!amber
2
3# Copyright 2022 Google LLC
4#
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
8#
9#     http://www.apache.org/licenses/LICENSE-2.0
10#
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.
16
17
18# A test for a coverage-gap found by the GraphicsFuzz project.
19
20# Short description: A fragment shader that covers specific LLVM code paths
21
22# The test passes because the shader always writes red.
23
24SHADER vertex variant_vertex_shader PASSTHROUGH
25
26# variant_fragment_shader is derived from the following GLSL:
27# #version 320 es
28# #define _int_1 _GLF_uniform_int_values[0]
29# #define _int_0 _GLF_uniform_int_values[1]
30# #define _int_2 _GLF_uniform_int_values[2]
31#
32# precision highp float;
33# precision highp int;
34#
35# // Contents of _GLF_uniform_int_values: [1, 0, 2]
36# layout(set = 0, binding = 0) uniform buf0
37# {
38#     int _GLF_uniform_int_values[3];
39# };
40#
41# const int _GLF_global_loop_bound = 10;
42# int _GLF_global_loop_count = 0;
43#
44# // Contents of injectionSwitch: [0.0, 1.0]
45# layout(set = 0, binding = 1) uniform buf1
46# {
47#     vec2 injectionSwitch;
48# };
49#
50# layout(location = 0) out vec4 _GLF_color;
51#
52# void main()
53# {
54#     int a = _int_0;
55#
56#     // Iterates twice.
57#     for(int i = _int_1; _GLF_global_loop_count < _GLF_global_loop_bound; i = _int_2)
58#     {
59#         _GLF_global_loop_count++;
60#
61#         int b = i - int(injectionSwitch.x) + int(max(injectionSwitch, injectionSwitch).x) - 1;
62#
63#         // Loops until the global loop bound is reached, but only during the second iteration
64#         // when i == 2.
65#         while(b >= _int_1 && _GLF_global_loop_count < _GLF_global_loop_bound)
66#         {
67#             _GLF_global_loop_count++;
68#         }
69#
70#         // Iterates once when i == 1. The global loop bound is already reached when i == 2.
71#         for(int j = _int_1; j <= i && _GLF_global_loop_count < _GLF_global_loop_bound; j++)
72#         {
73#             _GLF_global_loop_count++;
74#             a++;
75#         }
76#     }
77#
78#     // Always true.
79#     if(a == _int_1)
80#     {
81#         _GLF_color = vec4(_int_1, _int_0, _int_0, _int_1);
82#     }
83#     else
84#     {
85#         _GLF_color = vec4(_int_0);
86#     }
87# }
88SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0
89; SPIR-V
90; Version: 1.0
91; Generator: Khronos Glslang Reference Front End; 10
92; Bound: 123
93; Schema: 0
94               OpCapability Shader
95          %1 = OpExtInstImport "GLSL.std.450"
96               OpMemoryModel Logical GLSL450
97               OpEntryPoint Fragment %4 "main" %104
98               OpExecutionMode %4 OriginUpperLeft
99               OpSource ESSL 320
100               OpName %4 "main"
101               OpName %8 "_GLF_global_loop_count"
102               OpName %11 "a"
103               OpName %15 "buf0"
104               OpMemberName %15 0 "_GLF_uniform_int_values"
105               OpName %17 ""
106               OpName %22 "i"
107               OpName %36 "b"
108               OpName %40 "buf1"
109               OpMemberName %40 0 "injectionSwitch"
110               OpName %42 ""
111               OpName %73 "j"
112               OpName %104 "_GLF_color"
113               OpDecorate %14 ArrayStride 16
114               OpMemberDecorate %15 0 Offset 0
115               OpDecorate %15 Block
116               OpDecorate %17 DescriptorSet 0
117               OpDecorate %17 Binding 0
118               OpMemberDecorate %40 0 Offset 0
119               OpDecorate %40 Block
120               OpDecorate %42 DescriptorSet 0
121               OpDecorate %42 Binding 1
122               OpDecorate %104 Location 0
123          %2 = OpTypeVoid
124          %3 = OpTypeFunction %2
125          %6 = OpTypeInt 32 1
126          %7 = OpTypePointer Private %6
127          %8 = OpVariable %7 Private
128          %9 = OpConstant %6 0
129         %10 = OpTypePointer Function %6
130         %12 = OpTypeInt 32 0
131         %13 = OpConstant %12 3
132         %14 = OpTypeArray %6 %13
133         %15 = OpTypeStruct %14
134         %16 = OpTypePointer Uniform %15
135         %17 = OpVariable %16 Uniform
136         %18 = OpConstant %6 1
137         %19 = OpTypePointer Uniform %6
138         %31 = OpConstant %6 10
139         %32 = OpTypeBool
140         %38 = OpTypeFloat 32
141         %39 = OpTypeVector %38 2
142         %40 = OpTypeStruct %39
143         %41 = OpTypePointer Uniform %40
144         %42 = OpVariable %41 Uniform
145         %43 = OpConstant %12 0
146         %44 = OpTypePointer Uniform %38
147         %49 = OpTypePointer Uniform %39
148         %93 = OpConstant %6 2
149        %102 = OpTypeVector %38 4
150        %103 = OpTypePointer Output %102
151        %104 = OpVariable %103 Output
152          %4 = OpFunction %2 None %3
153          %5 = OpLabel
154         %11 = OpVariable %10 Function
155         %22 = OpVariable %10 Function
156         %36 = OpVariable %10 Function
157         %73 = OpVariable %10 Function
158               OpStore %8 %9
159         %20 = OpAccessChain %19 %17 %9 %18
160         %21 = OpLoad %6 %20
161               OpStore %11 %21
162         %23 = OpAccessChain %19 %17 %9 %9
163         %24 = OpLoad %6 %23
164               OpStore %22 %24
165               OpBranch %25
166         %25 = OpLabel
167               OpLoopMerge %27 %28 None
168               OpBranch %29
169         %29 = OpLabel
170         %30 = OpLoad %6 %8
171         %33 = OpSLessThan %32 %30 %31
172               OpBranchConditional %33 %26 %27
173         %26 = OpLabel
174         %34 = OpLoad %6 %8
175         %35 = OpIAdd %6 %34 %18
176               OpStore %8 %35
177         %37 = OpLoad %6 %22
178         %45 = OpAccessChain %44 %42 %9 %43
179         %46 = OpLoad %38 %45
180         %47 = OpConvertFToS %6 %46
181         %48 = OpISub %6 %37 %47
182         %50 = OpAccessChain %49 %42 %9
183         %51 = OpLoad %39 %50
184         %52 = OpAccessChain %49 %42 %9
185         %53 = OpLoad %39 %52
186         %54 = OpExtInst %39 %1 FMax %51 %53
187         %55 = OpCompositeExtract %38 %54 0
188         %56 = OpConvertFToS %6 %55
189         %57 = OpIAdd %6 %48 %56
190         %58 = OpISub %6 %57 %18
191               OpStore %36 %58
192               OpBranch %59
193         %59 = OpLabel
194               OpLoopMerge %61 %62 None
195               OpBranch %63
196         %63 = OpLabel
197         %64 = OpLoad %6 %36
198         %65 = OpAccessChain %19 %17 %9 %9
199         %66 = OpLoad %6 %65
200         %67 = OpSGreaterThanEqual %32 %64 %66
201         %68 = OpLoad %6 %8
202         %69 = OpSLessThan %32 %68 %31
203         %70 = OpLogicalAnd %32 %67 %69
204               OpBranchConditional %70 %60 %61
205         %60 = OpLabel
206         %71 = OpLoad %6 %8
207         %72 = OpIAdd %6 %71 %18
208               OpStore %8 %72
209               OpBranch %62
210         %62 = OpLabel
211               OpBranch %59
212         %61 = OpLabel
213         %74 = OpAccessChain %19 %17 %9 %9
214         %75 = OpLoad %6 %74
215               OpStore %73 %75
216               OpBranch %76
217         %76 = OpLabel
218               OpLoopMerge %78 %79 None
219               OpBranch %80
220         %80 = OpLabel
221         %81 = OpLoad %6 %73
222         %82 = OpLoad %6 %22
223         %83 = OpSLessThanEqual %32 %81 %82
224         %84 = OpLoad %6 %8
225         %85 = OpSLessThan %32 %84 %31
226         %86 = OpLogicalAnd %32 %83 %85
227               OpBranchConditional %86 %77 %78
228         %77 = OpLabel
229         %87 = OpLoad %6 %8
230         %88 = OpIAdd %6 %87 %18
231               OpStore %8 %88
232         %89 = OpLoad %6 %11
233         %90 = OpIAdd %6 %89 %18
234               OpStore %11 %90
235               OpBranch %79
236         %79 = OpLabel
237         %91 = OpLoad %6 %73
238         %92 = OpIAdd %6 %91 %18
239               OpStore %73 %92
240               OpBranch %76
241         %78 = OpLabel
242               OpBranch %28
243         %28 = OpLabel
244         %94 = OpAccessChain %19 %17 %9 %93
245         %95 = OpLoad %6 %94
246               OpStore %22 %95
247               OpBranch %25
248         %27 = OpLabel
249         %96 = OpLoad %6 %11
250         %97 = OpAccessChain %19 %17 %9 %9
251         %98 = OpLoad %6 %97
252         %99 = OpIEqual %32 %96 %98
253               OpSelectionMerge %101 None
254               OpBranchConditional %99 %100 %118
255        %100 = OpLabel
256        %105 = OpAccessChain %19 %17 %9 %9
257        %106 = OpLoad %6 %105
258        %107 = OpConvertSToF %38 %106
259        %108 = OpAccessChain %19 %17 %9 %18
260        %109 = OpLoad %6 %108
261        %110 = OpConvertSToF %38 %109
262        %111 = OpAccessChain %19 %17 %9 %18
263        %112 = OpLoad %6 %111
264        %113 = OpConvertSToF %38 %112
265        %114 = OpAccessChain %19 %17 %9 %9
266        %115 = OpLoad %6 %114
267        %116 = OpConvertSToF %38 %115
268        %117 = OpCompositeConstruct %102 %107 %110 %113 %116
269               OpStore %104 %117
270               OpBranch %101
271        %118 = OpLabel
272        %119 = OpAccessChain %19 %17 %9 %18
273        %120 = OpLoad %6 %119
274        %121 = OpConvertSToF %38 %120
275        %122 = OpCompositeConstruct %102 %121 %121 %121 %121
276               OpStore %104 %122
277               OpBranch %101
278        %101 = OpLabel
279               OpReturn
280               OpFunctionEnd
281END
282
283# uniforms for variant
284
285# injectionSwitch
286BUFFER variant_injectionSwitch DATA_TYPE vec2<float> STD140 DATA
287 0.0 1.0
288END
289# _GLF_uniform_int_values
290BUFFER variant__GLF_uniform_int_values DATA_TYPE int32[] STD140 DATA
291 1 0 2
292END
293
294BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM
295
296PIPELINE graphics variant_pipeline
297  ATTACH variant_vertex_shader
298  ATTACH variant_fragment_shader
299  FRAMEBUFFER_SIZE 32 32
300  BIND BUFFER variant_framebuffer AS color LOCATION 0
301  BIND BUFFER variant_injectionSwitch AS uniform DESCRIPTOR_SET 0 BINDING 1
302  BIND BUFFER variant__GLF_uniform_int_values AS uniform DESCRIPTOR_SET 0 BINDING 0
303END
304CLEAR_COLOR variant_pipeline 0 0 0 255
305
306CLEAR variant_pipeline
307RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 32 32
308
309EXPECT variant_framebuffer IDX 0 0 SIZE 32 32 EQ_RGBA 255 0 0 255
310