3 # Copyright 2018 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.
17 # A test for a bug found by GraphicsFuzz.
19 # A fragment shader with somewhat complex control flow and a switch.
20 # Derived from the following GLSL fragment shader.
21 # We check that all pixels are red. The test passes because the final
22 # statement writes red to _GLF_color and there are no discard statements.
26 # precision highp float;
27 # precision highp int;
29 # layout(set = 0, binding = 0) uniform buf0 {
30 # vec2 injectionSwitch;
32 # layout(location=0) out vec4 _GLF_color;
46 # switch(int(injectionSwitch.x))
49 # S a = S(bool(injectionSwitch.x));
65 # S a = S(bool(injectionSwitch.x));
79 # _GLF_color = vec4(f(), 1.0);
80 # // always true at runtime
81 # if (injectionSwitch.x == 0.0) {
82 # _GLF_color = vec4(1.0, 0.0, 0.0, 1.0);
86 SHADER vertex variant_vertex_shader PASSTHROUGH
88 SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0
91 ; Generator: Khronos SPIR-V Tools Assembler; 0
95 %1 = OpExtInstImport "GLSL.std.450"
96 OpMemoryModel Logical GLSL450
97 OpEntryPoint Fragment %2 "main" %3
98 OpExecutionMode %2 OriginUpperLeft
102 OpMemberName %4 0 "injectionSwitch"
104 OpName %3 "_GLF_color"
105 OpMemberDecorate %4 0 Offset 0
107 OpDecorate %5 DescriptorSet 0
108 OpDecorate %5 Binding 0
109 OpDecorate %3 Location 0
111 %7 = OpTypeFunction %6
114 %10 = OpTypeVector %9 3
116 %12 = OpConstant %11 0
117 %13 = OpConstant %11 1
118 %14 = OpTypeVector %9 2
119 %4 = OpTypeStruct %14
120 %15 = OpTypePointer Uniform %4
121 %5 = OpVariable %15 Uniform
123 %17 = OpConstant %16 0
124 %18 = OpTypePointer Uniform %9
125 %19 = OpConstant %9 0
126 %20 = OpConstantTrue %8
127 %21 = OpConstantComposite %10 %19 %19 %19
128 %22 = OpConstant %9 1
129 %23 = OpConstantComposite %10 %22 %22 %22
130 %24 = OpTypeVector %9 4
131 %25 = OpTypePointer Output %24
132 %3 = OpVariable %25 Output
133 %26 = OpConstantComposite %24 %22 %19 %19 %22
134 %27 = OpConstantFalse %8
136 %2 = OpFunction %6 None %7
140 OpLoopMerge %31 %32 None
143 %34 = OpAccessChain %18 %5 %12 %17
145 %36 = OpFOrdNotEqual %8 %35 %19
146 OpSelectionMerge %37 None
147 OpBranchConditional %36 %38 %37
153 OpLoopMerge %40 %41 None
156 %43 = OpPhi %8 %28 %39 %44 %72
157 %46 = OpPhi %11 %12 %39 %47 %72
158 %48 = OpSLessThan %8 %46 %13
159 OpLoopMerge %49 %72 None
160 OpBranchConditional %48 %50 %49
162 %51 = OpConvertFToS %11 %35
163 OpSelectionMerge %52 None
164 OpSwitch %51 %45 9 %53 42 %54
168 %44 = OpPhi %8 %43 %50 %55 %56
169 %47 = OpIAdd %11 %46 %13
176 %55 = OpPhi %8 %43 %50 %36 %53
177 OpSelectionMerge %56 None
178 OpBranchConditional %55 %57 %56
184 %58 = OpPhi %8 %28 %42 %20 %57
185 %59 = OpPhi %8 %27 %42 %20 %57
186 OpSelectionMerge %60 None
187 OpBranchConditional %59 %40 %60
193 %61 = OpPhi %8 %58 %49 %20 %60
194 OpSelectionMerge %62 None
195 OpBranchConditional %61 %63 %62
203 %64 = OpPhi %10 %21 %38 %23 %63 %23 %62
204 %65 = OpCompositeExtract %9 %64 0
205 %66 = OpCompositeExtract %9 %64 1
206 %67 = OpCompositeExtract %9 %64 2
207 %68 = OpCompositeConstruct %24 %65 %66 %67 %22
209 %69 = OpFOrdEqual %8 %35 %19
210 OpSelectionMerge %70 None
211 OpBranchConditional %69 %71 %70
221 # uniforms for variant
224 BUFFER variant_injectionSwitch DATA_TYPE vec2<float> DATA
228 BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM
230 PIPELINE graphics variant_pipeline
231 ATTACH variant_vertex_shader
232 ATTACH variant_fragment_shader
233 FRAMEBUFFER_SIZE 256 256
234 BIND BUFFER variant_framebuffer AS color LOCATION 0
235 BIND BUFFER variant_injectionSwitch AS uniform DESCRIPTOR_SET 0 BINDING 0
237 CLEAR_COLOR variant_pipeline 0 0 0 255
239 CLEAR variant_pipeline
240 RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 256 256
242 EXPECT variant_framebuffer IDX 0 0 SIZE 256 256 EQ_RGBA 255 0 0 255