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