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