• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 nested switch-loop-switch
21
22# The test passes because the shader always writes red.
23
24SHADER vertex variant_vertex_shader PASSTHROUGH
25
26# variant_fragment_shader is derived from the following GLSL:
27# #version 310 es
28# precision highp float;
29#
30# layout(set = 0, binding = 0) uniform buf0
31# {
32#   vec2 injectionSwitch;
33# };
34#
35# layout(location = 0) out vec4 _GLF_color;
36#
37# void main()
38# {
39#   int i = int(injectionSwitch.x); // 0
40#
41#   switch (i) // 0
42#   {
43#   case 0:
44#     do
45#     {
46#       ++i;
47#       switch (i) // 1
48#       {
49#       case 1:
50#         continue; // Exit loop.
51#       case 2:
52#         i += 5;
53#         break;
54#       default:
55#         i += 7;
56#       }
57#     } while (i > 200); // Always false.
58#
59#     // Always false.
60#     if (i > 100)
61#     {
62#       i -= 2;
63#       break;
64#     }
65#
66#   default:
67#     // i == 1.
68#     i -= 3;
69#     // i == -2.
70#   }
71#
72#   // Always true.
73#   if (i == -2)
74#     _GLF_color = vec4(1.0, 0.0, 0.0, 1.0); // Red.
75#   else
76#     _GLF_color = vec4(0.0, 0.0, 0.0, 1.0);
77# }
78SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0
79; SPIR-V
80; Version: 1.0
81; Generator: Khronos Glslang Reference Front End; 8
82; Bound: 76
83; Schema: 0
84               OpCapability Shader
85          %1 = OpExtInstImport "GLSL.std.450"
86               OpMemoryModel Logical GLSL450
87               OpEntryPoint Fragment %4 "main" %70
88               OpExecutionMode %4 OriginUpperLeft
89               OpSource ESSL 310
90               OpName %4 "main"
91               OpName %8 "i"
92               OpName %11 "buf0"
93               OpMemberName %11 0 "injectionSwitch"
94               OpName %13 ""
95               OpName %70 "_GLF_color"
96               OpDecorate %8 RelaxedPrecision
97               OpMemberDecorate %11 0 Offset 0
98               OpDecorate %11 Block
99               OpDecorate %13 DescriptorSet 0
100               OpDecorate %13 Binding 0
101               OpDecorate %20 RelaxedPrecision
102               OpDecorate %21 RelaxedPrecision
103               OpDecorate %29 RelaxedPrecision
104               OpDecorate %31 RelaxedPrecision
105               OpDecorate %32 RelaxedPrecision
106               OpDecorate %39 RelaxedPrecision
107               OpDecorate %40 RelaxedPrecision
108               OpDecorate %43 RelaxedPrecision
109               OpDecorate %44 RelaxedPrecision
110               OpDecorate %46 RelaxedPrecision
111               OpDecorate %50 RelaxedPrecision
112               OpDecorate %56 RelaxedPrecision
113               OpDecorate %57 RelaxedPrecision
114               OpDecorate %60 RelaxedPrecision
115               OpDecorate %61 RelaxedPrecision
116               OpDecorate %63 RelaxedPrecision
117               OpDecorate %70 Location 0
118          %2 = OpTypeVoid
119          %3 = OpTypeFunction %2
120          %6 = OpTypeInt 32 1
121          %7 = OpTypePointer Function %6
122          %9 = OpTypeFloat 32
123         %10 = OpTypeVector %9 2
124         %11 = OpTypeStruct %10
125         %12 = OpTypePointer Uniform %11
126         %13 = OpVariable %12 Uniform
127         %14 = OpConstant %6 0
128         %15 = OpTypeInt 32 0
129         %16 = OpConstant %15 0
130         %17 = OpTypePointer Uniform %9
131         %30 = OpConstant %6 1
132         %38 = OpConstant %6 5
133         %42 = OpConstant %6 7
134         %47 = OpConstant %6 200
135         %48 = OpTypeBool
136         %51 = OpConstant %6 100
137         %55 = OpConstant %6 2
138         %59 = OpConstant %6 3
139         %64 = OpConstant %6 -2
140         %68 = OpTypeVector %9 4
141         %69 = OpTypePointer Output %68
142         %70 = OpVariable %69 Output
143         %71 = OpConstant %9 1
144         %72 = OpConstant %9 0
145         %73 = OpConstantComposite %68 %71 %72 %72 %71
146         %75 = OpConstantComposite %68 %72 %72 %72 %71
147          %4 = OpFunction %2 None %3
148          %5 = OpLabel
149          %8 = OpVariable %7 Function
150         %18 = OpAccessChain %17 %13 %14 %16
151         %19 = OpLoad %9 %18
152         %20 = OpConvertFToS %6 %19
153               OpStore %8 %20
154         %21 = OpLoad %6 %8
155               OpSelectionMerge %24 None
156               OpSwitch %21 %23 0 %22
157         %23 = OpLabel
158         %60 = OpLoad %6 %8
159         %61 = OpISub %6 %60 %59
160               OpStore %8 %61
161               OpBranch %24
162         %22 = OpLabel
163               OpBranch %25
164         %25 = OpLabel
165               OpLoopMerge %27 %28 None
166               OpBranch %26
167         %26 = OpLabel
168         %29 = OpLoad %6 %8
169         %31 = OpIAdd %6 %29 %30
170               OpStore %8 %31
171         %32 = OpLoad %6 %8
172               OpSelectionMerge %36 None
173               OpSwitch %32 %35 1 %33 2 %34
174         %35 = OpLabel
175         %43 = OpLoad %6 %8
176         %44 = OpIAdd %6 %43 %42
177               OpStore %8 %44
178               OpBranch %36
179         %33 = OpLabel
180               OpBranch %28
181         %34 = OpLabel
182         %39 = OpLoad %6 %8
183         %40 = OpIAdd %6 %39 %38
184               OpStore %8 %40
185               OpBranch %36
186         %36 = OpLabel
187               OpBranch %28
188         %28 = OpLabel
189         %46 = OpLoad %6 %8
190         %49 = OpSGreaterThan %48 %46 %47
191               OpBranchConditional %49 %25 %27
192         %27 = OpLabel
193         %50 = OpLoad %6 %8
194         %52 = OpSGreaterThan %48 %50 %51
195               OpSelectionMerge %54 None
196               OpBranchConditional %52 %53 %54
197         %53 = OpLabel
198         %56 = OpLoad %6 %8
199         %57 = OpISub %6 %56 %55
200               OpStore %8 %57
201               OpBranch %24
202         %54 = OpLabel
203               OpBranch %23
204         %24 = OpLabel
205         %63 = OpLoad %6 %8
206         %65 = OpIEqual %48 %63 %64
207               OpSelectionMerge %67 None
208               OpBranchConditional %65 %66 %74
209         %66 = OpLabel
210               OpStore %70 %73
211               OpBranch %67
212         %74 = OpLabel
213               OpStore %70 %75
214               OpBranch %67
215         %67 = OpLabel
216               OpReturn
217               OpFunctionEnd
218END
219
220# uniforms for variant
221
222# injectionSwitch
223BUFFER variant_injectionSwitch DATA_TYPE vec2<float> DATA
224 0.0 1.0
225END
226
227BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM
228
229PIPELINE graphics variant_pipeline
230  ATTACH variant_vertex_shader
231  ATTACH variant_fragment_shader
232  FRAMEBUFFER_SIZE 256 256
233  BIND BUFFER variant_framebuffer AS color LOCATION 0
234  BIND BUFFER variant_injectionSwitch AS uniform DESCRIPTOR_SET 0 BINDING 0
235END
236CLEAR_COLOR variant_pipeline 0 0 0 255
237
238CLEAR variant_pipeline
239RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 256 256
240
241EXPECT variant_framebuffer IDX 0 0 SIZE 256 256 EQ_RGBA 255 0 0 255
242