Skip to content

perf(renderer): row-pair RGBA to YUV420 converter for targets without NEON - #281

Open
mikenilox wants to merge 1 commit into
dmtrKovalenko:mainfrom
mikenilox:perf/yuv420-row-pairs
Open

mikenilox wants to merge 1 commit into
dmtrKovalenko:mainfrom
mikenilox:perf/yuv420-row-pairs

Conversation

@mikenilox

@mikenilox mikenilox commented Dec 1, 2026 •

Copy link
Copy Markdown

Problem

On x86_64 (and every target without NEON), fill_yuv420_from_rgba_pixmap_accelerated falls back to the scalar converter, which tests every pixel for even coordinates and indexes with bounds checks. Rendering short motion-graphics cards with the Skia CPU renderer on an AMD EPYC server, perf put 26% of the whole process (Skia rasterization and libx264 included) in fill_yuv420_from_rgba_pixmap_base.

Solution

An accelerated converter for targets without NEON that walks the image two rows at a time:

  • the chroma of each 2×2 block is computed once, with no per-pixel branch;
  • the rows are sliced up front, so the loops carry no bounds checks;
  • Y is summed in 16-bit lanes (a const assertion checks that every matrix fits), twice as many per vector as i32.

LLVM vectorizes the loops. On x86_64 the same code is also compiled for AVX2 and picked at runtime with is_x86_feature_detected!. Odd widths and heights take the scalar path. The output is bit for bit identical to fill_yuv420_from_rgba_pixmap_base (same chroma sample, same flooring). NEON targets are untouched.

Before / after

cargo bench -p fframes --bench yuv420_conversion -- 1920x1080 on an AMD EPYC 9354P:

1920×1080 before (scalar) after (row pairs, AVX2)
YUV420 Conversion 7.20 ms 1.06 ms (6.8×)

Without AVX2 (x86_64 baseline, SSE2) the same code measured ~3.0 ms in a standalone bench.

End to end, on a batch of 53 real cards (Skia CPU renderer, libx264 veryfast, 1 thread) with the same change applied to our fork: CPU time 407 s → 309 s (−24%), wall time 265 s → 192 s, and all 50 rendered MP4s byte-identical to before.

Tests

  • The three yuv_neon_* tests now run on every target as yuv_accelerated_*.
  • New yuv_accelerated_matches_base_on_any_size: odd sizes, padded line sizes, both matrices, random 1920×1080.
  • The benchmark measures the accelerated converter on every architecture, not only aarch64.
  • cargo test -p fframes --lib yuv: 7 passed. cargo clippy -p fframes --all-targets -- -D warnings: clean. cargo fmt --check: clean.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Performance
    • YUV420 conversion can now use accelerated processing on additional CPU architectures, including AVX2-capable x86_64 systems.
    • Conversion retains a scalar fallback for dimensions that are nonpositive or odd, while supported even dimensions use paired-row processing.

… NEON

On x86_64 and every other target without NEON, the accelerated converter
fell back to the scalar one. It now walks the image two rows at a time:
the chroma of a 2x2 block is computed once, rows are sliced up front so
the loops carry no bounds checks, and Y is summed in 16 bit lanes (a const
assertion checks every matrix fits). On x86_64 the same code is also
compiled for AVX2 and picked at runtime. Odd sizes keep the scalar path.
The output is bit for bit the scalar converter's.

The NEON tests now run on every target as yuv_accelerated_*, a new test
covers odd sizes, padded line sizes and both matrices, and the benchmark
measures the accelerated converter on every architecture.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The non-NEON YUV420 converter now processes even dimensions in row pairs and uses AVX2 dispatch on supported x86_64 systems. Tests compare accelerated output with the base converter across dimensions and strides. The accelerated benchmark is registered on all targets.

Changes: YUV420 acceleration

Layer / File(s) Summary
Paired-row conversion
fframes/src/renderer/pix_fmt.rs
The converter uses scalar conversion for nonpositive or odd dimensions. For positive even dimensions, it uses paired-row conversion and selects an AVX2-targeted path when AVX2 is detected on x86_64. A compile-time check validates luma-weight bounds.
Conversion tests
fframes/src/renderer/tests/yuv420_conversion_tests.rs
Tests compare accelerated and base output for both matrices, multiple dimensions, and padded strides. The accelerated tests no longer use NEON-specific names or target-feature gates.
Benchmark registration
fframes/benches/yuv420_conversion.rs
The accelerated benchmark is registered on all targets and uses the accelerated_{width}x{height} name.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Refactor

Sequence Diagram(s)

sequenceDiagram
  participant Caller as YUV420 conversion caller
  participant AcceleratedConverter
  participant ScalarConverter
  participant AVX2Detection
  participant AVX2Converter as convert_avx2
  participant RowPairs as row_pairs::convert
  Caller->>AcceleratedConverter: Convert image
  alt Dimensions are nonpositive or odd
    AcceleratedConverter->>ScalarConverter: Convert image
  else Positive even dimensions on x86_64
    AcceleratedConverter->>AVX2Detection: Check AVX2 support
    alt AVX2 is available
      AcceleratedConverter->>AVX2Converter: Convert image
      AVX2Converter->>RowPairs: Forward conversion
    else AVX2 is unavailable
      AcceleratedConverter->>RowPairs: Convert image
    end
  else Positive even dimensions on another non-NEON target
    AcceleratedConverter->>RowPairs: Convert image
  end
Loading

Suggested reviewers: dmtrkovalenko

Merge Risk: Minimal · up to f1d87

Non-NEON targets now convert even-sized frames with a faster paired-row path, using AVX2 where available. The reported tests show output matching the previous converter, and odd sizes keep the original path. No merge-blocking risk is evident.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the main change: a row-pair RGBA to YUV420 converter for targets without NEON, with the perf() type. The summary and objectives confirm this is the primary change. The title does not m…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the main change: a row-pair RGBA to YUV420 converter for targets without NEON, with the perf() type. The summary and objectives confirm this is the primary change. The title does not mention the x86_64 AVX2 dispatch or the test renaming, but those are secondary aspects.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: a47c441f-d0c8-404e-882c-61acc336526b
Commits

Reviewing files that changed from the base of the PR and between 356429f and f1d8739.

Files selected for processing: 3

  • fframes/benches/yuv420_conversion.rs
  • fframes/src/renderer/pix_fmt.rs
  • fframes/src/renderer/tests/yuv420_conversion_tests.rs

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

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