2022-11-20 03:45:42 +11:00
|
|
|
// SPDX-License-Identifier: Apache-2.0 OR MIT OR Unlicense
|
2022-10-25 08:53:12 +11:00
|
|
|
|
2022-11-03 12:07:32 +11:00
|
|
|
#import config
|
2022-10-28 01:27:46 +11:00
|
|
|
#import pathtag
|
2022-10-25 08:53:12 +11:00
|
|
|
|
|
|
|
@group(0) @binding(0)
|
2022-11-30 12:23:12 +11:00
|
|
|
var<uniform> config: Config;
|
2022-10-25 08:53:12 +11:00
|
|
|
|
|
|
|
@group(0) @binding(1)
|
2022-11-03 12:07:32 +11:00
|
|
|
var<storage> scene: array<u32>;
|
|
|
|
|
|
|
|
@group(0) @binding(2)
|
2022-10-25 08:53:12 +11:00
|
|
|
var<storage, read_write> reduced: array<TagMonoid>;
|
|
|
|
|
|
|
|
let LG_WG_SIZE = 8u;
|
|
|
|
let WG_SIZE = 256u;
|
|
|
|
|
|
|
|
var<workgroup> sh_scratch: array<TagMonoid, WG_SIZE>;
|
|
|
|
|
|
|
|
@compute @workgroup_size(256)
|
|
|
|
fn main(
|
|
|
|
@builtin(global_invocation_id) global_id: vec3<u32>,
|
|
|
|
@builtin(local_invocation_id) local_id: vec3<u32>,
|
|
|
|
) {
|
|
|
|
let ix = global_id.x;
|
2022-11-03 12:07:32 +11:00
|
|
|
let tag_word = scene[config.pathtag_base + ix];
|
2022-10-25 08:53:12 +11:00
|
|
|
var agg = reduce_tag(tag_word);
|
|
|
|
sh_scratch[local_id.x] = agg;
|
|
|
|
for (var i = 0u; i < firstTrailingBit(WG_SIZE); i += 1u) {
|
|
|
|
workgroupBarrier();
|
|
|
|
if local_id.x + (1u << i) < WG_SIZE {
|
|
|
|
let other = sh_scratch[local_id.x + (1u << i)];
|
|
|
|
agg = combine_tag_monoid(agg, other);
|
|
|
|
}
|
|
|
|
workgroupBarrier();
|
|
|
|
sh_scratch[local_id.x] = agg;
|
|
|
|
}
|
|
|
|
if local_id.x == 0u {
|
|
|
|
reduced[ix >> LG_WG_SIZE] = agg;
|
|
|
|
}
|
2022-10-28 01:27:46 +11:00
|
|
|
}
|