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