feat(gpu/host): add native F12 backbuffer PNG screenshots (#276) #360
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/360"
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?
Imported from Androtim/MiniVI. Originally posted by Androtim on 2026-12-02T16:17:25Z.
Implements full-resolution native swapchain backbuffer screenshots triggered by pressing
F12, part of #276.Summary
VK_F12on the foreground key thread with edge debouncing so holdingF12triggers one capture per press. Enabled by default; setVICTORY_SCREENSHOTS=0to disable.F3/menu/notice overlay draws onto the active swapchain backbuffer inpresent_planes, issues aCopyTextureRegioninto a pooledID3D12Resourcereadback staging buffer before transitioning toD3D12_RESOURCE_STATE_PRESENT.victory-screenshotworker thread, waits for GPU completion viaID3D12Fencewithout blocking the presenter, convertsRGBA8/BGRA8/BGRX8/R10G10B10A2/RGBA16Fbackbuffers to 8-bit RGB PNG viazlib-rs, writes collision-safeminivi-YYYYMMDD-HHMMSS.pngunder<VICTORY_HOME>/screenshots(or%LOCALAPPDATA%/victory/screenshots), and logs oneINFOline with filename and pixel dimensions.crates/victory-gpu/src/host/screenshot.rscovering format conversions, edge trigger debouncing, env gating, screenshot directory selection, and unique filename generation.Verification (offline host checks)
cargo clippy -p victory-gpu --all-targets -- -D warnings: passed (0 warnings)cargo clippy -p victory-gpu --all-targets --all-features -- -D warnings: passed (0 warnings)cargo test -p xtask: 8 passed, 0 failedcargo xtask policy: 326 files okcargo test -p victory-gpu --lib -- --test-threads=1: 731 passed, 0 failed, 39 ignored (including all 8host::screenshot::tests; ignored cases are pre-existing host-GPU/benchmark tests)Imported from Androtim/MiniVI. Originally posted by Androtim on 2026-12-02T16:34:50Z.
Architect Review (CI
46925476715GREEN, clean-room verified):F12native backbuffer screenshot implementation (VICTORY_SCREENSHOTS=0kill-switch, zero overhead whenF12is not pressed,backresource-state transitionsCOPY_DEST -> COPY_SOURCE -> PRESENTmatch both composed and non-composed paths inpresent_planes, RAIIEventHandle+ device-removedu64::MAXguards + 30s timeout, staging buffer dropped before PNG encode/disk I/O, atomiccreate_newfilenames, 8/8 unit tests).F12smoke test (confirming full-res PNG withF3overlay, correct RGB orientation, and zero D3D12 errors) before merge.Imported from Androtim/MiniVI. Originally posted by Androtim on 2026-12-02T17:05:35Z.
Automated triage for the maintainers (not an approval).
Verdict:
needs-work· CI (check):passingOverall this is a clean, well-scoped implementation of native
F12backbuffer PNG screenshots incrates/victory-gpu/src/host.rsandcrates/victory-gpu/src/host/screenshot.rs. The resource state transitions inpresent_planes(COPY_DEST -> COPY_SOURCE -> PRESENT), rising-edge key debouncing, format conversions, collision-safe PNG writing, and unit tests all look solid.There are two concrete synchronization bugs in
wait_for_fence(crates/victory-gpu/src/host/screenshot.rs) that should be fixed before merging:EventHandlesignal:worker_loopreuses a single auto-resetEventHandleacross jobs. If a previous job returns viaWAIT_TIMEOUT(afternow >= target) or times out after 30s and the GPU signalseventafterward,eventremains signaled for the next job (SetEventOnCompletiondoes not reset it). Inwait_for_fence, theWAIT_OBJECT_0arm returnsfence.GetCompletedValue() != u64::MAXwithout checking>= target, soprocess_jobcanMapand readpending.bufferbefore the GPU copy has finished.let Some(event) = event elseloop,while fence.GetCompletedValue() < targetimmediately exits whenGetCompletedValue() == u64::MAX(sinceu64::MAX < targetisfalse), making the inner== u64::MAXcheck unreachable and returningtrueinstead offalseon device removal.Minor note
crates/victory-gpu/src/host.rs(present_planes), whenslotisSome(_)andexecute_own_with_fencereturns(0, None)(ifsubmitfell back to synchronous execution),screenshot::submitis skipped and the capture is silently dropped. Consider confirming whetherNonemeans synchronous completion vs submission failure, or unifying the match onfence_value.To change the verdict:
wait_for_fence(crates/victory-gpu/src/host/screenshot.rs), onWAIT_OBJECT_0, verifylet now = fence.GetCompletedValue();is neitheru64::MAX(returnfalse) nor< target(keep waiting / re-arm if stale) before returningtrue.event == Nonepolling fallback ofwait_for_fence, checklet now = fence.GetCompletedValue(); if now == u64::MAX { return false; } if now >= target { return true; }inside aloopso device removal returnsfalse.F12in-game with and without theF3overlay/menu, plus rapid presses andVICTORY_SCREENSHOTS=0) to verify the D3D12 backbuffer readback and PNG output end-to-end.Generated with Antigravity CLI (
agy).Imported from Androtim/MiniVI. Originally posted by Androtim on 2026-12-02T19:36:24Z.
Verified
5c67b199resolves Audit Pass #3 Finding#12(and bothminivi-triagewait_for_fencenotes:ResetEventbeforeSetEventOnCompletion, re-checkingGetCompletedValue() >= target+u64::MAXdevice-removal detection across both event and polling paths, bounded 30s timeout, plusFakeFenceunit tests). CI46952425065is GREEN, zero runtime overhead whenF12is unused,VICTORY_SCREENSHOTS=0kill-switch. Merging tomain.