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
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,9 @@ Fill the reusable DXIL cache ahead of a run with the read-only package wrapper.
fills into its GPU views) are applied: a GPU-view page shows the physical page mapped into it.
`XCL_PAGE_MAPPINGS=0` turns them off (the call is ignored and a GPU-view page shows its CPU view at
the same offset, as before).
- XCL's own heaps get a residency priority when they are made: render-target arenas, window tile pools
and texture page pools holding targets `HIGH`, so that over the video memory budget Windows demotes
idle texture pages first. `XCL_RESIDENCY_PRIORITY=0` turns it off.
- Every run writes `report.json` (called stubs, unknown D3D12.X slots and interfaces, XGameRuntime
classes asked for, shader statistics, audio formats, crash).
`d3d12.presents` counts presentations, not visible content. With `XCL_FRAME_DUMP=N` (`N > 1`),
Expand Down
21 changes: 17 additions & 4 deletions crates/xcl/src/hle/d3d12x/vram.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1011,20 +1011,24 @@ pub(super) fn role_priority(role: HeapRole) -> Option<D3D12_RESIDENCY_PRIORITY>
}
}

/// `XCL_RESIDENCY_PRIORITY=1` (read once, off by default): XCL's own heaps get the residency
/// `XCL_RESIDENCY_PRIORITY` (read once, on unless it is `0`): XCL's own heaps get the residency
/// priority of their role (`role_priority`) when they are made; nothing is called per frame.
fn residency_priority_enabled(v: Option<&str>) -> bool {
v.map_or(true, |v| v.trim() != "0")
}

fn residency_priority_wanted() -> bool {
static ON: std::sync::OnceLock<bool> = std::sync::OnceLock::new();
*ON.get_or_init(|| {
let on = std::env::var("XCL_RESIDENCY_PRIORITY").is_ok_and(|v| v.trim() == "1");
let on = residency_priority_enabled(std::env::var("XCL_RESIDENCY_PRIORITY").ok().as_deref());
if on {
crate::xlog_info!("D3D12.X: XCL_RESIDENCY_PRIORITY: render-target arenas, window tile pools and texture page pools holding targets get HIGH residency priority, other texture pages NORMAL");
}
on
})
}

/// Gives a new heap of `role` its residency priority when `XCL_RESIDENCY_PRIORITY=1`. A failure
/// Gives a new heap of `role` its residency priority unless `XCL_RESIDENCY_PRIORITY=0`. A failure
/// is logged (once) and leaves the heap at the default.
pub(super) unsafe fn set_heap_priority(dev: &ID3D12Device, heap: &ID3D12Heap, role: HeapRole) {
if !residency_priority_wanted() {
Expand Down Expand Up @@ -2179,7 +2183,7 @@ impl Pages {

/// The pool heaps holding the pages `used` / `used_extra` of a texture of `role`
/// (`pages_role`) get its residency priority, each heap once (`newly_high`); a pool of only
/// sampled textures stays at the default. Nothing when `XCL_RESIDENCY_PRIORITY` is off.
/// sampled textures stays at the default. Nothing when `XCL_RESIDENCY_PRIORITY=0`.
unsafe fn keep_pools(&mut self, dev: &ID3D12Device, role: HeapRole, used: &[usize], used_extra: &[(usize, usize)]) {
if !residency_priority_wanted() || role_priority(role).is_none() {
return;
Expand Down Expand Up @@ -4153,6 +4157,15 @@ mod tests {
SRV_TRACKING_FOR_TEST.store(false, std::sync::atomic::Ordering::Relaxed);
}

/// `XCL_RESIDENCY_PRIORITY` is on unless it is `0`.
#[test]
fn residency_priority_is_on_by_default() {
assert!(residency_priority_enabled(None));
assert!(residency_priority_enabled(Some("1")));
assert!(!residency_priority_enabled(Some("0")));
assert!(!residency_priority_enabled(Some(" 0 ")));
}

/// Render-target arenas and the windows' tile pools are kept over texture pages: they get
/// `HIGH`, texture pages the default (no call), and nothing gets `MAXIMUM` (the UMA upload
/// segment's, which every console program reads from).
Expand Down
Loading