Skip to content
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

Allow large numbers of draw objects #526

Merged
merged 3 commits into from
Mar 20, 2024
Merged
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
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;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider assigning the dimensions to params.resolution (where params refers to the second parameter to this function). That will adjust the scene transform so that the contents fit inside the window.

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