GPU: split and flush command list segments after texture read-backs #2606
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2608"
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 Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-25T16:45:13Z.
Summary
list::read_backcopies texture rows from host readback memory into the title's buffer insideHostList::defer_after, which runs inHost::executeafter the host command lists finish on the GPU.However, a subsequent
CopyTextureRegion(buffer-to-texture viadefer_fill),CopyBufferRegion/CopyResource(defer_copy),CopyMemoryToMemoryX,title_writtentexture upload, or draw/dispatch (Shadow::refresh/bindless::uploads) prepares its title-memory reads insideHostList::run_deferredbefore GPU execution. This causes two related hazards:read_back), transitioning B, and copying Buffer B -> Texture C (or Buffer C) in one command list reads B's stale pre-readback bytes.ExecuteCommandListsbatch:hold::Held::pumpbatches consecutive ready segments on the same queue into a singlepiecepassed to oneHost::execute(&lists)call, so a second command list reading B still runsrun_deferredbefore the first list'sdefer_afterwrites B.Changes
crates/victory-gpu/src/host.rs: track pending read-back guest ranges (read_backs: Vec<(usize, usize)>) inDeferred(cleared automatically onHostList::reset()), withnote_read_back,has_read_backs, andreads_after_read_back.crates/victory-gpu/src/hold.rs&crates/victory-gpu/src/queue.rs: addWorld::flush_after(&|s| s.has_read_backs()inqueue::pump) soHeld::pumpflushespieceimmediately after any segment with pending read-backs, letting itsdefer_afterwrites land before the next segment prepares its copies.crates/victory-gpu/src/list.rs: record read-back row ranges inread_back, extract sharedcut_segment, and cut onto a freshHostListsegment only when a subsequent copy overlaps pending read-back ranges or a subsequent draw/dispatch/title_writtenupload follows in the same list (consecutive independentread_backs do not split).crates/victory-gpu/src/resource.rs&crates/victory-gpu/src/hold.rs: add unit tests covering same-listread_back -> copy_texture_region, same-listread_back -> copy_buffer_region, single-batchExecuteCommandLists(2, [list_a, list_b]), andHeld::pumpflush_afterpiece splitting.Verification
read_back -> copy_texture_regionandread_back -> copy_buffer_regionfail reading sentinel0x5Abytes instead of[1..=16]/[5..=20].--test-threads=1):read_back(4/4),hold::tests(11/11),list::tests(4/4),draw::tests(11/11),resource::tests(20/20) pass.VICTORY_D3D12_WARP=1,--features diagnostics,--test-threads=1): fullvictory-gpu --libsuite passes (202 passed; 0 failed; 1 ignored).cargo clippy -p victory-gpu --all-targets -- -D warningsand--features diagnostics— pass (0 warnings).cargo xtask policy— pass (184 files ok).Imported from Marvisak/VIctory. Originally posted by oni-swr on 2026-11-25T17:15:46Z.
WARP verification of
5bf6464merged cleanly ontoorigin/main13f91ca(detached checkout).Environment: Windows 11. No physical GPU device was created:
VICTORY_D3D12_WARP=1,VICTORY_WARP=1,cargo -j 4, separateCARGO_TARGET_DIR.Commands and results:
cargo clippy -j 4 -p victory-gpu --features diagnostics --all-targets: clean, no warnings.cargo test -j 4 -p victory-gpu --features diagnostics --lib: 202 passed, 0 failed, 1 ignored (origin/main: 198 passed). The 4 new tests pass:hold::a_segment_with_flush_after_runs_before_the_next_segmentand threeresource::a_*read_back*tests.benchmark_private_data_release) run with-- --ignored: 1 passed.list.rstoorigin/mainmakes the threeresourceread-back tests fail (3 failed, 1 passed under theread_backfilter).Review notes:
hold.rspump): textually clean and complementary. #2611 flushes the buffered piece before evaluating a segment's waits, and this PR flushes after a segment with read-backs. #2608 + #2611 together: 204 passed, 0 failed, 1 ignored.World::flush_after, and #2605's new testan_unreadable_wait_holds_its_queue_until_readablebuildsWorld { read, fence, run, signal }without it. With both merged,cargo testfails with E0063. Whichever lands second needsflush_after: &|_| falsethere.next_segmentreturnsNone,cut_segmentreturnsNone, so the deferred copy or draw at that call site is skipped. Before, it was recorded on the current list. This only applies when a read-back is pending and no further segment is available.Not tested: physical GPU or driver behaviour, or a retail title. WARP only.
Independent review and WARP verification by Claude Code (Claude Sonnet 5.5), an AI. No game files, dumps or retail data were used.
Imported from Marvisak/VIctory. Originally posted by kotekompotek on 2026-11-25T17:50:56Z.
Reviewed:
flush_afterends the piece after a segment whose title-memory writes land after submission (read-backs) — the only way a following segment's wait can observe them. Complementary to #2611 (which flushes the buffered piece before evaluating waits); different failure, both needed. Test repro is clean. CI green.Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-25T21:01:42Z.
I reproduced #2781 by recording a real D3D12 GPU write and then invoking the guest CopyBufferRegion vtable entry. The GPU and title copies of the source both contain 0x55667788 after submission. The destination still reads the old 0x11223344 with main
13f91caand with #2608 at5bf6464when both commands share a list or a submission. The separate-submission control reads the new value.34fc326 is one commit on your exact
5bf646428c. It reuses the segmentation path for a deferred buffer copy whose source overlaps a prior declared GPU write. The queue submits the current piece before preparing a later list with the same dependency. The same fixture now reads 0x55667788 in all three layouts. The disjoint-range and copy-before-write controls retain their original values and stay in one segment. Surrounding words stay intact.Six paired runs reproduced these results in both debug settings. The full serial GPU suite passed 203 tests with one ignored in each setting. Strict Clippy in both configurations and asset policy passed. If you prefer to keep this as a separate follow-up, the fork branch retains your exact PR head.
Please retain the Git author on cherry-pick or rebase. If you fold the fix or test into another commit, please add the following trailer.
Co-authored-by: andrewpozdnakov7-jpg [email protected]
AI-assisted with Codex. Synthetic GPU commands on WARP.
Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-25T21:21:32Z.
Thanks for the thorough reproduction and verification of
#2781! Keeping#2608scoped to textureread_backsegmentation and tracking#2781(deferred buffer copies after shader writes) as a separate follow-up (alongside#2810, which tackles#2781inhost.rswithout splitting GPU submissions) keeps both changes clean and easy for maintainers to compare and review.Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T23:20:43Z.
Automated triage for the maintainers.
Recommended for a maintainer's look.
read_backincrates/victory-gpu/src/list.rswrites title memory indefer_after, after the host lists run, while later copies, draws and dispatches in the same list or the sameHeld::pumppiece read title memory before submission. The PR records read-back ranges inDeferred(note_read_back/reads_after_read_backinhost.rs), cuts the segment where a later command could observe them, and ends the piece after such a segment viaWorld::flush_after(hold.rs, set inqueue::pump). New tests cover same-list texture and buffer copies, two lists in one submission, and the piece split; it merges cleanly and CIcheckis passing.On your reply: confirmed.
host_list_after_read_back,host_list_after_buffersandlist_for_texture_copynow usecut_segment(this, current).unwrap_or(current), so a failednext_segmentrecords the command on the current list instead of dropping it. Note for whoever merges #2605 later: its hold test buildsWorldwithoutflush_afterand will needflush_after: &|_| false.Generated by Claude Code
Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-25T23:28:33Z.
Rebased onto
origin/main(842b0cb) and updated in40d72b9bper triage feedback:host_list_after_read_back,host_list_after_buffers, andlist_for_texture_copyincrates/victory-gpu/src/list.rsnow fall back to the current host list (cut_segment(this, current).unwrap_or(current)) whennext_segmentfails instead of dropping the subsequent copy/draw/dispatch command.#2605'sWorldliteral (flush_after: &|_| false) if#2605lands first.Verified after rebase on Windows 11 (RTX 5090 + WARP):
hold::tests(11/11),list::tests(4/4 on RTX 5090 and 4/4 on WARP),cargo clippy -p victory-gpu --all-targets -- -D warnings(default and--features diagnostics), andcargo xtask policy(191 files ok).Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T05:16:10Z.
Review: APPROVED
Tested locally merged onto
origin/main(63bcca4) on Windows 11 x64 (NVIDIA GeForce RTX 5090 + WARP):read_backguest-memory ranges onHostList, cutting onto a fresh segment when subsequent copies/draws/dispatches in the same list would read those bytes, and flushing the piece viaWorld::flush_afterinHeld::pumpensures texture read-backs complete before dependent work in the same list or batch executes.cargo test -p victory-gpu hold::tests: 11 passed, 0 failed (includinga_segment_with_flush_after_runs_before_the_next_segment).cargo test -p victory-gpu resource::tests -- --test-threads=1(RTX 5090): 21 passed, 0 failed (including all 3 new read-back-then-copy tests).VICTORY_WARP=1 cargo test -p victory-gpu resource::tests -- --test-threads=1(WARP): 21 passed, 0 failed.cargo clippy -p victory-gpu --all-targets -- -D warnings: clean.cargo xtask policy: 191 files ok.Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
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.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.