Repository navigation
D3D12.X: recycle released reserved sampled textures by description and state - #2436
Conversation
e2cf935 to
bebf2dd
Compare
|
Independent AMD RDNA4 (native wave64) test report on exact head Tested
Regression run (60 s retail-title smoke, (Matched Not tested
AI use
|
Port upstream PR #2436 (by Saintwolf, adapted for #2306 lazy level pages and #2275 multi-queue retirement) onto amd-dev. Streamed sampled textures placed on shared 64 KiB video-memory pages previously called CreateReservedResource and GetResourceTiling on every placement, costing 0.6-1.7 ms per texture on AMD drivers (#1268). Keep a bounded per-device pool (512 idle entries, FIFO eviction, opt-out via XCL_RESERVED_POOL=0) of released reserved sampled textures keyed by exact (D3D12_RESOURCE_DESC, uniform D3D12_RESOURCE_STATES), also caching the #2306 Levels tiling layout so XCL_TEXTURE_LEVEL_PAGES=1 placements skip both CreateReservedResource and GetResourceTiling on reuse. When late_release finishes draining all live GPU queues past a texture's batch, vram::recycle_ready unmaps any still-mapped tiles on the background thread (skipping unmap for lazy textures that had zero mapped levels) and parks the ID3D12Resource for reuse. Fixes #1268. Part of #1833. Assisted-by: Antigravity (Gemini 4 Neon High)
Port upstream PR #1835 (commits 2441d59..5005620) cleanly onto amd-dev with #2436 reserved-texture recycling and #2306 lazy levels. Small sampled textures (< 64 KiB) previously each consumed a full 64 KiB tile plus CreateReservedResource, GetResourceTiling, and UpdateTileMappings overhead. Pack eligible sub-64 KiB sampled textures (when not aliasing an existing live 64 KiB GPU-owned page) into shared 4 KiB-aligned 4 MiB default heaps via CreatePlacedResource in vram_small.rs, reclaiming their 4 KiB slots on release in vram::forget_for_recycle before falling through to reserved-page recycling. Fixes #1835. Assisted-by: Antigravity (Gemini 4 Neon High)
|
|
|
Verification on RTX 3060 Ti (Windows 11), branch merged with current
The lowered program is missing an expected group barrier (or emits one where none is expected). Needs a fix before merge. — Devin |
bmjask
left a comment
There was a problem hiding this comment.
P2: ReservedPool::take at vram.rs:196-204 removes an entry from by_key/live but does not remove or invalidate its matching VecDeque entry in order. Every reuse/repark adds another order entry (:225-227), so a pool below cap accumulates stale entries indefinitely. At cap, a stale entry can match a reparked pointer and evict it by its original rather than current parking time, violating the intended bounded FIFO behavior. The test takes entries only once and misses reuse->repark cycles. Please tombstone/remove by generation on take and add a repeated recycle/repark plus cap-FIFO test.
bebf2dd to
2f92cc8
Compare
|
@bmjask Good catch — fixed in
|
…extures) Integrates xcl-dev#2436 cleanly alongside xcl-dev#2385 (top-mip shedding) and xcl-dev#2474 (foreign-thread release_cleanup). Assisted-by: Antigravity (Gemini 4 Neon)
|
Independent AMD report for Tested
Not tested
AI use Claude Code (Claude Sonnet 5.5) ran the tests and wrote this report. No game files, dumps or shader names are included. |
|
Re-verification on RTX 3060 Ti (Windows 11), new head merged with current
Thanks! — Devin |
luckyteagirl
left a comment
There was a problem hiding this comment.
vram.rs:1177–1185: this returns the same native ID3D12Resource for a new texture without clearing its ID3D12Object private data. If a title sets a custom GUID payload on eligible sampled texture A, releases/drains A into this pool, and creates matching texture B, GetPrivateData on B can return A's payload. SetPrivateDataInterface also retains its attached COM reference until that native object is destroyed or the same GUID is overwritten (Microsoft's lifetime contract), so pooling can carry that ownership across apparent texture lifetimes. The pool key covers description/state, and I do not see setter tracking or a private-data reset on reuse.
Could a resource with application private data be excluded from reuse, or its tracked GUIDs be cleared before it is handed to B? A focused test could tag A with a custom GUID and confirm B behaves like a fresh resource. This is source/API-contract review at exact head 2f92cc841ad65e2dc7e63fea17d227a71e44f16b; I have not run the native reuse fixture or observed a title using custom private data. AI-assisted review with Codex.
2f92cc8 to
bab2f53
Compare
|
@luckyteagirl Good catch — fixed in
|
|
Please keep recycled textures alive through their tile-unmap fence. At Please retain pending textures behind their own unmap fence, then add them to the ready pool or release them after completion. A CPU test with a fake fence can assert that a pending texture stays retained when the pool is full or reuse fails. The current GPU fixture waits for the mapping fence before its final release and leaves this ordering untested. Local result: I tested this head applied to main AI use: Codex (GPT-6) inspected the release and mapping paths, ran the focused tests, and verified the recorded results. Optional temporary Discord for coordinating contributor work, testing, and comparing results. |
|
Follow-up to Prime1997's tile-unmap lifetime review, tested against exact head I tested the attached uncommitted candidate. It keeps the owned resource in a per-device pending FIFO with the mapping queue's fence value, including when the resource was already unmapped by an earlier queued update. The existing late-release worker promotes completed entries to the ready pool; native releases of evicted entries happen outside On Windows 11, RTX 3080 Ti / driver 621.35, Ryzen 7 9800X3D, rustc 1.99.1 MSVC:
No paired clean-tree smoke run, retail title, AMD, or Intel test was done for this local candidate. The diff is a review suggestion for the existing PR, not a merge-readiness claim. Candidate diff against bab2f53diff --git a/crates/xcl/src/hle/d3d12x/late_release.rs b/crates/xcl/src/hle/d3d12x/late_release.rs
index 624d6d77..07b69b7b 100644
--- a/crates/xcl/src/hle/d3d12x/late_release.rs
+++ b/crates/xcl/src/hle/d3d12x/late_release.rs
@@ -107,7 +107,7 @@ pub unsafe fn hold(res: usize) {
std::hint::spin_loop();
drain_known(false);
}
- if HELD.lock().unwrap().as_ref().is_none_or(Held::is_empty) {
+ if HELD.lock().unwrap().as_ref().is_none_or(Held::is_empty) && !super::vram::pending_recycles() {
return;
}
// A thread of its own lets the held ones go: the title may release a resource and then
@@ -125,6 +125,7 @@ pub unsafe fn hold(res: usize) {
/// Release what every queue XCL knows of is past: the title's, the tile-mapping one, the
/// upload ones.
pub unsafe fn drain_known(seal_now: bool) {
+ super::vram::drain_recycled();
if HELD.lock().unwrap().as_ref().is_none_or(Held::is_empty) {
return;
}
@@ -149,6 +150,7 @@ pub unsafe fn drain_known(seal_now: bool) {
let f: unsafe extern "system" fn(*mut c_void) -> u32 = std::mem::transmute(super::real::orig_fn(res as *mut c_void, 2));
f(res as *mut c_void);
}
+ super::vram::drain_recycled();
}
#[cfg(test)]
diff --git a/crates/xcl/src/hle/d3d12x/vram.rs b/crates/xcl/src/hle/d3d12x/vram.rs
index 5c74a150..9b021193 100644
--- a/crates/xcl/src/hle/d3d12x/vram.rs
+++ b/crates/xcl/src/hle/d3d12x/vram.rs
@@ -254,6 +254,25 @@ impl ReservedPool {
}
}
+/// Owns the retired resource until the mapping queue finishes its last tile update.
+struct PendingRecycle {
+ key: ReservedKey,
+ raw: usize,
+ total: u32,
+ mark: u64,
+}
+
+fn promote_pending(pool: &mut ReservedPool, pending: &mut std::collections::VecDeque<PendingRecycle>, completed: u64) -> Vec<usize> {
+ let mut evicted = Vec::new();
+ while pending.front().is_some_and(|item| item.mark <= completed) {
+ let item = pending.pop_front().unwrap();
+ if let Some(old) = pool.push(item.key, item.raw, item.total) {
+ evicted.push(old);
+ }
+ }
+ evicted
+}
+
/// Metadata for a released reserved sampled texture awaiting GPU completion in `late_release`.
#[derive(Clone, Copy)]
pub(super) struct RecycleInfo {
@@ -264,6 +283,32 @@ pub(super) struct RecycleInfo {
}
static PARKING: Mutex<Option<std::collections::HashMap<usize, RecycleInfo>>> = Mutex::new(None);
+static PENDING_RECYCLES: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0);
+
+pub(super) fn pending_recycles() -> bool {
+ PENDING_RECYCLES.load(std::sync::atomic::Ordering::Acquire) != 0
+}
+
+/// Promote finished mapping-queue updates before a resource can be reused or evicted.
+/// Native Releases run outside `PAGES.lock()`.
+pub(super) unsafe fn drain_recycled() {
+ if !pending_recycles() {
+ return;
+ }
+ let mut evicted = Vec::new();
+ {
+ let mut g = PAGES.lock().unwrap();
+ for pages in g.values_mut().flatten() {
+ let before = pages.pending_recycles.len();
+ evicted.extend(promote_pending(&mut pages.reserved_pool, &mut pages.pending_recycles, pages.fence.GetCompletedValue()));
+ PENDING_RECYCLES.fetch_sub(before - pages.pending_recycles.len(), std::sync::atomic::Ordering::Release);
+ }
+ }
+ for old in evicted {
+ let f: unsafe extern "system" fn(*mut c_void) -> u32 = std::mem::transmute(super::real::orig_fn(old as *mut c_void, 2));
+ f(old as *mut c_void);
+ }
+}
pub(super) fn forget_for_recycle(resource: usize, held: bool) -> Option<RecycleInfo> {
let placed = PLACED_TEXTURES.lock().unwrap().as_mut().is_some_and(|textures| textures.remove(&resource));
@@ -283,7 +328,7 @@ pub(super) fn park_recyclable(resource: usize, mut info: RecycleInfo, final_stat
}
/// Called by `late_release` once every live GPU queue is past the batch containing `resource`.
-/// Returns `true` when `resource` was unmapped and parked in the per-device reuse pool (so
+/// Returns `true` when `resource` was retained for later reuse (so
/// `late_release` must not call `Release` on it).
pub(super) unsafe fn recycle_ready(resource: usize) -> bool {
let Some(info) = PARKING.lock().unwrap().as_mut().and_then(|m| m.remove(&resource)) else {
@@ -292,7 +337,7 @@ pub(super) unsafe fn recycle_ready(resource: usize) -> bool {
if !reserved_pool_enabled() {
return false;
}
- let evicted = {
+ {
let mut g = PAGES.lock().unwrap();
let Some(Some(pages)) = g.get_mut(&info.dev_key) else {
return false;
@@ -302,11 +347,8 @@ pub(super) unsafe fn recycle_ready(resource: usize) -> bool {
pages.unmap(res, info.total);
}
}
- pages.reserved_pool.push(info.key, resource, info.total)
- };
- if let Some(old) = evicted {
- let f: unsafe extern "system" fn(*mut c_void) -> u32 = std::mem::transmute(super::real::orig_fn(old as *mut c_void, 2));
- f(old as *mut c_void);
+ pages.pending_recycles.push_back(PendingRecycle { key: info.key, raw: resource, total: info.total, mark: pages.value });
+ PENDING_RECYCLES.fetch_add(1, std::sync::atomic::Ordering::Release);
}
true
}
@@ -781,6 +823,8 @@ struct Pages {
reservable_cache: std::collections::HashMap<(i32, u32), bool>,
/// idle reserved sampled textures kept for reuse by `(desc, state)` (#1268)
reserved_pool: ReservedPool,
+ /// released resources awaiting completion of the tile-mapping queue's last update
+ pending_recycles: std::collections::VecDeque<PendingRecycle>,
/// reusable scratch buffers for `map()`
scratch_heaps: Vec<u32>,
scratch_flags: Vec<D3D12_TILE_RANGE_FLAGS>,
@@ -821,6 +865,7 @@ impl Pages {
waited: std::collections::HashMap::new(),
reservable_cache: std::collections::HashMap::new(),
reserved_pool: ReservedPool::new(RESERVED_POOL_MAX),
+ pending_recycles: std::collections::VecDeque::new(),
scratch_heaps: Vec::new(),
scratch_flags: Vec::new(),
scratch_offsets: Vec::new(),
@@ -2435,6 +2480,31 @@ mod tests {
assert_eq!(disabled.push(k_common, 0x4000, 1), Some(0x4000));
}
+ #[test]
+ fn recycled_texture_stays_owned_until_its_mapping_mark_completes() {
+ let desc = D3D12_RESOURCE_DESC {
+ Dimension: D3D12_RESOURCE_DIMENSION_TEXTURE2D,
+ Width: 256,
+ Height: 256,
+ DepthOrArraySize: 1,
+ MipLevels: 1,
+ Format: windows::Win32::Graphics::Dxgi::Common::DXGI_FORMAT_BC1_UNORM,
+ SampleDesc: windows::Win32::Graphics::Dxgi::Common::DXGI_SAMPLE_DESC { Count: 1, Quality: 0 },
+ ..Default::default()
+ };
+ let key = ReservedKey::from_desc(&desc, D3D12_RESOURCE_STATE_COMMON.0 as u32);
+ let mut pool = ReservedPool::new(1);
+ let mut pending = std::collections::VecDeque::from([PendingRecycle { key, raw: 0x1000, total: 1, mark: 2 }]);
+ assert!(promote_pending(&mut pool, &mut pending, 1).is_empty());
+ assert_eq!(pool.take(&key), None, "the pending resource cannot be reused");
+ assert_eq!(pool.push(key, 0x2000, 1), None);
+ assert_eq!(pool.push(key, 0x3000, 1), Some(0x2000));
+ assert_eq!(pending.len(), 1, "pool pressure cannot evict the pending resource");
+ assert_eq!(promote_pending(&mut pool, &mut pending, 2), vec![0x3000]);
+ assert!(pending.is_empty());
+ assert_eq!(pool.take(&key), Some((0x1000, 1)));
+ }
+
#[test]
fn reserved_pool_repark_tombstones_stale_order_and_preserves_fifo() {
use windows::Win32::Graphics::Dxgi::Common::{DXGI_FORMAT_BC1_UNORM, DXGI_SAMPLE_DESC};
@@ -2529,9 +2599,22 @@ mod tests {
let key = ReservedKey::from_desc(&desc, D3D12_RESOURCE_STATE_COMMON.0 as u32);
let (used1, extra1) = pages.bind(&dev, borrowed, 0x2000_0000, Some(total as u64 * PAGE as u64), total).expect("initial bind");
+ let gate: ID3D12Fence = dev.CreateFence(0, D3D12_FENCE_FLAG_NONE).unwrap();
+ pages.queue.Wait(&gate, 1).unwrap();
pages.unmap(borrowed, total);
pages.release_tiles(used1, extra1, std::time::Instant::now(), false);
- assert_eq!(pages.reserved_pool.push(key, raw, total), None);
+ let mark = pages.value;
+ pages.pending_recycles.push_back(PendingRecycle { key, raw, total, mark });
+ let before_completion = pages.fence.GetCompletedValue();
+ let early = promote_pending(&mut pages.reserved_pool, &mut pages.pending_recycles, before_completion);
+ let early_hit = pages.reserved_pool.take(&key);
+ gate.Signal(1).unwrap();
+ let _ = pages.fence.SetEventOnCompletion(mark, windows::Win32::Foundation::HANDLE::default());
+ assert!(before_completion < mark, "the mapping queue was held behind the gate");
+ assert!(early.is_empty() && early_hit.is_none(), "a pending unmap must not publish the texture");
+ assert_eq!(pages.pending_recycles.len(), 1);
+ assert!(promote_pending(&mut pages.reserved_pool, &mut pages.pending_recycles, pages.fence.GetCompletedValue()).is_empty());
+ assert!(pages.pending_recycles.is_empty());
// Mismatched state does not reuse it.
let wrong_state = ReservedKey::from_desc(&desc, D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE.0 as u32);
@@ -2648,6 +2731,27 @@ mod tests {
drop(ID3D12Resource::from_raw(raw_c));
late_release::drain_known(true);
+ // C may still be held by the mapping queue after its title-side Release.
+ let start = std::time::Instant::now();
+ let pending_mark = loop {
+ late_release::drain_known(true);
+ let g = PAGES.lock().unwrap();
+ let pages = g.get(&(dev.as_raw() as usize)).and_then(Option::as_ref).unwrap();
+ if pages.reserved_pool.live_gen.contains_key(&(raw_c as usize)) {
+ break None;
+ }
+ if let Some(item) = pages.pending_recycles.iter().find(|p| p.raw == raw_c as usize) {
+ break Some((pages.fence.clone(), item.mark));
+ }
+ assert!(start.elapsed() < std::time::Duration::from_secs(5), "C did not reach the recycle queue");
+ drop(g);
+ std::thread::yield_now();
+ };
+ if let Some((fence, mark)) = pending_mark {
+ let _ = fence.SetEventOnCompletion(mark, windows::Win32::Foundation::HANDLE::default());
+ drain_recycled();
+ }
+
let raw_d = place(va).expect("place D");
assert_eq!(raw_d, raw_c, "untagged texture C should still recycle into D");
drop(ID3D12Resource::from_raw(raw_d));AI use: Codex (GPT-6.2 Sol) inspected the ownership path, implemented and checked the local candidate, ran the tests, and drafted this comment. |
|
NVIDIA and AMD full-suite run, to go with the reports above by Prime1997, thehollowedone, since none of them covers AMD. Tested exact head Tested
Not tested
AI use
|
bab2f53 to
3d6e230
Compare
|
@Prime1997 @thehollowedone Fixed in
|
|
Independent RTX 4060 (8 GB) / Windows 11 release verification of PR #2436 updated head Setup
Targeted RTX 4060 release unit & GPU tests (
|
|
Independent AMD report for Tested
Regression run ( No device removal, no crash; 1381 frames vs 1413 on the merge-base (97.7 %), peak commit 16622 MB vs 13754 MB (121 %, under the 125 % limit). The last-3 presents-per-2-s sample of the PR run was Not tested
AI use Claude Code (Claude Sonnet 5.5) ran the tests and drafted this report. No game files, dumps, shader names or retail hashes are included; the title in the |
Port upstream PR xcl-dev#1835 (commits 2441d59..5005620) cleanly onto amd-dev with xcl-dev#2436 reserved-texture recycling and xcl-dev#2306 lazy levels. Small sampled textures (< 64 KiB) previously each consumed a full 64 KiB tile plus CreateReservedResource, GetResourceTiling, and UpdateTileMappings overhead. Pack eligible sub-64 KiB sampled textures (when not aliasing an existing live 64 KiB GPU-owned page) into shared 4 KiB-aligned 4 MiB default heaps via CreatePlacedResource in vram_small.rs, reclaiming their 4 KiB slots on release in vram::forget_for_recycle before falling through to reserved-page recycling. Fixes xcl-dev#1835. Assisted-by: Antigravity (Gemini 4 Neon High) # Conflicts: # crates/xcl/src/hle/d3d12x/title_textures.rs # crates/xcl/src/hle/d3d12x/vram.rs
…d state Streamed sampled textures placed on shared 64 KiB video-memory pages previously called CreateReservedResource and GetResourceTiling on every placement, costing 0.6-1.7 ms per texture on AMD drivers (xcl-dev#1268) and ~111-140 us on NVIDIA. Keep a bounded per-device pool (512 idle entries, FIFO eviction, opt-out via XCL_RESERVED_POOL=0) of released reserved sampled textures keyed by exact (D3D12_RESOURCE_DESC, uniform D3D12_RESOURCE_STATES). When late_release finishes draining all live GPU queues past a texture's batch, vram::recycle_ready unmaps any still-mapped tiles on the background thread and parks the ID3D12Resource for reuse; matching place_pages calls QueryInterface on the pooled object and reuse its cached tile count, skipping CreateReservedResource and GetResourceTiling. Fixes xcl-dev#1268. Part of xcl-dev#1833. Assisted-by: Antigravity (Gemini 4 Neon) # Conflicts: # crates/xcl/src/hle/d3d12x/vram.rs # Conflicts: # crates/xcl/src/hle/d3d12x/late_release.rs # crates/xcl/src/hle/d3d12x/real.rs # crates/xcl/src/hle/d3d12x/title_textures.rs # crates/xcl/src/hle/d3d12x/vram.rs
3d6e230 to
cd1c1d8
Compare
Prime1997
left a comment
There was a problem hiding this comment.
Approving on a merge-check run on an RTX 3060 Ti 8 GB (driver 32.0.16.1714, i5-10400, Windows 11 Pro 26200, Rust 1.100.0).
- Head
cd1c1d8d76ce5f1b93910c28836a293923a8c89bmerged cleanly ontomain7db2f391, and the workspace builds. cargo test --workspace --no-fail-fast -- --test-threads=4, with--skipfor threeuma_drivertests that can end the library harness on this PC on plainmaintoo: 2,596 passed, 0 failed, 49 ignored, 28 SKIPPED (21 of them no wave64).mainwith the same skips: 2,591 passed, 0 failed. All five new tests pass, including the GPU unmap, reuse and remap test.- 60 s
scripts/smoke.ps1withXCL_PREPARE=0: 1,393 frames against 1,385 onmain, peak commit 15,321 MB against 15,626 MB, no device removal, no crash. - Runtime hunks read in full, no blocking finding. A parked texture now stays owned in
pending_recyclesuntil the page queue passes its unmap mark, which answers my earlier comment here about the fence. - Not exercised here: world streaming, where the pool is actually hit. The smoke stays in menus and video.
AI use: Claude Code ran the builds, tests and smoke on Prime's PC and wrote this text. Approving is Prime's decision.
I use a temporary Discord to coordinate my work. Anyone helping test XCL or compare results is welcome. Test coordination on Discord
…d state Port of xcl-dev/xcl PR #2436 (cd1c1d8, merged on main as 7d96cad, by Saintwolf), adapted to amd-dev's vram.rs. Streamed sampled textures placed on shared 64 KiB video-memory pages call CreateReservedResource and GetResourceTiling for every placement (0.6-1.7 ms a texture on AMD drivers, #1268). The retail title places 300 to 950 textures every 2 s in its open world ("925 placed textures in 224 ms"). A bounded per-device pool (512 idle, FIFO eviction) keeps released reserved sampled textures keyed by exact D3D12_RESOURCE_DESC and the uniform state they were left in (title_textures::forget now returns it). When late_release has let the queues pass a texture's batch, vram::recycle_ready unmaps its tiles and parks it behind the tile-mapping queue's fence; a matching place_on_pages takes it with QueryInterface and its cached tile count instead of CreateReservedResource (and GetResourceTiling when its levels do not get pages one by one). Textures that got private data or a name are never reused (SetPrivateData, SetPrivateDataInterface and SetName are hooked for that in real.rs). Differences from the PR: amd-dev's vram::forget keeps its small-texture path and becomes forget_for_recycle; only a texture still mapped at its release is kept (one a superseding placement unmapped may still have that unmap waiting for the queues, unmap_placed); Pages::bind takes the physical pages here. XCL_RESERVED_POOL=0 turns it off; on by default as upstream. Tests: the PR's five tests (pool order and eviction, the mapping mark, GPU reuse and remap, private data excluded). cargo test -p xcl --lib -- d3d12x::vram d3d12x::title_textures d3d12x::texture_upload d3d12x::late_release d3d12x::real: 207 passed, 1 failed, 1 ignored (RX 9070 XT); the failure, real::release_tests::the_last_release_drops_ entries_before_the_object_goes, fails the same way on f33df5a. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> (cherry picked from commit 3765d6119c7d98f686d22a6e4f68b4462570bf60)
…d state Port of xcl-dev/xcl PR #2436 (cd1c1d8, merged on main as 7d96cad, by Saintwolf), adapted to amd-dev's vram.rs. Streamed sampled textures placed on shared 64 KiB video-memory pages call CreateReservedResource and GetResourceTiling for every placement (0.6-1.7 ms a texture on AMD drivers, #1268). The retail title places 300 to 950 textures every 2 s in its open world ("925 placed textures in 224 ms"). A bounded per-device pool (512 idle, FIFO eviction) keeps released reserved sampled textures keyed by exact D3D12_RESOURCE_DESC and the uniform state they were left in (title_textures::forget now returns it). When late_release has let the queues pass a texture's batch, vram::recycle_ready unmaps its tiles and parks it behind the tile-mapping queue's fence; a matching place_on_pages takes it with QueryInterface and its cached tile count instead of CreateReservedResource (and GetResourceTiling when its levels do not get pages one by one). Textures that got private data or a name are never reused (SetPrivateData, SetPrivateDataInterface and SetName are hooked for that in real.rs). Differences from the PR: amd-dev's vram::forget keeps its small-texture path and becomes forget_for_recycle; only a texture still mapped at its release is kept (one a superseding placement unmapped may still have that unmap waiting for the queues, unmap_placed); Pages::bind takes the physical pages here. XCL_RESERVED_POOL=0 turns it off; on by default as upstream. Tests: the PR's five tests (pool order and eviction, the mapping mark, GPU reuse and remap, private data excluded). cargo test -p xcl --lib -- d3d12x::vram d3d12x::title_textures d3d12x::texture_upload d3d12x::late_release d3d12x::real: 207 passed, 1 failed, 1 ignored (RX 9070 XT); the failure, real::release_tests::the_last_release_drops_ entries_before_the_object_goes, fails the same way on f33df5a. (cherry picked from commit 3765d6119c7d98f686d22a6e4f68b4462570bf60)
Recycles released reserved sampled textures in a bounded per-device pool keyed by exact
(D3D12_RESOURCE_DESC, uniform D3D12_RESOURCE_STATES)so streamed texture placements skipCreateReservedResourceandGetResourceTiling. Fixes #1268. Part of #1833.What is in it
crates/xcl/src/hle/d3d12x/title_textures.rs:forget(res)returns the removed texture's last tracked uniformD3D12_RESOURCE_STATESwhen all subresources share a single state (states.len() == 1), orNonefor mixed-state / untracked textures.crates/xcl/src/hle/d3d12x/real.rs: hooksSetPrivateData,SetPrivateDataInterface, andSetNameonKind::Resourceto track resources with application private data or debug names; on finalRelease(n == 0) whilelate_releaseholds the last PC ref, parks eligible untaggedplace_pagessampled textures with their actual uniform D3D12 state (excluding any resource with private data so custom GUID payloads andSetPrivateDataInterfaceCOM references never leak across lifetimes); exposesnote_reservedso reused pointers re-register inRESERVED.crates/xcl/src/hle/d3d12x/late_release.rs: once every live GPU queue is past a batch's fence, hands parked textures tovram::recycle_readyinstead of destroying them; callsvram::drain_recycled()indrain_knownand keeps the worker started whilevram::pending_recycles()is non-empty.crates/xcl/src/hle/d3d12x/vram.rs: addsReservedKey, a per-devicepending_recyclesfence-gated staging FIFO (PendingRecycle), and a bounded per-deviceReservedPool(512idle entries/device, generation-tombstoned FIFO eviction with boundedordercompaction, evicted entries dropped outsidePAGES.lock(), opt-out viaXCL_RESERVED_POOL=0).recycle_readyunmaps any still-mapped tiles (pages.unmap) and stages the texture withpages.valueso it stays owned until the tile-mapping queue passes that fence mark beforedrain_recycled()promotes it intoReservedPool.place_on_pagespops matching pooled reserved textures viaQueryInterfaceand reuses their cached tile count, skippingCreateReservedResourceandGetResourceTiling. Adds unit tests (reuse hit, state isolation, FIFO eviction, cap=0, repeated take/repark tombstoning + cap-FIFO ordering, pending-mark retention) and GPU tests (fence-gated unmap/recycle/rebind, private-data exclusion).Tested
32.0.16.2140), AMD Ryzen 7 7800X3D,rustc 1.100.0 (0ef1bc386 2026-11-09), DXC/DXIL1.8.2502.11.main(beeb81be) ascd1c1d8d:cargo test -p xcl --lib hle::d3d12x::vram:: -- --test-threads=1: 69 passed, 0 failed, 1 ignored (includingreserved_pool_reuses_matching_key_isolates_state_and_evicts_fifo,recycled_texture_stays_owned_until_its_mapping_mark_completes,reserved_pool_repark_tombstones_stale_order_and_preserves_fifo,reserved_resource_recycle_unmaps_reuses_and_remaps_on_gpu, andreserved_resource_with_private_data_is_excluded_from_recycle).cargo test -p xcl --lib hle::d3d12x::late_release:: -- --test-threads=1: 4 passed, 0 failed.#1268microbenchmark on RTX 4070 SUPER (release,2,000iterations each):256x256 BC1 (9 mips):CreateReservedResource + GetResourceTiling + Release222.33 ms (111.17 µs/tex) → recycled pool 0.04 ms (0.019 µs/tex) (5,730× faster).1024x1024 BC7 (11 mips): 279.58 ms (139.79 µs/tex) → recycled pool 0.04 ms (0.019 µs/tex) (7,262× faster).XCL_DIRECT_DXIL=1,XCL_PSO_WAIT_MS=50,XCL_PRESS_A_AT=15,20,25,30,35,40,45, isolated caches):XCL_RESERVED_POOL=1cleanly recycled 32+ streamed reserved textures live before both arms hit the same pre-existingxboxbvhbuilder.dll40-bit VA exception (~112–116 s), with0device removals and-352 MBlower peak commit (28,903 MBvs29,255 MB).Regression run
Not tested
0.62–1.70 msper-textureCreateReservedResourcestall from D3D12.X: CreateReservedResource for each streamed title texture costs ~1 ms on AMD and stalls the title's render thread during world loading #1268 was measured on AMD RDNA2 and should see the largest streaming speedup there).xboxbvhbuilder.dll40-bit VA exception).AI use