Skip to content

Commit

Permalink
Add a failing test and warning for #680 (#681)
Browse files Browse the repository at this point in the history
See #680 for details.

This test will currently pass, but only because the behaviour is
incorrect.

This adds a warning for when this bug would apply, for users
  • Loading branch information
DJMcNab authored Sep 20, 2024
1 parent 3bf5428 commit 3073647
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 1 deletion.
13 changes: 13 additions & 0 deletions vello/src/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,19 @@ impl Render {
}
let cpu_config =
RenderConfig::new(&layout, params.width, params.height, &params.base_color);
// HACK: The coarse workgroup counts is the number of active bins.
if (cpu_config.workgroup_counts.coarse.0
* cpu_config.workgroup_counts.coarse.1
* cpu_config.workgroup_counts.coarse.2)
> 256
{
log::warn!(
"Trying to paint too large image. {}x{}.\n\
See https://github.com/linebender/vello/issues/680 for details",
params.width,
params.height
);
}
let buffer_sizes = &cpu_config.buffer_sizes;
let wg_counts = &cpu_config.workgroup_counts;

Expand Down
15 changes: 14 additions & 1 deletion vello_tests/src/snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,14 +147,27 @@ pub fn smoke_snapshot_test_sync(scene: Scene, params: &TestParams) -> Result<Sna
pollster::block_on(snapshot_test(scene, params, SnapshotDirectory::Smoke))
}

/// Run a snapshot test of the given scene.
/// Run an snapshot test of the given scene.
///
/// In most cases, you should use [`snapshot_test_sync`] or [`smoke_snapshot_test_sync`].
pub async fn snapshot_test(
scene: Scene,
params: &TestParams,
directory: SnapshotDirectory,
) -> Result<Snapshot> {
let raw_rendered = render_then_debug(&scene, params).await?;
snapshot_test_image(raw_rendered, params, directory)
}

/// Evaluate a snapshot test on the given image.
///
/// This is useful if a post-processing step needs to happen
/// in-between running Vello and the image.
pub fn snapshot_test_image(
raw_rendered: Image,
params: &TestParams,
directory: SnapshotDirectory,
) -> Result<Snapshot> {
let reference_path = snapshot_dir(directory)
.join(&params.name)
.with_extension("png");
Expand Down
67 changes: 67 additions & 0 deletions vello_tests/tests/known_issues.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// Copyright 2024 the Vello Authors
// SPDX-License-Identifier: Apache-2.0 OR MIT

//! Reproductions for known bugs, to allow test driven development

use vello::{
kurbo::{Affine, Rect},
peniko::{Color, Format},
Scene,
};
use vello_tests::TestParams;

/// A reproduction of <https://github.com/linebender/vello/issues/680>
fn many_bins(use_cpu: bool) {
let mut scene = Scene::new();
scene.fill(
vello::peniko::Fill::NonZero,
Affine::IDENTITY,
Color::RED,
None,
&Rect::new(-5., -5., 256. * 20., 256. * 20.),
);
let params = TestParams {
use_cpu,
..TestParams::new("many_bins", 256 * 17, 256 * 17)
};
// To view, use VELLO_DEBUG_TEST=many_bins
let image = vello_tests::render_then_debug_sync(&scene, &params).unwrap();
assert_eq!(image.format, Format::Rgba8);
let mut red_count = 0;
let mut black_count = 0;
for pixel in image.data.data().chunks_exact(4) {
let &[r, g, b, a] = pixel else { unreachable!() };
let is_red = r == 255 && g == 0 && b == 0 && a == 255;
let is_black = r == 0 && g == 0 && b == 0 && a == 255;
if !is_red && !is_black {
panic!("{pixel:?}");
}
match (is_red, is_black) {
(true, true) => unreachable!(),
(true, false) => red_count += 1,
(false, true) => black_count += 1,
(false, false) => panic!("Got unexpected pixel {pixel:?}"),
}
}
// When #680 is fixed, this will become:
// let drawn_bins = 17 /* x bins */ * 17 /* y bins*/;

// The current maximum number of bins.
let drawn_bins = 256;
let expected_red_count = drawn_bins * 256 /* tiles per bin */ * 256 /* Pixels per tile */;
assert_eq!(red_count, expected_red_count);
assert!(black_count > 0);
}

#[test]
#[cfg_attr(skip_gpu_tests, ignore)]
fn many_bins_gpu() {
many_bins(false);
}

#[test]
#[cfg_attr(skip_gpu_tests, ignore)]
#[should_panic]
fn many_bins_cpu() {
many_bins(true);
}

0 comments on commit 3073647

Please sign in to comment.