Skip to content
Merged
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
61 changes: 59 additions & 2 deletions crates/rendering/tests/downscale_filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -503,9 +503,38 @@ fn shrunk_draw(source: &Source, ratio: f32) -> Draw {
}
}

const SOFTWARE_BORDER_BAND_PX: f32 = 3.0;

fn card_edge_distance(uniforms: &CompositeVideoFrameUniforms, x: u32, y: u32) -> f32 {
let [left, top, right, bottom] = uniforms.target_bounds;
let p = [
x as f32 + 0.5 - (left + right) * 0.5,
y as f32 + 0.5 - (top + bottom) * 0.5,
];
let corner = match (p[0] < 0.0, p[1] < 0.0) {
(true, true) => 0,
(false, true) => 1,
(true, false) => 2,
(false, false) => 3,
};
let radius = uniforms.rounding_px * uniforms.corner_radii[corner];
let q = [
p[0].abs() - (right - left) * 0.5 + radius,
p[1].abs() - (bottom - top) * 0.5 + radius,
];
let (outside_x, outside_y) = (q[0].max(0.0), q[1].max(0.0));
let outside = if uniforms.rounding_type < 0.5 {
outside_x.hypot(outside_y)
} else {
(outside_x.powi(4) + outside_y.powi(4)).powf(0.25)
};
outside + q[0].max(q[1]).min(0.0) - radius
}

#[test]
fn plain_pipeline_draws_the_same_pixels_when_no_layer_filter_applies() {
let Some(gpu) = gpu() else { return };
let software_renderer = cfg!(windows) && cap_rendering::is_software_wgpu_adapter(&gpu.adapter);
let opaque = text_like(440, 220);
// A background-removed camera frame: transparent texels keep an unrelated
// colour that straight-alpha filtering must not pull in.
Expand Down Expand Up @@ -617,10 +646,38 @@ fn plain_pipeline_draws_the_same_pixels_when_no_layer_filter_applies() {
if filtered {
continue;
}
assert!(
render_with(&gpu, &source, &draw, chosen) == render(&gpu, &source, &draw),
let case = format!(
"{kind} ratio {ratio} preserve_alpha {preserve_alpha} blur {motion_blur:?}"
);
let plain = render_with(&gpu, &source, &draw, chosen);
let full = render(&gpu, &source, &draw);
// On WARP the blur taps' rounded-corner coverage calls fwidth() after
// the border's per-pixel early return in composite-video-frame.wgsl,
// so pixels next to a blurred card's border change between identical
// draws (#4964). Only that band is left out, and only there.
if software_renderer && motion_blur != [0.0; 2] && uniforms.border_enabled > 0.0
{
let band = -SOFTWARE_BORDER_BAND_PX
..=uniforms.border_width + SOFTWARE_BORDER_BAND_PX;
let (mut left_out, mut differed) = (0, 0);
for (index, (plain_pixel, full_pixel)) in
plain.chunks_exact(4).zip(full.chunks_exact(4)).enumerate()
{
let (x, y) =
(index as u32 % draw.output[0], index as u32 / draw.output[0]);
if band.contains(&card_edge_distance(&uniforms, x, y)) {
left_out += 1;
differed += usize::from(plain_pixel != full_pixel);
} else {
assert_eq!(plain_pixel, full_pixel, "{case} pixel {x},{y}");
}
}
eprintln!(
"{case}: software renderer, left out {left_out} pixels within {SOFTWARE_BORDER_BAND_PX} px of the card border, {differed} of them differed"
);
} else {
assert!(plain == full, "{case}");
}
checked += 1;
}
}
Expand Down
Loading