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