Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 52 additions & 8 deletions crates/xcl/src/hle/d3d12x/sparse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3528,24 +3528,68 @@ impl State {
let h = self.add_pool(heap);
return Some(((h, 0), true));
}
let desc = D3D12_HEAP_DESC {
static L0_SPARSE_HEAP_UNSUPPORTED: AtomicBool = AtomicBool::new(false);
let allow_l0 = super::vram::l0_vram_margin() > 0
&& !L0_SPARSE_HEAP_UNSUPPORTED.load(Ordering::Relaxed);
let spill_l0 = allow_l0 && super::vram::should_spill_l0_for_vram();
let make_desc = |l0: bool| D3D12_HEAP_DESC {
SizeInBytes: POOL_TILES as u64 * TILE as u64,
Properties: D3D12_HEAP_PROPERTIES { Type: D3D12_HEAP_TYPE_DEFAULT, ..Default::default() },
Properties: if l0 {
D3D12_HEAP_PROPERTIES {
Type: D3D12_HEAP_TYPE_CUSTOM,
CPUPageProperty: D3D12_CPU_PAGE_PROPERTY_NOT_AVAILABLE,
MemoryPoolPreference: D3D12_MEMORY_POOL_L0,
CreationNodeMask: 0,
VisibleNodeMask: 0,
}
} else {
D3D12_HEAP_PROPERTIES { Type: D3D12_HEAP_TYPE_DEFAULT, ..Default::default() }
},
Alignment: 0,
Flags: D3D12_HEAP_FLAG_DENY_RT_DS_TEXTURES | D3D12_HEAP_FLAG_DENY_NON_RT_DS_TEXTURES,
};
// (a heap takes its time, with the state locked: what waits for its mapping goes first, a
// CPU signal that asks meanwhile gives up after 2 ms)
self.flush_pending();
let mut heap: Option<ID3D12Heap> = None;
if let Err(e) = super::title_textures::own_work(|| self.dev.CreateHeap(&desc, &mut heap)) {
crate::xlog_warn!("sparse windows: no video memory for more tiles ({e})");
return None;
let mut placed_l0 = spill_l0;
if let Err(e) = super::title_textures::own_work(|| self.dev.CreateHeap(&make_desc(spill_l0), &mut heap)) {
if spill_l0 {
super::vram::note_l0_heap_error(&L0_SPARSE_HEAP_UNSUPPORTED, &e);
placed_l0 = false;
if let Err(e2) = super::title_textures::own_work(|| self.dev.CreateHeap(&make_desc(false), &mut heap)) {
crate::xlog_warn!("sparse windows: no video memory for more tiles ({e2})");
return None;
}
} else if allow_l0 {
placed_l0 = true;
if let Err(e2) = super::title_textures::own_work(|| self.dev.CreateHeap(&make_desc(true), &mut heap)) {
super::vram::note_l0_heap_error(&L0_SPARSE_HEAP_UNSUPPORTED, &e2);
crate::xlog_warn!("sparse windows: no video memory for more tiles ({e}; L0 fallback: {e2})");
return None;
}
} else {
crate::xlog_warn!("sparse windows: no video memory for more tiles ({e})");
return None;
}
}
let heap = heap?;
let _ = heap.SetName(windows::core::w!("xcl sparse tile pool"));
// (once, when made: a retired pool taken back above keeps the priority it got)
super::vram::set_heap_priority(&self.dev, &heap, super::vram::HeapRole::WindowPool);
if placed_l0 {
let _ = heap.SetName(windows::core::w!("xcl sparse tile pool (L0)"));
static L0_MADE: AtomicU64 = AtomicU64::new(0);
let n = L0_MADE.fetch_add(1, Ordering::Relaxed) + 1;
if n <= 4 || n.is_power_of_two() {
let (used, budget) = super::real::video_memory().map_or((0, 0), |(u, _, b)| (u >> 20, b >> 20));
crate::xlog_info!(
"sparse windows: tile pool #{n} spilled to L0 system memory ({} MiB spilled so far; local VRAM {used}/{budget} MiB)",
(n * (POOL_TILES as u64 * TILE as u64)) >> 20
);
}
} else {
let _ = heap.SetName(windows::core::w!("xcl sparse tile pool"));
// (once, when made: a retired pool taken back above keeps the priority it got)
super::vram::set_heap_priority(&self.dev, &heap, super::vram::HeapRole::WindowPool);
}
let h = self.add_pool(heap);
Some(((h, 0), false))
}
Expand Down
Loading
Loading