GPU/descriptor: invalidate HostHeap::copied cache on API writes, unmake, and raw zeroing #807
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/fxceless--victory-fork!807
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-807"
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?
@AscilCH on GitHub · 2026-11-25 08:21 UTC · original
AscilCH:fix/gpu-descriptor-host-copied-cache-invalidation→main· +232 −63 · 2 files · 1 commits · openSummary
Fixes two cache-invalidation bugs in
HostHeap::mirror_copied(crates/victory-gpu/src/descriptor/host.rs), complementary to #792 (which addresses themirror_copiedTOCTOU re-read separately):Stale
HostHeap::copiedfingerprint across API writes andunmake():self.copied[index]was previously written only bymirror_copied()and never cleared whenmirror()(called byCreate*View/CopyDescriptors),texture_slot_gone(), or stale placed-textureunmake()modified or nulled a slot.raw-copy A -> API write B -> raw-copy A(orraw-copy A -> unmake -> raw-copy A) matched*last == print(A)and skipped mirroring, leaving the host heap slot permanently stuck onBorNULL.self.copied[index]viaforget_copied()(always outside theself.madelock to avoid lock-order inversion) whenevermirror()orunmake()modifies or nulls a slot.Raw zeroing of an API-populated slot skipped:
When a slot was populated through D3D12 API calls (
made[index] != 0,copied[index] == 0) and later cleared by raw zeroing in guest memory,*last == 0 && all_zeroreturnedfalsewithout checkingmade[index], leaving the stale host descriptor active and pinning itsKeptGPU resource.*last == 0 && all_zero, checkself.made[index](outside theself.copiedlock) before skipping.Verification
descriptor::tests::copied_fingerprint_invalidates_across_api_writes_unmake_and_zeroingcovering:raw A -> API B -> raw AAPI A -> raw zeroingraw A -> texture_slot_gone unmake -> raw Acargo test -p victory-gpu --lib --locked -- descriptor::— 29 passed, 0 failed, 0 ignored.cargo clippy -p victory-gpu --all-targets --all-features --locked— 0 warnings incrates/victory-gpu/src/descriptor/host.rsandcrates/victory-gpu/src/descriptor.rs.cargo xtask policy— 171 files ok.(AI-assisted; synthetic unit tests only, no game data.)
@Filip722 on GitHub · 2026-11-25 08:56 UTC · original
Independent Proton result on an RTX 5060 Laptop GPU (8 GB), NVIDIA 615.78.08, Bazzite 44, Proton Experimental 11.0-20261112, and vkd3d-proton 3.1.0. Windows MSVC release tests were cross-built with Rust 1.98.1.
I applied the same synthetic fenced D3D12 sampler fixture and #20's DXC support to parent
9376fd6and PR head0cee70d. The tested sequence was raw sampler A → API sampler B → raw sampler A. The GPU adapter was checked by LUID in both runs.The PR’s existing
copied_fingerprint_invalidates_across_api_writes_unmake_and_zeroingtest also passed under Proton. The GPU fixture adapts the sampler probe from #792 to this sequence. These runs used synthetic inputs and verify this descriptor behavior on Proton.OpenAI Codex (GPT-6.2-Sol) adapted and ran the tests and drafted this report.
@MamaLeVrai on GitHub · 2026-11-25 09:54 UTC · original
Test report on real hardware: AMD RX 6950 XT (RDNA2), Windows 11, Rust 1.98.1, with a GPU present. I merged this PR's head
0cee70dintomain9376fd6in a throwaway tree (no conflict).cargo clippy --workspace --all-targets --locked -- -D warningsfails, with the same two errors asmainitself on this machine (function placed_filler_twins is never used,field depth_written is never read,victory-gpu): this PR adds none and removes none.cargo test --workspace --locked: thevictory-gputest binary dies withSTATUS_ACCESS_VIOLATION(0xc0000005) every time: 2 of 2 full runs, then 3 of 3 runs ofcargo test -p victory-gpu --lib, then once more with--test-threads=1. With--test-threads=1the last test started isdescriptor::tests::copied_fingerprint_invalidates_across_api_writes_unmake_and_zeroing, the test this PR adds, so the crash is in it or in the code it calls.mainalone passes (540 passed, two runs). The title was not run, so this says nothing about in-game effect. No game data.AI-assisted (Claude Code); no game data.
@MamaLeVrai on GitHub · 2026-11-25 10:07 UTC · original
Follow-up to my test report above, with where the crash is and what I checked (RX 6950 XT, Windows 11, this PR's head
0cee70dmerged intomain9376fd6).Where. The crash is deterministic:
descriptor::tests::copied_fingerprint_invalidates_across_api_writes_unmake_and_zeroingdies withSTATUS_ACCESS_VIOLATIONeven when run alone. I put progress markers in the test: scenarios A and B pass, and the process dies insidehost.texture_slot_gone(7)in scenario C (the markers before and after that call: only the first prints).Why, as far as I can tell. The heap in this test is a sampler heap (
kind: SAMPLERS).texture_slot_goneis for view heaps: it callsunmake, which reads the slot's made key as a view key (view_at(key as u32, (key >> 32) as u32)) and writes a null view descriptor atself.cpu(index). For a sampler slot the key is a sampler's, and the CPU handle belongs to a sampler heap, so a view descriptor is written there.What I checked. With a local guard
if self.sampler { return false; }at the top oftexture_slot_gone, the crash disappears and the test fails cleanly atassert!(host.texture_slot_gone(7))(line 1334), because the call now returns false for a sampler heap. So the crash is that call on that heap.Two ways out. Run scenario C against a
CBV_SRV_UAVheap with a view made in slot 7 (which is whattexture_slot_goneis for), or keep scenarios A and B on the sampler heap and drop C from this test. A guard like the one above intexture_slot_goneis also worth considering, since calling it on a sampler heap writes the wrong kind of descriptor; that part is your call, I did not test it beyond the run described.Nothing here touches the title.
AI-assisted (Claude Code); no game data.
@LeonardoS11 on GitHub · 2026-11-25 12:54 UTC · original
A note for the rebase onto
a253706, found while carrying this PR on a branch of ours.a253706replaced the heap sync withmirror_copied_page(one lock a page), and on that path this PR's fix does not reach: a slot made through the API and then zeroed as bytes keeps its old descriptor, and this PR's own test (copied_fingerprint_invalidates…) fails once the PR is applied ona253706unchanged.What made it pass here: the page pass collects the slots it found zeroed and checks them against
madeafter it has let go ofcopied, so the order of the two locks is not inverted. It is 27 lines indescriptor/host.rs, commit 9c8a7b7 inLeonardoS11/victory-fork(branchport/v7), in case you want to take it or compare. With itcargo test --workspaceon that branch is 579 passed and 1 failed, the failure being the indirect budget test that is flaky onmain(#847, #849).(Found and fixed on our branch with Claude Code; not run in the game on its own.)
View command line instructions
Manual merge helper
Use this merge commit message when completing the merge manually.
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.