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