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 do while and undefined int 21 22# The test passes because the shader always writes color red. performPartition() writes the color red and then always returns early. 23 24# Optimized using spirv-opt with the following arguments: 25# '--if-conversion' 26# '--redundancy-elimination' 27# '--eliminate-local-multi-store' 28# '--ccp' 29# '--eliminate-local-multi-store' 30# '--eliminate-dead-inserts' 31# '--ccp' 32# '--eliminate-dead-branches' 33# '--merge-blocks' 34# '--eliminate-dead-inserts' 35# '--ccp' 36# '--eliminate-dead-branches' 37# '--private-to-local' 38# '--eliminate-dead-branches' 39# spirv-opt commit hash: ad7f2c5c4c7f51360e9e079109a9217aa5ba5cc0 40 41 42 43SHADER vertex variant_vertex_shader PASSTHROUGH 44 45# variant_fragment_shader is derived from the following GLSL: 46# #version 310 es 47# precision highp float; 48# 49# layout(location = 0) out vec4 _GLF_color; 50# 51# layout(set = 0, binding = 0) uniform buf0 52# { 53# vec2 injectionSwitch; 54# }; 55# 56# int performPartition() 57# { 58# _GLF_color = vec4(1.0, 0.0, 0.0, 1.0); // Write color red 59# int i; 60# do 61# { 62# if (injectionSwitch.y < 0.0) // Always false 63# { 64# } 65# else 66# { 67# for (int GLF_live0i = 0; GLF_live0i < 1; GLF_live0i++) 68# { 69# if (injectionSwitch.y < 0.0) // Always false 70# { 71# break; 72# } 73# return 1; // We always return here. The code below is never executed. 74# } 75# if (injectionSwitch.y < 0.0) 76# { 77# do 78# { 79# return 1; 80# } while (false); 81# } 82# } 83# } while (false); 84# return i; 85# } 86# 87# void main() 88# { 89# performPartition(); 90# } 91SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0 92; SPIR-V 93; Version: 1.0 94; Generator: Khronos Glslang Reference Front End; 7 95; Bound: 80 96; Schema: 0 97 OpCapability Shader 98 %1 = OpExtInstImport "GLSL.std.450" 99 OpMemoryModel Logical GLSL450 100 OpEntryPoint Fragment %4 "main" %13 101 OpExecutionMode %4 OriginUpperLeft 102 OpSource ESSL 310 103 OpName %4 "main" 104 OpName %8 "performPartition(" 105 OpName %13 "_GLF_color" 106 OpName %22 "buf0" 107 OpMemberName %22 0 "injectionSwitch" 108 OpName %24 "" 109 OpName %37 "GLF_live0i" 110 OpName %66 "i" 111 OpDecorate %8 RelaxedPrecision 112 OpDecorate %13 Location 0 113 OpMemberDecorate %22 0 Offset 0 114 OpDecorate %22 Block 115 OpDecorate %24 DescriptorSet 0 116 OpDecorate %24 Binding 0 117 OpDecorate %37 RelaxedPrecision 118 OpDecorate %66 RelaxedPrecision 119 OpDecorate %70 RelaxedPrecision 120 OpDecorate %73 RelaxedPrecision 121 OpDecorate %72 RelaxedPrecision 122 OpDecorate %73 RelaxedPrecision 123 OpDecorate %73 RelaxedPrecision 124 %2 = OpTypeVoid 125 %3 = OpTypeFunction %2 126 %6 = OpTypeInt 32 1 127 %7 = OpTypeFunction %6 128 %10 = OpTypeFloat 32 129 %11 = OpTypeVector %10 4 130 %12 = OpTypePointer Output %11 131 %13 = OpVariable %12 Output 132 %14 = OpConstant %10 1 133 %15 = OpConstant %10 0 134 %16 = OpConstantComposite %11 %14 %15 %15 %14 135 %21 = OpTypeVector %10 2 136 %22 = OpTypeStruct %21 137 %23 = OpTypePointer Uniform %22 138 %24 = OpVariable %23 Uniform 139 %25 = OpConstant %6 0 140 %26 = OpTypeInt 32 0 141 %27 = OpConstant %26 1 142 %28 = OpTypePointer Uniform %10 143 %31 = OpTypeBool 144 %36 = OpTypePointer Function %6 145 %44 = OpConstant %6 1 146 %65 = OpConstantFalse %31 147 %74 = OpUndef %6 148 %78 = OpConstantTrue %31 149 %4 = OpFunction %2 None %3 150 %5 = OpLabel 151 %70 = OpFunctionCall %6 %8 152 OpReturn 153 OpFunctionEnd 154 %8 = OpFunction %6 None %7 155 %9 = OpLabel 156 %37 = OpVariable %36 Function 157 %66 = OpVariable %36 Function 158 OpStore %13 %16 159 OpBranch %17 160 %17 = OpLabel 161 %73 = OpPhi %6 %74 %9 %72 %34 162 OpLoopMerge %19 %34 None 163 OpBranch %18 164 %18 = OpLabel 165 %29 = OpAccessChain %28 %24 %25 %27 166 %30 = OpLoad %10 %29 167 %32 = OpFOrdLessThan %31 %30 %15 168 OpSelectionMerge %79 None 169 OpBranchConditional %32 %33 %35 170 %35 = OpLabel 171 OpStore %37 %25 172 OpBranch %38 173 %38 = OpLabel 174 %45 = OpSLessThan %31 %25 %44 175 OpLoopMerge %49 %41 None 176 OpBranch %39 177 %39 = OpLabel 178 OpSelectionMerge %50 None 179 OpBranchConditional %32 %49 %50 180 %49 = OpLabel 181 OpSelectionMerge %59 None 182 OpBranchConditional %32 %58 %59 183 %50 = OpLabel 184 OpReturnValue %44 185 %41 = OpLabel 186 OpBranch %38 187 %58 = OpLabel 188 OpBranch %60 189 %60 = OpLabel 190 OpLoopMerge %62 %63 None 191 OpBranch %61 192 %61 = OpLabel 193 OpReturnValue %44 194 %63 = OpLabel 195 OpBranch %60 196 %62 = OpLabel 197 OpUnreachable 198 %59 = OpLabel 199 OpBranch %34 200 %33 = OpLabel 201 OpBranch %34 202 %79 = OpLabel 203 OpBranch %34 204 %34 = OpLabel 205 %72 = OpPhi %6 %73 %33 %73 %59 %25 %79 206 OpBranchConditional %65 %17 %19 207 %19 = OpLabel 208 OpReturnValue %72 209 OpFunctionEnd 210END 211 212# uniforms for variant 213 214# injectionSwitch 215BUFFER variant_injectionSwitch DATA_TYPE vec2<float> DATA 216 0.0 1.0 217END 218 219BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM 220 221PIPELINE graphics variant_pipeline 222 ATTACH variant_vertex_shader 223 ATTACH variant_fragment_shader 224 FRAMEBUFFER_SIZE 256 256 225 BIND BUFFER variant_framebuffer AS color LOCATION 0 226 BIND BUFFER variant_injectionSwitch AS uniform DESCRIPTOR_SET 0 BINDING 0 227END 228CLEAR_COLOR variant_pipeline 0 0 0 255 229 230CLEAR variant_pipeline 231RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 256 256 232 233EXPECT variant_framebuffer IDX 0 0 SIZE 256 256 EQ_RGBA 255 0 0 255 234