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>;
|
2022-10-25 08:53:12 +11:00
|
|
|
|
|
|
|
@group(0) @binding(2)
|
2022-11-03 12:07:32 +11:00
|
|
|
var<storage> reduced: array<TagMonoid>;
|
|
|
|
|
|
|
|
@group(0) @binding(3)
|
2022-10-25 08:53:12 +11:00
|
|
|
var<storage, read_write> tag_monoids: array<TagMonoid>;
|
|
|
|
|
|
|
|
let LG_WG_SIZE = 8u;
|
|
|
|
let WG_SIZE = 256u;
|
|
|
|
|
2023-01-06 09:22:14 +11:00
|
|
|
#ifdef small
|
2022-10-25 08:53:12 +11:00
|
|
|
var<workgroup> sh_parent: array<TagMonoid, WG_SIZE>;
|
2023-01-06 09:22:14 +11:00
|
|
|
#endif
|
2022-10-25 08:53:12 +11:00
|
|
|
// These could be combined?
|
|
|
|
var<workgroup> sh_monoid: 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>,
|
|
|
|
@builtin(workgroup_id) wg_id: vec3<u32>,
|
|
|
|
) {
|
2023-01-06 09:22:14 +11:00
|
|
|
#ifdef small
|
2022-10-25 08:53:12 +11:00
|
|
|
var agg = tag_monoid_identity();
|
2022-11-05 15:41:37 +11:00
|
|
|
if local_id.x < wg_id.x {
|
2022-10-25 08:53:12 +11:00
|
|
|
agg = reduced[local_id.x];
|
|
|
|
}
|
|
|
|
sh_parent[local_id.x] = agg;
|
|
|
|
for (var i = 0u; i < LG_WG_SIZE; i += 1u) {
|
|
|
|
workgroupBarrier();
|
2022-11-05 15:41:37 +11:00
|
|
|
if local_id.x + (1u << i) < WG_SIZE {
|
2022-10-25 08:53:12 +11:00
|
|
|
let other = sh_parent[local_id.x + (1u << i)];
|
|
|
|
agg = combine_tag_monoid(agg, other);
|
|
|
|
}
|
|
|
|
workgroupBarrier();
|
|
|
|
sh_parent[local_id.x] = agg;
|
|
|
|
}
|
2023-01-06 09:22:14 +11:00
|
|
|
#endif
|
2022-10-25 08:53:12 +11:00
|
|
|
|
|
|
|
let ix = global_id.x;
|
2022-11-03 12:07:32 +11:00
|
|
|
let tag_word = scene[config.pathtag_base + ix];
|
2023-01-06 09:22:14 +11:00
|
|
|
var agg_part = reduce_tag(tag_word);
|
|
|
|
sh_monoid[local_id.x] = agg_part;
|
2022-10-25 08:53:12 +11:00
|
|
|
for (var i = 0u; i < LG_WG_SIZE; i += 1u) {
|
|
|
|
workgroupBarrier();
|
2022-11-05 15:41:37 +11:00
|
|
|
if local_id.x >= 1u << i {
|
2022-10-25 08:53:12 +11:00
|
|
|
let other = sh_monoid[local_id.x - (1u << i)];
|
2023-01-06 09:22:14 +11:00
|
|
|
agg_part = combine_tag_monoid(other, agg_part);
|
2022-10-25 08:53:12 +11:00
|
|
|
}
|
|
|
|
workgroupBarrier();
|
2023-01-06 09:22:14 +11:00
|
|
|
sh_monoid[local_id.x] = agg_part;
|
2022-10-25 08:53:12 +11:00
|
|
|
}
|
|
|
|
// prefix up to this workgroup
|
2023-01-06 09:22:14 +11:00
|
|
|
#ifdef small
|
2022-10-25 08:53:12 +11:00
|
|
|
var tm = sh_parent[0];
|
2023-01-06 09:22:14 +11:00
|
|
|
#else
|
|
|
|
var tm = reduced[wg_id.x];
|
|
|
|
#endif
|
2022-11-05 15:41:37 +11:00
|
|
|
if local_id.x > 0u {
|
2022-10-25 08:53:12 +11:00
|
|
|
tm = combine_tag_monoid(tm, sh_monoid[local_id.x - 1u]);
|
|
|
|
}
|
|
|
|
// exclusive prefix sum, granularity of 4 tag bytes
|
|
|
|
tag_monoids[ix] = tm;
|
|
|
|
}
|