Skip to content

D3D12.X: hand the title reserved textures with live page tables - #3553

Open
lucsoft wants to merge 3 commits into
xcl-dev:mainfrom
lucsoft:pr/live-reserved-textures
Open

lucsoft wants to merge 3 commits into
xcl-dev:mainfrom
lucsoft:pr/live-reserved-textures

Conversation

@lucsoft

@lucsoft lucsoft commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

On amdgpu (Linux, RADV) a title can fault the GPU on a reserved texture XCL has just created for one of its placements: the GPU reads it through work submitted before the texture existed, and the kernel has not mapped it yet. This hands the title reserved textures whose page tables already exist, and makes the rare new one wait for its mapping. It is on by default only under Wine on an AMD GPU, where the problem exists; XCL_LIVE_RESERVED=1/0 forces it either way.

What is in it

  • Cause. amdgpu runs a process's page-table updates in order on one entity (vm->delayed). Every unmap, and every sparse rebind (REPLACE puts the old range on vm->freed), first waits for all of the VM's submitted work (amdgpu_vm_clear_freed, AMDGPU_SYNC_EQ_OWNER). A new submit waits for vm->last_update, but work already submitted does not. So while a long frame runs, a reserved texture created after that frame was submitted has no PTEs at all, not even the PRT ones from vkCreateImage. When the title writes its descriptor into memory that the already-submitted work reads (fine on the console), the read faults: [gfxhub] page fault … client TCP, PERMISSION_FAULTS 0x3, then DXGI_ERROR_DEVICE_REMOVED. Shown with RADV_DEBUG=bo_history, the kernel log on the same clock and a devcoredump: the faulting virtual BO was created 32–38 ms before the fault, and the hung IB is in a CS BO created 437 ms before the texture.
  • Stacked on D3D12.X: cover tile mappings whose Signal failed #3566 at 94b0d761. The bottom commits cover failed mapping Signals and Waits on every platform. Only the top commit belongs to D3D12.X: hand the title reserved textures with live page tables #3553.
  • Fix (vram.rs, one commit: the parts only work together. Without the wait a burst of new textures outruns the spares and faults; without the spares every new placement waits a frame):
    • ReservedPool also takes render-target, depth and UAV textures and textures with an optimised clear value. The key copies and compares only the clear value's meaningful bytes: format + four colour floats, or depth float + stencil byte (the union's tail is never read).
    • Each placement tops its description up to XCL_RESERVED_SPARES (default 2) spares made ahead. A spare enters the pool only after a Signal on the mapping queue that was sent after it completes, so its PTEs exist. Missing spares are reserved under the pages lock (pooled, pending and in-flight ones count), so concurrent placements of one description do not over-create them; a drop guard returns the reservation on every early exit. Spares are kept out of the RESERVED registry (and so out of dumps) until handed out, and every pool eviction removes the entry before the release.
    • A texture that still has to be created new (the first of a description, or a burst that outruns the spares) sends its own Signal and waits for it, up to XCL_PLACE_MAP_WAIT_MS (default 1000; 0 = off), by polling the fence with short sleeps: no event is registered, so none can be left with vkd3d-proton after a timeout. If that Signal cannot be queued, the placement fails as a failed creation does (nothing is mapped or noted yet), instead of handing out a texture nothing covers.
    • Spares and new placements count on D3D12.X: cover tile mappings whose Signal failed #3566's marks: a spare whose Signal fails is released, not pooled; a new texture whose readiness Signal cannot be queued (also after a retry) is not placed.
  • Gate: decided once per device. Default on only under Wine with an AMD GPU (vendor 0x1002), judged by the Vulkan physical device vkd3d-proton drives (through its ID3D12DXVKInteropDevice; DXVK's DXGI may report an NVIDIA GPU as AMD), else by the DXGI adapter. Windows drivers do not run page-table updates behind in-flight work, and the spares and the wait cost time on the title's thread. Elsewhere the previous behaviour is unchanged. XCL_LIVE_RESERVED=1/0 forces it; XCL_RESERVED_POOL=0 still turns the pool off.
  • Log lines: placements from the pool / new / spares made, the time spent making the spares on the placing threads (total and the longest call), and the new placements' waits (count, timeouts, total, longest).
  • Cost of the spares (review): about one CreateReservedResource per placement still runs on the placing thread. Measured in the retail run below: 66126 spares made in 2071 ms over 130 s (31 µs each on average, longest call 10 ms), about 1.6 % of one thread; the waits of new placements are on top (5.3 s over 125 s, longest 102 ms).
  • Related: D3D12.X: fail lazy texture placement when mappings are unfinished #3124 also waits for a new lazy texture's mapping before handing it out (an explicit NULL mapping for an NVIDIA device removal, 5 s deadline); it touches the same spot in place_on_pages but solves a different problem.
  • Tests: the gate and the vendor source (Wine+AMD, NVIDIA behind an AMD-reporting DXGI, Windows, no adapter, forced), the depth clear key with garbage in the union tail, the fence wait (returns at the Signal; after a timeout the old fence does not signal a new event), injected Signal failures through bind, unmap, before_execute and recycling (the value stays reachable, no spares pooled, the work is held until a later Signal), a lazy placement without a readiness Signal, a depth clear value placed right before a no-access page, concurrent same-description placements (at most 2 spares), spares kept out of dumps, and a GPU test through place_on_pages (with the mapping queue held a new texture waits and gets two spares, the next comes from the pool without a wait; gate off: no spares, no wait).

Tested

  • AMD Radeon RX 7800 XT, Mesa RADV, Ryzen 7 7800X3D, Wine. Windows GNU release builds of the runtime and workspace test binaries completed.
  • Four-thread hle::d3d12x::vram::tests:: run on this head under Wine: ok. 83 passed; 0 failed; 1 ignored; 0 measured; 2702 filtered out; finished in 3.11s
  • Windows 11 / RTX 5070 Ti at 18547df7: 2,918 passed, 0 failed, 51 ignored in the four-thread workspace suite. Test report

Regression run

main:

xcl-smoke v1
commit: 86e86fcb33f94fa5d0c809d9b50af7b84bf49cce
gpu: AMD Radeon RX 7800 XT (RADV NAVI32)
title: retail-gta6
seconds: 180
exit: 0x0
frames shown: 2569 (PresentX 2569)
presents per 2 s (last 3): 1 0 0
device removals: 0
crashes: 0
peak commit: 0 MB

PR:

xcl-smoke v1
commit: 5800b721b3c7ae0e1fe80afa5bb4b86777c8a959
gpu: AMD Radeon RX 7800 XT (RADV NAVI32)
title: retail-gta6
seconds: 180
exit: 0x0
frames shown: 2410 (PresentX 2410)
presents per 2 s (last 3): 1 1 0
device removals: 0
crashes: 0
peak commit: 0 MB

The PR's kernel log recorded 0 page faults, 0 ring timeouts, 0 ring resets, 0 coredumps, 0 bus losses.

Not tested

  • Native Windows GPU suite on this head.
  • A driver-generated mapping Signal or Wait failure. The regression test injects failures.
  • Wine reports peak commit as 0 MB in this comparison.
  • Windows with XCL_LIVE_RESERVED=1, NVIDIA under Wine, and other AMD generations.

AI use

🤖 Generated with Claude Code

@github-actions github-actions Bot added area:d3d12 D3D12.X runtime, command lists, resources, sparse memory area:memory Virtual/physical memory, arenas, VRAM budget, UMA gpu:amd Code is specific to AMD / RDNA / wave64 GPUs (scope tag; see needs:amd-test) labels Nov 30, 2026
@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

merge-check
base: d0832e6
head: 83ed4c7
merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2892 passed, 0 failed, 51 ignored (the lib binary aborted with STATUS_ACCESS_VIOLATION after 2752/2775 tests in the first run, no failures before it; the 23 unreported tests pass alone, and a full rerun of cargo test -p xcl --lib -- --test-threads=4 gave 2744 passed / 0 failed / 31 ignored, counted here together with the other binaries' 148/0/20; matches the open intermittent issue #1487); SKIPPED: 28 (22 no wave64, 2 no heap windows (opt-in), 3 no D3D12 debug layer / d3d12SDKLayers.dll, 1 driver cache needs Developer Mode); failing: none
review: (1) "PR description" check fails: the Tested / Not tested / AI use sections are missing (no model named), and there are no xcl-smoke blocks for main or for head 83ed4c7; CI build was still pending. (2) On by default on every platform, but measured only on Linux/Wine/RADV: make_spares (vram.rs:845-879, called at 2597) creates up to 2 reserved textures with CreateReservedResource on the title's thread whenever a description has fewer than 2 pooled or pending ones, which brings back the per-placement cost the pool was added to remove (#1268: 0.6-1.7 ms AMD, ~0.1 ms NVIDIA), and each new placement waits for a GPU round trip (wait_new_placement, 801-841). (3) ReservedKey::from_desc_clear (903-909) compares all 20 bytes of D3D12_CLEAR_VALUE; depth clear values leave 11 bytes uninitialized, so equal depth clears can make different keys (pool misses, spares that are never used, extra waits). (4) The wait spins with yield_now for up to 1000 ms (817-823) instead of waiting on an event. (5) Spares are registered in RESERVED by dev_create_reserved_resource and freed with the original Release when evicted (1073, 2504-2507), leaving stale RESERVED entries. (6) The new GPU test only checks promote_pending (already covered by an existing test); make_spares, wait_new_placement and the place_on_pages changes have no test. (7) Render target, depth and UAV textures are now recycled by default; not tested on any Windows driver. The amdgpu fault itself cannot be reproduced on Windows; no retail title was run here (no smoke run).
performance: can cost frame time by default: extra synchronous CreateReservedResource calls and a queue Signal for spares, plus a CPU spin wait of up to 1 s per new placement on the title's thread; not measured on Windows (no retail title on this machine); the PR's own numbers are from Linux/Wine/RADV only
verdict: not yet: PR description check fails (no Tested / Not tested / AI use, no xcl-smoke blocks for main and head 83ed4c7); clear-value key compares uninitialized bytes for depth clears; default-on spares and CPU wait are unmeasured on Windows (cost per placement, spin wait)
hardware / tool and model: NVIDIA GeForce RTX 5070 Ti (driver 32.0.16.2114 / 621.14), AMD Ryzen 7 7800X3D, Windows 11 Pro 10.0.26300, rustc 1.100.0 MSVC / Claude Code, Claude Opus 5.5

@github-actions github-actions Bot added the needs-pr-check Failing the PR description check (CONTRIBUTING.md) label Dec 1, 2026
lucsoft added a commit to lucsoft/xcl that referenced this pull request Dec 1, 2026
Review follow-ups to xcl-dev#3553:

- The pool widening, spares and the new-placement wait work around
  amdgpu's in-order page-table updates, which Windows drivers do not
  have, and cost CreateReservedResource calls and waits on the title's
  thread. They are now on by default only under Wine on an AMD adapter
  (vendor 0x1002), decided per device; XCL_LIVE_RESERVED=1/0 forces
  them on or off anywhere.
- A clear value keys the pool by its meaningful bytes only: the format
  and the colour, or the depth and stencil of a depth-stencil texture,
  never the uninitialised rest of the union.
- The new-placement wait sleeps on an event (SetEventOnCompletion and
  WaitForSingleObject) instead of spinning.
- Spares are not kept as reserved resources of the title while they
  sit in the pool, and pool entries evicted without a title Release
  leave that registry too.

Tests: the gate, the depth clear key with garbage in the tail,
wait_fence returning at the Signal and timing out, and place_on_pages
with the gate on (a new texture waits behind a held mapping queue and
gets two spares; the next one comes from the pool without waiting) and
off (no spares, no wait).
@lucsoft

lucsoft commented Dec 1, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the review. Addressed in 797541b:

  1. Description rewritten to the template: Tested with counts (one thread, under Wine on RADV; the main baseline run the same way), and xcl-smoke blocks for main 86e86fc and head 797541b.
      1. The pool widening (render targets, depth, UAV), the spares and the new-placement wait are now on by default only under Wine with an AMD adapter, where amdgpu runs page-table updates behind in-flight work. On Windows and NVIDIA the previous behaviour is unchanged, so no extra CreateReservedResource calls or waits on the title's thread there. XCL_LIVE_RESERVED=1/0 forces it.
  2. The key now compares only the meaningful bytes of the clear value: format + four colour floats, or depth float + stencil byte for depth-stencil textures. Test with garbage in the union tail.
  3. The wait sleeps on an event (SetEventOnCompletion + WaitForSingleObject with the timeout) instead of spinning.
  4. Spares stay out of RESERVED until they are handed out, and every pool eviction goes through one helper that removes the entry before the release.
  5. New tests: the gate, the depth key, the fence wait, and a GPU test through place_on_pages (new texture waits and gets spares, the next comes from the pool without a wait; gate off: neither).

@github-actions github-actions Bot removed the needs-pr-check Failing the PR description check (CONTRIBUTING.md) label Dec 1, 2026
@thehollowedone

Copy link
Copy Markdown
Contributor

Source review of current head 797541b7, following the earlier merge-check. The updated gate, clear-key comparison, and tests address several of its points. I still see these paths to resolve:

  1. wait_fence closes the event after a timeout even when the fence has not completed. vkd3d-proton registers the supplied handle for later signalling and wraps the caller's handle. If it completes after the timeout, a reused handle could signal an unrelated event. Keep a registered handle alive until completion, or use bounded polling without registration. A delayed-completion test should time out, create another event, then confirm that event is not signalled by the old fence.

  2. signal_now increments pages.value and ignores a failed native_queue_signal. make_spares can then publish pending spares against that value, while before_execute submits a GPU wait for it. If no later successful signal reaches the value, that wait cannot complete. Propagate the signal error, publish a mark only after success, and release the new spares or fail the placement path on error. The existing bind/unmap callers also discard signal errors; please account for those paths in the fix. An injected signal failure should not leave the next submission waiting on an unreachable value.

  3. from_desc_clear now compares only the meaningful depth/stencil bytes, but first read_unaligned reads the entire 20-byte clear-value union. A depth/stencil clear may leave its colour-sized tail uninitialised. Copy only the selected prefix into the already-zeroed key; the current test fills the unused tail with garbage, so it does not exercise this case.

Candidate clear-key correction
diff --git a/crates/xcl/src/hle/d3d12x/vram.rs b/crates/xcl/src/hle/d3d12x/vram.rs
@@
-            let raw = std::ptr::read_unaligned(clear as *const [u8; CLEAR_VALUE_BYTES]);
             let used = if desc.Flags.contains(D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL) { 4 + 4 + 1 } else { CLEAR_VALUE_BYTES };
-            key.clear[..used].copy_from_slice(&raw[..used]);
+            std::ptr::copy_nonoverlapping(clear.cast::<u8>(), key.clear.as_mut_ptr(), used);
  1. Spare demand is counted under PAGES, but spares are created after releasing it. Concurrent same-key placements can each observe the same shortage and create excess reserved resources. Track in-flight spare reservations under the lock and return them on creation failure. A barrier-controlled concurrent placement test would bound the number created.

This is source review, not a new GPU or title test of this head. AI use: OpenAI Codex (GPT-6.2 Sol) traced the current source and vkd3d-proton path; OpenAI Codex (GPT-6.2 Astra) independently checked the lifecycle and concurrency paths.

lucsoft added a commit to lucsoft/xcl that referenced this pull request Dec 1, 2026
Second review of xcl-dev#3553:

- wait_fence polls the fence with short sleeps instead of registering
  an event: vkd3d-proton keeps a registered handle until the value is
  reached, so an event closed after a timeout could be signalled later
  under a reused handle.
- signal_now moves the mapping queue's value only once its Signal was
  queued, and says when it failed. Queues wait for that value before
  their work, so a value no Signal reaches would hold them forever. The
  bind and unmap paths go through it; a mapping whose Signal failed is
  covered by the next one that succeeds. A new placement whose Signal
  failed does not wait, and spares without their Signal are released.
- A depth-stencil clear value is read only as far as its depth and
  stencil, never the rest of the union.
- place_on_pages reserves the spares a description lacks under the
  pages lock (in-flight ones count), and the reservation is given back
  when they are made, fail, or the placement ends early, so placements
  of one description at once make no more than XCL_RESERVED_SPARES.

Tests: a timed-out wait leaves no event to signal; a clear value right
before an unreadable page; an injected Signal failure publishes no
value and no spares and gives the reservation back; four placements of
one description at once behind a held mapping queue make at most the
spares of one.
@lucsoft

lucsoft commented Dec 1, 2026

Copy link
Copy Markdown
Contributor Author

Thanks, all four addressed in 85c1c59:

  1. wait_fence no longer registers an event: it polls the fence with sleeps of at most 0.5 ms up to the timeout, so nothing is left with vkd3d-proton after a timeout. Test: time out, create a new event, signal the old value; the new event stays unsignalled.
  2. signal_now advances the mapping queue's value only after the Signal was queued and returns the failure; bind/unmap go through it, so a failed Signal never leaves the value before_execute waits on unreachable. A new placement whose Signal fails does not wait, and spares made without their Signal are released and their reservation returned. Test with an injected Signal failure.
  3. from_desc_clear copies only the meaningful prefix with copy_nonoverlapping (9 bytes for depth-stencil, 20 for colour). Test: a depth clear value placed right before a PAGE_NOACCESS page.
  4. Missing spares are reserved under PAGES (counting pooled, pending and in-flight ones), created after the lock, and the reservation is returned on failure through a drop guard. Test: 4 barrier-synchronised placements of one description with the mapping queue held make at most 2 spares, and no reservation is left.

Description updated: suite and xcl-smoke block for head 85c1c59 (2499 frames, no device removal, no page fault in the kernel log).

@thehollowedone

Copy link
Copy Markdown
Contributor

Follow-up on head 85c1c599 to my earlier review: the event lifetime, clear-value read, and concurrent spare reservation changes address those points. The failed-Signal path still needs to cover mapping and unmapping already queued.

Pages::map and unmap_range queue UpdateTileMappings, then discard signal_now() returning None. After a failed Signal, bind_range still returns success, while before_execute waits only on the previous successful value. A consuming queue can therefore proceed without a fence mark covering the new mapping. On retirement, recycle_ready publishes that old value for a NULL unmap; if it is already complete, drain_recycled can return the reserved texture to the pool before the unmap finishes. The new failure test invokes signal_now directly and checks spares; it does not exercise either caller.

Please track mapping work whose Signal failed and obtain a successful later mark before allowing dependent execution or recycling. If no mark can be queued, keep the mapping/resource unavailable rather than treating the previous completed value as its mark. A regression can complete mark N, inject a failed Signal after a bind or NULL unmap, hold the mapping queue behind a test fence, and verify that execution/recycling waits for a successfully queued N+1 and its completion.

This is a source trace; I did not inject a failure or run a GPU test on this revision. AI use: Codex (GPT-6.2 Sol) checked the revised call paths; Codex (GPT-6.2 Astra) independently reviewed the mapping and retirement sequence.

@lucsoft

lucsoft commented Dec 1, 2026

Copy link
Copy Markdown
Contributor Author

Thanks, the follow-up is right: a failed Signal after Pages::map / unmap_range still leaves the mapping without a mark. I'm fixing that next: mapping work whose Signal failed will need a later successful mark before dependent execution or recycling, with a test through the real callers (complete N, fail the Signal after a bind and after a NULL unmap, hold the mapping queue, check that execution and recycling wait for N+1).

On the other points raised elsewhere:

  • The new-placement wait (up to 1000 ms). It only applies under Wine on AMD, and only to textures that have to be created new (3–4 % of placements; the rest come from the pool or the spares). Measured: longest single wait 186 ms in a 600 s run and 607 ms in a 180 s run, no timeouts. A shorter cap means more timeouts, and a timeout means the page fault and device removal this PR fixes, so I'm keeping 1000 ms as the cap.
  • The doc comment naming a title is changed to neutral wording; it goes out with the fix above.
  • make_spares is complete in the branch; a review tool that showed it cut off was limited by the diff size.

@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

merge-check
base: d0832e6
head: 85c1c59
merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2899 passed, 0 failed, 51 ignored; SKIPPED: 28 (22 no wave64, 2 no heap windows, 2 no d3d12SDKLayers.dll, 1 no D3D12 debug layer, 1 cannot disable the driver cache); failing: none. The new vram tests (live_reserved_is_on_by_default_only_under_wine_on_amd, concurrent_placements_make_at_most_the_spares_of_one, a_failed_signal_publishes_no_value_and_no_spares, live_placements_wait_when_new_and_take_spares_without_waiting, wait_fence_returns_at_the_signal_or_times_out, the depth-clear key tests) ran and passed.
review: whole diff read. All points of the earlier merge-check and of the second review are addressed: on by default only under Wine with an AMD adapter (XCL_LIVE_RESERVED=1/0 forces it), the clear key compares only the meaningful bytes, the wait polls instead of spinning or registering an event, failed Signals publish no value, spares leave RESERVED when evicted, and the new paths have tests. On Windows + NVIDIA the default path adds no CreateReservedResource, Signal or wait. Remaining: (1) 797541b and 85c1c59 are review fixups that rewrite the first two commits (the wait went spin -> event -> polling); CONTRIBUTING wants them squashed. (2) about 821 changed lines (351 runtime, 462 test) with no reason in the description why it cannot be split. (3) not verified: DXVK's dxgi (Proton) can report an NVIDIA GPU as AMD, which would turn live mode on there (time, not a crash). (4) nits: signal_now's doc comment sits on reserve_spares; no linked issue.
performance: smoke 240 s on the merged tree 3fa20d5a vs main d0832e6 (same title, same input script): every run, main included, loses the device to a GPU page fault (DRED state 7) during the world load: main at 100.4 s / 100.4 s with 2195 / 2219 presents, this PR at 93.4 s with 1987 (90 %); peak commit 31916 MB vs 34766 / 32760 MB. Within run-to-run noise (an earlier run of 83ed4c7 had 2222); the live mode is off here, so the AMD/Wine path is not exercised on this machine.
verdict: not yet: squash the review fixups 797541b / 85c1c59 into the first commits (and say why ~820 lines cannot be split); the code has no blocking finding
hardware / tool and model: NVIDIA GeForce RTX 5070 Ti (driver 32.0.16.2114 / 621.14), AMD Ryzen 7 7800X3D, Windows 11 Pro 10.0.26300, rustc 1.100.0 MSVC / Claude Code, Claude Opus 5.5

@thehollowedone

Copy link
Copy Markdown
Contributor

One ordering detail for the failed-Signal fix you described on head 85c1c599: before_execute calls release_held_unmaps before it reads pages.value for the consumer wait. That helper can queue a new NULL unmap through self.unmap, whose Signal can fail. A recovery check only at before_execute entry would miss that unmarked work.

If recovery happens in before_execute, check again after release_held_unmaps and before using pages.value for the wait or reclaim decision. The real-caller regression should include a held unmap that becomes releasable during before_execute, with its NULL-mapping Signal forced to fail. This is a source-ordering check; I did not run the new revision. AI use: Codex (GPT-6.2 Sol) verified the call order; Codex (GPT-6.2 Astra) independently traced this path.

@thehollowedone

Copy link
Copy Markdown
Contributor

One separate lifetime point on head 85c1c599, for XCL_DUMP_TARGETS:

make_spares creates each idle spare through the title-facing dev_create_reserved_resource wrapper. For a 3D texture, that wrapper calls lut3d::created, which stores its raw pointer in VOLS. forget_reserved removes only the separate reserved-resource record. If the spare is later evicted, the original COM Release bypasses the normal hook that calls lut3d::forget. to_dump can then call GetDesc through that freed pointer, even for a volume it would otherwise exclude from readback.

Create an internal spare through the existing PC creator and register diagnostics only when a resource is handed to the title. The GPU-owned and sampled placement paths already do the latter after successful placement. Clearing VOLS only at eviction would still leave idle spares in dumps and miss the original Release after a failed QueryInterface on checkout.

Candidate diff against this head
diff --git a/crates/xcl/src/hle/d3d12x/vram.rs b/crates/xcl/src/hle/d3d12x/vram.rs
@@
-        let hr = super::real::dev_create_reserved_resource(this, tiled as *const _ as usize, state as usize, clear as usize, riid, &mut p);
+        let hr = super::real::pc_create_reserved_resource(this, tiled as *const _ as usize, state as usize, clear as usize, riid, &mut p);
@@
-        // (idle in the pool, as a title's released one: `note_reserved` again when handed out)
-        super::real::forget_reserved(p as usize);

Please add a deterministic regression with dump tracking enabled: make a 3D spare, check that the idle spare is absent from diagnostic enumeration, force pool eviction, then check that enumeration cannot touch the released resource. A checked-out 3D texture should still be registered. I traced this in source; I did not run that regression or a GPU test on this head. AI use: Codex (GPT-6.2 Sol) checked the release and diagnostic paths; Codex (GPT-6.2 Astra) independently traced the spare lifecycle.

@thehollowedone

Copy link
Copy Markdown
Contributor

One additional cold-placement case for the failed-Signal fix on head 85c1c599: with XCL_TEXTURE_LEVEL_PAGES=1 (off by default), a newly created, eligible sampled texture takes the lazy level path without queueing a tile map. Its initial page-table readiness then depends on wait_new_placement's Signal. If that Signal fails, the helper returns None, but the placement caller ignores it and returns success. A title could then use the descriptor before the newly created texture has live page-table entries. Repairing failed bind or unmap Signals in before_execute alone would miss this case: neither operation has queued a mapping, and previously submitted work cannot be made to wait there.

Please distinguish a disabled placement wait from a failed Signal. On failure, queue a successful readiness mark and wait for it before returning the resource, or roll back the placement and propagate failure. A focused regression can disable spares, hold the mapping queue behind a test fence, inject the first Signal failure during a cold lazy placement, and verify the caller does not receive a usable resource before a successful retry completes. This is a source trace; I did not run that failure injection or a GPU test on this head.

AI use: Codex (GPT-6.2 Sol) checked the call path; Codex (GPT-6.2 Astra) independently checked the page-table invariant.

@Aniseto

Aniseto commented Dec 1, 2026

Copy link
Copy Markdown

Ran the vram::tests module at 85c1c599 on an NVIDIA Blackwell desktop part with 16 GB of VRAM. The wider vram filter and a main control are also reported below.

Environment: Windows 11 Pro build 26200 x64, NVIDIA GeForce RTX 5070 Ti (Blackwell, 32-lane waves only, 16 GB, mesh shaders) driver 32.0.16.2140 (621.40), Intel Core i5-12400F, 64 GB RAM, rustc 1.100.0 (0ef1bc386 2026-11-09), MSVC 14.44.35207, DXC 1.9.2609.5, debug build, XCL_ADAPTER=NVIDIA, detached worktree at the exact PR head, no local patches.

XCL_ADAPTER=NVIDIA cargo test -q -p xcl --lib vram::tests -- --test-threads=1
78 passed; 0 failed; 1 ignored; 2702 filtered out      (exit 0)

XCL_ADAPTER=NVIDIA cargo test -q -p xcl --lib vram -- --test-threads=1
73 passed; 8 failed; 1 ignored; 2699 filtered out      (exit 101)

three new tests, each alone at 85c1c599: a_failed_signal_publishes_no_value_and_no_spares,
concurrent_placements_make_at_most_the_spares_of_one, live_placements_wait_when_new_and_take_spares_without_waiting
1 passed; 0 failed; 0 ignored each      (exit 0)

same wider `vram` filter on main 493dbd3d (own CARGO_TARGET_DIR): the test binary
exited 0x80004005 after "sparse upload preparation still failed after bounded retries";
no final test result line was produced on that run.

The 78/0/1 of vram::tests matches the description's lib-suite count for that module. On this Windows NVIDIA host the new behaviour is gated off (it defaults on only under Wine with an AMD adapter), so this is a no-registration check of the module, not a test of the gate's active path. The wider vram filter also selects placed_title_textures_share_vram_and_preserve_pixels, which already fails here on main (row 5: stale shadowed texture corrupted B); the seven other failures in that run are PoisonError cascades, and the three new tests pass when run alone. The control on main did not finish cleanly, so no A/B verdict is drawn from it.

Not tested: Wine with AMD/RADV (where the change is on by default), the XCL_LIVE_RESERVED=1 forced path on NVIDIA, an injected Signal failure with the gate active, the full workspace suite, a title run, native wave64 hosts, Intel GPUs, release profile, game data.

AI-assisted (OpenCode), model: MiMo-V2.6-Flash Free - checked out the PR's head commit in a detached worktree, built it, ran the tests, wrote this report; the worktree was not modified; no game data was used.

@lucsoft
lucsoft force-pushed the pr/live-reserved-textures branch from 85c1c59 to 5d7820c Compare December 1, 2026 08:08
@lucsoft

lucsoft commented Dec 1, 2026

Copy link
Copy Markdown
Contributor Author

Squashed into one commit, 5d7820c, which also covers the open points:

@Foniass's merge-check:

  1. The review fixups are squashed: one commit on main 86e86fc.
  2. Why one commit: the description now says it under Fix. Without the wait a burst of new textures outruns the spares and faults; without the spares every new placement waits a frame; without the marks a failed Signal lets the wait and the pool count on a mapping nothing covers. The diff is about 455 runtime lines (with comments) and 840 test lines.
  3. DXVK's DXGI reporting an NVIDIA GPU as AMD: the gate now takes the vendor of the Vulkan physical device vkd3d-proton drives (through ID3D12DXVKInteropDevice) and falls back to the DXGI adapter only when that is not available. Test: Vulkan NVIDIA behind a DXGI AMD stays off, and the reverse is on.
  4. The signal_now doc comment now sits on signal_now. There is no linked issue.

@thehollowedone:

  • Queued mapping work whose Signal failed (7297966755) and the ordering in before_execute (7298335865): a mapping whose Signal fails is marked unmarked. before_execute first runs release_held_unmaps, then gets a later mark (Pages::mark) and has the title's queue wait for that. If no Signal can be queued, the work does not go. A retired texture whose NULL unmap has no mark stays out of the pool until a later one completes. Test mappings_whose_signal_failed_get_a_later_mark_before_use holds the mapping queue behind a test fence and covers a bind, a held unmap that becomes releasable inside before_execute with its NULL mapping's Signal failing, the case with no Signal at all, and recycling.
  • Spares and dump tracking (7299475980): spares are made through pc_create_reserved_resource, so they are not in VOLS or RESERVED while idle; they are registered when handed out. Test spares_stay_out_of_dump_tracking_until_handed_out (an idle 3D spare is neither a reserved resource nor a dumped 3D texture, one released from the pool leaves nothing the dump enumerates, and a handed-out one is tracked).
  • The cold lazy placement (7300154479): wait_new_placement now tells a disabled wait from a failed Signal. On failure a retry is queued and waited for; if that fails too, the placement fails the way a failed creation does: nothing is mapped or noted yet, the texture is released and the title gets no resource. Test a_lazy_placement_without_a_readiness_signal_is_not_handed_out.

Description updated: suite (one module per process, 2 threads, failing modules rerun with 1) and the xcl-smoke block for 5d7820c (2358 frames, no device removal, no page fault in the kernel log).

@Aniseto

Aniseto commented Dec 1, 2026

Copy link
Copy Markdown

This is a new response on the same thread as my report at 85c1c599 (#3553 (comment)); the head moved to 5d7820cf (the four commits squashed into one), so I am not editing that comment.

Ran the vram::tests module at 5d7820cf on an NVIDIA Blackwell desktop part with 16 GB of VRAM.

Environment: Windows 11 Pro build 26200 x64, NVIDIA GeForce RTX 5070 Ti (Blackwell, 32-lane waves only, 16 GB, mesh shaders) driver 32.0.16.2140 (621.40), Intel Core i5-12400F, 64 GB RAM, rustc 1.100.0 (0ef1bc386 2026-11-09), MSVC 14.44.35207, DXC 1.9.2609.5, debug build, XCL_ADAPTER=NVIDIA, detached worktree at the exact PR head, no local patches.

XCL_ADAPTER=NVIDIA cargo test -q -p xcl --lib vram::tests -- --test-threads=1
82 passed; 0 failed; 1 ignored; 2702 filtered out      (exit 0)

All 82 tests pass at the squashed head, four more than the 78 of my earlier report at 85c1c599. On this Windows NVIDIA host the new behaviour is still gated off by default (it turns on under Wine with an AMD adapter), so this is a no-registration check of the module, not a test of the active path. I did not repeat the wider vram filter here; its earlier 8 failures came from the pre-existing placed_title_textures_share_vram_and_preserve_pixels failure and poisoned-lock cascades.

Not tested: Wine with AMD/RADV (where the change is on by default), the XCL_LIVE_RESERVED=1 forced path on NVIDIA, the full workspace suite, a title run, native wave64 hosts, Intel GPUs, release profile, game data.

AI-assisted (OpenCode), model: MiMo-V2.6-Flash Free - checked out the PR's head commit in a detached worktree, built it, ran the tests, wrote this report; the worktree was not modified; no game data was used.

@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

merge-check
base: 7d86c5d
head: 5d7820c
merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2909 passed, 0 failed, 51 ignored; SKIPPED: 28 (20 no wave64, 2 no d3d12SDKLayers.dll, 1 no D3D12 debug layer, 1 no heap windows, 1 cannot disable the driver cache, 3 others; the same set as on main); failing: none
review: re-review (my earlier merge-checks were on 83ed4c7 and 85c1c59); read the whole current diff (vram.rs +1298/-16, ~455 runtime lines and ~840 test lines, title_textures.rs, real.rs, lut3d.rs). The earlier points, mine and thehollowedone's, are addressed in the code. On Windows the live path is off (live_decide short-circuits before any vendor query); the only change there is how a failed Signal is handled. Under Wine on AMD it's on by default. Findings: (1) when vram::before_execute returns false (the mapping's Signal and a retry both failed, with no device removal), refresh_parts returns RetryRequired (title_textures.rs ~2066) and prepare_title_submission ends the title with "sparse upload preparation still failed after bounded retries" (real.rs ~12091-12098): the work is stopped, on every platform, with a message naming the wrong cause, where the description says it's held. Rare, but worth a clearer path. (2) In live mode the PR's own counters show 66,172 spares made for 65,536 placements, so about one CreateReservedResource per placement still runs synchronously on the title's thread (make_spares, ~2827), the cost the pool (#1268) existed to avoid; only frames were measured (92 % of main's). (3) 1,334 lines; the Signal-failure handling applies everywhere and could be its own preparation PR. (4) The PR's CI crash (0xc0000005 in eh::tests, before any vram test) looks like the intermittent #1487; see the run above. The PR's smoke blocks under Wine read 0 MB peak commit, so the 125 % check can't catch anything there. Still no linked issue. Fine: the gate takes the vendor from the Vulkan device behind ID3D12DXVKInteropDevice, the depth clear key reads only 9 bytes, the wait polls without registering an event, spares stay out of RESERVED / VOLS until handed out and are forgotten before Release, the spare reservation is returned through a drop guard on every early exit, and the GPU tests use skip_test.
performance: 60 s smoke of a retail title, main 7d86c5d vs this merge (bc3334cd): 1663 -> 1690 frames shown (101 %; last presents per 2 s: 60 60 61), peak commit 17153 -> 17335 MB, 0 device removals, 0 crashes. This Windows run takes the Signal-failure change only; the live path is Wine-only.
verdict: not yet: 1,334 changed lines (about 455 of them runtime), with no stated reason it can't be split; the Signal-failure handling, which applies on every platform, could be its own preparation PR. Also, a failed mapping Signal now ends the title with a message that names the wrong cause (finding 1). My earlier blocking points are fixed
hardware / tool and model: RTX 5070 Ti (driver 621.14), Ryzen 7 7800X3D, Windows 11 26300 / Claude Code with Claude Opus 5.5

AI-written and posted by Foniass without a human check of each point.

@lucsoft

lucsoft commented Dec 1, 2026

Copy link
Copy Markdown
Contributor Author

Thanks. All four points of 7306339703 are addressed; the new head is db57f30:

  1. The wrong stop message. When the mapping's Signal and its retry both fail without a device removal, refresh_parts now returns a separate PreparationOutcome::MappingUnmarked. The title stops with "a texture page mapping has no Signal of the mapping queue (its own and a retry failed)", and the wait-inside-a-submit path names the same cause. The description now says the title stops instead of "held". It stays fail-closed, like the other preparation failures: the D3D12 submit is void, so there is nothing to retry later.
  2. The spares on the title's thread. The log line now measures it. In the retail run on this head, 66126 spares were made in 2071 ms over 130 s (31 µs each on average, longest call 10 ms), about 1.6 % of one thread. The waits of new placements are on top (5.3 s over 125 s, longest 102 ms). Numbers and frames (90 % of main's in that run) are in the description.
  3. The split. The Signal-failure handling, which applies on every platform, is its own PR now: D3D12.X: cover tile mappings whose Signal failed #3566 (6970034, on main 86e86fc, about 290 lines with its tests). This PR is stacked on it: the first commit is D3D12.X: cover tile mappings whose Signal failed #3566, and its own commit db57f30 is the Wine-on-AMD part (about 1100 lines: about 380 runtime with comments in vram.rs, about 690 tests, the rest test hooks in real.rs and lut3d.rs).
  4. Intermittent access violations during parallel library tests on Windows 11 #1487. Agreed, the Windows crash is the intermittent one (the same 0xc0000005 hit an unrelated PR 15 minutes earlier). Still no linked issue.

Suite and xcl-smoke blocks are in both descriptions for their exact heads.

@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Re-review (head db57f30; range-diff from 5d7820c, which I merge-checked, read). Not a new merge-check: this head is stacked on #3566, which is still a draft.

  • Both blockers from my merge-check are answered. The Signal-failure handling, the part that applies on every platform, is now D3D12.X: cover tile mappings whose Signal failed #3566, the first commit here, which I reviewed separately. With it, a failed mapping Signal no longer ends the title with the misleading "bounded retries" message. The commit message now says why the rest is one change: the wait, the spares and the marks only work together.

  • Size. This PR's own commit is still +1097 / -7, about 1,077 of it in vram.rs and mostly tests. With the reason now stated, that is for the maintainer to accept.

  • New since 5d7820c:

    • a spare whose Signal fails is released, not pooled;
    • a new texture whose readiness Signal can't be queued fails as a failed creation does;
    • spares are kept out of dump tracking (lut3d.rs);
    • the log now reports the time spent making spares on the placing threads, which answers my finding about synchronous CreateReservedResource calls with a number per run.

    The new tests cover the failing-Signal spare and a cold lazy placement.

Once #3566 is out of draft and merged, a suite run and smoke pair of this commit on main would make it ready. On Windows the live path stays off, so the default path there is unchanged.

AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.

@Aniseto

Aniseto commented Dec 1, 2026

Copy link
Copy Markdown

This is a new response on the same thread as my report at 5d7820cf (#3553 (comment)); the head moved to db57f30c (now stacked on #3566), so I am not editing that comment.

Ran the vram::tests module at db57f30c on an NVIDIA Blackwell desktop part with 16 GB of VRAM.

Environment: Windows 11 Pro build 26200 x64, NVIDIA GeForce RTX 5070 Ti (Blackwell, 32-lane waves only, 16 GB, mesh shaders) driver 32.0.16.2140 (621.40), Intel Core i5-12400F, 64 GB RAM, rustc 1.100.0 (0ef1bc386 2026-11-09), MSVC 14.44.35207, DXC 1.9.2609.5, debug build, XCL_ADAPTER=NVIDIA, detached worktree at the exact PR head, no local patches.

XCL_ADAPTER=NVIDIA cargo test -q -p xcl --lib vram::tests -- --test-threads=1
83 passed; 0 failed; 1 ignored; 2702 filtered out      (exit 0)

All 83 tests pass at the stacked head, one more than the 82 of my previous report. The new behaviour remains gated off by default on Windows NVIDIA, so this is a no-registration check of the module, not a test of the Wine/AMD path.

Not tested: Wine with AMD/RADV (where the change is on by default), the XCL_LIVE_RESERVED=1 forced path on NVIDIA, the full workspace suite, a title run, native wave64 hosts, Intel GPUs, release profile, game data.

AI-assisted (OpenCode), model: MiMo-V2.6-Flash Free - checked out the PR's head commit in a detached worktree, built it, ran the tests, wrote this report; the worktree was not modified; no game data was used.

@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Triage (#1607) – head db57f30

Stacked on #3566: its first commit (6970034) is #3566, and that is where the 153 shared added lines come from. Not a duplicate. This PR's own commit, db57f30, adds the live reserved-texture pool, spares made ahead, and the wait for new placements in vram.rs. It is gated to Wine on AMD (live_decide) or XCL_LIVE_RESERVED.
#3124 touches the same spot in place_on_pages but solves a different problem (a NULL mapping for an NVIDIA removal).
No problems found in the diff.
Recommendation: keep open.

AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.

@lucsoft
lucsoft force-pushed the pr/live-reserved-textures branch from db57f30 to ee13d5a Compare December 1, 2026 10:49
@lucsoft

lucsoft commented Dec 1, 2026

Copy link
Copy Markdown
Contributor Author

The Windows CI job on db57f30 ran into its 45-minute timeout: with 4 test threads, several vram::tests never finished. Cause: there is one D3D12 device per adapter, so every test shares its mapping queue, and this PR's tests hold that queue behind a test fence; a test placing textures meanwhile without VRAM_TEST_LOCK waited behind it (a deadlock on WARP; on RADV it showed as a wait counter off by one). ee13d5a changes only tests: every fence that holds the mapping queue gets a watchdog that opens it after 10 s at the latest (so a race can fail a test but never hang the job), and reserved_resource_with_private_data_is_excluded_from_recycle takes the lock. vram:: with 4 threads: 5 of 5 clean here (0 of 3 before). #3566 is unchanged (6970034; its CI is green). New xcl-smoke block in the description (2700 frames, no page fault).

@Aniseto

Aniseto commented Dec 1, 2026

Copy link
Copy Markdown

This is a new response on the same thread as my report at db57f30c (#3553 (comment)); the head moved to ee13d5ad, so I am not editing that comment.

Ran the vram::tests module at ee13d5ad on an NVIDIA Blackwell desktop part with 16 GB of VRAM.

Environment: Windows 11 Pro build 26200 x64, NVIDIA GeForce RTX 5070 Ti (Blackwell, 32-lane waves only, 16 GB, mesh shaders) driver 32.0.16.2140 (621.40), Intel Core i5-12400F, 64 GB RAM, rustc 1.100.0 (0ef1bc386 2026-11-09), MSVC 14.44.35207, DXC 1.9.2609.5, debug build, XCL_ADAPTER=NVIDIA, detached worktree at the exact PR head, no local patches.

XCL_ADAPTER=NVIDIA cargo test -q -p xcl --lib vram::tests -- --test-threads=1
83 passed; 0 failed; 1 ignored; 2702 filtered out      (exit 0)

All 83 tests pass at this head, the same count as at db57f30c. The new behaviour remains gated off by default on Windows NVIDIA, so this is a no-registration check of the module, not a test of the Wine/AMD path.

Not tested: Wine with AMD/RADV (where the change is on by default), the XCL_LIVE_RESERVED=1 forced path on NVIDIA, the full workspace suite, a title run, native wave64 hosts, Intel GPUs, release profile, game data.

AI-assisted (OpenCode), model: MiMo-V2.6-Flash Free - checked out the PR's head commit in a detached worktree, built it, ran the tests, wrote this report; the worktree was not modified; no game data was used.

@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

merge-check
base: b2b1f10
head: ee13d5a
merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2916 passed, 0 failed, 51 ignored; SKIPPED: 28 (20 no wave64, 2 no d3d12SDKLayers.dll, 1 no D3D12 debug layer, 1 no heap windows, 1 cannot disable the driver cache, 3 others; the same set as on main); failing: none
review: re-check of this head (ee13d5a, stacked on #3566); my earlier merge-check (5d7820c) and re-reviews (db57f30, then test-only hardening) have the details. The PR's own commit hands the title reserved textures with live page tables, on by default only under Wine with an AMD GPU (judged by the Vulkan device behind vkd3d-proton), so on Windows the default path is unchanged; XCL_LIVE_RESERVED=1/0 forces it. My earlier blockers are answered: the Signal-failure handling is now #3566 underneath, with a correct stop reason, and the commit message says why the rest is one change (the wait, the spares and the marks only work together). Since then: a spare whose Signal fails is released, not pooled; a new texture whose readiness Signal can't be queued fails as a failed creation does; spares are kept out of dump tracking; and the log reports the time spent making spares on the placing threads. Still large (+1,097 of its own, mostly vram.rs tests), with the reason stated. Fine: spares stay out of RESERVED / VOLS until handed out and are forgotten before Release, the spare reservation is returned through a drop guard on every early exit, and the GPU tests use skip_test. The smoke run below covers Windows' default path, where the live path is off.
performance: 60 s smoke of a retail title, main b2b1f10 vs this merge (c8d15eee): 1671 -> 1624 frames shown (97 %; last presents per 2 s: 61 60 60), peak commit 17394 -> 19144 MB, 0 device removals, 0 crashes. On Windows the live path is off, so this measures #3566's Signal-failure handling and the unchanged default path. Peak commit is 11.5 % above main in this one run, within the 125 % limit; my earlier smoke of this PR (5d7820c) was 17335 MB and other runs today varied by 1-2 GB between runs of the same merge, so I read it as run-to-run variation.
verdict: safe to merge once #3566 below it carries the test watchdog (this head's copy of mappings_whose_signal_failed_get_a_later_mark_before_use has open_at_the_latest and passed here; #3566's own head hangs on it, see my comment there)
hardware / tool and model: RTX 5070 Ti (driver 621.14), Ryzen 7 7800X3D, Windows 11 26300 / Claude Code with Claude Opus 5.5

AI-written and posted by Foniass without a human check of each point.

@github-actions github-actions Bot added needs-2nd-check Has 1 safe merge-check; needs second independent check (#3041) needs:amd-test Needs a test report or merge-check on an AMD GPU labels Dec 1, 2026
@capy-ai

capy-ai Bot commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Review of head ee13d5a (not a full merge-check: no test suite or title run on this machine)

  • Merged onto main b2b1f10: clean, git diff --check clean. Also clean together with D3D12.X: compile the indirect guard with DXC, and guard split chains #3536.
  • cargo check --workspace --all-targets --target x86_64-pc-windows-gnu: ok for this merge and for D3D12.X: cover tile mappings whose Signal failed #3566 alone, with the same warning count as main.
  • I read both commits, and the runtime change looks right to me:
    • live is decided once per device and stays off on Windows (live_decide returns before any vendor query).
    • The spare reservation is given back on every early exit.
    • Spares get their mark from a Signal sent after they were created, and are released when that Signal fails.
    • wait_new_placement polls without registering an event and does not hold PAGES while it waits.

Blocking: the first commit, 6970034 (#3566 as it stands), lands with a test that can hang the suite. mappings_whose_signal_failed_get_a_later_mark_before_use installs its own Pages for the shared device and holds its mapping queue behind gate fences. reserved_resource_with_private_data_is_excluded_from_recycle places textures on that device without VRAM_TEST_LOCK. When the two overlap, or any assert fails between mq.Wait and the gate's Signal, the queue never reopens and the test process cannot exit. That is the mechanism described in #3553 (comment), and the hang Foniass hit on #3566 in #3566 (comment). The fix (open_at_the_latest on the three gates, plus the lock) exists only in ee13d5a. Merged as it is, the hanging version goes into history and #3566 closes along with it.

What would unblock it: move open_at_the_latest and the VRAM_TEST_LOCK line into #3566's commit, rebase this PR onto it, then merge #3566 and this PR in that order. With that change, this is ready from my side: Foniass's run of the merged tree passed the full Windows/NVIDIA suite with 0 failures.

Not blocking:

  • The size: about 1,100 lines of its own, mostly tests, and the reason is given.
  • The cost on Wine/AMD only: about 1.6 % of a thread making spares, plus waits of up to about 190 ms per new texture (both from the description).

Hardware: Linux x86_64 cloud machine, no GPU. The crate was type-checked only, not built for or run on Windows.
AI use: Capy (Claude Opus 5.5) did the merge, the type-check and the diff review, and wrote this comment.

vram's mapping queue raised its value and then signalled it, ignoring
the result. When that Signal failed, the value was one no Signal would
reach: every queue's next submit waited for it (before_execute) and a
retired texture's NULL unmap counted as done although nothing marked
it.

The value now moves only when the Signal was queued. A mapping or
unmapping whose Signal failed is marked, and gets a later Signal before
anything counts on it: before_execute queues one and has the title's
queue wait for it, and a retired texture stays out of the pool until
one completes. When none can be queued either, before_execute says so,
and the submission stops with that cause (MappingUnmarked) instead of
going out with mappings nothing covers.

Tests: a failed Signal leaves the value a Signal reached; with the
mapping queue held behind a test fence, a bind, a held unmap released
inside before_execute and a retired texture's unmap whose Signals fail
each get a later mark, and the work waits for it or does not go.


The held-queue test cannot hang the test process: each gate is a guard
that Drop opens on unwind, and a detached watchdog opens it after 10 s
and fails the test with the phase it was held in. With FAIL_SIGNALS
nothing else signals the gates, so an assert between mq.Wait and a
gate's Signal, or a test placing on the shared device meanwhile, would
otherwise leave the mapping queue waiting for good.
reserved_resource_with_private_data_is_excluded_from_recycle takes
VRAM_TEST_LOCK, and a test-only lock keeps drain_recycled from marking
the test's retired texture while it checks that nothing marked it.
@lucsoft
lucsoft force-pushed the pr/live-reserved-textures branch from ee13d5a to 18547df Compare December 1, 2026 20:06
@github-actions github-actions Bot removed needs-2nd-check Has 1 safe merge-check; needs second independent check (#3041) needs:amd-test Needs a test report or merge-check on an AMD GPU labels Dec 1, 2026
@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Test report (not a merge-check: PR description red: its smoke block is for an older head)
base: 6bfb5c5
head: 18547df
merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2918 passed, 0 failed, 51 ignored; SKIPPED: 28 (20 no wave64, 2 no d3d12SDKLayers.dll, 1 no D3D12 debug layer, 1 no heap windows, 1 cannot disable the driver cache, 3 others; the same set as on main); failing: none
review: follow-up on 18547df (rebased from ee13d5a, the head of my merge-check above; stacked on #3566 at f5a5743). The PR's own commit was only rebased, apart from two hunks dropped because #3566 now carries them: the VRAM_TEST_LOCK guard in reserved_resource_with_private_data_is_excluded_from_recycle, and its three open_at_the_latest(&gate*) calls in #3566's failed-Signal test, which now uses #3566's Gate. The commit message is the same (1,117 insertions against 1,121 before). Nit: the PR's own tests still use open_at_the_latest (vram.rs ~6240, ~6312, ~6419), so the module now has two watchdogs for held mapping queues; its doc comment (~6805) still says it exists for "a shared device's mapping queue" though the remaining callers hold private Pages::new queues, and when it fires it doesn't fail the test, unlike #3566's Gate. It can't hang the process, so it doesn't block. Fine: the rebased commit sits on f5a5743 without duplicated code and merges cleanly into current main; the Gate / AtomicU8 / mpsc imports don't clash; the lock order is the same in both (VRAM_TEST_LOCK, then RECYCLE_DRAIN_TEST_LOCK, then PAGES), and the PR adds no drain_recycled call outside tests. The Windows default path is unchanged: live_decide is still on by default only when under_wine() is true and the Vulkan vendor is 0x1002, with XCL_LIVE_RESERVED forcing it either way.
performance: 60 s smoke of a retail title, main 6bfb5c5 vs this merge (8125b27e): 1646 -> 1663 frames shown (101 %; last presents per 2 s: 60 60 61), peak commit 18685 -> 18384 MB, 0 device removals, 0 crashes. The first run of this merge lost the lib test binary to the known uma_driver coherent-window abort; this is the rerun. On Windows the live path is off by default, so the smoke run covers the default path only.
assessment: merges, builds and passes the whole suite on current main at 18547df (with #3566's f5a5743 underneath, whose test no longer hangs), and the smoke run is clean; the PR's own commit was only rebased. What remains for a merge-check is the description's smoke block on this head, and #3566 below it landing first
hardware / tool and model: RTX 5070 Ti (driver 621.14), Ryzen 7 7800X3D, Windows 11 26300 / Claude Code with Claude Opus 5.5

AI-written and posted by Foniass without a human check of each point.

Publish a consumer wait only once it was queued. Propagate mapping readiness failures out of texture upload preparation, including mappings made after the title queue’s initial wait.

Assisted-by: Codex (GPT-6.2 Sol)
amdgpu, the Linux kernel driver, runs a process's page-table updates in
order on one queue, and every unmap and every sparse rebind (REPLACE
frees the old range) waits for all command submissions of the VM
first. While a frame is in flight, a reserved texture made after its
submit has no page-table entries, not even the PRT ones, until that
frame is done. A console title may write a descriptor of a texture it
has just placed that work it already submitted reads; on the console
the memory is there, here the read is a GPU page fault (TCP,
PERMISSION_FAULTS 0x3) and the device is lost. RADV_DEBUG=bo_history
and the kernel log put the faulting virtual BO 32-38 ms after its
creation, by a new placement, with the hung IB older than the texture.

A texture from the pool has had its entries since before: its rebind
still lands late, but the work in flight reads a NULL tile meanwhile.
So:

- the pool also takes render targets, depth and UAV textures and those
  with a clear value, keyed by its meaningful bytes;
- every placement tops its description up to XCL_RESERVED_SPARES
  (default 2) spares made ahead, reserved under the pages lock and
  pooled only once a Signal of the mapping queue after them completes;
- a placement that still has to make a new texture waits up to
  XCL_PLACE_MAP_WAIT_MS (default 1000) for such a Signal, polling the
  fence; when no Signal can be queued for it, the placement fails as a
  failed creation does.

It is one change because the parts only work together: without the
wait a burst of new textures outruns the spares and faults; without
the spares every new placement waits a frame. It builds on the marks
for mappings whose Signal failed (the commit before): spares and new
placements count on a Signal reaching their mappings.

On by default only under Wine with an AMD GPU, judged by the Vulkan
physical device vkd3d-proton drives (DXVK's DXGI may report an NVIDIA
GPU as AMD), else by the DXGI adapter: Windows drivers do not order
page-table updates like this, and the extra creations and waits cost
time on the title's thread (the log says how much: the placements,
the spares made and the time spent making them, and the waits).
XCL_LIVE_RESERVED=1/0 forces it either way.

Tests: the gate and the vendor source, clear keys, the fence wait,
placements with the gate on and off, concurrent placements and their
spares, spares and a cold lazy placement whose Signal fails, and spares
kept out of dump tracking.
@lucsoft
lucsoft force-pushed the pr/live-reserved-textures branch from 18547df to 5800b72 Compare December 1, 2026 22:07
@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

merge-check
base: f07e426
head: 5800b72
merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2918 passed, 0 failed, 51 ignored; SKIPPED: 28 (20 no wave64, 2 no d3d12SDKLayers.dll, 1 no D3D12 debug layer, 1 no heap windows, 1 cannot disable the driver cache, 3 others; the same set as on main); failing: none
review: re-check of 5800b72, stacked on #3566 at 94b0d76. Since my test report on 18547df the PR's own commit is unchanged (git range-diff: =); only #3566's new commit 94b0d76 came in underneath (reviewed on #3566). Against ee13d5a, the own commit was only rebased, apart from two hunks dropped because #3566 now carries them: the VRAM_TEST_LOCK guard in reserved_resource_with_private_data_is_excluded_from_recycle, and its three open_at_the_latest(&gate*) calls in #3566's failed-Signal test, which now uses #3566's Gate. The commit message is the same (1,117 insertions against 1,121 before). Nit: the PR's own tests still use open_at_the_latest (vram.rs ~6240, ~6312, ~6419), so the module now has two watchdogs for held mapping queues; its doc comment (~6805) still says it exists for "a shared device's mapping queue" though the remaining callers hold private Pages::new queues, and when it fires it doesn't fail the test, unlike #3566's Gate. It can't hang the process, so it doesn't block. Fine: the rebased commit sits on f5a5743 without duplicated code and merges cleanly into current main; the Gate / AtomicU8 / mpsc imports don't clash; the lock order is the same in both (VRAM_TEST_LOCK, then RECYCLE_DRAIN_TEST_LOCK, then PAGES), and the PR adds no drain_recycled call outside tests. The Windows default path is unchanged: live_decide is still on by default only when under_wine() is true and the Vulkan vendor is 0x1002, with XCL_LIVE_RESERVED forcing it either way.
performance: 60 s smoke of a retail title, main f07e426 vs this merge (5fd0b6ce): 1672 -> 1658 frames shown (99 %; last presents per 2 s: 60 60 60), peak commit 17352 -> 18865 MB, 0 device removals, 0 crashes. On Windows the live path is off by default, so the smoke run covers the default path only.
verdict: safe to merge once #3566 below it is merged: the PR's own commit is unchanged since my last review, the merge passes the whole suite and the smoke run is clean; on Windows the live path is off by default, so the run covers the default path, and the remaining nit (two test watchdogs) doesn't block
hardware / tool and model: RTX 5070 Ti (driver 621.14), Ryzen 7 7800X3D, Windows 11 26300 / Claude Code with Claude Opus 5.5

AI-written and posted by Foniass without a human check of each point.

@github-actions github-actions Bot added needs-2nd-check Has 1 safe merge-check; needs second independent check (#3041) needs:amd-test Needs a test report or merge-check on an AMD GPU labels Dec 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:d3d12 D3D12.X runtime, command lists, resources, sparse memory area:memory Virtual/physical memory, arenas, VRAM budget, UMA gpu:amd Code is specific to AMD / RDNA / wave64 GPUs (scope tag; see needs:amd-test) needs:amd-test Needs a test report or merge-check on an AMD GPU needs-2nd-check Has 1 safe merge-check; needs second independent check (#3041)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants