d3d12_xs: drop gpu_va ranges when their resource is destroyed #283
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
library
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/omonkeyz--xbox-emulator!283
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/283/head"
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?
@GDAgent on GitHub · 2026-11-23 11:55 UTC · original
GDAgent:fix/d3d12-gpu-va-forget-destroyed→main· +155 −5 · 1 files · 1 commits · closed without mergingLibrary / area:
d3d12_xs(gpu_va.rs)Exports changed (exports.txt rows): none
Source of the behaviour: a crash in The Matrix Awakens (Xbox Series X build), native Windows 11 on an RDNA2 GPU (gfx1032); not run under Proton.
gpu_varecords the GPU (and mapped CPU) address range of every buffer and texture it is told about, but never removed a range when the title released the resource. The range stayed until a newer resource happened to overlap it, solookup,lookup_bufferand similar calls could return a resource that no longer exists.Several callers pass the looked-up resource straight to the driver (the copy paths in
console_slots.rsandcl_console_fix.rs,fill.rs,gds.rs,bop64.rs, ...), so a stale entry there means a call on a destroyed resource.Evidence: I hit it with a not-yet-submitted path of ours that writes buffer descriptors for every tracked buffer (it uses the same
gpu_vatables). About 31 s into loading, the title crashed inside the runtime'sCreateShaderResourceViewwhile those descriptors were being written. The faulting instruction loads the resource's vtable (mov rax,[rdx]) and then reads slot 10 (mov rax,[rax+0x50]); the access violation was a read at address 0x50, so the vtable pointer of the passed resource was 0, a destroyed object.Change:
note_resourceattaches a small COM object to each resource withSetPrivateDataInterface(own GUID), once per resource. The runtime releases private data when the resource is destroyed; the object's lastReleasecallsgpu_va::forget(res).insert/insert_cpurecord each range's start per resource.forgetremoves exactly those entries (only where the entry at that start still belongs to the resource, so another resource's range at the same start, e.g. a nested one on another level, stays), plus the resource's texture VA, width and state.SetPrivateDataInterfacefails, nothing is forgotten and the nextnote_resourcefor that resource tries again.Tests:
forget_drops_only_the_ranges_of_that_resource: GPU and CPU ranges of one resource are removed; a neighbour and a larger range sharing a start with a nested one of the forgotten resource stay; a secondforgetis a no-op.a_destroyed_buffer_leaves_the_tables_and_a_second_note_keeps_the_watch: a committed buffer on the default adapter is noted twice, found bylookup, and is gone (range and state) after its lastRelease. Without the watcher this test fails: the destroyed buffer is still returned.cargo test -p d3d12_xs --lib -- --test-threads=1(withTOMBOX_REMOVED_EXIT_MS=off): 663 passed, 5 failed, 71 ignored. The same 4 fail onmainhere (alias::tests::msaa_depth_with_a_larger_pc_layout_never_overlaps_the_next_title_placement,placed_offset::tests::uneven_views_get_exact_helpers_and_msaa_shares_the_alias_heap,title_shadow::tests::buffer_then_texture_migrates_to_one_local_heap_and_keeps_bytes,xs_exports::console_fixed_tests::fixed_result_dxgix_exports_match_every_console_d3d12_xs); the fifth,dbcount::tests::translated_pixel_shaders_with_uavs_keep_their_source, fails now and then in a full single-threaded run (a pointer-keyed map sees an address reused from an earlier test) and passes on its own.Verified in a title (partly): with this change on top of a local test branch, a 150 s run of The Matrix Awakens with the same settings that crashed at ~31 s loaded for the whole run without the crash (0 unhandled exceptions; the run ended at its time limit). The title was still loading at the end of the run, so later gameplay is not covered.
missingwith a note@omonkeyz on GitHub · 2026-11-23 13:45 UTC · original
Applied locally on main with your authorship kept (cherry-picked,
0cc4e3b); tests pass in a sandbox. It ships in the next release; this PR will be closed when that is pushed. Thanks.@omonkeyz on GitHub · 2026-11-25 13:09 UTC · original
Applied on main in
0cc4e3b(cherry-picked onto the current history with your authorship kept; comment lines stripped per CONTRIBUTING). Thank you.Pull request closed