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