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# '--copy-propagate-arrays' 26# '--eliminate-dead-inserts' 27# '--convert-local-access-chains' 28# '--private-to-local' 29# '--redundancy-elimination' 30# '--eliminate-local-multi-store' 31# '--eliminate-local-single-block' 32# '--eliminate-dead-code-aggressive' 33# '--copy-propagate-arrays' 34# '--eliminate-dead-inserts' 35# '--redundancy-elimination' 36# '--eliminate-local-single-block' 37# '--eliminate-local-single-store' 38# '--eliminate-local-single-store' 39# '--eliminate-dead-code-aggressive' 40# '--inline-entry-points-exhaustive' 41# '--combine-access-chains' 42# '--eliminate-dead-branches' 43# '--merge-return' 44# '--eliminate-local-single-block' 45# '--eliminate-dead-branches' 46# '--reduce-load-size' 47# '--eliminate-dead-inserts' 48# '--copy-propagate-arrays' 49# '--convert-local-access-chains' 50# '--vector-dce' 51# '--redundancy-elimination' 52# '--eliminate-local-multi-store' 53# '--redundancy-elimination' 54# '--eliminate-dead-inserts' 55# '--eliminate-dead-code-aggressive' 56# spirv-opt commit hash: a0370efd589be33d5d9a85cfde2f85841b3755af 57 58 59 60SHADER vertex texgen_vert PASSTHROUGH 61 62SHADER fragment texgen_frag GLSL 63#version 430 64precision highp float; 65 66layout(location = 0) out vec4 _GLF_color; 67 68void main() 69{ 70 _GLF_color = vec4( 71 floor(gl_FragCoord.x) * (1.0 / 255.0), 72 (int(gl_FragCoord.x) ^ int(gl_FragCoord.y)) * (1.0 / 255.0), 73 floor(gl_FragCoord.y) * (1.0 / 255.0), 74 1.0); 75} 76END 77BUFFER default_texture FORMAT B8G8R8A8_UNORM 78 79PIPELINE graphics texgen_pipeline 80 ATTACH texgen_vert 81 ATTACH texgen_frag 82 FRAMEBUFFER_SIZE 256 256 83 BIND BUFFER default_texture AS color LOCATION 0 84END 85 86CLEAR_COLOR texgen_pipeline 0 0 0 255 87CLEAR texgen_pipeline 88RUN texgen_pipeline DRAW_RECT POS 0 0 SIZE 256 256 89 90SHADER vertex variant_vertex_shader PASSTHROUGH 91 92# variant_fragment_shader is derived from the following GLSL: 93# #version 320 es 94# 95# precision highp float; 96# precision highp int; 97# 98# const int _GLF_global_loop_bound = 10; 99# int _GLF_global_loop_count = 0; 100# 101# struct S 102# { 103# int data; 104# }; 105# 106# layout(set = 0, binding = 0) uniform sampler2D tex; 107# 108# layout(location = 0) out vec4 _GLF_color; 109# 110# void main() 111# { 112# int a = 1; 113# int b = 1; 114# vec4 v = vec4(1.0); 115# S s = S(1); 116# 117# // Iterated once. 118# while(v.x + 1.0 > 0.0 && s.data <= 1 && _GLF_global_loop_count < _GLF_global_loop_bound) 119# { 120# _GLF_global_loop_count++; 121# 122# // Always false. 123# if(b++ > 3) 124# { 125# break; 126# } 127# 128# // The sampled value doesn't matter because the loop will exit in any case. 129# v = texture(tex, vec2(1.0)); 130# 131# // This will cause the loop to exit. 132# s.data++; 133# } 134# 135# // Always true. 136# if (s.data == 2) 137# _GLF_color = vec4(float(a), 0, 0, 1); 138# else 139# _GLF_color = vec4(0); 140# } 141SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0 142; SPIR-V 143; Version: 1.0 144; Generator: Khronos Glslang Reference Front End; 10 145; Bound: 96 146; Schema: 0 147 OpCapability Shader 148 %1 = OpExtInstImport "GLSL.std.450" 149 OpMemoryModel Logical GLSL450 150 OpEntryPoint Fragment %4 "main" %75 151 OpExecutionMode %4 OriginUpperLeft 152 OpSource ESSL 320 153 OpName %4 "main" 154 OpName %20 "S" 155 OpMemberName %20 0 "data" 156 OpName %60 "tex" 157 OpName %75 "_GLF_color" 158 OpDecorate %60 RelaxedPrecision 159 OpDecorate %60 DescriptorSet 0 160 OpDecorate %60 Binding 0 161 OpDecorate %61 RelaxedPrecision 162 OpDecorate %64 RelaxedPrecision 163 OpDecorate %75 Location 0 164 %2 = OpTypeVoid 165 %3 = OpTypeFunction %2 166 %6 = OpTypeInt 32 1 167 %9 = OpConstant %6 0 168 %12 = OpConstant %6 1 169 %14 = OpTypeFloat 32 170 %15 = OpTypeVector %14 4 171 %18 = OpConstant %14 1 172 %19 = OpConstantComposite %15 %18 %18 %18 %18 173 %20 = OpTypeStruct %6 174 %23 = OpConstantComposite %20 %12 175 %29 = OpTypeBool 176 %36 = OpConstant %14 0 177 %45 = OpConstant %6 10 178 %52 = OpConstant %6 3 179 %57 = OpTypeImage %14 2D 0 0 0 1 Unknown 180 %58 = OpTypeSampledImage %57 181 %59 = OpTypePointer UniformConstant %58 182 %60 = OpVariable %59 UniformConstant 183 %62 = OpTypeVector %14 2 184 %63 = OpConstantComposite %62 %18 %18 185 %70 = OpConstant %6 2 186 %74 = OpTypePointer Output %15 187 %75 = OpVariable %74 Output 188 %80 = OpConstantComposite %15 %36 %36 %36 %36 189 %4 = OpFunction %2 None %3 190 %5 = OpLabel 191 OpBranch %24 192 %24 = OpLabel 193 %95 = OpPhi %20 %23 %5 %85 %27 194 %94 = OpPhi %15 %19 %5 %64 %27 195 %90 = OpPhi %6 %12 %5 %51 %27 196 %88 = OpPhi %6 %9 %5 %49 %27 197 %93 = OpPhi %6 %12 %5 %93 %27 198 OpLoopMerge %26 %27 None 199 OpBranch %28 200 %28 = OpLabel 201 %34 = OpCompositeExtract %14 %94 0 202 %35 = OpFAdd %14 %34 %18 203 %37 = OpFOrdGreaterThan %29 %35 %36 204 OpSelectionMerge %39 None 205 OpBranchConditional %37 %38 %39 206 %38 = OpLabel 207 %41 = OpCompositeExtract %6 %95 0 208 %42 = OpSLessThanEqual %29 %41 %12 209 OpBranch %39 210 %39 = OpLabel 211 %43 = OpPhi %29 %37 %28 %42 %38 212 %46 = OpSLessThan %29 %88 %45 213 %47 = OpLogicalAnd %29 %43 %46 214 OpBranchConditional %47 %25 %26 215 %25 = OpLabel 216 %49 = OpIAdd %6 %88 %12 217 %51 = OpIAdd %6 %90 %12 218 %53 = OpSGreaterThan %29 %90 %52 219 OpSelectionMerge %55 None 220 OpBranchConditional %53 %54 %55 221 %54 = OpLabel 222 OpBranch %26 223 %55 = OpLabel 224 %61 = OpLoad %58 %60 225 %64 = OpImageSampleImplicitLod %15 %61 %63 226 %66 = OpCompositeExtract %6 %95 0 227 %67 = OpIAdd %6 %66 %12 228 %85 = OpCompositeInsert %20 %67 %95 0 229 OpBranch %27 230 %27 = OpLabel 231 OpBranch %24 232 %26 = OpLabel 233 %69 = OpCompositeExtract %6 %95 0 234 %71 = OpIEqual %29 %69 %70 235 OpSelectionMerge %73 None 236 OpBranchConditional %71 %72 %79 237 %72 = OpLabel 238 %77 = OpConvertSToF %14 %93 239 %78 = OpCompositeConstruct %15 %77 %36 %36 %18 240 OpStore %75 %78 241 OpBranch %73 242 %79 = OpLabel 243 OpStore %75 %80 244 OpBranch %73 245 %73 = OpLabel 246 OpReturn 247 OpFunctionEnd 248END 249 250# uniforms for variant 251 252# GLF_live1tex 253SAMPLER variant_GLF_live1tex 254 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 256 256 262 BIND BUFFER variant_framebuffer AS color LOCATION 0 263 BIND BUFFER default_texture AS combined_image_sampler SAMPLER variant_GLF_live1tex DESCRIPTOR_SET 0 BINDING 0 264END 265CLEAR_COLOR variant_pipeline 0 0 0 255 266 267CLEAR variant_pipeline 268RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 256 256 269 270EXPECT variant_framebuffer IDX 0 0 SIZE 256 256 EQ_RGBA 255 0 0 255 271