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, imfmtc4) writeonly uniform unfp image3D top_blob_3d;
47
layout (binding = 0) readonly buffer bottom_blob { sfp bottom_blob_data[]; };
48
layout (binding = 1) writeonly buffer top_blob { sfpvec8 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(outw) || gy >= psc(outh) * psc(outd) || gz >= psc(outc))
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);
150
y4 = gz * 8 + ivec4(0, 1, 2, 3);
157
x4 = 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(outh);
203
int yh = gy % psc(outh);
209
y4 = ivec4(yd * psc(h) + yh);
211
z4 = gz * 8 + ivec4(0, 1, 2, 3);
218
y4 = ivec4(yd * psc(h) + gx);
220
z4 = gz * 8 + ivec4(0, 1, 2, 3);
227
y4 = ivec4(yh * psc(h) + yd);
229
z4 = gz * 8 + ivec4(0, 1, 2, 3);
236
y4 = ivec4(gx * psc(h) + yd);
238
z4 = gz * 8 + ivec4(0, 1, 2, 3);
245
y4 = ivec4(yh * psc(h) + gx);
247
z4 = gz * 8 + ivec4(0, 1, 2, 3);
254
y4 = ivec4(gx * psc(h) + yh);
256
z4 = gz * 8 + ivec4(0, 1, 2, 3);
263
y4 = (gz * 8 + ivec4(0, 1, 2, 3)) * psc(h) + yh;
264
yy4 = y4 + 4 * psc(h);
272
y4 = (gz * 8 + ivec4(0, 1, 2, 3)) * psc(h) + gx;
273
yy4 = y4 + 4 * psc(h);
281
y4 = (gz * 8 + ivec4(0, 1, 2, 3)) * psc(h) + yd;
282
yy4 = y4 + 4 * psc(h);
290
y4 = (gz * 8 + ivec4(0, 1, 2, 3)) * psc(h) + yd;
291
yy4 = y4 + 4 * psc(h);
295
if (order_type == 10)
299
y4 = (gz * 8 + ivec4(0, 1, 2, 3)) * psc(h) + gx;
300
yy4 = y4 + 4 * psc(h);
304
if (order_type == 11)
308
y4 = (gz * 8 + ivec4(0, 1, 2, 3)) * psc(h) + yh;
309
yy4 = y4 + 4 * psc(h);
313
if (order_type == 12)
317
y4 = yh * psc(h) + gz * 8 + ivec4(0, 1, 2, 3);
322
if (order_type == 13)
326
y4 = gx * psc(h) + gz * 8 + ivec4(0, 1, 2, 3);
331
if (order_type == 14)
335
y4 = yd * psc(h) + gz * 8 + ivec4(0, 1, 2, 3);
340
if (order_type == 15)
344
y4 = yd * psc(h) + gz * 8 + ivec4(0, 1, 2, 3);
349
if (order_type == 16)
353
y4 = gx * psc(h) + gz * 8 + ivec4(0, 1, 2, 3);
358
if (order_type == 17)
362
y4 = yh * psc(h) + gz * 8 + ivec4(0, 1, 2, 3);
367
if (order_type == 18)
369
x4 = gz * 8 + ivec4(0, 1, 2, 3);
371
y4 = ivec4(yh * psc(h) + gx);
376
if (order_type == 19)
378
x4 = gz * 8 + ivec4(0, 1, 2, 3);
380
y4 = ivec4(gx * psc(h) + yh);
385
if (order_type == 20)
387
x4 = gz * 8 + ivec4(0, 1, 2, 3);
389
y4 = ivec4(yd * psc(h) + gx);
394
if (order_type == 21)
396
x4 = gz * 8 + ivec4(0, 1, 2, 3);
398
y4 = ivec4(yd * psc(h) + yh);
403
if (order_type == 22)
405
x4 = gz * 8 + ivec4(0, 1, 2, 3);
407
y4 = ivec4(gx * psc(h) + yd);
412
if (order_type == 23)
414
x4 = gz * 8 + ivec4(0, 1, 2, 3);
416
y4 = ivec4(yh * psc(h) + yd);
425
v[0].r = image3d_ld1(bottom_blob_3d, ivec3(x4.r, y4.r, z4.r));
426
v[0].g = image3d_ld1(bottom_blob_3d, ivec3(x4.g, y4.g, z4.g));
427
v[0].b = image3d_ld1(bottom_blob_3d, ivec3(x4.b, y4.b, z4.b));
428
v[0].a = image3d_ld1(bottom_blob_3d, ivec3(x4.a, y4.a, z4.a));
429
v[1].r = image3d_ld1(bottom_blob_3d, ivec3(xx4.r, yy4.r, zz4.r));
430
v[1].g = image3d_ld1(bottom_blob_3d, ivec3(xx4.g, yy4.g, zz4.g));
431
v[1].b = image3d_ld1(bottom_blob_3d, ivec3(xx4.b, yy4.b, zz4.b));
432
v[1].a = image3d_ld1(bottom_blob_3d, ivec3(xx4.a, yy4.a, zz4.a));
434
image3d_st8(top_blob_3d, ivec3(gx, gy, gz), v);
436
ivec4 v_offset = z4 * psc(cstep) + y4 * psc(w) + x4;
437
ivec4 vv_offset = zz4 * psc(cstep) + yy4 * psc(w) + xx4;
439
const int gi = gz * psc(outcstep) + gy * psc(outw) + gx;
441
buffer_cp1to8(top_blob_data, gi, bottom_blob_data, v_offset, vv_offset);