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