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