Pack and write capture pictures on a thread of their own #310
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/TaynanGT--Vice-Tay!310
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-310"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@wondasahnet on GitHub · 2026-11-27 15:37 UTC · original
wondasahnet:perf/capture-off-submit-thread→main· +364 −9 · 5 files · 3 commits · openWith
VICTORY_CAPTURE_WORLDevery 8th frame's picture in the world is saved as a PNG. The picture was packed (deflate, and a CRC-32 made a bit at a time) and written by the thread that prepares the submissions, the one a frame waits for. The pictures are there to judge the very runs they slowed down.Measured
RTX 5080, Ryzen 7 9800X3D, 64 GB, Windows 11. Series S build, prison intro (cell, corridor, common room), windowed, diagnostics build,
-Machine 4070, captures on. Self-driven runs; fps is the median of the frame lines with at least 1,000 draws, p10 the 10th percentile.A 25 s sampling profile of the submitting thread before the change: 23% of its samples in saving capture PNGs. After it that share is gone from the thread.
Runs of this scene differ by about 1 fps from one to the next, so the table says "somewhat more", not a ratio; the profile is the firmer evidence. A run without captures is not affected at all.
What changes
victory-capturethread through a bounded line of 16 pictures.Tests
crc_matches_the_png_check_valuegains the standard check value ("123456789"gives0xcbf43926) beside the PNGIENDone.Run on this branch at
708e0fa(basec44e2ce), Windows 11, RTX 5080, Ryzen 7 9800X3D, 64 GB:cargo check --workspace --all-targets --lockedcargo test --locked -p victory-gpu --features diagnostics --lib -- capture::cargo build --locked --profile diag -p victory --features diagnostics(before the rebase ontoc44e2ce, which was clean)git diff --checkThe four CI commands were run once on a local merge of this branch with five other branches of mine, on base
fe8a7a2before the rebase: both clippy commands clean,cargo test --workspace --lockedpassed, andcargo test --workspace --all-features --locked -- --test-threads=1passed exceptmodules::lifecycle::tests::direct_close_suspends_and_exitsinvictory-hle, a window test in a crate this branch does not touch; it passed in the default job of the same run and when run again alone. After the rebase the merge was linted again with both clippy commands: clean.Not covered
Since the runs above the branch was rebased onto
mainat16edfec(no conflicts;cargo check -p victory-gpu --all-targets --lockedclean); its tip is2312bbdnow.@TaynanGT on GitHub · 2026-11-27 15:54 UTC · original
@wondasahnet The drop in submit-thread samples spent writing PNGs is worth keeping. The open case is a normal close with pictures still queued. Drain the worker on that path and verify a PNG written by the worker before calling the capture complete.
@UncommonDLL on GitHub · 2026-11-27 16:30 UTC · original
@wondasahnet @TaynanGT We implemented the normal-close drain on
2312bbd3. The Windows regression held a worker write pending, filled the queue and exercised the synchronous fallback. Before the drain returned, the worker finished 17 writes. All 18 PNGs decoded to 11×7 RGB8 and matched every expected pixel. With the drain disabled, the same test caught close returning with zero worker writes completed.The four capture tests passed. The existing
WM_CLOSEprocess-exit test passed separately. The patch credits Cuebert’s queued-frame regression in fxceless #142. OpenAI Codex implemented and tested the change on Windows. Claude Sonnet 5.5 Extra reviewed it.Capture-drain-aabfb888.patch
Apply with
git am Capture-drain-aabfb888.patch.@TaynanGT on GitHub · 2026-11-27 16:37 UTC · original
@UncommonDLL The 18 pixel-exact files and the disabled-drain control cover the normal-close case. Please put the drain and its regression on the PR branch so the Windows checks run both together on the new head.
@wondasahnet on GitHub · 2026-11-27 16:38 UTC · original
Done in
db2a446, on top of the reviewed tip.The drain. The capture thread's line can now be closed. At an orderly end of the process the line is closed and the thread is waited for until every picture that was in it is written. The wait is bounded at three seconds; if it runs out, the number of pictures left is logged and the process goes on ending, so a disk that does not answer cannot hold the exit. It waits for the thread's last picture rather than for the thread's own end, because a thread ends under the loader's lock, which the exiting thread may hold. A picture saved after the drain is written by its caller.
It runs where the pipeline books are already saved:
lifecycle'send, beforeTerminateProcess);exit(the loader's hook that runs before the other threads are ended, inside its five-second deadline);The PNG written by the worker.
pictures_in_the_line_are_valid_png_files_when_finish_returnssends eight pictures through the process's own line into a temporary folder, waits as the exit does, then reads each file back and checks it as a decoder would: signature; every chunk's length and check value, computed with a bit-at-a-time CRC-32 rather than the writer's table; the header's width, height, bit depth, colour type, compression, filter and interlace fields; the packed rows inflated (with the zlib crate that is already a dependency, no new one) and compared byte for byte with the rows handed in; filter type 0 in every row; the end chunk last and nothing behind it. The test asserts that each picture really went to the thread and not to the caller's fallback.Two more tests on the line itself:
a_closed_line_is_worked_off_before_the_wait_ends(nine of ten pictures still queued when the line is closed; all ten are worked off, in order) andthe_wait_for_the_line_is_bounded_and_counts_what_is_left(a thread that never comes back holds the wait for its bound and no longer; the three pictures it had are reported as left).Checks.
cargo check --workspace --all-targets --locked, andcargo clippy --workspace --all-targets --locked -- -D warningswith and without--all-features: clean.cargo test --locked -p victory-gpu --features diagnostics --lib -- capture::: 6 passed, five runs.cargo test --locked -p victory-hle --all-features --lib -- lifecycle --test-threads=1: 19 passed; that includes the close test whose child process now runs the drain (with an empty line).Not covered.
TerminateProcessorabort, the exit after a device loss, a crash, the loader's deadline running out, a kill from outside. Up to 16 pictures can still be lost there.@TaynanGT on GitHub · 2026-11-27 16:45 UTC · original · edited 2026-11-27 16:50 UTC
@wondasahnet The three-second cap and the completion signal before thread teardown address the slow-disk and loader-lock cases. I’ve started the Windows checks on
db2a446. There’s one overlap to cover: a window close and CRT exit can both reachfinish(). Once the first caller changes the line toCaller, the second can end the process while the first still waits. The shared wait is up in926102e. The isolated held-writer test reproduced the early return ondb2a446and passes with both callers waiting. The Windows checks are on the new head.View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.