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