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