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 a specific LLVM analysis code path. 21 22# The test passes because 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# 33# layout(set = 0, binding = 0) uniform buf0 34# { 35# int three; 36# }; 37# 38# void main() 39# { 40# int a = 0; 41# for(int i = 0; i < 7 + three; i++) 42# { 43# switch(i) 44# { 45# case 7: 46# case 8: 47# a++; 48# break; 49# } 50# } 51# 52# if (a == 2) // Always true. 53# _GLF_color = vec4(1, 0, 0, 1); 54# else 55# _GLF_color = vec4(0); 56# } 57SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0 58; SPIR-V 59; Version: 1.0 60; Generator: Khronos Glslang Reference Front End; 8 61; Bound: 51 62; Schema: 0 63 OpCapability Shader 64 %1 = OpExtInstImport "GLSL.std.450" 65 OpMemoryModel Logical GLSL450 66 OpEntryPoint Fragment %4 "main" %45 67 OpExecutionMode %4 OriginUpperLeft 68 OpSource ESSL 310 69 OpName %4 "main" 70 OpName %8 "a" 71 OpName %10 "i" 72 OpName %18 "buf0" 73 OpMemberName %18 0 "three" 74 OpName %20 "" 75 OpName %45 "_GLF_color" 76 OpMemberDecorate %18 0 Offset 0 77 OpDecorate %18 Block 78 OpDecorate %20 DescriptorSet 0 79 OpDecorate %20 Binding 0 80 OpDecorate %45 Location 0 81 %2 = OpTypeVoid 82 %3 = OpTypeFunction %2 83 %6 = OpTypeInt 32 1 84 %7 = OpTypePointer Function %6 85 %9 = OpConstant %6 0 86 %17 = OpConstant %6 7 87 %18 = OpTypeStruct %6 88 %19 = OpTypePointer Uniform %18 89 %20 = OpVariable %19 Uniform 90 %21 = OpTypePointer Uniform %6 91 %25 = OpTypeBool 92 %31 = OpConstant %6 1 93 %38 = OpConstant %6 2 94 %42 = OpTypeFloat 32 95 %43 = OpTypeVector %42 4 96 %44 = OpTypePointer Output %43 97 %45 = OpVariable %44 Output 98 %46 = OpConstant %42 1 99 %47 = OpConstant %42 0 100 %48 = OpConstantComposite %43 %46 %47 %47 %46 101 %50 = OpConstantComposite %43 %47 %47 %47 %47 102 %4 = OpFunction %2 None %3 103 %5 = OpLabel 104 %8 = OpVariable %7 Function 105 %10 = OpVariable %7 Function 106 OpStore %8 %9 107 OpStore %10 %9 108 OpBranch %11 109 %11 = OpLabel 110 OpLoopMerge %13 %14 None 111 OpBranch %15 112 %15 = OpLabel 113 %16 = OpLoad %6 %10 114 %22 = OpAccessChain %21 %20 %9 115 %23 = OpLoad %6 %22 116 %24 = OpIAdd %6 %17 %23 117 %26 = OpSLessThan %25 %16 %24 118 OpBranchConditional %26 %12 %13 119 %12 = OpLabel 120 %27 = OpLoad %6 %10 121 OpSelectionMerge %29 None 122 OpSwitch %27 %29 7 %28 8 %28 123 %28 = OpLabel 124 %30 = OpLoad %6 %8 125 %32 = OpIAdd %6 %30 %31 126 OpStore %8 %32 127 OpBranch %29 128 %29 = OpLabel 129 OpBranch %14 130 %14 = OpLabel 131 %35 = OpLoad %6 %10 132 %36 = OpIAdd %6 %35 %31 133 OpStore %10 %36 134 OpBranch %11 135 %13 = OpLabel 136 %37 = OpLoad %6 %8 137 %39 = OpIEqual %25 %37 %38 138 OpSelectionMerge %41 None 139 OpBranchConditional %39 %40 %49 140 %40 = OpLabel 141 OpStore %45 %48 142 OpBranch %41 143 %49 = OpLabel 144 OpStore %45 %50 145 OpBranch %41 146 %41 = OpLabel 147 OpReturn 148 OpFunctionEnd 149END 150 151# uniforms for variant 152 153# three 154BUFFER variant_three DATA_TYPE int32 DATA 155 3 156END 157 158BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM 159 160PIPELINE graphics variant_pipeline 161 ATTACH variant_vertex_shader 162 ATTACH variant_fragment_shader 163 FRAMEBUFFER_SIZE 256 256 164 BIND BUFFER variant_framebuffer AS color LOCATION 0 165 BIND BUFFER variant_three AS uniform DESCRIPTOR_SET 0 BINDING 0 166END 167CLEAR_COLOR variant_pipeline 0 0 0 255 168 169CLEAR variant_pipeline 170RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 256 256 171 172EXPECT variant_framebuffer IDX 0 0 SIZE 256 256 EQ_RGBA 255 0 0 255 173