1
// Tencent is pleased to support the open source community by making ncnn available.
3
// Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
5
// Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
6
// in compliance with the License. You may obtain a copy of the License at
8
// https://opensource.org/licenses/BSD-3-Clause
10
// Unless required by applicable law or agreed to in writing, software distributed
11
// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
12
// CONDITIONS OF ANY KIND, either express or implied. See the License for the
13
// specific language governing permissions and limitations under the License.
18
#extension GL_EXT_shader_16bit_storage: require
20
#if NCNN_fp16_arithmetic
21
#extension GL_EXT_shader_explicit_arithmetic_types_float16: require
24
layout (constant_id = 0) const int align_corner = 0;
26
#define shape_constant_id_offset 1
27
layout (constant_id = shape_constant_id_offset + 0) const int w = 0;
28
layout (constant_id = shape_constant_id_offset + 1) const int outw = 0;
30
layout (binding = 0) writeonly buffer alpha_blob { sfpvec4 alpha_blob_data[]; };
31
layout (binding = 1) writeonly buffer xofs_blob { int xofs_blob_data[]; };
33
layout (push_constant) uniform parameter
42
int gx = int(gl_GlobalInvocationID.x);
43
int gy = int(gl_GlobalInvocationID.y);
44
int gz = int(gl_GlobalInvocationID.z);
46
if (gx >= psc(outw) || gy >= 1 || gz >= 1)
50
if (align_corner == 1)
52
fx = afp(gx) * afp(p.scale);
56
fx = (afp(gx) + afp(0.5f)) * afp(p.scale) - afp(0.5f);
59
int sx = int(floor(fx));
62
// interpolate_cubic(fx, coeffs);
65
const afp A = afp(-0.75f);
67
afp fx0 = fx + afp(1.f);
69
afp fx2 = afp(1.f) - fx;
70
// afp fx3 = afp(2.f) - fx;
72
coeffs.r = A * fx0*fx0*fx0 - afp(5.f)*A * fx0*fx0 + afp(8.f)*A * fx0 - afp(4.f)*A;
73
coeffs.g = (A+afp(2.f)) * fx1*fx1*fx1 - (A+afp(3.f)) * fx1*fx1 + afp(1.f);
74
coeffs.b = (A+afp(2.f)) * fx2*fx2*fx2 - (A+afp(3.f)) * fx2*fx2 + afp(1.f);
75
coeffs.a = afp(1.f) - coeffs.r - coeffs.g - coeffs.b;
81
coeffs.r = afp(1.f) - coeffs.a;
89
coeffs.r = coeffs.r + coeffs.g;
97
coeffs.a = coeffs.b + coeffs.a;
102
if (sx >= psc(w) - 1)
105
coeffs.a = afp(1.f) - coeffs.r;
111
buffer_st4(alpha_blob_data, gx, coeffs);
113
xofs_blob_data[gx] = sx;