1#!amber 2 3# Copyright 2021 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# #define _int_1 _GLF_uniform_int_values[0] 29# #define _int_4 _GLF_uniform_int_values[1] 30# #define _int_35 _GLF_uniform_int_values[2] 31# #define _int_0 _GLF_uniform_int_values[3] 32# #define _float_1_0 _GLF_uniform_float_values[0] 33# #define _float_0_0 _GLF_uniform_float_values[1] 34# #define _float_2_0 _GLF_uniform_float_values[2] 35# 36# precision highp float; 37# precision highp int; 38# 39# // Contents of _GLF_uniform_float_values: [1.0, 0.0, 2.0] 40# layout(set = 0, binding = 0) uniform buf0 41# { 42# float _GLF_uniform_float_values[3]; 43# }; 44# 45# // Contents of _GLF_uniform_int_values: [1, 4, 35, 0] 46# layout(set = 0, binding = 1) uniform buf1 47# { 48# int _GLF_uniform_int_values[4]; 49# }; 50# 51# const int _GLF_global_loop_bound = 100; 52# int _GLF_global_loop_count = 0; 53# 54# struct S 55# { 56# int data0; 57# int data1; 58# }; 59# 60# int a = 1; 61# 62# S arr[10] = S[10](S(1, 1), S(1, 1), S(1, 1), S(1, 1), S(1, 1), S(1, 1), S(1, 1), S(1, 1), S(1, 1), S(1, 1)); 63# 64# layout(location = 0) out vec4 _GLF_color; 65# 66# // Has no effect because the original value is always one. Also this function is never called. 67# void func0(inout S s) 68# { 69# s.data0 = _int_1; 70# } 71# 72# // Always returns vec4(fract(x), 1, 1). 73# vec3 func1(float x) 74# { 75# // Always false because x is the result of a call to sin. 76# if(x > _float_1_0) 77# { 78# return vec3(_int_0); 79# } 80# 81# return vec3(fract(x), _float_1_0, _float_1_0); 82# } 83# 84# vec3 func2() 85# { 86# // Always true. 87# if(gl_FragCoord.x > _float_0_0) 88# { 89# // a becomes one. 90# a = S[10](S(_int_1, _int_1), S(_int_1, _int_1), S(_int_1, _int_1), S(_int_1, _int_1), S(_int_1, _int_1), S(_int_1, _int_1), S(_int_1, _int_1), S(_int_1, _int_1), S(_int_1, _int_1), S(_int_1, _int_1))[a].data1; 91# } 92# 93# vec3 v0 = vec3(_float_1_0); 94# for(int i = _int_35; i >= _int_1 && _GLF_global_loop_count < _GLF_global_loop_bound; i--) 95# { 96# _GLF_global_loop_count++; 97# 98# vec3 v1 = func1(sin(float(i))); 99# 100# // Always true. 101# if(length(v1) >= _float_0_0) 102# { 103# v0 = v1; 104# } 105# } 106# 107# return v0; 108# } 109# 110# void main() 111# { 112# a = _int_4; 113# func2(); 114# vec3 v = func2(); 115# 116# // Always true. 117# if(gl_FragCoord.x > _float_0_0) 118# { 119# // Always false. 120# if(arr[a].data1 == 0) 121# { 122# func0(arr[a]); 123# return; 124# } 125# } 126# 127# // Guaranteed to be true because of an identical check in func2. 128# if(length(v) > _float_0_0) 129# { 130# _GLF_color = vec4(_int_1, _int_0, _int_0, _int_1); 131# } 132# else 133# { 134# _GLF_color = vec4(_int_0); 135# } 136# } 137SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0 138; SPIR-V 139; Version: 1.0 140; Generator: Khronos Glslang Reference Front End; 10 141; Bound: 238 142; Schema: 0 143 OpCapability Shader 144 %1 = OpExtInstImport "GLSL.std.450" 145 OpMemoryModel Logical GLSL450 146 OpEntryPoint Fragment %4 "main" %75 %219 147 OpExecutionMode %4 OriginUpperLeft 148 OpSource ESSL 320 149 OpName %4 "main" 150 OpName %7 "S" 151 OpMemberName %7 0 "data0" 152 OpMemberName %7 1 "data1" 153 OpName %11 "func0(struct-S-i1-i11;" 154 OpName %10 "s" 155 OpName %18 "func1(f1;" 156 OpName %17 "x" 157 OpName %21 "func2(" 158 OpName %24 "_GLF_global_loop_count" 159 OpName %26 "a" 160 OpName %32 "arr" 161 OpName %37 "buf1" 162 OpMemberName %37 0 "_GLF_uniform_int_values" 163 OpName %39 "" 164 OpName %48 "buf0" 165 OpMemberName %48 0 "_GLF_uniform_float_values" 166 OpName %50 "" 167 OpName %75 "gl_FragCoord" 168 OpName %138 "indexable" 169 OpName %142 "v0" 170 OpName %146 "i" 171 OpName %165 "v1" 172 OpName %169 "param" 173 OpName %187 "v" 174 OpName %203 "param" 175 OpName %219 "_GLF_color" 176 OpDecorate %36 ArrayStride 16 177 OpMemberDecorate %37 0 Offset 0 178 OpDecorate %37 Block 179 OpDecorate %39 DescriptorSet 0 180 OpDecorate %39 Binding 1 181 OpDecorate %47 ArrayStride 16 182 OpMemberDecorate %48 0 Offset 0 183 OpDecorate %48 Block 184 OpDecorate %50 DescriptorSet 0 185 OpDecorate %50 Binding 0 186 OpDecorate %75 BuiltIn FragCoord 187 OpDecorate %219 Location 0 188 %2 = OpTypeVoid 189 %3 = OpTypeFunction %2 190 %6 = OpTypeInt 32 1 191 %7 = OpTypeStruct %6 %6 192 %8 = OpTypePointer Function %7 193 %9 = OpTypeFunction %2 %8 194 %13 = OpTypeFloat 32 195 %14 = OpTypePointer Function %13 196 %15 = OpTypeVector %13 3 197 %16 = OpTypeFunction %15 %14 198 %20 = OpTypeFunction %15 199 %23 = OpTypePointer Private %6 200 %24 = OpVariable %23 Private 201 %25 = OpConstant %6 0 202 %26 = OpVariable %23 Private 203 %27 = OpConstant %6 1 204 %28 = OpTypeInt 32 0 205 %29 = OpConstant %28 10 206 %30 = OpTypeArray %7 %29 207 %31 = OpTypePointer Private %30 208 %32 = OpVariable %31 Private 209 %33 = OpConstantComposite %7 %27 %27 210 %34 = OpConstantComposite %30 %33 %33 %33 %33 %33 %33 %33 %33 %33 %33 211 %35 = OpConstant %28 4 212 %36 = OpTypeArray %6 %35 213 %37 = OpTypeStruct %36 214 %38 = OpTypePointer Uniform %37 215 %39 = OpVariable %38 Uniform 216 %40 = OpTypePointer Uniform %6 217 %43 = OpTypePointer Function %6 218 %46 = OpConstant %28 3 219 %47 = OpTypeArray %13 %46 220 %48 = OpTypeStruct %47 221 %49 = OpTypePointer Uniform %48 222 %50 = OpVariable %49 Uniform 223 %51 = OpTypePointer Uniform %13 224 %54 = OpTypeBool 225 %58 = OpConstant %6 3 226 %73 = OpTypeVector %13 4 227 %74 = OpTypePointer Input %73 228 %75 = OpVariable %74 Input 229 %76 = OpConstant %28 0 230 %77 = OpTypePointer Input %13 231 %137 = OpTypePointer Function %30 232 %141 = OpTypePointer Function %15 233 %147 = OpConstant %6 2 234 %160 = OpConstant %6 100 235 %204 = OpTypePointer Private %7 236 %218 = OpTypePointer Output %73 237 %219 = OpVariable %218 Output 238 %4 = OpFunction %2 None %3 239 %5 = OpLabel 240 %187 = OpVariable %141 Function 241 %203 = OpVariable %8 Function 242 OpStore %24 %25 243 OpStore %26 %27 244 OpStore %32 %34 245 %184 = OpAccessChain %40 %39 %25 %27 246 %185 = OpLoad %6 %184 247 OpStore %26 %185 248 %186 = OpFunctionCall %15 %21 249 %188 = OpFunctionCall %15 %21 250 OpStore %187 %188 251 %189 = OpAccessChain %77 %75 %76 252 %190 = OpLoad %13 %189 253 %191 = OpAccessChain %51 %50 %25 %27 254 %192 = OpLoad %13 %191 255 %193 = OpFOrdGreaterThan %54 %190 %192 256 OpSelectionMerge %195 None 257 OpBranchConditional %193 %194 %195 258 %194 = OpLabel 259 %196 = OpLoad %6 %26 260 %197 = OpAccessChain %23 %32 %196 %27 261 %198 = OpLoad %6 %197 262 %199 = OpIEqual %54 %198 %25 263 OpSelectionMerge %201 None 264 OpBranchConditional %199 %200 %201 265 %200 = OpLabel 266 %202 = OpLoad %6 %26 267 %205 = OpAccessChain %204 %32 %202 268 %206 = OpLoad %7 %205 269 OpStore %203 %206 270 %207 = OpFunctionCall %2 %11 %203 271 %208 = OpLoad %7 %203 272 %209 = OpAccessChain %204 %32 %202 273 OpStore %209 %208 274 OpReturn 275 %201 = OpLabel 276 OpBranch %195 277 %195 = OpLabel 278 %211 = OpLoad %15 %187 279 %212 = OpExtInst %13 %1 Length %211 280 %213 = OpAccessChain %51 %50 %25 %27 281 %214 = OpLoad %13 %213 282 %215 = OpFOrdGreaterThan %54 %212 %214 283 OpSelectionMerge %217 None 284 OpBranchConditional %215 %216 %233 285 %216 = OpLabel 286 %220 = OpAccessChain %40 %39 %25 %25 287 %221 = OpLoad %6 %220 288 %222 = OpConvertSToF %13 %221 289 %223 = OpAccessChain %40 %39 %25 %58 290 %224 = OpLoad %6 %223 291 %225 = OpConvertSToF %13 %224 292 %226 = OpAccessChain %40 %39 %25 %58 293 %227 = OpLoad %6 %226 294 %228 = OpConvertSToF %13 %227 295 %229 = OpAccessChain %40 %39 %25 %25 296 %230 = OpLoad %6 %229 297 %231 = OpConvertSToF %13 %230 298 %232 = OpCompositeConstruct %73 %222 %225 %228 %231 299 OpStore %219 %232 300 OpBranch %217 301 %233 = OpLabel 302 %234 = OpAccessChain %40 %39 %25 %58 303 %235 = OpLoad %6 %234 304 %236 = OpConvertSToF %13 %235 305 %237 = OpCompositeConstruct %73 %236 %236 %236 %236 306 OpStore %219 %237 307 OpBranch %217 308 %217 = OpLabel 309 OpReturn 310 OpFunctionEnd 311 %11 = OpFunction %2 None %9 312 %10 = OpFunctionParameter %8 313 %12 = OpLabel 314 %41 = OpAccessChain %40 %39 %25 %25 315 %42 = OpLoad %6 %41 316 %44 = OpAccessChain %43 %10 %25 317 OpStore %44 %42 318 OpReturn 319 OpFunctionEnd 320 %18 = OpFunction %15 None %16 321 %17 = OpFunctionParameter %14 322 %19 = OpLabel 323 %45 = OpLoad %13 %17 324 %52 = OpAccessChain %51 %50 %25 %25 325 %53 = OpLoad %13 %52 326 %55 = OpFOrdGreaterThan %54 %45 %53 327 OpSelectionMerge %57 None 328 OpBranchConditional %55 %56 %57 329 %56 = OpLabel 330 %59 = OpAccessChain %40 %39 %25 %58 331 %60 = OpLoad %6 %59 332 %61 = OpConvertSToF %13 %60 333 %62 = OpCompositeConstruct %15 %61 %61 %61 334 OpReturnValue %62 335 %57 = OpLabel 336 %64 = OpLoad %13 %17 337 %65 = OpExtInst %13 %1 Fract %64 338 %66 = OpAccessChain %51 %50 %25 %25 339 %67 = OpLoad %13 %66 340 %68 = OpAccessChain %51 %50 %25 %25 341 %69 = OpLoad %13 %68 342 %70 = OpCompositeConstruct %15 %65 %67 %69 343 OpReturnValue %70 344 OpFunctionEnd 345 %21 = OpFunction %15 None %20 346 %22 = OpLabel 347 %138 = OpVariable %137 Function 348 %142 = OpVariable %141 Function 349 %146 = OpVariable %43 Function 350 %165 = OpVariable %141 Function 351 %169 = OpVariable %14 Function 352 %78 = OpAccessChain %77 %75 %76 353 %79 = OpLoad %13 %78 354 %80 = OpAccessChain %51 %50 %25 %27 355 %81 = OpLoad %13 %80 356 %82 = OpFOrdGreaterThan %54 %79 %81 357 OpSelectionMerge %84 None 358 OpBranchConditional %82 %83 %84 359 %83 = OpLabel 360 %85 = OpAccessChain %40 %39 %25 %25 361 %86 = OpLoad %6 %85 362 %87 = OpAccessChain %40 %39 %25 %25 363 %88 = OpLoad %6 %87 364 %89 = OpCompositeConstruct %7 %86 %88 365 %90 = OpAccessChain %40 %39 %25 %25 366 %91 = OpLoad %6 %90 367 %92 = OpAccessChain %40 %39 %25 %25 368 %93 = OpLoad %6 %92 369 %94 = OpCompositeConstruct %7 %91 %93 370 %95 = OpAccessChain %40 %39 %25 %25 371 %96 = OpLoad %6 %95 372 %97 = OpAccessChain %40 %39 %25 %25 373 %98 = OpLoad %6 %97 374 %99 = OpCompositeConstruct %7 %96 %98 375 %100 = OpAccessChain %40 %39 %25 %25 376 %101 = OpLoad %6 %100 377 %102 = OpAccessChain %40 %39 %25 %25 378 %103 = OpLoad %6 %102 379 %104 = OpCompositeConstruct %7 %101 %103 380 %105 = OpAccessChain %40 %39 %25 %25 381 %106 = OpLoad %6 %105 382 %107 = OpAccessChain %40 %39 %25 %25 383 %108 = OpLoad %6 %107 384 %109 = OpCompositeConstruct %7 %106 %108 385 %110 = OpAccessChain %40 %39 %25 %25 386 %111 = OpLoad %6 %110 387 %112 = OpAccessChain %40 %39 %25 %25 388 %113 = OpLoad %6 %112 389 %114 = OpCompositeConstruct %7 %111 %113 390 %115 = OpAccessChain %40 %39 %25 %25 391 %116 = OpLoad %6 %115 392 %117 = OpAccessChain %40 %39 %25 %25 393 %118 = OpLoad %6 %117 394 %119 = OpCompositeConstruct %7 %116 %118 395 %120 = OpAccessChain %40 %39 %25 %25 396 %121 = OpLoad %6 %120 397 %122 = OpAccessChain %40 %39 %25 %25 398 %123 = OpLoad %6 %122 399 %124 = OpCompositeConstruct %7 %121 %123 400 %125 = OpAccessChain %40 %39 %25 %25 401 %126 = OpLoad %6 %125 402 %127 = OpAccessChain %40 %39 %25 %25 403 %128 = OpLoad %6 %127 404 %129 = OpCompositeConstruct %7 %126 %128 405 %130 = OpAccessChain %40 %39 %25 %25 406 %131 = OpLoad %6 %130 407 %132 = OpAccessChain %40 %39 %25 %25 408 %133 = OpLoad %6 %132 409 %134 = OpCompositeConstruct %7 %131 %133 410 %135 = OpCompositeConstruct %30 %89 %94 %99 %104 %109 %114 %119 %124 %129 %134 411 %136 = OpLoad %6 %26 412 OpStore %138 %135 413 %139 = OpAccessChain %43 %138 %136 %27 414 %140 = OpLoad %6 %139 415 OpStore %26 %140 416 OpBranch %84 417 %84 = OpLabel 418 %143 = OpAccessChain %51 %50 %25 %25 419 %144 = OpLoad %13 %143 420 %145 = OpCompositeConstruct %15 %144 %144 %144 421 OpStore %142 %145 422 %148 = OpAccessChain %40 %39 %25 %147 423 %149 = OpLoad %6 %148 424 OpStore %146 %149 425 OpBranch %150 426 %150 = OpLabel 427 OpLoopMerge %152 %153 None 428 OpBranch %154 429 %154 = OpLabel 430 %155 = OpLoad %6 %146 431 %156 = OpAccessChain %40 %39 %25 %25 432 %157 = OpLoad %6 %156 433 %158 = OpSGreaterThanEqual %54 %155 %157 434 %159 = OpLoad %6 %24 435 %161 = OpSLessThan %54 %159 %160 436 %162 = OpLogicalAnd %54 %158 %161 437 OpBranchConditional %162 %151 %152 438 %151 = OpLabel 439 %163 = OpLoad %6 %24 440 %164 = OpIAdd %6 %163 %27 441 OpStore %24 %164 442 %166 = OpLoad %6 %146 443 %167 = OpConvertSToF %13 %166 444 %168 = OpExtInst %13 %1 Sin %167 445 OpStore %169 %168 446 %170 = OpFunctionCall %15 %18 %169 447 OpStore %165 %170 448 %171 = OpLoad %15 %165 449 %172 = OpExtInst %13 %1 Length %171 450 %173 = OpAccessChain %51 %50 %25 %27 451 %174 = OpLoad %13 %173 452 %175 = OpFOrdGreaterThanEqual %54 %172 %174 453 OpSelectionMerge %177 None 454 OpBranchConditional %175 %176 %177 455 %176 = OpLabel 456 %178 = OpLoad %15 %165 457 OpStore %142 %178 458 OpBranch %177 459 %177 = OpLabel 460 OpBranch %153 461 %153 = OpLabel 462 %179 = OpLoad %6 %146 463 %180 = OpISub %6 %179 %27 464 OpStore %146 %180 465 OpBranch %150 466 %152 = OpLabel 467 %181 = OpLoad %15 %142 468 OpReturnValue %181 469 OpFunctionEnd 470END 471 472# uniforms for variant 473 474# _GLF_uniform_int_values 475BUFFER variant__GLF_uniform_int_values DATA_TYPE int32[] STD140 DATA 476 1 4 35 0 477END 478# _GLF_uniform_float_values 479BUFFER variant__GLF_uniform_float_values DATA_TYPE float[] STD140 DATA 480 1.0 0.0 2.0 481END 482 483BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM 484 485PIPELINE graphics variant_pipeline 486 ATTACH variant_vertex_shader 487 ATTACH variant_fragment_shader 488 FRAMEBUFFER_SIZE 256 256 489 BIND BUFFER variant_framebuffer AS color LOCATION 0 490 BIND BUFFER variant__GLF_uniform_int_values AS uniform DESCRIPTOR_SET 0 BINDING 1 491 BIND BUFFER variant__GLF_uniform_float_values AS uniform DESCRIPTOR_SET 0 BINDING 0 492END 493CLEAR_COLOR variant_pipeline 0 0 0 255 494 495CLEAR variant_pipeline 496RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 256 256 497 498EXPECT variant_framebuffer IDX 0 0 SIZE 256 256 EQ_RGBA 255 0 0 255 499