Repository navigation
D3D12.X: pack sub-64 KiB sampled textures into 4 KiB-aligned VRAM heaps - #1835
raylitebull wants to merge 5 commits into
Conversation
|
Regression run for this PR: head main this PR: 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. |
|
I tested exact head Tested
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 5af3b9ddiff --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; |
|
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.
AI-assisted. Codex (GPT-6 family, exact variant unavailable) extended and ran the test and drafted this report. |
|
@thehollowedone Thank you for the RTX 3080 Ti verification of the live-page coexistence guard and 4 KiB aliasing behavior on @WebIdentity1 Thank you as well for testing
We'll follow up with that small guard + regression test shortly (and refresh the smoke run for the updated head when pushed). |
|
Test report for 5af3b9d on NVIDIA. Tested
main: PR:
Not tested
AI use
|
5af3b9d to
44adb5f
Compare
|
@WebIdentity1 Thank you for the catches — both are now fixed in
We'll attach a fresh exact-head 60 s |
44adb5f to
53685ad
Compare
|
@grahamster2 @WebIdentity1 Pushed
A fresh re-run of |
|
Test report — RTX 3060 Ti (Windows 11), branch merged with current
then Repro: |
|
@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! |
53685ad to
39014d3
Compare
|
Thanks for flagging the sequential test failure ( Rebased
Pushed |
PR #1835 compatibility verificationHead 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 ( Tested
Focused runs used
The single full run, Failures were the same BC1 placement, 26 DXIL/recompiler tests (22 compute PSO rejections with 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 AI use T3 Code / Codex ( |
|
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.
Commands were AI-assisted. Codex (GPT-6, exact variant unavailable) ran the tests and drafted this report. |
…TER in small-texture test
… ignore expired idle pages
…ll-texture GPU test
39014d3 to
b5a04ad
Compare
|
Thanks for testing on RTX 3080 Ti and Arc A770, Rebased
|
|
Where
So the reserved resource itself is the cost on this driver, not the mapping, the AI use: Claude Code (Claude Opus 5.5) measured this and wrote the comment on the maintainer's behalf. |
|
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):
On this card AI use: Claude Code (Claude Opus 5.5) read the code and wrote this on the maintainer's behalf. |
|
Regression run of Against the limits in CONTRIBUTING.md: 100 % of AMD Radeon RX 9070 (RDNA4, driver 32.0.32029.2010), Ryzen 7 7800X3D, 32 GB, Windows 11 build 26300, Rust 1.100.0, AI use: Claude Code (Claude Opus 5.5) built both trees and ran |
|
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:
Not tested: the time spent placing textures and the number of reserved resources (the maintainer's timing comment above); not rebuilt on 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. |
Packs sub-64 KiB single-sample non-RT/DS sampled textures into shared 16 MiB
D3D12_HEAP_TYPE_DEFAULTheaps 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 —
TitleHoldwas 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: addSmallPoolsallocator (UNIT = 4 KiB,POOL_UNITS = 4096/ 16 MiB heaps,XCL_VRAM_SMALL=0opt-out) with(va, units)alias sharing, size-class slot recycling afterIDLE + COOL,CreateHeap/CreatePlacedResourceoutside locks (re-checkingtry_acquireunder the lock insideadd_pool_and_acquire),vram_small::flush_idle_for(dev_key)for test isolation, adapter selection viagpu::adapter::candidatesforXCL_ADAPTER, and capability-gated GPU testgpu_small_textures_pack_at_4k_granularity_and_preserve_pixels(skipping steps cleanly with diagnosticSKIPPEDmessages when an adapter lacksResourceHeapTier >= 2, 4 KiBD3D12_SMALL_RESOURCE_PLACEMENT_ALIGNMENT, orTiledResourcesTier >= 2).crates/xcl/src/hle/d3d12x/vram.rs: ignore expired idle pages inhas_live_page, sweep expired idle entries invram_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 inforget.crates/xcl/src/hle/d3d12x/title_textures.rs: update the 4 KiB adjacent-placement assertions and addflush_idle_for(dev_key)calls between isolated GPU test phases inplaced_title_textures_share_vram_and_preserve_pixelsandgpu_small_textures_pack_at_4k_granularity_and_preserve_pixels, keeping#1990'sconsole_has_packed_3d_mips(desc)check ahead ofvram_small::place.Tested
10.0.22631.0),rustc 1.99.1 (58cf8f9c3 2026-10-13), rebased cleanly onto82e63982(b5a04adf).b5a04adf:cargo check --workspace --testspassed (0new 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 ofgpu_small_textures_pack_at_4k_granularity_and_preserve_pixels(0skips:512 x 64x64 BC1in+2,097,152 Binside one16 MiBheap, hardware RGBA8 alias/crosstalk readback, and live RTvram::Pagesalias).39014d3passed RTX 3080 Ti (27/0,@thehollowedone), and5af3b9d/44adb5fpassed RTX 3060 smoke (@Anon64) and RTX 3090 (@WebIdentity1).Regression run
scripts/smoke.ps1pair onb5a04adfvs82e63982has not been run yet. AMD and NVIDIA reviewers (and Intel Arc A770 verification of the new adapter capability checks ingpu_small_textures_pack_at_4k_granularity_and_preserve_pixels) are invited to run tests/scripts/smoke.ps1and post results in the comments.Not tested
scripts/smoke.ps1pair and fullcargo test --workspacesuite onb5a04adfvs82e63982, Intel Arc A770 re-run onb5a04adf, and Linux/Wine/vkd3d-proton.AI use