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 always false if in switch statement 21 22# The test passes because the shader always writes the color red 23 24# Optimized using spirv-opt with the following arguments: 25# '--private-to-local' 26# '--eliminate-local-multi-store' 27# '--simplify-instructions' 28# '--eliminate-dead-inserts' 29# spirv-opt commit hash: 4a00a80c40484a6f6f72f48c9d34943cf8f180d4 30 31 32 33SHADER vertex variant_vertex_shader PASSTHROUGH 34 35# variant_fragment_shader is derived from the following GLSL: 36# #version 310 es 37# 38# precision highp float; 39# 40# layout(location = 0) out vec4 _GLF_color; 41# 42# void main() 43# { 44# switch (0) 45# { 46# case 0: 47# if (false) 48# { 49# } 50# } 51# 52# _GLF_color = vec4(1.0, 0.0, 0.0, 1.0); 53# } 54SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0 55; SPIR-V 56; Version: 1.0 57; Generator: Khronos Glslang Reference Front End; 7 58; Bound: 22 59; Schema: 0 60 OpCapability Shader 61 %1 = OpExtInstImport "GLSL.std.450" 62 OpMemoryModel Logical GLSL450 63 OpEntryPoint Fragment %4 "main" %18 64 OpExecutionMode %4 OriginUpperLeft 65 OpSource ESSL 310 66 OpName %4 "main" 67 OpName %18 "_GLF_color" 68 OpDecorate %18 Location 0 69 %2 = OpTypeVoid 70 %3 = OpTypeFunction %2 71 %6 = OpTypeInt 32 1 72 %7 = OpConstant %6 0 73 %10 = OpTypeBool 74 %11 = OpConstantFalse %10 75 %15 = OpTypeFloat 32 76 %16 = OpTypeVector %15 4 77 %17 = OpTypePointer Output %16 78 %18 = OpVariable %17 Output 79 %19 = OpConstant %15 1 80 %20 = OpConstant %15 0 81 %21 = OpConstantComposite %16 %19 %20 %20 %19 82 %4 = OpFunction %2 None %3 83 %5 = OpLabel 84 OpSelectionMerge %9 None 85 OpSwitch %7 %9 0 %8 86 %8 = OpLabel 87 OpSelectionMerge %13 None 88 OpBranchConditional %11 %12 %13 89 %12 = OpLabel 90 OpBranch %13 91 %13 = OpLabel 92 OpBranch %9 93 %9 = OpLabel 94 OpStore %18 %21 95 OpReturn 96 OpFunctionEnd 97END 98 99# uniforms for variant 100 101 102BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM 103 104PIPELINE graphics variant_pipeline 105 ATTACH variant_vertex_shader 106 ATTACH variant_fragment_shader 107 FRAMEBUFFER_SIZE 256 256 108 BIND BUFFER variant_framebuffer AS color LOCATION 0 109END 110CLEAR_COLOR variant_pipeline 0 0 0 255 111 112CLEAR variant_pipeline 113RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 256 256 114 115EXPECT variant_framebuffer IDX 0 0 SIZE 256 256 EQ_RGBA 255 0 0 255 116