Repository navigation
D3D12.X: pack sub-64 KiB sampled textures into 4 KiB-aligned VRAM heaps - #1835
raylitebull wants to merge 4 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! |
…TER in small-texture test
… ignore expired idle pages
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 NVIDIA recheck of 39014d3 against the requested 8f5fca5 baseline. Windows 11 build 26300, RTX 3080 Ti / 621.35, Rust 1.99.1 MSVC, debug build. Built both with The new test placed all 512 BC1 textures in 2 MiB of slots within one 16 MiB heap. Same-address RGBA8 aliases returned the expected pixels, and adjacent textures had no crosstalk. The stock shared-VRAM streaming and pixel test passed on both revisions. This run covered synthetic tests with default driver validation. AI-assisted. Codex (GPT-6, exact variant unavailable) ran the tests and drafted this report. |
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 unit tests (small_pool_packs_shares_and_recycles_by_size_class,candidate_filters_large_gpu_owned_and_msaa_textures).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(eliminating cross-test stale expired-idle sweeps under sequential--test-threads=1runs), keeping#1990'sconsole_has_packed_3d_mips(desc)check ahead ofvram_small::place.Tested
rustc 1.99.1 (58cf8f9c3 2026-10-13), rebased cleanly onto8f5fca5(39014d3).39014d3was rebased onto8f5fca5and updated with the cross-test idle sweep fix (flush_idle_for/has_live_page) via pure git during a local test hold; queued for GitHub ActionsBuild and testand AMD / NVIDIA GPU verification (cargo test -p xcl -- --test-threads=1 hle::d3d12x::vram hle::d3d12x::title_textures).53685ad,5af3b9d,44adb5f):53685adpassedcargo check --workspace --tests+ CPU testsvram_small::tests/overlapping_placements_retire_superseded_entries(3/3), and5af3b9d/44adb5fpassede2e(3/3), RTX 3060 smoke (@Anon64), RTX 3080 Ti GPU test (@thehollowedone), and RTX 3090 checks (@WebIdentity1).Regression run
scripts/smoke.ps1pair and GPU tests (--test-threads=1 hle::d3d12x::vram hle::d3d12x::title_textures) on39014d3vs8f5fca5have not been run locally yet. AMD and NVIDIA reviewers are invited to test39014d3vs8f5fca5and post results in the comments.Not tested
cargo check/cargo test/ GPU tests (--test-threads=1 hle::d3d12x::vram hle::d3d12x::title_textures) andscripts/smoke.ps1on rebased head39014d3, Intel GPUs, and Linux/Wine/vkd3d-proton.AI use