Repository navigation
perf(media-io): video_scaler_scale writes straight into a matching frame (#3192) - #3378
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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_alloclinesize,sws_scalewrites intooutput[]/out_linesizedirectly, 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 fromvideo_frame_inituse 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):
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.
./lintpasses.