Skip to content

perf(filter): optimize three_point_balance, colorenhance, hueshift0r, sopsat, and sigmoidaltransfer - #341

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

Quantum-Quasar wants to merge 5 commits into
dyne:masterfrom
Quantum-Quasar:perf/color-grading-wave3

Conversation

@Quantum-Quasar

Copy link
Copy Markdown

Summary

Bit-exact (max_abs_diff = 0) CPU rendering optimizations for five color grading plugins:

  • three_point_balance: Switch from column-major (width * 4 stride) to row-major traversal, cache stack-computed uint8_t[256] LUTs with dirty tracking, and 4×-unroll uint32_t packing.
  • colorenhance: Add a 4-pixel SoA SSE2 Oklab pipeline with a boundary-guarded 2-iteration Halley SSE2 cbrtf (falling back to libm cbrtf within 0.002 of an integer boundary for 0 max-abs-diff) and double-precision SSE2 cubing.
  • hueshift0r: Eliminate redundant full-frame memcpy and fuse into a single-pass 4-pixel SSE2 3×3 hue-rotation matrix multiply.
  • sopsat: Cache LUTs across frames with parameter dirty-checking, precompute weighted Rec. 709 double luma/channel LUTs, and vectorize 2 pixels at a time with SSE2.
  • sigmoidaltransfer: Precompute double-precision Rec. 601 luma LUTs + packed uint32_t sigmoid RGB LUT and vectorize 2 pixels at a time with 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
three_point_balance 12.35 ms 2.11 ms 5.85× 146.53 ms 9.54 ms 15.36× 0
colorenhance 213.06 ms 37.85 ms 5.63× 854.35 ms 151.92 ms 5.62× 0
hueshift0r 6.51 ms 3.07 ms 2.12× 26.91 ms 12.37 ms 2.18× 0
sopsat 13.44 ms 6.64 ms 2.03× 53.80 ms 27.17 ms 1.98× 0
sigmoidaltransfer 3.44 ms 2.23 ms 1.54× 14.08 ms 9.19 ms 1.53× 0

Verification

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

frei0r perf added 5 commits November 26, 2026 15:08
Eliminate column-major cache thrashing (stride width*4 bytes per pixel)
by switching to row-major traversal with memcpy for the unmodified split
preview half. Cache stack-computed uint8 LUTs on the instance and only
rebuild when color parameters change, with 4x unrolled uint32 pixel
packing.

Verified 0 max-abs-diff against baseline on 1080p and 4K across all
preview modes (1080p ~4.2x, 4K ~14.4x).
…SSE2

Skip rebuilding the 4x256 pow() lookup tables on every frame when
parameters are unchanged, store LUTs inline instead of heap-allocating,
precompute weighted luma and double channel LUTs, and vectorize the
Rec. 709 saturation loop 2 pixels at a time with bit-exact SSE2 double
arithmetic and packed uint32 stores.

Verified 0 max-abs-diff against baseline on 1080p and 4K (~2.5x).
Eliminate the redundant full-frame memcpy before applymatrix and
vectorize the 3x3 floating-point color matrix multiplication and
[0, 255] saturation 4 pixels at a time with SSE2.

Verified 0 max-abs-diff against baseline on 1080p and 4K (~2.1-2.2x).
…th SSE2

Precompute 0.299*r, 0.587*g, 0.114*b double LUTs and a packed uint32
sigmoid RGB LUT on the instance, and vectorize the Rec. 601 luma sum
2 pixels at a time with bit-exact SSE2 double arithmetic.

Verified 0 max-abs-diff against baseline on 1080p and 4K (~1.5x).
… Halley cbrtf

Vectorize the entire RGB->XYZ->Oklab->LUT->XYZ->RGB pipeline 4 pixels
at a time in SoA SSE2. Replace scalar libm cbrtf with a 2-iteration
Halley SSE2 approximation guarded by an integer-boundary check (falling
back to exact libm cbrtf only when any lane lies within 0.002 of an
integer boundary), and replace scalar powf(x, 3) with exact
double-precision SSE2 cubing.

Verified 0 max-abs-diff against baseline on 1080p and 4K (~5.6x).

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