1
// Tencent is pleased to support the open source community by making ncnn available.
3
// Copyright (C) 2020 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 order_type = 0;
26
layout (constant_id = 1) const int bugihfa = 0;
28
#define shape_constant_id_offset 2
29
layout (constant_id = shape_constant_id_offset + 0) const int dims = 0;
30
layout (constant_id = shape_constant_id_offset + 1) const int w = 0;
31
layout (constant_id = shape_constant_id_offset + 2) const int h = 0;
32
layout (constant_id = shape_constant_id_offset + 3) const int d = 0;
33
layout (constant_id = shape_constant_id_offset + 4) const int c = 0;
34
layout (constant_id = shape_constant_id_offset + 5) const int cstep = 0;
36
layout (constant_id = shape_constant_id_offset + 6) const int outdims = 0;
37
layout (constant_id = shape_constant_id_offset + 7) const int outw = 0;
38
layout (constant_id = shape_constant_id_offset + 8) const int outh = 0;
39
layout (constant_id = shape_constant_id_offset + 9) const int outd = 0;
40
layout (constant_id = shape_constant_id_offset + 10) const int outc = 0;
41
layout (constant_id = shape_constant_id_offset + 11) const int outcstep = 0;
44
layout (binding = 0) uniform unfp sampler3D bottom_blob_3d;
45
layout (binding = 1, imfmtc1) writeonly uniform unfp image3D top_blob_3d;
47
layout (binding = 0) readonly buffer bottom_blob { sfpvec8 bottom_blob_data[]; };
48
layout (binding = 1) writeonly buffer top_blob { sfp top_blob_data[]; };
51
layout (push_constant) uniform parameter
70
int gx = int(gl_GlobalInvocationID.x);
71
int gy = int(gl_GlobalInvocationID.y);
72
int gz = int(gl_GlobalInvocationID.z);
74
if (gx >= psc(w) || gy >= psc(h) * psc(d) || gz >= psc(c))
98
y4 = gy * 8 + ivec4(0, 1, 2, 3);
103
x4 = gy * 8 + ivec4(0, 1, 2, 3);
109
else if (psc(dims) == 3)
125
z4 = gz * 8 + ivec4(0, 1, 2, 3);
134
z4 = gz * 8 + ivec4(0, 1, 2, 3);
141
y4 = gz * 8 + ivec4(0, 1, 2, 3);
148
x4 = gz * 8 + ivec4(0, 1, 2, 3);
159
y4 = gz * 8 + ivec4(0, 1, 2, 3);
166
x4 = gz * 8 + ivec4(0, 1, 2, 3);
174
else // if (psc(dims) == 4)
202
int yd = gy / psc(h);
203
int yh = gy % psc(h);
211
z4 = gz * 8 + ivec4(0, 1, 2, 3);
218
y4 = ivec4(yd * psc(outh) + gx);
220
z4 = gz * 8 + ivec4(0, 1, 2, 3);
227
y4 = ivec4(yh * psc(outh) + yd);
229
z4 = gz * 8 + ivec4(0, 1, 2, 3);
236
y4 = ivec4(yh * psc(outh) + gx);
238
z4 = gz * 8 + ivec4(0, 1, 2, 3);
245
y4 = ivec4(gx * psc(outh) + yd);
247
z4 = gz * 8 + ivec4(0, 1, 2, 3);
254
y4 = ivec4(gx * psc(outh) + yh);
256
z4 = gz * 8 + ivec4(0, 1, 2, 3);
263
y4 = (gz * 8 + ivec4(0, 1, 2, 3)) * psc(outh) + yh;
264
yy4 = (gz * 8 + ivec4(0, 1, 2, 3) + 4) * psc(outh) + yh;
272
y4 = (gz * 8 + ivec4(0, 1, 2, 3)) * psc(outh) + gx;
273
yy4 = (gz * 8 + ivec4(0, 1, 2, 3) + 4) * psc(outh) + gx;
281
y4 = yh * psc(outh) + gz * 8 + ivec4(0, 1, 2, 3);
288
x4 = gz * 8 + ivec4(0, 1, 2, 3);
290
y4 = ivec4(yh * psc(outh) + gx);
295
if (order_type == 10)
299
y4 = gx * psc(outh) + gz * 8 + ivec4(0, 1, 2, 3);
304
if (order_type == 11)
306
x4 = gz * 8 + ivec4(0, 1, 2, 3);
308
y4 = ivec4(gx * psc(outh) + yh);
313
if (order_type == 12)
317
y4 = (gz * 8 + ivec4(0, 1, 2, 3)) * psc(outh) + yd;
318
yy4 = (gz * 8 + ivec4(0, 1, 2, 3) + 4) * psc(outh) + yd;
322
if (order_type == 13)
326
y4 = (gz * 8 + ivec4(0, 1, 2, 3)) * psc(outh) + gx;
327
yy4 = (gz * 8 + ivec4(0, 1, 2, 3) + 4) * psc(outh) + gx;
331
if (order_type == 14)
335
y4 = yd * psc(outh) + gz * 8 + ivec4(0, 1, 2, 3);
340
if (order_type == 15)
342
x4 = gz * 8 + ivec4(0, 1, 2, 3);
344
y4 = ivec4(yd * psc(outh) + gx);
349
if (order_type == 16)
353
y4 = gx * psc(outh) + gz * 8 + ivec4(0, 1, 2, 3);
358
if (order_type == 17)
360
x4 = gz * 8 + ivec4(0, 1, 2, 3);
362
y4 = ivec4(gx * psc(outh) + yd);
367
if (order_type == 18)
371
y4 = (gz * 8 + ivec4(0, 1, 2, 3)) * psc(outh) + yd;
372
yy4 = (gz * 8 + ivec4(0, 1, 2, 3) + 4) * psc(outh) + yd;
376
if (order_type == 19)
380
y4 = (gz * 8 + ivec4(0, 1, 2, 3)) * psc(outh) + yh;
381
yy4 = (gz * 8 + ivec4(0, 1, 2, 3) + 4) * psc(outh) + yh;
385
if (order_type == 20)
389
y4 = yd * psc(outh) + gz * 8 + ivec4(0, 1, 2, 3);
394
if (order_type == 21)
396
x4 = gz * 8 + ivec4(0, 1, 2, 3);
398
y4 = ivec4(yd * psc(outh) + yh);
403
if (order_type == 22)
407
y4 = yh * psc(outh) + gz * 8 + ivec4(0, 1, 2, 3);
412
if (order_type == 23)
414
x4 = gz * 8 + ivec4(0, 1, 2, 3);
416
y4 = ivec4(yh * psc(outh) + yd);
424
afpvec8 v = image3d_ld8(bottom_blob_3d, ivec3(gx, gy, gz));
426
image3d_st1(top_blob_3d, ivec3(x4.r, y4.r, z4.r), v[0].r);
427
image3d_st1(top_blob_3d, ivec3(x4.g, y4.g, z4.g), v[0].g);
428
image3d_st1(top_blob_3d, ivec3(x4.b, y4.b, z4.b), v[0].b);
429
image3d_st1(top_blob_3d, ivec3(x4.a, y4.a, z4.a), v[0].a);
430
image3d_st1(top_blob_3d, ivec3(xx4.r, yy4.r, zz4.r), v[1].r);
431
image3d_st1(top_blob_3d, ivec3(xx4.g, yy4.g, zz4.g), v[1].g);
432
image3d_st1(top_blob_3d, ivec3(xx4.b, yy4.b, zz4.b), v[1].b);
433
image3d_st1(top_blob_3d, ivec3(xx4.a, yy4.a, zz4.a), v[1].a);
435
ivec4 v_offset = z4 * psc(outcstep) + y4 * psc(outw) + x4;
436
ivec4 vv_offset = zz4 * psc(outcstep) + yy4 * psc(outw) + xx4;
438
int gi = gz * psc(cstep) + gy * psc(w) + gx;
440
buffer_cp8to1(top_blob_data, v_offset, vv_offset, bottom_blob_data, gi);