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