Fix missing dependency on sparse binds
[platform/upstream/VK-GL-CTS.git] / external / vulkancts / data / vulkan / amber / graphicsfuzz / struct-array-data-as-loop-iterator.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 fragment shader that uses struct array data for loop iterator value
21
22 # The test passes because shader always writes red.
23
24 # Optimized using spirv-opt with the following arguments:
25 # '-O'
26 # spirv-opt commit hash: ab7ac60f14ae66006bed5c989a2cfd4c4881704c
27
28
29
30 SHADER vertex variant_vertex_shader PASSTHROUGH
31
32 # variant_fragment_shader is derived from the following GLSL:
33 # #version 310 es
34 # precision highp float;
35 # precision highp int;
36 #
37 # layout(location = 0) out vec4 _GLF_color;
38 #
39 # layout(set = 0, binding = 0) uniform buf0
40 # {
41 #     float zero;
42 # };
43 #
44 # struct S
45 # {
46 #     int a;
47 # };
48 #
49 # // Always returns given parameter value.
50 # int func(int x)
51 # {
52 #     S arr[9];
53 #     arr[0].a = 1;
54 #
55 #     for (int i = 0; i < 1 + int(zero); i++)
56 #     {
57 #         // Always true.
58 #         if (zero < 1.0)
59 #             return x;
60 #
61 #         i = arr[i].a;
62 #     }
63 #
64 #     return -1;
65 # }
66 #
67 # void main()
68 # {
69 #     for (int i = 0; i < 2; i++)
70 #     {
71 #         switch (func(i))
72 #         {
73 #             case -1:
74 #             return;
75 #             case 0:
76 #                 if (func(5) == 5)
77 #                     _GLF_color = vec4(1, 0, 0, 1);
78 #                 else
79 #                     _GLF_color = vec4(0);
80 #                 return;
81 #         }
82 #     }
83 #     _GLF_color = vec4(0); // Should never be reached.
84 # }
85 SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0
86 ; SPIR-V
87 ; Version: 1.0
88 ; Generator: Khronos Glslang Reference Front End; 8
89 ; Bound: 204
90 ; Schema: 0
91                OpCapability Shader
92           %1 = OpExtInstImport "GLSL.std.450"
93                OpMemoryModel Logical GLSL450
94                OpEntryPoint Fragment %4 "main" %79
95                OpExecutionMode %4 OriginUpperLeft
96                OpSource ESSL 310
97                OpName %4 "main"
98                OpName %12 "S"
99                OpMemberName %12 0 "a"
100                OpName %29 "buf0"
101                OpMemberName %29 0 "zero"
102                OpName %31 ""
103                OpName %79 "_GLF_color"
104                OpMemberDecorate %29 0 Offset 0
105                OpDecorate %29 Block
106                OpDecorate %31 DescriptorSet 0
107                OpDecorate %31 Binding 0
108                OpDecorate %79 Location 0
109           %2 = OpTypeVoid
110           %3 = OpTypeFunction %2
111           %6 = OpTypeInt 32 1
112           %7 = OpTypePointer Function %6
113          %12 = OpTypeStruct %6
114          %13 = OpTypeInt 32 0
115          %14 = OpConstant %13 9
116          %15 = OpTypeArray %12 %14
117          %16 = OpTypePointer Function %15
118          %18 = OpConstant %6 0
119          %19 = OpConstant %6 1
120          %28 = OpTypeFloat 32
121          %29 = OpTypeStruct %28
122          %30 = OpTypePointer Uniform %29
123          %31 = OpVariable %30 Uniform
124          %32 = OpTypePointer Uniform %28
125          %37 = OpTypeBool
126          %41 = OpConstant %28 1
127          %52 = OpConstant %6 -1
128          %62 = OpConstant %6 2
129          %71 = OpConstant %6 5
130          %77 = OpTypeVector %28 4
131          %78 = OpTypePointer Output %77
132          %79 = OpVariable %78 Output
133          %80 = OpConstant %28 0
134          %81 = OpConstantComposite %77 %41 %80 %80 %41
135          %83 = OpConstantComposite %77 %80 %80 %80 %80
136          %92 = OpConstantFalse %37
137          %95 = OpConstantTrue %37
138         %188 = OpUndef %6
139           %4 = OpFunction %2 None %3
140           %5 = OpLabel
141         %144 = OpVariable %16 Function
142         %109 = OpVariable %16 Function
143                OpBranch %89
144          %89 = OpLabel
145                OpLoopMerge %88 %91 None
146                OpBranch %56
147          %56 = OpLabel
148         %186 = OpPhi %6 %188 %89 %182 %59
149         %177 = OpPhi %6 %18 %89 %87 %59
150          %63 = OpSLessThan %37 %177 %62
151                OpLoopMerge %58 %59 None
152                OpBranchConditional %63 %57 %58
153          %57 = OpLabel
154                OpBranch %112
155         %112 = OpLabel
156         %116 = OpAccessChain %7 %109 %18 %18
157                OpStore %116 %19
158                OpLoopMerge %113 %114 None
159                OpBranch %117
160         %117 = OpLabel
161         %178 = OpPhi %6 %18 %112 %138 %119
162         %122 = OpAccessChain %32 %31 %18
163         %123 = OpLoad %28 %122
164         %124 = OpConvertFToS %6 %123
165         %125 = OpIAdd %6 %19 %124
166         %126 = OpSLessThan %37 %178 %125
167                OpLoopMerge %118 %119 None
168                OpBranchConditional %126 %127 %118
169         %127 = OpLabel
170         %130 = OpFOrdLessThan %37 %123 %41
171                OpSelectionMerge %131 None
172                OpBranchConditional %130 %132 %131
173         %132 = OpLabel
174                OpBranch %118
175         %131 = OpLabel
176         %135 = OpAccessChain %7 %109 %178 %18
177         %136 = OpLoad %6 %135
178                OpBranch %119
179         %119 = OpLabel
180         %138 = OpIAdd %6 %136 %19
181                OpBranch %117
182         %118 = OpLabel
183         %183 = OpPhi %6 %186 %117 %177 %132
184         %179 = OpPhi %37 %92 %117 %95 %132
185                OpSelectionMerge %140 None
186                OpBranchConditional %179 %113 %140
187         %140 = OpLabel
188                OpBranch %113
189         %114 = OpLabel
190                OpBranch %112
191         %113 = OpLabel
192         %182 = OpPhi %6 %183 %118 %52 %140
193                OpSelectionMerge %69 None
194                OpSwitch %182 %69 -1 %67 0 %68
195          %68 = OpLabel
196                OpBranch %147
197         %147 = OpLabel
198         %151 = OpAccessChain %7 %144 %18 %18
199                OpStore %151 %19
200                OpLoopMerge %148 %149 None
201                OpBranch %152
202         %152 = OpLabel
203         %189 = OpPhi %6 %18 %147 %173 %154
204         %161 = OpSLessThan %37 %189 %125
205                OpLoopMerge %153 %154 None
206                OpBranchConditional %161 %162 %153
207         %162 = OpLabel
208         %165 = OpFOrdLessThan %37 %123 %41
209                OpSelectionMerge %166 None
210                OpBranchConditional %165 %167 %166
211         %167 = OpLabel
212                OpBranch %153
213         %166 = OpLabel
214         %170 = OpAccessChain %7 %144 %189 %18
215         %171 = OpLoad %6 %170
216                OpBranch %154
217         %154 = OpLabel
218         %173 = OpIAdd %6 %171 %19
219                OpBranch %152
220         %153 = OpLabel
221         %194 = OpPhi %6 %188 %152 %71 %167
222         %190 = OpPhi %37 %92 %152 %95 %167
223                OpSelectionMerge %175 None
224                OpBranchConditional %190 %148 %175
225         %175 = OpLabel
226                OpBranch %148
227         %149 = OpLabel
228                OpBranch %147
229         %148 = OpLabel
230         %193 = OpPhi %6 %194 %153 %52 %175
231          %74 = OpIEqual %37 %193 %71
232                OpSelectionMerge %76 None
233                OpBranchConditional %74 %75 %82
234          %82 = OpLabel
235                OpStore %79 %83
236                OpBranch %76
237          %75 = OpLabel
238                OpStore %79 %81
239                OpBranch %76
240          %76 = OpLabel
241                OpBranch %58
242          %67 = OpLabel
243                OpBranch %58
244          %69 = OpLabel
245                OpBranch %59
246          %59 = OpLabel
247          %87 = OpIAdd %6 %177 %19
248                OpBranch %56
249          %58 = OpLabel
250         %203 = OpPhi %37 %92 %56 %95 %67 %95 %76
251                OpSelectionMerge %96 None
252                OpBranchConditional %203 %88 %96
253          %96 = OpLabel
254                OpStore %79 %83
255                OpBranch %88
256          %91 = OpLabel
257                OpBranch %89
258          %88 = OpLabel
259                OpReturn
260                OpFunctionEnd
261 END
262
263 # uniforms for variant
264
265 # zero
266 BUFFER variant_zero DATA_TYPE float DATA
267  0.0
268 END
269
270 BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM
271
272 PIPELINE graphics variant_pipeline
273   ATTACH variant_vertex_shader
274   ATTACH variant_fragment_shader
275   FRAMEBUFFER_SIZE 256 256
276   BIND BUFFER variant_framebuffer AS color LOCATION 0
277   BIND BUFFER variant_zero AS uniform DESCRIPTOR_SET 0 BINDING 0
278 END
279 CLEAR_COLOR variant_pipeline 0 0 0 255
280
281 CLEAR variant_pipeline
282 RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 256 256
283
284 EXPECT variant_framebuffer IDX 0 0 SIZE 256 256 EQ_RGBA 255 0 0 255