diff --git a/d3d12/crates/leonida-gpu/src/host.rs b/d3d12/crates/leonida-gpu/src/host.rs index 020ac1553a..0573e4ce15 100644 --- a/d3d12/crates/leonida-gpu/src/host.rs +++ b/d3d12/crates/leonida-gpu/src/host.rs @@ -13810,7 +13810,39 @@ impl Host { ); self.log_video_memory("right after that change"); } - Some([own.Budget, own.CurrentUsage, shared.Budget, shared.CurrentUsage]) + // `LEONIDA_VRAM_BUDGET_MB`: the card's budget every decision takes, in place of the system's + // (`crate::resource::effective_budget`). The lines above keep saying the system's. + static SAID_BUDGET: std::sync::Once = std::sync::Once::new(); + let setting = crate::resource::card_budget_setting(); + SAID_BUDGET.call_once(|| match crate::resource::card_budget_fixed() { + Some(bytes) => { + tracing::info!( + budget_mb = bytes >> 20, + system_mb = own.Budget >> 20, + "the card's budget is LEONIDA_VRAM_BUDGET_MB's, not the system's" + ); + // Past the system's budget the runtime's own guards allow the process more than the system + // gives it, which on Windows ended runs 20 and 24 ([`crate::resource::room`]). Clamping would + // defeat the Wine use this is for, so say it once and go on. + if bytes > own.Budget { + tracing::warn!( + budget_mb = bytes >> 20, + system_mb = own.Budget >> 20, + "LEONIDA_VRAM_BUDGET_MB is above the system's budget: from here the runtime lets the process go past what the system gives it" + ); + } + } + None => { + if let Some(value) = setting { + tracing::warn!( + value = %value, + "LEONIDA_VRAM_BUDGET_MB is not a whole number of MB from 256: the system's budget is used" + ); + } + } + }); + let budget = crate::resource::effective_budget(own.Budget, setting); + Some([budget, own.CurrentUsage, shared.Budget, shared.CurrentUsage]) } /// Both of the system's memory groups for this process, in bytes: for diff --git a/d3d12/crates/leonida-gpu/src/host/panel.rs b/d3d12/crates/leonida-gpu/src/host/panel.rs index 6ba7daf7be..fa5fd539cc 100644 --- a/d3d12/crates/leonida-gpu/src/host/panel.rs +++ b/d3d12/crates/leonida-gpu/src/host/panel.rs @@ -159,6 +159,9 @@ fn text(c: &[f64; COUNTERS], ms: f64, worst: f64, cost: f64, host: &Host) -> Vec let gb = |bytes: u64| bytes as f64 / (1u64 << 30) as f64; let (working, private) = crate::copystat::process_memory(); let [budget, used, _, shared] = host.video_memory().unwrap_or_default(); + // The budget is `LEONIDA_VRAM_BUDGET_MB`'s when it is set, not the card's: say so on the line, or 7,000 MB + // reads as the card's own beside the log's "as the system counts it". + let fixed = crate::resource::card_budget_fixed().is_some(); let idle = (c[1] / 1e3).min(ms); // The frame-time line's last numbers (every five seconds), once there is one. let stalls = super::frametime::LAST.lock().ok().and_then(|last| *last); @@ -174,7 +177,11 @@ fn text(c: &[f64; COUNTERS], ms: f64, worst: f64, cost: f64, host: &Host) -> Vec format!("RECORDING {:.0} MS COPY BACK {:.1}", c[9] / 1e6, c[5] / 1e3), format!("MB UP {:.0} TEXTURES {:.0} BACK {:.0}", c[7] / 1e6, c[4] / 1e6, c[6] / 1e6), format!("RAM {:.1} GB IN MEMORY {:.1}", gb(private), gb(working)), - format!("VRAM {:.1}/{:.1} GB SHARED {:.1}", gb(used), gb(budget), gb(shared)), + if fixed { + format!("VRAM {:.1}/{:.1} GB FIXED SHARED {:.1}", gb(used), gb(budget), gb(shared)) + } else { + format!("VRAM {:.1}/{:.1} GB SHARED {:.1}", gb(used), gb(budget), gb(shared)) + }, format!("THIS PANEL {:.0} US A FRAME", cost), ]; if let Some(s) = stalls { diff --git a/d3d12/crates/leonida-gpu/src/resource.rs b/d3d12/crates/leonida-gpu/src/resource.rs index 8793a88a46..64d7121bcf 100644 --- a/d3d12/crates/leonida-gpu/src/resource.rs +++ b/d3d12/crates/leonida-gpu/src/resource.rs @@ -2025,6 +2025,58 @@ fn texture_floor_bytes(vram_budget: Option) -> u64 { } } +/// `LEONIDA_VRAM_BUDGET_MB`: the budget of the card's own memory, in bytes, +/// that every decision on it takes in place of the one the system gives +/// ([`crate::host::Host::video_memory`]: the texture queue's room, the card +/// copies of title buffers, the staging per frame). `None` (the system's +/// budget) when unset or not a whole number of MB from 256 up to 1 TiB. +/// +/// A measure for Wine and Proton rather than a knob for Windows: there the +/// system's budget is what Vulkan reports as left to the process, and above +/// what the card has free allocations fail rather than move to the PC's memory +/// as on Windows. Below what the card has in use it keeps the card over budget, +/// and the copies the keep rule evicts are made again as fast as the texture +/// budget lets them be. +/// +/// Measured under Proton with `4000` against a system budget of 6 967 MB (RTX +/// 3060 Ti, driver 620.73.04): the highest in use over 2 min 18 s was 3 999 MB, +/// a draw whose texture did not fit brought up to date the copy already on the +/// card instead of taking new room, and nothing failed to allocate. With +/// `LEONIDA_TEXTURE_BUDGET_MB` unset the make-then-evict churn is not what runs: +/// the host copies stayed flat (666 alive, 1 180 MB) while pipelines were still +/// being made. +#[cfg(any(windows, test))] +pub(crate) fn fixed_card_budget(setting: Option<&str>) -> Option { + let mb = setting?.trim().parse::().ok()?; + (256..=1 << 20).contains(&mb).then_some(mb << 20) +} + +/// `LEONIDA_VRAM_BUDGET_MB` as the environment gives it, read once: the log, +/// the choice and the panel all see the same answer. +#[cfg(any(windows, test))] +pub(crate) fn card_budget_setting() -> Option<&'static str> { + static SETTING: std::sync::OnceLock> = std::sync::OnceLock::new(); + SETTING + .get_or_init(|| std::env::var("LEONIDA_VRAM_BUDGET_MB").ok().filter(|v| !v.trim().is_empty())) + .as_deref() +} + +/// The bytes `LEONIDA_VRAM_BUDGET_MB` names, when it names a budget that can be +/// used ([`fixed_card_budget`]). +#[cfg(any(windows, test))] +pub(crate) fn card_budget_fixed() -> Option { + fixed_card_budget(card_budget_setting()) +} + +/// The budget the runtime works to: `LEONIDA_VRAM_BUDGET_MB`'s when it names +/// one, the system's ([`fixed_card_budget`]'s `None`) otherwise. The choice is a +/// function of its own so that a test covers it: the environment and the +/// adapter's answer are read elsewhere. +#[cfg(any(windows, test))] +pub(crate) fn effective_budget(system: u64, setting: Option<&str>) -> u64 { + fixed_card_budget(setting).unwrap_or(system) +} + /// The limit `LEONIDA_TEXTURE_BUDGET_MB` sets on the bytes of host copies of /// the title's textures, if it is set. #[cfg(windows)] @@ -5733,6 +5785,40 @@ float4 lit() : SV_Target { return 1.0; } assert_eq!(targets_turn(false, most, 3072 * MIB, 0), None); } + #[test] + fn a_fixed_card_budget_is_a_size_in_mb() { + const MIB: u64 = 1 << 20; + assert_eq!(fixed_card_budget(Some("7000")), Some(7_000 * MIB)); + assert_eq!(fixed_card_budget(Some(" 7000 ")), Some(7_000 * MIB)); + assert_eq!(fixed_card_budget(Some("256")), Some(256 * MIB)); + // Unset, empty or not a number of MB: the system's budget stays. + assert_eq!(fixed_card_budget(None), None); + assert_eq!(fixed_card_budget(Some("")), None); + assert_eq!(fixed_card_budget(Some("7 GB")), None); + assert_eq!(fixed_card_budget(Some("-1")), None); + // Too small to be meant, or past any card. + assert_eq!(fixed_card_budget(Some("0")), None); + assert_eq!(fixed_card_budget(Some("255")), None); + assert_eq!(fixed_card_budget(Some("1048577")), None); + } + + /// The choice [`fixed_card_budget`] feeds, apart from the process-global + /// environment: the setting's budget when it names one, the system's + /// otherwise. + #[test] + fn a_fixed_card_budget_wins_over_the_systems_and_the_system_otherwise() { + const MIB: u64 = 1 << 20; + let system = 15_293 * MIB; // an RTX 4070 Ti SUPER's own, as the system reports it + assert_eq!(effective_budget(system, Some("7000")), 7_000 * MIB); + // Above the system's too: the Wine case, where the system's budget is what Vulkan leaves the process. + assert_eq!(effective_budget(system, Some("20000")), 20_000 * MIB); + assert_eq!(effective_budget(system, Some("256")), 256 * MIB); + assert_eq!(effective_budget(system, None), system); + assert_eq!(effective_budget(system, Some("")), system); + assert_eq!(effective_budget(system, Some("7 GB")), system); + assert_eq!(effective_budget(system, Some("0")), system); + } + /// A placed texture viewed from a later level has a host copy of that /// and the smaller levels; a view from an earlier one gets another. #[cfg(windows)] diff --git a/d3d12/docs/switches.md b/d3d12/docs/switches.md index 397b5abc18..8f1986a275 100644 --- a/d3d12/docs/switches.md +++ b/d3d12/docs/switches.md @@ -6,7 +6,7 @@ It says which names exist and what the code's own comments say of them. It is ** settings and says nothing of what a switch gains: for that read [findings.md](findings.md) first, and [how to measure frame rates](../../docs/measuring_fps.md) before trying one. -661 names; 621 have a sentence of a comment below, the others no comment or only a bare list. +662 names; 622 have a sentence of a comment below, the others no comment or only a bare list. - **Kind**: how the code reads it, where that can be told. "see the code" is a number, a path, a list or a switch read some other way; its default is not given here. @@ -527,7 +527,7 @@ and [how to measure frame rates](../../docs/measuring_fps.md) before trying one. | `LEONIDA_TEXBACK_LIGHT` | on, `0` turns it off | yes | | | `leonida-gpu/texback.rs` | Whether read-backs go the light way (`LEONIDA_TEXBACK_LIGHT=0`: as before): a read-back is tiled outside the tickets' lock, which is taken for the write into title memory alone, into memory its thread keeps; and of a lis... | | `LEONIDA_TEXTURE_AWAY_MS` | see the code | | | | `leonida-gpu/descriptor/host.rs` | Only when it is still away `AWAY_MS` after it was first found away (`LEONIDA_TEXTURE_AWAY_MS`; 0: at once, as before). | | `LEONIDA_TEXTURE_BACK` | see the code | | | | `leonida-gpu/texback.rs` | For textures of the kinds in `LEONIDA_TEXTURE_BACK` (comma-separated `<width>x<height>f<format>`; unset or `1`: the four water formats found by the upstream trace; `0`: none), a list in which shaders write one copies it... | -| `LEONIDA_TEXTURE_BUDGET_MB` | see the code | | | | `leonida-gpu/resource.rs` | The limit `LEONIDA_TEXTURE_BUDGET_MB` sets on the bytes of host copies of the title's textures, if it is set. | +| `LEONIDA_TEXTURE_BUDGET_MB` | see the code | | | | `leonida-gpu/resource.rs` | With `LEONIDA_TEXTURE_BUDGET_MB` unset the make-then-evict churn is not what runs: the host copies stayed flat (666 alive, 1 180 MB) while pipelines were still being made. | | `LEONIDA_TEXTURE_CATCHUP` | see the code | | | | `leonida-gpu/draw.rs` | `LEONIDA_TEXTURE_CATCHUP=0` keeps the plain budget. | | `LEONIDA_TEXTURE_COPY` | see the code | | | | `leonida-gpu/texture.rs` | Whether a texture all of whose memory is mapped is read through the kernel's copy instead of in place (`LEONIDA_TEXTURE_COPY=1`; off by default). | | `LEONIDA_TEXTURE_FAVOR_REUSED` | off unless set and not `0` | yes | | | `leonida-gpu/resource.rs` | ...idle ([`let_go_idle`], where the card's room sets a limit; `LEONIDA_TEXTURE_FAVOR_REUSED=1`; off by default; `LEONIDA_AB` can name it).... | @@ -583,6 +583,7 @@ and [how to measure frame rates](../../docs/measuring_fps.md) before trying one. | `LEONIDA_VIEW_THREADS_WIDE` | see the code | yes | | yes | `leonida-gpu/land.rs` | Threads of the pool for the views picked by index ([`each_view`]): as before, and with `LEONIDA_VIEW_THREADS_WIDE=1`. | | `LEONIDA_VIPATCH_NO_VIGNETTE` | see the code | | | | `leonida-gpu/host/menu.rs` +1 | | | `LEONIDA_VOLUME_VIEWS` | see the code | | | | `leonida-gpu/descriptor/host.rs` | ...ead as a volume, levels that are not there), this says so. `LEONIDA_VOLUME_VIEWS=0`: not.... | +| `LEONIDA_VRAM_BUDGET_MB` | see the code | | | | `leonida-gpu/host.rs` +2 | `LEONIDA_VRAM_BUDGET_MB`: the budget of the card's own memory, in bytes, that every decision on it takes in place of the one the system gives ([`crate::host::Host::video_memory`]: the texture queue's room, the card copie... | | `LEONIDA_WAIT_ASK` | see the code | | | | `leonida-gpu/list.rs` | `LEONIDA_WAIT_ASK=1` asks first, as before. | | `LEONIDA_WAIT_FORCE` | see the code | | | | `leonida-gpu/queue.rs` | `LEONIDA_WAIT_FORCE=0` keeps it held: for finding out whether the title's waits reach across its presents; a wait nothing ever meets then stops the title for good. | | `LEONIDA_WAIT_RESIDENT` | see the code | | | | `leonida-gpu/host.rs` | Whether new memory is made resident, and waited for, before anything can name it (on by default; `LEONIDA_WAIT_RESIDENT=0`: as before). | @@ -694,7 +695,7 @@ and [how to measure frame rates](../../docs/measuring_fps.md) before trying one. | `LEONIDA_HDR_CLAMP` | see the code | | | | `leonida-shader/emit/lower.rs` +1 | Whether the float colours a pixel program writes are held to what every HDR format of the console can hold, [-65024, 65024] (on; `LEONIDA_HDR_CLAMP=0`: written as they are, as before). | | `LEONIDA_LDS_EXACT` | see the code | | | yes | `leonida-shader/emit/lds_exact.rs` | `LEONIDA_LDS_EXACT=0` turns this off. | | `LEONIDA_LDS_INIT_HOIST` | see the code | | | yes | `leonida-shader/emit/lds_init.rs` | `LEONIDA_LDS_INIT_HOIST=0` turns it off. | -| `LEONIDA_LEGACY_PLAIN` | see the code | | | | `leonida-shader/emit/lower.rs` +1 | ...ain product where the zero rule cannot apply, on any host (`LEONIDA_LEGACY_PLAIN=1`; off by default): of a value with itself, of two factors known to be finite, and with a finite constant that is not 0; and only the fini... | +| `LEONIDA_LEGACY_PLAIN` | see the code | | | yes | `leonida-shader/emit/lower.rs` +1 | ...ain product where the zero rule cannot apply, on any host (`LEONIDA_LEGACY_PLAIN=1`; off by default): of a value with itself, of two factors known to be finite, and with a finite constant that is not 0; and only the fini... | | `LEONIDA_LOOPS_WAVE` | see the code | | | yes | `leonida-shader/emit/lower.rs` +4 | `LEONIDA_LOOPS_WAVE`: - unset or `1`: console wave64 compute programs on a host of 32-lane waves; - `0`: none; - `2`: every compute program. | | `LEONIDA_LSHL_ADD_SCC` | see the code | | | | `leonida-shader/emit/lower.rs` | `LEONIDA_LSHL_ADD_SCC=0` restores the old lowering. | | `LEONIDA_MED3_CLAMP` | see the code | | | yes | `leonida-shader/emit/lower.rs` | Whether the median of a value and two constants that are normal numbers or infinities is a clamp (`Lower::med3_clamp`; `LEONIDA_MED3_CLAMP=0`: the general form, as before): the same bits, with fewer instructions (bounds... |