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 batch = 1;
27
#define shape_constant_id_offset 1
28
layout (constant_id = shape_constant_id_offset + 0) const int c = 0;
29
layout (constant_id = shape_constant_id_offset + 1) const int cstep = 0;
31
layout (constant_id = shape_constant_id_offset + 2) const int outw = 0;
32
layout (constant_id = shape_constant_id_offset + 3) const int outc = 0;
33
layout (constant_id = shape_constant_id_offset + 4) const int outcstep = 0;
36
layout (binding = 0) uniform unfp sampler3D bottom_tm_blob;
37
layout (binding = 1, imfmtc4) writeonly uniform unfp image3D top_tm_blob;
38
layout (binding = 2) uniform unfp sampler3D weight_tm_blob;
40
layout (binding = 0) readonly buffer bottom_tm_blob { sfp bottom_tm_blob_data[]; };
41
layout (binding = 1) writeonly buffer top_tm_blob { sfpvec8 top_tm_blob_data[]; };
42
layout (binding = 2) readonly buffer weight_tm_blob { sfpvec8 weight_tm_data[]; };
45
layout (push_constant) uniform parameter
57
int gx = int(gl_GlobalInvocationID.x) * 4;
58
int gy = int(gl_GlobalInvocationID.y);
59
int gz = int(gl_GlobalInvocationID.z);
61
if (gx >= psc(outw) || gy >= psc(outc) || gz >= batch)
64
afpvec8 sum0 = afpvec8(afpvec4(0.f), afpvec4(0.f));
65
afpvec8 sum1 = afpvec8(afpvec4(0.f), afpvec4(0.f));
66
afpvec8 sum2 = afpvec8(afpvec4(0.f), afpvec4(0.f));
67
afpvec8 sum3 = afpvec8(afpvec4(0.f), afpvec4(0.f));
70
for (int z = 0; z < psc(c); z++)
72
afp v0 = image3d_ld1(bottom_tm_blob, ivec3(gx + 0, z, gz));
73
afp v1 = image3d_ld1(bottom_tm_blob, ivec3(gx + 1, z, gz));
74
afp v2 = image3d_ld1(bottom_tm_blob, ivec3(gx + 2, z, gz));
75
afp v3 = image3d_ld1(bottom_tm_blob, ivec3(gx + 3, z, gz));
77
afpvec8 k = image3d_ld8(weight_tm_blob, ivec3(z, gy, gz));
93
int v_offset = gz * psc(cstep) + gx;
94
int w_offset = gz * psc(c) * psc(outc) + gy * psc(c);
96
for (int z = 0; z < psc(c); z++)
98
afp v0 = buffer_ld1(bottom_tm_blob_data, v_offset + 0);
99
afp v1 = buffer_ld1(bottom_tm_blob_data, v_offset + 1);
100
afp v2 = buffer_ld1(bottom_tm_blob_data, v_offset + 2);
101
afp v3 = buffer_ld1(bottom_tm_blob_data, v_offset + 3);
103
afpvec8 k = buffer_ld8(weight_tm_data, w_offset);
106
sum0[0] += v0 * k[0];
107
sum0[1] += v0 * k[1];
109
sum1[0] += v1 * k[0];
110
sum1[1] += v1 * k[1];
112
sum2[0] += v2 * k[0];
113
sum2[1] += v2 * k[1];
115
sum3[0] += v3 * k[0];
116
sum3[1] += v3 * k[1];
118
v_offset += psc(outw);
124
image3d_st8(top_tm_blob, ivec3(gx + 0, gy, gz), sum0);
125
image3d_st8(top_tm_blob, ivec3(gx + 1, gy, gz), sum1);
126
image3d_st8(top_tm_blob, ivec3(gx + 2, gy, gz), sum2);
127
image3d_st8(top_tm_blob, ivec3(gx + 3, gy, gz), sum3);
129
int gi = gz * psc(outcstep) + gy * psc(outw) + gx;
131
buffer_st8(top_tm_blob_data, gi + 0, sum0);
132
if (gx + 1 < psc(outw)) buffer_st8(top_tm_blob_data, gi + 1, sum1);
133
if (gx + 2 < psc(outw)) buffer_st8(top_tm_blob_data, gi + 2, sum2);
134
if (gx + 3 < psc(outw)) buffer_st8(top_tm_blob_data, gi + 3, sum3);