Fix missing dependency on sparse binds
[platform/upstream/VK-GL-CTS.git] / external / vulkancts / data / vulkan / amber / graphicsfuzz / switch-with-fall-through-cases.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 with switch cases that fall through
21
22 # The test passes because shader always writes red.
23
24 # Optimized using spirv-opt with the following arguments:
25 # '--ccp'
26 # '--eliminate-local-single-block'
27 # '--combine-access-chains'
28 # '--copy-propagate-arrays'
29 # '--eliminate-local-single-store'
30 # '--eliminate-local-multi-store'
31 # '--eliminate-local-single-block'
32 # '--private-to-local'
33 # spirv-opt commit hash: ab7ac60f14ae66006bed5c989a2cfd4c4881704c
34
35
36
37 SHADER vertex variant_vertex_shader PASSTHROUGH
38
39 # variant_fragment_shader is derived from the following GLSL:
40 # #version 310 es
41 # precision highp float;
42 # precision highp int;
43 #
44 # layout(location = 0) out vec4 _GLF_color;
45 #
46 # layout(set = 0, binding = 0) uniform buf0 {
47 #  vec2 injectionSwitch;
48 # };
49 #
50 # void main()
51 # {
52 #     for(int i = 0; i < 2 + int(injectionSwitch.x); i++)
53 #     {
54 #         int value = i;
55 #         float y = 0.5;
56 #
57 #         switch(value)
58 #         {
59 #             case 0:
60 #                 y += 0.5;
61 #             // Always falls through.
62 #             case 1:
63 #                 y = clamp(1.0, 0.5, y);
64 #             // Always falls through.
65 #             case 2:
66 #             default:
67 #             // Always ends up here.
68 #                 // Always true.
69 #                 if (y == 1.0)
70 #                 {
71 #                     _GLF_color = vec4(value + 1, 0, 0, 1);
72 #                     return;
73 #                 }
74 #         }
75 #     }
76 # }
77 SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0
78 ; SPIR-V
79 ; Version: 1.0
80 ; Generator: Khronos Glslang Reference Front End; 8
81 ; Bound: 66
82 ; Schema: 0
83                OpCapability Shader
84           %1 = OpExtInstImport "GLSL.std.450"
85                OpMemoryModel Logical GLSL450
86                OpEntryPoint Fragment %4 "main" %52
87                OpExecutionMode %4 OriginUpperLeft
88                OpSource ESSL 310
89                OpName %4 "main"
90                OpName %8 "i"
91                OpName %19 "buf0"
92                OpMemberName %19 0 "injectionSwitch"
93                OpName %21 ""
94                OpName %31 "value"
95                OpName %34 "y"
96                OpName %52 "_GLF_color"
97                OpMemberDecorate %19 0 Offset 0
98                OpDecorate %19 Block
99                OpDecorate %21 DescriptorSet 0
100                OpDecorate %21 Binding 0
101                OpDecorate %52 Location 0
102           %2 = OpTypeVoid
103           %3 = OpTypeFunction %2
104           %6 = OpTypeInt 32 1
105           %7 = OpTypePointer Function %6
106           %9 = OpConstant %6 0
107          %16 = OpConstant %6 2
108          %17 = OpTypeFloat 32
109          %18 = OpTypeVector %17 2
110          %19 = OpTypeStruct %18
111          %20 = OpTypePointer Uniform %19
112          %21 = OpVariable %20 Uniform
113          %22 = OpTypeInt 32 0
114          %23 = OpConstant %22 0
115          %24 = OpTypePointer Uniform %17
116          %29 = OpTypeBool
117          %33 = OpTypePointer Function %17
118          %35 = OpConstant %17 0.5
119          %43 = OpConstant %17 1
120          %50 = OpTypeVector %17 4
121          %51 = OpTypePointer Output %50
122          %52 = OpVariable %51 Output
123          %54 = OpConstant %6 1
124          %57 = OpConstant %17 0
125           %4 = OpFunction %2 None %3
126           %5 = OpLabel
127           %8 = OpVariable %7 Function
128          %31 = OpVariable %7 Function
129          %34 = OpVariable %33 Function
130                OpStore %8 %9
131                OpBranch %10
132          %10 = OpLabel
133          %63 = OpPhi %6 %9 %5 %62 %13
134                OpLoopMerge %12 %13 None
135                OpBranch %14
136          %14 = OpLabel
137          %25 = OpAccessChain %24 %21 %9 %23
138          %26 = OpLoad %17 %25
139          %27 = OpConvertFToS %6 %26
140          %28 = OpIAdd %6 %16 %27
141          %30 = OpSLessThan %29 %63 %28
142                OpBranchConditional %30 %11 %12
143          %11 = OpLabel
144                OpStore %31 %63
145                OpStore %34 %35
146                OpSelectionMerge %40 None
147                OpSwitch %63 %39 0 %37 1 %38 2 %39
148          %39 = OpLabel
149          %65 = OpPhi %17 %35 %11 %45 %38
150          %47 = OpFOrdEqual %29 %65 %43
151                OpSelectionMerge %49 None
152                OpBranchConditional %47 %48 %49
153          %48 = OpLabel
154          %55 = OpIAdd %6 %63 %54
155          %56 = OpConvertSToF %17 %55
156          %58 = OpCompositeConstruct %50 %56 %57 %57 %43
157                OpStore %52 %58
158                OpReturn
159          %49 = OpLabel
160                OpBranch %40
161          %37 = OpLabel
162          %42 = OpFAdd %17 %35 %35
163                OpStore %34 %42
164                OpBranch %38
165          %38 = OpLabel
166          %64 = OpPhi %17 %35 %11 %42 %37
167          %45 = OpExtInst %17 %1 FClamp %43 %35 %64
168                OpStore %34 %45
169                OpBranch %39
170          %40 = OpLabel
171                OpBranch %13
172          %13 = OpLabel
173          %62 = OpIAdd %6 %63 %54
174                OpStore %8 %62
175                OpBranch %10
176          %12 = OpLabel
177                OpReturn
178                OpFunctionEnd
179 END
180
181 # uniforms for variant
182
183 # injectionSwitch
184 BUFFER variant_injectionSwitch DATA_TYPE vec2<float> DATA
185  0.0 1.0
186 END
187
188 BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM
189
190 PIPELINE graphics variant_pipeline
191   ATTACH variant_vertex_shader
192   ATTACH variant_fragment_shader
193   FRAMEBUFFER_SIZE 256 256
194   BIND BUFFER variant_framebuffer AS color LOCATION 0
195   BIND BUFFER variant_injectionSwitch AS uniform DESCRIPTOR_SET 0 BINDING 0
196 END
197 CLEAR_COLOR variant_pipeline 0 0 0 255
198
199 CLEAR variant_pipeline
200 RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 256 256
201
202 EXPECT variant_framebuffer IDX 0 0 SIZE 256 256 EQ_RGBA 255 0 0 255