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