Skip to content

perf(media-io): video_scaler_scale writes straight into a matching frame (#3192) - #3378

Merged
zackees merged 2 commits into
masterfrom
perf/3192-scaler-direct
Nov 1, 2026
Merged

zackees merged 2 commits into
masterfrom
perf/3192-scaler-direct

Conversation

@zackees

@zackees zackees commented Nov 1, 2026

Copy link
Copy Markdown
Member

Fixes #3192

RED (guard and measurement) e6b1f20: a new cmocka test, test_video_scaler_direct (Linux, libobs only), scales a BGRA picture to NV12 at 1080p, at 4K, and from 4K to 1080p. It scales into a frame laid out like the scaler's internal buffer (32-byte aligned, rows a multiple of 32) and into one with rows 16 bytes longer. It requires identical visible bytes from both and prints the median of 15 frames for each. It passes on master too, where both frames take the copy; it is the guard that the direct path is bit-exact.

GREEN 43f52d8: when every output plane is 32-byte aligned and its linesize is a multiple of 32 and at least the internal av_image_alloc linesize, sws_scale writes into output[]/out_linesize directly, with no internal buffer and no plane copy. Rows then have the internal buffer's padding, so swscale's row writes stay inside each row. Any other layout keeps the existing buffer and copy. Frames from video_frame_init use the 32-byte base alignment, so 1080p and 720p NV12 take the direct path.

Measured (median of 15 frames, Linux container, BICUBIC; same binary built on master and on this branch):

case master, aligned frame this PR, aligned frame (direct) this PR, odd linesize (copy)
1080p BGRA→NV12 6.65 ms 6.65 ms 7.39 ms
4K BGRA→NV12 30.3 ms 24.3 ms 25.9 ms
4K→1080p BGRA→NV12 21.9 ms 20.9 ms 20.9 ms

The colour conversion dominates. The copy the issue sized at about 1.2 ms per 4K frame is a few percent of a 25–30 ms scale. Within one run the direct path is 6% faster than the copy path at 4K and the same at 4K→1080p (a 1080p copy is small). Run-to-run noise in this container is about ±10% (on master the two identical-layout cases already differed by 3.5% at 1080p and 11% at 4K), so read the gain as a modest one at 4K, not as a measured 20%. The change is bit-exact and removes a full-frame memcpy, so I think it is worth landing even with that much noise.

The issue asked for a Criterion bench. The Rust benches call the C oracle's own video_scaler_scale (rust/obs-c-oracle/oracle/video_io.c), which stays the unchanged reference, so a Criterion bench would measure the old code. The C test above measures libobs itself.

Tiers: libobs C only. Tier 2: the new test. Tier 3 is unchanged (the oracle copy is untouched). Tiers 1 and 4 do not apply. ./lint passes.

@zackees
zackees enabled auto-merge November 1, 2026 06:55
@zackees
zackees added this pull request to the merge queue Nov 1, 2026
Merged via the queue into master with commit 08cf33c Nov 1, 2026
42 checks passed
@zackees
zackees deleted the perf/3192-scaler-direct branch November 1, 2026 07:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

perf: media-io: let video_scaler_scale write straight into the output frame

1 participant