1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
groupshared float scratch[64];
struct Params {
uint count;
float scale;
};
RWStructuredBuffer<Params> params : register(u0, space0);
struct DataBuffer {
float values[64];
};
RWStructuredBuffer<DataBuffer> data : register(u1, space0);
[numthreads(64, 1, 1)]
void main(uint3 global_id : SV_DispatchThreadID, uint3 local_id : SV_GroupThreadID) {
uint idx = local_id.x;
scratch[idx] = (data.values[idx] * params.scale);
GroupMemoryBarrierWithGroupSync();
if ((idx < 32)) {
scratch[idx] = (scratch[idx] + scratch[(idx + 32)]);
}
GroupMemoryBarrierWithGroupSync();
data.values[idx] = scratch[idx];
}