Skip to content

perf(rendering): AVX2 software RGBA→NV12 - #3287

Merged
richiemcilroy merged 6 commits into
CapSoftware:mainfrom
kyzer1023:kyzer/perf-rendering-avx2-rgba-nv12-9048
Oct 26, 2026
Merged

richiemcilroy merged 6 commits into
CapSoftware:mainfrom
kyzer1023:kyzer/perf-rendering-avx2-rgba-nv12-9048

Conversation

@kyzer1023

@kyzer1023 kyzer1023 commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

What

Add an AVX2 path for software RGBA→NV12 in crates/rendering (cpu_yuv / ProjectRenderer::convert_rgba_to_nv12). Dispatches when AVX2 is present and stride/length checks pass. 8-pixel vector kernel; width % 8 and leftover odd row stay scalar. Chroma still averages each complete 2×2 with (sum + 2) / 4 before the matrix (BT.709). Single-threaded (no rayon on this path).

Why

Export / software-adapter encode converts RGBA→NV12 on CPU. Inverse of #3281 (YUV→RGBA). Exact match vs existing scalar (max abs diff 0).

Measurement

Hardware: Intel Xeon family 6 model 207 (KVM, 4 vCPU), AVX2, rustc 1.88.0. Release profile (opt-level=s, codegen-units=1, lto=thin), generic x86-64 (no -C target-cpu=native). Warmup 8, samples 31, median. Stride = renderer 256-byte row padding.

Size Stride Scalar AVX2 Speedup
1920×1080 7680 3.803 ms 1.242 ms 3.06×
3024×1964 12288 10.829 ms 3.582 ms 3.02×
3840×2160 15360 15.064 ms 4.926 ms 3.06×

Max abs diff vs scalar: 0 (incl. odd widths / padded strides).

Test plan

  • cargo test -p cap-rendering --lib cpu_yuv:: (21 passed)
  • Timed benches above under release flags
  • Manual export / software-adapter encode spot check

No overlap with #3281 (YUV→RGBA), #3227 (YUV plane pack), or Windows MF encode PRs.

RetriggerView in GreptileConfidence Score: 5/5

The PR appears safe to merge, with the previous build issue fixed and no new actionable findings.

Summary

Adds an AVX2 path for software RGBA→NV12 conversion and moves the renderer’s scalar conversion into cpu_yuv.

  • Software-rendered frames convert to NV12 faster on AVX2 CPUs.

Reviews (2) · Last reviewed commit: "fix(rendering): gate RGBA to NV12 bounds..." · Reviewed by Greptile

@vercel

vercel Bot commented Oct 25, 2026

Copy link
Copy Markdown
Contributor

@kyzer1023 is attempting to deploy a commit to the Cap Software Inc Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Copy Markdown
Contributor Author

@greptileai review

Comment thread crates/rendering/src/cpu_yuv.rs
@richiemcilroy

Copy link
Copy Markdown
Member

Thanks @kyzer1023! Before we can merge, this needs a 5/5 from Greptile on its latest commit and green CI. It's at 4/5, and there are three things to sort out:

  • It now conflicts with main in crates/rendering/src/cpu_yuv.rs after perf(rendering): AVX2 the software YUV to RGBA path #3281 landed, so it needs a rebase.
  • rgba_nv12_bounds_ok is only called from the x86 block, so on Apple Silicon it's dead code. That fails macOS Clippy (-D warnings). Gate it with the same #[cfg] as its caller.
  • Engine verify and macos / test 1/2 failed on this head. Please check whether that's still the case after the rebase.

Once it's rebased and green, request a re-review.

Export's software BT.709 conversion now uses an AVX2 kernel that matches
the scalar 2x2 average, with a scalar tail for width % 8 and odd rows.
@cursor
cursor Bot force-pushed the kyzer/perf-rendering-avx2-rgba-nv12-9048 branch from ef04413 to f939e0b Compare October 25, 2026 23:10
The helper is only called from the AVX2 dispatch, so aarch64 clippy
with -D warnings reported it as dead code.
@cursor
cursor Bot force-pushed the kyzer/perf-rendering-avx2-rgba-nv12-9048 branch from f939e0b to af48fba Compare October 25, 2026 23:10

Copy link
Copy Markdown
Contributor Author

@greptileai review

@kyzer1023

Copy link
Copy Markdown
Contributor Author

@richiemcilroy Ready for another look: rebased onto main after #3281, rgba_nv12_bounds_ok is now cfg-gated so aarch64 Clippy is clean, and the Engine verify/macOS failures are gone. Greptile 5/5 and CI green on af48fba63 (Vercel auth checks aside).

@richiemcilroy
richiemcilroy merged commit 586522a into CapSoftware:main Oct 26, 2026
47 of 49 checks passed
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.

2 participants