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