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