Skip to content

perf(filter): optimize select0r, keyspillm0pup, and alpha0ps keying/alpha plugins - #342

Open
Quantum-Quasar wants to merge 3 commits into
dyne:masterfrom
Quantum-Quasar:perf/color-keying-wave3
Open

Quantum-Quasar wants to merge 3 commits into
dyne:masterfrom
Quantum-Quasar:perf/color-keying-wave3

Conversation

@Quantum-Quasar

Copy link
Copy Markdown

Summary

Bit-exact (max_abs_diff = 0) CPU rendering optimizations for Kdenlive's core keying and alpha-channel plugins:

  • select0r (Chroma Key Advanced): Replace per-frame 33 MB (1080p) / 132 MB (4K) calloc/free float buffer and 4 full-frame passes with an L1-resident 256-pixel stack tile and 4-pixel SSE2 vectorization for RGB/ABI selection, inversion, and all 5 alpha compositing ops.
  • keyspillm0pup: Eliminate per-frame 41 MB / 165 MB calloc/free allocations (sl + mask), fuse pointwise masks into a zero-alloc single pass with SSE2 4-pixel RGB-distance fast-reject, cache the edge-mask buffer on the instance, replace hypotf with bit-exact double-precision hardware sqrt, and prune atan2f via early sat_thres, opposite-quadrant rejection, and exact dot-product guards.
  • alpha0ps (alpha0ps_alpha0ps, alpha0ps_alphagrad, alpha0ps_alphaspot): Eliminate per-frame 16 MB / 64 MB calloc/free and copy-back via cached buffers + pointer swapping + SSE2 stencil/pack; shrink alphagrad mask from uint32_t to uint8_t (4× less memory) with SSE2 alpha ops; fuse alphaspot memcpy + alpha pass into single-pass SSE2.

Benchmarks (3-Run Median, 1080p & 4K RGBA8888, GCC 12.2.0 Release)

Plugin 1080p Before 1080p After 1080p Speedup 4K Before 4K After 4K Speedup Max Abs Diff
select0r 11.81 ms 2.42 ms 4.89× 123.09 ms 10.10 ms 12.19× 0
alpha0ps_alpha0ps 5.61 ms 3.35 ms 1.68× 58.40 ms 23.95 ms 2.44× 0
keyspillm0pup 124.20 ms 65.95 ms 1.88× 576.98 ms 267.34 ms 2.16× 0
alpha0ps_alphagrad 1.15 ms 0.67 ms 1.71× 7.67 ms 3.99 ms 1.92× 0
alpha0ps_alphaspot 1.62 ms 0.66 ms 2.45× 6.58 ms 3.67 ms 1.79× 0

Verification

  • Verified max_abs_diff = 0 against baseline .so builds across all tested modes/presets at 1080p and 4K.
  • Clean Release build with zero compiler warnings; all plugin ctest targets pass.

frei0r perf added 3 commits November 26, 2026 15:08
…iled SSE2

Replace per-frame calloc/free of w*h*16 bytes (33 MB at 1080p, 132 MB
at 4K) and 4 full-frame memory passes with an L1-resident 256-pixel
stack tile. Vectorize RGB and ABI subspace selection, inversion, and all
5 alpha compositing operations 4 pixels at a time with SSE2, preserving
double-precision 0.3333 ABI intensity scaling for bit-exactness.

Verified 0 max-abs-diff against baseline on 1080p and 4K across all
subspaces, shapes, edge modes, and alpha operations (1080p ~5.1x,
4K ~10.5x).
…ct hue-gate pruning

Eliminate per-frame 41 MB/165 MB calloc/free buffers (sl and mask) for
RGB-distance and transparency masks and cache the edge-mask buffer on
the instance. Fuse mask evaluation, hue gating, saturation thresholding,
and color ops into a single pass with SSE2 4-pixel RGB-distance
fast-reject, opposite-quadrant and early sat_thres pruning, hardware
double-precision sqrt (bit-exact to hypotf), and exact dot-product
fast-accept/reject before atan2f.

Verified 0 max-abs-diff against baseline on 1080p and 4K across all 4
mask types and all ops (1080p ~1.9x, 4K ~2.1x).
- alpha0ps_alpha0ps: cache scratch float buffers on instance, swap
  pointers instead of full-frame copy-back, zero only borders, vectorize
  shave/shrink/grow and alpha pack/unpack with SSE2, add zero-alloc fast
  path for NOP/threshold, and eliminate per-pixel division in checkerboard.
- alpha0ps_alphagrad: shrink gradient mask from uint32 to uint8 (4x less
  memory), skip redundant fill_grad on op-only changes, vectorize all 5
  alpha ops with SSE2.
- alpha0ps_alphaspot: eliminate redundant memcpy pass by fusing into
  single-pass SSE2 alpha compositing, skip redundant draw on op-only
  changes.

Verified 0 max-abs-diff across all presets on 1080p and 4K.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant