Repository navigation
Conversation
|
merge-check AI-written and posted by Foniass without a human check of each point. |
|
merge-check claim |
|
merge-check |
|
In the world with #3617 and residency priority on current AI use: Claude Code (Claude Opus 5.5). |
|
Follow-up on exact head I added a synthetic regression to the unchanged head. It failed because the failed hot-tile allocation caused the adjacent cold tile to remain The change tracks failure separately for video and system-memory allocation, so failure in one pool does not suppress an attempt from the other. If both the L0 request and its video fallback fail, it preserves the existing NVIDIA GeForce RTX 3080 Ti (driver 621.40), AMD Ryzen 7 9800X3D, Windows 11 build 26300, rustc 1.99.1. Candidate diffdiff --git a/crates/xcl/src/hle/d3d12x/sparse.rs b/crates/xcl/src/hle/d3d12x/sparse.rs
index f31636e5..c0958fa9 100644
--- a/crates/xcl/src/hle/d3d12x/sparse.rs
+++ b/crates/xcl/src/hle/d3d12x/sparse.rs
@@ -3970,13 +3970,15 @@ impl State {
let end = a.saturating_add(n);
let mut t = a & !(TILE - 1);
let (mut got, mut left) = (0, 0);
+ let (mut video_failed, mut sys_failed) = (false, false);
while t < end {
if self.mapped.get(&t).is_some_and(|e| e.pool == LAZY) {
let at_hand = !self.free.is_empty() || cooled(&self.cooling, std::time::Instant::now()) || !self.retired.is_empty();
// (short of video memory: a tile of the system-memory pools does not wait for it)
let sys = sysmem_tiles() && !is_hot(t);
- let wait = left > 0 || (!force && !sys && self.short_of_memory() && !at_hand);
- match if wait { None } else { self.take_tile_for(t) } {
+ let wait = if sys { sys_failed } else { video_failed }
+ || (!force && !sys && self.short_of_memory() && !at_hand);
+ match if wait { None } else if sys { self.take_sys_tile() } else { self.take_tile() } {
@@ -3988,9 +3990,13 @@ impl State {
got += 1;
}
None => {
if !wait {
+ // `take_sys_tile` falls back to video memory if an L0 heap
+ // cannot be made; if that fallback also fails, retain the
+ // existing video-memory retry backoff.
self.no_memory = Some(std::time::Instant::now());
+ if sys { sys_failed = true; } else { video_failed = true; }
}
left += 1;
}
@@ -11602,6 +11608,44 @@ mod tests {
drop(lazy);
}
+ /// A failed video-memory allocation for a hot tile does not skip the next cold tile, which
+ /// can still be backed by the system-memory pool.
+ #[test]
+ fn a_hot_tile_without_video_memory_does_not_block_a_cold_system_memory_tile() {
+ let lazy = Lazy::on(true);
+ lazy.sysmem(true);
+ unsafe {
+ let Some((base, mut s, queue)) = lazy_state(3) else { return crate::gpu::recomp::runner::skip_test("no GPU with tiled resources tier 2") };
+ let probe = base + 2 * TILE;
+ s.ensure_mapped(probe, TILE, |_| (0, 0));
+ if !s.mapped.get(&probe).is_some_and(|entry| entry.pool != LAZY && entry.pool.0 & SYS != 0) {
+ return crate::gpu::recomp::runner::skip_test("no system-memory pool heap");
+ }
+ s.commit_range(base, 2 * TILE);
+ assert_eq!(s.mapped[&base].pool, LAZY);
+ assert_eq!(s.mapped[&(base + TILE)].pool, LAZY);
+
+ struct ForgetHot(usize);
+ impl Drop for ForgetHot {
+ fn drop(&mut self) { forget_hot(self.0); }
+ }
+ note_hot(base, TILE);
+ let _hot = ForgetHot(base);
+
+ lazy.no_tiles(true);
+ s.give_memory(&[(base, 2 * TILE)]);
+ assert_eq!(s.mapped[&base].pool, LAZY, "the hot tile had no video memory");
+ assert_ne!(s.mapped[&(base + TILE)].pool, LAZY, "the cold tile still got a pool tile");
+ assert_ne!(s.mapped[&(base + TILE)].pool.0 & SYS, 0, "the cold tile used system memory");
+
+ let dirty = write_tile(base + TILE, 17);
+ s.before_execute_on(&queue, &dirty, PAGE);
+ let cpu = std::slice::from_raw_parts((base + TILE) as *const u8, TILE).to_vec();
+ assert_eq!(window_bytes(&mut s, base + TILE, TILE), cpu, "the CPU bytes reached the GPU through the system-memory tile");
+ }
+ drop(lazy);
+ }AI use: OpenAI Codex (GPT-6.2 Sol) prepared and tested this candidate. |
bmjask
left a comment
There was a problem hiding this comment.
Review of 24a84ca3: 4 finding(s) (4 medium), most severe first.
- Medium
crates/xcl/src/hle/d3d12x/sparse.rs:11598:LAZYis (u32::MAX, u32::MAX), which has the SYS bit set. (inline) - Medium
crates/xcl/src/hle/d3d12x/sparse.rs:3658: Only the XCL_COHERENT_HEAPS=sparse heaps are marked hot, so every other GPU-critical sparse allocation goes to system memory under the flag: XMemAllocDefault graphics memory and MEM_GRAPHICS VirtualAlloc (kernelx.rs:967 and 1432), consol.... (inline) - Medium
crates/xcl/src/hle/d3d12x/sparse.rs:4035: The swap from a system-memory tile to a video tile at a GPU-heap address only checksparked, so a SYS tile held inkeptat that address is taken back as-is by.or_else(|| self.kept.remove(&t)). (inline) - Medium
crates/xcl/src/hle/d3d12x/sparse.rs:549: Not certain about this one: SYS_POOLS is a process-global static, but the video pools, the fence and the quarantine live in State, whichsparse::initreplaces, so the system-memory pools outlive the State whose tiles and fence values t.... (inline)
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.
| assert_eq!(s.mapped[&base].pool, LAZY); | ||
| let dirty = write_tile(base, 11); | ||
| s.before_execute_on(&queue, &dirty, PAGE); | ||
| assert_ne!(s.mapped[&base].pool.0 & SYS, 0, "its first bytes gave it a system-memory tile"); |
There was a problem hiding this comment.
Medium: LAZY is (u32::MAX, u32::MAX), which has the SYS bit set. So a LAZY handle that reaches pool_heap or cool is routed to SYS_POOLS with index 0x7FFFFFFF, an out-of-bounds panic where it used to hit the existing "live pool" check. In the test, assert_ne!(pool.0 & SYS, 0, ...) also passes even when the tile never got memory. Checking for LAZY before the SYS test (in pool_heap, cool and the test) would avoid both.
| /// A pool tile for window tile `t`: from the system-memory pools under `XCL_SPARSE_SYSMEM` | ||
| /// unless `t` is in a GPU heap of the title. | ||
| unsafe fn take_tile_for(&mut self, t: usize) -> Option<((u32, u32), bool)> { | ||
| if sysmem_tiles() && !is_hot(t) { self.take_sys_tile() } else { self.take_tile() } |
There was a problem hiding this comment.
Medium: Only the XCL_COHERENT_HEAPS=sparse heaps are marked hot, so every other GPU-critical sparse allocation goes to system memory under the flag: XMemAllocDefault graphics memory and MEM_GRAPHICS VirtualAlloc (kernelx.rs:967 and 1432), console descriptor tables (console_heap.rs:869 via alloc_in), and command-list scratch (console_list.rs:662, bind.rs:4978). With XCL_SPARSE_SYSMEM=1, a title's XMemAlloc render targets and textures, and the descriptor tables shaders read every draw, get L0 tiles and are read and written over PCIe. The flag is described as moving only tiles outside the title's GPU heaps, so marking those allocations hot too would match the description.
| // a tile parked here from before is in system memory and a GPU heap of the title | ||
| // is here now: a video-memory tile takes its place, mapped over it at once, and it | ||
| // goes once the GPU is past that (one a placed buffer uses stays; none found: it stays) | ||
| let swap = self.parked.get(&t).is_some_and(|tile| tile.0 & SYS != 0 && !self.pinned.contains_key(tile)) && is_hot(t); |
There was a problem hiding this comment.
Medium: The swap from a system-memory tile to a video tile at a GPU-heap address only checks parked, so a SYS tile held in kept at that address is taken back as-is by .or_else(|| self.kept.remove(&t)). With XCL_SPARSE_SYSMEM=1 plus XCL_VIEW_KEEP or a placed buffer's kept tile, a non-hot reservation leaves a SYS tile in kept. If the address is then reused for a title GPU heap (alloc_as(.., true)), ensure_mapped finds the tile in kept, swap is false, and the GPU heap's tile stays in system memory.
| // D3D12 heaps are free-threaded | ||
| unsafe impl Send for SysPools {} | ||
|
|
||
| static SYS_POOLS: Mutex<Option<SysPools>> = Mutex::new(None); |
There was a problem hiding this comment.
Medium: Not certain about this one: SYS_POOLS is a process-global static, but the video pools, the fence and the quarantine live in State, which sparse::init replaces, so the system-memory pools outlive the State whose tiles and fence values they track. If sparse::init runs again (two first real::init calls, or crates/xcl/tests/sparse_reinit.rs), the old State's mapped, parked and quarantined SYS tiles are dropped without being cooled, so SYS_POOLS counts them in use forever and those heaps never retire. Retired heaps also keep fence marks from the old fence, compared against a new one that restarts at 0, and heaps made on the old device can be handed to the new State's UpdateTileMappings. Keeping the sys pools inside State would tie their lifetime to it.
|
@Prime1997 could you take a look at this one for review and merge? My automated review notes are above, if any. |
|
Linux / AMD RDNA4 (RADV, Wine + vkd3d-proton): full test suite on Merged onto Setup
Tested:
About the failures on
|
|
merge-check Windows / AMD RDNA4 (native D3D12) — workspace suite and sparse heap checks on Clean merge onto Setup
Tested
Counts are partial because two test processes aborted on each build.
Shared failures and process aborts
Retail smoke Ran
The enabled run logged seven pool-allocation milestones, up to 256 MiB of system-memory pool heaps. It ended before retail heap reclamation could be measured. Diff review Read the full diff and confirmed the existing mixed-range concern in Not tested Tests after the aborts, retail pool reclamation, frame performance, and allocation behavior under forced VRAM pressure. AI use Codex (GPT-6) merged and built the PR, ran the tests and smoke checks, compared the results with the prior |
|
Following up on the retry reported above, we tested Video-memory fallback succeeded for both tiles, and each received a distinct slot. The only assertion that failed was the request count: expected one, observed two. This was a synthetic allocator test. No title was run. |
|
On For two consecutive cold The candidate checks reusable tiles and retired system heaps before suppressing another creation attempt. The refusal expires when The production patch applies independently to 1. Original regressiondiff --git a/crates/xcl/src/hle/d3d12x/sparse.rs b/crates/xcl/src/hle/d3d12x/sparse.rs
index f31636e5e4edacbadb0f00646fa79aade29aca6f..6654aa545fa3658f3f5da5cdf47b464369c74e41 100644
--- a/crates/xcl/src/hle/d3d12x/sparse.rs
+++ b/crates/xcl/src/hle/d3d12x/sparse.rs
@@ -3615,7 +3615,12 @@ impl State {
/// `take_tile` from the system-memory pools (`XCL_SPARSE_SYSMEM`).
unsafe fn take_sys_tile(&mut self) -> Option<((u32, u32), bool)> {
self.drain_quarantined();
- let mut g = SYS_POOLS.lock().unwrap();
+ let pools = &SYS_POOLS;
+ #[cfg(test)]
+ let refusal = tests::SYS_HEAP_REFUSAL.with_borrow(Clone::clone);
+ #[cfg(test)]
+ let pools = refusal.as_ref().map_or(pools, |r| &r.pools);
+ let mut g = pools.lock().unwrap();
let p = g.get_or_insert_with(SysPools::default);
if let Some((h, t)) = reuse_tile(&mut p.free, &mut p.cooling, std::time::Instant::now()) {
return Some(((SYS | h, t), true));
@@ -3637,7 +3642,14 @@ impl State {
Flags: D3D12_HEAP_FLAG_DENY_RT_DS_TEXTURES | D3D12_HEAP_FLAG_DENY_NON_RT_DS_TEXTURES,
};
let mut heap: Option<ID3D12Heap> = None;
- if let Err(e) = super::title_textures::own_work(|| self.dev.CreateHeap(&desc, &mut heap)) {
+ if let Err(e) = super::title_textures::own_work(|| {
+ #[cfg(test)]
+ if let Some(r) = &refusal {
+ r.requests.borrow_mut().push(desc.SizeInBytes);
+ return Err(windows::Win32::Foundation::E_OUTOFMEMORY.into());
+ }
+ self.dev.CreateHeap(&desc, &mut heap)
+ }) {
crate::xlog_warn!("sparse windows: no system-memory pool heap ({e}) - video memory instead");
drop(g);
return self.take_tile();
@@ -8650,7 +8662,16 @@ fn forget_in(s: &mut State, res: usize) {
mod tests {
use super::*;
+ #[derive(Default)]
+ pub(super) struct SysHeapRefusal {
+ // Start empty even when another test has reusable system-memory tiles.
+ pub(super) pools: Mutex<Option<SysPools>>,
+ pub(super) requests: std::cell::RefCell<Vec<u64>>,
+ }
+
thread_local! {
+ pub(super) static SYS_HEAP_REFUSAL: std::cell::RefCell<Option<std::rc::Rc<SysHeapRefusal>>> =
+ const { std::cell::RefCell::new(None) };
/// The VirtualQuery calls `source_holes` made on this thread.
pub(super) static VIRTUAL_QUERIES: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
/// Run by `take_asks` on this thread between the look up of the asked tiles' pairs and
@@ -11500,6 +11521,7 @@ mod tests {
LAZY_COMMITS_FOR_TEST.with(|c| c.set(None));
NO_TILES.with(|c| c.set(false));
SYSMEM_FOR_TEST.with(|c| c.set(false));
+ SYS_HEAP_REFUSAL.with_borrow_mut(|r| *r = None);
}
}
@@ -11578,6 +11600,42 @@ mod tests {
drop(lazy);
}
+ #[test]
+ fn one_materialize_call_only_requests_a_refused_system_heap_once() {
+ let lazy = Lazy::on(true);
+ lazy.sysmem(true);
+ unsafe {
+ let Some((base, mut s, _queue)) = lazy_state(2) else {
+ return crate::gpu::recomp::runner::skip_test("no GPU with tiled resources tier 2");
+ };
+ let tiles = [base, base + TILE];
+ s.commit_range(base, tiles.len() * TILE);
+ assert!(tiles.iter().all(|t| s.mapped[t].pool == LAZY && !is_hot(*t)));
+
+ let ((video_heap, _), _) = s.take_tile().expect("seed the video fallback heap");
+ assert!(s.free.heap_len(video_heap as usize) >= tiles.len());
+ let heap = s.pools[video_heap as usize].as_ref().expect("live video heap");
+ assert_eq!(heap.GetDesc().Properties.Type, D3D12_HEAP_TYPE_DEFAULT);
+
+ let refusal = std::rc::Rc::new(SysHeapRefusal::default());
+ SYS_HEAP_REFUSAL.with_borrow_mut(|r| *r = Some(refusal.clone()));
+ let (got, left) = s.materialize(base, tiles.len() * TILE, false, &mut Vec::new());
+ let backing = tiles.map(|t| s.mapped[&t].pool);
+ let requests = refusal.requests.borrow();
+ let luid = s.dev.GetAdapterLuid();
+ eprintln!("L0 fallback: requested_bytes={requests:?} attempts={} materialized={got} left={left} \
+ video_heap={video_heap} tile_backing={backing:?} adapter_luid={:08x}:{:08x}",
+ requests.len(), luid.HighPart as u32, luid.LowPart);
+ drop(s);
+ assert_ne!(VirtualFree(base as *mut c_void, 0, windows_sys::Win32::System::Memory::MEM_RELEASE), 0);
+ assert_eq!((got, left), (tiles.len(), 0));
+ assert!(backing.iter().all(|&(h, t)| h == video_heap && t < POOL_TILES));
+ assert_ne!(backing[0], backing[1], "the tiles need distinct video backing");
+ assert!(requests.iter().all(|&bytes| bytes == POOL_TILES as u64 * TILE as u64));
+ assert_eq!(requests.len(), 1, "retry the refused system heap only on a later call");
+ }
+ }
+
/// Under `XCL_SPARSE_SYSMEM` a lazy tile outside the title's GPU heaps gets its memory from the
/// system-memory pools at its first bytes, as an eager one does, and the bytes reach the GPU.
#[test]2. Production changediff --git a/crates/xcl/src/hle/d3d12x/sparse.rs b/crates/xcl/src/hle/d3d12x/sparse.rs
index f31636e5e4edacbadb0f00646fa79aade29aca6f..693f60d3aab1cd83f495a0137eea3db91e3e69e3 100644
--- a/crates/xcl/src/hle/d3d12x/sparse.rs
+++ b/crates/xcl/src/hle/d3d12x/sparse.rs
@@ -3615,3 +3615,3 @@ impl State {
/// `take_tile` from the system-memory pools (`XCL_SPARSE_SYSMEM`).
- unsafe fn take_sys_tile(&mut self) -> Option<((u32, u32), bool)> {
+ unsafe fn take_sys_tile(&mut self, sys_heap_refused: &mut bool) -> Option<((u32, u32), bool)> {
self.drain_quarantined();
@@ -3627,2 +3627,7 @@ impl State {
}
+ // Reuse is still possible after a new heap was refused in this call.
+ if *sys_heap_refused {
+ drop(g);
+ return self.take_tile();
+ }
let desc = D3D12_HEAP_DESC {
@@ -3641,2 +3646,3 @@ impl State {
crate::xlog_warn!("sparse windows: no system-memory pool heap ({e}) - video memory instead");
+ *sys_heap_refused = true;
drop(g);
@@ -3656,4 +3662,4 @@ impl State {
/// unless `t` is in a GPU heap of the title.
- unsafe fn take_tile_for(&mut self, t: usize) -> Option<((u32, u32), bool)> {
- if sysmem_tiles() && !is_hot(t) { self.take_sys_tile() } else { self.take_tile() }
+ unsafe fn take_tile_for(&mut self, t: usize, sys_heap_refused: &mut bool) -> Option<((u32, u32), bool)> {
+ if sysmem_tiles() && !is_hot(t) { self.take_sys_tile(sys_heap_refused) } else { self.take_tile() }
}
@@ -3972,2 +3978,3 @@ impl State {
let (mut got, mut left) = (0, 0);
+ let mut sys_heap_refused = false;
while t < end {
@@ -3978,3 +3985,3 @@ impl State {
let wait = left > 0 || (!force && !sys && self.short_of_memory() && !at_hand);
- match if wait { None } else { self.take_tile_for(t) } {
+ match if wait { None } else { self.take_tile_for(t, &mut sys_heap_refused) } {
Some((tile, used)) => {
@@ -4057,3 +4064,4 @@ impl State {
} else {
- let Some((tile, reused)) = self.take_tile_for(t) else { break };
+ let mut sys_heap_refused = false;
+ let Some((tile, reused)) = self.take_tile_for(t, &mut sys_heap_refused) else { break };
let (holes, not_rw) = initial_state(t);3. Call-boundary testdiff --git a/crates/xcl/src/hle/d3d12x/sparse.rs b/crates/xcl/src/hle/d3d12x/sparse.rs
index 9265f14275502aaf9d0f60389b879be2097aae9f..fecbd6ea7d7099039f86368185ca2adeec8ef5be 100644
--- a/crates/xcl/src/hle/d3d12x/sparse.rs
+++ b/crates/xcl/src/hle/d3d12x/sparse.rs
@@ -11644,6 +11644,56 @@ mod tests {
}
}
+ #[test]
+ fn refused_system_heap_is_retried_on_the_next_materialize_call() {
+ let lazy = Lazy::on(true);
+ lazy.sysmem(true);
+ unsafe {
+ let Some((base, mut s, _queue)) = lazy_state(3) else {
+ return crate::gpu::recomp::runner::skip_test("no GPU with tiled resources tier 2");
+ };
+ let tiles = [base, base + TILE, base + 2 * TILE];
+ s.commit_range(base, 2 * TILE);
+ assert!(tiles[..2].iter().all(|t| s.mapped[t].pool == LAZY && !is_hot(*t)));
+
+ let ((video_heap, _), _) = s.take_tile().expect("seed the video fallback heap");
+ assert!(s.free.heap_len(video_heap as usize) >= tiles.len());
+ let heap = s.pools[video_heap as usize].as_ref().expect("live video heap");
+ assert_eq!(heap.GetDesc().Properties.Type, D3D12_HEAP_TYPE_DEFAULT);
+
+ let refusal = std::rc::Rc::new(SysHeapRefusal::default());
+ SYS_HEAP_REFUSAL.with_borrow_mut(|r| *r = Some(refusal.clone()));
+ let first = s.materialize(base, 2 * TILE, false, &mut Vec::new());
+ let first_attempts = refusal.requests.borrow().len();
+
+ let fresh = tiles[2];
+ s.commit_range(fresh, TILE);
+ assert!(s.mapped[&fresh].pool == LAZY && !is_hot(fresh));
+ {
+ let pools = refusal.pools.lock().unwrap();
+ let pools = pools.as_ref().expect("first call checked the system pools");
+ assert!(pools.heaps.is_empty() && pools.free.is_empty()
+ && pools.cooling.is_empty() && pools.retired.is_empty());
+ }
+ let second = s.materialize(fresh, TILE, false, &mut Vec::new());
+ let backing = tiles.map(|t| s.mapped[&t].pool);
+ let requests = refusal.requests.borrow();
+ let luid = s.dev.GetAdapterLuid();
+ eprintln!("L0 call boundary: first_attempts={first_attempts} total_attempts={} requested_bytes={requests:?} \
+ first={first:?} second={second:?} video_heap={video_heap} tile_backing={backing:?} \
+ adapter_luid={:08x}:{:08x}", requests.len(), luid.HighPart as u32, luid.LowPart);
+ drop(s);
+ assert_ne!(VirtualFree(base as *mut c_void, 0, windows_sys::Win32::System::Memory::MEM_RELEASE), 0);
+ assert_eq!(first, (2, 0));
+ assert_eq!(second, (1, 0));
+ assert!(backing.iter().all(|&(h, t)| h == video_heap && t < POOL_TILES));
+ assert!(backing[0] != backing[1] && !backing[..2].contains(&backing[2]));
+ assert_eq!(first_attempts, 1);
+ let heap_bytes = POOL_TILES as u64 * TILE as u64;
+ assert_eq!(requests.as_slice(), &[heap_bytes, heap_bytes]);
+ }
+ }
+
/// Under `XCL_SPARSE_SYSMEM` a lazy tile outside the title's GPU heaps gets its memory from the
/// system-memory pools at its first bytes, as an eager one does, and the bytes reach the GPU.
#[test] |
With XCL_COHERENT_HEAPS=sparse the title's GPU heaps (committed memory with a PAGE_GRAPHICS_* protection, ~4.5 GB in a retail title) live in the sparse windows. Those are the data the title's shaders read and write every frame; in the coherent window (system memory, read over PCIe) one retail compute program took 1,364 ms a frame on an RTX 3080, under 33 ms in video memory. With them in video memory the windows hold ~7.5 GB of tiles and the device ran out of its budget (19 GB in use against 8.9 GB, removed at 659 s). XCL_SPARSE_SYSMEM=1 (off by default): kernelx registers a GPU heap's range as hot before its commit maps its tiles (sparse::alloc_as); every other sparse-window tile takes a pool tile in system-memory pool heaps (custom heaps, L0, write-back), which the GPU reads over PCIe. A pool tile of those heaps has SYS in its pool index; freed ones cool in their own lists, kept by the heap's number without SYS (the free table is indexed by heap number). RTX 3080, retail title, 400 s of its world after the menus: heaps in video memory alone 0.98 presents/s and 19 GB of video memory; with this and the texture-level counterpart 1.70 presents/s, 12.7 GB, no device removal in 900 s. An RTX 4080 report on xcl-dev#2688 found the same with a port of it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
24a84ca to
84646d4
Compare
|
Rebased onto main (1) Cold tiles skipped after one tile finds no video memory. (2) A refused system-memory heap is retried for every cold tile. (3) "Workspace suite aborted on both builds." I don't think this PR causes it. The report's own table shows the same abort ( Tested at Still open: showing the 3.8 GB coming back in a title run (finding 4). We will measure it. The memory coming back, measured at @Foniass @stijn-boer could you re-check AI use: Claude Code (Claude Opus 5.5). |
|
merge-check Windows / AMD RDNA4 — sparse system-memory heaps on Follow-up for the later #3613 head. I applied #3707 at Setup AMD Radeon RX 9060 XT (driver 32.0.32029.2010), Ryzen 7 5700X, Windows 10 21H2 build 19044.6332, Rust 1.100.0 debug, Agility SDK 1.620.2 with matching debug layer, DXC 1.9.2609.5. Tested
Counts are partial because the library process exited with Focused sparse tests — 6 passed, 0 failed, 0 ignored, 0 skip notices with isolated libtest invocations using Shared failures and skips
Retail smoke Ran
All three runs logged zero device removals and zero crashes. The enabled run logged system-memory pool allocation milestones up to 512 MiB. On the same build, enabling the flag corresponded to about 14% fewer frames and 421 MB more peak process commit in this pair. One run per setting leaves repeatability and the cause open. The allocation milestones do not measure subsequent heap release or net VRAM savings. Merge request Could maintainers prioritize merging #3707 and #3455 once their required checks pass? In this retest, plain Not tested A standalone #3613 retail run, retail heap reclamation and net VRAM savings, repeated performance pairs, and #3455 in this test configuration. AI use Codex (GPT-6) prepared the two local builds, ran the tests and smoke comparisons, reviewed the changed allocation paths, and drafted this report. Follow-up with #3455 added to both builds Same #3613 head, Tested
The library exited Retail smoke Same AMD host, title hash
All three runs logged zero device removals and zero crashes. With both companion PRs included, enabling the switch corresponded to about 23% more frames and 31% lower peak process commit versus leaving it unset on the same build. The enabled run again logged a 512 MiB system-memory pool allocation milestone. This single pair reversed the earlier switch comparison. An isolated #3455 effect, repeatability, retail heap release, and net VRAM savings remain unverified. Follow-up verdict — not yet. The combined smoke runs completed and the focused checks passed. Both full workspace runs still aborted. |
|
merge-check |
bmjask
left a comment
There was a problem hiding this comment.
Review of 84646d4d: 4 finding(s) (1 high, 3 medium), most severe first.
- High
crates/xcl/src/hle/d3d12x/sparse.rs:549: The system-memory pools (SYS_POOLS) are a process global, but the tiles, quarantine, fence (value/done) and device that drive them belong to oneState, so the pools don't follow that State's lifetime or device. (inline) - Medium
crates/xcl/src/hle/d3d12x/sparse.rs:3650: When the system-memory pools are refused,take_sys_tilefalls back totake_tile()and skips the video-memory waitsmaterializeapplies to hot tiles (no_video, andshort_of_memory() && !at_hand). (inline) - Medium
crates/xcl/src/hle/d3d12x/sparse.rs:3666:take_sys_tilecalls CreateHeap with the state lock held but without theflush_pending()thattake_tiledoes first, andtake_tile's comment explains why: a CPU signal waiting meanwhile gives up after 2 ms. (inline) - Medium
crates/xcl/src/hle/d3d12x/sparse.rs:488: TheSYStag (bit 31) overlaps the sentinelsLAZY = (u32::MAX, u32::MAX)andSHADOW_POOL = u32::MAX, sopool.0 & SYS != 0is also true for a tile with no memory or a shadow tile. (inline)
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.
| // D3D12 heaps are free-threaded | ||
| unsafe impl Send for SysPools {} | ||
|
|
||
| static SYS_POOLS: Mutex<Option<SysPools>> = Mutex::new(None); |
There was a problem hiding this comment.
High: The system-memory pools (SYS_POOLS) are a process global, but the tiles, quarantine, fence (value/done) and device that drive them belong to one State, so the pools don't follow that State's lifetime or device. init can replace STATE (when the windows are set up again). The old State takes its mapped, parked and quarantined SYS tiles with it, so their heaps never become all free and leak. Entries in SysPools.retired keep the old fence's marks and are compared with the new fence's done, which restarts at 0, so heaps can be reused while the GPU may still use them. A new State on another device then maps heaps made on the old device (pool_heap -> UpdateTileMappings), which gives a D3D12 error or device removal. Owning the system pools in State, like the video pools, would fix all three.
| // tile (each asked, and logged it): video memory meanwhile | ||
| if self.sys_refused.is_some_and(|t| t.elapsed() < std::time::Duration::from_secs(1)) { | ||
| drop(g); | ||
| return self.take_tile(); |
There was a problem hiding this comment.
Medium: When the system-memory pools are refused, take_sys_tile falls back to take_tile() and skips the video-memory waits materialize applies to hot tiles (no_video, and short_of_memory() && !at_hand). After a hot tile fails to get video memory (setting no_video/no_memory), the next cold tile computes wait = no_sys (false) and calls take_sys_tile, which within 1 s of sys_refused goes to take_tile(), runs flush_pending and another failing CreateHeap, and logs 'no video memory for more tiles'. This repeats on every materialize in that second, which is exactly what no_memory/short_of_memory prevent. When it does succeed, cold tiles take video memory while hot GPU-heap tiles are made to wait. Respecting no_video in the fallback would fix it.
| let mut heap: Option<ID3D12Heap> = None; | ||
| #[cfg(test)] | ||
| tests::SYS_HEAPS_ASKED.with(|c| c.set(c.get() + 1)); | ||
| let made = if refuse { Err(windows::Win32::Foundation::E_OUTOFMEMORY.into()) } else { super::title_textures::own_work(|| self.dev.CreateHeap(&desc, &mut heap)) }; |
There was a problem hiding this comment.
Medium: take_sys_tile calls CreateHeap with the state lock held but without the flush_pending() that take_tile does first, and take_tile's comment explains why: a CPU signal waiting meanwhile gives up after 2 ms. Tiles already pending in self.pending (e.g. from earlier iterations of the same ensure_mapped loop) aren't sent before the slow custom-L0 CreateHeap, so a title queue or CPU signal waiting on their mapping times out, the regression take_tile guards against. Calling flush_pending() first would match.
| /// title's GPU heaps (`note_hot`) get pool tiles in system memory (custom heaps in L0, read by | ||
| /// the GPU over PCIe) instead of video memory; the GPU heaps' tiles keep video memory. A pool | ||
| /// tile of these heaps has `SYS` set in its pool index. | ||
| const SYS: u32 = 1 << 31; |
There was a problem hiding this comment.
Medium: The SYS tag (bit 31) overlaps the sentinels LAZY = (u32::MAX, u32::MAX) and SHADOW_POOL = u32::MAX, so pool.0 & SYS != 0 is also true for a tile with no memory or a shadow tile. In a_lazy_tile_outside_the_gpu_heaps_gets_system_memory, assert_ne!(s.mapped[&base].pool.0 & SYS, 0, ...) passes when the tile is still LAZY, so that check proves nothing. Any SYS check that sees a LAZY or shadow entry (in cool, pool_heap or pool_bytes) would treat it as system heap 0x7FFF_FFFF, so FreePools::push would resize by_heap to 2^31 entries, or pool_heap would index out of bounds and panic. Excluding the sentinels in an is_sys() helper would close it.
|
@stijn-boer thanks for the AMD run. On the two points:
Did the RX 9060 XT reach the world with the switch on, and how much video memory did it save there? AI use: Claude Code (Claude Opus 5.5). |
…ll free The system-memory pools of XCL_SPARSE_SYSMEM only grew: unlike the video pools they had no retirement path, so the process kept its peak (about 3.8 GB in our world runs). Review point on xcl-dev#2987: xcl-dev#2987 (comment) A heap whose 64 tiles are all free or cooled (COOL) is released, and kept alive in a retired list until the sparse queue's fence is past the value it got, as State::retired does for video memory (the tiles' unmaps were already quarantined behind the fences before they cooled). Heap slots become Option so the indexes encoded in tile handles of live heaps do not move; the next heap takes the free slot, and a retired heap is taken back before a new one is created (xcl-dev#913). State::retire_free_pools_with runs it, and the submit path's retire_due also looks at the system pools' cooling queue. Test: a_system_memory_heap_with_all_tiles_free_is_given_back fails with retirement disabled and passes with it. Before a new system-memory heap is made (CreateHeap of a custom L0 heap, with the state locked), the tiles waiting for their mapping are sent, as take_tile does before a video-memory heap: a CPU signal that asks for the lock meanwhile gives up after 2 ms (bmjask's review). The pools' lock is let go for it, since map_tiles takes it. Test: pending_mappings_go_out_before_a_system_memory_heap_is_made fails without the flush (1 tile pending at the heap request) and passes with it. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
84646d4 to
b98038b
Compare
|
Thanks for the third round. One of the four points is a real bug and is fixed. The other three are explained below with what I would do as follow-ups. Since the code changed, the merge check claimed on 3. Medium: 1. High: 2. Medium: the fallback to 4. Medium: Tests (Windows, debug, RTX 4080): Each round has found new points so far. Would the remaining ones (1, 2, 4) block the merge, or can they be follow-ups once this round is in? Pushed as AI use: Claude Code (Claude Opus 5.5). |
|
@Pipodi heads-up for your merge-check claim: the head moved from |
|
merge-check In short: The PR carries #2987's opt-in XCL_SPARSE_SYSMEM commit and adds retirement of system-memory pool heaps whose tiles are all free. The new push (range-diff against 84646d4) only adds flush_pending before a system-memory heap is made, with a test, and the rest of the diff is unchanged. Nothing blocks merging and the default path is unchanged, but the earlier medium points (cold-tile fallback skipping the video waits, kept SYS tiles at GPU-heap addresses, untested retirement wiring, a description that no longer matches the commits or the head) are still open. Medium
Nit
Checked and fine
How this was tested
Written by Claude Code (Claude Opus 5.5) and posted by Foniass without a human check of each point. |
|
merge-check Replaces my check of 84646d4 (head moved). |
Carries #2987 (treybertram06's commit unchanged, rebased on main) and adds the system-pool retirement asked for in its review; supersedes #2987 if its author does not return.
The system-memory pools of
XCL_SPARSE_SYSMEM=1only grew: unlike the video pools they had no way to give back a heap whose tiles are all free, so the process kept its peak (about 3.8 GB in our world runs). Review point: #2987 (comment)What is in it
D3D12.X: sparse tiles outside the GPU heaps can live in system memory- treybertram06's commit, unchanged (sparse.rs,kernelx.rs); default off.D3D12.X: system-memory sparse pools give back heaps whose tiles are all free(crates/xcl/src/hle/d3d12x/sparse.rs):SysPools::retirereleases a heap whose 64 tiles are all free or cooled (COOL), keeps it in a retired list until the sparse queue's fence is past its mark (asState::retireddoes), and a retired heap is taken back before a new one is made. Heap slots areOptionso the indexes in live tile handles never move; the next heap takes a free slot.State::retire_free_pools_withcalls it, and the submit path'sretire_duealso looks at the system pools' cooling queue. Test:a_system_memory_heap_with_all_tiles_free_is_given_back(checksbytes()drops, live heap keeps its index, retired heap waits for the fence, a later heap reuses the slot); it fails with the retirement disabled.Tested
cargo build --workspace && cargo test --workspace -- --test-threads=4on headb98038bb(after bmjask's third review): 3012 passed, 0 failed, 52 ignored, 25SKIPPEDlines.XCL_RESIDENCY_PRIORITY=1): run 505 withXCL_SPARSE_SYSMEMoff: peak 18,948 MB of a 15,171 MB budget, 3.13 presents/s. Run 506 with it on: peak 15,737 MB of 15,166 MB (−3.2 GB), 3.01 presents/s (−4 %). Neither run had a device removal or crash.SKIPPEDlines in the log: 25 (gpu, hle, shaders andheap_window_out_of_memory_falls_back_to_the_switch_form); not counted as coverage.retiredisabled (panic at the firstbytes()assertion after retirement).Regression run
main
817eb1fc9:this PR's head:
Not tested
AI use
🤖 Generated with Claude Code