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