3 # Copyright 2019 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 shader with a switch statement containing unreachable discards
22 # The test passes because the shader always writes the color red.
24 # Optimized using spirv-opt with the following arguments:
26 # spirv-opt commit hash: 6b072126595dd8c2448eb1fda616251c5e6d7079
30 SHADER vertex variant_vertex_shader PASSTHROUGH
32 # variant_fragment_shader is derived from the following GLSL:
34 # precision highp float;
36 # layout(location = 0) out vec4 _GLF_color;
38 # layout(set = 0, binding = 0) uniform buf0 {
39 # vec2 injectionSwitch;
41 # vec3 drawShape(vec2 square)
43 # switch(int(injectionSwitch.x))
46 # return vec3(1.0, 0.0, 0.0);
66 # vec3 color = vec3(0.0);
73 # color = drawShape(center);
74 # if(length(color) <= 0.0)
79 # _GLF_color = vec4(color, 1.0);
81 SHADER fragment variant_fragment_shader SPIRV-ASM
84 ; Generator: Khronos Glslang Reference Front End; 7
88 %1 = OpExtInstImport "GLSL.std.450"
89 OpMemoryModel Logical GLSL450
90 OpEntryPoint Fragment %4 "main" %78
91 OpExecutionMode %4 OriginUpperLeft
95 OpMemberName %14 0 "injectionSwitch"
97 OpName %78 "_GLF_color"
98 OpMemberDecorate %14 0 Offset 0
100 OpDecorate %16 DescriptorSet 0
101 OpDecorate %16 Binding 0
102 OpDecorate %75 RelaxedPrecision
103 OpDecorate %78 Location 0
104 OpDecorate %132 RelaxedPrecision
105 OpDecorate %132 RelaxedPrecision
106 OpDecorate %132 RelaxedPrecision
108 %3 = OpTypeFunction %2
110 %7 = OpTypeVector %6 2
111 %9 = OpTypeVector %6 3
112 %14 = OpTypeStruct %7
113 %15 = OpTypePointer Uniform %14
114 %16 = OpVariable %15 Uniform
116 %18 = OpConstant %17 0
118 %20 = OpConstant %19 0
119 %21 = OpTypePointer Uniform %6
120 %28 = OpConstant %6 1
121 %29 = OpConstant %6 0
122 %30 = OpConstantComposite %9 %28 %29 %29
124 %48 = OpConstantComposite %9 %28 %28 %28
125 %53 = OpConstantComposite %9 %29 %29 %29
126 %62 = OpConstant %17 1
127 %76 = OpTypeVector %6 4
128 %77 = OpTypePointer Output %76
129 %78 = OpVariable %77 Output
131 %4 = OpFunction %2 None %3
135 %133 = OpPhi %9 %53 %5 %137 %59
136 %132 = OpPhi %17 %18 %5 %75 %59
137 %63 = OpSLessThan %39 %132 %62
138 OpLoopMerge %58 %59 None
139 OpBranchConditional %63 %57 %58
143 OpLoopMerge %105 %106 None
146 %108 = OpAccessChain %21 %16 %18 %20
147 %109 = OpLoad %6 %108
148 %110 = OpConvertFToS %17 %109
149 OpSelectionMerge %111 None
150 OpSwitch %110 %111 0 %112 67 %113
154 OpLoopMerge %115 %116 None
157 %119 = OpCompositeExtract %6 %135 0
158 %120 = OpFOrdLessThan %39 %28 %119
159 OpSelectionMerge %122 None
160 OpBranchConditional %120 %122 %123
162 %124 = OpFunctionCall %2 %84
166 %126 = OpFunctionCall %2 %84
172 %138 = OpPhi %9 %125 %123 %127 %122
181 %137 = OpPhi %9 %138 %115 %30 %112 %48 %111
182 %69 = OpExtInst %6 %1 Length %137
183 %70 = OpFOrdLessThanEqual %39 %69 %29
184 OpSelectionMerge %72 None
185 OpBranchConditional %70 %71 %72
191 %75 = OpIAdd %17 %132 %62
194 %80 = OpCompositeExtract %6 %133 0
195 %81 = OpCompositeExtract %6 %133 1
196 %82 = OpCompositeExtract %6 %133 2
197 %83 = OpCompositeConstruct %76 %80 %81 %82 %28
201 %84 = OpFunction %2 None %3
207 # uniforms for variant
210 BUFFER variant_injectionSwitch DATA_TYPE vec2<float> DATA
214 BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM
216 PIPELINE graphics variant_pipeline
217 ATTACH variant_vertex_shader
218 ATTACH variant_fragment_shader
219 FRAMEBUFFER_SIZE 256 256
220 BIND BUFFER variant_framebuffer AS color LOCATION 0
221 BIND BUFFER variant_injectionSwitch AS uniform DESCRIPTOR_SET 0 BINDING 0
223 CLEAR_COLOR variant_pipeline 0 0 0 255
225 CLEAR variant_pipeline
226 RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 256 256
228 EXPECT variant_framebuffer IDX 0 0 SIZE 256 256 EQ_RGBA 255 0 0 255