Skip to content

perf(desktop-gpui): AVX2/SSSE3 rgba to bgra unpad - #3309

Open
kyzer1023 wants to merge 2 commits into
CapSoftware:mainfrom
kyzer1023:kyzer/desktop-gpui-avx2-rgba-bgra-unpad-5e89
Open

kyzer1023 wants to merge 2 commits into
CapSoftware:mainfrom
kyzer1023:kyzer/desktop-gpui-avx2-rgba-bgra-unpad-5e89

Conversation

@kyzer1023

@kyzer1023 kyzer1023 commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Summary

unpad_rgba_to_bgra (used by frame_image for every RGBA editor preview frame, and portable camera-blur readback when the texture is RGBA) now uses AVX2 vpshufb (8 px) when available, SSSE3 (4 px) otherwise, and the prior scalar loop as fallback. Channel swap + tight pack of already-RGBA pixels — does not replace YUYV/NV12/BGRZ kernels (#3294 path still coexists).

Benchmarks

rustc 1.95.0, opt-level=3, thin LTO, codegen-units=1, RUSTFLAGS=-C target-cpu=x86-64. Intel Xeon family 6 model 207 (AVX2+SSSE3). Warmup 10, 30 measured, interleaved, median. Before = scalar pointer loop in the same binary.

Workload Stride Scalar AVX2
preview 1248×702 5120 0.348 ms 0.207 ms (~1.68×)
1080p 7680 0.830 ms 0.489 ms
4k 15360 3.294 ms 1.950 ms

Tests

Release assert_eq matched on all three sizes. Unit tests: AVX2 and SSSE3 match scalar on full 1248×702 (odd widths + padding).

Notes

RetriggerView in GreptileConfidence Score: 5/5

The PR appears safe to merge; the previous test coverage gap is fixed.

Summary

Adds AVX2 and SSSE3 paths for swapping RGBA to BGRA while removing row padding, with a scalar fallback.

  • RGBA frames now swap channels and drop padding in wider groups.

Reviews (3) · Last reviewed commit: "test(desktop-gpui): cover ssse3 unpad ta..." · Reviewed by Greptile

Dispatch the editor preview's RGBA row unpad through AVX2, or SSSE3 when AVX2 is absent. The same function tightens portable camera-blur readback when that texture is RGBA.
@vercel

vercel Bot commented Oct 26, 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 on lines +514 to +516
if is_x86_feature_detected!("ssse3") {
let ssse3 = unsafe { unpad_rgba_to_bgra_ssse3(&data, width, stride, rows, width * 4) };
assert_eq!(ssse3, scalar);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 SSSE3 edge cases go unchecked

On an AVX2 machine, the odd-width and padding test always selects AVX2. The only direct SSSE3 test uses width 1248, which is divisible by four, so it never checks where SSSE3 stops and the scalar tail starts. This leaves fallback boundary mistakes undetected on those machines.

Run the existing width-and-stride cases directly through each supported helper, keeping the feature checks.

Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/desktop-gpui/kernels/src/frame.rs
Line: 514-516

Comment:
**SSSE3 edge cases go unchecked**

On an AVX2 machine, the odd-width and padding test always selects AVX2. The only direct SSSE3 test uses width 1248, which is divisible by four, so it never checks where SSSE3 stops and the scalar tail starts. This leaves fallback boundary mistakes undetected on those machines.

Run the existing width-and-stride cases directly through each supported helper, keeping the feature checks.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Run the existing odd-width and padded-stride cases through the scalar, SSSE3, and AVX2 helpers, gated by runtime feature detection. The dispatcher picks AVX2 whenever it is available, so those cases never reached the SSSE3 tail before.

Copy link
Copy Markdown
Contributor Author

@greptileai review

1 similar comment
@kyzer1023

Copy link
Copy Markdown
Contributor Author

@greptileai review

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