Repository navigation
d3d12: lists' scratch stays in the PC's memory by default for now (D3D12-SCRATCH-CARD-OFF-BY-DEFAULT) - #2819
Conversation
…D12-SCRATCH-CARD-OFF-BY-DEFAULT) Part of enlighted's D3D12-REAPER-BOUNDED-QUEUE, agreed with them. Card scratch, on by default where the card's budget is 9 GiB or more and it has a GPU upload heap, churns chunks: SPARE_CARD keeps 256 MiB in all and gives back an exact size only, so chunks of other sizes are let go in the list resets on the reaper and made again on the recording threads. The reaper falls behind and the memory it holds piles up. Measured on an RTX 3090 with a resizable BAR (23 pairs): frame median 64.6 ms with card scratch against 33.3 ms without. It is off by default until the card's spare chunks are kept by size; LEONIDA_SCRATCH_CARD=1 still puts it there and LEONIDA_AB still switches it. A card that used to get it says once that it is off now. switches.md is regenerated for that row.
|
Verified by OreoFR on macOS 27.2.1, Apple M5, head MEASURED
READ IN CODE
ASSUMED
AI-assisted: Claude Code |
|
Verified on Windows, for a merge (not the author). AI-assisted (Claude Code agent Head Tests (
In-game run on the merged build (
Limits: this card's budget is under 9 GiB, so it already had the scratch in the PC's memory before this change: the run shows no regression, not the gain. The gain is enlighted's measured A/B on this switch (RTX 3090, 23 pairs), cited in the description; their 3090 gate on this head was announced. |
|
Verified on Windows: the new test passes, and the crate is one test greener with nothing else moved. The one failure in the crate is
That one failure is red on What the change is, from the code and the doc line together: What I did not run: the title path itself - lists' scratch actually staying in the PC's memory needs a title with lists to allocate, which needs the game. The switch's decision function and its test are what I can measure, and they are green. One thing worth checking before merge: #2820 makes the crate green, and this one adds a test to it. Whichever lands second will need the other's context to look green in CI - AI-assisted: yes - DeepSeek v4.1 (flash), which ran both the new test and the crate. Written with an AI assistant. |
|
RUN (independent run on Windows, #2819 head f8ad7e2, merged locally into main d920d85 with Commands, in
In-game gate on the RTX 3090 (24 GB, NVIDIA 621.40, Windows 11), leonida.exe built from this head (f8ad7e2;
Not checked: Series X, walking, picture; cards between 9 and 16 GB. No runtime/ C++ or Python in this PR, so no link or import check applies. |
|
Merging. Head |
|
Correction to my merge comment above: enlighted's RTX 3090 gate on this head was posted two minutes before the merge (#2819 (comment)): PASS, 527 s in the world, 0 device loss, at the default settings; the reaper pile-up gone (queue max 140, private memory flat at 28.9 GB), median 23.3 fps against 18.0 and 12.1 on main. So the change was also run on a card where it takes effect. AI-assisted (Claude Code agent |
…, guards against churn, and is on again for big cards TheGeogeo turned LEONIDA_SCRATCH_CARD off by default (f8ad7e2, #2819) "until the card's spare chunks are kept by size": the card's pool kept 256 MiB of spare chunks in all, in the order they came, and let go of every chunk given back past it, so the lists' resets freed chunks the recording threads made again (1,158 a second and 35 ms a frame of MakeResident on an RTX 3090). Now: - the card's spare chunks are kept up to a sixteenth of its budget, between 256 MiB and 1 GiB (LEONIDA_SPARE_CARD_MB=<MB> says it), and when the pool is full those kept longest go, not the one given back (Spare::give_evicting); LEONIDA_SPARE_CARD_GROW=0 keeps the old pool, LEONIDA_AB can name it; - a guard sends new chunks to the PC's memory for the rest of the run if more than 1,000 are made in the card's within 10 s (100 a second; this PC's worst was 48 with the old pool), said once; - with both, card scratch is on again where the card's budget is 9 GiB or more, as before #2819. Measured before the change (run d281, RTX 4060 Ti 16 GB, by turns of 4 s standing, the old pool): card scratch on against off, the frame's median -1.15 +-0.36 ms, the card -1.72 +-0.30, with 48 chunks a second made in the card's memory and 3.7 ms a frame waited for their residency. AI-assisted (Claude). Tested on RTX 4060 Ti 16 GB, driver 616.64: cargo check with and without diagnostics, the two new tests (the default by card and switch, the pool letting the oldest go); in-game A/B to follow. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The reaper thread's channel had no bound and nothing slowed its senders. On an RTX 3090 its line grew to hundreds of thousands of things in most runs; the landed host lists waiting there kept their scratch chunks, and the runs that were not stopped ended in a device loss as private memory neared Windows' commit limit, while LEONIDA_REAPER=0 kept memory flat. The lists' scratch was in card memory; it is in PC memory by default since #2819, where the line should stay short. This bound is the safety net for LEONIDA_SCRATCH_CARD=1 and any other cause of a backlog. Once the line (REAPING) holds LEONIDA_REAPER_LIMIT things (4096 by default; 0: no bound, as before; LEONIDA_AB can turn it on and off), what the host is done with is let go of by the thread done with it, as LEONIDA_REAPER=0 does. land(), bury() and fronts_let_go() go through one helper (reap), which counts each batch as the reaper thread takes it off; the check and the count are one atomic step (hand_over), so the line holds fewer than the bound and one batch however many threads send. A batch comes off the line also if letting it go panics. The first time the bound takes hold is logged once; the census memory line counts what was let go in place (REAPED_IN_PLACE) and says the bound. Diagnostics only: host lists and preludes made per frame by the title's threads, the submitting thread and the others, with their time; a SPLIT slot for preludes made and recorded; HostList::reset split into what the list held let go and the allocator and list resets. Claim: D3D12-REAPER-BOUNDED-QUEUE Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claimed in the coordination issue as: D3D12-SCRATCH-CARD-OFF-BY-DEFAULT (#2570 (comment)), part of enlighted's D3D12-REAPER-BOUNDED-QUEUE (#2570 (comment)), agreed with them.
What and why
Lists' scratch memory goes into the card's own memory, where the CPU maps it, on cards whose budget is 9 GiB or more at the first ask and that have a GPU upload heap (resizable BAR). This came with 7b907de. On those cards it churns chunks:
SPARE_CARDkeeps 256 MiB in all and gives back an exact size only (Spare::take/give).MakeResident.Measured by enlighted on an RTX 3090 24 GB with a resizable BAR, standing 600 s, with
LEONIDA_ABon this switch over 23 pairs:MakeResidentper frameThis turns it off by default for now, until enlighted's pool that keeps the card's spare chunks by size lands. That pool will turn it back on.
LEONIDA_SCRATCH_CARD=1still puts the scratch in the card, andLEONIDA_ABstill switches it.d3d12/docs/switches.mdis regenerated. Only that switch's row changes.Tested
On Windows 11 Pro 10.0, Rust 1.98.1 pinned:
cargo test -p leonida-gpu --lib --locked scratch_card:host::scratch_card_tests::card_scratch_is_off_unless_asked_forpasses. It checks that nothing,0or another value means off, and that1means on.main: the test needs the newscratch_card_chosen, so it does not build there. The behaviour it pins is the default flip, read inscratch_card(). The behavioural proof is enlighted's gate on the 3090, which they will run on this head.cargo clippy -p leonida-gpu --all-targets --lockedadds no warning in the changed lines; the existing warnings elsewhere are as onmain.tools/d3d12_switches.py --check d3d12/docs/switches.md, the docs tests andscripts/check_no_game_data.pyare clean. It merges cleanly with currentmain.GPUs tested: NVIDIA GeForce RTX 3080 10 GB, driver 32.0.16.2140: build and unit test only. This card has no GPU upload heap, so the change has no effect on it in game.
AI-assisted: yes
Checklist
mainand merges cleanly (a conflicting pull request is labeledneeds rebase).docs/design.md, with how it was confirmed. (n/a: no translator change)