Elffuss BraidHub

kikocis/ncnn public

master · 3.1 KiBRawPermalink
1// Tencent is pleased to support the open source community by making ncnn available.
2//
3// Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
4//
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
7//
8// https://opensource.org/licenses/BSD-3-Clause
9//
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.
14
15#version 450
16
17#if NCNN_fp16_storage
18#extension GL_EXT_shader_16bit_storage: require
19#endif
20#if NCNN_fp16_arithmetic
21#extension GL_EXT_shader_explicit_arithmetic_types_float16: require
22#endif
23
24layout (constant_id = 0) const int align_corner = 0;
25
26#define shape_constant_id_offset 1
27layout (constant_id = shape_constant_id_offset + 0) const int w = 0;
28layout (constant_id = shape_constant_id_offset + 1) const int outw = 0;
29
30layout (binding = 0) writeonly buffer alpha_blob { sfpvec4 alpha_blob_data[]; };
31layout (binding = 1) writeonly buffer xofs_blob { int xofs_blob_data[]; };
32
33layout (push_constant) uniform parameter
34{
35 int w;
36 int outw;
37 float scale;
38} p;
39
40void main()
41{
42 int gx = int(gl_GlobalInvocationID.x);
43 int gy = int(gl_GlobalInvocationID.y);
44 int gz = int(gl_GlobalInvocationID.z);
45
46 if (gx >= psc(outw) || gy >= 1 || gz >= 1)
47 return;
48
49 afp fx;
50 if (align_corner == 1)
51 {
52 fx = afp(gx) * afp(p.scale);
53 }
54 else
55 {
56 fx = (afp(gx) + afp(0.5f)) * afp(p.scale) - afp(0.5f);
57 }
58
59 int sx = int(floor(fx));
60 fx -= afp(sx);
61
62 // interpolate_cubic(fx, coeffs);
63 afpvec4 coeffs;
64 {
65 const afp A = afp(-0.75f);
66
67 afp fx0 = fx + afp(1.f);
68 afp fx1 = fx;
69 afp fx2 = afp(1.f) - fx;
70 // afp fx3 = afp(2.f) - fx;
71
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;
76 }
77
78 if (sx <= -1)
79 {
80 sx = 1;
81 coeffs.r = afp(1.f) - coeffs.a;
82 coeffs.g = coeffs.a;
83 coeffs.b = afp(0.f);
84 coeffs.a = afp(0.f);
85 }
86 if (sx == 0)
87 {
88 sx = 1;
89 coeffs.r = coeffs.r + coeffs.g;
90 coeffs.g = coeffs.b;
91 coeffs.b = coeffs.a;
92 coeffs.a = afp(0.f);
93 }
94 if (sx == psc(w) - 2)
95 {
96 sx = psc(w) - 3;
97 coeffs.a = coeffs.b + coeffs.a;
98 coeffs.b = coeffs.g;
99 coeffs.g = coeffs.r;
100 coeffs.r = afp(0.f);
101 }
102 if (sx >= psc(w) - 1)
103 {
104 sx = psc(w) - 3;
105 coeffs.a = afp(1.f) - coeffs.r;
106 coeffs.b = coeffs.r;
107 coeffs.g = afp(0.f);
108 coeffs.r = afp(0.f);
109 }
110
111 buffer_st4(alpha_blob_data, gx, coeffs);
112
113 xofs_blob_data[gx] = sx;
114}