Skip to content
Merged
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
79 changes: 62 additions & 17 deletions crates/victory-gpu/src/shadow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -763,8 +763,8 @@ fn window_card_for(size: u64) -> Option<ID3D12Resource> {
}

/// The most bytes of windows outside buffers that lie in the card's memory
/// and are filled by the CPU through the bus (`VICTORY_WINDOWS_BAR_MB`; 0, the
/// default, none): one buffer (`D3D12_HEAP_TYPE_GPU_UPLOAD`), no CPU's side, no
/// and are filled by the CPU through the bus (`VICTORY_WINDOWS_BAR_MB`; unset,
/// [`window_mapped_default`]): one buffer (`D3D12_HEAP_TYPE_GPU_UPLOAD`), no CPU's side, no
/// copy to send and no list of changes, unlike [`window_card_most`]. The CPU
/// only writes them, as no shader is declared to write a window; if one were,
/// its snapshot and compare would read through the bus, right but slow. In a
Expand All @@ -776,25 +776,66 @@ fn window_card_for(size: u64) -> Option<ID3D12Resource> {
fn window_mapped_most() -> u64 {
static MOST: std::sync::OnceLock<u64> = std::sync::OnceLock::new();
*MOST.get_or_init(|| {
// Unset: 4096 when the shared budget is small and card memory can be
// mapped; else 3072 on a small host, by itself: Windows lets a card
// share at most half the RAM, and the windows filled that on a 16 GB
// PC (RTX 3060) about a minute into the world: `0x8007000E` on a host
// command list, then a driver fault (issue #1520; PR #6, the
// launcher's auto of 85a529b, lost when the script became a shim).
// An explicit `VICTORY_WINDOWS_BAR_MB` (0 included) decides as before.
// Bigger machines keep it off, as before.
let unset = if crate::residency::shared_is_small() {
4096
} else if crate::residency::small_host_ram() {
3072
} else {
0
};
let big_card = host()
.and_then(|host| host.video_memory())
.is_some_and(|[budget, ..]| budget >= WINDOW_MAPPED_BIG_CARD);
let unset = window_mapped_default(
crate::residency::shared_is_small(),
crate::residency::small_host_ram(),
big_card,
);
std::env::var("VICTORY_WINDOWS_BAR_MB").ok().and_then(|v| v.trim().parse::<u64>().ok()).unwrap_or(unset) << 20
})
}

/// The card's own budget from which a host that is neither of the small ones
/// puts windows in card memory the CPU maps by itself: 16 GB cards (an RTX
/// 5080 reports 15,209 MB), not 12 or 8 GB ones, whose render targets,
/// texture floor and card copies arrive after the windows and need the room.
const WINDOW_MAPPED_BIG_CARD: u64 = 14 << 30;

/// [`window_mapped_most`] in MiB when `VICTORY_WINDOWS_BAR_MB` is unset.
/// 4096 when the shared budget is small and card memory can be mapped; else
/// 3072 on a small host, by itself: Windows lets a card share at most half
/// the RAM, and the windows filled that on a 16 GB PC (RTX 3060) about a
/// minute into the world: `0x8007000E` on a host command list, then a driver
/// fault (issue #1520; PR #6, the launcher's auto of 85a529b, lost when the
/// script became a shim). Else 4096 on a card with a big budget
/// ([`WINDOW_MAPPED_BIG_CARD`]): on an RTX 5080 16 GB with 32 GB of RAM the
/// process's shared GPU memory was 1.6-2.4 GB lower in the world and the
/// card's own 1.9-2.2 GB higher, with the picture unchanged. Other machines
/// keep them off, as before. An explicit
/// `VICTORY_WINDOWS_BAR_MB` (0 included) decides as before.
fn window_mapped_default(shared_small: bool, small_ram: bool, big_card: bool) -> u64 {
if shared_small {
4096
} else if small_ram {
3072
} else if big_card {
4096
} else {
0
}
}

#[cfg(test)]
mod window_mapped_default_tests {
use super::window_mapped_default;

#[test]
fn big_cards_get_windows_in_card_memory_small_hosts_as_before() {
// The small hosts, whatever the card: as before.
for big_card in [false, true] {
assert_eq!(window_mapped_default(true, true, big_card), 4096);
assert_eq!(window_mapped_default(true, false, big_card), 4096);
assert_eq!(window_mapped_default(false, true, big_card), 3072);
}
// A bigger host: only with a big card.
assert_eq!(window_mapped_default(false, false, true), 4096);
assert_eq!(window_mapped_default(false, false, false), 0);
}
}

/// Bytes alive of windows in card memory the CPU maps.
static WINDOW_MAPPED_BYTES: AtomicU64 = AtomicU64::new(0);

Expand All @@ -806,6 +847,10 @@ fn window_mapped_for(size: u64) -> Option<(ID3D12Resource, *mut u8)> {
return None;
}
let host = host()?;
// Nothing to ask for without card memory the CPU maps (no resizable BAR).
if !host.mapped_card_memory() {
return None;
}
if let Some([budget, used, ..]) = host.video_memory()
&& used + size > budget / 10 * 8
{
Expand Down
Loading