Repository navigation
Expand file tree
/
Copy pathrepeat_channel.glsl
More file actions
58 lines (40 loc) · 1.56 KB
/
Copy pathrepeat_channel.glsl
File metadata and controls
58 lines (40 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree.
*/
#version 450 core
#define PRECISION ${PRECISION}
#define VEC4_T ${texel_type(DTYPE)}
layout(std430) buffer;
#include "indexing_utils.h"
layout(set = 0, binding = 0, ${IMAGE_FORMAT[DTYPE]}) uniform PRECISION restrict writeonly ${IMAGE_T[NDIM][DTYPE]} image_out;
layout(set = 0, binding = 1) uniform PRECISION sampler3D image_in;
layout(set = 0, binding = 2) uniform PRECISION restrict RepeatArgs {
// With input_size (n, c_i, h, w) and repeat r
// out_size == (n, c_i * r, h, w)
ivec4 out_sizes;
ivec4 in_sizes;
};
layout(local_size_x_id = 0, local_size_y_id = 1, local_size_z_id = 2) in;
layout(constant_id = 3) const int packed_dim = C_DIM;
void main() {
const ivec3 out_pos = ivec3(gl_GlobalInvocationID);
const ivec4 out_whcn = to_tensor_idx(out_pos, out_sizes, packed_dim);
if (any(greaterThanEqual(out_whcn, out_sizes))) {
return;
}
VEC4_T v;
// Loop over the 4 elements in texel, calculate the corresponding elem, and
// fetch. Not most efficient algorithm because likely we fetch same texel
// multiple times in this loop.
for (int i=0; i<4;i++) {
ivec4 in_whcn = out_whcn;
in_whcn.z = (out_whcn.z + i) % in_sizes.z;
ivec4 in_elem_pos = to_texture_elem_pos(in_whcn, in_sizes, packed_dim);
v[i] = VEC4_T(texelFetch(image_in, in_elem_pos.xyz, 0))[in_elem_pos.w];
}
imageStore(image_out, out_pos, v);
}