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# A test for a bug found by GraphicsFuzz. 18 19# Short description: A fragment shader with a switch and some data flow 20 21# Checks that all pixels are red. 22# Passes because main always writes red to _GLF_color. 23 24# Optimized using spirv-opt with the following arguments: 25# '-Os' 26 27# Derived from the following GLSL. 28 29# Fragment shader GLSL: 30# #version 310 es 31# 32# precision highp float; 33# 34# layout(location = 0) out vec4 _GLF_color; 35# 36# layout(set = 0, binding = 0) uniform buf0 37# { 38# vec2 injectionSwitch; 39# }; 40# 41# void main() 42# { 43# float data[2]; 44# data[0] = injectionSwitch.x; 45# data[1] = injectionSwitch.x; 46# 47# _GLF_color = vec4(1.0, 0.0, 0.0, 1.0); 48# 49# if (data[1] > 1.0) 50# { 51# switch (int(injectionSwitch.x)) 52# { 53# case 0: 54# float temp = 1.0; 55# case 1: 56# data[int(injectionSwitch.x)] = temp; 57# _GLF_color = vec4(0.0, 0.0, 0.0, 0.0); 58# default: 59# break; 60# } 61# } 62# } 63 64SHADER vertex variant_vertex_shader PASSTHROUGH 65 66SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0 67; SPIR-V 68; Version: 1.0 69; Generator: Khronos Glslang Reference Front End; 7 70; Bound: 58 71; Schema: 0 72 OpCapability Shader 73 %1 = OpExtInstImport "GLSL.std.450" 74 OpMemoryModel Logical GLSL450 75 OpEntryPoint Fragment %4 "main" %30 76 OpExecutionMode %4 OriginUpperLeft 77 OpSource ESSL 310 78 OpName %4 "main" 79 OpName %11 "data" 80 OpName %15 "buf0" 81 OpMemberName %15 0 "injectionSwitch" 82 OpName %17 "" 83 OpName %30 "_GLF_color" 84 OpMemberDecorate %15 0 Offset 0 85 OpDecorate %15 Block 86 OpDecorate %17 DescriptorSet 0 87 OpDecorate %17 Binding 0 88 OpDecorate %30 Location 0 89 %2 = OpTypeVoid 90 %3 = OpTypeFunction %2 91 %6 = OpTypeFloat 32 92 %7 = OpTypeInt 32 0 93 %8 = OpConstant %7 2 94 %9 = OpTypeArray %6 %8 95 %10 = OpTypePointer Function %9 96 %12 = OpTypeInt 32 1 97 %13 = OpConstant %12 0 98 %14 = OpTypeVector %6 2 99 %15 = OpTypeStruct %14 100 %16 = OpTypePointer Uniform %15 101 %17 = OpVariable %16 Uniform 102 %18 = OpConstant %7 0 103 %19 = OpTypePointer Uniform %6 104 %22 = OpTypePointer Function %6 105 %24 = OpConstant %12 1 106 %28 = OpTypeVector %6 4 107 %29 = OpTypePointer Output %28 108 %30 = OpVariable %29 Output 109 %31 = OpConstant %6 1 110 %32 = OpConstant %6 0 111 %33 = OpConstantComposite %28 %31 %32 %32 %31 112 %36 = OpTypeBool 113 %53 = OpConstantComposite %28 %32 %32 %32 %32 114 %57 = OpUndef %6 115 %4 = OpFunction %2 None %3 116 %5 = OpLabel 117 %11 = OpVariable %10 Function 118 %20 = OpAccessChain %19 %17 %13 %18 119 %21 = OpLoad %6 %20 120 %23 = OpAccessChain %22 %11 %13 121 OpStore %23 %21 122 %27 = OpAccessChain %22 %11 %24 123 OpStore %27 %21 124 OpStore %30 %33 125 %35 = OpLoad %6 %27 126 %37 = OpFOrdGreaterThan %36 %35 %31 127 OpSelectionMerge %39 None 128 OpBranchConditional %37 %38 %39 129 %38 = OpLabel 130 %42 = OpConvertFToS %12 %21 131 OpSelectionMerge %45 None 132 OpSwitch %42 %45 0 %43 1 %44 133 %45 = OpLabel 134 OpBranch %39 135 %43 = OpLabel 136 OpBranch %44 137 %44 = OpLabel 138 %56 = OpPhi %6 %57 %38 %31 %43 139 %52 = OpAccessChain %22 %11 %42 140 OpStore %52 %56 141 OpStore %30 %53 142 OpBranch %45 143 %39 = OpLabel 144 OpReturn 145 OpFunctionEnd 146END 147 148# uniforms for variant 149 150# injectionSwitch 151BUFFER variant_injectionSwitch DATA_TYPE vec2<float> DATA 152 0.0 1.0 153END 154 155BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM 156 157PIPELINE graphics variant_pipeline 158 ATTACH variant_vertex_shader 159 ATTACH variant_fragment_shader 160 FRAMEBUFFER_SIZE 256 256 161 BIND BUFFER variant_framebuffer AS color LOCATION 0 162 BIND BUFFER variant_injectionSwitch AS uniform DESCRIPTOR_SET 0 BINDING 0 163END 164CLEAR_COLOR variant_pipeline 0 0 0 255 165 166CLEAR variant_pipeline 167RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 256 256 168 169EXPECT variant_framebuffer IDX 0 0 SIZE 256 256 EQ_RGBA 255 0 0 255 170