Skip to content

Commit

Permalink
Fix error in clip reduction (#659)
Browse files Browse the repository at this point in the history
One bit of logic from the GLSL (piet-gpu) version of clip_reduce didn't
get copied over.

Fixes #648
  • Loading branch information
raphlinus authored Aug 9, 2024
1 parent 59c0fa5 commit eecbf55
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 1 deletion.
31 changes: 31 additions & 0 deletions examples/scenes/src/test_scenes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export_scenes!(
brush_transform(brush_transform: animated),
blend_grid(blend_grid),
deep_blend(deep_blend),
many_clips(many_clips),
conflation_artifacts(conflation_artifacts),
labyrinth(labyrinth),
robust_paths(robust_paths),
Expand All @@ -82,7 +83,11 @@ export_scenes!(
/// Implementations for the test scenes.
/// In a module because the exported [`ExampleScene`](crate::ExampleScene) creation functions use the same names.
mod impls {
use std::f64::consts::PI;

use crate::SceneParams;
use rand::Rng;
use rand::{rngs::StdRng, SeedableRng};
use vello::kurbo::{
Affine, BezPath, Cap, Circle, Ellipse, Join, PathEl, Point, Rect, Shape, Stroke, Vec2,
};
Expand Down Expand Up @@ -1094,6 +1099,32 @@ mod impls {
}
}

pub(super) fn many_clips(scene: &mut Scene, params: &mut SceneParams) {
params.resolution = Some(Vec2::new(1000., 1000.));
let mut rng = StdRng::seed_from_u64(42);
let mut base_tri = BezPath::new();
base_tri.move_to((-50.0, 0.0));
base_tri.line_to((25.0, -43.3));
base_tri.line_to((25.0, 43.3));
for y in 0..10 {
for x in 0..10 {
let translate =
Affine::translate((100. * (x as f64 + 0.5), 100. * (y as f64 + 0.5)));
const CLIPS_PER_FILL: usize = 3;
for _ in 0..CLIPS_PER_FILL {
let rot = Affine::rotate(rng.gen_range(0.0..PI));
scene.push_layer(Mix::Clip, 1.0, translate * rot, &base_tri);
}
let rot = Affine::rotate(rng.gen_range(0.0..PI));
let color = Color::rgb(rng.gen(), rng.gen(), rng.gen());
scene.fill(Fill::NonZero, translate * rot, color, None, &base_tri);
for _ in 0..CLIPS_PER_FILL {
scene.pop_layer();
}
}
}
}

// Support functions

pub(super) fn render_cardioid(scene: &mut Scene) {
Expand Down
3 changes: 3 additions & 0 deletions vello_shaders/shader/clip_reduce.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ fn main(
workgroupBarrier();
let size = sh_bic[0].b;
bic = Bic();
if local_id.x + 1u < WG_SIZE {
bic = sh_bic[local_id.x + 1u];
}
if is_push && bic.a == 0u {
let local_ix = size - bic.b - 1u;
sh_parent[local_ix] = local_id.x;
Expand Down
2 changes: 1 addition & 1 deletion vello_shaders/src/cpu/clip_reduce.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ fn clip_reduce_main(
let inp = clip_inp[global_ix].path_ix;
let is_push = inp >= 0;
let bic = ClipBic::new(1 - is_push as u32, is_push as u32);
bic_reduced = bic.combine(bic_reduced);
if is_push && bic_reduced.a == 0 {
scratch.push(global_ix as u32);
}
bic_reduced = bic.combine(bic_reduced);
}
reduced[wg_ix as usize] = bic_reduced;
for (i, parent_ix) in scratch.iter().rev().enumerate() {
Expand Down
3 changes: 3 additions & 0 deletions vello_tests/snapshots/many_clips.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions vello_tests/tests/snapshots.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,11 @@ fn snapshot_deep_blend() {
let params = TestParams::new("deep_blend", 200, 200);
snapshot_test_scene(test_scene, params);
}

#[test]
#[cfg_attr(skip_gpu_tests, ignore)]
fn snapshot_many_clips() {
let test_scene = test_scenes::many_clips();
let params = TestParams::new("many_clips", 200, 200);
snapshot_test_scene(test_scene, params);
}

0 comments on commit eecbf55

Please sign in to comment.