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