Skip to content

D3D12.X: retain resources when retirement fences fail - #3125

Open
Prime1997 wants to merge 2 commits into
xcl-dev:mainfrom
Prime1997:codex/nv-retirement-20261128
Open

Prime1997 wants to merge 2 commits into
xcl-dev:mainfrom
Prime1997:codex/nv-retirement-20261128

Conversation

@Prime1997

@Prime1997 Prime1997 commented Nov 28, 2026 •

Copy link
Copy Markdown
Collaborator

Keep deferred resources and sparse tiles held when queue completion cannot be established. D3D12 reports device removal as UINT64_MAX; treating that as a normal completed fence can release or reuse GPU resources without proving completion.

Related to Decodere’s #2538, reviewed at 2fc8268271f4d025d408527a9b9cfd62730fab1c, which covers target-page retirement. This focused NVIDIA follow-up covers the separate late_release and sparse-buffer paths, directly on NVIDIA 54225f5884a94cd23b7aab3f703a7c975070aa77. It does not import the prior integration branch or claim to establish the cause of any device removal.

Rebased onto main (2026-11-28). nvidia-dev was merged into main by #3203, so this PR now targets main and its branch was rebased onto main 765b2c5bfff6754e8c9886a73e188a86aca3c64c: head edfddd5a92d79f7dbf19faa35b74cc778648bdc7 (was 8a1f1c8a5961573d0e8315feaeed8fa371f9351b). main had rewritten quarantine_tiles_for and retire_free_pools_with in sparse.rs, so the second commit's checks were ported onto that code by hand: the checked mark on the sparse queue goes through native_queue_signal, and sync_known_queues no longer exists. That port needs a review. In late_release.rs the checked mark keeps main's native_queue_signal. On the rebased head, on the same RTX 3060 Ti PC, debug profile: cargo check -p xcl --all-targets exited 0, and cargo test -p xcl --lib -- --test-threads=4 late_release_marks_never_signal_the_removal_sentinel_or_wrap removal_does_not_complete_a_held_batch sparse_retirement_requires_real_completion_on_every_queue quarantine late_release retire gave 52 passed, 0 failed, 0 ignored, no SKIPPED. The whole suite and the paired title runs have not been rerun on this head; every other result below is from the earlier head. The rebase and its conflict resolution were done with Claude Code.

What is in it

  • Deferred releases reject removal sentinels and checked fence increments prevent sentinel/wrap signals.
  • Sparse quarantine records a checked sparse-queue mark after unmaps and requires genuine completion of every queue mark. Missing/failed marks retain the batch.
  • Sparse allocation and retired-heap release reject removal sentinels. Add three pure retirement fixtures.

Tested

  • Standalone PR head: 8a1f1c8a5961573d0e8315feaeed8fa371f9351b.
  • Combined integration d54d80e1bc9d070cbec4a619abb5f4b89880b2f5 compiled with cargo build --locked --release -p xcl --target-dir <isolated-target>: exit 0, 229.200 seconds. This is compilation of the combined candidate, not a build or runtime validation of this standalone PR. Zero tests executed; no GPU checks or smoke run.
  • Independent source review and git diff --check only, at 8a1f1c8a5.
  • Two focused commits over the NVIDIA base; three files, 90 insertions / 8 deletions.

Regression run
Not run. No smoke blocks or runtime test results are claimed.

Not tested
Build, fixtures, full suite, real-title behavior and device-removal recovery have not been validated at this standalone head. Keep as draft pending validation. Fail-closed retention can keep memory held until teardown after a failed signal; it is not a memory-budget cap.

AI use
Codex (GPT-6) implemented the narrow lifetime checks, inspected local SDK contracts, wrote fixtures and performed independent source review. Original target-page retirement credit belongs to Decodere’s #2538; that separately owned implementation remains unchanged.

Optional contributor/test coordination: https://discord.gg/6B4TykyC4W

@Prime1997

Copy link
Copy Markdown
Collaborator Author

Failed interactive integration result for d54d80e1bc9d070cbec4a619abb5f4b89880b2f5, containing this PR's change together with the other memory/removal repairs. This was not a standalone test of 8a1f1c8a5961573d0e8315feaeed8fa371f9351b and does not establish which change caused or prevented a symptom.

  • RTX 3060 Ti 8 GiB, 32 GiB system RAM, release, about 402 seconds with 126 read-only monitoring samples. XCL ended the title itself with 0x887a0005 (DEVICE_REMOVED); no external stop or automated inputs.
  • Peak process commit: 22,994 MiB; peak resident process-tree RAM: 15.79 GiB. Peak DXGI local usage: 6,839 MiB; all 196 console memory lines were below their simultaneous local budget, with minimum headroom 218 MiB. Sampling cannot rule out a transient overrun.
  • Last positive presentation interval was observed around 173 seconds. Audio/diagnostic activity continued during the later rendering stall.
  • DRED state was UNKNOWN. Both page-fault output and breadcrumbs returned 0x887a0004 (unsupported), so there is no reliable GPU fault location. System commit still had 34,764 MiB headroom at removal; no out-of-memory result was established.

The existing CPU-write guard held its write when the producer became Removed and the fence returned UINT64_MAX. The new retirement guards were not independently fault-injected. Fail-closed resource retention is not a device-removal cure or global budget cap.

This run does not justify merge approval or a claim that RAM growth/device removal is fixed. Full standalone validation and matching main/head smoke reports remain outstanding. No builds or synthetic GPU tests ran during gameplay. Logs, hashes, counter samples and source/installed-data preservation checks are retained locally.

AI use: OpenAI Codex (GPT-6) launched the prepared candidate at the user's request, monitored existing logs and read-only counters, and prepared this report; a separate Codex agent reviewed the log evidence.

Optional contributor/test coordination: https://discord.gg/gK3y7WRRY

@kole07139

Copy link
Copy Markdown

Test report for head 8a1f1c8a. No new failure.

Tested: NVIDIA GeForce RTX 3070 8 GB (driver 617.42, wave32), Intel i9-9900K, 32 GB RAM, Windows 11 Pro N 26200, rustc 1.99.0, DXC 1.8.2502.11, debug. Each head was tested alone, with its own target directory, on its base nvidia-dev 54225f58. The library tests were run as cargo test -p xcl --lib --no-fail-fast -- --test-threads=4 --skip a_refused_gpu_upload_segment_becomes_custom. That one test is left out because the library test binary stops at its fail-stop (0x7C10003), as throny reported on #3041, with or without this PR; alone it passes. On the base the same command gives 1771 passed, 6 failed, 28 ignored. The 6 failures (placed_title_textures_share_vram_and_preserve_pixels, three stream_recheck_*, d32s8_targets_take_their_own_size_of_video_memory, gpu_retire_queue_holds_heap_until_blocked_queue_passes_mark) are the base's own and are not repeated below.

I also merged the four heads #3122–#3125 together on 54225f58 (only README.md conflicts, plus the two new tests of #3123 and #3125 at the same place in sparse.rs; both kept). On that tree cargo test --workspace --no-fail-fast -- --test-threads=4 gives: library binary stopped at the same fail-stop; the other test binaries 132 passed, 0 failed, 20 ignored. The library command above: 1779 passed, 9 failed, 28 ignored, that is the base's 6 plus the 3 named below.

Not tested: a title run or smoke run of this head, a release build, AMD and Intel GPUs.

AI use: Claude Code (Claude Opus 5.5) ran the merges, builds and tests, and wrote this report.

@KDenKC

KDenKC commented Nov 28, 2026

Copy link
Copy Markdown
Contributor

@Prime1997 the whole suite of your head on an RTX 3090 against its base on the same machine: no failure the base doesn't have; its new tests pass: late_release::tests::late_release_marks_never_signal_the_removal_sentinel_or_wrap, late_release::tests::removal_does_not_complete_a_held_batch, sparse::tests::sparse_retirement_requires_real_completion_on_every_queue.

Tested: 8a1f1c8a and its base nvidia-dev 54225f58.

  • RTX 3090 24 GB, NVIDIA 621.24, i7-10700T x8 (a VM with the GPU passed through), Windows 11 26H2 (26300.9974), Rust 1.99.1 (stable-x86_64-pc-windows-msvc), debug, no XCL_* set.
  • cargo test --workspace --no-fail-fast -- --test-threads=4 --skip uma_driver::tests::a_refused_gpu_upload_segment_becomes_custom --skip uma_driver::tests::mixed_window_keeps_its_bytes_and_the_gpu_sees_every_segment --skip uma_driver::tests::failed_restore_stops_before_importing_an_unbacked_window (those three end the lib test binary on 621.24, at the base too)
  • base: 1,900 passed, 7 failed, 48 ignored; head: 1,903 passed, 7 failed, 48 ignored. The 7 failures are the same tests on both, and they come from this VM (4 title_textures: one 0x8007000E in the full run, passes alone, and three PoisonError from it; 2 vram 0x8007000E; e2e test_title_runs_and_game_folder_is_untouched).
  • SKIPPED: 30, the same on both.

Not tested: a title run; a release build; AMD / Intel.

AI use: an agent swarm: Claude Fable 5.2, Claude Opus 5.5, GPT-6.2-Sol and Gemini 4 Neon.

Prime1997 and others added 2 commits November 28, 2026 12:18
Reject the fence removal sentinel when draining held resources and do not signal or wrap into reserved fence values. Two CPU fixtures added but not executed; source reviewed independently. Not built in this task. Assisted-by: Codex (GPT-6)
Reject device-removal sentinel completions, mark sparse unmaps with a checked queue signal, and retain tiles when any queue mark is unavailable. Add a pure retirement fixture (not executed).

Related to xcl-dev#2538 (2fc8268), whose fail-closed target-page retirement principle does not cover sparse buffer pools. Source-reviewed independently; no native tests or runtime claims. Prepared with Codex (GPT-6).
@Prime1997
Prime1997 force-pushed the codex/nv-retirement-20261128 branch from 8a1f1c8 to edfddd5 Compare November 28, 2026 20:35
@Prime1997
Prime1997 marked this pull request as ready for review November 29, 2026 02:12
@github-actions github-actions Bot added area:d3d12 D3D12.X runtime, command lists, resources, sparse memory area:docs-ci Documentation, scripts, workflows, repo governance area:memory Virtual/physical memory, arenas, VRAM budget, UMA gpu:nvidia Code is specific to NVIDIA / wave32 GPUs (scope tag; see needs:nvidia-test) labels Nov 29, 2026
@thehollowedone

Copy link
Copy Markdown
Contributor

Independent Windows check of head edfddd5a92d79f7dbf19faa35b74cc778648bdc7 merged cleanly onto main fa204595a488c60c6c5f905244f0172072c9c2a9; git diff --check passed. RTX 3080 Ti / 621.35, Ryzen 7 9800X3D, Windows 11 build 26300, debug profile.

  • cargo build --workspace: passed.
  • cargo test --workspace --no-fail-fast -- --test-threads=4: library 2,471 passed, 1 failed, 29 ignored; 26 printed SKIPPED GPU notices. gpu_two_pass_cache_e2e: 0 passed, 1 failed. The remaining test targets passed. The library failure was console_mesh_caches_hlsl_compute_pass_in_memory_and_on_disk (DXIL not compiled yet). The two-pass test expected its final state count to return to zero but observed one. Both failures reproduced in focused runs on untouched main fa204595, so these runs do not identify a regression from this PR.

One lifetime gap remains in the changed path. If a title queue submits work and its retirement mark fails, present retains the queue as Retiring::Failed, but active_queues_held excludes it. late_release::drain_known only passes active title queues plus internal queues to Held::drain. A resource held after that failed retirement can therefore be sealed and released when the internal queues finish, even though the failed title queue has no trustworthy completion mark. The existing failed_retirement_is_permanently_pinned test proves the registry keeps that queue owner, but does not exercise deferred resource release.

The bounded fix is to use queue_completion_snapshot() when sealing: keep the open batch held if blocked, include installed retirement marks alongside successful active-queue signals, and continue rejecting the removal sentinel when checking marks. A regression should cover a failed retirement followed by a held resource and successful completion of other queues; the resource must remain held. A marked-retirement case should release only after its mark completes.

Merge status: not yet. The PR-description check also remains red because this head lacks the required clean-head paired smoke blocks. I did not run a title smoke or a device-removal injection, so neither behavior is claimed here.

AI use: Codex (GPT-6.2 Sol) reviewed the source and ran the local build and tests.

@vasanex

vasanex commented Nov 29, 2026

Copy link
Copy Markdown
merge-check
base: fa204595a488c60c6c5f905244f0172072c9c2a9
head: edfddd5a92d79f7dbf19faa35b74cc778648bdc7
merge: clean (clashes with #3123 and #3124 in README.md, with #3123 also in the sparse.rs test module)
build: cargo build --workspace -> ok
tests: not run alone; in a stack of 11 of your PRs on this base: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2650 passed, 1 failed, 49 ignored; SKIPPED: 27 lines; failing: #3123's private_physical_pages_reach_the_gpu_on_mapping only. Alone: hle::d3d12x::late_release:: hle::d3d12x::sparse:: 147 passed, 0 failed, 1 ignored.
review: no defect found in the diff; the port onto main's quarantine_tiles_for reads right. Notes: flush_parked_for still calls self.signal() and quarantine_tiles_for then signals again (one extra Signal per flush with unmaps); take_tile reads the fence once per tile; after a device removal nothing is released any more (held until exit) - fine if the title ends on removal, a maintainer's call otherwise; the new tests cover the helper predicates only. thehollowedone's gap (a failed retirement queue is not in active_queues_held, so drain_known can release behind it) stands as they describe it; drain_known does take active_queues_held (late_release.rs:250).
performance: 60 s smoke of the merged tree (57b679d8): 1692 frames, peak commit 17021 MB, 0 removals, 0 crashes (base 1629-1689 frames, 16065-16596 MB). No removal or failed Signal was injected.
verdict: not yet: the failed-retirement gap reported by thehollowedone is open; description check red (these smoke numbers are for the merged tree, not a clean-head block)
hardware / tool and model: RTX 3080 10 GB 621.40, Ryzen 9 7950X, Windows 11 26200 / Claude Code (Claude Opus 5.5, Claude Fable 5.2)

How this was run: the suite ran once on the 11 of your PRs that build on this base, merged together (#3047 #3048 #3049 #3091 #3092 #3103 #3104 #3105 #3107 #3123 #3125; a local tree, only #3125 needed a resolution in README and the sparse.rs test module); the base alone gave 2608 passed, 0 failed, 49 ignored with the same 27 SKIPPED lines (21 no wave64, 3 refused per-lane f16/f32 forms, 2 heap windows opt-in, 1 driver cache needs Developer Mode). This PR alone was merged onto the base, built (cargo build --workspace, then release), its modules' lib tests run (debug), and smoke-run once for 60 s (scripts/smoke.ps1, retail title, front end, XCL_PREPARE=0). The smoke numbers are for my local merged tree, not a clean-head block for the description.

AI use: Claude Code (Claude Opus 5.5 and Claude Fable 5.2) ran the builds, tests and title runs, reviewed the diff and wrote this; the code points cited were checked against the merged tree.

@Kalmarv

Kalmarv commented Nov 29, 2026

Copy link
Copy Markdown
Contributor

merge-check
base: beeb81b (mergeable cleanly on current main)
head: edfddd5
merge: clean
build: cargo check -p xcl --all-targets -> ok
tests: non-GPU lib tests of touched modules (late_release 5 passed, sparse 19 passed). Full workspace suite and GPU tests not run.
review: none blocking. Device-removal sentinel (u64::MAX) is no longer treated as completion, marks cannot wrap to the sentinel, and sparse retirement takes a checked native signal before initial_quarantine_marks.
performance: one extra queue signal per retirement batch; no overhead seen. Tested in a combined 600 s retail run on main beeb81b + 13 PRs (warm cache, defaults) vs baseline: presents/2 s 3.27 vs 3.29, peak commit 35,016 vs 35,767 MB, local video memory 14.19-14.76 vs 14.32-14.95 GB, 0 pipeline waits >= 1 s vs 5, 0 device removals, 0 crashes. Combined result across all 13 PRs, not isolated to this PR.
verdict: not yet: full workspace suite not run on its own merge.
hardware / tool and model: NVIDIA GeForce RTX 5070 Ti, driver 32.0.16.1074, AMD Ryzen 9 9950X, Windows 11 Pro 26200 / Claude Code (claude-opus-5-5)

@github-actions github-actions Bot added the needs-pr-check Failing the PR description check (CONTRIBUTING.md) label Nov 29, 2026

@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.

Critical review of current head edfddd5a. The patch correctly excludes UINT64_MAX from completion and avoids signalling the removal sentinel in both deferred-release and sparse retirement paths. I found no new code blocker in those checks. The key regression to retain is a failed queue Signal followed by later valid work: resources must remain pinned until a fresh, proven mark, without reusing tiles from the failed batch. The new unit tests exercise the sentinel and mark arithmetic; please keep the device-removal/failure integration evidence linked before merge. No local Windows run.

@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Collaborator

Review (head edfddd5, diff read, not a merge-check; it conflicts with main and PR description fails, so not built or run):

  • The late-release part has to be redone on main's new seal. late_release.rs conflicts with main's d783592, which split the seal into begin_seal / end_seal with the Signals outside HELD; end_seal(ok=false) already puts a batch back after a failed Signal. Not superseded, but next_mark / marks_completed need rewriting there.
  • A one-off Signal failure now stops sparse tile reuse for good (sparse.rs ~5955-5964). Main's self.signal() ignores a failed Signal and a later successful one passes the value, so tiles are freed late but never early. The PR's extra Signal turns one failure into marks: None; that batch stays at the front of quarantined and blocks every later batch, so freed tiles stop going back into use and video memory keeps growing. The extra Signal, and the comment justifying it ("an earlier unchecked signal cannot authorize reuse"), look unnecessary: an unsignalled value can't complete early.
  • The device-removal case is mostly not a hazard: a removed device runs no more GPU work, and main already ends the process after every title submit and present once the device is removed (real.rs ~12060, present.rs ~139), so treating UINT64_MAX as done only holds memory until the next submit.
  • PR description fails: no xcl-smoke blocks. AI use names Codex (GPT-6) but no model for the Claude Code rebase. The wrap checks in next_mark can't trigger at one fence step per 10 ms, and the README lines describe internals, not user-visible behaviour.

Fine: the helper tests, the blocked behaviour is unchanged, and sparse.rs merges cleanly.

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

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:docs-ci Documentation, scripts, workflows, repo governance area:memory Virtual/physical memory, arenas, VRAM budget, UMA gpu:nvidia Code is specific to NVIDIA / wave32 GPUs (scope tag; see needs:nvidia-test) needs-pr-check Failing the PR description check (CONTRIBUTING.md)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants