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