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