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