Check the GPU's effects analytically instead of against the CPU baking

This commit is contained in:
Keavon Chambers committed 2026-12-05 13:30:51 -08:00
1 parent 98d636c1e5
commit 5418fcbf7b
15 files changed
+2582 -1102

No files matched your search

@@ -480,10 +480,8 @@ mod tests {
#[test]
fn values_a_blend_if_hides_stay_hidden_through_adjustments_raising_alpha_as_rasters_do() {
use crate::raster_effects::{evaluate_raster_effects, premultiplied_gamma_channels};
use graphic_types::EffectKind;
use graphic_types::blend_if::BlendIfRanges;
use raster_types::{Image, Raster};
// Shown only where the gray is at least half
let mut hides_darks = BlendIfRanges::default();
@@ -497,15 +495,8 @@ mod tests {
opacity: 100.,
});
// Black consumed as a color, which agrees with a raster's pixel of it
let black_through = |name: &str, rows: &[(EffectOperation, f64)]| {
let color = *evaluate_color_effects(stamped(Color::BLACK, rows)).element();
let raster = evaluate_raster_effects(stamped(Raster::new_cpu(Image::new(1, 1, Color::BLACK)), rows));
let pixel = raster.element().data.first().copied().unwrap_or(Color::TRANSPARENT);
let (color_channels, pixel_channels) = (premultiplied_gamma_channels(color), premultiplied_gamma_channels(pixel));
assert!(close(color_channels, pixel_channels), "black {name}: {color_channels:?} vs the raster's {pixel_channels:?}");
color
};
// Black consumed as a color, which the GPU's render of a raster of it agrees with (`blend_ifs_hide_rasters_through_adjustments_raising_alpha_as_they_hide_values` in wgpu-executor)
let black_through = |rows: &[(EffectOperation, f64)]| *evaluate_color_effects(stamped(Color::BLACK, rows)).element();
// Hidden black stays hidden when made opaque, in its run or the next, where an overlay finds nothing to paint within either
let hidden = [
@@ -514,11 +505,11 @@ mod tests {
("made opaque and painted in the next run", vec![(blend_if.clone(), 1.), (make_opaque.clone(), 2.), (red.clone(), 2.)]),
];
for (name, rows) in hidden {
assert_eq!(black_through(name, &rows).a(), 0., "black {name}");
assert_eq!(black_through(&rows).a(), 0., "black {name}");
}
// In its own run, an overlay still paints within the full-strength black
let painted = black_through("made opaque and painted", &[(blend_if.clone(), 1.), (make_opaque.clone(), 1.), (red, 1.)]);
let painted = black_through(&[(blend_if.clone(), 1.), (make_opaque.clone(), 1.), (red, 1.)]);
assert!(close(gamma(painted), [1., 0., 0., 1.]), "{:?}", gamma(painted));
// A ramp made opaque stays hidden where it's dark, in the Blend If's run or the next
@@ -21,8 +21,7 @@ impl Context {
}
/// The context the GPU tests run on, which wgpu's environment variables can aim at each backend and shader compiler in turn.
#[cfg(test)]
pub(crate) async fn for_tests() -> Option<Self> {
pub async fn for_tests() -> Option<Self> {
let context = ContextBuilder::new().with_environment_overrides().build().await;
// A backend asked for by name fails the tests if it can't run them, rather than passing them all as skipped
@@ -199,6 +199,12 @@ impl WgpuExecutor {
Self::with_context(WgpuContext::new().await?)
}
/// The executor GPU tests run on, on the context [`WgpuContext::for_tests`] makes, or `None` without a GPU.
#[cfg(not(target_family = "wasm"))]
pub async fn for_tests() -> Option<Self> {
Self::with_context(WgpuContext::for_tests().await?)
}
pub fn with_context(context: WgpuContext) -> Option<Self> {
let vello_renderer = VelloRenderer::new(&context.device, &context.adapter);
File diff suppressed because it is too large. Load diff