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 fragment shader with switch cases that fall through
22 # The test passes because shader always writes red.
24 # Optimized using spirv-opt with the following arguments:
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
37 SHADER vertex variant_vertex_shader PASSTHROUGH
39 # variant_fragment_shader is derived from the following GLSL:
41 # precision highp float;
42 # precision highp int;
44 # layout(location = 0) out vec4 _GLF_color;
46 # layout(set = 0, binding = 0) uniform buf0 {
47 # vec2 injectionSwitch;
52 # for(int i = 0; i < 2 + int(injectionSwitch.x); i++)
61 # // Always falls through.
63 # y = clamp(1.0, 0.5, y);
64 # // Always falls through.
67 # // Always ends up here.
71 # _GLF_color = vec4(value + 1, 0, 0, 1);
77 SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0
80 ; Generator: Khronos Glslang Reference Front End; 8
84 %1 = OpExtInstImport "GLSL.std.450"
85 OpMemoryModel Logical GLSL450
86 OpEntryPoint Fragment %4 "main" %52
87 OpExecutionMode %4 OriginUpperLeft
92 OpMemberName %19 0 "injectionSwitch"
96 OpName %52 "_GLF_color"
97 OpMemberDecorate %19 0 Offset 0
99 OpDecorate %21 DescriptorSet 0
100 OpDecorate %21 Binding 0
101 OpDecorate %52 Location 0
103 %3 = OpTypeFunction %2
105 %7 = OpTypePointer Function %6
107 %16 = OpConstant %6 2
109 %18 = OpTypeVector %17 2
110 %19 = OpTypeStruct %18
111 %20 = OpTypePointer Uniform %19
112 %21 = OpVariable %20 Uniform
114 %23 = OpConstant %22 0
115 %24 = OpTypePointer Uniform %17
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
127 %8 = OpVariable %7 Function
128 %31 = OpVariable %7 Function
129 %34 = OpVariable %33 Function
133 %63 = OpPhi %6 %9 %5 %62 %13
134 OpLoopMerge %12 %13 None
137 %25 = OpAccessChain %24 %21 %9 %23
139 %27 = OpConvertFToS %6 %26
140 %28 = OpIAdd %6 %16 %27
141 %30 = OpSLessThan %29 %63 %28
142 OpBranchConditional %30 %11 %12
146 OpSelectionMerge %40 None
147 OpSwitch %63 %39 0 %37 1 %38 2 %39
149 %65 = OpPhi %17 %35 %11 %45 %38
150 %47 = OpFOrdEqual %29 %65 %43
151 OpSelectionMerge %49 None
152 OpBranchConditional %47 %48 %49
154 %55 = OpIAdd %6 %63 %54
155 %56 = OpConvertSToF %17 %55
156 %58 = OpCompositeConstruct %50 %56 %57 %57 %43
162 %42 = OpFAdd %17 %35 %35
166 %64 = OpPhi %17 %35 %11 %42 %37
167 %45 = OpExtInst %17 %1 FClamp %43 %35 %64
173 %62 = OpIAdd %6 %63 %54
181 # uniforms for variant
184 BUFFER variant_injectionSwitch DATA_TYPE vec2<float> DATA
188 BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM
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
197 CLEAR_COLOR variant_pipeline 0 0 0 255
199 CLEAR variant_pipeline
200 RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 256 256
202 EXPECT variant_framebuffer IDX 0 0 SIZE 256 256 EQ_RGBA 255 0 0 255