Skip to content

Commit

Permalink
Allow large numbers of draw objects
Browse files Browse the repository at this point in the history
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
  • Loading branch information
raphlinus committed Mar 19, 2024
1 parent 399a723 commit e6937f4
Show file tree
Hide file tree
Showing 7 changed files with 253 additions and 202 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
20 changes: 19 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 @@ -31,6 +33,7 @@ macro_rules! scene {

pub fn test_scenes() -> SceneSet {
let scenes = vec![
scene!(many_draw),
scene!(splash_with_tiger(), "splash_with_tiger", false),
scene!(funky_paths),
scene!(stroke_styles(Affine::IDENTITY), "stroke_styles", false),
Expand Down Expand Up @@ -67,6 +70,21 @@ pub fn test_scenes() -> SceneSet {

// Scenes

fn many_draw(scene: &mut Scene, _: &mut SceneParams) {
const N_WIDE: usize = 300;
const N_HIGH: usize = 300;
const SCENE_WIDTH: f64 = 2000.0;
const SCENE_HEIGHT: f64 = 1500.0;
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 funky_paths(scene: &mut Scene, _: &mut SceneParams) {
use PathEl::*;
let missing_movetos = [
Expand Down
Loading

0 comments on commit e6937f4

Please sign in to comment.