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