summaryrefslogtreecommitdiffstats
path: root/third_party/rust/gfx-backend-metal/shaders/fill.metal
blob: fffe9b4a077ef4deced799d8354e05487c1bada5 (plain)
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
#include <metal_stdlib>
using namespace metal;

typedef struct {
    uint value;
    uint length;
} FillBufferValue;

kernel void cs_fill_buffer(
    device uint *buffer [[ buffer(0) ]],
    constant FillBufferValue &fill [[ buffer(1) ]],
    uint index [[ thread_position_in_grid ]]
) {
    if (index < fill.length) {
        buffer[index] = fill.value;
    }
}

typedef struct {
    uint size;
    uint offsets;
} CopyBufferRange;

kernel void cs_copy_buffer(
    device uchar *dest [[ buffer(0) ]],
    device uchar *source [[ buffer(1) ]],
    constant CopyBufferRange &range [[ buffer(2) ]],
    uint index [[ thread_position_in_grid ]]
) {
    if (index < range.size) {
        dest[(range.offsets>>16) + index] = source[(range.offsets & 0xFFFF) + index];
    }
}