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 nested if 21 22# The test passes because main always writes color red. 23# Running code after writing red does not matter. 24 25# Optimized using spirv-opt with the following arguments: 26# '--copy-propagate-arrays' 27# '--if-conversion' 28# '--convert-local-access-chains' 29# '--convert-local-access-chains' 30# '--vector-dce' 31# '--reduce-load-size' 32# '--reduce-load-size' 33# '--eliminate-dead-branches' 34# '--merge-blocks' 35# '--inline-entry-points-exhaustive' 36# '--redundancy-elimination' 37# '--private-to-local' 38# '--eliminate-dead-code-aggressive' 39# '--ccp' 40# '--simplify-instructions' 41# '--eliminate-dead-branches' 42# '--inline-entry-points-exhaustive' 43# '--eliminate-dead-inserts' 44# '--eliminate-dead-branches' 45# spirv-opt commit hash: 6b072126595dd8c2448eb1fda616251c5e6d7079 46 47 48 49SHADER vertex variant_vertex_shader PASSTHROUGH 50 51# variant_fragment_shader is derived from the following GLSL: 52# #version 310 es 53# precision highp float; 54# 55# layout(location = 0) out vec4 _GLF_color; 56# 57# layout(set = 0, binding = 0) uniform buf0 58# { 59# vec2 injectionSwitch; 60# }; 61# void main() 62# { 63# _GLF_color = vec4(1.0, 0.0, 0.0, 1.0); // Write color red 64# 65# do 66# { 67# if (injectionSwitch.y < 0.0) // Always false 68# { 69# bool GLF_live12c5 = false; 70# if (GLF_live12c5) 71# { 72# } 73# continue; 74# } 75# break; 76# } while (false); 77# } 78SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0 79; SPIR-V 80; Version: 1.0 81; Generator: Khronos Glslang Reference Front End; 7 82; Bound: 39 83; Schema: 0 84 OpCapability Shader 85 %1 = OpExtInstImport "GLSL.std.450" 86 OpMemoryModel Logical GLSL450 87 OpEntryPoint Fragment %4 "main" %9 88 OpExecutionMode %4 OriginUpperLeft 89 OpSource ESSL 310 90 OpName %4 "main" 91 OpName %9 "_GLF_color" 92 OpName %18 "buf0" 93 OpMemberName %18 0 "injectionSwitch" 94 OpName %20 "" 95 OpName %33 "GLF_live12c5" 96 OpDecorate %9 Location 0 97 OpMemberDecorate %18 0 Offset 0 98 OpDecorate %18 Block 99 OpDecorate %20 DescriptorSet 0 100 OpDecorate %20 Binding 0 101 %2 = OpTypeVoid 102 %3 = OpTypeFunction %2 103 %6 = OpTypeFloat 32 104 %7 = OpTypeVector %6 4 105 %8 = OpTypePointer Output %7 106 %9 = OpVariable %8 Output 107 %10 = OpConstant %6 1 108 %11 = OpConstant %6 0 109 %12 = OpConstantComposite %7 %10 %11 %11 %10 110 %17 = OpTypeVector %6 2 111 %18 = OpTypeStruct %17 112 %19 = OpTypePointer Uniform %18 113 %20 = OpVariable %19 Uniform 114 %21 = OpTypeInt 32 1 115 %22 = OpConstant %21 0 116 %23 = OpTypeInt 32 0 117 %24 = OpConstant %23 1 118 %25 = OpTypePointer Uniform %6 119 %28 = OpTypeBool 120 %32 = OpTypePointer Function %28 121 %34 = OpConstantFalse %28 122 %4 = OpFunction %2 None %3 123 %5 = OpLabel 124 %33 = OpVariable %32 Function 125 OpStore %9 %12 126 OpBranch %13 127 %13 = OpLabel 128 OpLoopMerge %15 %37 None 129 OpBranch %14 130 %14 = OpLabel 131 %26 = OpAccessChain %25 %20 %22 %24 132 %27 = OpLoad %6 %26 133 %29 = OpFOrdLessThan %28 %27 %11 134 OpSelectionMerge %31 None 135 OpBranchConditional %29 %30 %31 136 %30 = OpLabel 137 OpStore %33 %34 138 %35 = OpLoad %28 %33 139 OpSelectionMerge %38 None 140 OpBranchConditional %35 %36 %37 141 %36 = OpLabel 142 OpBranch %37 143 %38 = OpLabel 144 OpBranch %37 145 %37 = OpLabel 146 OpBranchConditional %34 %13 %15 147 %31 = OpLabel 148 OpBranch %15 149 %15 = OpLabel 150 OpReturn 151 OpFunctionEnd 152END 153 154# uniforms for variant 155 156# injectionSwitch 157BUFFER variant_injectionSwitch DATA_TYPE vec2<float> DATA 158 0.0 1.0 159END 160 161BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM 162 163PIPELINE graphics variant_pipeline 164 ATTACH variant_vertex_shader 165 ATTACH variant_fragment_shader 166 FRAMEBUFFER_SIZE 256 256 167 BIND BUFFER variant_framebuffer AS color LOCATION 0 168 BIND BUFFER variant_injectionSwitch AS uniform DESCRIPTOR_SET 0 BINDING 0 169END 170CLEAR_COLOR variant_pipeline 0 0 0 255 171 172CLEAR variant_pipeline 173RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 256 256 174 175EXPECT variant_framebuffer IDX 0 0 SIZE 256 256 EQ_RGBA 255 0 0 255 176