diff --git a/d3d12/crates/leonida-gpu/src/host.rs b/d3d12/crates/leonida-gpu/src/host.rs index b22544b398..d1fc0f5b94 100644 --- a/d3d12/crates/leonida-gpu/src/host.rs +++ b/d3d12/crates/leonida-gpu/src/host.rs @@ -2432,9 +2432,19 @@ const SPARE_CARD_MOST: u64 = 256 << 20; /// Leonida: whether lists' scratch memory lies in the card's own memory, which the CPU maps and /// writes through the bus (`D3D12_HEAP_TYPE_GPU_UPLOAD`, a resizable BAR), instead of upload -/// memory in the PC's: on where the card's budget is 9 GiB or more at the first ask (cards of 12 GB -/// and up; it holds some hundreds of MB more of the card's memory, at most [`SPARE_CARD_MOST`] of -/// them idle), `LEONIDA_SCRATCH_CARD=1` or `0` either way, `LEONIDA_AB` by turns. +/// memory in the PC's: `LEONIDA_SCRATCH_CARD=1` (it holds some hundreds of MB more of the card's +/// memory, at most [`SPARE_CARD_MOST`] of them idle), `0` or unset not, `LEONIDA_AB` by turns. +/// +/// Off by default for now ([`scratch_card_chosen`]). It was on where the card's budget is 9 GiB or +/// more at the first ask and the card has a GPU upload heap, until the card's spare chunks are kept +/// by size: [`SPARE_CARD`] keeps [`SPARE_CARD_MOST`] in all and gives back an exact size only, so +/// chunks of other sizes are let go and made again without end. Those releases run in the list +/// resets on the reaper, which falls behind, and the lists and memory it holds pile up. Measured +/// (RTX 3090 24 GB with a resizable BAR, standing 600 s, `LEONIDA_AB` on this switch, 23 pairs, +/// 2026-12-01): the frame's median 64.6 ms with card scratch against 33.3 ms without; 1,158 chunks +/// made a second against 0; `MakeResident` 35.4 ms a frame against 0.01; the card busy 34.3 +/// against 32.9 ms a frame. What it gave (below) is lost meanwhile; the pool kept by size turns it +/// back on. /// /// What lists put there is read by the card at the head of a draw's work: the constant buffers /// of tables made afresh (some 23,000 a frame, 9 MB, `port_cbv.rs`), root constant buffers not on @@ -2455,13 +2465,39 @@ fn scratch_card(host: &Host) -> bool { return on; } static ON: OnceLock = OnceLock::new(); - *ON.get_or_init(|| match std::env::var(SWITCH).as_deref() { - Ok("0") => false, - Ok("1") => true, - _ => host.video_memory().is_some_and(|[budget, ..]| budget >= 9 << 30), + *ON.get_or_init(|| { + let on = scratch_card_chosen(std::env::var(SWITCH).ok().as_deref()); + // Said once where it used to be on by default, so that a tester knows what changed. + let was_on = host.video_memory().is_some_and(|[budget, ..]| budget >= 9 << 30); + if !on && was_on && host.mapped_card_memory() { + tracing::info!( + "lists' scratch stays in the PC's memory: off by default for now ({SWITCH}=1 \ + puts it in the card's, which a card like this one used to get)" + ); + } + on }) } +/// [`scratch_card`] as `LEONIDA_SCRATCH_CARD` says: on with `1` only, off by default for now. +fn scratch_card_chosen(switch: Option<&str>) -> bool { + switch == Some("1") +} + +#[cfg(test)] +mod scratch_card_tests { + use super::scratch_card_chosen; + + #[test] + fn card_scratch_is_off_unless_asked_for() { + // Off by default whatever the card (it churned chunks, the reaper piled up); `1` keeps it. + assert!(!scratch_card_chosen(None)); + assert!(!scratch_card_chosen(Some("0"))); + assert!(!scratch_card_chosen(Some("yes"))); + assert!(scratch_card_chosen(Some("1"))); + } +} + /// Whether a list's read-back buffers are kept, when the list is reset, for /// the next read backs of their sizes (`LEONIDA_READ_BACK_POOL=0`: each is /// made for its read back and let go with its list, as before; `LEONIDA_AB` diff --git a/d3d12/docs/switches.md b/d3d12/docs/switches.md index 86e60d6c4b..1fe9306d6d 100644 --- a/d3d12/docs/switches.md +++ b/d3d12/docs/switches.md @@ -471,7 +471,7 @@ and [how to measure frame rates](../../docs/measuring_fps.md) before trying one. | `LEONIDA_SAMPLERS_AGAIN` | on, `0` turns it off | yes | | | `leonida-gpu/descriptor.rs` | Leonida: a sampler heap is looked through whole every so often, for a record the calls and the written pages both missed (`HostHeap::samplers_again`; `LEONIDA_SAMPLERS_AGAIN=0`: not). | | `LEONIDA_SAMPLE_MASK` | see the code | | | | `leonida-gpu/list.rs` +1 | `LEONIDA_SAMPLE_MASK=0`: ignored, as before. | | `LEONIDA_SCISSOR_TEST` | see the code | | | | `leonida-gpu/draw.rs` | An experiment on the title's scissor rectangles (`LEONIDA_SCISSOR_TEST=full`): they are all widened to the whole target. | -| `LEONIDA_SCRATCH_CARD` | see the code | yes | | yes | `leonida-gpu/host.rs` | ... card's memory, at most [`SPARE_CARD_MOST`] of them idle), `LEONIDA_SCRATCH_CARD=1` or `0` either way, `LEONIDA_AB` by turns.... | +| `LEONIDA_SCRATCH_CARD` | see the code | yes | | yes | `leonida-gpu/host.rs` | `LEONIDA_SCRATCH_CARD=1` (it holds some hundreds of MB more of the card's memory, at most [`SPARE_CARD_MOST`] of them idle), `0` or unset not, `LEONIDA_AB` by turns. | | `LEONIDA_SCRATCH_POOL` | see the code | | | | `leonida-gpu/host.rs` +1 | `LEONIDA_SCRATCH_POOL=0`: chunks of 4 MiB kept by their list, as before. | | `LEONIDA_SCREEN_WAIT_MS` | see the code | | | | `leonida-gpu/pipeline/make.rs` | As [`wait_budget`], for passes over the screen (`LEONIDA_SCREEN_WAIT_MS`, 10 s; 0: like the others). | | `LEONIDA_SECTION_MB` | see the code | | yes | yes | `leonida-gpu/inplace.rs` +2 | `LEONIDA_SECTION_MB=<MiB>` makes an allocation of sections of that many MiB at most (unset, 0 or not a number: all its pages in one section, as before). |