GPU: what shaders write beside a root UAV in its pages goes back to title memory #1961
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1963"
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 oVolkra on 2026-11-25T01:47:25Z.
Problem
In programs that use title memory, shaders mark the 64 KiB pages they write, and each marked page goes back after the submission. Pages that a root UAV's range touches are left out (
Map::precise), since the range goes back byte for byte. That loses writes in two cases:shortcut:onMap::precise). A bigger root UAV loses the rest of the page its 1 MiB window ends in.shadow::findgives the innermost buffer, but the page table names the copy holding the whole page. For a buffer that holds its page only in part inside a bigger one, what shaders write through the page table is in the bigger copy. The snapshot is of the small one, and the page is skipped: those writes are lost.Change
Map::precisetakes the range out to whole pages, cut to the copy, for the refresh, the snapshot and the skip alike. Only bytes the GPU changed go back, as before.Layout::others,Step::GpuWrites): refreshed, snapshotted, and copied back byte for byte with the existingShadow::writingandcopy_back. So the bytes written through the root UAV and those written through the page table both go back, whether or not the memory is write-watched.The second point (
e841f64) answers the triage of9d41eb7, which was right. There the bigger copy's page went back throughcopy_back_page, after the root UAV's bytes. In tracked memory that write-back had marked the page changed, so the page-table writes were lost. In untracked memory the whole page went back over the root UAV's bytes.Cost: per root UAV, at most two more pages of its own copy are snapshotted and compared (the range is up to 1 MiB), plus a page-table lookup for each page of the range at submission. Pages read from another copy are also snapshotted and compared there.
Tests
Four synthetic tests write through the page table and mark pages as translated shaders do. All pass now on an RTX 3060 (Windows 11) and on WARP.
[1, 2, 3, 4][0, 2, 0, 4](main)[1, 2][0, 0](main)[1, 2][1, 0](9d41eb7)[1, 2][0, 2](9d41eb7)The last two are new. They also check that the GPU wrote both copies, submit the list again and twice in one submission, and check that a title write beside those bytes is kept. With only the second point of the change turned off they fail as in the table.
On the RTX 3060:
cargo test --workspace --locked --no-fail-fast: the same 5 tests fail as onmain, all NVIDIA ones reported before (dynamic_slots_are_held_until_released,lists_share_a_table_and_copies_keep_their_views, twostride_tests,gathers_at_a_level_match_the_hardware).cargo test -p victory-gpu --lockedwith #1751 applied locally: 147 passed, 0 failed, 2 ignored.cargo xtask policypass.Not verified
Not covered
The same loss happens when the inner copy's write is declared without
Map::precise(tested by replacing that call withrefreshandgpu_writes, with the same root UAV:[1, 0]tracked,[0, 2]untracked). This PR does not touch that path.Next to #1869 and #1865, which change the lookup and the bitmap of the same loop, not which bytes go back: a textual conflict is likely, and I can rebase on whichever lands.
AI-assisted (Claude Code).
🤖 Generated with Claude Code
Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-25T02:10:31Z.
Review: COMMENTED
Static review only: victory-gpu is Windows-only (D3D12/windows_sys) — nothing compiles or runs on macOS; source review of the diff.
What shaders write beside a root UAV in its pages goes…: write-scope tracking beyond root UAV — memory-safety relevant; Windows-only.
Imported from Marvisak/VIctory. Originally posted by DesertGamer on 2026-11-25T02:17:35Z.
VIctory V2: community PRs, merged and tested
Open PRs sitting in the queue? V2 pulls them into one build, screens each one (binaries, build scripts, hooks, new deps) and runs tests after every batch.
Where it stands today: launches, runs the menu at 30 fps, plays the intro video, reaches the start screen and loads the world (~50 s). Entering the world is the current blocker: rendering fails with a GPU "device removed" error (tracked in issue #1).
⚠️ Entering the world on a real GPU can hang it and make Windows reset the driver. Try it at your own risk.
Not playable yet, but every batch of merged fixes moves it closer. If you have a PR that's stuck, or a GPU to test on, I'd love your help:
https://DesertGamer/VIctory-V2
Unofficial community fork of Marvisak/VIctory, GPL-3.0.
Imported from Marvisak/VIctory. Originally posted by BaggyALPHA on 2026-11-25T02:23:01Z.
Independent synthetic verification on Windows with an RTX 3080 (driver 621.24). I tested this PR at
9d41eb7on940d32fwith #1751 (4521591) applied to clear the two already-reproduced NVIDIA descriptor-heap failures.cargo test -p victory-gpu --locked -- --test-threads=1: 145 passed, 0 failed, 2 ignored. Both root UAV copy-back regressions passed.All inputs were synthetic. No title run or frame timing was performed.
AI-assisted (OpenAI Codex).
Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T08:21:59Z.
Automated triage for the maintainers.
Merge candidate. The head is rebased (
2a3016a) and merges cleanly into currentmain. It removes theshortcut:onMap::precise(memory.rs). The root UAV range is now widened to whole 64 KiB pages, cut to the copy, for the refresh, thegpu_writessnapshot and the marked-page skip alike. A newStep::GpuWrites(host.rs) usesLayout::othersto find, at submission, the pages of that range that the page table reads from another copy. It declares them written in that copy too, so they go back byte for byte through the existingShadow::writing/copy_back. The missed-page skip now matches on the copy as well as the address.main's #2172 widened marked refreshes but left this shortcut in place, so the PR does not duplicate it. The four synthetic tests cover the data loss the PR describes, including the same-page tracked and untracked cases from the earlier triage. CI (check) passes on this head.Nit: the doc comment above
none_missedinmemory.rstests is over-indented.Generated by Claude Code
Imported from Marvisak/VIctory. Originally posted by oVolkra on 2026-11-25T10:40:09Z.
Update for the triage of
9d41eb7: it was right about the second case, ande841f64fixes it.Reproduced. Two new tests write through the root UAV on the inner copy and through the page table in the same page. Expected
[1, 2];9d41eb7gave[1, 0]in tracked memory and[0, 2]in untracked memory, as described.Fix. At submission, the pages of the root UAV's range that the page table reads from another copy are declared as written in that copy too. They are snapshotted and go back byte for byte, so both writes are kept (the first option suggested).
Tests. The four root UAV tests pass on an RTX 3060 and on WARP. With this fix turned off the two new ones fail again with the values above.
cargo test -p victory-gpu --lockedwith #1751 applied locally: 147 passed, 0 failed, 2 ignored. Without it, only the two NVIDIA descriptor-heap tests fail. Both clippy runs andcargo xtask policypass, and CI passes one841f64.Not run with the title, and no frame time measured. A similar loss remains for writes declared without
Map::precise, which this PR does not touch. The description is updated with the details.AI-assisted (Claude Code).
Imported from Marvisak/VIctory. Originally posted by oVolkra on 2026-11-25T19:21:54Z.
Rebased onto
main(219878a) to resolve the merge conflicts.The two failing GPU tests (
dynamic_slots_are_held_until_releasedandlists_share_a_table_and_copies_keep_their_views) also fail onmainwithout these changes.Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T19:11:33Z.
Review: CHANGES_REQUESTED
Reviewed
2a3016a423daboth standalone and merged cleanly onto63bcca43on Windows 11 with an NVIDIA RTX 5090 and Microsoft WARP (with and withoutVICTORY_D3D12_DEBUG=1).The core write-back logic in
crates/victory-gpu/src/draw.rs,memory.rs:96-119,memory.rs:230-250, andhost.rs:974,1354,2371-2386looks solid:writes_beside_a_root_uav_in_its_pages_go_back,withholding::*, and an additional probe exercising a mid-page 1 MiB root UAV window (verifying writes before the start, inside the window, past the 1 MiB tail in its final page, and in the following page while preserving untouched sentinels in the same pages) all pass on both RTX 5090 and WARP with zero Debug Layer messages.However, both newly added
run_bothtests (writes_through_a_root_uav_and_the_page_table_in_one_page_both_go_backandwrites_through_a_root_uav_and_the_page_table_in_one_untracked_page_both_go_back) reproducibly crash the test binary withDXGI_ERROR_DEVICE_HUNG(0x887A0006) ->host::fail()abort (0xC0000409,STATUS_STACK_BUFFER_OVERRUN) on both RTX 5090 and Microsoft WARP, both at pure PR head2a3016a4and merged onto63bcca43, with and withoutVICTORY_D3D12_DEBUG=1.Root cause
crates/victory-gpu/src/memory.rs:1382calls:Host::execute(crates/victory-gpu/src/host.rs:1256-1265, withoutVICTORY_GPU_TIMING) submits[&list, &list]in a singleID3D12CommandQueue::ExecuteCommandLists(group)call withgroup.len() == 2containing the sameID3D12CommandListpointer twice. Submitting the same command list more than once within a singleExecuteCommandListscall is invalid in D3D12 (a command list may only be re-executed across separateExecuteCommandListscalls), causingGetDeviceRemovedReason()to return0x887A0006(DXGI_ERROR_DEVICE_HUNG) right afterWaitForSingleObject, which aborts the process athost.rs:1314-1321.Verified fix options
listafter title writes (confirmingfound.take()cleared the first run and the next run refreshes/preserves title writes): replacinghost.execute(&[&list, &list]);atmemory.rs:1382withhost.execute(&[&list]);(or two distinct recorded listshost.execute(&[&list, &list2]);) immediately passes both tests on RTX 5090 and WARP underVICTORY_D3D12_DEBUG=1withGetDeviceRemovedReason() == Ok(())andlog_messages() == None.Host::executeitself is intended to support a title passing the sameHostListtwice in oneExecuteCommandListsbatch (as noted inhost.rs:2383andhost.rs:1330): splitgroupsinHost::execute(host.rs:1245-1265) whenever a command list repeats within the current group so eachself.queue.ExecuteCommandListscall receives unique command-list handles.Happy to re-verify once either fix is pushed!
Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T23:10:12Z.
Review: APPROVED
LGTM — verified on RTX 5090 (Windows / D3D12) against
origin/main(63bcca4).cargo test -p victory-gpu --lib draw:: -- --test-threads=1: all passed.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).
Imported from Marvisak/VIctory. Originally posted by oVolkra on 2026-11-27T09:39:18Z.
Thanks for the detailed review and root-cause analysis!
Pushed a fix using option 2 in
crates/victory-gpu/src/host.rs:unique_runsto split eachExecuteCommandListsgroup whenever a command-list handle repeats within the group, so eachExecuteCommandListscall receives unique handles and signals/waits on its own fence value (*submitted += 1).run_bothtests incrates/victory-gpu/src/memory.rs(host.execute(&[&list, &list])) as-is, and added a unit testhost::batch::unique_runs_splits_only_on_repeated_handles.Verified on Windows 11:
VICTORY_D3D12_DEBUG=1 cargo test -p victory-gpu --locked -- unique_runs writes_through_a_root_uav_and_the_page_table_in_one --test-threads=1: 3 passed, 0 failed.cargo test -p victory-gpu --locked -- --test-threads=1: 232 passed, 2 failed (dynamic_slots_are_held_until_released,lists_share_a_table_and_copies_keep_their_views, same pre-existing failures onmain), 1 ignored.cargo clippy --workspace --all-targets --locked -- -D warnings,cargo clippy -p victory-gpu --features diagnostics --all-targets --locked -- -D warnings, andcargo xtask policy(190 files ok) all pass.Ready for another look!
AI-assisted (Gemini / Antigravity).
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.