Skip to content

Make segments and seg_counts use the same buffer size. #708

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions vello_encoding/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,10 @@ pub struct ConfigUniform {
pub binning_size: u32,
/// Size of tile buffer allocation (in [`Tile`]s).
pub tiles_size: u32,
/// Size of segment count buffer allocation (in [`SegmentCount`]s).
pub seg_counts_size: u32,
/// Size of segment buffer allocation (in [`PathSegment`]s).
/// The maximum number of segments we can support.
///
/// This is the size of the segment count buffer allocation (in [`SegmentCount`]s)
/// *and* the segment buffer allocation (in [`PathSegment`]s).
pub segments_size: u32,
/// Size of blend spill buffer (in `u32` pixels).
// TODO: Maybe store in TILE_WIDTH * TILE_HEIGHT blocks of pixels instead?
Expand Down Expand Up @@ -175,6 +176,8 @@ impl RenderConfig {
let workgroup_counts =
WorkgroupCounts::new(layout, width_in_tiles, height_in_tiles, n_path_tags);
let buffer_sizes = BufferSizes::new(layout, &workgroup_counts);
let segments_size = buffer_sizes.segments.len();
debug_assert_eq!(segments_size, buffer_sizes.seg_counts.len());
Self {
gpu: ConfigUniform {
width_in_tiles,
Expand All @@ -185,8 +188,7 @@ impl RenderConfig {
lines_size: buffer_sizes.lines.len(),
binning_size: buffer_sizes.bin_data.len() - layout.bin_data_start,
tiles_size: buffer_sizes.tiles.len(),
seg_counts_size: buffer_sizes.seg_counts.len(),
segments_size: buffer_sizes.segments.len(),
segments_size,
blend_size: buffer_sizes.blend_spill.len(),
ptcl_size: buffer_sizes.ptcl.len(),
layout: *layout,
Expand Down Expand Up @@ -398,8 +400,10 @@ impl BufferSizes {
let bin_data = BufferSize::new(1 << 18);
let tiles = BufferSize::new(1 << 21);
let lines = BufferSize::new(1 << 21);
let seg_counts = BufferSize::new(1 << 21);
let segments = BufferSize::new(1 << 21);
// These two buffer sizes *must* be the same.
let max_segments = 1 << 21;
let seg_counts = BufferSize::new(max_segments);
let segments = BufferSize::new(max_segments);
// 16 * 16 (1 << 8) is one blend spill, so this allows for 4096 spills.
let blend_spill = BufferSize::new(1 << 20);
let ptcl = BufferSize::new(1 << 23);
Expand Down
5 changes: 4 additions & 1 deletion vello_shaders/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ fn main() {
let mut shaders = match compile::ShaderInfo::from_default() {
Ok(s) => s,
Err(err) => {
eprintln!("{err}");
let formatted = err.to_string();
for line in formatted.lines() {
println!("cargo:warning={line}");
}
return;
}
};
Expand Down
2 changes: 1 addition & 1 deletion vello_shaders/shader/coarse.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ fn main(
// we still want to know this workgroup's memory requirement.
if local_id.x == 0u {
var failed = atomicLoad(&bump.failed) & (STAGE_BINNING | STAGE_TILE_ALLOC | STAGE_FLATTEN);
if atomicLoad(&bump.seg_counts) > config.seg_counts_size {
if atomicLoad(&bump.seg_counts) > config.segments_size {
failed |= STAGE_PATH_COUNT;
}
// Reuse sh_part_count to hold failed flag, shmem is tight
Expand Down
2 changes: 1 addition & 1 deletion vello_shaders/shader/path_count.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ fn main(
let counts = (seg_within_slice << 16u) | subix;
let seg_count = SegmentCount(line_ix, counts);
let seg_ix = seg_base + i - imin;
if seg_ix < config.seg_counts_size {
if seg_ix < config.segments_size {
seg_counts[seg_ix] = seg_count;
}
// Note: since we're iterating, we have a reliable value for
Expand Down
1 change: 0 additions & 1 deletion vello_shaders/shader/shared/config.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ struct Config {
lines_size: u32,
binning_size: u32,
tiles_size: u32,
seg_counts_size: u32,
segments_size: u32,
blend_size: u32,
ptcl_size: u32,
Expand Down