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