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