1#!amber 2 3# Copyright 2022 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 coverage-gap found by the GraphicsFuzz project. 19 20# Short description: A fragment shader that covers specific LLVM code paths 21 22# The test passes because the shader always writes red. 23 24SHADER vertex variant_vertex_shader PASSTHROUGH 25 26# variant_fragment_shader is derived from the following GLSL: 27# #version 320 es 28# 29# #define _int_1 _GLF_uniform_int_values[0] 30# #define _int_0 _GLF_uniform_int_values[1] 31# #define _int_10 _GLF_uniform_int_values[2] 32# #define _int_5 _GLF_uniform_int_values[3] 33# 34# precision highp float; 35# precision highp int; 36# 37# // Contents of _GLF_uniform_int_values: [1, 0, 10, 5] 38# layout(set = 0, binding = 0) uniform buf0 39# { 40# int _GLF_uniform_int_values[4]; 41# }; 42# 43# // Contents of injectionSwitch: [0.0, 1.0] 44# layout(push_constant) uniform buf_push { 45# highp vec2 injectionSwitch; 46# }; 47# 48# layout(location = 0) out vec4 _GLF_color; 49# 50# struct S 51# { 52# int data; 53# }; 54# 55# S arr[10] = S[10](S(1), S(1), S(1), S(1), S(1), S(1), S(1), S(1), S(1), S(1)); 56# 57# void func(inout S s) 58# { 59# // Always false. 60# if(injectionSwitch.x > injectionSwitch.y) 61# { 62# return; 63# } 64# 65# // Always false. 66# if(gl_FragCoord.y < 0.0) 67# { 68# return; 69# } 70# 71# s.data = 0; 72# } 73# 74# void main() 75# { 76# func(arr[_int_1]); 77# bool b = false; 78# 79# // Always false. 80# if(injectionSwitch.x > injectionSwitch.y) 81# { 82# b = true; 83# } 84# 85# // Always true. 86# if(!b) 87# { 88# int idx = 0; 89# 90# for(int i = 0; i < _int_5; i++) 91# { 92# arr[idx].data = _int_1; 93# func(arr[i]); 94# } 95# } 96# 97# // The first five elements had data set to zero, but also the first element was set back to one in iterations i = 1..4. 98# int ref[10] = int[10](_int_1, _int_0, _int_0, _int_0, _int_0, _int_1, _int_1, _int_1, _int_1, _int_1); 99# 100# // Check the results and set an output color to black if the check fails. 101# _GLF_color = vec4(_int_1, _int_0, _int_0, _int_1); 102# for(int i = _int_0; i < _int_10; i++) 103# { 104# if(arr[i].data != ref[i]) 105# { 106# _GLF_color = vec4(_int_0); 107# } 108# } 109# } 110SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0 111; SPIR-V 112; Version: 1.0 113; Generator: Khronos Glslang Reference Front End; 10 114; Bound: 175 115; Schema: 0 116 OpCapability Shader 117 %1 = OpExtInstImport "GLSL.std.450" 118 OpMemoryModel Logical GLSL450 119 OpEntryPoint Fragment %4 "main" %41 %133 120 OpExecutionMode %4 OriginUpperLeft 121 OpSource ESSL 320 122 OpName %4 "main" 123 OpName %7 "S" 124 OpMemberName %7 0 "data" 125 OpName %11 "func(struct-S-i11;" 126 OpName %10 "s" 127 OpName %17 "arr" 128 OpName %23 "buf_push" 129 OpMemberName %23 0 "injectionSwitch" 130 OpName %25 "" 131 OpName %41 "gl_FragCoord" 132 OpName %54 "buf0" 133 OpMemberName %54 0 "_GLF_uniform_int_values" 134 OpName %56 "" 135 OpName %60 "param" 136 OpName %68 "b" 137 OpName %82 "idx" 138 OpName %83 "i" 139 OpName %100 "param" 140 OpName %110 "ref" 141 OpName %133 "_GLF_color" 142 OpName %147 "i" 143 OpMemberDecorate %23 0 Offset 0 144 OpDecorate %23 Block 145 OpDecorate %41 BuiltIn FragCoord 146 OpDecorate %53 ArrayStride 16 147 OpMemberDecorate %54 0 Offset 0 148 OpDecorate %54 Block 149 OpDecorate %56 DescriptorSet 0 150 OpDecorate %56 Binding 0 151 OpDecorate %133 Location 0 152 %2 = OpTypeVoid 153 %3 = OpTypeFunction %2 154 %6 = OpTypeInt 32 1 155 %7 = OpTypeStruct %6 156 %8 = OpTypePointer Function %7 157 %9 = OpTypeFunction %2 %8 158 %13 = OpTypeInt 32 0 159 %14 = OpConstant %13 10 160 %15 = OpTypeArray %7 %14 161 %16 = OpTypePointer Private %15 162 %17 = OpVariable %16 Private 163 %18 = OpConstant %6 1 164 %19 = OpConstantComposite %7 %18 165 %20 = OpConstantComposite %15 %19 %19 %19 %19 %19 %19 %19 %19 %19 %19 166 %21 = OpTypeFloat 32 167 %22 = OpTypeVector %21 2 168 %23 = OpTypeStruct %22 169 %24 = OpTypePointer PushConstant %23 170 %25 = OpVariable %24 PushConstant 171 %26 = OpConstant %6 0 172 %27 = OpConstant %13 0 173 %28 = OpTypePointer PushConstant %21 174 %31 = OpConstant %13 1 175 %34 = OpTypeBool 176 %39 = OpTypeVector %21 4 177 %40 = OpTypePointer Input %39 178 %41 = OpVariable %40 Input 179 %42 = OpTypePointer Input %21 180 %45 = OpConstant %21 0 181 %50 = OpTypePointer Function %6 182 %52 = OpConstant %13 4 183 %53 = OpTypeArray %6 %52 184 %54 = OpTypeStruct %53 185 %55 = OpTypePointer Uniform %54 186 %56 = OpVariable %55 Uniform 187 %57 = OpTypePointer Uniform %6 188 %61 = OpTypePointer Private %7 189 %67 = OpTypePointer Function %34 190 %69 = OpConstantFalse %34 191 %77 = OpConstantTrue %34 192 %90 = OpConstant %6 3 193 %97 = OpTypePointer Private %6 194 %108 = OpTypeArray %6 %14 195 %109 = OpTypePointer Function %108 196 %132 = OpTypePointer Output %39 197 %133 = OpVariable %132 Output 198 %156 = OpConstant %6 2 199 %4 = OpFunction %2 None %3 200 %5 = OpLabel 201 %60 = OpVariable %8 Function 202 %68 = OpVariable %67 Function 203 %82 = OpVariable %50 Function 204 %83 = OpVariable %50 Function 205 %100 = OpVariable %8 Function 206 %110 = OpVariable %109 Function 207 %147 = OpVariable %50 Function 208 OpStore %17 %20 209 %58 = OpAccessChain %57 %56 %26 %26 210 %59 = OpLoad %6 %58 211 %62 = OpAccessChain %61 %17 %59 212 %63 = OpLoad %7 %62 213 OpStore %60 %63 214 %64 = OpFunctionCall %2 %11 %60 215 %65 = OpLoad %7 %60 216 %66 = OpAccessChain %61 %17 %59 217 OpStore %66 %65 218 OpStore %68 %69 219 %70 = OpAccessChain %28 %25 %26 %27 220 %71 = OpLoad %21 %70 221 %72 = OpAccessChain %28 %25 %26 %31 222 %73 = OpLoad %21 %72 223 %74 = OpFOrdGreaterThan %34 %71 %73 224 OpSelectionMerge %76 None 225 OpBranchConditional %74 %75 %76 226 %75 = OpLabel 227 OpStore %68 %77 228 OpBranch %76 229 %76 = OpLabel 230 %78 = OpLoad %34 %68 231 %79 = OpLogicalNot %34 %78 232 OpSelectionMerge %81 None 233 OpBranchConditional %79 %80 %81 234 %80 = OpLabel 235 OpStore %82 %26 236 OpStore %83 %26 237 OpBranch %84 238 %84 = OpLabel 239 OpLoopMerge %86 %87 None 240 OpBranch %88 241 %88 = OpLabel 242 %89 = OpLoad %6 %83 243 %91 = OpAccessChain %57 %56 %26 %90 244 %92 = OpLoad %6 %91 245 %93 = OpSLessThan %34 %89 %92 246 OpBranchConditional %93 %85 %86 247 %85 = OpLabel 248 %94 = OpLoad %6 %82 249 %95 = OpAccessChain %57 %56 %26 %26 250 %96 = OpLoad %6 %95 251 %98 = OpAccessChain %97 %17 %94 %26 252 OpStore %98 %96 253 %99 = OpLoad %6 %83 254 %101 = OpAccessChain %61 %17 %99 255 %102 = OpLoad %7 %101 256 OpStore %100 %102 257 %103 = OpFunctionCall %2 %11 %100 258 %104 = OpLoad %7 %100 259 %105 = OpAccessChain %61 %17 %99 260 OpStore %105 %104 261 OpBranch %87 262 %87 = OpLabel 263 %106 = OpLoad %6 %83 264 %107 = OpIAdd %6 %106 %18 265 OpStore %83 %107 266 OpBranch %84 267 %86 = OpLabel 268 OpBranch %81 269 %81 = OpLabel 270 %111 = OpAccessChain %57 %56 %26 %26 271 %112 = OpLoad %6 %111 272 %113 = OpAccessChain %57 %56 %26 %18 273 %114 = OpLoad %6 %113 274 %115 = OpAccessChain %57 %56 %26 %18 275 %116 = OpLoad %6 %115 276 %117 = OpAccessChain %57 %56 %26 %18 277 %118 = OpLoad %6 %117 278 %119 = OpAccessChain %57 %56 %26 %18 279 %120 = OpLoad %6 %119 280 %121 = OpAccessChain %57 %56 %26 %26 281 %122 = OpLoad %6 %121 282 %123 = OpAccessChain %57 %56 %26 %26 283 %124 = OpLoad %6 %123 284 %125 = OpAccessChain %57 %56 %26 %26 285 %126 = OpLoad %6 %125 286 %127 = OpAccessChain %57 %56 %26 %26 287 %128 = OpLoad %6 %127 288 %129 = OpAccessChain %57 %56 %26 %26 289 %130 = OpLoad %6 %129 290 %131 = OpCompositeConstruct %108 %112 %114 %116 %118 %120 %122 %124 %126 %128 %130 291 OpStore %110 %131 292 %134 = OpAccessChain %57 %56 %26 %26 293 %135 = OpLoad %6 %134 294 %136 = OpConvertSToF %21 %135 295 %137 = OpAccessChain %57 %56 %26 %18 296 %138 = OpLoad %6 %137 297 %139 = OpConvertSToF %21 %138 298 %140 = OpAccessChain %57 %56 %26 %18 299 %141 = OpLoad %6 %140 300 %142 = OpConvertSToF %21 %141 301 %143 = OpAccessChain %57 %56 %26 %26 302 %144 = OpLoad %6 %143 303 %145 = OpConvertSToF %21 %144 304 %146 = OpCompositeConstruct %39 %136 %139 %142 %145 305 OpStore %133 %146 306 %148 = OpAccessChain %57 %56 %26 %18 307 %149 = OpLoad %6 %148 308 OpStore %147 %149 309 OpBranch %150 310 %150 = OpLabel 311 OpLoopMerge %152 %153 None 312 OpBranch %154 313 %154 = OpLabel 314 %155 = OpLoad %6 %147 315 %157 = OpAccessChain %57 %56 %26 %156 316 %158 = OpLoad %6 %157 317 %159 = OpSLessThan %34 %155 %158 318 OpBranchConditional %159 %151 %152 319 %151 = OpLabel 320 %160 = OpLoad %6 %147 321 %161 = OpAccessChain %97 %17 %160 %26 322 %162 = OpLoad %6 %161 323 %163 = OpLoad %6 %147 324 %164 = OpAccessChain %50 %110 %163 325 %165 = OpLoad %6 %164 326 %166 = OpINotEqual %34 %162 %165 327 OpSelectionMerge %168 None 328 OpBranchConditional %166 %167 %168 329 %167 = OpLabel 330 %169 = OpAccessChain %57 %56 %26 %18 331 %170 = OpLoad %6 %169 332 %171 = OpConvertSToF %21 %170 333 %172 = OpCompositeConstruct %39 %171 %171 %171 %171 334 OpStore %133 %172 335 OpBranch %168 336 %168 = OpLabel 337 OpBranch %153 338 %153 = OpLabel 339 %173 = OpLoad %6 %147 340 %174 = OpIAdd %6 %173 %18 341 OpStore %147 %174 342 OpBranch %150 343 %152 = OpLabel 344 OpReturn 345 OpFunctionEnd 346 %11 = OpFunction %2 None %9 347 %10 = OpFunctionParameter %8 348 %12 = OpLabel 349 %29 = OpAccessChain %28 %25 %26 %27 350 %30 = OpLoad %21 %29 351 %32 = OpAccessChain %28 %25 %26 %31 352 %33 = OpLoad %21 %32 353 %35 = OpFOrdGreaterThan %34 %30 %33 354 OpSelectionMerge %37 None 355 OpBranchConditional %35 %36 %37 356 %36 = OpLabel 357 OpReturn 358 %37 = OpLabel 359 %43 = OpAccessChain %42 %41 %31 360 %44 = OpLoad %21 %43 361 %46 = OpFOrdLessThan %34 %44 %45 362 OpSelectionMerge %48 None 363 OpBranchConditional %46 %47 %48 364 %47 = OpLabel 365 OpReturn 366 %48 = OpLabel 367 %51 = OpAccessChain %50 %10 %26 368 OpStore %51 %26 369 OpReturn 370 OpFunctionEnd 371END 372 373# uniforms for variant 374 375# injectionSwitch 376BUFFER variant_injectionSwitch DATA_TYPE vec2<float> STD140 DATA 377 0.0 1.0 378END 379# _GLF_uniform_int_values 380BUFFER variant__GLF_uniform_int_values DATA_TYPE int32[] STD140 DATA 381 1 0 10 5 382END 383 384BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM 385 386PIPELINE graphics variant_pipeline 387 ATTACH variant_vertex_shader 388 ATTACH variant_fragment_shader 389 FRAMEBUFFER_SIZE 32 32 390 BIND BUFFER variant_framebuffer AS color LOCATION 0 391 BIND BUFFER variant_injectionSwitch AS push_constant 392 BIND BUFFER variant__GLF_uniform_int_values AS uniform DESCRIPTOR_SET 0 BINDING 0 393END 394CLEAR_COLOR variant_pipeline 0 0 0 255 395 396CLEAR variant_pipeline 397RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 32 32 398 399EXPECT variant_framebuffer IDX 0 0 SIZE 32 32 EQ_RGBA 255 0 0 255 400