Repository navigation
media-io: Scale directly into compatible output planes (experimental) - #743
chriscoveries wants to merge 4 commits into
Conversation
|
he's pushing the CI to the remote and doing minimal builds on his local end |
|
i've put the AI into a dream state and it's consolidating the strategies of the last day and evolving them last 24 hours we experimented with the merge queue The end result was one of the PRS got ejected eight times so we're now working on version two of the CI four this repo Hopefully the friction is reduced for you completely today. Please feel free to evolve the CI as we go. The guidelines are in the repo. |
|
CI triage: the only failure is "Rust Tier 2 macos-26", and it is a runner/SDK problem, not your change: the Xcode link of libobs fails with |
77db966 to
8b9a65b
Compare
|
Thanks for the triage, @zackees. I've rebased onto master ( Re-tested locally at that exact head on an Apple Silicon Mac ( |
|
Speed numbers, if you'd like them. We don't time on our shared machines, so we wrote a small before/after script that a reviewer can run on a quiet machine.
It prints a Markdown block with your machine details; please paste it here. The scaler source it compares is identical to this PR's rebased head. Tested on our Mac:
We haven't run a real timing. |
|
Review from the maintainer side. I read the body, the comments and the diff at Benchmark. Thanks for writing the A/B script. To be plain about where it stands: your 19:20 comment gives the method and the correctness results (12 of 12 byte-identical, unit tests pass), but it has no timing numbers yet, and the body still says the speed-up is unmeasured. So nothing posted so far shows the change is faster, and I can't say the numbers support it. I have not run Correctness (read, not run). The guards look sound to me: destination planes must be present, Tests. The alias fix has the right shape:
CI. 18 pass, 5 skipped, 0 failing, and the branch merges cleanly with master, so no rebase is needed. Verdict: (a) move out of draft after these changes: (1) a timing block that shows a gain beyond noise; (2) split the characterization test into its own commit ahead of the behaviour change; (3) the tail-overrun evidence above. No edits to existing C tests or public headers are involved, which is good. |
|
Coordinator check-in, @chriscoveries: there's been no activity here since the maintainer's review about 9 days ago. Are you still working on this? If you've moved on, say "handed off to the coordinator" and I'll keep the mechanical work (rebases, list conflicts, formatting) moving. Anything in the review that needs a design change stays with you. |
|
Status from the coordinator, @chriscoveries — this draft is
Context for why I am asking rather than just doing it: the last commit ( |
Add test_video_scaler, a characterization test that pins what video_scaler_scale() writes today, before the direct-output change. It scales a BGRA source into packed, padded and misaligned destinations of several formats and checks: - the visible bytes match a padded-stride reference; - canary bytes behind each plane and the uncopied last chroma row on odd heights stay untouched (characterized, not endorsed); - repeated calls through one scaler give the same output. The exact-extent cases give each plane exactly linesize * rows bytes, ending right before an inaccessible page, at widths that are not multiples of 16 or 32 (33 to 998), for eight formats and the point, fast bilinear and bicubic scale types. Any read or write past the last row faults, whichever code makes it, including FFmpeg, which is not built with ASan. No library change; the test passes on the current scratch-copy path.
video_scaler_scale() always had swscale write into the scaler's own scratch image and then copied every plane into the caller's output. When the caller's planes already have the layout swscale would write, that copy is extra work on every frame. Let swscale write straight into the caller's planes when every plane the destination format uses is present, aligned to base_get_alignment() and at FFmpeg's packed linesize for the width (av_image_fill_linesizes), and the height is a multiple of the vertical chroma subsampling. The frames video-io.c converts into come from video_frame_init(), whose planes are aligned and at these linesizes for even sizes. Every other layout keeps the scratch copy, so its output does not change. test_video_scaler passes unchanged, OFF and ON, including its exact-extent cases, which now take the direct path.
Add test_video_scaler_alias: BGRA, I420, NV12, P010 and YUVA sources scaled to BGRA into an output that overlaps the input (the same address, 128 bytes after or before it, or starting in a chroma plane). Each case compares three successive frames with a scratch-copy reference and checks that no byte outside the output changes. It fails on the direct path of the previous commit, which lets swscale read input rows it has already overwritten.
The direct-output path lets swscale write straight into the caller's planes. When those planes overlap the input, including partial and cross-plane overlaps, swscale reads pixels it has already overwritten. Build checked spans for every source and destination plane, and take the direct path only when all of them are disjoint, destination planes included, and the span arithmetic cannot overflow. Otherwise use the existing scratch copy. The predicates live in media-io/video-scaler-overlap.h, which libobs-media.pch.h includes for video-scaler-ffmpeg.c.h. They use no pointer arithmetic, so test_video_scaler_spans compiles the header alone, without libobs or FFmpeg, and checks them, including all 16 source and destination plane pairings and the arithmetic limits.
8b9a65b to
81cf5ee
Compare
|
Rebase status (coordinator pass, 2026-12-04): this branch is 1500+ commits behind master and was not rebased. A test merge onto current master conflicts in three places:
To rebase: |
GOOD MORNING OBSRUSTEES! 👋 Hi @zackees, hi everyone! We're still recovering on CI, but we're back in the game a little. @rdoupe, judging by how fast your fixes land, your CI must be the size of a small moon. 🌕
Problem
video_scaler_scalealways has swscale write each scaled frame into an internal scratch buffer, then copies it plane by plane into the caller's output. When the caller's planes are already aligned and packed, that copy is pure overhead on every frame.Fix
tests.d:test_video_scaler: characterization of packed, padded and misaligned destinations, repeated calls and odd heights.test_video_scaler_alias: BGRA, I420, NV12, P010 and YUVA sources scaled into an output that overlaps the input. It compares three successive frames with the scratch-copy result and checks that memory outside the output is untouched.test_video_scaler_spans: the overlap predicates themselves, including all 16 source and destination plane pairings and arithmetic limits.Evidence
Local runs on an Apple Silicon Mac (macOS 27, Xcode 27.0,
macos-cipreset, RelWithDebInfo):77db966d1): all three tests pass withENABLE_RUST_LIBOBSOFF and ON, 10 repeats each (60 of 60). The span checks also pass a standalone build under AddressSanitizer and UBSan: 65,536 range comparisons, plus the plane and overflow cases.a3a3e3fd0, before the overlap fix), OFF and ON:test_video_scaler_aliasfails withMemory is not equalinscaler_alias_bgraandscaler_alias_planar. The existingtest_video_scalerpasses 10 of 10. So the direct path, as first posted here, corrupted overlapping output, and this update fixes it.--dry-run --Werroron the changed C files and gersemi 0.25--checkon the new CMake fragments: clean.A local note for anyone running these on a Mac with Homebrew cmocka: RelWithDebInfo tests signed with the hardened runtime refuse to load it (
different Team IDs). We re-signed the three test executables ad hoc withdisable-library-validationand added absolute rpaths before runningctest.Compatibility & risk
Status
Draft and experimental. Updated with the overlap fix and its tests.
Thank you to the obs-rust maintainers and contributors for building this project in the open. In the American spirit of free expression and individual independence, and with the principle of judging contributions on their merit alone, this PR is a small piece of what independent people can build when they come together.