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 GraphicsFuzz. 19 20# Short description: A fragment shader that covers specific simplification and value tracking 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 310 es 28# precision highp float; 29# precision highp int; 30# 31# layout(location = 0) out vec4 _GLF_color; 32# layout(set = 0, binding = 0) uniform buf0 33# { 34# int two; 35# }; 36# 37# int func(int i, int x) 38# { 39# int r = 2; 40# 41# // Run until x = 3 (three iterations). 42# while(x <= r) 43# { 44# // Always false. 45# if(i == 1) 46# return -1; 47# 48# // Always false. 49# if(x < 1) 50# r = 1; 51# 52# // r is always 2. 53# // findLSB(2) = 1 54# // findMSB(1) = 0 55# // --> The while loop is run only once. 56# do 57# { 58# x++; 59# } 60# while(findMSB(findLSB(r)) > 1); 61# } 62# 63# return x; 64# } 65# 66# void main() 67# { 68# if(func(two, 1) == 3) 69# _GLF_color = vec4(1, 0, 0, 1); 70# else 71# _GLF_color = vec4(0); 72# } 73SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0 74; SPIR-V 75; Version: 1.0 76; Generator: Khronos Glslang Reference Front End; 8 77; Bound: 71 78; Schema: 0 79 OpCapability Shader 80 %1 = OpExtInstImport "GLSL.std.450" 81 OpMemoryModel Logical GLSL450 82 OpEntryPoint Fragment %4 "main" %65 83 OpExecutionMode %4 OriginUpperLeft 84 OpSource ESSL 310 85 OpName %4 "main" 86 OpName %11 "func(i1;i1;" 87 OpName %9 "i" 88 OpName %10 "x" 89 OpName %13 "r" 90 OpName %48 "buf0" 91 OpMemberName %48 0 "two" 92 OpName %50 "" 93 OpName %52 "param" 94 OpName %56 "param" 95 OpName %65 "_GLF_color" 96 OpMemberDecorate %48 0 Offset 0 97 OpDecorate %48 Block 98 OpDecorate %50 DescriptorSet 0 99 OpDecorate %50 Binding 0 100 OpDecorate %65 Location 0 101 %2 = OpTypeVoid 102 %3 = OpTypeFunction %2 103 %6 = OpTypeInt 32 1 104 %7 = OpTypePointer Function %6 105 %8 = OpTypeFunction %6 %7 %7 106 %14 = OpConstant %6 2 107 %22 = OpTypeBool 108 %25 = OpConstant %6 1 109 %29 = OpConstant %6 -1 110 %48 = OpTypeStruct %6 111 %49 = OpTypePointer Uniform %48 112 %50 = OpVariable %49 Uniform 113 %51 = OpConstant %6 0 114 %53 = OpTypePointer Uniform %6 115 %58 = OpConstant %6 3 116 %62 = OpTypeFloat 32 117 %63 = OpTypeVector %62 4 118 %64 = OpTypePointer Output %63 119 %65 = OpVariable %64 Output 120 %66 = OpConstant %62 1 121 %67 = OpConstant %62 0 122 %68 = OpConstantComposite %63 %66 %67 %67 %66 123 %70 = OpConstantComposite %63 %67 %67 %67 %67 124 %4 = OpFunction %2 None %3 125 %5 = OpLabel 126 %52 = OpVariable %7 Function 127 %56 = OpVariable %7 Function 128 %54 = OpAccessChain %53 %50 %51 129 %55 = OpLoad %6 %54 130 OpStore %52 %55 131 OpStore %56 %25 132 %57 = OpFunctionCall %6 %11 %52 %56 133 %59 = OpIEqual %22 %57 %58 134 OpSelectionMerge %61 None 135 OpBranchConditional %59 %60 %69 136 %60 = OpLabel 137 OpStore %65 %68 138 OpBranch %61 139 %69 = OpLabel 140 OpStore %65 %70 141 OpBranch %61 142 %61 = OpLabel 143 OpReturn 144 OpFunctionEnd 145 %11 = OpFunction %6 None %8 146 %9 = OpFunctionParameter %7 147 %10 = OpFunctionParameter %7 148 %12 = OpLabel 149 %13 = OpVariable %7 Function 150 OpStore %13 %14 151 OpBranch %15 152 %15 = OpLabel 153 OpLoopMerge %17 %18 None 154 OpBranch %19 155 %19 = OpLabel 156 %20 = OpLoad %6 %10 157 %21 = OpLoad %6 %13 158 %23 = OpSLessThanEqual %22 %20 %21 159 OpBranchConditional %23 %16 %17 160 %16 = OpLabel 161 %24 = OpLoad %6 %9 162 %26 = OpIEqual %22 %24 %25 163 OpSelectionMerge %28 None 164 OpBranchConditional %26 %27 %28 165 %27 = OpLabel 166 OpReturnValue %29 167 %28 = OpLabel 168 %31 = OpLoad %6 %10 169 %32 = OpSLessThan %22 %31 %25 170 OpSelectionMerge %34 None 171 OpBranchConditional %32 %33 %34 172 %33 = OpLabel 173 OpStore %13 %25 174 OpBranch %34 175 %34 = OpLabel 176 OpBranch %35 177 %35 = OpLabel 178 OpLoopMerge %37 %38 None 179 OpBranch %36 180 %36 = OpLabel 181 %39 = OpLoad %6 %10 182 %40 = OpIAdd %6 %39 %25 183 OpStore %10 %40 184 OpBranch %38 185 %38 = OpLabel 186 %41 = OpLoad %6 %13 187 %42 = OpExtInst %6 %1 FindILsb %41 188 %43 = OpExtInst %6 %1 FindSMsb %42 189 %44 = OpSGreaterThan %22 %43 %25 190 OpBranchConditional %44 %35 %37 191 %37 = OpLabel 192 OpBranch %18 193 %18 = OpLabel 194 OpBranch %15 195 %17 = OpLabel 196 %45 = OpLoad %6 %10 197 OpReturnValue %45 198 OpFunctionEnd 199END 200 201# uniforms for variant 202 203# two 204BUFFER variant_two DATA_TYPE int32 DATA 205 2 206END 207 208BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM 209 210PIPELINE graphics variant_pipeline 211 ATTACH variant_vertex_shader 212 ATTACH variant_fragment_shader 213 FRAMEBUFFER_SIZE 256 256 214 BIND BUFFER variant_framebuffer AS color LOCATION 0 215 BIND BUFFER variant_two AS uniform DESCRIPTOR_SET 0 BINDING 0 216END 217CLEAR_COLOR variant_pipeline 0 0 0 255 218 219CLEAR variant_pipeline 220RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 256 256 221 222EXPECT variant_framebuffer IDX 0 0 SIZE 256 256 EQ_RGBA 255 0 0 255 223