1# Copyright 2019 Google LLC 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); 4# you may not use this file except in compliance with the License. 5# You may obtain a copy of the License at 6# 7# http://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, 11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12# See the License for the specific language governing permissions and 13# limitations under the License. 14 15# A test for a bug found by GraphicsFuzz. 16 17# Short description: A compute shader with dead barriers 18 19# Checks that the output value is 42. 20# Passes because main always writes 42 to out_data. 21 22# Derived from the following GLSL. 23 24# Compute shader GLSL: 25# #version 310 es 26# 27# layout(set = 0, binding = 1) uniform buf1 28# { 29# vec2 injectionSwitch; 30# }; 31# 32# layout(std430, binding = 0) buffer theSSBO 33# { 34# int out_data; 35# }; 36# 37# layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in; 38# void main() 39# { 40# out_data = 42; 41# if (injectionSwitch.x > injectionSwitch.y) // false 42# { 43# barrier(); 44# } 45# 46# if (injectionSwitch.x > injectionSwitch.y) // false 47# { 48# barrier(); 49# } 50# 51# // single iteration loop 52# for ( 53# int i = int(injectionSwitch.y); // 1 54# i > 0; 55# --i) 56# { 57# barrier(); 58# } 59# 60# float GLF_live3s = 0.0; 61# 62# // single iteration loop 63# do 64# { 65# // single iteration loop 66# for ( 67# int i = 1; 68# i < 2; 69# i++) 70# { 71# if (injectionSwitch.x > 1.0) // false 72# { 73# barrier(); 74# } 75# 76# if (injectionSwitch.x > injectionSwitch.y) // false 77# { 78# barrier(); 79# } 80# 81# // single iteration loop 82# for ( 83# int z = int(injectionSwitch.y); // 1 84# z > 0; 85# --z) 86# { 87# GLF_live3s += 1.0; 88# } 89# 90# if (i >= 1) // true 91# { 92# if (injectionSwitch.x > 1.0) // false 93# { 94# barrier(); 95# } 96# } 97# } 98# } while (injectionSwitch.x > injectionSwitch.y); // false 99# 100# } 101 102[compute shader spirv] 103; SPIR-V 104; Version: 1.0 105; Generator: Khronos Glslang Reference Front End; 7 106; Bound: 115 107; Schema: 0 108 OpCapability Shader 109 %1 = OpExtInstImport "GLSL.std.450" 110 OpMemoryModel Logical GLSL450 111 OpEntryPoint GLCompute %4 "main" 112 OpExecutionMode %4 LocalSize 1 1 1 113 OpSource ESSL 310 114 OpName %4 "main" 115 OpName %7 "theSSBO" 116 OpMemberName %7 0 "out_data" 117 OpName %9 "" 118 OpName %16 "buf1" 119 OpMemberName %16 0 "injectionSwitch" 120 OpName %18 "" 121 OpName %41 "i" 122 OpName %56 "GLF_live3s" 123 OpName %62 "i" 124 OpName %84 "z" 125 OpMemberDecorate %7 0 Offset 0 126 OpDecorate %7 BufferBlock 127 OpDecorate %9 DescriptorSet 0 128 OpDecorate %9 Binding 0 129 OpMemberDecorate %16 0 Offset 0 130 OpDecorate %16 Block 131 OpDecorate %18 DescriptorSet 0 132 OpDecorate %18 Binding 1 133 %2 = OpTypeVoid 134 %3 = OpTypeFunction %2 135 %6 = OpTypeInt 32 1 136 %7 = OpTypeStruct %6 137 %8 = OpTypePointer Uniform %7 138 %9 = OpVariable %8 Uniform 139 %10 = OpConstant %6 0 140 %11 = OpConstant %6 42 141 %12 = OpTypePointer Uniform %6 142 %14 = OpTypeFloat 32 143 %15 = OpTypeVector %14 2 144 %16 = OpTypeStruct %15 145 %17 = OpTypePointer Uniform %16 146 %18 = OpVariable %17 Uniform 147 %19 = OpTypeInt 32 0 148 %20 = OpConstant %19 0 149 %21 = OpTypePointer Uniform %14 150 %24 = OpConstant %19 1 151 %27 = OpTypeBool 152 %31 = OpConstant %19 2 153 %32 = OpConstant %19 264 154 %40 = OpTypePointer Function %6 155 %53 = OpConstant %6 1 156 %55 = OpTypePointer Function %14 157 %57 = OpConstant %14 0 158 %69 = OpConstant %6 2 159 %73 = OpConstant %14 1 160 %4 = OpFunction %2 None %3 161 %5 = OpLabel 162 %41 = OpVariable %40 Function 163 %56 = OpVariable %55 Function 164 %62 = OpVariable %40 Function 165 %84 = OpVariable %40 Function 166 %13 = OpAccessChain %12 %9 %10 167 OpStore %13 %11 168 %22 = OpAccessChain %21 %18 %10 %20 169 %23 = OpLoad %14 %22 170 %25 = OpAccessChain %21 %18 %10 %24 171 %26 = OpLoad %14 %25 172 %28 = OpFOrdGreaterThan %27 %23 %26 173 OpSelectionMerge %30 None 174 OpBranchConditional %28 %29 %30 175 %29 = OpLabel 176 OpControlBarrier %31 %31 %32 177 OpBranch %30 178 %30 = OpLabel 179 %33 = OpAccessChain %21 %18 %10 %20 180 %34 = OpLoad %14 %33 181 %35 = OpAccessChain %21 %18 %10 %24 182 %36 = OpLoad %14 %35 183 %37 = OpFOrdGreaterThan %27 %34 %36 184 OpSelectionMerge %39 None 185 OpBranchConditional %37 %38 %39 186 %38 = OpLabel 187 OpControlBarrier %31 %31 %32 188 OpBranch %39 189 %39 = OpLabel 190 %42 = OpAccessChain %21 %18 %10 %24 191 %43 = OpLoad %14 %42 192 %44 = OpConvertFToS %6 %43 193 OpStore %41 %44 194 OpBranch %45 195 %45 = OpLabel 196 OpLoopMerge %47 %48 None 197 OpBranch %49 198 %49 = OpLabel 199 %50 = OpLoad %6 %41 200 %51 = OpSGreaterThan %27 %50 %10 201 OpBranchConditional %51 %46 %47 202 %46 = OpLabel 203 OpControlBarrier %31 %31 %32 204 OpBranch %48 205 %48 = OpLabel 206 %52 = OpLoad %6 %41 207 %54 = OpISub %6 %52 %53 208 OpStore %41 %54 209 OpBranch %45 210 %47 = OpLabel 211 OpStore %56 %57 212 OpBranch %58 213 %58 = OpLabel 214 OpLoopMerge %60 %61 None 215 OpBranch %59 216 %59 = OpLabel 217 OpStore %62 %53 218 OpBranch %63 219 %63 = OpLabel 220 OpLoopMerge %65 %66 None 221 OpBranch %67 222 %67 = OpLabel 223 %68 = OpLoad %6 %62 224 %70 = OpSLessThan %27 %68 %69 225 OpBranchConditional %70 %64 %65 226 %64 = OpLabel 227 %71 = OpAccessChain %21 %18 %10 %20 228 %72 = OpLoad %14 %71 229 %74 = OpFOrdGreaterThan %27 %72 %73 230 OpSelectionMerge %76 None 231 OpBranchConditional %74 %75 %76 232 %75 = OpLabel 233 OpControlBarrier %31 %31 %32 234 OpBranch %76 235 %76 = OpLabel 236 %77 = OpAccessChain %21 %18 %10 %20 237 %78 = OpLoad %14 %77 238 %79 = OpAccessChain %21 %18 %10 %24 239 %80 = OpLoad %14 %79 240 %81 = OpFOrdGreaterThan %27 %78 %80 241 OpSelectionMerge %83 None 242 OpBranchConditional %81 %82 %83 243 %82 = OpLabel 244 OpControlBarrier %31 %31 %32 245 OpBranch %83 246 %83 = OpLabel 247 %85 = OpAccessChain %21 %18 %10 %24 248 %86 = OpLoad %14 %85 249 %87 = OpConvertFToS %6 %86 250 OpStore %84 %87 251 OpBranch %88 252 %88 = OpLabel 253 OpLoopMerge %90 %91 None 254 OpBranch %92 255 %92 = OpLabel 256 %93 = OpLoad %6 %84 257 %94 = OpSGreaterThan %27 %93 %10 258 OpBranchConditional %94 %89 %90 259 %89 = OpLabel 260 %95 = OpLoad %14 %56 261 %96 = OpFAdd %14 %95 %73 262 OpStore %56 %96 263 OpBranch %91 264 %91 = OpLabel 265 %97 = OpLoad %6 %84 266 %98 = OpISub %6 %97 %53 267 OpStore %84 %98 268 OpBranch %88 269 %90 = OpLabel 270 %99 = OpLoad %6 %62 271 %100 = OpSGreaterThanEqual %27 %99 %53 272 OpSelectionMerge %102 None 273 OpBranchConditional %100 %101 %102 274 %101 = OpLabel 275 %103 = OpAccessChain %21 %18 %10 %20 276 %104 = OpLoad %14 %103 277 %105 = OpFOrdGreaterThan %27 %104 %73 278 OpSelectionMerge %107 None 279 OpBranchConditional %105 %106 %107 280 %106 = OpLabel 281 OpControlBarrier %31 %31 %32 282 OpBranch %107 283 %107 = OpLabel 284 OpBranch %102 285 %102 = OpLabel 286 OpBranch %66 287 %66 = OpLabel 288 %108 = OpLoad %6 %62 289 %109 = OpIAdd %6 %108 %53 290 OpStore %62 %109 291 OpBranch %63 292 %65 = OpLabel 293 OpBranch %61 294 %61 = OpLabel 295 %110 = OpAccessChain %21 %18 %10 %20 296 %111 = OpLoad %14 %110 297 %112 = OpAccessChain %21 %18 %10 %24 298 %113 = OpLoad %14 %112 299 %114 = OpFOrdGreaterThan %27 %111 %113 300 OpBranchConditional %114 %58 %60 301 %60 = OpLabel 302 OpReturn 303 OpFunctionEnd 304 305 306[test] 307## Uniforms 308# injectionSwitch 309uniform ubo 0:1 vec2 0 0.0 1.0 310## SSBO 311ssbo 0 subdata int 0 0 312 313compute 1 1 1 314probe ssbo int 0 0 == 42 315