Skip to content

Commit

Permalink
Allow large numbers of draw objects (#526)
Browse files Browse the repository at this point in the history
* Allow large numbers of draw objects

Previously there was a limit of workgroup size squared for the number of draw objects, which is 64k in practice. This PR makes each workgroup iterate multiple blocks if that limit is exceeded, borrowing a technique from FidelityFX sort.

WIP, this causes hangs on mac. Uploading to test on other hardware.

Also contains some changes for testing that may not want to be committed as is.

Fixes #334

* Add missing barrier

Add barrier for write-after-read hazard in coarse. The loop in question processes 64k draw objects at a time, so the barrier only gets invoked when that limit is exceeded.

Also move new test scene so it isn't the first.

* Address review comments

Set resolution in params for test scene. Add comments explaining division of work.
  • Loading branch information
raphlinus authored Mar 20, 2024
1 parent 399a723 commit 959d313
Show file tree
Hide file tree
Showing 7 changed files with 244 additions and 187 deletions.
12 changes: 7 additions & 5 deletions crates/encoding/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ impl WorkgroupCounts {
path_tag_wgs
};
let draw_object_wgs = (n_draw_objects + PATH_BBOX_WG - 1) / PATH_BBOX_WG;
let draw_monoid_wgs = draw_object_wgs.min(PATH_BBOX_WG);
let flatten_wgs = (n_path_tags + FLATTEN_WG - 1) / FLATTEN_WG;
let clip_reduce_wgs = n_clips.saturating_sub(1) / CLIP_REDUCE_WG;
let clip_wgs = (n_clips + CLIP_REDUCE_WG - 1) / CLIP_REDUCE_WG;
Expand All @@ -248,8 +249,8 @@ impl WorkgroupCounts {
path_scan: (path_tag_wgs, 1, 1),
bbox_clear: (draw_object_wgs, 1, 1),
flatten: (flatten_wgs, 1, 1),
draw_reduce: (draw_object_wgs, 1, 1),
draw_leaf: (draw_object_wgs, 1, 1),
draw_reduce: (draw_monoid_wgs, 1, 1),
draw_leaf: (draw_monoid_wgs, 1, 1),
clip_reduce: (clip_reduce_wgs, 1, 1),
clip_leaf: (clip_wgs, 1, 1),
binning: (draw_object_wgs, 1, 1),
Expand Down Expand Up @@ -364,8 +365,9 @@ impl BufferSizes {
let path_reduced_scan = BufferSize::new(path_tag_wgs);
let path_monoids = BufferSize::new(path_tag_wgs * PATH_REDUCE_WG);
let path_bboxes = BufferSize::new(n_paths);
let draw_object_wgs = workgroups.draw_reduce.0;
let draw_reduced = BufferSize::new(draw_object_wgs);
let binning_wgs = workgroups.binning.0;
let draw_monoid_wgs = workgroups.draw_reduce.0;
let draw_reduced = BufferSize::new(draw_monoid_wgs);
let draw_monoids = BufferSize::new(n_draw_objects);
let info = BufferSize::new(layout.bin_data_start);
let clip_inps = BufferSize::new(n_clips);
Expand All @@ -375,7 +377,7 @@ impl BufferSizes {
let draw_bboxes = BufferSize::new(n_paths);
let bump_alloc = BufferSize::new(1);
let indirect_count = BufferSize::new(1);
let bin_headers = BufferSize::new(draw_object_wgs * 256);
let bin_headers = BufferSize::new(binning_wgs * 256);
let n_paths_aligned = align_up(n_paths, 256);
let paths = BufferSize::new(n_paths_aligned);

Expand Down
21 changes: 20 additions & 1 deletion examples/scenes/src/test_scenes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
// SPDX-License-Identifier: Apache-2.0 OR MIT

use crate::{ExampleScene, SceneConfig, SceneParams, SceneSet};
use vello::kurbo::{Affine, BezPath, Cap, Ellipse, Join, PathEl, Point, Rect, Shape, Stroke, Vec2};
use vello::kurbo::{
Affine, BezPath, Cap, Circle, Ellipse, Join, PathEl, Point, Rect, Shape, Stroke, Vec2,
};
use vello::peniko::*;
use vello::*;

Expand Down Expand Up @@ -60,6 +62,7 @@ pub fn test_scenes() -> SceneSet {
scene!(longpathdash(Cap::Butt), "longpathdash (butt caps)", false),
scene!(longpathdash(Cap::Round), "longpathdash (round caps)", false),
scene!(crate::mmark::MMark::new(80_000), "mmark", false),
scene!(many_draw_objects),
];

SceneSet { scenes }
Expand Down Expand Up @@ -1520,6 +1523,22 @@ fn make_diamond(cx: f64, cy: f64) -> [PathEl; 5] {
]
}

fn many_draw_objects(scene: &mut Scene, params: &mut SceneParams) {
const N_WIDE: usize = 300;
const N_HIGH: usize = 300;
const SCENE_WIDTH: f64 = 2000.0;
const SCENE_HEIGHT: f64 = 1500.0;
params.resolution = Some((SCENE_WIDTH, SCENE_HEIGHT).into());
for j in 0..N_HIGH {
let y = (j as f64 + 0.5) * (SCENE_HEIGHT / N_HIGH as f64);
for i in 0..N_WIDE {
let x = (i as f64 + 0.5) * (SCENE_WIDTH / N_WIDE as f64);
let c = Circle::new((x, y), 3.0);
scene.fill(Fill::NonZero, Affine::IDENTITY, Color::YELLOW, None, &c);
}
}
}

fn splash_screen(scene: &mut Scene, params: &mut SceneParams) {
let strings = [
"Vello test",
Expand Down
1 change: 1 addition & 0 deletions shader/coarse.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ fn main(
if wr_ix - rd_ix >= N_TILE || (wr_ix >= ready_ix && partition_ix >= n_partitions) {
break;
}
workgroupBarrier();
}
// At this point, sh_drawobj_ix[0.. wr_ix - rd_ix] contains merged binning results.
var tag = DRAWTAG_NOP;
Expand Down
Loading

0 comments on commit 959d313

Please sign in to comment.