diff --git a/crates/shaders/src/cpu/backdrop.rs b/crates/shaders/src/cpu/backdrop.rs index 9e60c52b9..41303e1f7 100644 --- a/crates/shaders/src/cpu/backdrop.rs +++ b/crates/shaders/src/cpu/backdrop.rs @@ -1,11 +1,11 @@ // Copyright 2023 the Vello Authors // SPDX-License-Identifier: Apache-2.0 OR MIT OR Unlicense -use vello_encoding::{ConfigUniform, Path, Tile}; +use vello_encoding::{BumpAllocators, ConfigUniform, Path, Tile}; use super::CpuBinding; -fn backdrop_main(config: &ConfigUniform, paths: &[Path], tiles: &mut [Tile]) { +fn backdrop_main(config: &ConfigUniform, _: &BumpAllocators, paths: &[Path], tiles: &mut [Tile]) { for drawobj_ix in 0..config.layout.n_draw_objects { let path = paths[drawobj_ix as usize]; let width = path.bbox[2] - path.bbox[0]; @@ -24,7 +24,8 @@ fn backdrop_main(config: &ConfigUniform, paths: &[Path], tiles: &mut [Tile]) { pub fn backdrop(_n_wg: u32, resources: &[CpuBinding]) { let config = resources[0].as_typed(); - let paths = resources[1].as_slice(); - let mut tiles = resources[2].as_slice_mut(); - backdrop_main(&config, &paths, &mut tiles); + let bump = resources[1].as_typed(); + let paths = resources[2].as_slice(); + let mut tiles = resources[3].as_slice_mut(); + backdrop_main(&config, &bump, &paths, &mut tiles); } diff --git a/shader/backdrop_dyn.wgsl b/shader/backdrop_dyn.wgsl index 2664f6c37..7bdf5c70e 100644 --- a/shader/backdrop_dyn.wgsl +++ b/shader/backdrop_dyn.wgsl @@ -3,6 +3,7 @@ // Prefix sum for dynamically allocated backdrops +#import bump #import config #import tile @@ -10,9 +11,12 @@ var config: Config; @group(0) @binding(1) -var paths: array; +var bump: BumpAllocators; @group(0) @binding(2) +var paths: array; + +@group(0) @binding(3) var tiles: array; let WG_SIZE = 256u; @@ -26,6 +30,14 @@ fn main( @builtin(global_invocation_id) global_id: vec3, @builtin(local_invocation_id) local_id: vec3, ) { + // Abort if any of the prior stages failed. + if local_id.x == 0u { + sh_row_count[0] = atomicLoad(&bump.failed); + } + let failed = workgroupUniformLoad(&sh_row_count[0]); + if failed != 0u { + return; + } let drawobj_ix = global_id.x; var row_count = 0u; if drawobj_ix < config.n_drawobj { @@ -34,6 +46,9 @@ fn main( sh_row_width[local_id.x] = path.bbox.z - path.bbox.x; row_count = path.bbox.w - path.bbox.y; sh_offset[local_id.x] = path.tiles; + } else { + // Explicitly zero the row width, just in case. + sh_row_width[local_id.x] = 0u; } sh_row_count[local_id.x] = row_count; diff --git a/src/render.rs b/src/render.rs index ab44615c3..a248de311 100644 --- a/src/render.rs +++ b/src/render.rs @@ -358,7 +358,7 @@ impl Render { recording.dispatch( shaders.backdrop, wg_counts.backdrop, - [config_buf, path_buf, tile_buf], + [config_buf, bump_buf, path_buf, tile_buf], ); recording.dispatch( shaders.coarse, diff --git a/src/shaders.rs b/src/shaders.rs index 2e3a69956..7b9cdb972 100644 --- a/src/shaders.rs +++ b/src/shaders.rs @@ -180,7 +180,7 @@ pub fn full_shaders( ); let backdrop = add_shader!( backdrop_dyn, - [Uniform, BufReadOnly, Buffer], + [Uniform, Buffer, BufReadOnly, Buffer], CpuShaderType::Present(vello_shaders::cpu::backdrop) ); let coarse = add_shader!(