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 variant_vertex_shader PASSTHROUGH 25 26# variant_fragment_shader is derived from the following GLSL: 27# #version 320 es 28# #define _int_0 _GLF_uniform_int_values[0] 29# #define _int_1 _GLF_uniform_int_values[1] 30# #define _uint_5 _GLF_uniform_uint_values[0] 31# #define _float_0_0 _GLF_uniform_float_values[0] 32# 33# precision highp int; 34# precision highp float; 35# 36# // Contents of _GLF_uniform_float_values: 0.0 37# layout(set = 0, binding = 0) uniform buf0 38# { 39# float _GLF_uniform_float_values[1]; 40# }; 41# 42# // Contents of _GLF_uniform_uint_values: 5 43# layout(set = 0, binding = 1) uniform buf1 44# { 45# uint _GLF_uniform_uint_values[1]; 46# }; 47# 48# // Contents of _GLF_uniform_int_values: [0, 1] 49# layout(set = 0, binding = 2) uniform buf2 50# { 51# int _GLF_uniform_int_values[2]; 52# }; 53# 54# layout(location = 0) out vec4 _GLF_color; 55# 56# void main() 57# { 58# uint a = 0u; 59# int b = _int_1; 60# 61# // Always false. 62# if (gl_FragCoord.x < _float_0_0) 63# { 64# // Modulo of zero is undefined, but this is never executed. 65# b = int(_uint_5 % a); 66# } 67# 68# // Always true. 69# if (b == _int_1) 70# { 71# _GLF_color = vec4(_int_1, _int_0, _int_0, _int_1); 72# } 73# else 74# { 75# _GLF_color = vec4(_int_0); 76# } 77# } 78SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0 79; SPIR-V 80; Version: 1.0 81; Generator: Khronos Glslang Reference Front End; 10 82; Bound: 78 83; Schema: 0 84 OpCapability Shader 85 %1 = OpExtInstImport "GLSL.std.450" 86 OpMemoryModel Logical GLSL450 87 OpEntryPoint Fragment %4 "main" %26 %59 88 OpExecutionMode %4 OriginUpperLeft 89 OpSource ESSL 320 90 OpName %4 "main" 91 OpName %8 "a" 92 OpName %12 "b" 93 OpName %15 "buf2" 94 OpMemberName %15 0 "_GLF_uniform_int_values" 95 OpName %17 "" 96 OpName %26 "gl_FragCoord" 97 OpName %32 "buf0" 98 OpMemberName %32 0 "_GLF_uniform_float_values" 99 OpName %34 "" 100 OpName %43 "buf1" 101 OpMemberName %43 0 "_GLF_uniform_uint_values" 102 OpName %45 "" 103 OpName %59 "_GLF_color" 104 OpDecorate %14 ArrayStride 16 105 OpMemberDecorate %15 0 Offset 0 106 OpDecorate %15 Block 107 OpDecorate %17 DescriptorSet 0 108 OpDecorate %17 Binding 2 109 OpDecorate %26 BuiltIn FragCoord 110 OpDecorate %31 ArrayStride 16 111 OpMemberDecorate %32 0 Offset 0 112 OpDecorate %32 Block 113 OpDecorate %34 DescriptorSet 0 114 OpDecorate %34 Binding 0 115 OpDecorate %42 ArrayStride 16 116 OpMemberDecorate %43 0 Offset 0 117 OpDecorate %43 Block 118 OpDecorate %45 DescriptorSet 0 119 OpDecorate %45 Binding 1 120 OpDecorate %59 Location 0 121 %2 = OpTypeVoid 122 %3 = OpTypeFunction %2 123 %6 = OpTypeInt 32 0 124 %7 = OpTypePointer Function %6 125 %9 = OpConstant %6 0 126 %10 = OpTypeInt 32 1 127 %11 = OpTypePointer Function %10 128 %13 = OpConstant %6 2 129 %14 = OpTypeArray %10 %13 130 %15 = OpTypeStruct %14 131 %16 = OpTypePointer Uniform %15 132 %17 = OpVariable %16 Uniform 133 %18 = OpConstant %10 0 134 %19 = OpConstant %10 1 135 %20 = OpTypePointer Uniform %10 136 %23 = OpTypeFloat 32 137 %24 = OpTypeVector %23 4 138 %25 = OpTypePointer Input %24 139 %26 = OpVariable %25 Input 140 %27 = OpTypePointer Input %23 141 %30 = OpConstant %6 1 142 %31 = OpTypeArray %23 %30 143 %32 = OpTypeStruct %31 144 %33 = OpTypePointer Uniform %32 145 %34 = OpVariable %33 Uniform 146 %35 = OpTypePointer Uniform %23 147 %38 = OpTypeBool 148 %42 = OpTypeArray %6 %30 149 %43 = OpTypeStruct %42 150 %44 = OpTypePointer Uniform %43 151 %45 = OpVariable %44 Uniform 152 %46 = OpTypePointer Uniform %6 153 %58 = OpTypePointer Output %24 154 %59 = OpVariable %58 Output 155 %4 = OpFunction %2 None %3 156 %5 = OpLabel 157 %8 = OpVariable %7 Function 158 %12 = OpVariable %11 Function 159 OpStore %8 %9 160 %21 = OpAccessChain %20 %17 %18 %19 161 %22 = OpLoad %10 %21 162 OpStore %12 %22 163 %28 = OpAccessChain %27 %26 %9 164 %29 = OpLoad %23 %28 165 %36 = OpAccessChain %35 %34 %18 %18 166 %37 = OpLoad %23 %36 167 %39 = OpFOrdLessThan %38 %29 %37 168 OpSelectionMerge %41 None 169 OpBranchConditional %39 %40 %41 170 %40 = OpLabel 171 %47 = OpAccessChain %46 %45 %18 %18 172 %48 = OpLoad %6 %47 173 %49 = OpLoad %6 %8 174 %50 = OpUMod %6 %48 %49 175 %51 = OpBitcast %10 %50 176 OpStore %12 %51 177 OpBranch %41 178 %41 = OpLabel 179 %52 = OpLoad %10 %12 180 %53 = OpAccessChain %20 %17 %18 %19 181 %54 = OpLoad %10 %53 182 %55 = OpIEqual %38 %52 %54 183 OpSelectionMerge %57 None 184 OpBranchConditional %55 %56 %73 185 %56 = OpLabel 186 %60 = OpAccessChain %20 %17 %18 %19 187 %61 = OpLoad %10 %60 188 %62 = OpConvertSToF %23 %61 189 %63 = OpAccessChain %20 %17 %18 %18 190 %64 = OpLoad %10 %63 191 %65 = OpConvertSToF %23 %64 192 %66 = OpAccessChain %20 %17 %18 %18 193 %67 = OpLoad %10 %66 194 %68 = OpConvertSToF %23 %67 195 %69 = OpAccessChain %20 %17 %18 %19 196 %70 = OpLoad %10 %69 197 %71 = OpConvertSToF %23 %70 198 %72 = OpCompositeConstruct %24 %62 %65 %68 %71 199 OpStore %59 %72 200 OpBranch %57 201 %73 = OpLabel 202 %74 = OpAccessChain %20 %17 %18 %18 203 %75 = OpLoad %10 %74 204 %76 = OpConvertSToF %23 %75 205 %77 = OpCompositeConstruct %24 %76 %76 %76 %76 206 OpStore %59 %77 207 OpBranch %57 208 %57 = OpLabel 209 OpReturn 210 OpFunctionEnd 211END 212 213# uniforms for variant 214 215# _GLF_uniform_int_values 216BUFFER variant__GLF_uniform_int_values DATA_TYPE int32[] STD140 DATA 217 0 1 218END 219# _GLF_uniform_uint_values 220BUFFER variant__GLF_uniform_uint_values DATA_TYPE int32[] STD140 DATA 221 5 222END 223# _GLF_uniform_float_values 224BUFFER variant__GLF_uniform_float_values DATA_TYPE float[] STD140 DATA 225 0.0 226END 227 228BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM 229 230PIPELINE graphics variant_pipeline 231 ATTACH variant_vertex_shader 232 ATTACH variant_fragment_shader 233 FRAMEBUFFER_SIZE 256 256 234 BIND BUFFER variant_framebuffer AS color LOCATION 0 235 BIND BUFFER variant__GLF_uniform_int_values AS uniform DESCRIPTOR_SET 0 BINDING 2 236 BIND BUFFER variant__GLF_uniform_uint_values AS uniform DESCRIPTOR_SET 0 BINDING 1 237 BIND BUFFER variant__GLF_uniform_float_values AS uniform DESCRIPTOR_SET 0 BINDING 0 238END 239CLEAR_COLOR variant_pipeline 0 0 0 255 240 241CLEAR variant_pipeline 242RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 256 256 243 244EXPECT variant_framebuffer IDX 0 0 SIZE 256 256 EQ_RGBA 255 0 0 255 245