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
24# Optimized using spirv-opt with the following arguments:
25# '-O'
26# spirv-opt commit hash: a0370efd589be33d5d9a85cfde2f85841b3755af
27
28
29
30SHADER vertex variant_vertex_shader PASSTHROUGH
31
32# variant_fragment_shader is derived from the following GLSL:
33# #version 320 es
34#
35# #define _int_4 _GLF_uniform_int_values[0]
36# #define _int_0 _GLF_uniform_int_values[1]
37# #define _int_1 _GLF_uniform_int_values[2]
38# #define _float_1_0 _GLF_uniform_float_values[0]
39# #define _float_0_0 _GLF_uniform_float_values[1]
40#
41# precision highp float;
42# precision highp int;
43#
44# // Contents of _GLF_uniform_float_values: [1.0, 0.0]
45# layout(set = 0, binding = 0) uniform buf0
46# {
47#     float _GLF_uniform_float_values[2];
48# };
49#
50# // Contents of _GLF_uniform_int_values: [4, 0, 1]
51# layout(set = 0, binding = 1) uniform buf1
52# {
53#     int _GLF_uniform_int_values[3];
54# };
55#
56# // Contents of injectionSwitch: [0.0, 1.0]
57# layout(set = 0, binding = 2) uniform buf2
58# {
59#     highp vec2 injectionSwitch;
60# };
61#
62# layout(location = 0) out vec4 _GLF_color;
63#
64# void main()
65# {
66#     // Always false.
67#     if(injectionSwitch.x > injectionSwitch.y)
68#     {
69#         _GLF_color = vec4(_float_1_0);
70#     }
71#
72#     for(int i = _int_0; i < _int_4; i ++)
73#     {
74#         // Iterates once.
75#         do
76#         {
77#             // Always false.
78#             if(injectionSwitch.x > injectionSwitch.y)
79#             {
80#                 _GLF_color = atanh(vec4(_float_1_0));
81#             }
82#             do
83#             {
84#                 _GLF_color = vec4(_float_1_0);
85#             }
86#             while(gl_FragCoord.x < _float_0_0);
87#         }
88#         while(injectionSwitch.x > injectionSwitch.y);
89#
90#         // The last value of red is chosen during the last iteration.
91#         _GLF_color = vec4[4](vec4(_int_0), vec4(_int_0), vec4(_int_0), vec4(_int_1, _int_0, _int_0, _int_1))[i];
92#     }
93# }
94SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0
95; SPIR-V
96; Version: 1.0
97; Generator: Khronos Glslang Reference Front End; 10
98; Bound: 129
99; Schema: 0
100               OpCapability Shader
101          %1 = OpExtInstImport "GLSL.std.450"
102               OpMemoryModel Logical GLSL450
103               OpEntryPoint Fragment %4 "main" %27 %79
104               OpExecutionMode %4 OriginUpperLeft
105               OpSource ESSL 320
106               OpName %4 "main"
107               OpName %8 "buf2"
108               OpMemberName %8 0 "injectionSwitch"
109               OpName %10 ""
110               OpName %27 "_GLF_color"
111               OpName %30 "buf0"
112               OpMemberName %30 0 "_GLF_uniform_float_values"
113               OpName %32 ""
114               OpName %40 "buf1"
115               OpMemberName %40 0 "_GLF_uniform_int_values"
116               OpName %42 ""
117               OpName %79 "gl_FragCoord"
118               OpName %122 "indexable"
119               OpMemberDecorate %8 0 Offset 0
120               OpDecorate %8 Block
121               OpDecorate %10 DescriptorSet 0
122               OpDecorate %10 Binding 2
123               OpDecorate %27 Location 0
124               OpDecorate %29 ArrayStride 16
125               OpMemberDecorate %30 0 Offset 0
126               OpDecorate %30 Block
127               OpDecorate %32 DescriptorSet 0
128               OpDecorate %32 Binding 0
129               OpDecorate %39 ArrayStride 16
130               OpMemberDecorate %40 0 Offset 0
131               OpDecorate %40 Block
132               OpDecorate %42 DescriptorSet 0
133               OpDecorate %42 Binding 1
134               OpDecorate %79 BuiltIn FragCoord
135          %2 = OpTypeVoid
136          %3 = OpTypeFunction %2
137          %6 = OpTypeFloat 32
138          %7 = OpTypeVector %6 2
139          %8 = OpTypeStruct %7
140          %9 = OpTypePointer Uniform %8
141         %10 = OpVariable %9 Uniform
142         %11 = OpTypeInt 32 1
143         %12 = OpConstant %11 0
144         %13 = OpTypeInt 32 0
145         %14 = OpConstant %13 0
146         %15 = OpTypePointer Uniform %6
147         %18 = OpConstant %13 1
148         %21 = OpTypeBool
149         %25 = OpTypeVector %6 4
150         %26 = OpTypePointer Output %25
151         %27 = OpVariable %26 Output
152         %28 = OpConstant %13 2
153         %29 = OpTypeArray %6 %28
154         %30 = OpTypeStruct %29
155         %31 = OpTypePointer Uniform %30
156         %32 = OpVariable %31 Uniform
157         %38 = OpConstant %13 3
158         %39 = OpTypeArray %11 %38
159         %40 = OpTypeStruct %39
160         %41 = OpTypePointer Uniform %40
161         %42 = OpVariable %41 Uniform
162         %43 = OpConstant %11 1
163         %44 = OpTypePointer Uniform %11
164         %78 = OpTypePointer Input %25
165         %79 = OpVariable %78 Input
166         %80 = OpTypePointer Input %6
167        %103 = OpConstant %11 2
168        %117 = OpConstant %13 4
169        %118 = OpTypeArray %25 %117
170        %121 = OpTypePointer Function %118
171        %123 = OpTypePointer Function %25
172          %4 = OpFunction %2 None %3
173          %5 = OpLabel
174        %122 = OpVariable %121 Function
175         %16 = OpAccessChain %15 %10 %12 %14
176         %17 = OpLoad %6 %16
177         %19 = OpAccessChain %15 %10 %12 %18
178         %20 = OpLoad %6 %19
179         %22 = OpFOrdGreaterThan %21 %17 %20
180               OpSelectionMerge %24 None
181               OpBranchConditional %22 %23 %24
182         %23 = OpLabel
183         %33 = OpAccessChain %15 %32 %12 %12
184         %34 = OpLoad %6 %33
185         %35 = OpCompositeConstruct %25 %34 %34 %34 %34
186               OpStore %27 %35
187               OpBranch %24
188         %24 = OpLabel
189         %45 = OpAccessChain %44 %42 %12 %43
190         %46 = OpLoad %11 %45
191               OpBranch %47
192         %47 = OpLabel
193        %128 = OpPhi %11 %46 %24 %127 %50
194         %53 = OpAccessChain %44 %42 %12 %12
195         %54 = OpLoad %11 %53
196         %55 = OpSLessThan %21 %128 %54
197               OpLoopMerge %49 %50 None
198               OpBranchConditional %55 %48 %49
199         %48 = OpLabel
200               OpBranch %56
201         %56 = OpLabel
202               OpLoopMerge %58 %59 None
203               OpBranch %57
204         %57 = OpLabel
205               OpSelectionMerge %66 None
206               OpBranchConditional %22 %65 %66
207         %65 = OpLabel
208         %67 = OpAccessChain %15 %32 %12 %12
209         %68 = OpLoad %6 %67
210         %69 = OpCompositeConstruct %25 %68 %68 %68 %68
211         %70 = OpExtInst %25 %1 Atanh %69
212               OpStore %27 %70
213               OpBranch %66
214         %66 = OpLabel
215               OpBranch %71
216         %71 = OpLabel
217         %75 = OpAccessChain %15 %32 %12 %12
218         %76 = OpLoad %6 %75
219         %77 = OpCompositeConstruct %25 %76 %76 %76 %76
220               OpStore %27 %77
221         %81 = OpAccessChain %80 %79 %14
222         %82 = OpLoad %6 %81
223         %83 = OpAccessChain %15 %32 %12 %43
224         %84 = OpLoad %6 %83
225         %85 = OpFOrdLessThan %21 %82 %84
226               OpLoopMerge %73 %71 None
227               OpBranchConditional %85 %71 %73
228         %73 = OpLabel
229               OpBranch %59
230         %59 = OpLabel
231               OpBranchConditional %22 %56 %58
232         %58 = OpLabel
233         %93 = OpConvertSToF %6 %46
234         %94 = OpCompositeConstruct %25 %93 %93 %93 %93
235        %104 = OpAccessChain %44 %42 %12 %103
236        %105 = OpLoad %11 %104
237        %106 = OpConvertSToF %6 %105
238        %116 = OpCompositeConstruct %25 %106 %93 %93 %106
239        %119 = OpCompositeConstruct %118 %94 %94 %94 %116
240               OpStore %122 %119
241        %124 = OpAccessChain %123 %122 %128
242        %125 = OpLoad %25 %124
243               OpStore %27 %125
244               OpBranch %50
245         %50 = OpLabel
246        %127 = OpIAdd %11 %128 %43
247               OpBranch %47
248         %49 = OpLabel
249               OpReturn
250               OpFunctionEnd
251END
252
253# uniforms for variant
254
255# injectionSwitch
256BUFFER variant_injectionSwitch DATA_TYPE vec2<float> STD140 DATA
257 0.0 1.0
258END
259# _GLF_uniform_int_values
260BUFFER variant__GLF_uniform_int_values DATA_TYPE int32[] STD140 DATA
261 4 0 1
262END
263# _GLF_uniform_float_values
264BUFFER variant__GLF_uniform_float_values DATA_TYPE float[] STD140 DATA
265 1.0 0.0
266END
267
268BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM
269
270PIPELINE graphics variant_pipeline
271  ATTACH variant_vertex_shader
272  ATTACH variant_fragment_shader
273  FRAMEBUFFER_SIZE 32 32
274  BIND BUFFER variant_framebuffer AS color LOCATION 0
275  BIND BUFFER variant_injectionSwitch AS uniform DESCRIPTOR_SET 0 BINDING 2
276  BIND BUFFER variant__GLF_uniform_int_values AS uniform DESCRIPTOR_SET 0 BINDING 1
277  BIND BUFFER variant__GLF_uniform_float_values AS uniform DESCRIPTOR_SET 0 BINDING 0
278END
279CLEAR_COLOR variant_pipeline 0 0 0 255
280
281CLEAR variant_pipeline
282RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 32 32
283
284EXPECT variant_framebuffer IDX 0 0 SIZE 32 32 EQ_RGBA 255 0 0 255
285