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