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 SPIR-V reader 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 gl_FragCoord.x * (1.0 / 256.0), 36 (int(gl_FragCoord.x) ^ int(gl_FragCoord.y)) * (1.0 / 256.0), 37 gl_FragCoord.y * (1.0 / 256.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# #define _int_0 _GLF_uniform_int_values[0] 59# #define _int_1 _GLF_uniform_int_values[1] 60# 61# precision highp int; 62# precision highp float; 63# 64# // Contents of _GLF_uniform_int_values: [0, 1] 65# layout(set = 0, binding = 0) uniform buf0 66# { 67# int _GLF_uniform_int_values[2]; 68# }; 69# 70# layout(set = 0, binding = 1) uniform sampler2D tex; 71# layout(location = 0) out vec4 _GLF_color; 72# 73# vec4 func(sampler2D s) 74# { 75# return texture(s, vec2(_int_0)); 76# } 77# 78# void main() 79# { 80# // Always true. 81# if (func(tex) == vec4(_int_0, _int_0, _int_0, _int_1)) 82# { 83# _GLF_color = vec4(_int_1, _int_0, _int_0, _int_1); 84# } 85# else 86# { 87# _GLF_color = vec4(_int_0); 88# } 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: 78 95; Schema: 0 96 OpCapability Shader 97 %1 = OpExtInstImport "GLSL.std.450" 98 OpMemoryModel Logical GLSL450 99 OpEntryPoint Fragment %4 "main" %59 100 OpExecutionMode %4 OriginUpperLeft 101 OpSource ESSL 320 102 OpName %4 "main" 103 OpName %13 "func(s21;" 104 OpName %12 "s" 105 OpName %20 "buf0" 106 OpMemberName %20 0 "_GLF_uniform_int_values" 107 OpName %22 "" 108 OpName %36 "tex" 109 OpName %59 "_GLF_color" 110 OpDecorate %12 RelaxedPrecision 111 OpDecorate %15 RelaxedPrecision 112 OpDecorate %19 ArrayStride 16 113 OpMemberDecorate %20 0 Offset 0 114 OpDecorate %20 Block 115 OpDecorate %22 DescriptorSet 0 116 OpDecorate %22 Binding 0 117 OpDecorate %27 RelaxedPrecision 118 OpDecorate %29 RelaxedPrecision 119 OpDecorate %30 RelaxedPrecision 120 OpDecorate %36 RelaxedPrecision 121 OpDecorate %36 DescriptorSet 0 122 OpDecorate %36 Binding 1 123 OpDecorate %59 Location 0 124 %2 = OpTypeVoid 125 %3 = OpTypeFunction %2 126 %6 = OpTypeFloat 32 127 %7 = OpTypeImage %6 2D 0 0 0 1 Unknown 128 %8 = OpTypeSampledImage %7 129 %9 = OpTypePointer UniformConstant %8 130 %10 = OpTypeVector %6 4 131 %11 = OpTypeFunction %10 %9 132 %16 = OpTypeInt 32 1 133 %17 = OpTypeInt 32 0 134 %18 = OpConstant %17 2 135 %19 = OpTypeArray %16 %18 136 %20 = OpTypeStruct %19 137 %21 = OpTypePointer Uniform %20 138 %22 = OpVariable %21 Uniform 139 %23 = OpConstant %16 0 140 %24 = OpTypePointer Uniform %16 141 %28 = OpTypeVector %6 2 142 %31 = OpTypePointer Function %10 143 %36 = OpVariable %9 UniformConstant 144 %47 = OpConstant %16 1 145 %52 = OpTypeBool 146 %53 = OpTypeVector %52 4 147 %58 = OpTypePointer Output %10 148 %59 = OpVariable %58 Output 149 %4 = OpFunction %2 None %3 150 %5 = OpLabel 151 %37 = OpFunctionCall %10 %13 %36 152 %38 = OpAccessChain %24 %22 %23 %23 153 %39 = OpLoad %16 %38 154 %40 = OpConvertSToF %6 %39 155 %41 = OpAccessChain %24 %22 %23 %23 156 %42 = OpLoad %16 %41 157 %43 = OpConvertSToF %6 %42 158 %44 = OpAccessChain %24 %22 %23 %23 159 %45 = OpLoad %16 %44 160 %46 = OpConvertSToF %6 %45 161 %48 = OpAccessChain %24 %22 %23 %47 162 %49 = OpLoad %16 %48 163 %50 = OpConvertSToF %6 %49 164 %51 = OpCompositeConstruct %10 %40 %43 %46 %50 165 %54 = OpFOrdEqual %53 %37 %51 166 %55 = OpAll %52 %54 167 OpSelectionMerge %57 None 168 OpBranchConditional %55 %56 %73 169 %56 = OpLabel 170 %60 = OpAccessChain %24 %22 %23 %47 171 %61 = OpLoad %16 %60 172 %62 = OpConvertSToF %6 %61 173 %63 = OpAccessChain %24 %22 %23 %23 174 %64 = OpLoad %16 %63 175 %65 = OpConvertSToF %6 %64 176 %66 = OpAccessChain %24 %22 %23 %23 177 %67 = OpLoad %16 %66 178 %68 = OpConvertSToF %6 %67 179 %69 = OpAccessChain %24 %22 %23 %47 180 %70 = OpLoad %16 %69 181 %71 = OpConvertSToF %6 %70 182 %72 = OpCompositeConstruct %10 %62 %65 %68 %71 183 OpStore %59 %72 184 OpBranch %57 185 %73 = OpLabel 186 %74 = OpAccessChain %24 %22 %23 %23 187 %75 = OpLoad %16 %74 188 %76 = OpConvertSToF %6 %75 189 %77 = OpCompositeConstruct %10 %76 %76 %76 %76 190 OpStore %59 %77 191 OpBranch %57 192 %57 = OpLabel 193 OpReturn 194 OpFunctionEnd 195 %13 = OpFunction %10 None %11 196 %12 = OpFunctionParameter %9 197 %14 = OpLabel 198 %32 = OpVariable %31 Function 199 %15 = OpLoad %8 %12 200 %25 = OpAccessChain %24 %22 %23 %23 201 %26 = OpLoad %16 %25 202 %27 = OpConvertSToF %6 %26 203 %29 = OpCompositeConstruct %28 %27 %27 204 %30 = OpImageSampleImplicitLod %10 %15 %29 205 OpStore %32 %30 206 %33 = OpLoad %10 %32 207 OpReturnValue %33 208 OpFunctionEnd 209END 210 211# uniforms for variant 212 213# tex 214SAMPLER variant_tex 215 216# _GLF_uniform_int_values 217BUFFER variant__GLF_uniform_int_values DATA_TYPE int32[] STD140 DATA 218 0 1 219END 220 221BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM 222 223PIPELINE graphics variant_pipeline 224 ATTACH variant_vertex_shader 225 ATTACH variant_fragment_shader 226 FRAMEBUFFER_SIZE 256 256 227 BIND BUFFER variant_framebuffer AS color LOCATION 0 228 BIND BUFFER default_texture AS combined_image_sampler SAMPLER variant_tex DESCRIPTOR_SET 0 BINDING 1 229 BIND BUFFER variant__GLF_uniform_int_values AS uniform DESCRIPTOR_SET 0 BINDING 0 230END 231CLEAR_COLOR variant_pipeline 0 0 0 255 232 233CLEAR variant_pipeline 234RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 256 256 235 236EXPECT variant_framebuffer IDX 0 0 SIZE 256 256 EQ_RGBA 255 0 0 255 237