Skip to content

D3D12.X: fail lazy texture placement when mappings are unfinished - #3124

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

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

Conversation

@Prime1997

@Prime1997 Prime1997 commented Nov 28, 2026 •

Copy link
Copy Markdown
Collaborator

Alternative follow-up to throny's #3116, preserving its explicit NULL mapping workaround and attribution. This branch targets nvidia-dev directly; it is not stacked on #3116. The original PR can still return a new lazy texture after Signal failure, a wait timeout, or the fence's device-removal sentinel. This adaptation returns an allocation error in those cases instead of publishing an unfinished resource.

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 3caa566dedf4c07a7cf96dc50eec54698ec10399 (was b5bca33d72f36f80a5f9edf14512e05e0fd25d19). Conflicts were in vram.rs: place_on_pages now also keeps main's texel accounting, and before_execute keeps main's wait measurement next to the settled-texture release. 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 failed_new_mapping_keeps_resource_until_a_real_completion new_mapping_wait_requires_completion_and_propagates_failures a_placed_texture_gets_the_pages_of_a_level_with_its_texels gave 3 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

  • Queue a whole-resource NULL mapping before publishing a new lazy texture. Wait outside the mapping lock, with a five-second failure deadline.
  • Preserve an unpublished resource while its queued mapping may still reference it. Release that hold only after genuine fence completion; an unmarked mapping or removed device remains held.
  • Add two CPU fixtures for completion/error/deadline and resource retention, and extend the existing native lazy-texture fixture to check mapping completion before placement returns.

Tested

  • Standalone PR head: b5bca33d72f36f80a5f9edf14512e05e0fd25d19.
  • 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.
  • Source review and git diff --check only. The NVIDIA-only port has the same added/removed lines as the independently reviewed local adaptation; it contains one commit over 54225f5884a94cd23b7aab3f703a7c975070aa77.

Regression run

  • Not run. GPU and shader/memory test batches were waived by the user for this preparation; no smoke blocks have been fabricated.

Not tested

  • Compilation, all new fixtures, native NVIDIA behavior, retail-title regression, AMD/Intel and Wine.
  • This is not proof of the cause of the observed device removal. D3D12 already specifies initially NULL reserved mappings; the explicit call remains the contributor's reported NVIDIA workaround.

AI use

  • OpenAI Codex (GPT-6) reviewed the existing PR and primary Microsoft/installed SDK contracts, adapted the completion/error handling, wrote unrun fixtures and prepared this description. Another Codex agent independently reviewed the source.

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 b5bca33d72f36f80a5f9edf14512e05e0fd25d19 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 combined run still removed the device. No initial-texture-mapping failure was logged. This does not identify a failing mapping or show that the reported workaround is ineffective; the failing GPU operation is unavailable.

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 b5bca33d. 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: vram::tests::failed_new_mapping_keeps_resource_until_a_real_completion, vram::tests::new_mapping_wait_requires_completion_and_propagates_failures.

Tested: b5bca33d 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,902 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.

@throny

throny commented Nov 28, 2026 •

Copy link
Copy Markdown
Collaborator

In-title check of head b5bca33d on nvidia-dev 54225f58: 10 of 10 world entries clean, no device removal, no placement failed.

Tested

runs device removed presents/s in the world
no fix (control, earlier today) 10 4 –
#3116 10 0 2.16–2.71
this PR 10 0 2.11–2.94

Not tested

  • The failure path itself in a title (it never triggered); a long session; the whole suite on this head (others posted it); AMD / Intel.

AI use: Claude Code (Claude Fable 5.2) built the tree, made the runs and wrote this.

Adapt throny PR xcl-dev#3116 explicit NULL mapping before publication. Signal errors, device removal and a five-second wait deadline fail placement while uncertain resources remain held. CPU and native fixture changes are present but unrun; this commit has not been built. Assisted-by: Codex (GPT-6)
@Prime1997
Prime1997 force-pushed the codex/nv-new-mappings-20261128 branch from b5bca33 to 3caa566 Compare November 28, 2026 20:35
@Kalmarv

Kalmarv commented Nov 28, 2026

Copy link
Copy Markdown
Contributor

One thing from building a local test branch of main with your open PRs on it (head 3caa566):

crates/xcl/src/hle/d3d12x/vram.rs:1904, in null_all, signals with self.queue.Signal(&self.fence, value). Every other signal on this queue in the same file goes through super::real::native_queue_signal (vram.rs:1777, 1808, 2290, 2667). Its doc comment in real.rs gives the reason: console queue layouts remap public slots 14 and up, so a COM call on an adopted queue may not reach the native Signal, and the helper also takes the queue's submit lease.

Suggested change:

super::real::native_queue_signal(&self.queue, &self.fence, value).map_err(|e| e.code().0)?;

Not tested on its own: with that one line changed the branch builds and the vram lib tests pass (41), no title run yet.

AI use: found by Claude Code (Claude Opus 5.5) while merging the PR onto main; checked by reading with Claude Fable 5.

@Prime1997
Prime1997 marked this pull request as ready for review November 29, 2026 02:13
@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) needs-rebase Has merge conflicts with its base branch labels Nov 29, 2026
@github-actions github-actions Bot removed the needs-rebase Has merge conflicts with its base branch label Nov 29, 2026
@thehollowedone

Copy link
Copy Markdown
Contributor

Current-head build blocker on #3124 at 75cb5fcbe212f9e0f3bd86c89b03379d4ffbadbf: vram.rs::place_on_pages contains both the new tuple-returning branch and an old copy of the branch after it. On main fa204595a488c60c6c5f905244f0172072c9c2a9, the unmodified head fails cargo test -p xcl --lib new_mapping_wait_requires_completion_and_propagates_failures before tests run: unexpected pages after (true, None), two missing Target.recycle fields, incompatible bool/tuple branches, and the old one-argument forget_pages call. This explains the red Windows build check.

I tested the correction below in an uncommitted local copy of that exact head. It preserves main's recycle_key, removes the duplicated branch, and passes false to forget_pages because the failed placement is unpublished and its resource is held separately in unsettled. It also applies Kalmarv's existing native_queue_signal finding; that call must use the native queue slot and submit lease.

Candidate diff against PR head
diff --git a/crates/xcl/src/hle/d3d12x/vram.rs b/crates/xcl/src/hle/d3d12x/vram.rs
@@ -2134,7 +2134,7 @@ impl Pages {
         let flag = D3D12_TILE_RANGE_FLAG_NULL;
         self.queue.UpdateTileMappings(res, 1, None, None, None, 1, Some(&flag), None, None, D3D12_TILE_MAPPING_FLAG_NONE);
-        self.queue.Signal(&self.fence, value).map_err(|e| e.code().0)?;
+        super::real::native_queue_signal(&self.queue, &self.fence, value).map_err(|e| e.code().0)?;
         self.value = value;
@@ -2462,18 +2462,12 @@ unsafe fn place_on_pages(
                 LEVEL_STATS[1].fetch_add(total as u64, std::sync::atomic::Ordering::Relaxed);
                 record_texel_insert(&texels);
-                pages.targets.insert(raw as usize, Target { va, console_bytes, total, mapped: true, used: Vec::new(), used_extra: Vec::new(), levels, texels });
-                (true, Some(pages.null_all(res)))
-            } else if let Some((used, used_extra)) = pages.bind(dev, res, va, console_bytes, total) {
-                record_texel_insert(&texels);
-                pages.targets.insert(raw as usize, Target { va, console_bytes, total, mapped: true, used, used_extra, levels: None, texels });
-                (true, None)
                 pages.targets.insert(raw as usize, Target { va, console_bytes, total, mapped: true, used: Vec::new(), used_extra: Vec::new(), levels, texels, recycle: recycle_key });
-                true
+                (true, Some(pages.null_all(res)))
             } else if let Some((used, used_extra)) = pages.bind(dev, res, va, console_bytes, total) {
                 record_texel_insert(&texels);
                 pages.targets.insert(raw as usize, Target { va, console_bytes, total, mapped: true, used, used_extra, levels: None, texels, recycle: recycle_key });
-                true
+                (true, None)
             } else {
                 (false, None)
             }
@@ -2489,7 +2483,7 @@ unsafe fn place_on_pages(
             if let Some(Some(pages)) = PAGES.lock().unwrap().get_mut(&dev_key) {
                 pages.unsettled.push((res.clone(), retirement));
             }
-            forget_pages(raw as usize);
+            forget_pages(raw as usize, false);
             drop(windows::core::IUnknown::from_raw(raw));

Tested: Windows 11 build 26300, RTX 3080 Ti / 621.35, Ryzen 7 9800X3D. On the candidate, cargo build --workspace passed; cargo test -p xcl --lib new_mapping -- --test-threads=1 passed 2/2; cargo test -p xcl --lib a_placed_texture_gets_the_pages_of_a_level_with_its_texels -- --test-threads=1 passed 1/1 on the GPU with no skip. cargo test --workspace --no-fail-fast -- --test-threads=4 ran: library 2,470 passed, 1 failed, 29 ignored, with 26 printed SKIPPED notices; gpu_two_pass_cache_e2e failed, and the other targets passed. Both named failures (console_mesh_caches_hlsl_compute_pass_in_memory_and_on_disk and two_pass_driver_cache_reuses_both_passes_and_recovers_corrupt_blobs) also reproduce in focused runs on untouched main, so they are not established regressions from this candidate.

Not tested: a clean-head paired title smoke, a forced signal failure, AMD/Intel, and Wine. The PR-description check still needs generated smoke blocks after the author pushes the fix. This local candidate is a build/test aid, not a merge-ready verdict.

AI use: Codex (GPT-6.2 Sol) reviewed the current head, wrote the local correction, and ran the tests.

@throny

throny commented Nov 29, 2026

Copy link
Copy Markdown
Collaborator

merge-check claim
head: 75cb5fc

Re-check of the head rebased onto main.

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

throny commented Nov 29, 2026

Copy link
Copy Markdown
Collaborator

merge-check
base: fa20459
head: 75cb5fc
merge: clean
build: cargo build --workspace -> cargo build --workspace on the merge result with main fa20459 -> FAILED, 4 errors in crates/xcl/src/hle/d3d12x/vram.rs: 2 x E0063 missing field recycle in an initializer of vram::Target, E0308 "if and else have incompatible types", E0061 "this function takes 2 arguments but 1 argument was supplied". The PR's own CI on this head is red with the same errors.
tests: none: the merge result does not build.
review: re-check of the head rebased onto main. The PR's own lines differ from the head I ran in the title only where the rebase had to follow main (the two inserts of a target now carry the texels field). What breaks is the other side of the same rebase: main has since given Target a recycle field and changed two things next to the lines this PR rewrites, and the rebased code was not brought along. The logic of the fix is unchanged and still the one that gave 10 of 10 clean world entries here.
performance: nothing new.
verdict: not yet: it does not build on current main (rebase onto main again and add recycle to the two initializers, and follow the changed signature); I re-check and re-run the world entries on the new head at once, since everyone needs this fix to reach the world.
hardware / tool and model: RTX 4080 16 GB (621.40), i9-12900K, Windows 11 26300, Rust 1.100.0, debug. Claude Code; merge, build and suite run by Claude Fable 5.2, diff review by Claude Opus 5.5 (every hunk read; nothing run on the GPU beyond the suite).

@throny

throny commented Nov 29, 2026

Copy link
Copy Markdown
Collaborator

To get this unblocked: I ported the change of this PR (from its earlier head b5bca33d, the one with the 10 clean world entries) onto current main d8bd9a38 locally, and it builds and runs. What it needed, in case it helps the rebase here:

  • In vram.rs place_on_pages, the failure path's call becomes forget_pages(raw as usize, false): on main that function now takes (resource, held). I passed false because the placement was never published, so it should not feed the recycle pool; that choice is a judgement, not tested on its own.
  • The two Target initializers stay as main has them, with recycle: recycle_key; only their results are wrapped in this PR's tuple. With that there is no missing-field error and no if/else type mismatch.

Tested on that port (RTX 4080 16 GB, 621.40; main d8bd9a38 + this change + a local input-timing patch):

  • cargo build --release -p xcl: ok. cargo test --release -p xcl --lib vram -- --test-threads=4: 74 passed, 0 failed, 1 ignored (the two tests of this PR among them).
  • Two world runs of 600 s after the first frame: both reached the world and ran to the end, 2.06 to 2.20 presents/s, no device removal, no hang.

Not tested: the whole suite on the port, and more than two world entries. As soon as the head here builds, I run the merge check and ten world entries on it. If it is easier, I can also put the ported diff in a comment.

AI use: Claude Code; Claude Sonnet 5.5 made the port and ran the tests, Claude Fable 5.2 made the world runs and wrote this.

@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 75cb5fcb. Build blocker: the rebased vram.rs::place_on_pages contains the new tuple-returning branch followed by an old copy of that branch, causing incompatible branch types and stale Target/forget_pages calls against current main. This was reproduced in the current-head build report. Please remove the duplicated old path, port the new path to main's recycle field and two-argument forget_pages, then rerun cargo check --all-targets and the failed-mapping GPU fixture. The failure policy itself is sensible, but this head is not mergeable as working code. No local Windows run.

@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Review (head 75cb5fc, diff read, not a merge-check: Build and test and PR description both fail, so not built or run here):

  • The head doesn't compile. The merge of main left the PR's tuple-returning branches and main's old recycle: recycle_key / true branches in the same if/else chain (vram.rs ~2456-2480), and forget_pages(raw as usize) (~2492) is missing main's new held argument. Please rebase rather than merge main in.
  • A failure the console never reports. On a timeout or a failed Signal, return Some(error) (~2496) becomes placed_hr at device_x.rs ~1298, which skips the fallback to a committed resource, so the title gets a failed CreatePlacedResourceX with a null ppv and will likely crash (the same problem as D3D12.X: map lazy texture levels when title_textures::register fails #3276). Keeping the texture in unsettled and returning None, as the !bound path does, would fall back instead.
  • null_all calls self.queue.Signal while holding PAGES (~2137), while every other Signal on this queue goes through native_queue_signal (~1939, ~1970), which also takes the submit lease.
  • Every lazy placement now waits on the CPU for the GPU (about 200 µs per placement per D3D12.X: a new texture with lazy levels has its tiles mapped by a call #3116), unmeasured here.
  • PR description fails: no xcl-smoke blocks, and the stated head (3caa566) isn't the real one. AI use gives no model for the Claude Code rebase.

Fine: nothing changes by default (XCL_TEXTURE_LEVEL_PAGES is off), the wait happens without holding PAGES, the unpublished texture is kept until its mapping really completes, and the helper tests and extended GPU test look right.

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

@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Test report (not a merge-check: PR description red)
base: b2b1f10
head: 75cb5fc
merge: clean (no textual conflict)
build: cargo build --workspace -> failed: the merge doesn't compile. In crates/xcl/src/hle/d3d12x/vram.rs ~2570-2584 the PR's pages.targets.insert(raw as usize, Target { va, console_bytes, total, mapped: true, ... }) lacks the recycle field vram::Target has on main now (E0063, twice), a ; is missing after (true, None) (~2575), and the if / else arms no longer have the same type (E0308, ~2584). The code around it changed on main since this PR's base, so it needs a rebase rather than a merge.
tests: not run (no build).
review: not repeated here; my review of this same head is at #3124 (comment), and its findings stand. This run adds what reading couldn't: whether the change merges, builds and passes the whole suite on current main.
performance: not measured.
assessment: needs a rebase onto current main; the findings in my review stand
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.

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