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