Skip to content

D3D12.X: cover tile mappings whose Signal failed - #3566

Open
lucsoft wants to merge 2 commits into
xcl-dev:mainfrom
lucsoft:pr/mapping-signal-failures
Open

lucsoft wants to merge 2 commits into
xcl-dev:mainfrom
lucsoft:pr/mapping-signal-failures

Conversation

@lucsoft

@lucsoft lucsoft commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

vram's tile-mapping queue raised its value and then signalled it, ignoring the result. When that Signal failed, the value was one no Signal would ever 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. This makes the value move only when the Signal was queued, and gives every mapping whose Signal failed a later one before anything counts on it. It is split out of #3553 (asked for in its review): it applies on every platform, while #3553 is Wine-on-AMD only.

Related: #3553 builds on this (its spares and new placements count on a Signal reaching their mappings). #3010 (draft) changes the same Signal lines to signal once before the next title work; with signal_now that single Signal would get this failure handling too.

What is in it (vram.rs, plus the callers of before_execute)

  • Pages::signal_now advances value only after the Signal was queued and reports a failure; map and unmap_range go through it. A mapping or unmapping whose Signal failed leaves the pages unmarked.
  • Pages::mark gives the value that covers every mapping queued so far: value, or a new Signal when one is unmarked. before_execute calls it after release_held_unmaps (which can queue a NULL unmap of its own) and has the title's queue wait for that value.
  • recycle_ready queues a retired texture with that mark, or UNMARKED when no Signal can be queued; drain_recycled gives such textures a later mark before they can return to the pool.
  • A title queue's cached mapping mark advances only after its Wait succeeds. An upload that cannot establish mapping readiness blocks the title's submission, including lazy level updates made after the initial mapping check.
  • When no Signal can be queued at all, before_execute returns false: the submission is not made and the title stops with that cause (PreparationOutcome::MappingUnmarked: "could not queue a Signal or Wait for texture page mappings"), following the existing fail-closed rule in prepare_title_submission, instead of going out with mappings nothing covers. The GPU content probe returns an error.
  • Tests: a failed Signal leaves the value a Signal reached (and the fence reaches it). With the mapping queue held behind a test fence: a bind whose Signal fails gets mark N+1 at the next before_execute, and the title's work waits for it; with no Signal at all before_execute returns false; a held unmap that becomes releasable inside before_execute with its NULL mapping's Signal failing gets a later mark, and the work waits for it; a retired texture whose unmap's Signal and the retry fail stays out of the pool until a later mark completes. Signal failures are injected through a test-only counter (FAIL_SIGNALS). The same test injects a failed consumer Wait and verifies that the next attempt still waits for the replacement mark.

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. 71 passed; 0 failed; 1 ignored; 0 measured; 2702 filtered out; finished in 2.58s
  • Windows 11 / RTX 5070 Ti at f5a57437: 2,906 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: 60
exit: 0x0
frames shown: 1489 (PresentX 1489)
presents per 2 s (last 3): 59 60 60
device removals: 0
crashes: 0
peak commit: 0 MB

PR:

xcl-smoke v1
commit: 94b0d76108c326118783374a8a1fc7e5568a4129
gpu: AMD Radeon RX 7800 XT (RADV NAVI32)
title: retail-gta6
seconds: 60
exit: 0x0
frames shown: 1508 (PresentX 1508)
presents per 2 s (last 3): 59 59 61
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.

The 180 s standalone RADV run of this head lost the device at about 158 s after three kernel page faults and a gfx ring timeout. The preceding head showed the same failure pattern in two runs. The follow-up above covers startup. The full #3553 stack completed 180 s on the same host without a page fault.

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.

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 Dec 1, 2026
@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Review (head 6970034, diff read, not a merge-check; draft, PR description red: the smoke block is TODO-SMOKE):

Fine:

  • The covered value moves only after a Signal is actually queued (signal_now, vram.rs ~1961), so no queue waits for a value nothing will signal. That was the hang on main.
  • The retry Signal goes on the same in-order mapping queue, and the title queue waits for it (~2841).
  • mark() runs after release_held_unmaps, so a queued NULL unmap is covered too.
  • Heap reclaim waits while a mapping is uncovered (~2849), and recycled textures stay out of the pool until a later Signal covers them.
  • When no Signal is possible at all, the title stops with a correct message.
  • The normal path is unchanged apart from a flag write and a scan that returns at once.

#3010 rewrites the same Signal lines, so the two will conflict.

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

@lucsoft
lucsoft marked this pull request as ready for review December 1, 2026 09:48
@lucsoft

lucsoft commented Dec 1, 2026

Copy link
Copy Markdown
Contributor Author

Thanks. Since your review: the smoke block is in (6970034, 2289 frames, clean) and it is out of draft. #3553 is now stacked on this PR (db57f30 on 6970034) without its own copy, so it gets MappingUnmarked and the right stop message. The list_x arm is there only to make the match complete; mapped_after_wait still never calls vram::before_execute. I left it rather than push a new head for a line that cannot run.

@mokkamokacaffe

Copy link
Copy Markdown
Contributor

Native Windows / NVIDIA verification for #3566

Tested PR head 69700342ee0b67429a4dbdb771cffa5d708bfde6 and used its exact upstream parent 86e86fcb33f94fa5d0c809d9b50af7b84bf49cce for the smoke comparison. The PR head still matched after testing.

Windows 11 24H2 build 26100.9711, Intel Core i9-14900KF, NVIDIA GeForce RTX 4080 SUPER, driver 621.40, Rust 1.100.0 (x86_64-pc-windows-msvc). Workspace tests used the debug profile. Both smokes used release builds.

Tested

  • Both new tests selected exactly one test apiece and ran without a skip. A failed mapping-queue Signal preserved the last reachable fence value. Queued work waited for a successful retry, submission was refused while no mark could be obtained, and a retired texture only returned to the pool after its replacement mark completed.
  • The PR workspace built. The four-thread workspace suite reported 2,891 passed, 0 failed, 51 ignored across 43 harnesses. The focused reruns are separate. The passing totals include 24 explicit skip messages: 22 for lack of wave64 and two for disabled heap windows. Private sample environment variables were unset.
  • All eight uma_driver tests, the placed-texture pixel preservation test, all three stream_recheck_* tests, and the root-signature serialization test flagged in the Wine report passed on this machine.
  • All 73 benchmark cases passed in test mode. No benchmark timings were collected.

Commands from the PR worktree:

cargo build --workspace
cargo test -p xcl --lib hle::d3d12x::vram::tests::a_failed_signal_leaves_the_value_a_signal_reached -- --exact --nocapture
cargo test -p xcl --lib hle::d3d12x::vram::tests::mappings_whose_signal_failed_get_a_later_mark_before_use -- --exact --nocapture
cargo test --workspace --no-fail-fast -- --test-threads=4 --nocapture
cargo bench -p xcl --bench '*' -- --test

Regression run

Each clean worktree used its own cargo build --release -p xcl binary and scripts/smoke.ps1. The parent ran first. Both runs used the same local title for 180 seconds with networking and preparation disabled, the same DXC and Agility SDK, and separate empty XCL data and shader cache directories. The PR showed 102.1% of the parent's frames and 99.7% of its peak commit, meeting the repository's 80% frame minimum and 125% memory ceiling.

Main (exact parent)

xcl-smoke v1
commit: 86e86fcb33f94fa5d0c809d9b50af7b84bf49cce
gpu: NVIDIA GeForce RTX 4080 SUPER
title: retail-local
seconds: 180
exit: 0x0
frames shown: 5146 (PresentX 5146)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 16543 MB

PR head

xcl-smoke v1
commit: 69700342ee0b67429a4dbdb771cffa5d708bfde6
gpu: NVIDIA GeForce RTX 4080 SUPER
title: retail-local
seconds: 180
exit: 0x0
frames shown: 5252 (PresentX 5252)
presents per 2 s (last 3): 60 60 59
device removals: 0
crashes: 0
peak commit: 16499 MB

Not tested

A spontaneous mapping-queue Signal failure on the NVIDIA driver remains unverified. The focused tests injected failures. The smoke pair checks ordinary execution; it does not establish a performance improvement.

AI use

OpenAI Codex ran the local builds, tests, and smokes, checked the logs, and prepared this report.

@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Triage (#1607) – head 6970034

#3553 contains this PR's commit (6970034) and is stacked on it; this is the split-out base requested in #3553's review, not a duplicate. #3010 changes the same Signal lines to signal once per title submission, which is a different change.
No problems found in the diff. vram.rs:Pages::signal_now advances value only after a Signal is queued; mark and mark_pending_recycles cover unmarked mappings before before_execute or the reserved pool depend on them; and every non-test caller of vram::before_execute now handles the false return (title_textures.rs refresh_parts, submit_on, probe_gpu_content).
Recommendation: keep open.

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

@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

merge-check
base: b2b1f10
head: 6970034
merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> did not finish: the lib test binary hung in this PR's own test hle::d3d12x::vram::tests::mappings_whose_signal_failed_get_a_later_mark_before_use, from about 2 min in, and three other vram tests (reservable_agrees_with_the_driver, superseded_texture_waits_for_every_title_queue, tracked_srv_global_cleanup_hooks_are_gated_and_exact, which pass on main) never finished either, most likely stuck behind it on the shared test lock. After 17 minutes I stopped the process; it couldn't exit, which is what a GPU queue stuck on a fence nothing signals looks like. No counts.
review: read the whole diff earlier on this head (my review comment has the details); the code findings there stand and none was blocking. What blocks is the test above. With FAIL_SIGNALS the native Signal is skipped, so a queue made to wait for that value waits for good unless the test opens it; on this machine (Windows, NVIDIA) nothing did. #3553's later commit added open_at_the_latest, a 10 s watchdog that opens such a test fence ("a test that holds a shared device's mapping queue can fail but never hang the test process"), to its copy of these tests; this head doesn't have it. With it, a test that goes wrong fails instead of taking the suite and the GPU process down.
performance: not measured (the run stopped at the hung test).
verdict: not yet: mappings_whose_signal_failed_get_a_later_mark_before_use hangs the lib test binary on Windows / NVIDIA, leaving a process that can't exit; bring #3553's open_at_the_latest watchdog (and VRAM_TEST_LOCK use) into this PR's tests, then rerun the suite on Windows
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.

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.

@bmjask bmjask left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review of 69700342: 2 finding(s). 1 are inline. These are on lines outside the diff:

crates/xcl/src/hle/d3d12x/vram.rs:2866: This is older code, but the same class of bug the PR fixes on the Signal side: reserve_page_wait sets waited[queue] = value before native_queue_wait, and that result is thrown away with let _. If the Wait fails (e.g. E_OUTOFMEMORY), every later before_execute on that queue sees waited >= value and skips the wait, so title work can run before mappings up to N are done.


These findings come from an AI-assisted review (Claude Code) and focus on correctness. Each is a candidate; please check it before acting on it.

// `map_levels_with_texels`): a copy into a tile still unmapped is a copy-engine page fault
// on NVIDIA (`DmaPageFaultWrite`).
super::vram::before_execute(queue);
if !super::vram::before_execute(queue) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If before_execute fails inside submit_on here, the Err branch (~2919) treats it as an ordinary upload failure and queues a 100 ms retry. refresh_parts still returns Ready, so the title's ExecuteCommandLists go out against level tiles that map_levels_with_texels_in just mapped, with no Signal covering them and no queue Wait on them. That's the case the PR says should end the title with MappingUnmarked.

@lucsoft
lucsoft force-pushed the pr/mapping-signal-failures branch from 6970034 to f5a5743 Compare December 1, 2026 20:06
@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: f5a5743
merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2906 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 f5a5743 (rebased and amended from 6970034, the head of my merge-check above). Only test-side changes: a new Gate test guard in vram.rs (~5726-5794), reserved_resource_with_private_data_is_excluded_from_recycle now takes VRAM_TEST_LOCK (~5577), and a #[cfg(test)] RECYCLE_DRAIN_TEST_LOCK (~900) is taken in drain_recycled (~915) and around the test's park / recycle_ready / "no mark yet" step (~5925); the list_x.rs, real.rs, sparse.rs and title_textures.rs hunks and the runtime parts of vram.rs are the same as in 6970034. The hang blocker is fixed: all three gates are Gate locals, so unwinding drops them before _vram_guard is released; Drop signals the gate whenever open() hasn't finished, open() takes cancel only after its Signal succeeded, a failed queue Wait in Gate::new panics with the gate already built, and a panic inside with releases PAGES before the gates drop. Each watchdog holds only its own gate's fence and leaves when the sender drops, so it can't open the next test's gate; another test's work waiting behind a gate is limited by the 10 s watchdog, and the test then fails instead of hanging (the run below confirms it: the suite finished, and both of the PR's tests passed). RECYCLE_DRAIN_TEST_LOCK can't deadlock: drain_recycled takes it before PAGES, the test takes it before PARKING / PAGES, its two callers in late_release.rs (~306, ~363) hold no lock, and nothing reverses VRAM_TEST_LOCK -> drain lock. Earlier points: (1) still only FAIL_SIGNALS failures are tested; (2) still open: sparse::before_execute has no path returning MappingUnmarked, so the arm at list_x.rs ~3622 can't run; (3) resolved, #3553 is now on top of f5a5743. New, none blocking: (4) vram.rs ~5933: the test now calls mark_pending_recycles() itself while holding the lock, so the next drain_recycled() finds the recycle already marked and the retry inside drain_recycled (~918) is no longer tested; dropping the lock after the "no mark yet" assert and leaving the retry to drain_recycled would test it. (5) ~5687: the private-data test's SetEventOnCompletion(mark, NULL) blocks for good if item.mark is UNMARKED (u64::MAX, introduced here), which only happens after a real Signal failure. (6) ~5967: a panic in the gated test leaves its Pages in PAGES (only the last line removes it), so later tests can fail one after another, though they no longer hang. (7) The commit message has a doubled blank line before the new paragraph. Fine: the gate's ARMED / OPENED / RESCUED state machine and its ordering, the gate fence created on the original (unhooked) CreateFence slot, and git diff --check is clean.
performance: 60 s smoke of a retail title, main 6bfb5c5 vs this merge (01196f9a): 1646 -> 1672 frames shown (101 %; last presents per 2 s: 60 60 61), peak commit 18685 -> 18636 MB, 0 device removals, 0 crashes.
assessment: merges, builds and passes the whole suite on current main, and the test that hung on 6970034 now finishes and passes (mappings_whose_signal_failed_get_a_later_mark_before_use ... ok), so the blocker from my merge-check is gone; the smoke run is clean. What remains for a merge-check is the description's smoke block on this head (f5a5743); the new points (4)-(7) are not blocking
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)
@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

merge-check
base: f07e426
head: 94b0d76
merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2906 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 94b0d76 (+84/-35 since f5a5743, the head of my test report above). The commit closes two gaps f5a5743 left. A failed consumer Wait was still ignored (already so on main: let _ = native_queue_wait), and reserve_page_wait recorded the queue as having waited before the Wait was queued, so after a failed Wait every later submit skipped it and could read tiles that weren't mapped; now vram::before_execute (vram.rs ~2866) queues the Wait under the consumer queue's queue_submit lease, records waited only after it succeeds, and returns false when it fails. And submit_on's before_execute failure, only a warning with a retry before, now becomes UploadError::MappingUnmarked (title_textures.rs ~2677 / ~2932), passed up through upload_all and refresh_parts so prepare_title_submission stops the title; under XCL_TEXTURE_LEVEL_PAGES=1 there's one more before_execute after lazy levels are mapped (~2943). On the hang class: the only Wait value is still pages.mark() on pages.fence, which f5a5743 limits to values whose Signal was queued, so nothing waits for a value nobody signals. Lock order: per-queue serial -> lease(Q) was already there through native_queue_wait, and the new step only adds lease(Q) -> PAGES; PAGES is held across a queue call only in signal_now on the mapping queue, never a before_execute queue, so no deadlock with the tile-mapping queue was found. Default-path cost: two extra PAGES lock acquisitions on submits that need a mapping Wait, no new CPU or GPU wait. Findings: (a) the title_textures propagation has no test: the changed vram test (~5881, FAIL_MAPPING_WAIT) fails without the vram half, but nothing drives submit_on -> upload_all -> refresh_parts to MappingUnmarked, or the lazy-level recheck. (b) The test's "the next submission retries the Wait" step can't happen at run time, since a false from before_execute stops the title; it only checks the waited cache, so it shouldn't be presented as a retry. (c) On the own-upload-queue branch (title compute / copy queue, ~2900), a failed Signal or Wait puts the textures on RETRY and then stops the title anyway, so that RETRY push is dead there. (d) The already_waited recheck inside the lease (~2870) and its comment about a racing submit describe a race that can't happen, since before_execute holds the queue's serial lock throughout (harmless). (e) Scope: the Wait half fixes a bug main already had, not a failed Signal; it's small and the same class, so acceptable as its own commit, but the subject doesn't say a failed Wait now stops the title. Earlier points: (1) now one injected Wait failure is tested too, still no real driver failure; (2) unchanged, the arm at list_x.rs ~3622 is still dead; (4)-(6) unchanged. Fine: no new wait on a value nothing signals, no lock-order cycle, the description covers the change, and its smoke block names this head.
performance: 60 s smoke of a retail title, main f07e426 vs this merge (4a4d8f5f): 1672 -> 1653 frames shown (98 %; last presents per 2 s: 60 60 61), peak commit 17352 -> 18273 MB, 0 device removals, 0 crashes. The suite counts are from the first run of this merge (same head and base), whose smoke run hit a smoke-script startup error unrelated to the PR (the same build ran the title normally by hand); the smoke above is from the second run, whose lib test binary was lost to this machine's known intermittent uma_driver coherent-window abort.
verdict: safe to merge: the hang is gone (both of the PR's tests pass, the suite finishes), the new commit adds no wait on a value nothing signals and no lock-order cycle, and the smoke run is clean; the open points (tests for the title_textures propagation, the dead RETRY push and list_x.rs arm, wording) don'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 the needs-pr-check Failing the PR description check (CONTRIBUTING.md) label 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-pr-check Failing the PR description check (CONTRIBUTING.md)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants