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
|
|
|
|
|
|
|
// Note: this is the non-atomic version
|
|
|
|
struct Tile {
|
|
|
|
backdrop: i32,
|
|
|
|
segments: u32,
|
|
|
|
}
|
|
|
|
|
2022-10-28 01:27:46 +11:00
|
|
|
#import config
|
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)
|
|
|
|
var<storage, read_write> tiles: array<Tile>;
|
|
|
|
|
|
|
|
let WG_SIZE = 64u;
|
|
|
|
|
|
|
|
var<workgroup> sh_backdrop: array<i32, WG_SIZE>;
|
|
|
|
|
|
|
|
// Each workgroup computes the inclusive prefix sum of the backdrops
|
|
|
|
// in one row of tiles.
|
|
|
|
@compute @workgroup_size(64)
|
|
|
|
fn main(
|
|
|
|
@builtin(local_invocation_id) local_id: vec3<u32>,
|
|
|
|
@builtin(workgroup_id) wg_id: vec3<u32>,
|
|
|
|
) {
|
|
|
|
let width_in_tiles = config.width_in_tiles;
|
|
|
|
let ix = wg_id.x * width_in_tiles + local_id.x;
|
|
|
|
var backdrop = 0;
|
2022-11-26 03:43:21 +11:00
|
|
|
if local_id.x < width_in_tiles {
|
2022-10-25 08:53:12 +11:00
|
|
|
backdrop = tiles[ix].backdrop;
|
|
|
|
}
|
|
|
|
sh_backdrop[local_id.x] = backdrop;
|
2022-10-26 03:03:13 +11:00
|
|
|
// iterate log2(WG_SIZE) times
|
2022-10-25 08:53:12 +11:00
|
|
|
for (var i = 0u; i < firstTrailingBit(WG_SIZE); i += 1u) {
|
|
|
|
workgroupBarrier();
|
2022-11-26 03:43:21 +11:00
|
|
|
if local_id.x >= (1u << i) {
|
2022-10-25 08:53:12 +11:00
|
|
|
backdrop += sh_backdrop[local_id.x - (1u << i)];
|
|
|
|
}
|
|
|
|
workgroupBarrier();
|
|
|
|
sh_backdrop[local_id.x] = backdrop;
|
|
|
|
}
|
2022-11-26 03:43:21 +11:00
|
|
|
if local_id.x < width_in_tiles {
|
2022-10-25 08:53:12 +11:00
|
|
|
tiles[ix].backdrop = backdrop;
|
|
|
|
}
|
|
|
|
}
|