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