1#!amber 2 3# Copyright 2019 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 18# A test for a bug found by GraphicsFuzz. 19 20# Short description: A fragment shader with an always discarding main function 21 22# The test passes because: the framebuffer is cleared to black, 23# the fragment shader always discards, 24# and we check that the framebuffer is still black. 25 26# Optimized using spirv-opt with the following arguments: 27# '--private-to-local' 28# '--reduce-load-size' 29# '--eliminate-dead-code-aggressive' 30# '--eliminate-local-multi-store' 31# '--eliminate-dead-branches' 32# '--merge-return' 33# '--private-to-local' 34# '--combine-access-chains' 35# '--eliminate-dead-branches' 36# '--eliminate-dead-branches' 37# '--inline-entry-points-exhaustive' 38# '--scalar-replacement=100' 39# '--if-conversion' 40# '--combine-access-chains' 41# '--vector-dce' 42# '--vector-dce' 43# '--combine-access-chains' 44# '--reduce-load-size' 45# '--redundancy-elimination' 46# '--eliminate-local-multi-store' 47# '--vector-dce' 48# '--vector-dce' 49# spirv-opt commit hash: e82a428605f6ce0a07337b36f8ba3935c9f165ac 50 51 52 53SHADER vertex variant_vertex_shader PASSTHROUGH 54 55# variant_fragment_shader is derived from the following GLSL: 56# #version 310 es 57# precision highp float; 58# 59# layout(location = 0) out vec4 _GLF_color; 60# 61# layout(set = 0, binding = 0) uniform buf0 62# { 63# vec2 injectionSwitch; 64# }; 65# 66# struct tmp_struct 67# { 68# int nmb[1]; 69# }; 70# 71# int binarySearch(tmp_struct obj) 72# { 73# int one = 1; 74# 75# while (one > 10) 76# { 77# int zero = one - 1; 78# 79# if (obj.nmb[zero] == 1) 80# return 1; 81# 82# one = zero; 83# } 84# 85# return -1; 86# } 87# 88# void main() 89# { 90# tmp_struct obj; 91# float tmp_float = injectionSwitch.y; 92# vec3 color = vec3(tmp_float); 93# 94# if (binarySearch(obj) == -1) // Always true 95# { 96# discard; 97# } 98# else 99# { 100# _GLF_color = vec4(0.0, 0.0, 0.0, 0.0); 101# color.yz += vec2(1.0); 102# if (injectionSwitch.x > 1.0) 103# { 104# return; 105# } 106# } 107# _GLF_color = vec4(color, 1.0); 108# } 109SHADER fragment variant_fragment_shader SPIRV-ASM 110; SPIR-V 111; Version: 1.0 112; Generator: Khronos Glslang Reference Front End; 8 113; Bound: 159 114; Schema: 0 115 OpCapability Shader 116 %1 = OpExtInstImport "GLSL.std.450" 117 OpMemoryModel Logical GLSL450 118 OpEntryPoint Fragment %4 "main" %69 119 OpExecutionMode %4 OriginUpperLeft 120 OpSource ESSL 310 121 OpName %4 "main" 122 OpName %10 "tmp_struct" 123 OpMemberName %10 0 "nmb" 124 OpName %14 "binarySearch(struct-tmp_struct-i1[1]1;" 125 OpName %13 "obj" 126 OpName %17 "one" 127 OpName %28 "zero" 128 OpName %45 "tmp_float" 129 OpName %47 "buf0" 130 OpMemberName %47 0 "injectionSwitch" 131 OpName %49 "" 132 OpName %55 "color" 133 OpName %69 "_GLF_color" 134 OpMemberDecorate %10 0 RelaxedPrecision 135 OpDecorate %14 RelaxedPrecision 136 OpDecorate %17 RelaxedPrecision 137 OpDecorate %28 RelaxedPrecision 138 OpDecorate %30 RelaxedPrecision 139 OpDecorate %34 RelaxedPrecision 140 OpMemberDecorate %47 0 Offset 0 141 OpDecorate %47 Block 142 OpDecorate %49 DescriptorSet 0 143 OpDecorate %49 Binding 0 144 OpDecorate %69 Location 0 145 OpDecorate %92 RelaxedPrecision 146 OpDecorate %102 RelaxedPrecision 147 OpDecorate %111 RelaxedPrecision 148 OpDecorate %112 RelaxedPrecision 149 OpDecorate %113 RelaxedPrecision 150 OpDecorate %114 RelaxedPrecision 151 OpDecorate %122 RelaxedPrecision 152 OpDecorate %120 RelaxedPrecision 153 OpDecorate %128 RelaxedPrecision 154 OpDecorate %137 RelaxedPrecision 155 OpDecorate %144 RelaxedPrecision 156 OpDecorate %143 RelaxedPrecision 157 OpDecorate %154 RelaxedPrecision 158 OpDecorate %153 RelaxedPrecision 159 %2 = OpTypeVoid 160 %3 = OpTypeFunction %2 161 %6 = OpTypeInt 32 1 162 %7 = OpTypeInt 32 0 163 %8 = OpConstant %7 1 164 %9 = OpTypeArray %6 %8 165 %10 = OpTypeStruct %9 166 %11 = OpTypePointer Function %10 167 %12 = OpTypeFunction %6 %11 168 %16 = OpTypePointer Function %6 169 %18 = OpConstant %6 1 170 %25 = OpConstant %6 10 171 %26 = OpTypeBool 172 %31 = OpConstant %6 0 173 %40 = OpConstant %6 -1 174 %43 = OpTypeFloat 32 175 %44 = OpTypePointer Function %43 176 %46 = OpTypeVector %43 2 177 %47 = OpTypeStruct %46 178 %48 = OpTypePointer Uniform %47 179 %49 = OpVariable %48 Uniform 180 %50 = OpTypePointer Uniform %43 181 %53 = OpTypeVector %43 3 182 %54 = OpTypePointer Function %53 183 %67 = OpTypeVector %43 4 184 %68 = OpTypePointer Output %67 185 %69 = OpVariable %68 Output 186 %70 = OpConstant %43 0 187 %71 = OpConstantComposite %67 %70 %70 %70 %70 188 %72 = OpConstant %43 1 189 %73 = OpConstantComposite %46 %72 %72 190 %79 = OpConstant %7 0 191 %91 = OpUndef %10 192 %97 = OpConstantFalse %26 193 %98 = OpTypePointer Function %26 194 %100 = OpConstantTrue %26 195 %135 = OpConstantNull %9 196 %136 = OpTypePointer Function %9 197 %148 = OpUndef %6 198 %149 = OpUndef %26 199 %157 = OpUndef %6 200 %158 = OpUndef %26 201 %4 = OpFunction %2 None %3 202 %5 = OpLabel 203 %137 = OpVariable %136 Function 204 %110 = OpVariable %98 Function %97 205 %111 = OpVariable %16 Function 206 %112 = OpVariable %16 Function 207 %113 = OpVariable %16 Function 208 %114 = OpVariable %16 Function 209 %99 = OpVariable %98 Function %97 210 %45 = OpVariable %44 Function 211 %55 = OpVariable %54 Function 212 OpBranch %94 213 %94 = OpLabel 214 OpLoopMerge %93 %96 None 215 OpBranch %95 216 %95 = OpLabel 217 %51 = OpAccessChain %50 %49 %31 %8 218 %52 = OpLoad %43 %51 219 OpStore %45 %52 220 %57 = OpCompositeConstruct %53 %52 %52 %52 221 OpStore %55 %57 222 %138 = OpCompositeExtract %9 %91 0 223 OpStore %137 %138 224 OpStore %110 %97 225 OpBranch %115 226 %115 = OpLabel 227 %142 = OpPhi %26 %97 %95 %149 %117 228 OpLoopMerge %116 %117 None 229 OpBranch %118 230 %118 = OpLabel 231 OpStore %112 %18 232 OpBranch %119 233 %119 = OpLabel 234 %122 = OpPhi %6 %18 %118 %120 %121 235 OpLoopMerge %123 %121 None 236 OpBranch %124 237 %124 = OpLabel 238 %125 = OpSGreaterThan %26 %122 %25 239 OpBranchConditional %125 %126 %123 240 %126 = OpLabel 241 %120 = OpISub %6 %122 %18 242 OpStore %113 %120 243 %139 = OpAccessChain %16 %137 %120 244 %128 = OpLoad %6 %139 245 %129 = OpIEqual %26 %128 %18 246 OpSelectionMerge %130 None 247 OpBranchConditional %129 %131 %130 248 %131 = OpLabel 249 OpStore %110 %100 250 OpStore %111 %18 251 OpBranch %123 252 %130 = OpLabel 253 OpStore %112 %120 254 OpBranch %121 255 %121 = OpLabel 256 OpBranch %119 257 %123 = OpLabel 258 %144 = OpPhi %6 %148 %124 %18 %131 259 %140 = OpPhi %26 %142 %124 %100 %131 260 OpSelectionMerge %133 None 261 OpBranchConditional %140 %116 %133 262 %133 = OpLabel 263 OpStore %110 %100 264 OpStore %111 %40 265 OpBranch %116 266 %117 = OpLabel 267 OpBranch %115 268 %116 = OpLabel 269 %143 = OpPhi %6 %144 %123 %40 %133 270 OpStore %114 %143 271 %62 = OpIEqual %26 %143 %40 272 OpSelectionMerge %64 None 273 OpBranchConditional %62 %63 %66 274 %63 = OpLabel 275 OpKill 276 %66 = OpLabel 277 OpStore %69 %71 278 %75 = OpVectorShuffle %46 %57 %57 1 2 279 %76 = OpFAdd %46 %75 %73 280 %78 = OpVectorShuffle %53 %57 %76 0 3 4 281 OpStore %55 %78 282 %80 = OpAccessChain %50 %49 %31 %79 283 %81 = OpLoad %43 %80 284 %82 = OpFOrdGreaterThan %26 %81 %72 285 OpSelectionMerge %84 None 286 OpBranchConditional %82 %83 %84 287 %83 = OpLabel 288 OpStore %99 %100 289 OpBranch %93 290 %84 = OpLabel 291 OpBranch %64 292 %64 = OpLabel 293 %87 = OpCompositeExtract %43 %78 0 294 %88 = OpCompositeExtract %43 %78 1 295 %89 = OpCompositeExtract %43 %78 2 296 %90 = OpCompositeConstruct %67 %87 %88 %89 %72 297 OpStore %69 %90 298 OpStore %99 %100 299 OpBranch %93 300 %96 = OpLabel 301 OpBranch %94 302 %93 = OpLabel 303 OpReturn 304 OpFunctionEnd 305 %14 = OpFunction %6 None %12 306 %13 = OpFunctionParameter %11 307 %15 = OpLabel 308 %107 = OpVariable %98 Function %97 309 %102 = OpVariable %16 Function 310 %17 = OpVariable %16 Function 311 %28 = OpVariable %16 Function 312 OpBranch %104 313 %104 = OpLabel 314 %152 = OpPhi %26 %97 %15 %158 %106 315 OpLoopMerge %101 %106 None 316 OpBranch %105 317 %105 = OpLabel 318 OpStore %17 %18 319 OpBranch %19 320 %19 = OpLabel 321 %92 = OpPhi %6 %18 %105 %30 %22 322 OpLoopMerge %21 %22 None 323 OpBranch %23 324 %23 = OpLabel 325 %27 = OpSGreaterThan %26 %92 %25 326 OpBranchConditional %27 %20 %21 327 %20 = OpLabel 328 %30 = OpISub %6 %92 %18 329 OpStore %28 %30 330 %33 = OpAccessChain %16 %13 %31 %30 331 %34 = OpLoad %6 %33 332 %35 = OpIEqual %26 %34 %18 333 OpSelectionMerge %37 None 334 OpBranchConditional %35 %36 %37 335 %36 = OpLabel 336 OpStore %107 %100 337 OpStore %102 %18 338 OpBranch %21 339 %37 = OpLabel 340 OpStore %17 %30 341 OpBranch %22 342 %22 = OpLabel 343 OpBranch %19 344 %21 = OpLabel 345 %154 = OpPhi %6 %157 %23 %18 %36 346 %150 = OpPhi %26 %152 %23 %100 %36 347 OpSelectionMerge %108 None 348 OpBranchConditional %150 %101 %108 349 %108 = OpLabel 350 OpStore %107 %100 351 OpStore %102 %40 352 OpBranch %101 353 %106 = OpLabel 354 OpBranch %104 355 %101 = OpLabel 356 %153 = OpPhi %6 %154 %21 %40 %108 357 OpReturnValue %153 358 OpFunctionEnd 359END 360 361# uniforms for variant 362 363# injectionSwitch 364BUFFER variant_injectionSwitch DATA_TYPE vec2<float> DATA 365 0.0 1.0 366END 367 368BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM 369 370PIPELINE graphics variant_pipeline 371 ATTACH variant_vertex_shader 372 ATTACH variant_fragment_shader 373 FRAMEBUFFER_SIZE 256 256 374 BIND BUFFER variant_framebuffer AS color LOCATION 0 375 BIND BUFFER variant_injectionSwitch AS uniform DESCRIPTOR_SET 0 BINDING 0 376END 377CLEAR_COLOR variant_pipeline 0 0 0 255 378 379CLEAR variant_pipeline 380RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 256 256 381 382EXPECT variant_framebuffer IDX 0 0 SIZE 256 256 EQ_RGBA 0 0 0 255 383