Repository navigation
D3D12.X: flush pending tile mappings before submit and fix VRAM unmap/retire races - #2981
Saksukella wants to merge 270 commits into
Conversation
In a pixel shader EXEC holds helper lanes (s_wqm), and on a primitive's edge the first lane of EXEC is often one. v_readfirstlane read that lane. An RDNA2 driver (RX 6700 XT, 32.0.21045) gives 0 for everything a helper lane holds once a WaveReadLaneAt ran inside a loop, quad reads included. A loop whose state the console's compiler carries in a vector register (v_mov v, s ... v_readfirstlane s, v) then read 0 back on each pass and ran to the loop budget: a retail title's volumetric light pass took seconds per draw at its world start and Windows reset the GPU (xcl-dev#675). v_readfirstlane now reads the first lane of EXEC that is live (ballot(true), per half in the wave32-in-64 form) when EXEC has one, and the first lane of EXEC as before when it has none. The value is the same: the console's compiler reads the first lane of a value equal in every lane, or of a lane it then removes from EXEC (a waterfall loop). The new GPU test draws that title's list-loop shape on two triangles sharing a diagonal. Without the change, on the RX 6700 XT, 69 of 1024 pixels run the loop 65 536 times (the budget) with wrong results; with it, none, and at most 16 passes. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…esent in flight)
A retail game unmaps addresses while it streams its world with
XMemMapPhysicalPagesScatter(addresses, n, NULL); it checks the result
and runs into its own int3 when the call fails (+0xb18de7, then its
crash reporter). XCL refused a NULL page array with
ERROR_INVALID_PARAMETER. Page 0 already means "unmap this address" in a
scatter, so no array is taken as page 0 for every address.
Test scatter_without_pages_unmaps: two pages mapped and written, unmapped
with no array (the call succeeds, the addresses are no longer committed),
mapped again they read what was written. It fails without the change
("refused").
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A retail title keeps its destination page lists in slots of its own table and writes a slot's pages after EnqueueRequest. At enqueue such a slot can still name the pages of the slot's previous request, and the snapshot taken then is what execute() wrote to (xcl-dev#289 rereads only the entries that are 0). Over 16 000 requests a run were written into pages the title had since reused: its objects got garbage pointers and it crashed about 20 s into world loading; when the old pages were freed, the request failed with E_ACCESS_VIOLATION. The console reads the list when it runs the request. execute() now reads it again (through read_own, as the snapshot) and takes it when it differs and every page in it is allocated (kernelx::physical_pages_live). A list that was on the enqueuing thread's stack keeps the snapshot: that memory is reused once the call returns, and a page ID written there since can belong to another live allocation. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…heir pages with their texels A retail title places its streamed textures at full size and has memory behind their levels only as it loads them, the small ones first. vram::place_pages gives a sampled texture a 64 KiB page of video memory for every tile at once: when that title's world is set up about 92 % of those pages have nothing behind them (80 690 pages, 6 809 committed, on one card). With the switch (off by default) a sampled 2D texture of one slice is placed with no tile mapped. Its tiling is kept as groups of tiles, one for each level with tiles of its own and one for the packed levels, and a group gets its pages before the first upload that has texels for it - the same pages by address as before, so textures placed at one address still share them. A texture the GPU writes gets all its pages. Part of xcl-dev#1773. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
… done When the GPU-wait watchdog releases a wait (xcl-dev#505), its lines say which queues wait on which, but not what the GPU is running. With XCL_GPU_CULPRIT=1 every dispatch XCL records (title lists, console-recorded lists, ExecuteIndirect of a translated compute pipeline) is wrapped in WriteBufferImmediate markers, in before and out after, one pair of words per PC list in a readback buffer. At a release the lists whose marker in is above their marker out are logged with the dispatches between the two: console CS (fnv64 of the title's bytecode), PC pipeline and groups. On the retail title of xcl-dev#505 (RTX 5080) this named, at each stall, one list with a run of 1-D dispatches of one CS whose first never finished; not the same CS from run to run. DRED breadcrumbs were tried first: they change the driver's pipeline cache keys, so every pipeline was built again and the title never got past its start. Off by default; without the variable nothing is recorded. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Tested on unmodified PR head
The blocked-queue retirement and sparse fixtures use the D3D12 default adapter, which I checked is the integrated Radeon on this machine. Not tested — The full workspace suite, retail-title smoke, the streaming race on RX 6800M, or a comparison with upstream main. AI use — Codex (GPT-6, exact variant unavailable) selected and ran the tests and wrote this report. |
|
Tested (retail title, RX 6800): not the clean PR tree. This PR's three files (
Not tested: the clean PR head, the test suite on this tree, AI use: Claude Code with Claude Fable 5.2 ran the title, read the logs and wrote this report. |
|
Updated RX 9070 / Wine check on RX 9070 16 GB (RADV GFX1201), Ryzen 7 7700, CachyOS kernel 7.3.6-1-cachyos, Mesa 26.3.1-5, GE-Proton11-12 / Wine 11.0 Staging, ntsync. Native vkd3d-proton Tested The four new tests each passed in a separate fresh process (1 passed / 0 failed), then together at both Under
Also
18 processes total. Copied source trees, original assertions unchanged; only passive test observations and the local native fixture added. The last filter is a local fixture using actual Earlier result retained: my original Not tested: full AI use: OpenAI Codex (GPT-6; exact serving variant not exposed) reviewed both public revisions, added passive adapter/state observations, ran the new tests and native controls, independently checked the results, and updated this report. Publication authorized by the account owner. |
|
Rerun on the new head Same machine.
NVIDIA run (listed under Not tested): no new failure compared with Tested:
The new tests run a copy of each fix rather than the code that ships:
If you want the field order guarded, a test on Not tested: a title on NVIDIA with this branch, a release build, Intel, a long run. AI use: Claude Code (Claude Opus 5.5) ran the tests and the scratch mutations and wrote this report. |
|
Linux (Wine) run of #2981 on the NVIDIA+Wine lane: your fixes do not change this branch's behavior there - the suite still dies at the same place. Boxb (i5-10600K, 16 GB DDR4, GTX 1070 8 GB, 550.163.01, Debian 13, wine-10.0, xvfb),
Solo deadlock test at tip AMD+Wine lane (rig, RX 7900 XT, wine-11.0 Proton) cannot complete any recent amd-dev suite (dies partway), so no rig numbers for this one. AI use: Hermes agent (local Qwen-class) ran the tests and drafted this; I checked it before posting. |
|
Follow-up to the independent NVIDIA mutation check: I verified a small way for the existing retirement test to guard the production type's field order, rather than a separate On #2981 head
Candidate test-only diff (production behavior unchanged)--- a/crates/xcl/src/hle/d3d12x/vram.rs
+++ b/crates/xcl/src/hle/d3d12x/vram.rs
@@
-struct RetiringHeap {
- _zero_buf: Option<ID3D12Resource>,
- _heap: ID3D12Heap,
+struct RetiringHeap<Z = ID3D12Resource, H = ID3D12Heap> {
+ _zero_buf: Option<Z>,
+ _heap: H,
}
@@
- struct FakeRetiringHeap {
- _zero_buf: Option<DropTracker>,
- _heap: DropTracker,
- }
let dropped = Arc::new(AtomicUsize::new(0));
let order = Arc::new(std::sync::Mutex::new(Vec::new()));
- let item = FakeRetiringHeap {
+ let item = RetiringHeap {
_zero_buf: Some(DropTracker(dropped.clone(), "zero_buf", order.clone())),
_heap: DropTracker(dropped.clone(), "heap", order.clone()),
};
- let mut rq: RetireQueue<FakeRetiringHeap, Arc<AtomicU64>> = RetireQueue::new();
+ let mut rq: RetireQueue<RetiringHeap<DropTracker, DropTracker>, Arc<AtomicU64>> = RetireQueue::new();This covers the field-order regression only. It does not establish the native COM lifetime, the late mapping wait, or the unmap snapshot race; those still need their own production-path evidence. No title executable or full workspace suite was run for this candidate. AI use: Codex (GPT-6.2 Sol) reviewed the code, wrote the local diff, and ran the passing and mutation checks. |
…ecycle_ready, and take_heap paths directly
|
Thanks @fromthemoonx and @thehollowedone! Pushed shipped-code tests directly exercising \seal_and_drain_unmaps_with, \�ram::wait_pending_mappings, \�ram::recycle_ready, \sparse::wait_pending_mappings, and \PoolHeaps::take_heap\ + \RetiringHeap\ COM refcount retention (\39/39\ \�ram, \38/38\ \sparse\ passed on RX 9070 XT). |
|
Clean-tree title A/B on an RX 6800 (RDNA2): with Setup: RX 6800 16 GB, driver 32.0.21045.5002, i5-10600KF, 32 GB, Windows 11 Pro 26200, release builds of
Not tested: AI use: Claude Code (Claude Opus 5.5) ran the A/B through a local test runner, read the logs and wrote this comment. Update, on the current
So on this card the two clean 300 s runs above came from runs that were simply shorter than the reset, which happens at 330-350 s here. With 600 s runs the PR did not remove the reset. Please read the earlier table as "no reset within 300 s", not as a fix. |
|
RDNA3 / Windows data for #2981 at the new head: 0 of 3 600 s runs hung with it; on the same setup the amd-dev tree hung in 1 of 3. That is "no hang seen in 3 runs", not a fix claim. RDNA2 counterpart: vibryxcx's run above (7214590553). Setup: RX 7800 XT 16 GB (RDNA3), driver 32.0.31035.1003, Ryzen 7 5700X3D, 64 GB, Windows 11 build 26200, DXC 1.8.2502.11, release builds, the same retail title.
Not tested: more than 3 runs per arm (1 vs 0 hangs is not a difference), DRED, a cold cache, other GPUs. AI use: Claude Code (Claude Sonnet 5.5) built the trees, ran the title, read the logs and wrote this comment. Every number comes from those runs. |
|
Second RX 9070 XT data point, matching @bobosneefdev's RX 6800 run above: with this PR the device removal and Setup: RX 9070 XT 16 GB, Windows 10 22H2 (19045), i7-9700K, 32 GB RAM. Release build of ecbbf96 plus bfb4031 (amd-dev, cherry-picked) plus the #662 XG fix.
So on this machine, with the PR the title queues go idle, and the stuck work is on XCL's own upload, page and sparse queues. One run only, so the order may vary. Next I'm testing Tested with Claude Code (Claude Opus 5.5). The lines are from the run logs. |
Port the mapping and retirement changes from #2981. Seal only the unmaps covered by the queue signals and keep zero-buffer aliases alive through retirement. Assisted-by: Codex (exact model identifier unavailable)
|
Independent test report under Wine/Proton (not native Windows) for head Setup
Tests (debug,
Retail title, 300 s (release;
Not tested
AI use
|
|
Review of
The 4 GPU tests do exercise the sealing, wait and retire paths. Retail runs in the thread still show the GTA 6 AI use: Gemini 4 Hydrogen High (agy2 for #2981, agy3 for #2985 and #2989; Antigravity) read the PR diff, its comments and the touched code and wrote the report; Claude Code (Claude Sonnet 5.5, coordinator) spot-checked the points marked "checked" against |
|
Follow-up on iggyvilla's ZeroSlot lifetime observation, exact production ecbbf96. Physical NVIDIA RTX 4060 Laptop / NVIDIA 590.48.1 / Linux 6.17 / Wine 11, diagnostic-relaxed-vtable vkd3d 2576c0b4adfae4a+ (not stock certification). Local changes are tests only in vram.rs and sparse.rs. A bounded, protective-reference probe confirms the public COM ownership hole after real GPU zero-fill completion:
Reproduction structure:
Suggested owner correction: couple placed-buffer owners to a durable heap owner, or retire completed zero-slot buffer references before the corresponding heap can leave production ownership. Cover every remaining holder, not only Other selected gates: six passed in the first runnable invocation, including real VRAM mapping/wait/recycle readback (all 64 canary words), concurrent-unmap snapshot exclusion, and real-type mocked Release ordering plus real-resource retirement checks. The strengthened sparse readback initially failed before submission because my new upload descriptor inherited ALLOW_UNORDERED_ACCESS from the reserved-buffer helper; clearing that flag in the test only made its separate corrected invocation pass 1/1 (all 64 canary words). That setup error is not a PR failure. Final coverage across those invocations: seven selected gates pass; the added completed-zero-slot lifetime gate fails. No matched parent, pending-cross-queue churn, full suite, retail or measured RAM-saving claim. Evidence:
AI-assisted local verification: OpenAI Codex GPT-6-Astra. |
|
Another RDNA4 run. NVIDIA was asked for, but these tests can't give an NVIDIA result on this machine; details below. Tested: pass, at the PR head
On NVIDIA: the new tests make their device with Not tested: NVIDIA, a soak beyond the tests, Intel. AI use: Claude Code (Claude Opus 5.5) ran the tests on this machine and wrote this report. |
|
The other amd-dev PRs that share most of this diff (#2912, #2913, #2988, #2989, #3023-#3025, #3061, #3079) share it only because they were all opened on the old amd-dev head AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human. |
Fixes four tile-mapping synchronization and VRAM retirement races that caused deterministic
DXGI_ERROR_DEVICE_HUNG(0x887A0006) GPU page faults during world streaming on AMD RDNA 4 (RX 9070 XT).Root causes & fixes (
real.rs,sparse.rs,vram.rs)record_deferredtile-mapping flush & wait (real.rs,sparse.rs,vram.rs):q_execute_command_listsflushedsparseandvramtile mappings viatitle_textures::refreshbeforelist_x::record_deferred, which can block for several milliseconds while compiling pipelines.UpdateTileMappingsor recycled-tile zero-fills queued on another thread during thatrecord_deferredwindow were never flushed or waited on beforeexecute_with_waits_on, letting active dispatches read pages whose tile mappings or GPU zero-fills were still in flight.sparse::wait_pending_mappings(q)andvram::wait_pending_mappings(q)right beforeexecute_with_waits_on(returns immediately with 0 signals / 0 waits when no concurrent thread dirtied mappings duringrecord_deferred).seal_and_drain_unmapsTOCTOU & missingflush_signal(vram.rs):seal_and_drain_unmapspreviously droppedPAGES.lock(), calledsignal_device_queues, re-acquired the lock, and only then calledstd::mem::take(&mut pages.unsealed_unmaps)— attaching concurrent unmaps pushed after the signal to stale fence marks soUpdateTileMappings(NULL)could unmap tiles while a newer title submit was still reading them.unsealed_unmapsbefore releasingPAGES.lock()(seal_snapshot_ops) and flushespages.flush_signal()wheneverpages.dirty_signalis true (coveringPendingUnmapOp::Tiles).recycle_readyunsignaled unmap (vram.rs):pages.flush_signal()immediately afterpages.unmap(res, info.total)before pushing the recycled resource back intoreserved_pool.zero_buflifetime (vram.rs):PoolHeaps::take_heapnow returns(ID3D12Heap, Option<ID3D12Resource>)and retires both insideRetiringHeap { _zero_buf, _heap }inRetireQueue(dropping_zero_bufbefore its backing_heap) instead of dropping the placed alias buffer underPAGES.lock()while still in flight.Tested
amd-dev(bf7c82ee+ebef6042,--test-threads=1, 0 new warnings):cargo test -p xcl --lib hle::d3d12x::vram -- --test-threads=1:36 passed; 0 failed; 1 ignored, including 3 new pure-CPU regression tests:seal_and_drain_unmaps_does_not_attach_stale_marks_to_concurrent_unmapswait_pending_mappings_flushes_post_refresh_dirty_signalretire_queue_keeps_zero_buf_alive_until_marks_completecargo test -p xcl --lib hle::d3d12x::sparse -- --test-threads=1:37 passed; 0 failed; 1 ignored73 passed; 0 failed; 2 ignored.XCL_DIRECT_DXIL=1 XCL_PER_LANE=1 XCL_RT_GATE=miss XCL_DRED=1 XCL_GPU_CULPRIT=1):71b8e6e0base): deterministic0x887A0006DRED page fault (VA 0x1c7103000) att=100.7swithvram pages queuework pending during arecord_deferredwindow.amd-dev(bf7c82ee+ebef6042): survived full 240.04 s (1,464frames,00x887A0006,00x887A0005,0DRED page faults,0crashes,0exceptions).Not tested
Regression run
Baseline (
main,b49be183):This PR (
ebef6042onamd-devbf7c82ee):AI use