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 24SHADER vertex texgen_vert PASSTHROUGH 25 26SHADER fragment texgen_frag GLSL 27#version 430 28precision highp float; 29 30layout(location = 0) out vec4 _GLF_color; 31 32void main() 33{ 34 _GLF_color = vec4( 35 floor(gl_FragCoord.x) * (1.0 / 255.0), 36 (int(gl_FragCoord.x) ^ int(gl_FragCoord.y)) * (1.0 / 255.0), 37 floor(gl_FragCoord.y) * (1.0 / 255.0), 38 1.0); 39} 40END 41BUFFER default_texture FORMAT B8G8R8A8_UNORM 42 43PIPELINE graphics texgen_pipeline 44 ATTACH texgen_vert 45 ATTACH texgen_frag 46 FRAMEBUFFER_SIZE 256 256 47 BIND BUFFER default_texture AS color LOCATION 0 48END 49 50CLEAR_COLOR texgen_pipeline 0 0 0 255 51CLEAR texgen_pipeline 52RUN texgen_pipeline DRAW_RECT POS 0 0 SIZE 256 256 53 54SHADER vertex variant_vertex_shader PASSTHROUGH 55 56# variant_fragment_shader is derived from the following GLSL: 57# #version 320 es 58# 59# precision highp float; 60# precision highp int; 61# 62# layout(set = 0, binding = 0) uniform sampler2D tex; 63# 64# layout(location = 0) out vec4 _GLF_color; 65# 66# void main() 67# { 68# ivec2 ipos = ivec2(gl_FragCoord.xy); 69# int a = (ipos.x & 5) + ((ipos.y & 5) | (ipos.x & 10)); 70# 71# // This loop reduces a to a range of 0..3. 72# while(a > 3) 73# { 74# vec4 v = texture(tex, vec2(1.0)); 75# 76# // Sampled values are between 0..1 making this condition always false. 77# while(v.x > 2.0) 78# { 79# } 80# 81# a -= 4; 82# } 83# 84# // Always true. 85# if (a >= 0 && a < 4) 86# _GLF_color = vec4[4](vec4(1, 0, 0, 1), vec4(1, 0, 0, 1), vec4(1, 0, 0, 1), vec4(1, 0, 0, 1))[a]; 87# else 88# _GLF_color = vec4(0); 89# } 90SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0 91; SPIR-V 92; Version: 1.0 93; Generator: Khronos Glslang Reference Front End; 10 94; Bound: 90 95; Schema: 0 96 OpCapability Shader 97 %1 = OpExtInstImport "GLSL.std.450" 98 OpMemoryModel Logical GLSL450 99 OpEntryPoint Fragment %4 "main" %13 %77 100 OpExecutionMode %4 OriginUpperLeft 101 OpSource ESSL 320 102 OpName %4 "main" 103 OpName %9 "ipos" 104 OpName %13 "gl_FragCoord" 105 OpName %19 "a" 106 OpName %46 "v" 107 OpName %50 "tex" 108 OpName %77 "_GLF_color" 109 OpName %85 "indexable" 110 OpDecorate %13 BuiltIn FragCoord 111 OpDecorate %50 RelaxedPrecision 112 OpDecorate %50 DescriptorSet 0 113 OpDecorate %50 Binding 0 114 OpDecorate %51 RelaxedPrecision 115 OpDecorate %54 RelaxedPrecision 116 OpDecorate %77 Location 0 117 %2 = OpTypeVoid 118 %3 = OpTypeFunction %2 119 %6 = OpTypeInt 32 1 120 %7 = OpTypeVector %6 2 121 %8 = OpTypePointer Function %7 122 %10 = OpTypeFloat 32 123 %11 = OpTypeVector %10 4 124 %12 = OpTypePointer Input %11 125 %13 = OpVariable %12 Input 126 %14 = OpTypeVector %10 2 127 %18 = OpTypePointer Function %6 128 %20 = OpTypeInt 32 0 129 %21 = OpConstant %20 0 130 %24 = OpConstant %6 5 131 %26 = OpConstant %20 1 132 %32 = OpConstant %6 10 133 %42 = OpConstant %6 3 134 %43 = OpTypeBool 135 %45 = OpTypePointer Function %11 136 %47 = OpTypeImage %10 2D 0 0 0 1 Unknown 137 %48 = OpTypeSampledImage %47 138 %49 = OpTypePointer UniformConstant %48 139 %50 = OpVariable %49 UniformConstant 140 %52 = OpConstant %10 1 141 %53 = OpConstantComposite %14 %52 %52 142 %60 = OpTypePointer Function %10 143 %63 = OpConstant %10 2 144 %65 = OpConstant %6 4 145 %69 = OpConstant %6 0 146 %76 = OpTypePointer Output %11 147 %77 = OpVariable %76 Output 148 %78 = OpConstant %20 4 149 %79 = OpTypeArray %11 %78 150 %80 = OpConstant %10 0 151 %81 = OpConstantComposite %11 %52 %80 %80 %52 152 %82 = OpConstantComposite %79 %81 %81 %81 %81 153 %84 = OpTypePointer Function %79 154 %89 = OpConstantComposite %11 %80 %80 %80 %80 155 %4 = OpFunction %2 None %3 156 %5 = OpLabel 157 %9 = OpVariable %8 Function 158 %19 = OpVariable %18 Function 159 %46 = OpVariable %45 Function 160 %85 = OpVariable %84 Function 161 %15 = OpLoad %11 %13 162 %16 = OpVectorShuffle %14 %15 %15 0 1 163 %17 = OpConvertFToS %7 %16 164 OpStore %9 %17 165 %22 = OpAccessChain %18 %9 %21 166 %23 = OpLoad %6 %22 167 %25 = OpBitwiseAnd %6 %23 %24 168 %27 = OpAccessChain %18 %9 %26 169 %28 = OpLoad %6 %27 170 %29 = OpBitwiseAnd %6 %28 %24 171 %30 = OpAccessChain %18 %9 %21 172 %31 = OpLoad %6 %30 173 %33 = OpBitwiseAnd %6 %31 %32 174 %34 = OpBitwiseOr %6 %29 %33 175 %35 = OpIAdd %6 %25 %34 176 OpStore %19 %35 177 OpBranch %36 178 %36 = OpLabel 179 OpLoopMerge %38 %39 None 180 OpBranch %40 181 %40 = OpLabel 182 %41 = OpLoad %6 %19 183 %44 = OpSGreaterThan %43 %41 %42 184 OpBranchConditional %44 %37 %38 185 %37 = OpLabel 186 %51 = OpLoad %48 %50 187 %54 = OpImageSampleImplicitLod %11 %51 %53 188 OpStore %46 %54 189 OpBranch %55 190 %55 = OpLabel 191 OpLoopMerge %57 %58 None 192 OpBranch %59 193 %59 = OpLabel 194 %61 = OpAccessChain %60 %46 %21 195 %62 = OpLoad %10 %61 196 %64 = OpFOrdGreaterThan %43 %62 %63 197 OpBranchConditional %64 %56 %57 198 %56 = OpLabel 199 OpBranch %58 200 %58 = OpLabel 201 OpBranch %55 202 %57 = OpLabel 203 %66 = OpLoad %6 %19 204 %67 = OpISub %6 %66 %65 205 OpStore %19 %67 206 OpBranch %39 207 %39 = OpLabel 208 OpBranch %36 209 %38 = OpLabel 210 %68 = OpLoad %6 %19 211 %70 = OpSGreaterThanEqual %43 %68 %69 212 %71 = OpLoad %6 %19 213 %72 = OpSLessThan %43 %71 %65 214 %73 = OpLogicalAnd %43 %70 %72 215 OpSelectionMerge %75 None 216 OpBranchConditional %73 %74 %88 217 %74 = OpLabel 218 %83 = OpLoad %6 %19 219 OpStore %85 %82 220 %86 = OpAccessChain %45 %85 %83 221 %87 = OpLoad %11 %86 222 OpStore %77 %87 223 OpBranch %75 224 %88 = OpLabel 225 OpStore %77 %89 226 OpBranch %75 227 %75 = OpLabel 228 OpReturn 229 OpFunctionEnd 230END 231 232# uniforms for variant 233 234# GLF_dead6tex 235SAMPLER variant_GLF_dead6tex 236 237 238BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM 239 240PIPELINE graphics variant_pipeline 241 ATTACH variant_vertex_shader 242 ATTACH variant_fragment_shader 243 FRAMEBUFFER_SIZE 256 256 244 BIND BUFFER variant_framebuffer AS color LOCATION 0 245 BIND BUFFER default_texture AS combined_image_sampler SAMPLER variant_GLF_dead6tex DESCRIPTOR_SET 0 BINDING 0 246END 247CLEAR_COLOR variant_pipeline 0 0 0 255 248 249CLEAR variant_pipeline 250RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 256 256 251 252EXPECT variant_framebuffer IDX 0 0 SIZE 256 256 EQ_RGBA 255 0 0 255 253