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