M13.13: gpu texture pool, Auto per-comp backend choice, warp-family GPU ports
- gpu: pooled working textures (released once every encoder that could read them is submitted), shared zero images, reused readback staging buffers, direct readback into Image; NaN-poisoned scratch images under test and NaN-aware diffs; validation errors panic under test - render: AutoPick (per comp / scale / path EWMA of CPU vs GPU frame times, warm-up and periodic re-probe) behind Backend::Auto; viewer uses it too; cached adjustment footprints (uploaded once) - gpu fx_warp: Warp, Bezier Warp, CC Bend It, CC Page Turn, Smear, Reshape, Color Emboss, Cartoon; sliding-histogram median for large radii; CC Power Pin perspective < 100 - cli: bench --gpu reports Auto and per-frame upload / readback MB Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
f5a136e346
commit
9ff0e5aa3c
@@ -100,6 +100,15 @@ pub fn gpu_supported(id: &str, ctx: &crate::EffectCtx) -> bool {
|
||||
match id {
|
||||
"ec.generate.cellpattern" if (6..=10).contains(&ctx.params.e("cellPattern")) => return false,
|
||||
"ec.distort.turbulentdisplace" if ctx.params.e("pinning") >= 8 => return false,
|
||||
// Fisheye / Twist (a crease at the unit circle) bent past 50 % or with Horizontal /
|
||||
// Vertical Distortion: Newton's inverse wanders chaotically before converging near the
|
||||
// fold, so f32 lands on other pixels than the CPU's f64.
|
||||
"ec.distort.warp"
|
||||
if matches!(ctx.params.e("warpStyle"), 11 | 14)
|
||||
&& (ctx.params.f("bend").abs() > 50.0 || ctx.params.f("horizontalDistortion") != 0.0 || ctx.params.f("verticalDistortion") != 0.0) =>
|
||||
{
|
||||
return false;
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
let Some((_, controls)) = CPU_ONLY_CONTROLS.iter().find(|(e, _)| *e == id) else { return true };
|
||||
|
||||
@@ -507,6 +507,15 @@ fn bez(p0: [f64; 2], p1: [f64; 2], p2: [f64; 2], p3: [f64; 2], t: f64) -> [f64;
|
||||
}
|
||||
|
||||
fn bezier_warp(ctx: &EffectCtx, mut b: Buf) -> Buf {
|
||||
let (n, dest, srcp) = bezier_grid(ctx, b.offset, b.scale);
|
||||
b.img = grid_warp(&b.img, b.img.width, b.img.height, n, n, &dest, &srcp);
|
||||
b
|
||||
}
|
||||
|
||||
/// Bezier Warp's n×n grid: (n, destination points, source points) in buffer pixels (the GPU
|
||||
/// rasterises the same grid).
|
||||
pub fn bezier_grid(ctx: &EffectCtx, offset: [f64; 2], scale: f64) -> (usize, Vec<Pt>, Vec<Pt>) {
|
||||
let to_px = |p: [f64; 2]| (p[0] * scale + offset[0], p[1] * scale + offset[1]);
|
||||
let g = |id: &str| ctx.params.v2(id);
|
||||
let (tl, tlt, trt, tr) = (g("topLeftVertex"), g("topLeftTangent"), g("topRightTangent"), g("rightTopVertex"));
|
||||
let (rtt, rbt, br) = (g("rightTopTangent"), g("rightBottomTangent"), g("bottomRightVertex"));
|
||||
@@ -529,12 +538,11 @@ fn bezier_warp(ctx: &EffectCtx, mut b: Buf) -> Buf {
|
||||
let bil = (1.0 - u) * (1.0 - v) * tl[k] + u * (1.0 - v) * tr[k] + (1.0 - u) * v * bl[k] + u * v * br[k];
|
||||
s[k] = (1.0 - v) * c0[k] + v * c1[k] + (1.0 - u) * d0[k] + u * d1[k] - bil;
|
||||
}
|
||||
dest.push(b.to_px(s));
|
||||
srcp.push(b.to_px([u * lw, v * lh]));
|
||||
dest.push(to_px(s));
|
||||
srcp.push(to_px([u * lw, v * lh]));
|
||||
}
|
||||
}
|
||||
b.img = grid_warp(&b.img, b.img.width, b.img.height, n, n, &dest, &srcp);
|
||||
b
|
||||
(n, dest, srcp)
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- CC Bend It
|
||||
|
||||
@@ -386,8 +386,25 @@ fn cc_split2(ctx: &EffectCtx, b: Buf) -> Buf {
|
||||
|
||||
// ---------------------------------------------------------------- Smear (mask based)
|
||||
|
||||
fn smear(ctx: &EffectCtx, mut b: Buf) -> Buf {
|
||||
let (Some((src_m, _)), Some((bound, _))) = (mask_px(ctx, &b, "sourceMask"), mask_px(ctx, &b, "boundaryMask")) else { return b };
|
||||
/// Smear's set-up in buffer pixels (shared with the GPU kernel).
|
||||
pub struct SmearSetup {
|
||||
/// Boundary outline and the source outline moved by offset / rotation / scale.
|
||||
pub bound: Vec<[f64; 2]>,
|
||||
pub moved: Vec<[f64; 2]>,
|
||||
/// Source outline centroid, rotation (cos, sin), scale, offset (buffer pixels).
|
||||
pub c: [f64; 2],
|
||||
pub cs: f64,
|
||||
pub sn: f64,
|
||||
pub scl: f64,
|
||||
pub off: [f64; 2],
|
||||
pub pct: f64,
|
||||
/// Elasticity exponent.
|
||||
pub kexp: f64,
|
||||
}
|
||||
|
||||
/// `None` when Smear leaves the buffer as it is (a mask missing, Percent 0).
|
||||
pub fn smear_setup(ctx: &EffectCtx, b: &Buf) -> Option<SmearSetup> {
|
||||
let (Some((src_m, _)), Some((bound, _))) = (mask_px(ctx, b, "sourceMask"), mask_px(ctx, b, "boundaryMask")) else { return None };
|
||||
let pct = ctx.params.f("percent") / 100.0;
|
||||
let off = ctx.params.v2("maskOffset");
|
||||
let (ox, oy) = (off[0] * b.scale, off[1] * b.scale);
|
||||
@@ -400,23 +417,30 @@ fn smear(ctx: &EffectCtx, mut b: Buf) -> Buf {
|
||||
let (dx, dy) = ((p[0] - c[0]) * scl, (p[1] - c[1]) * scl);
|
||||
[c[0] + dx * cs - dy * sn + ox, c[1] + dx * sn + dy * cs + oy]
|
||||
};
|
||||
let moved: Vec<[f64; 2]> = src_m.iter().map(|&q| fwd(q)).collect();
|
||||
if pct == 0.0 {
|
||||
return None;
|
||||
}
|
||||
Some(SmearSetup { bound, moved, c, cs, sn, scl, off: [ox, oy], pct, kexp })
|
||||
}
|
||||
|
||||
fn smear(ctx: &EffectCtx, mut b: Buf) -> Buf {
|
||||
let Some(s) = smear_setup(ctx, &b) else { return b };
|
||||
let (c, cs, sn, scl, [ox, oy]) = (s.c, s.cs, s.sn, s.scl, s.off);
|
||||
let inv = |x: f64, y: f64| -> (f64, f64) {
|
||||
let (dx, dy) = (x - ox - c[0], y - oy - c[1]);
|
||||
(c[0] + (dx * cs + dy * sn) / scl, c[1] + (-dx * sn + dy * cs) / scl)
|
||||
};
|
||||
let moved: Vec<[f64; 2]> = src_m.iter().map(|&q| fwd(q)).collect();
|
||||
if pct == 0.0 {
|
||||
return b;
|
||||
}
|
||||
let (bound, moved, pct, kexp) = (&s.bound, &s.moved, s.pct, s.kexp);
|
||||
b.img = remap(&b.img, false, |x, y| {
|
||||
if !point_in_poly(&bound, x, y) {
|
||||
if !point_in_poly(bound, x, y) {
|
||||
return Some((x, y));
|
||||
}
|
||||
let w = if point_in_poly(&moved, x, y) {
|
||||
let w = if point_in_poly(moved, x, y) {
|
||||
1.0
|
||||
} else {
|
||||
let dm = dist_to_poly(&moved, true, x, y);
|
||||
let db = dist_to_poly(&bound, true, x, y);
|
||||
let dm = dist_to_poly(moved, true, x, y);
|
||||
let db = dist_to_poly(bound, true, x, y);
|
||||
(db / (db + dm).max(1e-9)).powf(1.0 / kexp)
|
||||
};
|
||||
let (ix, iy) = inv(x, y);
|
||||
@@ -464,15 +488,33 @@ fn map_fraction(pairs: &[(f64, f64)], u: f64, closed: bool) -> f64 {
|
||||
(a.0 + ds * t).rem_euclid(1.0)
|
||||
}
|
||||
|
||||
fn reshape(ctx: &EffectCtx, mut b: Buf) -> Buf {
|
||||
let (Some((sm, sc)), Some((dm, dc))) = (mask_px(ctx, &b, "sourceMask"), mask_px(ctx, &b, "destinationMask")) else { return b };
|
||||
/// Points Reshape samples each outline at.
|
||||
pub const RESHAPE_POINTS: usize = 48;
|
||||
|
||||
/// Reshape's set-up in buffer pixels (shared with the GPU kernel).
|
||||
pub struct ReshapeSetup {
|
||||
/// The destination outline's sample points and the displacement back to the source
|
||||
/// outline at each.
|
||||
pub dest: Vec<[f64; 2]>,
|
||||
pub disp: Vec<[f64; 2]>,
|
||||
pub bound: Option<Vec<[f64; 2]>>,
|
||||
/// Elasticity exponent.
|
||||
pub kexp: f64,
|
||||
pub pct: f64,
|
||||
/// Smooth interpolation of the boundary fade.
|
||||
pub smooth: bool,
|
||||
}
|
||||
|
||||
/// `None` when Reshape leaves the buffer as it is (a mask missing, Percent 0).
|
||||
pub fn reshape_setup(ctx: &EffectCtx, b: &Buf) -> Option<ReshapeSetup> {
|
||||
let (Some((sm, sc)), Some((dm, dc))) = (mask_px(ctx, b, "sourceMask"), mask_px(ctx, b, "destinationMask")) else { return None };
|
||||
let pct = ctx.params.f("percent") / 100.0;
|
||||
if pct == 0.0 {
|
||||
return b;
|
||||
return None;
|
||||
}
|
||||
let bound = mask_px(ctx, &b, "boundaryMask").map(|m| m.0);
|
||||
let bound = mask_px(ctx, b, "boundaryMask").map(|m| m.0);
|
||||
let kexp = elastic_exp(ctx.params.e("elasticity"));
|
||||
const N: usize = 48;
|
||||
const N: usize = RESHAPE_POINTS;
|
||||
let s = resample_poly(&sm, sc, N);
|
||||
let d = resample_poly(&dm, dc, N);
|
||||
// Align the starting correspondence point (closed shapes): best cyclic rotation.
|
||||
@@ -506,6 +548,12 @@ fn reshape(ctx: &EffectCtx, mut b: Buf) -> Buf {
|
||||
})
|
||||
.collect();
|
||||
let smooth = ctx.params.e("interpolation") == 2;
|
||||
Some(ReshapeSetup { dest: d, disp, bound, kexp, pct, smooth })
|
||||
}
|
||||
|
||||
fn reshape(ctx: &EffectCtx, mut b: Buf) -> Buf {
|
||||
const N: usize = RESHAPE_POINTS;
|
||||
let Some(ReshapeSetup { dest: d, disp, bound, kexp, pct, smooth }) = reshape_setup(ctx, &b) else { return b };
|
||||
b.img = remap(&b.img, false, |x, y| {
|
||||
if let Some(bd) = &bound
|
||||
&& !point_in_poly(bd, x, y)
|
||||
|
||||
@@ -72,7 +72,8 @@ pub use color_fx::{
|
||||
};
|
||||
pub use color2::{Curve, auto_correct_settings, equalize_tables, luma_clip_points, shadow_highlight_amounts};
|
||||
pub use distort::transform_shutter;
|
||||
pub use distort2::{MAGNIFY_MODES, parse_mesh};
|
||||
pub use distort2::{MAGNIFY_MODES, bezier_grid, parse_mesh};
|
||||
pub use distort3::{RESHAPE_POINTS, ReshapeSetup, SmearSetup, reshape_setup, smear_setup};
|
||||
pub use distort4::liquify_mesh;
|
||||
use effectcraft_keyframe::Value;
|
||||
use effectcraft_project::build::Ids;
|
||||
@@ -912,6 +913,15 @@ pub const GPU_EFFECTS: &[&str] = &[
|
||||
"ec.channel.minimax",
|
||||
"ec.time.echo",
|
||||
"ec.time.posterizetime",
|
||||
// effectcraft-gpu fx_warp (warps, cartoon)
|
||||
"ec.distort.warp",
|
||||
"ec.distort.bezierwarp",
|
||||
"ec.distort.ccbendit",
|
||||
"ec.distort.ccpageturn",
|
||||
"ec.distort.smear",
|
||||
"ec.distort.reshape",
|
||||
"ec.stylize.coloremboss",
|
||||
"ec.stylize.cartoon",
|
||||
];
|
||||
|
||||
/// Effects whose output depends on [`EffectCtx::time`] directly (not only through animated
|
||||
|
||||
Reference in New Issue
Block a user