Skip to content

D3D12.X: pack sub-64 KiB sampled textures into 4 KiB-aligned VRAM heaps - #1835

Open
raylitebull wants to merge 5 commits into
xcl-dev:mainfrom
raylitebull:feat/vram-small-textures
Open

raylitebull wants to merge 5 commits into
xcl-dev:mainfrom
raylitebull:feat/vram-small-textures

Conversation

@raylitebull

@raylitebull raylitebull commented Nov 24, 2026 •

Copy link
Copy Markdown
Member

Packs sub-64 KiB single-sample non-RT/DS sampled textures into shared 16 MiB D3D12_HEAP_TYPE_DEFAULT heaps at 4 KiB placement alignment (D3D12_SMALL_RESOURCE_PLACEMENT_ALIGNMENT), eliminating up to 16x per-texture VRAM bloat and WDDM residency paging cliffs during heavy texture streaming.

Part of #1607 and #1673; complementary to #1782 (no overlapping files — TitleHold was intentionally omitted here so this PR stays scoped solely to sub-64 KiB texture packing).

What is in it

  • crates/xcl/src/hle/d3d12x/vram_small.rs & mod.rs: add SmallPools allocator (UNIT = 4 KiB, POOL_UNITS = 4096 / 16 MiB heaps, XCL_VRAM_SMALL=0 opt-out) with (va, units) alias sharing, size-class slot recycling after IDLE + COOL, CreateHeap / CreatePlacedResource outside locks (re-checking try_acquire under the lock inside add_pool_and_acquire), vram_small::flush_idle_for(dev_key) for test isolation, adapter selection via gpu::adapter::candidates for XCL_ADAPTER, and capability-gated GPU test gpu_small_textures_pack_at_4k_granularity_and_preserve_pixels (skipping steps cleanly with diagnostic SKIPPED messages when an adapter lacks ResourceHeapTier >= 2, 4 KiB D3D12_SMALL_RESOURCE_PLACEMENT_ALIGNMENT, or TiledResourcesTier >= 2).
  • crates/xcl/src/hle/d3d12x/vram.rs: ignore expired idle pages in has_live_page, sweep expired idle entries in vram_small::bytes_for / vram::page_bytes_for / vram::extra_page_bytes_for, add #[cfg(test)] vram::flush_idle_for(dev_key), and release small-pool slots cleanly in forget.
  • crates/xcl/src/hle/d3d12x/title_textures.rs: update the 4 KiB adjacent-placement assertions and add flush_idle_for(dev_key) calls between isolated GPU test phases in placed_title_textures_share_vram_and_preserve_pixels and gpu_small_textures_pack_at_4k_granularity_and_preserve_pixels, keeping #1990's console_has_packed_3d_mips(desc) check ahead of vram_small::place.

Tested

  • Hardware & toolchain: AMD Radeon RX 9070 XT (16191 MiB VRAM, RDNA4, native wave64), Windows 11 x64 (10.0.22631.0), rustc 1.99.1 (58cf8f9c3 2026-10-13), rebased cleanly onto 82e63982 (b5a04adf).
  • On b5a04adf: cargo check --workspace --tests passed (0 new warnings); cargo test -p xcl --lib -- --nocapture --test-threads=1 hle::d3d12x::vram hle::d3d12x::title_textures: 33 passed, 0 failed, 1 ignored (2.91s), including all 3 steps of gpu_small_textures_pack_at_4k_granularity_and_preserve_pixels (0 skips: 512 x 64x64 BC1 in +2,097,152 B inside one 16 MiB heap, hardware RGBA8 alias/crosstalk readback, and live RT vram::Pages alias).
  • Earlier heads: 39014d3 passed RTX 3080 Ti (27/0, @thehollowedone), and 5af3b9d / 44adb5f passed RTX 3060 smoke (@Anon64) and RTX 3090 (@WebIdentity1).

Regression run

  • Standalone 60 s scripts/smoke.ps1 pair on b5a04adf vs 82e63982 has not been run yet. AMD and NVIDIA reviewers (and Intel Arc A770 verification of the new adapter capability checks in gpu_small_textures_pack_at_4k_granularity_and_preserve_pixels) are invited to run tests/scripts/smoke.ps1 and post results in the comments.

Not tested

  • 60 s scripts/smoke.ps1 pair and full cargo test --workspace suite on b5a04adf vs 82e63982, Intel Arc A770 re-run on b5a04adf, and Linux/Wine/vkd3d-proton.

AI use

  • Antigravity assisted with implementation, VRAM pool design, and capability/test fixes; the author reviewed the diff and test output.

@Anon64

Anon64 commented Nov 24, 2026

Copy link
Copy Markdown

Regression run for this PR: head 5af3b9d, based on main c4d37be. RTX 3060 12 GB (581.80, wave32), Windows 11 26200, release, XCL_NETWORK=0, A pressed every 4 s from 20 s, scripts/smoke.ps1 on a retail title for 60 s, back to back with the main run.

main c4d37be:

xcl-smoke v1
commit: c4d37bec1bb4286eb373aea963404a23f13401fa
gpu: NVIDIA GeForce RTX 3060
title: 21222967
seconds: 60
exit: 0x0
frames shown: 1476 (PresentX 1477)
presents per 2 s (last 3): 34 0 7
device removals: 0
crashes: 0
peak commit: 24106 MB

this PR:

xcl-smoke v1
commit: 5af3b9d4004bbfbc23e3104d68426bf1a96cf0b6
gpu: NVIDIA GeForce RTX 3060
title: 21222967
seconds: 60
exit: 0x0
frames shown: 1473 (PresentX 1473)
presents per 2 s (last 3): 8 2 4
device removals: 0
crashes: 0
peak commit: 24709 MB

No device removals or crashes; 100 % of main's frames, 103 % of its peak commit.

Not tested: the whole suite; world loading with this PR; whether the title reaches all of the changed code in these 60 s (default settings, so the direct DXIL path is off).

Written with Claude Code (Claude Opus 5.5) from runs on this machine.

@WebIdentity1

Copy link
Copy Markdown
Contributor

I tested exact head 5af3b9d4004bbfbc23e3104d68426bf1a96cf0b6 on Windows 10 19045, RTX 3090 (591.74), Rust 1.98.1 MSVC. This uncovered one allocator issue and one test-selection gap.

Tested

  • Head: XCL_ADAPTER=3090 cargo test --locked -p xcl --lib hle::d3d12x::vram_small::tests -- --test-threads=1 --show-output: 3 passed, 0 failed. However, the GPU test uses EnumAdapters1(0), so this stock run does not prove which GPU executed it.
  • Test-only adapter-selection overlay using the existing gpu::adapter::candidates: same command, 3 passed, 0 failed, 0 SKIPPED; test output explicitly names NVIDIA GeForce RTX 3090. Its hardware upload/readback assertions for same-address aliasing and adjacent-texture crosstalk passed. The 512 BC1 case reported 2,097,152 B of occupied small slots in one 16,777,216 B heap. The 16× comparison is occupied slot bytes against 64 KiB tile bytes; the actual small-pool heap allocated for this case is 16 MiB.
  • I simulated two callers creating heaps before either published one. The new regression fails on unmodified add_pool_and_acquire: retained pools are 33,554,432 B versus 16,777,216 B expected (0 passed, 1 failed). The function pushes the second heap before checking whether the first caller has already supplied the slot or enough free space. A guard that calls try_acquire before pushing the new heap makes that regression pass (1/0). All four small-pool tests then pass on the selected 3090 (4/0, no skips).

The patch below includes the selector, regression and guard. Four 304-file source archives were SHA-256 checked before and after the runs; no source mutation occurred on Windows. This is a deterministic race interleaving test, not a measured concurrent GPU race.

Not tested: full workspace suite, retail title smoke, AMD/Intel on the patch, gameplay or long streaming memory use. This does not establish merge readiness.

AI use: Codex desktop (GPT-6) prepared the test-only selector, regression, guard and report; the results above are from actual Windows runs.

Local patch against 5af3b9d
diff --git a/crates/xcl/src/hle/d3d12x/vram_small.rs b/crates/xcl/src/hle/d3d12x/vram_small.rs
index 3a1daf8..363c266 100644
--- a/crates/xcl/src/hle/d3d12x/vram_small.rs
+++ b/crates/xcl/src/hle/d3d12x/vram_small.rs
@@ -132,6 +132,11 @@ impl<H: Clone> SmallPools<H> {
     /// Register a newly created pool heap and acquire `(va, units)` (re-checking whether another
     /// thread raced and already created the same slot while the heap was being made).
     fn add_pool_and_acquire(&mut self, heap: H, key: SlotKey, now: Instant) -> (H, u32) {
+        // A different thread may have made enough space while CreateHeap ran outside the lock.
+        // Drop this heap rather than keeping an empty 16 MiB pool for the life of the device.
+        if let Some(got) = self.try_acquire(key, now) {
+            return got;
+        }
         let pool_idx = self.pools.len() as u32;
         self.pools.push(Pool { heap, next_unit: 0 });
         if let Some(got) = self.try_acquire(key, now) {
@@ -358,6 +363,25 @@ mod tests {
         assert_eq!((h_next, off_next), (0, 17));
     }
 
+    #[test]
+    fn racing_heap_creation_does_not_retain_unused_pool() {
+        let now = Instant::now();
+        let mut p: SmallPools<u32> = SmallPools::new();
+        let first = p.add_pool_and_acquire(0, (0x10_0000, 1), now);
+        assert_eq!(first, (0, 0));
+
+        // Both callers observed no pool before creating their heaps. The first caller published
+        // its slot while the second was in CreateHeap, so the second heap is no longer needed.
+        let raced_same = p.add_pool_and_acquire(1, (0x10_0000, 1), now);
+        assert_eq!(raced_same, first);
+        assert_eq!(p.bytes().1, POOL_UNITS as usize * UNIT, "raced heap must be dropped");
+
+        // A different address racing the first allocation can fit in the existing heap too.
+        let raced_other = p.add_pool_and_acquire(2, (0x10_1000, 1), now);
+        assert_eq!(raced_other, (0, 1));
+        assert_eq!(p.bytes().1, POOL_UNITS as usize * UNIT, "no second heap is needed");
+    }
+
     #[test]
     fn candidate_filters_large_gpu_owned_and_msaa_textures() {
         let mut d = D3D12_RESOURCE_DESC {
@@ -397,14 +421,19 @@ mod tests {
         use windows::Win32::Graphics::Dxgi::Common::*;
         use windows::Win32::Graphics::Dxgi::*;
         unsafe {
-            let factory: IDXGIFactory4 = CreateDXGIFactory1().expect("DXGI factory");
-            let Ok(adapter) = factory.EnumAdapters1(0) else { return };
-            if adapter.GetDesc1().is_ok_and(|d| d.Flags & DXGI_ADAPTER_FLAG_SOFTWARE.0 as u32 != 0) {
+            let factory: IDXGIFactory6 = CreateDXGIFactory1().expect("DXGI factory");
+            let sel = crate::gpu::adapter::Selector::from_env_or("auto");
+            let Some((adapter, desc)) = crate::gpu::adapter::candidates(&factory, &sel).into_iter().next() else {
+                crate::gpu::recomp::runner::skip_test(&crate::gpu::adapter::no_match(&factory, &sel));
                 return;
-            }
+            };
+            println!("small texture GPU test adapter: {}", crate::gpu::adapter::name(&desc));
             let mut dev: Option<ID3D12Device> = None;
             let _ = D3D12CreateDevice(&adapter, D3D_FEATURE_LEVEL_11_0, &mut dev);
-            let Some(dev) = dev else { return };
+            let Some(dev) = dev else {
+                crate::gpu::recomp::runner::skip_test("no D3D12 device");
+                return;
+            };
             super::super::real::adopt(dev.as_raw(), super::super::real::Kind::Device);
             let dev_key = dev.as_raw() as usize;
             let riid = &ID3D12Resource::IID as *const windows::core::GUID as *const windows_sys::core::GUID;

@thehollowedone

Copy link
Copy Markdown

Independent check of 5af3b9d on an RTX 3080 Ti (621.35), Windows 11 build 26300, Rust 1.99.1 MSVC debug.

I extended the bundled test to inspect the 64 KiB tile backing a render target and the sampled texture at the same guest address. Both resources referenced the same tile. The tile's user count went from two to one when the sampled texture was released. A sampled texture at the next 64 KiB-aligned address occupied its own 16 KiB small-pool allocation. With just the live-page guard bypassed in a local control, the same-address texture incorrectly took 16 KiB from the small pool and the test failed at that assertion.

cargo test --offline --locked -p xcl --lib gpu_small_textures_pack_at_4k_granularity_and_preserve_pixels -- --nocapture --test-threads=1 passed 1/1 with the test extension and the PR's runtime code, with zero skips. Synthetic textures only.

AI-assisted. Codex (GPT-6 family, exact variant unavailable) extended and ran the test and drafted this report.

@raylitebull

Copy link
Copy Markdown
Member Author

@thehollowedone Thank you for the RTX 3080 Ti verification of the live-page coexistence guard and 4 KiB aliasing behavior on 5af3b9d!

@WebIdentity1 Thank you as well for testing 5af3b9d on the RTX 3090 and for both catches in vram_small.rs:

  • Calling self.try_acquire(key, now) before self.pools.push(...) inside add_pool_and_acquire cleanly drops the redundant 16 MiB pool if two threads race during CreateHeap.
  • Switching gpu_small_textures_pack_at_4k_granularity_and_preserve_pixels from EnumAdapters1(0) to gpu::adapter::candidates properly honors XCL_ADAPTER.

We'll follow up with that small guard + regression test shortly (and refresh the smoke run for the updated head when pushed).

@grahamster2

Copy link
Copy Markdown
Collaborator

Test report for 5af3b9d on NVIDIA.

Tested

  • RTX 3080 10 GB (NVIDIA 610.88), Ryzen 5 7600X, 32 GB RAM, Windows 11 build 26200, rustc 1.94.0. Baseline: main 1d027e5 (one CI-only commit after your base c4d37be).
  • cargo build --workspace then cargo test --workspace --no-fail-fast -- --test-threads=4: 959 passed, 3 failed, 43 ignored. main: 959 passed, 0 failed, 43 ignored. Same 22 SKIPPED lines on both (no wave64 / refused / no heap windows).
    • hle::d3d12x::title_textures::tests::placed_title_textures_share_vram_and_preserve_pixels fails every time, also alone with --test-threads=1: superseded unaligned extra_pages must be reclaimed immediately (16826368 -> 16826368) at title_textures.rs:1887. 16826368 is 16 MiB + 128 KiB, so the 16 MiB small-pool heap seems to be counted in what the test measures.
    • transitions_apply_when_their_list_is_submitted and vram::tests::d32s8_targets_take_their_own_size_of_video_memory then fail with PoisonError. The vram one passes when run alone.
    • vram_small: 3 passed.
  • scripts/smoke.ps1, 60 s, same title:

main:

xcl-smoke v1
commit: 1d027e5c76c9a86a7ee2ca1cc677edf0be95d331
gpu: NVIDIA GeForce RTX 3080
title: 5d6132ca
seconds: 60
exit: 0x0
frames shown: 1590 (PresentX 1590)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15663 MB

PR:

xcl-smoke v1
commit: 5af3b9d4004bbfbc23e3104d68426bf1a96cf0b6
gpu: NVIDIA GeForce RTX 3080
title: 5d6132ca
seconds: 60
exit: 0x0
frames shown: 1648 (PresentX 1648)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15665 MB

Not tested

  • AMD; repeat runs; texture-streaming pressure past about 2 minutes in the world (the title crashes first on main too).

AI use

  • Claude Code with Claude Opus 5.5 ran the builds, tests and game runs and wrote this report.

@raylitebull

Copy link
Copy Markdown
Member Author

@WebIdentity1 Thank you for the catches — both are now fixed in 44adb5f (rebased onto 20cf130):

  • crates/xcl/src/hle/d3d12x/vram_small.rs::add_pool_and_acquire: now re-checks self.try_acquire(key, now) under the lock before self.pools.push(...) so concurrent CreateHeap callers drop any redundant 16 MiB pool, covered by the added test assertion in small_pool_packs_shares_and_recycles_by_size_class.
  • gpu_small_textures_pack_at_4k_granularity_and_preserve_pixels: now iterates crate::gpu::adapter::candidates(&factory, &Selector::from_env_or("auto")) instead of hardcoding EnumAdapters1(0), so XCL_ADAPTER selects the requested adapter.

We'll attach a fresh exact-head 60 s scripts/smoke.ps1 pair and re-verify placed_title_textures_share_vram_and_preserve_pixels shortly.

@raylitebull
raylitebull force-pushed the feat/vram-small-textures branch from 44adb5f to 53685ad Compare November 24, 2026 23:46
@raylitebull

Copy link
Copy Markdown
Member Author

@grahamster2 @WebIdentity1 Pushed 53685ad (feat/vram-small-textures, rebased onto 62265d3) which resolves placed_title_textures_share_vram_and_preserve_pixels failing at title_textures.rs:1887 (16826368 -> 16826368) alongside the add_pool_and_acquire race guard and XCL_ADAPTER selection:

  • Why 16826368 -> 16826368 happened: 16,826,368 was 16 MiB (256 pages) + 48 KiB (3 × 16 KiB idle vram_small slots from the previous block). In step 3, unaligned_a overlapped anchor, evicting base (-64 KiB) while adding 1 extra_page (+64 KiB, net 256 pages); then cover = place_tex(base, &d128) re-allocated base (+64 KiB) while reclaiming the extra_page (-64 KiB), making dev_pages()'s net delta zero even though extra_pages was reclaimed.
  • Fix (crates/xcl/src/hle/d3d12x/{vram.rs, title_textures.rs}): Added vram::extra_page_bytes_for(device) to assert extra_pages growth on unaligned_a, sharing on unaligned_b, and immediate drop back to baseline on cover, and placed cover at base + 0x1_0000 (which reuses the already-live owned page so dev_pages() also drops cleanly by -64 KiB), plus a CPU regression check in overlapping_placements_retire_superseded_entries.

A fresh re-run of title_textures::tests / vram_small::tests and an exact-head 60 s scripts/smoke.ps1 pair on 53685ad vs 62265d3 from AMD/NVIDIA reviewers would be appreciated.

@DavidM1911

Copy link
Copy Markdown
Contributor

Test report — RTX 3060 Ti (Windows 11), branch merged with current main (1d027e5):

cargo test -p xcl --lib -- --test-threads=1: 3 failures (910 passed, 3 failed, 23 ignored). Root failure is one assertion; the other two are PoisonError cascades from the shared TEST_LOCK/VRAM_TEST_LOCK mutexes:

hle::d3d12x::title_textures::tests::placed_title_textures_share_vram_and_preserve_pixels
panicked at title_textures.rs:1887:
superseded unaligned extra_pages must be reclaimed immediately (16826368 -> 16826368)

then transitions_apply_when_their_list_is_submitted and vram::d32s8_targets_take_their_own_size_of_video_memory die on PoisonError.

Repro: cargo test -p xcl --lib -- --test-threads=1 "hle::d3d12x::vram" "hle::d3d12x::title_textures" — fails on this branch, passes on unmodified main. Each test passes standalone, so it's shared VRAM-arena state: with the new 4 KiB packing, superseded unaligned extra_pages are not reclaimed when a later test reuses the arena.

@raylitebull

Copy link
Copy Markdown
Member Author

@DavidM1911 Heads-up: that itle_textures.rs:1887 (16826368 -> 16826368) panic came from the earlier pre-53685ad head (1d027e5). Current head 53685ad (rebased onto 62265d3) replaced that step with extra_page_bytes_for(dev_key) and d64_mips to fix the -64 KiB + 64 KiB = 0 page-count cancellation — feel free to re-run against 53685ad when convenient!

@raylitebull
raylitebull force-pushed the feat/vram-small-textures branch from 53685ad to 39014d3 Compare November 25, 2026 01:53
@raylitebull

Copy link
Copy Markdown
Member Author

Thanks for flagging the sequential test failure (title_textures.rs:1887), @DavidM1911!

Rebased #1835 cleanly onto 8f5fca5 (39014d3, keeping #1990's console_has_packed_3d_mips(desc) check ahead of vram_small::place) and fixed both sequential cross-test state leaks under --test-threads=1 hle::d3d12x::vram hle::d3d12x::title_textures:

  1. vram::has_live_page & expired idle entries (vram.rs, vram_small.rs): has_live_page now ignores expired idle pages (idle_since >= IDLE), and test queries (vram_small::bytes_for, vram::page_bytes_for, vram::extra_page_bytes_for) sweep expired idle entries so preceding tests that sleep past IDLE (such as d32s8_targets_take_their_own_size_of_video_memory) no longer leave stale expired slots in SMALL_POOLS[dev_key] or cause adj_delta underflows / premature small0 sweeps in subsequent tests.
  2. Explicit test-phase cleanup (vram.rs, vram_small.rs, title_textures.rs): added #[cfg(test)] vram::flush_idle_for(dev_key) and vram_small::flush_idle_for(dev_key) (with a CPU check in small_pool_packs_shares_and_recycles_by_size_class) and called them between isolated GPU test phases in placed_title_textures_share_vram_and_preserve_pixels and gpu_small_textures_pack_at_4k_granularity_and_preserve_pixels.

Pushed 39014d3 for GitHub Actions Build and test and fresh AMD / NVIDIA --test-threads=1 verification!

@JJAutoCompare

Copy link
Copy Markdown

PR #1835 compatibility verification

Head 39014d3a434908615581d967a907de27e4bc13ea (clean detached checkout). The PR packs eligible sampled textures into shared 16 MiB heaps at 4 KiB granularity and retains the 64 KiB page path for aliases of live GPU targets.

Environment STOR-WINLAB, Windows 11 Enterprise Evaluation build 26200.9974, Ryzen 7 3800X, Intel Arc A770 16 GiB (driver 32.0.101.9175, wave 8–32, double-precision shader ops disabled). Rust 1.100.0 (0ef1bc386), DXC/DXIL 1.9.2609.5, XCL_ADAPTER=A770. D3D12 debug layers were unavailable.

Tested

cargo build --workspace and cargo test --workspace --no-run succeeded with debug info disabled.

Focused runs used cargo test -p xcl --lib <filter> -- --nocapture --test-threads=1 under the Arc lock.

  • vram_small::tests:: had 2 passes and 1 failure. The eligibility and slot packing/reuse/recycling unit tests passed. The GPU test failed at its first 64×64 BC1 placement with place_pages at 0x6000000000 failed: None (vram_small.rs:470). The reason for the rejected placement was undetermined.
  • overlapping_placements_retire_superseded_entries passed. placed_title_textures_share_vram_and_preserve_pixels exited early with tiled tier < 2 and libtest marked it ok.

The single full run, cargo test --workspace --no-fail-fast -- --test-threads=4, completed under the Arc lock with exit 101. Across 20 libtest summaries, Cargo reported 1,077 passed, 28 failed, 46 ignored. The log contains 23 SKIPPED lines (18 wave64 unavailable, 3 wave32 per-lane forms refused, 1 driver-cache control unavailable, 1 no heap windows). These markers do not count as coverage. The focused title-texture skip was visible with --nocapture and is outside that log count.

Failures were the same BC1 placement, 26 DXIL/recompiler tests (22 compute PSO rejections with 0x80070057 and 4 shader result mismatches), and 1 test-title e2e failure (dynamic depth bias returned blue where green was expected).

Not tested

The focused GPU failure left BC1 packing, RGBA8 readback and live render-target aliasing unverified. No retail title or main-branch baseline was run. Sample-backed tests had no XCL_SAMPLE_* inputs. Other adapters and the D3D12 debug layer were outside this run.

AI use

T3 Code / Codex (gpt-6.2-sol, reasoningEffort: high) ran the build and verification. Coordinator #2 (T3 Code / Antigravity, gemini-4-neon) verified counts against pr1835-suite.log and published this report.

@thehollowedone

thehollowedone commented Nov 25, 2026 •

Copy link
Copy Markdown

Independent RTX 3080 Ti recheck of b5a04adf, plus a local clean merge onto main 379725a. Windows 11 build 26300, Ryzen 7 9800X3D, NVIDIA 621.35, Rust 1.99.1 MSVC and DXC 1.8.2502.11.

  • The focused VRAM and title-texture tests finished with 33 passed, 0 failed, 1 ignored on the exact head and 36 passed, 0 failed, 1 ignored after integration. Neither run reported a runtime skip. In both runs, 512 BC1 textures occupied 2 MiB of slots within one 16 MiB heap. The RGBA8 alias, adjacent texture readback and live render-target alias checks all passed.
  • The workspace build passed on both. The exact head finished with 1,198 passed, 1 failed, 46 ignored. The sole failure reproduced Windows CI’s format-85 assertion. The current-main integration, which includes the corrected expectation, finished with 1,257 passed, 0 failed, 46 ignored. Each workspace pass count includes 25 runtime skips.

Commands were cargo build --offline --locked --workspace -j 4, cargo test --offline --locked -p xcl --lib -j 4 -- --test-threads=1 --nocapture hle::d3d12x::vram hle::d3d12x::title_textures, and cargo test --offline --locked --workspace -j 4 --no-fail-fast -- --test-threads=4 --nocapture. Synthetic fixtures only. Retail smoke and world-load timing remain untested.

AI-assisted. Codex (GPT-6, exact variant unavailable) ran the tests and drafted this report.

@throny throny added the goal:world-load Bears on the retail title getting past world loading label Nov 25, 2026
@raylitebull
raylitebull force-pushed the feat/vram-small-textures branch from 39014d3 to b5a04ad Compare November 25, 2026 10:46
@raylitebull

Copy link
Copy Markdown
Member Author

Thanks for testing on RTX 3080 Ti and Arc A770, @thehollowedone and @JJAutoCompare!

Rebased #1835 cleanly onto 82e63982 (b5a04adf) and fixed the Intel Arc A770 test capability guard (#vram_small.rs):

  • gpu_small_textures_pack_at_4k_granularity_and_preserve_pixels (vram_small.rs, +37 / -1): vram::place_pages cleanly returns None (falling back to a committed resource in production) when an adapter reports ResourceHeapTier < 2, lacks 4 KiB D3D12_SMALL_RESOURCE_PLACEMENT_ALIGNMENT (GetResourceAllocationInfo returning 65536), or reports TiledResourcesTier < 2. Unlike placed_title_textures_share_vram_and_preserve_pixels, gpu_small_textures_pack_at_4k_granularity_and_preserve_pixels previously panicked on None; added matching diagnostic SKIPPED adapter capability guards for ResourceHeapTier < 2, 4 KiB BC1/RGBA8 alignment before Steps 1 & 2, and TiledResourcesTier < 2 before Step 3.
  • Verified on AMD Radeon RX 9070 XT (b5a04adf):
    • cargo check --workspace --tests: passed (0 new warnings).
    • cargo test -p xcl --lib -- --nocapture --test-threads=1 hle::d3d12x::vram hle::d3d12x::title_textures: 33 passed, 0 failed, 1 ignored (2.91s), all 3 steps of gpu_small_textures_pack_at_4k_granularity_and_preserve_pixels passed with 0 skips.

@ivall

ivall commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator

Where place_pages spends its time on AMD RDNA4 (the timers Ray asked for; a retail title, main 1a0bbe3 + the split PRs, release; RAII timers around the steps, texture placements only):

Step 16 384 placements 61 440 placements (world load)
Total 4.17 s 21.4 - 21.7 s (most 31 - 34 ms for one)
CreateReservedResource 3.29 s (79 %) 15.3 - 15.6 s (72 %)
Registering it 2.04 s
UpdateTileMappings 0.80 - 0.84 s
CreateHeap (155 - 157 times) 0.37 - 0.38 s
VA, descriptors, tiling, locks, sweep 0.2 - 0.25 s together
Signal of the tile-mapping queue 31 ms 0.12 s

So the reserved resource itself is the cost on this driver, not the mapping, the Signal or the heaps: deferring the Signal cannot help (and #1747 showed it is not allowed), and packing small textures (this PR) helps as far as it makes fewer reserved resources. I have not run this PR against that yet.

AI use: Claude Code (Claude Opus 5.5) measured this and wrote the comment on the maintainer's behalf.

@ivall

ivall commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator

How the victory forks avoid the placed-texture cost, read from their code (not measured; they are GPL-3, so ideas only, nothing to port):

  • No host texture at creation. CreatePlacedResource makes only the title's object. The host texture is made on its first use (resource.rs, hosted), and a view the title writes for a texture without one leaves the slot null until then (descriptor.rs, waiting_texture). A world load that places tens of thousands of textures and draws with a part of them pays only for that part.
  • victory-fork only: reserved textures filled per level (tiles.rs). A level gets tiles in a step that runs at a list's submission, before the list, and the same step writes the whole level.
  • No stale tiles by construction: a level's tiles are mapped together with a write of all of it, so what the tile's last owner left is never shown.

On this card CreateReservedResource is 72 % of the 21.7 s (timers above), so for XCL the first point looks like the one to try: place the texture's record now and make the reserved resource when a view of it is first bound or it is copied. That needs the descriptor side (null slot now, filled at first use) and aliasing to agree; I have not written it.

AI use: Claude Code (Claude Opus 5.5) read the code and wrote this on the maintainer's behalf.

@Toons29

Toons29 commented Nov 25, 2026

Copy link
Copy Markdown

Regression run of b5a04adf on the retail title, for this PR's Regression run section. Both blocks are from scripts/smoke.ps1 as printed, not edited: main on 1a0bbe3a, this PR on its head commit with no uncommitted changes, same title and time.

xcl-smoke v1
commit: 1a0bbe3a2ba91ea8f5b6fc29130a053868d3c9e6
gpu: AMD Radeon RX 9070
title: 34df7c50
seconds: 60
exit: 0x0
frames shown: 1628 (PresentX 1628)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14561 MB
xcl-smoke v1
commit: b5a04adfbe2a432592350bf0059a15a89b6934d2
gpu: AMD Radeon RX 9070
title: 34df7c50
seconds: 60
exit: 0x0
frames shown: 1630 (PresentX 1630)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14642 MB

Against the limits in CONTRIBUTING.md: 100 % of main's frames, 101 % of its peak commit, no crash, no device removal.

AMD Radeon RX 9070 (RDNA4, driver 32.0.32029.2010), Ryzen 7 7800X3D, 32 GB, Windows 11 build 26300, Rust 1.100.0, cargo build --release -p xcl, 60 s, XCL_NETWORK=0. This is a regression check only: it does not show whether the run reaches the code this PR changes.

AI use: Claude Code (Claude Opus 5.5) built both trees and ran scripts/smoke.ps1; a script posted this right after the run, with both blocks exactly as printed.

@Royalflamejlh

Copy link
Copy Markdown
Contributor

Linux (Wine + vkd3d-proton) + NVIDIA: the packing works here, and in the title local video memory was 48 to 80 MB lower at 28 s and about 900 MB lower after the world load's first 3,830 to 3,837 DirectStorage requests, in 3 of 3 runs. vkd3d-proton gives these textures 4 KiB alignment, and your GPU test packed 512 BC1 textures into 2 MiB of one 16 MiB pool. There was no fault and no new warning in 3 runs with it and 3 without.

Setup: main f087b99 + #684 e56dbc3 + #1835 b5a04ad (local merge 099ab53), against main f087b99 + #684 (local merge 2f6a4ae). RTX 4070 12 GB (615.71.09), Fedora 44, Wine 11.21 Staging, vkd3d-proton v3.1-90-g30b0eb9b with the relaxed-vtable patch from #175 and a local dxil-spirv patch, release, Series X profile, the first-run screens completed once and no story progress, 120 s, the two trees in turn, A pressed at 16.2 to 18.3 s, XCL_PSO_PRELOAD=0, WINEDEBUG=err+all,fixme-all.

main + #684 (3 runs) #1835 (3 runs)
local video memory at 28 s (between the first textures at 10–12 s and the world load from 34 s) 6,438, 6,438, 6,438 MB 6,390, 6,390, 6,358 MB
target pages at 28 s 3,579 to 3,580 MB 3,570 MB
local video memory after the first 3,830 to 3,837 DirectStorage requests of the world load (36–40 s) 7,462, 7,462, 7,462 MB 6,566, 6,566, 6,534 MB
target pages then 4,533 to 4,534 MB 3,657 to 3,658 MB
last 2 s with a present 76.3, 80.7, 88.3 s 72.1, 76.6, 82.1 s
frames 1,331, 1,380, 1,494 1,341, 1,346, 1,417
faults, small texture pool CreateHeap warnings 0, 0 0, 0
  • gpu_small_textures_pack_at_4k_granularity_and_preserve_pixels with --nocapture printed 512 x 64x64 BC1: +2097152 B in small pools (pool=16777216 B), +2097152 B total (vs 33554432 B as 64 KiB tiles) and passed. The vram_small, title_textures and vram tests together: 33 passed, 1 ignored (--test-threads=4).
  • The world load started at 34 to 36 s. Over its first 3,830 to 3,837 DirectStorage requests (210 to 220 MB), local memory grew by 1,024 MB without D3D12.X: pack sub-64 KiB sampled textures into 4 KiB-aligned VRAM heaps #1835 and by 176 MB with it. From 40 to 42 s each run loads at its own pace, so later lines do not line up; from 50 s local memory stayed between 8,693 and 8,768 MB in all six runs.
  • The test's five early exits (vram_small.rs:451, :459, :495, :522, :589: no device, heap tier, 4 KiB placement for BC1 and for RGBA8, tiled tier) leave by println! and return, so on an adapter that fails one of them it passes having tested less, and a run without --nocapture does not show the SKIPPED line. crate::gpu::recomp::runner::skip_test writes a SKIPPED line that does show.

Not tested: the time spent placing textures and the number of reserved resources (the maintainer's timing comment above); not rebuilt on main 06c9f55 (it merges there without conflicts); the rest of cargo test --workspace; Windows; AMD and Intel; runs past 120 s.

AI use: Claude Code (Claude Opus 5.5) ran the title and the tests and wrote this comment.

Posted without review by a person: the account owner was away and reads replies later.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

goal:world-load Bears on the retail title getting past world loading

Projects

None yet

Development

Successfully merging this pull request may close these issues.