Fix missing dependency on sparse binds
[platform/upstream/VK-GL-CTS.git] / external / vulkancts / data / vulkan / amber / graphicsfuzz / global-array-loops.amber
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 bug found by GraphicsFuzz.
19
20 # Short description: A loop that writes then reads a global array
21
22 # The test passes because the first 4-iteration loop increments acc, and then the
23 # shader writes red if acc == 4, which is always the case.
24
25 # Optimized using spirv-opt with the following arguments:
26 # '--reduce-load-size'
27 # '--combine-access-chains'
28 # '--ccp'
29 # '--inline-entry-points-exhaustive'
30 # '--eliminate-dead-code-aggressive'
31 # '--eliminate-dead-branches'
32 # '--merge-return'
33 # '--combine-access-chains'
34 # '--scalar-replacement=100'
35 # '--private-to-local'
36 # '--convert-local-access-chains'
37 # '--private-to-local'
38 # '--scalar-replacement=100'
39 # '--eliminate-local-single-block'
40 # '--scalar-replacement=100'
41 # '--vector-dce'
42 # '--eliminate-local-multi-store'
43 # '--redundancy-elimination'
44 # '--eliminate-local-multi-store'
45 # '--vector-dce'
46 # '--inline-entry-points-exhaustive'
47 # spirv-opt commit hash: 18b3b94567a9251a6f8491a6d07c4422abadd22c
48
49
50
51 SHADER vertex variant_vertex_shader PASSTHROUGH
52
53 # variant_fragment_shader is derived from the following GLSL:
54 # #version 310 es
55 # precision highp float;
56 #
57 # layout(location = 0) out vec4 _GLF_color;
58 #
59 # layout(set = 0, binding = 0) uniform buf0
60 # {
61 #     float one;
62 # };
63 #
64 # int globalNumbers[10];
65 #
66 # // Sets globalNumbers[0] to 1.
67 # // We assume:
68 # //  n == 0
69 # //  globalNumbers[0] == 0
70 # int setGlobalNumberZeroToOne(int n)
71 # {
72 #     for (
73 #         int i = 0;
74 #         i <= n;
75 #         i++)
76 #     {
77 #         if (globalNumbers[n] <= 1)
78 #         {
79 #             globalNumbers[n] = 1;
80 #         }
81 #     }
82 #     return 2;
83 # }
84 #
85 # int yieldsZero()
86 # {
87 #     for (
88 #         int i = 0;
89 #         i < int(one);
90 #         i++)
91 #     {
92 #         return i;
93 #     }
94 # }
95 #
96 # void main()
97 # {
98 #     int acc = 0;
99 #     int localNumbers[2];
100 #     for (
101 #         int i = 0;
102 #         i < 4;
103 #         i++)
104 #     {
105 #         localNumbers[1] = yieldsZero();
106 #         globalNumbers[0] = 0;
107 #         setGlobalNumberZeroToOne(localNumbers[1]);
108 #         acc += globalNumbers[int(one) - 1]; // acc += 1;
109 #     }
110 #
111 #     // acc should be 4.
112 #
113 #     if (acc == 4)
114 #         _GLF_color = vec4(1.0, 0.0, 0.0, 1.0);
115 #     else
116 #         _GLF_color = vec4(0.0, 0.0, 0.0, 1.0);
117 # }
118 SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0
119 ; SPIR-V
120 ; Version: 1.0
121 ; Generator: Khronos Glslang Reference Front End; 8
122 ; Bound: 191
123 ; Schema: 0
124                OpCapability Shader
125           %1 = OpExtInstImport "GLSL.std.450"
126                OpMemoryModel Logical GLSL450
127                OpEntryPoint Fragment %4 "main" %104
128                OpExecutionMode %4 OriginUpperLeft
129                OpSource ESSL 310
130                OpName %4 "main"
131                OpName %13 "yieldsZero("
132                OpName %30 "globalNumbers"
133                OpName %46 "i"
134                OpName %54 "buf0"
135                OpMemberName %54 0 "one"
136                OpName %56 ""
137                OpName %67 "acc"
138                OpName %68 "i"
139                OpName %80 "localNumbers"
140                OpName %84 "param"
141                OpName %104 "_GLF_color"
142                OpDecorate %13 RelaxedPrecision
143                OpDecorate %30 RelaxedPrecision
144                OpDecorate %46 RelaxedPrecision
145                OpMemberDecorate %54 0 Offset 0
146                OpDecorate %54 Block
147                OpDecorate %56 DescriptorSet 0
148                OpDecorate %56 Binding 0
149                OpDecorate %67 RelaxedPrecision
150                OpDecorate %68 RelaxedPrecision
151                OpDecorate %80 RelaxedPrecision
152                OpDecorate %86 RelaxedPrecision
153                OpDecorate %93 RelaxedPrecision
154                OpDecorate %95 RelaxedPrecision
155                OpDecorate %97 RelaxedPrecision
156                OpDecorate %104 Location 0
157                OpDecorate %110 RelaxedPrecision
158                OpDecorate %122 RelaxedPrecision
159                OpDecorate %129 RelaxedPrecision
160                OpDecorate %131 RelaxedPrecision
161                OpDecorate %143 RelaxedPrecision
162                OpDecorate %144 RelaxedPrecision
163                OpDecorate %146 RelaxedPrecision
164                OpDecorate %147 RelaxedPrecision
165                OpDecorate %148 RelaxedPrecision
166                OpDecorate %161 RelaxedPrecision
167                OpDecorate %160 RelaxedPrecision
168                OpDecorate %156 RelaxedPrecision
169                OpDecorate %167 RelaxedPrecision
170                OpDecorate %168 RelaxedPrecision
171                OpDecorate %169 RelaxedPrecision
172                OpDecorate %178 RelaxedPrecision
173                OpDecorate %186 RelaxedPrecision
174                OpDecorate %190 RelaxedPrecision
175           %2 = OpTypeVoid
176           %3 = OpTypeFunction %2
177           %6 = OpTypeInt 32 1
178           %7 = OpTypePointer Function %6
179          %12 = OpTypeFunction %6
180          %16 = OpConstant %6 0
181          %24 = OpTypeBool
182          %26 = OpTypeInt 32 0
183          %27 = OpConstant %26 10
184          %28 = OpTypeArray %6 %27
185          %29 = OpTypePointer Private %28
186          %32 = OpTypePointer Private %6
187          %35 = OpConstant %6 1
188          %53 = OpTypeFloat 32
189          %54 = OpTypeStruct %53
190          %55 = OpTypePointer Uniform %54
191          %56 = OpVariable %55 Uniform
192          %57 = OpTypePointer Uniform %53
193          %75 = OpConstant %6 4
194          %77 = OpConstant %26 2
195          %78 = OpTypeArray %6 %77
196          %79 = OpTypePointer Function %78
197         %102 = OpTypeVector %53 4
198         %103 = OpTypePointer Output %102
199         %104 = OpVariable %103 Output
200         %105 = OpConstant %53 1
201         %106 = OpConstant %53 0
202         %107 = OpConstantComposite %102 %105 %106 %106 %105
203         %109 = OpConstantComposite %102 %106 %106 %106 %105
204         %136 = OpConstantFalse %24
205         %137 = OpTypePointer Function %24
206         %139 = OpConstantTrue %24
207         %142 = OpTypePointer Function %28
208         %164 = OpUndef %6
209         %165 = OpUndef %24
210           %4 = OpFunction %2 None %3
211           %5 = OpLabel
212         %166 = OpVariable %137 Function %136
213         %167 = OpVariable %7 Function
214         %168 = OpVariable %7 Function
215         %169 = OpVariable %7 Function
216          %30 = OpVariable %142 Function
217         %110 = OpVariable %7 Function
218          %67 = OpVariable %7 Function
219          %68 = OpVariable %7 Function
220          %80 = OpVariable %79 Function
221          %84 = OpVariable %7 Function
222                OpStore %67 %16
223                OpStore %68 %16
224                OpBranch %69
225          %69 = OpLabel
226         %147 = OpPhi %6 %16 %5 %95 %72
227         %146 = OpPhi %6 %16 %5 %97 %72
228                OpLoopMerge %71 %72 None
229                OpBranch %73
230          %73 = OpLabel
231          %76 = OpSLessThan %24 %146 %75
232                OpBranchConditional %76 %70 %71
233          %70 = OpLabel
234                OpStore %166 %136
235                OpBranch %170
236         %170 = OpLabel
237         %172 = OpPhi %24 %136 %70 %165 %171
238                OpLoopMerge %173 %171 None
239                OpBranch %174
240         %174 = OpLabel
241                OpStore %168 %16
242                OpBranch %175
243         %175 = OpLabel
244         %177 = OpPhi %24 %172 %174 %165 %176
245         %178 = OpPhi %6 %16 %174 %164 %176
246                OpLoopMerge %179 %176 None
247                OpBranch %180
248         %180 = OpLabel
249         %181 = OpAccessChain %57 %56 %16
250         %182 = OpLoad %53 %181
251         %183 = OpConvertFToS %6 %182
252         %184 = OpSLessThan %24 %178 %183
253                OpBranchConditional %184 %185 %179
254         %185 = OpLabel
255                OpStore %166 %139
256                OpStore %167 %178
257                OpBranch %179
258         %176 = OpLabel
259                OpBranch %175
260         %179 = OpLabel
261         %186 = OpPhi %6 %164 %180 %178 %185
262         %187 = OpPhi %24 %177 %180 %139 %185
263                OpSelectionMerge %188 None
264                OpBranchConditional %187 %173 %188
265         %188 = OpLabel
266         %189 = OpUndef %6
267                OpStore %166 %139
268                OpStore %167 %189
269                OpBranch %173
270         %171 = OpLabel
271                OpBranch %170
272         %173 = OpLabel
273         %190 = OpPhi %6 %186 %179 %189 %188
274                OpStore %169 %190
275          %81 = OpLoad %6 %169
276         %143 = OpLoad %78 %80
277         %144 = OpCompositeInsert %78 %81 %143 1
278                OpStore %80 %144
279          %83 = OpAccessChain %7 %30 %16
280                OpStore %83 %16
281          %85 = OpAccessChain %7 %80 %35
282          %86 = OpCompositeExtract %6 %144 1
283                OpStore %84 %86
284                OpStore %110 %16
285                OpBranch %112
286         %112 = OpLabel
287         %148 = OpPhi %6 %16 %173 %129 %114
288                OpLoopMerge %113 %114 None
289                OpBranch %115
290         %115 = OpLabel
291         %118 = OpSLessThanEqual %24 %148 %86
292                OpBranchConditional %118 %119 %113
293         %119 = OpLabel
294         %121 = OpAccessChain %7 %30 %86
295         %122 = OpLoad %6 %121
296         %123 = OpSLessThanEqual %24 %122 %35
297                OpSelectionMerge %124 None
298                OpBranchConditional %123 %125 %124
299         %125 = OpLabel
300                OpStore %121 %35
301                OpBranch %124
302         %124 = OpLabel
303                OpBranch %114
304         %114 = OpLabel
305         %129 = OpIAdd %6 %148 %35
306                OpStore %110 %129
307                OpBranch %112
308         %113 = OpLabel
309          %88 = OpAccessChain %57 %56 %16
310          %89 = OpLoad %53 %88
311          %90 = OpConvertFToS %6 %89
312          %91 = OpISub %6 %90 %35
313          %92 = OpAccessChain %7 %30 %91
314          %93 = OpLoad %6 %92
315          %95 = OpIAdd %6 %147 %93
316                OpStore %67 %95
317                OpBranch %72
318          %72 = OpLabel
319          %97 = OpIAdd %6 %146 %35
320                OpStore %68 %97
321                OpBranch %69
322          %71 = OpLabel
323          %99 = OpIEqual %24 %147 %75
324                OpSelectionMerge %101 None
325                OpBranchConditional %99 %100 %108
326         %100 = OpLabel
327                OpStore %104 %107
328                OpBranch %101
329         %108 = OpLabel
330                OpStore %104 %109
331                OpBranch %101
332         %101 = OpLabel
333                OpReturn
334                OpFunctionEnd
335          %13 = OpFunction %6 None %12
336          %14 = OpLabel
337         %138 = OpVariable %137 Function %136
338         %131 = OpVariable %7 Function
339          %46 = OpVariable %7 Function
340                OpBranch %133
341         %133 = OpLabel
342         %159 = OpPhi %24 %136 %14 %165 %135
343                OpLoopMerge %130 %135 None
344                OpBranch %134
345         %134 = OpLabel
346                OpStore %46 %16
347                OpBranch %47
348          %47 = OpLabel
349         %158 = OpPhi %24 %159 %134 %165 %50
350         %156 = OpPhi %6 %16 %134 %164 %50
351                OpLoopMerge %49 %50 None
352                OpBranch %51
353          %51 = OpLabel
354          %58 = OpAccessChain %57 %56 %16
355          %59 = OpLoad %53 %58
356          %60 = OpConvertFToS %6 %59
357          %61 = OpSLessThan %24 %156 %60
358                OpBranchConditional %61 %48 %49
359          %48 = OpLabel
360                OpStore %138 %139
361                OpStore %131 %156
362                OpBranch %49
363          %50 = OpLabel
364                OpBranch %47
365          %49 = OpLabel
366         %161 = OpPhi %6 %164 %51 %156 %48
367         %157 = OpPhi %24 %158 %51 %139 %48
368                OpSelectionMerge %140 None
369                OpBranchConditional %157 %130 %140
370         %140 = OpLabel
371          %66 = OpUndef %6
372                OpStore %138 %139
373                OpStore %131 %66
374                OpBranch %130
375         %135 = OpLabel
376                OpBranch %133
377         %130 = OpLabel
378         %160 = OpPhi %6 %161 %49 %66 %140
379                OpReturnValue %160
380                OpFunctionEnd
381 END
382
383 # uniforms for variant
384
385 # one
386 BUFFER variant_one DATA_TYPE float DATA
387  1.0
388 END
389
390 BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM
391
392 PIPELINE graphics variant_pipeline
393   ATTACH variant_vertex_shader
394   ATTACH variant_fragment_shader
395   FRAMEBUFFER_SIZE 256 256
396   BIND BUFFER variant_framebuffer AS color LOCATION 0
397   BIND BUFFER variant_one AS uniform DESCRIPTOR_SET 0 BINDING 0
398 END
399 CLEAR_COLOR variant_pipeline 0 0 0 255
400
401 CLEAR variant_pipeline
402 RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 256 256
403
404 EXPECT variant_framebuffer IDX 0 0 SIZE 256 256 EQ_RGBA 255 0 0 255