Fix missing dependency on sparse binds
[platform/upstream/VK-GL-CTS.git] / external / vulkancts / data / vulkan / amber / graphicsfuzz / loops-breaks-returns.amber
1 #!amber
2
3 # Copyright 2019 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 compute shader with loops, breaks, returns
21
22 # The test passes because the shader immediately writes 42 to the 0th position
23 # in the SSBO and that is the only thing we check. All loops terminate. All
24 # other writes to the SSBO are at indices greater than 0.
25
26 # Optimized using spirv-opt with the following arguments:
27 # '--eliminate-dead-code-aggressive'
28 # '--simplify-instructions'
29 # '--redundancy-elimination'
30 # '--copy-propagate-arrays'
31 # '--convert-local-access-chains'
32 # '--eliminate-dead-branches'
33 # '--eliminate-local-multi-store'
34 # '--eliminate-local-multi-store'
35 # '--eliminate-dead-inserts'
36 # '--eliminate-local-single-block'
37 # '--redundancy-elimination'
38 # '--eliminate-dead-branches'
39 # spirv-opt commit hash: 4a00a80c40484a6f6f72f48c9d34943cf8f180d4
40
41
42
43 # variant_compute_shader is derived from the following GLSL:
44 # #version 310 es
45 #
46 # layout(std430, binding = 0) buffer theSSBO
47 # {
48 #   uint data_out[5];
49 # };
50 #
51 # layout(set = 0, binding = 1) uniform buf0 {
52 #   vec2 injectionSwitch;
53 # };
54 #
55 # layout(local_size_x = 100, local_size_y = 1, local_size_z = 1) in;
56 #
57 # void main()
58 # {
59 #   data_out[0] = 42u;
60 #   uint gid = uint(injectionSwitch.y); // 1
61 #   do
62 #   {
63 #     if (1u != gid) // always false
64 #     {
65 #       data_out[1] = 1u;
66 #       return;
67 #     }
68 #   } while (false);
69 #
70 #   uint d;
71 #   while (true)
72 #   {
73 #     if (d != 0u)
74 #     {
75 #       data_out[1] = 2u;
76 #       for (int i = 0; i < 1; ++i)
77 #       {
78 #         data_out[1] = 3u;
79 #         return;
80 #       }
81 #     }
82 #     break;
83 #   }
84 #   data_out[gid] = 7u; // gid == 1
85 # }
86 SHADER compute variant_compute_shader SPIRV-ASM TARGET_ENV spv1.0
87 ; SPIR-V
88 ; Version: 1.0
89 ; Generator: Khronos Glslang Reference Front End; 7
90 ; Bound: 86
91 ; Schema: 0
92                OpCapability Shader
93           %1 = OpExtInstImport "GLSL.std.450"
94                OpMemoryModel Logical GLSL450
95                OpEntryPoint GLCompute %4 "main"
96                OpExecutionMode %4 LocalSize 100 1 1
97                OpSource ESSL 310
98                OpName %4 "main"
99                OpName %9 "theSSBO"
100                OpMemberName %9 0 "data_out"
101                OpName %11 ""
102                OpName %18 "gid"
103                OpName %21 "buf0"
104                OpMemberName %21 0 "injectionSwitch"
105                OpName %23 ""
106                OpName %48 "d"
107                OpName %57 "i"
108                OpDecorate %8 ArrayStride 4
109                OpMemberDecorate %9 0 Offset 0
110                OpDecorate %9 BufferBlock
111                OpDecorate %11 DescriptorSet 0
112                OpDecorate %11 Binding 0
113                OpMemberDecorate %21 0 Offset 0
114                OpDecorate %21 Block
115                OpDecorate %23 DescriptorSet 0
116                OpDecorate %23 Binding 1
117                OpDecorate %76 BuiltIn WorkgroupSize
118           %2 = OpTypeVoid
119           %3 = OpTypeFunction %2
120           %6 = OpTypeInt 32 0
121           %7 = OpConstant %6 5
122           %8 = OpTypeArray %6 %7
123           %9 = OpTypeStruct %8
124          %10 = OpTypePointer Uniform %9
125          %11 = OpVariable %10 Uniform
126          %12 = OpTypeInt 32 1
127          %13 = OpConstant %12 0
128          %14 = OpConstant %6 42
129          %15 = OpTypePointer Uniform %6
130          %17 = OpTypePointer Function %6
131          %19 = OpTypeFloat 32
132          %20 = OpTypeVector %19 2
133          %21 = OpTypeStruct %20
134          %22 = OpTypePointer Uniform %21
135          %23 = OpVariable %22 Uniform
136          %24 = OpConstant %6 1
137          %25 = OpTypePointer Uniform %19
138          %34 = OpTypeBool
139          %38 = OpConstant %12 1
140          %41 = OpConstantFalse %34
141          %47 = OpConstantTrue %34
142          %50 = OpConstant %6 0
143          %54 = OpConstant %6 2
144          %56 = OpTypePointer Function %12
145          %65 = OpConstant %6 3
146          %72 = OpConstant %6 7
147          %74 = OpTypeVector %6 3
148          %75 = OpConstant %6 100
149          %76 = OpConstantComposite %74 %75 %24 %24
150          %80 = OpUndef %6
151          %85 = OpUndef %12
152           %4 = OpFunction %2 None %3
153           %5 = OpLabel
154          %18 = OpVariable %17 Function
155          %48 = OpVariable %17 Function
156          %57 = OpVariable %56 Function
157          %16 = OpAccessChain %15 %11 %13 %13
158                OpStore %16 %14
159          %26 = OpAccessChain %25 %23 %13 %24
160          %27 = OpLoad %19 %26
161          %28 = OpConvertFToU %6 %27
162                OpStore %18 %28
163                OpBranch %29
164          %29 = OpLabel
165                OpLoopMerge %31 %32 None
166                OpBranch %30
167          %30 = OpLabel
168          %35 = OpINotEqual %34 %24 %28
169                OpSelectionMerge %37 None
170                OpBranchConditional %35 %36 %37
171          %36 = OpLabel
172          %39 = OpAccessChain %15 %11 %13 %38
173                OpStore %39 %24
174                OpReturn
175          %37 = OpLabel
176                OpBranch %32
177          %32 = OpLabel
178                OpBranchConditional %41 %29 %31
179          %31 = OpLabel
180                OpBranch %42
181          %42 = OpLabel
182                OpLoopMerge %44 %45 None
183                OpBranch %46
184          %46 = OpLabel
185                OpBranch %43
186          %43 = OpLabel
187          %51 = OpINotEqual %34 %80 %50
188                OpSelectionMerge %53 None
189                OpBranchConditional %51 %52 %53
190          %52 = OpLabel
191          %55 = OpAccessChain %15 %11 %13 %38
192                OpStore %55 %54
193                OpStore %57 %13
194                OpBranch %58
195          %58 = OpLabel
196                OpLoopMerge %60 %61 None
197                OpBranch %62
198          %62 = OpLabel
199          %64 = OpSLessThan %34 %13 %38
200                OpBranchConditional %64 %59 %60
201          %59 = OpLabel
202                OpStore %55 %65
203                OpReturn
204          %61 = OpLabel
205                OpBranch %58
206          %60 = OpLabel
207                OpBranch %53
208          %53 = OpLabel
209          %82 = OpPhi %6 %28 %43 %28 %60
210                OpBranch %44
211          %45 = OpLabel
212                OpBranch %42
213          %44 = OpLabel
214          %73 = OpAccessChain %15 %11 %13 %82
215                OpStore %73 %72
216                OpReturn
217                OpFunctionEnd
218 END
219
220 # uniforms for variant
221
222 # injectionSwitch
223 BUFFER variant_injectionSwitch DATA_TYPE vec2<float> DATA
224  0.0 1.0
225 END
226
227 BUFFER variant_ssbo DATA_TYPE uint32 DATA
228  0 0 0 0 0
229 END
230
231 PIPELINE compute variant_pipeline
232   ATTACH variant_compute_shader
233   BIND BUFFER variant_ssbo AS storage DESCRIPTOR_SET 0 BINDING 0
234   BIND BUFFER variant_injectionSwitch AS uniform DESCRIPTOR_SET 0 BINDING 1
235 END
236
237 RUN variant_pipeline 1 1 1
238
239 EXPECT variant_ssbo IDX 0 EQ 42