1#!amber 2 3# Copyright 2018 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# A test for a bug found by GraphicsFuzz. 18 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. 23 24# #version 310 es 25# 26# precision highp float; 27# precision highp int; 28# 29# layout(set = 0, binding = 0) uniform buf0 { 30# vec2 injectionSwitch; 31# }; 32# layout(location=0) out vec4 _GLF_color; 33# 34# struct S { 35# bool ok; 36# }; 37# 38# bool g() 39# { 40# for( 41# int i = 0; 42# i < 1; 43# i++ 44# ) 45# { 46# switch(int(injectionSwitch.x)) 47# { 48# case 9: 49# S a = S(bool(injectionSwitch.x)); 50# S b = a; 51# case 42: 52# if(b.ok) 53# { 54# return true; 55# } 56# default: 57# break; 58# } 59# } 60# return true; 61# } 62# vec3 f() 63# { 64# { 65# S a = S(bool(injectionSwitch.x)); 66# if(a.ok) 67# { 68# return vec3(0.0); 69# } 70# if(g()) 71# { 72# return vec3(1.0); 73# } 74# } 75# return vec3(1.0); 76# } 77# void main() 78# { 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); 83# } 84# } 85 86SHADER vertex variant_vertex_shader PASSTHROUGH 87 88SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0 89; SPIR-V 90; Version: 1.0 91; Generator: Khronos SPIR-V Tools Assembler; 0 92; Bound: 73 93; Schema: 0 94 OpCapability Shader 95 %1 = OpExtInstImport "GLSL.std.450" 96 OpMemoryModel Logical GLSL450 97 OpEntryPoint Fragment %2 "main" %3 98 OpExecutionMode %2 OriginUpperLeft 99 OpSource ESSL 310 100 OpName %2 "main" 101 OpName %4 "buf0" 102 OpMemberName %4 0 "injectionSwitch" 103 OpName %5 "" 104 OpName %3 "_GLF_color" 105 OpMemberDecorate %4 0 Offset 0 106 OpDecorate %4 Block 107 OpDecorate %5 DescriptorSet 0 108 OpDecorate %5 Binding 0 109 OpDecorate %3 Location 0 110 %6 = OpTypeVoid 111 %7 = OpTypeFunction %6 112 %8 = OpTypeBool 113 %9 = OpTypeFloat 32 114 %10 = OpTypeVector %9 3 115 %11 = OpTypeInt 32 1 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 122 %16 = OpTypeInt 32 0 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 135 %28 = OpUndef %8 136 %2 = OpFunction %6 None %7 137 %29 = OpLabel 138 OpBranch %30 139 %30 = OpLabel 140 OpLoopMerge %31 %32 None 141 OpBranch %33 142 %33 = OpLabel 143 %34 = OpAccessChain %18 %5 %12 %17 144 %35 = OpLoad %9 %34 145 %36 = OpFOrdNotEqual %8 %35 %19 146 OpSelectionMerge %37 None 147 OpBranchConditional %36 %38 %37 148 %38 = OpLabel 149 OpBranch %31 150 %37 = OpLabel 151 OpBranch %39 152 %39 = OpLabel 153 OpLoopMerge %40 %41 None 154 OpBranch %42 155 %42 = OpLabel 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 161 %50 = OpLabel 162 %51 = OpConvertFToS %11 %35 163 OpSelectionMerge %52 None 164 OpSwitch %51 %45 9 %53 42 %54 165 %52 = OpLabel 166 OpBranch %72 167 %45 = OpLabel 168 %44 = OpPhi %8 %43 %50 %55 %56 169 %47 = OpIAdd %11 %46 %13 170 OpBranch %72 171 %72 = OpLabel 172 OpBranch %42 173 %53 = OpLabel 174 OpBranch %54 175 %54 = OpLabel 176 %55 = OpPhi %8 %43 %50 %36 %53 177 OpSelectionMerge %56 None 178 OpBranchConditional %55 %57 %56 179 %57 = OpLabel 180 OpBranch %49 181 %56 = OpLabel 182 OpBranch %45 183 %49 = OpLabel 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 188 %60 = OpLabel 189 OpBranch %40 190 %41 = OpLabel 191 OpBranch %39 192 %40 = OpLabel 193 %61 = OpPhi %8 %58 %49 %20 %60 194 OpSelectionMerge %62 None 195 OpBranchConditional %61 %63 %62 196 %63 = OpLabel 197 OpBranch %31 198 %62 = OpLabel 199 OpBranch %31 200 %32 = OpLabel 201 OpBranch %30 202 %31 = OpLabel 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 208 OpStore %3 %68 209 %69 = OpFOrdEqual %8 %35 %19 210 OpSelectionMerge %70 None 211 OpBranchConditional %69 %71 %70 212 %71 = OpLabel 213 OpStore %3 %26 214 OpBranch %70 215 %70 = OpLabel 216 OpReturn 217 OpFunctionEnd 218END 219 220 221# uniforms for variant 222 223# injectionSwitch 224BUFFER variant_injectionSwitch DATA_TYPE vec2<float> DATA 225 0.0 1.0 226END 227 228BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM 229 230PIPELINE 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 236END 237CLEAR_COLOR variant_pipeline 0 0 0 255 238 239CLEAR variant_pipeline 240RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 256 256 241 242EXPECT variant_framebuffer IDX 0 0 SIZE 256 256 EQ_RGBA 255 0 0 255 243