D3D12.X: map lazy texture levels when title_textures::register fails #3276

Closed
Kalmarv wants to merge 1 commit from upstream-pr/3276 into main
Kalmarv commented 2026-11-29 03:22:33 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Kalmarv on 2026-11-29T03:22:33Z.


Map all lazy-level tiles in CreatePlacedResourceX when XCL_TEXTURE_LEVEL_PAGES=1 placed a sampled texture on shared pages but title_textures::register returned Err(_).

Previously, vram::place_pages placed a single-slice non-MSAA sampled 2D texture with lazy = true (zero tiles mapped initially, deferring tile mapping to title_textures's CPU-upload path). If title_textures::register then rejected the texture (for example, console float formats 116/117 mapped to R16G16B16A16_FLOAT, multi-plane sampled descriptors, or unsupported layouts), the resource was never entered in title_textures, so vram::map_levels was never called for it and its reserved tiles stayed unmapped (NULL) permanently.

What is in it

  • crates/xcl/src/hle/d3d12x/device_x.rs:
    • In create_placed_resource_x, when title_textures::register returns Err(e) for a texture that vram::place_pages placed under vram::level_pages(), call vram::map_levels(r, None) so all of its levels are backed by the shared 64 KiB pages at va while still logging the rate-limited warning.
    • Add child-process-isolated WARP test lazy_placed_texture_maps_levels_when_title_textures_register_fails verifying with XCL_TEXTURE_LEVEL_PAGES=1 that a console format 116 texture rejected by title_textures::register gets its lazy tiles mapped (!has_unmapped_levels, mapped_level_tiles > 0), while a tracked format 28 control texture stays lazy (mapped_level_tiles == Some(0)).

Tested

  • Hardware / toolchain: NVIDIA GeForce RTX 5070 Ti (driver 32.0.16.1074), AMD Ryzen 9 9950X, Windows 11 Pro (build 26200), rustc 1.99.0 (b940084d7 2026-09-28), DXC 1.9 (XCL_DXC_DIR), debug for tests and release for xcl-smoke.
  • Targeted test (cargo test -p xcl --lib -- hle::d3d12x::device_x::tests:: --nocapture): failed before the fix (untracked lazy texture must not remain with unmapped levels), passed after rebase onto origin/main (21 passed, 0 failed, 0.25s, runs on WARP with 0 skips).
  • Full workspace (cargo test --workspace -j 2 -- --test-threads=4 --skip test_title_runs_and_game_folder_is_untouched --skip uma_driver::tests::): 2662 passed, 0 failed, 49 ignored, 9 filtered across 41 test binaries.
  • SKIPPED GPU tests on this wave32 adapter (26 total across --nocapture workspace baseline): 21 no wave64 (RTX 5070 Ti is wave32), 3 wave32 per-lane #1426 f16/cvt-f16 refusals, 2 no heap windows (opt-in XCL_HEAP_WINDOWS=1).
  • Retail title (ea3b5e4d) 150 s regression run below (0 device removals, 0 crashes, 1541 frames vs 1695 on main, 33556 MB peak commit vs 31546 MB on main).

Regression run

xcl-smoke v1
commit: f0e8fdd5c3942ddd399d5ee11384c8595c5aacff
gpu: NVIDIA GeForce RTX 5070 Ti
title: ea3b5e4d
seconds: 150
exit: 0x0
frames shown: 1695 (PresentX 1695)
presents per 2 s (last 3): 0 0 0
device removals: 0
crashes: 0
peak commit: 31546 MB
xcl-smoke v1
commit: b161ba8b1968519a0a218d977397cbe61cc599d4
gpu: NVIDIA GeForce RTX 5070 Ti
title: ea3b5e4d
seconds: 150
exit: 0x0
frames shown: 1541 (PresentX 1541)
presents per 2 s (last 3): 0 0 0
device removals: 0
crashes: 0
peak commit: 33556 MB

Not tested

  • AMD RDNA / wave64 GPUs and retail titles running with XCL_TEXTURE_LEVEL_PAGES=1 (ea3b5e4d smoke is a default-config regression check; lazy-level fallback behavior is verified by the XCL_TEXTURE_LEVEL_PAGES=1 WARP test).
  • uma_driver::tests:: (skipped locally due to pre-existing 0x7C10003 exit on NVIDIA) and test_title_runs_and_game_folder_is_untouched.

AI use

  • Antigravity (Gemini) used for root-cause verification, implementation, test authoring, and local verification; all diffs, tests, and smoke outputs reviewed and run locally.
<!-- greyfinch-sync:ivall/xcl:issue:5547149741 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3276). Originally posted by [Kalmarv](https://github.com/Kalmarv) on 2026-11-29T03:22:33Z. --- Map all lazy-level tiles in `CreatePlacedResourceX` when `XCL_TEXTURE_LEVEL_PAGES=1` placed a sampled texture on shared pages but `title_textures::register` returned `Err(_)`. Previously, `vram::place_pages` placed a single-slice non-MSAA sampled 2D texture with `lazy = true` (zero tiles mapped initially, deferring tile mapping to `title_textures`'s CPU-upload path). If `title_textures::register` then rejected the texture (for example, console float formats `116`/`117` mapped to `R16G16B16A16_FLOAT`, multi-plane sampled descriptors, or unsupported layouts), the resource was never entered in `title_textures`, so `vram::map_levels` was never called for it and its reserved tiles stayed unmapped (`NULL`) permanently. **What is in it** - `crates/xcl/src/hle/d3d12x/device_x.rs`: - In `create_placed_resource_x`, when `title_textures::register` returns `Err(e)` for a texture that `vram::place_pages` placed under `vram::level_pages()`, call `vram::map_levels(r, None)` so all of its levels are backed by the shared 64 KiB pages at `va` while still logging the rate-limited warning. - Add child-process-isolated WARP test `lazy_placed_texture_maps_levels_when_title_textures_register_fails` verifying with `XCL_TEXTURE_LEVEL_PAGES=1` that a console format `116` texture rejected by `title_textures::register` gets its lazy tiles mapped (`!has_unmapped_levels`, `mapped_level_tiles > 0`), while a tracked format `28` control texture stays lazy (`mapped_level_tiles == Some(0)`). **Tested** - Hardware / toolchain: NVIDIA GeForce RTX 5070 Ti (driver 32.0.16.1074), AMD Ryzen 9 9950X, Windows 11 Pro (build 26200), `rustc 1.99.0 (b940084d7 2026-09-28)`, DXC 1.9 (`XCL_DXC_DIR`), debug for tests and release for `xcl-smoke`. - Targeted test (`cargo test -p xcl --lib -- hle::d3d12x::device_x::tests:: --nocapture`): failed before the fix (`untracked lazy texture must not remain with unmapped levels`), passed after rebase onto `origin/main` (`21 passed, 0 failed`, `0.25s`, runs on WARP with `0` skips). - Full workspace (`cargo test --workspace -j 2 -- --test-threads=4 --skip test_title_runs_and_game_folder_is_untouched --skip uma_driver::tests::`): 2662 passed, 0 failed, 49 ignored, 9 filtered across 41 test binaries. - `SKIPPED` GPU tests on this wave32 adapter (26 total across `--nocapture` workspace baseline): 21 `no wave64` (RTX 5070 Ti is wave32), 3 wave32 per-lane `#1426` f16/cvt-f16 refusals, 2 `no heap windows` (opt-in `XCL_HEAP_WINDOWS=1`). - Retail title (`ea3b5e4d`) 150 s regression run below (`0` device removals, `0` crashes, `1541` frames vs `1695` on `main`, `33556 MB` peak commit vs `31546 MB` on `main`). **Regression run** ``` xcl-smoke v1 commit: f0e8fdd5c3942ddd399d5ee11384c8595c5aacff gpu: NVIDIA GeForce RTX 5070 Ti title: ea3b5e4d seconds: 150 exit: 0x0 frames shown: 1695 (PresentX 1695) presents per 2 s (last 3): 0 0 0 device removals: 0 crashes: 0 peak commit: 31546 MB ``` ``` xcl-smoke v1 commit: b161ba8b1968519a0a218d977397cbe61cc599d4 gpu: NVIDIA GeForce RTX 5070 Ti title: ea3b5e4d seconds: 150 exit: 0x0 frames shown: 1541 (PresentX 1541) presents per 2 s (last 3): 0 0 0 device removals: 0 crashes: 0 peak commit: 33556 MB ``` **Not tested** - AMD RDNA / wave64 GPUs and retail titles running with `XCL_TEXTURE_LEVEL_PAGES=1` (`ea3b5e4d` smoke is a default-config regression check; lazy-level fallback behavior is verified by the `XCL_TEXTURE_LEVEL_PAGES=1` WARP test). - `uma_driver::tests::` (skipped locally due to pre-existing `0x7C10003` exit on NVIDIA) and `test_title_runs_and_game_folder_is_untouched`. **AI use** - Antigravity (Gemini) used for root-cause verification, implementation, test authoring, and local verification; all diffs, tests, and smoke outputs reviewed and run locally.
thehollowedone commented 2026-11-29 07:55:37 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by thehollowedone on 2026-11-29T07:55:37Z.


merge-check
base: d8bd9a3820
head: 43f61224dc
merge: clean (local merge 3407dfad213d48bb7e03907ed7259a167b0323d5; git diff --check clean)
build: cargo build --workspace -> ok; clean release builds of base and merge -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2,619 passed, 0 failed, 49 ignored on both the base and merge retry; 26 explicit GPU skips on each (21 no wave64, 3 unsupported per-lane operations, 2 no heap windows). The first merged-tree suite run exited with 0xc0000005 during concurrent library tests; the same command passed on retry. The focused PR test passed on the RTX 3080 Ti after locally replacing its WARP adapter selection (1 passed, 0 failed, 0 ignored, 0 skips); that test-only edit was removed before the smoke runs.
review: The normal format-116 fallback maps its lazy tiles, while format 28 remains lazy. One allocation-failure path still returns S_OK with an unmapped, untracked texture: map_levels skips a group when its backing heap cannot be allocated, and the new caller discards that result. A local test-only heap-allocation failure reproduced the unmapped-level assertion on the unmodified PR head. The candidate below returned E_OUTOFMEMORY with a null output; both focused normal and injected tests passed (1/0/0 each). The child test should also remove inherited XCL_VRAM_ARENAS, which otherwise disables the placement it asserts. GPU readback of a multi-mip fallback texture remains untested.
performance: With XCL_TEXTURE_LEVEL_PAGES=1 and matched 60 s guarded runs, base/merge showed 1,645/1,664 frames and 15,014/14,985 MB peak commit, with no crash or device removal. Both logs confirmed the opt-in and recorded four registration-rejection warnings; the smoke did not establish which resources received lazy tile mappings or reach world load. These menu-phase differences do not establish a frame-time or memory improvement.
verdict: not yet: return a failure and null resource if the fallback cannot map every lazy level, and cover that allocation-failure path with a regression.
hardware / tool and model: Windows 11 build 26300, Ryzen 7 9800X3D, RTX 3080 Ti / 621.35, Rust 1.99.1 MSVC, DXC 1.8.2502.11 / Codex (GPT-6.2 Sol) ran and reviewed the tests and candidate; Codex (GPT-6.2 Astra) reviewed the allocation path.

Candidate diff for the allocation-failure path

This is a local candidate on the PR head, not a pushed commit. The test hook forces the same alloc_pool_heap failure that a failed CreateHeap reaches. Without the runtime change, the injected test fails because an unregistered texture still has unmapped levels; with it, both the injected and normal focused runs pass.

diff --git a/crates/xcl/src/hle/d3d12x/device_x.rs b/crates/xcl/src/hle/d3d12x/device_x.rs
@@
 const E_FAIL: HRESULT = 0x8000_4005u32 as i32;
+const E_OUTOFMEMORY: HRESULT = 0x8007_000Eu32 as i32;
@@
                 if placed_hr.is_some() && super::vram::level_pages() {
-                    if let Some(r) = ID3D12Resource::from_raw_borrowed(&*ppv) {
+                    let incomplete = if let Some(r) = ID3D12Resource::from_raw_borrowed(&*ppv) {
                         super::vram::map_levels(r, None);
+                        super::vram::has_unmapped_levels(*ppv as usize)
+                    } else {
+                        false
+                    };
+                    if incomplete {
+                        drop(windows::core::IUnknown::from_raw(*ppv));
+                        *ppv = std::ptr::null_mut();
+                        return E_OUTOFMEMORY;
                     }
@@
             let out = std::process::Command::new(exe)
                 .env(ENV, "1")
                 .env("XCL_TEXTURE_LEVEL_PAGES", "1")
+                .env_remove("XCL_VRAM_ARENAS")
@@
             let hr_116 = create_placed_resource_x(dev.as_raw(), 0x7_3000_0000, desc_116.as_ptr(), 0, std::ptr::null(), riid, &mut raw_116);
+            if std::env::var_os("XCL_TEST_POOL_HEAP_FAIL_3276").is_some() {
+                assert_eq!(hr_116, E_OUTOFMEMORY, "mapping failure must be returned to the caller");
+                assert!(raw_116.is_null(), "failed creation must not return an unbacked texture");
+                return;
+            }
diff --git a/crates/xcl/src/hle/d3d12x/vram.rs b/crates/xcl/src/hle/d3d12x/vram.rs
@@
 unsafe fn alloc_pool_heap(dev: &ID3D12Device) -> Option<ID3D12Heap> {
+    if cfg!(test) && std::env::var_os("XCL_TEST_POOL_HEAP_FAIL_3276").is_some() {
+        return None;
+    }
Generated opt-in smoke blocks

Both blocks came from scripts/smoke.ps1 -Seconds 60 on clean release trees with XCL_TEXTURE_LEVEL_PAGES=1, XCL_PREPARE=0, the same adapter, a fresh cache per tree, and the script's network-off setting. A 16 GiB process-tree commit cap, 8 GiB system-commit headroom floor, and 210 s launcher timeout guarded each run; no guard stopped either run.

xcl-smoke v1
commit: d8bd9a38204667f3ca7dd9eeffcc2f1c937b07b0
gpu: NVIDIA GeForce RTX 3080 Ti
title: 9cc6a39e
seconds: 60
exit: 0x0
frames shown: 1645 (PresentX 1645)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15014 MB
xcl-smoke v1
commit: 3407dfad213d48bb7e03907ed7259a167b0323d5
gpu: NVIDIA GeForce RTX 3080 Ti
title: 9cc6a39e
seconds: 60
exit: 0x0
frames shown: 1664 (PresentX 1664)
presents per 2 s (last 3): 60 61 60
device removals: 0
crashes: 0
peak commit: 14985 MB
<!-- greyfinch-sync:ivall/xcl:comment:7252776065 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3276#issuecomment-7252776065). Originally posted by [thehollowedone](https://github.com/thehollowedone) on 2026-11-29T07:55:37Z. --- merge-check base: d8bd9a38204667f3ca7dd9eeffcc2f1c937b07b0 head: 43f61224dc6249853c367d8e3693fed5f6e84d31 merge: clean (local merge 3407dfad213d48bb7e03907ed7259a167b0323d5; `git diff --check` clean) build: `cargo build --workspace` -> ok; clean release builds of base and merge -> ok tests: `cargo test --workspace --no-fail-fast -- --test-threads=4` -> 2,619 passed, 0 failed, 49 ignored on both the base and merge retry; 26 explicit GPU skips on each (21 no wave64, 3 unsupported per-lane operations, 2 no heap windows). The first merged-tree suite run exited with 0xc0000005 during concurrent library tests; the same command passed on retry. The focused PR test passed on the RTX 3080 Ti after locally replacing its WARP adapter selection (1 passed, 0 failed, 0 ignored, 0 skips); that test-only edit was removed before the smoke runs. review: The normal format-116 fallback maps its lazy tiles, while format 28 remains lazy. One allocation-failure path still returns `S_OK` with an unmapped, untracked texture: `map_levels` skips a group when its backing heap cannot be allocated, and the new caller discards that result. A local test-only heap-allocation failure reproduced the unmapped-level assertion on the unmodified PR head. The candidate below returned `E_OUTOFMEMORY` with a null output; both focused normal and injected tests passed (1/0/0 each). The child test should also remove inherited `XCL_VRAM_ARENAS`, which otherwise disables the placement it asserts. GPU readback of a multi-mip fallback texture remains untested. performance: With `XCL_TEXTURE_LEVEL_PAGES=1` and matched 60 s guarded runs, base/merge showed 1,645/1,664 frames and 15,014/14,985 MB peak commit, with no crash or device removal. Both logs confirmed the opt-in and recorded four registration-rejection warnings; the smoke did not establish which resources received lazy tile mappings or reach world load. These menu-phase differences do not establish a frame-time or memory improvement. verdict: not yet: return a failure and null resource if the fallback cannot map every lazy level, and cover that allocation-failure path with a regression. hardware / tool and model: Windows 11 build 26300, Ryzen 7 9800X3D, RTX 3080 Ti / 621.35, Rust 1.99.1 MSVC, DXC 1.8.2502.11 / Codex (GPT-6.2 Sol) ran and reviewed the tests and candidate; Codex (GPT-6.2 Astra) reviewed the allocation path. <details><summary>Candidate diff for the allocation-failure path</summary> This is a local candidate on the PR head, not a pushed commit. The test hook forces the same `alloc_pool_heap` failure that a failed `CreateHeap` reaches. Without the runtime change, the injected test fails because an unregistered texture still has unmapped levels; with it, both the injected and normal focused runs pass. ```diff diff --git a/crates/xcl/src/hle/d3d12x/device_x.rs b/crates/xcl/src/hle/d3d12x/device_x.rs @@ const E_FAIL: HRESULT = 0x8000_4005u32 as i32; +const E_OUTOFMEMORY: HRESULT = 0x8007_000Eu32 as i32; @@ if placed_hr.is_some() && super::vram::level_pages() { - if let Some(r) = ID3D12Resource::from_raw_borrowed(&*ppv) { + let incomplete = if let Some(r) = ID3D12Resource::from_raw_borrowed(&*ppv) { super::vram::map_levels(r, None); + super::vram::has_unmapped_levels(*ppv as usize) + } else { + false + }; + if incomplete { + drop(windows::core::IUnknown::from_raw(*ppv)); + *ppv = std::ptr::null_mut(); + return E_OUTOFMEMORY; } @@ let out = std::process::Command::new(exe) .env(ENV, "1") .env("XCL_TEXTURE_LEVEL_PAGES", "1") + .env_remove("XCL_VRAM_ARENAS") @@ let hr_116 = create_placed_resource_x(dev.as_raw(), 0x7_3000_0000, desc_116.as_ptr(), 0, std::ptr::null(), riid, &mut raw_116); + if std::env::var_os("XCL_TEST_POOL_HEAP_FAIL_3276").is_some() { + assert_eq!(hr_116, E_OUTOFMEMORY, "mapping failure must be returned to the caller"); + assert!(raw_116.is_null(), "failed creation must not return an unbacked texture"); + return; + } diff --git a/crates/xcl/src/hle/d3d12x/vram.rs b/crates/xcl/src/hle/d3d12x/vram.rs @@ unsafe fn alloc_pool_heap(dev: &ID3D12Device) -> Option<ID3D12Heap> { + if cfg!(test) && std::env::var_os("XCL_TEST_POOL_HEAP_FAIL_3276").is_some() { + return None; + } ``` </details> <details><summary>Generated opt-in smoke blocks</summary> Both blocks came from `scripts/smoke.ps1 -Seconds 60` on clean release trees with `XCL_TEXTURE_LEVEL_PAGES=1`, `XCL_PREPARE=0`, the same adapter, a fresh cache per tree, and the script's network-off setting. A 16 GiB process-tree commit cap, 8 GiB system-commit headroom floor, and 210 s launcher timeout guarded each run; no guard stopped either run. ``` xcl-smoke v1 commit: d8bd9a38204667f3ca7dd9eeffcc2f1c937b07b0 gpu: NVIDIA GeForce RTX 3080 Ti title: 9cc6a39e seconds: 60 exit: 0x0 frames shown: 1645 (PresentX 1645) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 15014 MB ``` ``` xcl-smoke v1 commit: 3407dfad213d48bb7e03907ed7259a167b0323d5 gpu: NVIDIA GeForce RTX 3080 Ti title: 9cc6a39e seconds: 60 exit: 0x0 frames shown: 1664 (PresentX 1664) presents per 2 s (last 3): 60 61 60 device removals: 0 crashes: 0 peak commit: 14985 MB ``` </details>
Foniass commented 2026-12-01 04:39:04 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T04:39:04Z.


Review (head 5b2ad07c, diff read, not a merge-check: the PR description check fails, so not built or run here yet):

  • A failure the console never reports. When map_levels can't get pages, the new branch (device_x.rs ~1292-1299) returns E_OUTOFMEMORY and a null resource. The non-lazy path handles the same failure by releasing the reserved resource and falling back to a committed one with S_OK (place_on_pages -> place_pages returns None). Console titles don't expect CreatePlacedResourceX to fail, so this probably turns a blank texture (main: no tiles mapped, reads return 0) into a crash. Falling back to a committed resource would match the other path.
  • The smoke block is on b161ba8b, not the head 5b2ad07c, which is why PR description fails. The description is also out of date: it doesn't mention the E_OUTOFMEMORY path, the second test child or the vram.rs hook.
  • AI use names "Antigravity (Gemini)", not an exact model, and the commit's Co-Authored-By: Claude Opus 5.5 trailer isn't mentioned.

Fine: it's off by default (XCL_TEXTURE_LEVEL_PAGES=1; the vram.rs hook is test-only), the level pages are freed through the release hook (forget_pages), so the failure path neither leaks nor maps twice, and the test fails without the fix in both children, runs on WARP and clears XCL_VRAM_ARENAS.

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

<!-- greyfinch-sync:ivall/xcl:comment:7300952336 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3276#issuecomment-7300952336). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-01T04:39:04Z. --- Review (head 5b2ad07c, diff read, not a merge-check: the `PR description` check fails, so not built or run here yet): - **A failure the console never reports.** When `map_levels` can't get pages, the new branch (`device_x.rs` ~1292-1299) returns `E_OUTOFMEMORY` and a null resource. The non-lazy path handles the same failure by releasing the reserved resource and falling back to a committed one with S_OK (`place_on_pages` -> `place_pages` returns None). Console titles don't expect CreatePlacedResourceX to fail, so this probably turns a blank texture (main: no tiles mapped, reads return 0) into a crash. Falling back to a committed resource would match the other path. - **The smoke block is on b161ba8b, not the head 5b2ad07c**, which is why `PR description` fails. The description is also out of date: it doesn't mention the E_OUTOFMEMORY path, the second test child or the `vram.rs` hook. - AI use names "Antigravity (Gemini)", not an exact model, and the commit's `Co-Authored-By: Claude Opus 5.5` trailer isn't mentioned. Fine: it's off by default (`XCL_TEXTURE_LEVEL_PAGES=1`; the `vram.rs` hook is test-only), the level pages are freed through the release hook (`forget_pages`), so the failure path neither leaks nor maps twice, and the test fails without the fix in both children, runs on WARP and clears `XCL_VRAM_ARENAS`. AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.
Foniass commented 2026-12-01 16:35:32 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T16:35:32Z.


Test report (not a merge-check: PR description red)
base: b2b1f109d2
head: 5b2ad07c8a
merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2903 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: not repeated here; my review of this same head is at https://github.com/xcl-dev/xcl/pull/3276#issuecomment-7300952336, 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: no smoke run.
assessment: merges, builds and passes the whole suite on current main (0 failed); 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.

<!-- greyfinch-sync:ivall/xcl:comment:7317860122 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3276#issuecomment-7317860122). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-01T16:35:32Z. --- Test report (not a merge-check: `PR description` red) base: b2b1f109d27e746a62ec95b04dd1f9924452e682 head: 5b2ad07c8a656a0a76cf156cf9d2397513b67689 merge: clean build: cargo build --workspace -> ok tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2903 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: not repeated here; my review of this same head is at https://github.com/xcl-dev/xcl/pull/3276#issuecomment-7300952336, 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: no smoke run. assessment: merges, builds and passes the whole suite on current main (0 failed); 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.
bmjask commented 2026-12-01 20:14:52 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by bmjask on 2026-12-01T20:14:52Z.

Code review location: crates/xcl/src/hle/d3d12x/device_x.rs; line 1299

@@ -1284,15 +1284,30 @@ pub(super) unsafe extern "system" fn create_placed_resource_x(this: *mut c_void,
                 super::lut3d::created(if placed_hr.is_some() { "CreatePlacedResourceX (sampled: on shared pages)" } else if small_hr.is_some() { "CreatePlacedResourceX (sampled: 4 KiB placement)" } else { "CreatePlacedResourceX (sampled: committed)" }, *ppv, Some(&x), Some(va as usize), true, state);
                 return hr;
             }
-            Err(e) if once(&M, 4) => {
-                let u = |o: usize| u32::from_le_bytes(x[o..o + 4].try_into().unwrap());
-                crate::xlog_warn!(
-                    "D3D12.X: CreatePlacedResourceX texture at {va:#x} (dimension {} {}x{}x{}, {} mips, format {}, {} samples, layout {:#x}, flags {:#x}): not kept in step with the memory ({e})",
-                    u(0), u64::from_le_bytes(x[0x10..0x18].try_into().unwrap()), u(0x18), u16::from_le_bytes(x[0x1C..0x1E].try_into().unwrap()),
-                    u16::from_le_bytes(x[0x1E..0x20].try_into().unwrap()), u(0x20), u(0x24), u(0x2C), u(0x30)
-                )
+            Err(e) => {
+                // If `vram::place_pages` placed this sampled texture with lazy levels,
+                // `title_textures` will never drive `map_levels` for it; map all levels now
+                // so it is backed by the shared pages at `va` instead of staying at 0 tiles.
+                // A level left without pages (no heap for them): the texture is not created.
+                if placed_hr.is_some() && super::vram::level_pages() {
+                    if let Some(r) = ID3D12Resource::from_raw_borrowed(&*ppv) {
+                        super::vram::map_levels(r, None);
+                    }
+                    if super::vram::has_unmapped_levels(*ppv as usize) {
+                        drop(windows::core::IUnknown::from_raw(*ppv));
+                        *ppv = std::ptr::null_mut();
+                        return crate::util::E_OUTOFMEMORY;

When the level pages can't be mapped (alloc_pool_heap/CreateHeap fails or take_batch returns None under VRAM pressure), this returns E_OUTOFMEMORY from CreatePlacedResourceX. Titles usually treat that as fatal, and before this PR the call returned S_OK. Every other place_on_pages bind failure falls back to small_tex::place / dev_create_committed_resource (~1270-1276). This one should drop the reserved resource and take the committed path too. The early return also skips both the warning and the hr < 0 log at ~1320, so the failure isn't logged at all.

<!-- greyfinch-sync:ivall/xcl:review-comment:4760339082 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3276#discussion_r4760339082). Originally posted by [bmjask](https://github.com/bmjask) on 2026-12-01T20:14:52Z. **Code review location:** `crates/xcl/src/hle/d3d12x/device_x.rs`; line 1299 ~~~~diff @@ -1284,15 +1284,30 @@ pub(super) unsafe extern "system" fn create_placed_resource_x(this: *mut c_void, super::lut3d::created(if placed_hr.is_some() { "CreatePlacedResourceX (sampled: on shared pages)" } else if small_hr.is_some() { "CreatePlacedResourceX (sampled: 4 KiB placement)" } else { "CreatePlacedResourceX (sampled: committed)" }, *ppv, Some(&x), Some(va as usize), true, state); return hr; } - Err(e) if once(&M, 4) => { - let u = |o: usize| u32::from_le_bytes(x[o..o + 4].try_into().unwrap()); - crate::xlog_warn!( - "D3D12.X: CreatePlacedResourceX texture at {va:#x} (dimension {} {}x{}x{}, {} mips, format {}, {} samples, layout {:#x}, flags {:#x}): not kept in step with the memory ({e})", - u(0), u64::from_le_bytes(x[0x10..0x18].try_into().unwrap()), u(0x18), u16::from_le_bytes(x[0x1C..0x1E].try_into().unwrap()), - u16::from_le_bytes(x[0x1E..0x20].try_into().unwrap()), u(0x20), u(0x24), u(0x2C), u(0x30) - ) + Err(e) => { + // If `vram::place_pages` placed this sampled texture with lazy levels, + // `title_textures` will never drive `map_levels` for it; map all levels now + // so it is backed by the shared pages at `va` instead of staying at 0 tiles. + // A level left without pages (no heap for them): the texture is not created. + if placed_hr.is_some() && super::vram::level_pages() { + if let Some(r) = ID3D12Resource::from_raw_borrowed(&*ppv) { + super::vram::map_levels(r, None); + } + if super::vram::has_unmapped_levels(*ppv as usize) { + drop(windows::core::IUnknown::from_raw(*ppv)); + *ppv = std::ptr::null_mut(); + return crate::util::E_OUTOFMEMORY; ~~~~ --- When the level pages can't be mapped (alloc_pool_heap/CreateHeap fails or take_batch returns None under VRAM pressure), this returns E_OUTOFMEMORY from CreatePlacedResourceX. Titles usually treat that as fatal, and before this PR the call returned S_OK. Every other place_on_pages bind failure falls back to `small_tex::place` / `dev_create_committed_resource` (~1270-1276). This one should drop the reserved resource and take the committed path too. The early return also skips both the warning and the `hr < 0` log at ~1320, so the failure isn't logged at all.
bmjask commented 2026-12-01 20:14:52 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by bmjask on 2026-12-01T20:14:52Z.

Code review location: crates/xcl/src/hle/d3d12x/device_x.rs; line 1296

@@ -1284,15 +1284,30 @@ pub(super) unsafe extern "system" fn create_placed_resource_x(this: *mut c_void,
                 super::lut3d::created(if placed_hr.is_some() { "CreatePlacedResourceX (sampled: on shared pages)" } else if small_hr.is_some() { "CreatePlacedResourceX (sampled: 4 KiB placement)" } else { "CreatePlacedResourceX (sampled: committed)" }, *ppv, Some(&x), Some(va as usize), true, state);
                 return hr;
             }
-            Err(e) if once(&M, 4) => {
-                let u = |o: usize| u32::from_le_bytes(x[o..o + 4].try_into().unwrap());
-                crate::xlog_warn!(
-                    "D3D12.X: CreatePlacedResourceX texture at {va:#x} (dimension {} {}x{}x{}, {} mips, format {}, {} samples, layout {:#x}, flags {:#x}): not kept in step with the memory ({e})",
-                    u(0), u64::from_le_bytes(x[0x10..0x18].try_into().unwrap()), u(0x18), u16::from_le_bytes(x[0x1C..0x1E].try_into().unwrap()),
-                    u16::from_le_bytes(x[0x1E..0x20].try_into().unwrap()), u(0x20), u(0x24), u(0x2C), u(0x30)
-                )
+            Err(e) => {
+                // If `vram::place_pages` placed this sampled texture with lazy levels,
+                // `title_textures` will never drive `map_levels` for it; map all levels now
+                // so it is backed by the shared pages at `va` instead of staying at 0 tiles.
+                // A level left without pages (no heap for them): the texture is not created.
+                if placed_hr.is_some() && super::vram::level_pages() {
+                    if let Some(r) = ID3D12Resource::from_raw_borrowed(&*ppv) {
+                        super::vram::map_levels(r, None);
+                    }
+                    if super::vram::has_unmapped_levels(*ppv as usize) {

Not certain about this one: map_levels returns without mapping when t.mapped is false, but has_unmapped_levels ignores mapped. If another thread places an overlapping texture between place_pages and here (hold_unmap sets mapped=false), this texture is destroyed with E_OUTOFMEMORY even though nothing failed to allocate.

<!-- greyfinch-sync:ivall/xcl:review-comment:4760339095 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3276#discussion_r4760339095). Originally posted by [bmjask](https://github.com/bmjask) on 2026-12-01T20:14:52Z. **Code review location:** `crates/xcl/src/hle/d3d12x/device_x.rs`; line 1296 ~~~~diff @@ -1284,15 +1284,30 @@ pub(super) unsafe extern "system" fn create_placed_resource_x(this: *mut c_void, super::lut3d::created(if placed_hr.is_some() { "CreatePlacedResourceX (sampled: on shared pages)" } else if small_hr.is_some() { "CreatePlacedResourceX (sampled: 4 KiB placement)" } else { "CreatePlacedResourceX (sampled: committed)" }, *ppv, Some(&x), Some(va as usize), true, state); return hr; } - Err(e) if once(&M, 4) => { - let u = |o: usize| u32::from_le_bytes(x[o..o + 4].try_into().unwrap()); - crate::xlog_warn!( - "D3D12.X: CreatePlacedResourceX texture at {va:#x} (dimension {} {}x{}x{}, {} mips, format {}, {} samples, layout {:#x}, flags {:#x}): not kept in step with the memory ({e})", - u(0), u64::from_le_bytes(x[0x10..0x18].try_into().unwrap()), u(0x18), u16::from_le_bytes(x[0x1C..0x1E].try_into().unwrap()), - u16::from_le_bytes(x[0x1E..0x20].try_into().unwrap()), u(0x20), u(0x24), u(0x2C), u(0x30) - ) + Err(e) => { + // If `vram::place_pages` placed this sampled texture with lazy levels, + // `title_textures` will never drive `map_levels` for it; map all levels now + // so it is backed by the shared pages at `va` instead of staying at 0 tiles. + // A level left without pages (no heap for them): the texture is not created. + if placed_hr.is_some() && super::vram::level_pages() { + if let Some(r) = ID3D12Resource::from_raw_borrowed(&*ppv) { + super::vram::map_levels(r, None); + } + if super::vram::has_unmapped_levels(*ppv as usize) { ~~~~ --- Not certain about this one: `map_levels` returns without mapping when `t.mapped` is false, but `has_unmapped_levels` ignores `mapped`. If another thread places an overlapping texture between place_pages and here (`hold_unmap` sets mapped=false), this texture is destroyed with E_OUTOFMEMORY even though nothing failed to allocate.
bmjask commented 2026-12-01 20:14:52 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by bmjask on 2026-12-01T20:14:52Z.

Review: COMMENTED


Review of 5b2ad07c: 3 finding(s). 2 are inline. These are on lines outside the diff:

crates/xcl/src/hle/d3d12x/vram.rs:2506: The levels are only mapped at creation. If the texture is later superseded (unmap_placed holds an unmap, and release_held_unmaps unmaps the tiles) and then remapped via placements::map_again, remap_if_unmapped takes its lazy branch, which only sets mapped=true. title_textures never tracks this texture, so no upload calls map_levels again, and it's back to 0 tiles and reading zeros, which is the bug this PR fixes.


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.

<!-- greyfinch-sync:ivall/xcl:review:6139285718 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3276#pullrequestreview-6139285718). Originally posted by [bmjask](https://github.com/bmjask) on 2026-12-01T20:14:52Z. **Review:** COMMENTED --- Review of `5b2ad07c`: 3 finding(s). 2 are inline. These are on lines outside the diff: **`crates/xcl/src/hle/d3d12x/vram.rs:2506`**: The levels are only mapped at creation. If the texture is later superseded (unmap_placed holds an unmap, and release_held_unmaps unmaps the tiles) and then remapped via `placements::map_again`, `remap_if_unmapped` takes its lazy branch, which only sets mapped=true. title_textures never tracks this texture, so no upload calls `map_levels` again, and it's back to 0 tiles and reading zeros, which is the bug this PR fixes. --- _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._
Kalmarv commented 2026-12-02 19:38:54 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Kalmarv on 2026-12-02T19:38:54Z.


Closing: returns E_OUTOFMEMORY from CreatePlacedResourceX where the console does not fail, risking a crash instead of committed fallback.

<!-- greyfinch-sync:ivall/xcl:comment:7356504006 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3276#issuecomment-7356504006). Originally posted by [Kalmarv](https://github.com/Kalmarv) on 2026-12-02T19:38:54Z. --- Closing: returns `E_OUTOFMEMORY` from `CreatePlacedResourceX` where the console does not fail, risking a crash instead of committed fallback.

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
xcl-dev/xcl!3276
No description provided.