Fix missing dependency on sparse binds
[platform/upstream/VK-GL-CTS.git] / external / vulkancts / data / vulkan / amber / graphicsfuzz / two-nested-for-loops-with-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 two nested for loops
21
22 # The test passes because main always outputs 42.0.
23
24 # Optimized using spirv-opt with the following arguments:
25 # '--private-to-local'
26 # '--eliminate-local-multi-store'
27 # '--simplify-instructions'
28 # '--eliminate-dead-inserts'
29 # '--eliminate-dead-branches'
30 # spirv-opt commit hash: 4a00a80c40484a6f6f72f48c9d34943cf8f180d4
31
32
33
34 # variant_compute_shader is derived from the following GLSL:
35 # #version 310 es
36 #
37 # precision highp float;
38 #
39 # layout(std430, binding = 0) buffer doesNotMatter
40 # {
41 #     float _compute_data[];
42 # };
43 #
44 # float nb_mod()
45 # {
46 #     float s = 0.0;
47 #
48 #     // Loop is entered, but we always return 42.0 during the first iteration.
49 #     for (
50 #         int i = 5;
51 #         i < 800;
52 #         i++)
53 #     {
54 #         int GLF_live1_looplimiter2;
55 #
56 #         // Loop is entered and we possibly return.
57 #         for (
58 #             int GLF_live1i = 0;
59 #             GLF_live1i < 20;
60 #             ++GLF_live1i)
61 #         {
62 #             // GLF_live1_looplimiter2 is undefined, so we may break; doesn't matter.
63 #             if (GLF_live1_looplimiter2 >= 5)
64 #             {
65 #                 ++s;
66 #                 break;
67 #             }
68 #             // If we didn't break, we return 42.0 here.
69 #             return 42.0;
70 #         }
71 #
72 #         if (float(i) <= s) // Always false: s is 0.0 or 1.0.
73 #         {
74 #             break;
75 #         }
76 #         // We return 42.0 and we don't loop.
77 #         return 42.0;
78 #     }
79 #     // Unreachable at runtime.
80 #     return s;
81 # }
82 #
83 # void main()
84 # {
85 #     _compute_data[0] = nb_mod(); // Always returns 42.0.
86 # }
87 SHADER compute variant_compute_shader SPIRV-ASM TARGET_ENV spv1.0
88 ; SPIR-V
89 ; Version: 1.0
90 ; Generator: Khronos Glslang Reference Front End; 7
91 ; Bound: 82
92 ; Schema: 0
93                OpCapability Shader
94           %1 = OpExtInstImport "GLSL.std.450"
95                OpMemoryModel Logical GLSL450
96                OpEntryPoint GLCompute %4 "main"
97                OpExecutionMode %4 LocalSize 1 1 1
98                OpSource ESSL 310
99                OpName %4 "main"
100                OpName %8 "nb_mod("
101                OpName %11 "s"
102                OpName %15 "i"
103                OpName %26 "GLF_live1i"
104                OpName %36 "GLF_live1_looplimiter2"
105                OpName %64 "doesNotMatter"
106                OpMemberName %64 0 "_compute_data"
107                OpName %66 ""
108                OpDecorate %63 ArrayStride 4
109                OpMemberDecorate %64 0 Offset 0
110                OpDecorate %64 BufferBlock
111                OpDecorate %66 DescriptorSet 0
112                OpDecorate %66 Binding 0
113           %2 = OpTypeVoid
114           %3 = OpTypeFunction %2
115           %6 = OpTypeFloat 32
116           %7 = OpTypeFunction %6
117          %10 = OpTypePointer Function %6
118          %12 = OpConstant %6 0
119          %13 = OpTypeInt 32 1
120          %14 = OpTypePointer Function %13
121          %16 = OpConstant %13 5
122          %23 = OpConstant %13 800
123          %24 = OpTypeBool
124          %27 = OpConstant %13 0
125          %34 = OpConstant %13 20
126          %42 = OpConstant %6 1
127          %45 = OpConstant %6 42
128          %48 = OpConstant %13 1
129          %63 = OpTypeRuntimeArray %6
130          %64 = OpTypeStruct %63
131          %65 = OpTypePointer Uniform %64
132          %66 = OpVariable %65 Uniform
133          %68 = OpTypePointer Uniform %6
134          %74 = OpUndef %13
135          %81 = OpUndef %6
136           %4 = OpFunction %2 None %3
137           %5 = OpLabel
138          %67 = OpFunctionCall %6 %8
139          %69 = OpAccessChain %68 %66 %27 %27
140                OpStore %69 %67
141                OpReturn
142                OpFunctionEnd
143           %8 = OpFunction %6 None %7
144           %9 = OpLabel
145          %11 = OpVariable %10 Function
146          %15 = OpVariable %14 Function
147          %26 = OpVariable %14 Function
148          %36 = OpVariable %14 Function
149                OpStore %11 %12
150                OpStore %15 %16
151                OpBranch %17
152          %17 = OpLabel
153                OpLoopMerge %19 %20 None
154                OpBranch %21
155          %21 = OpLabel
156          %25 = OpSLessThan %24 %16 %23
157                OpBranchConditional %25 %18 %19
158          %18 = OpLabel
159                OpStore %26 %27
160                OpBranch %28
161          %28 = OpLabel
162                OpLoopMerge %30 %31 None
163                OpBranch %32
164          %32 = OpLabel
165          %35 = OpSLessThan %24 %27 %34
166                OpBranchConditional %35 %29 %30
167          %29 = OpLabel
168          %38 = OpSGreaterThanEqual %24 %74 %16
169                OpSelectionMerge %40 None
170                OpBranchConditional %38 %39 %40
171          %39 = OpLabel
172          %43 = OpFAdd %6 %12 %42
173                OpStore %11 %43
174                OpBranch %30
175          %40 = OpLabel
176                OpReturnValue %45
177          %31 = OpLabel
178                OpBranch %28
179          %30 = OpLabel
180          %79 = OpPhi %6 %12 %32 %43 %39
181          %51 = OpConvertSToF %6 %16
182          %53 = OpFOrdLessThanEqual %24 %51 %79
183                OpSelectionMerge %55 None
184                OpBranchConditional %53 %54 %55
185          %54 = OpLabel
186                OpBranch %19
187          %55 = OpLabel
188                OpReturnValue %45
189          %20 = OpLabel
190                OpBranch %17
191          %19 = OpLabel
192          %80 = OpPhi %6 %12 %21 %79 %54
193                OpReturnValue %80
194                OpFunctionEnd
195 END
196
197 # uniforms for variant
198
199
200 BUFFER variant_ssbo DATA_TYPE float DATA
201  0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
202 END
203
204 PIPELINE compute variant_pipeline
205   ATTACH variant_compute_shader
206   BIND BUFFER variant_ssbo AS storage DESCRIPTOR_SET 0 BINDING 0
207 END
208
209 RUN variant_pipeline 7 3 4
210
211 EXPECT variant_ssbo IDX 0 EQ 42.0