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