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