1
// Tencent is pleased to support the open source community by making ncnn available.
3
// Copyright (C) 2022 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
19
struct sfpvec8 { f16vec4 abcd; f16vec4 efgh; };
21
#if NCNN_fp16_arithmetic
22
#extension GL_EXT_shader_explicit_arithmetic_types_float16: require
25
layout (constant_id = 0) const int maxk = 1;
27
#define shape_constant_id_offset 1
28
layout (constant_id = shape_constant_id_offset + 0) const int w = 0;
29
layout (constant_id = shape_constant_id_offset + 1) const int h = 0;
30
layout (constant_id = shape_constant_id_offset + 2) const int c = 0;
31
layout (constant_id = shape_constant_id_offset + 3) const int cstep = 0;
33
layout (constant_id = shape_constant_id_offset + 4) const int outw = 0;
34
layout (constant_id = shape_constant_id_offset + 5) const int outh = 0;
37
layout (binding = 0) uniform unfp sampler3D bottom_blob;
38
layout (binding = 1, imfmtc4) writeonly uniform unfp image3D col_blob;
39
layout (binding = 2) uniform unfp sampler3D weight_blob;
41
layout (binding = 0) readonly buffer bottom_blob { sfp bottom_blob_data[]; };
42
layout (binding = 1) writeonly buffer col_blob { sfpvec8 col_blob_data[]; };
43
layout (binding = 2) readonly buffer weight_blob { sfpvec8 weight_data[]; };
46
layout (push_constant) uniform parameter
59
int gx = int(gl_GlobalInvocationID.x) * 4;
60
int gy = int(gl_GlobalInvocationID.y);
62
if (gx >= psc(outw) || gy >= psc(outh))
65
afpvec8 sum0 = afpvec8(afpvec4(0.f), afpvec4(0.f));
66
afpvec8 sum1 = afpvec8(afpvec4(0.f), afpvec4(0.f));
67
afpvec8 sum2 = afpvec8(afpvec4(0.f), afpvec4(0.f));
68
afpvec8 sum3 = afpvec8(afpvec4(0.f), afpvec4(0.f));
71
ivec4 gx4 = gx + ivec4(0, 1, 2, 3);
73
ivec4 sy4 = gx4 / psc(w);
74
ivec4 sx4 = gx4 % psc(w);
76
for (int z = 0; z < psc(c); z++)
78
afp v0 = image3d_ld1(bottom_blob, ivec3(sx4.r, sy4.r, z));
79
afp v1 = image3d_ld1(bottom_blob, ivec3(sx4.g, sy4.g, z));
80
afp v2 = image3d_ld1(bottom_blob, ivec3(sx4.b, sy4.b, z));
81
afp v3 = image3d_ld1(bottom_blob, ivec3(sx4.a, sy4.a, z));
83
afpvec8 k = image3d_ld8(weight_blob, ivec3(z, gy, 0));
100
int w_offset = gy * psc(c);
102
for (int z = 0; z < psc(c); z++)
104
afp v0 = buffer_ld1(bottom_blob_data, v_offset + 0);
105
afp v1 = buffer_ld1(bottom_blob_data, v_offset + 1);
106
afp v2 = buffer_ld1(bottom_blob_data, v_offset + 2);
107
afp v3 = buffer_ld1(bottom_blob_data, v_offset + 3);
109
afpvec8 k = buffer_ld8(weight_data, w_offset);
112
sum0[0] += v0 * k[0];
113
sum0[1] += v0 * k[1];
115
sum1[0] += v1 * k[0];
116
sum1[1] += v1 * k[1];
118
sum2[0] += v2 * k[0];
119
sum2[1] += v2 * k[1];
121
sum3[0] += v3 * k[0];
122
sum3[1] += v3 * k[1];
124
v_offset += psc(cstep);
130
image3d_st8(col_blob, ivec3(gx4.r, gy, 0), sum0);
131
image3d_st8(col_blob, ivec3(gx4.g, gy, 0), sum1);
132
image3d_st8(col_blob, ivec3(gx4.b, gy, 0), sum2);
133
image3d_st8(col_blob, ivec3(gx4.a, gy, 0), sum3);
135
const int gi = gy * psc(outw) + gx;
137
buffer_st8(col_blob_data, gi, sum0);
138
if (gx + 1 < psc(outw)) buffer_st8(col_blob_data, gi + 1, sum1);
139
if (gx + 2 < psc(outw)) buffer_st8(col_blob_data, gi + 2, sum2);
140
if (gx + 3 < psc(outw)) buffer_st8(col_blob_data, gi + 3, sum3);