3 # Copyright 2020 Google LLC
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
9 # http://www.apache.org/licenses/LICENSE-2.0
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.
18 # A test for a bug found by GraphicsFuzz.
20 # Short description: A nested switch-loop-switch
22 # The test passes because the shader always writes red.
24 SHADER vertex variant_vertex_shader PASSTHROUGH
26 # variant_fragment_shader is derived from the following GLSL:
28 # precision highp float;
30 # layout(set = 0, binding = 0) uniform buf0
32 # vec2 injectionSwitch;
35 # layout(location = 0) out vec4 _GLF_color;
39 # int i = int(injectionSwitch.x); // 0
50 # continue; // Exit loop.
57 # } while (i > 200); // Always false.
74 # _GLF_color = vec4(1.0, 0.0, 0.0, 1.0); // Red.
76 # _GLF_color = vec4(0.0, 0.0, 0.0, 1.0);
78 SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0
81 ; Generator: Khronos Glslang Reference Front End; 8
85 %1 = OpExtInstImport "GLSL.std.450"
86 OpMemoryModel Logical GLSL450
87 OpEntryPoint Fragment %4 "main" %70
88 OpExecutionMode %4 OriginUpperLeft
93 OpMemberName %11 0 "injectionSwitch"
95 OpName %70 "_GLF_color"
96 OpDecorate %8 RelaxedPrecision
97 OpMemberDecorate %11 0 Offset 0
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
119 %3 = OpTypeFunction %2
121 %7 = OpTypePointer Function %6
123 %10 = OpTypeVector %9 2
124 %11 = OpTypeStruct %10
125 %12 = OpTypePointer Uniform %11
126 %13 = OpVariable %12 Uniform
127 %14 = OpConstant %6 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
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
149 %8 = OpVariable %7 Function
150 %18 = OpAccessChain %17 %13 %14 %16
152 %20 = OpConvertFToS %6 %19
155 OpSelectionMerge %24 None
156 OpSwitch %21 %23 0 %22
159 %61 = OpISub %6 %60 %59
165 OpLoopMerge %27 %28 None
169 %31 = OpIAdd %6 %29 %30
172 OpSelectionMerge %36 None
173 OpSwitch %32 %35 1 %33 2 %34
176 %44 = OpIAdd %6 %43 %42
183 %40 = OpIAdd %6 %39 %38
190 %49 = OpSGreaterThan %48 %46 %47
191 OpBranchConditional %49 %25 %27
194 %52 = OpSGreaterThan %48 %50 %51
195 OpSelectionMerge %54 None
196 OpBranchConditional %52 %53 %54
199 %57 = OpISub %6 %56 %55
206 %65 = OpIEqual %48 %63 %64
207 OpSelectionMerge %67 None
208 OpBranchConditional %65 %66 %74
220 # uniforms for variant
223 BUFFER variant_injectionSwitch DATA_TYPE vec2<float> DATA
227 BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM
229 PIPELINE 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
236 CLEAR_COLOR variant_pipeline 0 0 0 255
238 CLEAR variant_pipeline
239 RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 256 256
241 EXPECT variant_framebuffer IDX 0 0 SIZE 256 256 EQ_RGBA 255 0 0 255