d3d12: keep a minimum of the game in memory on PCs with little RAM (D3D12-MIN-WORKING-SET) #3198
Open
github-bot
wants to merge 5 commits from
github-bot/gh-3198 into main
AGit
pull from: github-bot/gh-3198
merge into: github:main
github:main
github:perf/darner-title-priority-ceiling
github:gh-readonly-queue/main/pr-3311-b5c45b663dbc5a9c3532bb3f307e5f81b32faefa
github:gh-readonly-queue/main/pr-3088-af22e7847ff5808f72d1a1881c24be2fafd20b54
github:gh-readonly-queue/main/pr-3123-7f3fa026a94c6646e89244f28e1ce22290361867
github:gh-readonly-queue/main/pr-3354-637baa0b77ba47222e7280b17c1a59c6a1781d57
github:gh-readonly-queue/main/pr-3365-d7a0e0196a43834813014b4bd3aa5502a8263b14
github:gh-readonly-queue/main/pr-3361-5dfe8bbd05ed12fb2f2e1718d9af77a7c5f46fd8
github:gh-readonly-queue/main/pr-3366-8da9148204e9d12c585efa9ac2b7cc1ab08c7682
github:fix/runtime-test-conservative-fixtures
github:ci/shard-semantic-linux
github:docs/fg-limit-fps-switch
github:fix/runtime-test-fixture-paths
github:fix/runtime-test-fixture-readers
github:fix/read-file-hard-link
github:fix/book-slot-heap-never-read
github:fix/depth-resolve-spv-path
github:fix/indirect-unused-batched
github:gh-pr/3358/base
github:fix/xmem-refusal-diagnostics
github:gh-pr/3357/base
github:ci/shorten-ci-time
github:fix/alias-later-queued-submissions
github:claude/gallant-sagan-aamatr
github:gh-pr/3342/base
github:gh-pr/3341/base
github:d3d12/agility-sdk-621
github:gh-pr/3293/base
github:gh-pr/3319/base
github:gh-pr/3318/base
github:gh-pr/3315/base
github:gh-pr/3313/base
github:gh-pr/3314/base
github:claude/fervent-curie-m19lnr
github:gh-pr/3216/base
github:gh-pr/3272/base
github:gh-pr/3276/base
github:gh-pr/3279/base
github:gh-pr/3257/base
github:gh-pr/3258/base
github:gh-pr/3271/base
github:codex/skip-no-hit-ray-passes
github:gh-pr/3230/base
github:gh-pr/3266/base
github:gh-pr/3247/base
github:gh-pr/3246/base
github:gh-pr/3244/base
github:claude/sharp-sagan-1jqnp3
github:t3/preserve-fsr-sdk-restart-path
github:t3/propagate-host-failure-hresult
github:t3/launcher-custom-parameters
github:t3/series-x-2160-startup
github:codex/d3d12-uncapped-simulation
github:ci/less-to-run
github:perf/native-compute-shader-forms
github:claude/blissful-franklin-ukp7ag
github:codex/full-precompile-default
github:gh-pr/3166/base
github:gh-pr/3148/base
github:gh-pr/3138/base
github:gh-pr/3106/base
github:gh-pr/3057/base
github:gh-pr/2756/base
github:gh-pr/2812/base
github:gh-pr/3032/base
github:gh-pr/2992/base
github:notes/card-time-and-plant-flicker
github:gh-pr/2986/base
github:gh-pr/3000/base
github:gh-pr/2966/base
github:gh-pr/2924/base
github:gh-pr/726/base
github:gh-pr/2761/base
github:gh-pr/2663/base
github:gh-pr/2861/base
github:gh-pr/2862/base
github:gh-pr/2820/base
github:gh-pr/2811/base
github:gh-pr/2803/base
github:rt-call-trace
github:gh-pr/2802/base
github:gh-pr/2766/base
github:perf/ahead-split
github:gh-pr/2589/base
github:gh-pr/2699/base
github:gh-pr/2696/base
github:docs/readme-runtime-proposal
github:gh-pr/1346/base
github:codex/coord-claim-check-20261124-7e48
No reviewers
Labels
Clear labels
accessibility
Barrier affecting people with disabilities
area: ci
.github/ workflows and settings
area: d3d12
The D3D12 runtime in d3d12/ (Rust: leonida.exe and its crates)
area: docs
Documentation
area: launcher
The launcher (launcher/)
area: runtime (legacy)
The earlier Vulkan runtime in runtime/
area: shader translator
The shader translator (leonida-shader, tools/rdna2spirv) and its tests
area: tools
tools/ and scripts/
area: viewer
The map viewer (viewer/)
bug
Something isn't working
dependencies
Pull requests that update a dependency file
documentation
Improvements or additions to documentation
duplicate
This issue or pull request already exists
enhancement
New feature or request
good first issue
Good for newcomers
help wanted
Extra attention is needed
invalid
This doesn't seem right
missing claim
Needs a claim in #14
needs in-game run
Changes the code a frame runs through: needs the 300 s in-game gate (docs/game_gate.md)
needs rebase
Conflicts with the base branch: rebase it on main
needs-triage
Needs maintainer evaluation before the next triage state
question
Further information is requested
ready-for-agent
Fully specified and ready for an AFK agent
submodules
Pull requests that update submodules code
wontfix
This will not be worked on
No labels
accessibility
area: ci
area: d3d12
area: docs
area: launcher
area: runtime (legacy)
area: shader translator
area: tools
area: viewer
bug
dependencies
documentation
duplicate
enhancement
good first issue
help wanted
invalid
missing claim
needs in-game run
needs rebase
needs-triage
question
ready-for-agent
submodules
wontfix
Milestone
Clear milestone
No items
No milestone
Assignees
Clear assignees
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".
No due date set.
Dependencies
No dependencies set
Reference
github/ubiquitarianism--leonida!3198
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-3198"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@pranjalprateek6 on GitHub · 2026-12-02 18:27 UTC · original
pranjalprateek6:d3d12-min-working-set→main· +408 −4 · 4 files · 5 commits · openClaimed in the coordination issue as: D3D12-MIN-WORKING-SET (#2570)
Related claim, no pull request yet: D3D12-WORKING-SET-TRIM (#2570) trims the working set under pressure. Both are opt-in; with both on, this minimum is a floor under any trim. Also related: #3332 (D3D12-ROLLING-TRIM), which lets go of pages nobody touches.
What and why
The problem. On a 16 GB laptop the game holds about 21 GB of private memory a minute into the world, and Windows keeps about 5 GB of it in memory; the PC reads pages in at about 110 MB/s. Walking, the frame stalls in bursts that follow the scene: in them the submitting thread runs 10 to 17 % of the time it records preludes. A Windows Performance Recorder capture of 78 s shows page-ins as part of it:
The details are in the new section of
d3d12/docs/findings.md.The change.
LEONIDA_MIN_WORKING_SET_MB(unset or 0: off, as before) asks Windows once, when the host device is made (host()), for a hard minimum working set:SetProcessWorkingSetSizeExwithQUOTA_LIMITS_HARDWS_MIN_ENABLE(residency::keep_working_set_minimum).GetProcessWorkingSetSizeEx; the maximum, and whether it is enforced, stay as they are.residency::pressuredcomes sooner (it limits texture prefetch).Not changed. No launcher default. To try it:
-More @{LEONIDA_MIN_WORKING_SET_MB='6144'}.d3d12/docs/findings.mdgets the measurements, andd3d12/docs/switches.mdis regenerated withtools/d3d12_switches.py.Tested
The in-game numbers below were taken with the first form of the call, which also set the maximum to the PC's physical memory, not enforced. With the maximum kept they have not been taken again, so they do not show the effect of the minimum alone (
findings.mdand the function's comment say so too). The runs of others in the comments were made on80a627bb1, before this change.In game, on the hardware below: the diag build with DLSS, Series S, no frame generation, the same scripted walk in a circle from one save, a web browser closed.
Within one run. By turns of 15 s (
LEONIDA_AB, 49 phases), using a scratch switch around the same call, since the setting itself is read once:The submitting thread and the card show it; the frame's median does not clear 0 within the run. The phases without the minimum keep what the phases with it kept in memory, which narrows the difference.
Across separate starts (medians of the frame lines' 5 s windows):
Pages read in on the PC (
Memory\Pages Input/sec, medians over minutes 2 to 6 of the walk, one run each): 105 MB/s without it, 94 with it flipped every 15 s, 81 with it throughout.No errors in any run. The setting's log line showed the value applied (6,144 MB, not cut).
residency::tests::a_working_set_minimum_is_what_is_asked_and_at_most_half_the_memorypins: nothing asked, a size below the cap, exactly half (not cut), cut to half, huge values (no wrap), and a memory too small to keep anything.a_minimum_keeps_the_maximum_and_its_enforcementanda_minimum_is_in_force_when_windows_holds_at_least_that_hard(the decisions, without Windows) andwindows_takes_a_minimum_and_keeps_the_maximum(against Windows, on a command prompt started for the test, so the test process's own limits stay; it passed without any privilege enabled).cargo test -p leonida-gpu --lockedon this branch withmain09273248cmerged: 733 passed, 0 failed, 59 ignored.cargo clippy -p leonida-gpu --all-targets --locked: nothing inresidency.rs. Clippy with-D warningsalready fails onmain, per.github/workflows/d3d12.yml.python -I scripts/check_no_game_data.pyon the four files: clean.python -I tests/test_d3d12_switches.py: OK.python -m unittest discover -s tests -p "test_docs_*.py": 59 tests OK.texture::alias_cast_tests::committed_and_placed_r32_uint_textures_cast_to_r9g9b9e5_under_legacy_barriersis flaky under the parallel test runner on unchanged code (it failed 1 of 3 fullcargo test -p leonida-gpu --features diagnostics --libruns ona252854a2, and passes alone). No game files are needed to see it; seen on the hardware below.GPUs tested: NVIDIA GeForce RTX 5060 Laptop GPU 8 GB, driver 621.40, Windows 11 Home 26300 (Intel Core Ultra 7 255HX, 16 GB RAM)
AI-assisted: yes (AI coding assistant). A separate, read-only AI reviewer checked the diff before opening; the findings section and the code comment were rewritten after that check. Two more such reviews, on 3 December, checked the rewritten text with
mainmerged, and the corrections they asked for are in this version. The change that keeps the maximum was checked by another one before it was pushed, and again after its findings were worked in.Checklist
mainand merges cleanly (a conflicting pull request is labeledneeds rebase).docs/design.md, with how it was confirmed. (n/a: no translator change)@lixonik on GitHub · 2026-12-02 20:26 UTC · original
RUN (in game) -- unit tests + 300 s render-path verification for PR #3198:
80a627bb1mainSHA:f1a559851(git merge --no-ff, clean merge)python -I scripts/check_no_game_data.pyPASSpython -I tools/d3d12_switches.py --check d3d12/docs/switches.mdPASScargo test -p leonida-gpu --features diagnostics --lib --locked residency::-- 4 passed, 0 failed (includinga_working_set_minimum_is_what_is_asked_and_at_most_half_the_memory)diagprofile (diagnostics,dlss,mimalloc), Series S profile, DLSS on, Frame Gen off,LEONIDA_MIN_WORKING_SET_MB=4096, same restored save snapshot80a627bb1onf1a559851,MIN_WORKING_SET_MB=4096)mainalone (f1a559851)Loaded cleanly into the world with
LEONIDA_MIN_WORKING_SET_MB=4096, stayed up past 300 s in-world with 0 device lost / 0 crashes / 0ERRORlines, and closed cleanly. Rendered FPS matchesmain(26.9vs27.2fps).Verdict: PASS.
AI-assisted: yes (Antigravity).
@merzleckeier on GitHub · 2026-12-02 20:31 UTC · original · reviewed
Source review on
80a627bb. This also changes the maximum working-set policy.residency.rs:301–302always sets the maximum to physical RAM and disables hard maximum enforcement. Microsoft documents that the soft maximum still guides trimming when memory is scarce, and a hard maximum can already be configured. Thus the current call can relax another limit and the on/off measurement changes both settings. Could you read the current limits and flags withGetProcessWorkingSetSizeEx, preserve the maximum and its enforcement where possible, and document or decline a request above an existing hard maximum? If a soft maximum must rise to accommodate the minimum, raising it only that far would isolate the change. Set API · Get API. Source review only; I did not repeat the Windows workload. AI-assisted.@EdenBendheim on GitHub · 2026-12-02 21:01 UTC · original
RUN (in-game RTX 3090 300 s stress gate, 14-PR combined batch) — PASS covering exact head
80a627bb19421c51a5c04ab3caaf675b12a07554.git merge --no-ffontomainb41763227(diagnostics,dlss,mimalloc,exe_sha16 = c47eeb717f761d9d; changed-file clean-room scan exit0; workspace test targets compiled).14PRs):#3200d1a91afd1,#319880a627bb1,#319193b47ac9d,#3189c182fc392,#3176ae0075d9a,#3168337388052,#31641065952da,#3146ebc0253ff,#312464600ef0c,#3069311d33a40,#30318df1bfce7,#3029e49404808,#3054ff53fd8b9,#3010d645712a3.610.88, Series X profile,2560x1440,-NoFrameGen,scripts/game-gate.ps1(301.3 sin world) with downtown street-level teleport + 8-leg dynamic sprint/turn/strafe stress mod (GATE CONTROL moved=2.51 m,max_from_ctrl=5,053.9 m).c47eeb717f761d9d)mainb41763227baseline (cf499737bf684f6a)clean,0reasons,0warnings)clean,0reasons,0warnings)301.3 s(4,504frames)305.6 s0/0/00/0/020.10 FPS/69.76 ms19.13 FPS/74.01 ms8,048/5.222 s7,983/2.358 s35,619 MB/15,251 MB37,803 MB/16,220 MBVerdict: PASS for the 300 s in-game stability gate on
80a627bb1. (Single combined-batch stability check on a 32 GB RAM host, not a low-RAM/single-PR isolated measurement; if the head changes, this run no longer covers it.)(AI-assisted verification:
gemini-4-neon+gpt-6.2-astra.)@fiestorra on GitHub · 2026-12-02 21:02 UTC · original
VERIFY-3198 — Windows nativo: el test nuevo muerde y la suite sigue igual
(this PR)b41763227= currentmainmain— cleanRan
The one failure is this machine's, unchanged all day:
descriptor::host::tests::views_are_made_beside_the_heap_and_copied_in(the iGPU artefact ofD3D12CreateDevice(None, ..)that #2995 addresses).Negative control (synthetic, the test ships with the change): I removed the half-memory cap in a copy (
let bytes = asked), rebuilt and ran →FAILED: a_working_set_minimum_...,assertion left == right failed: cut to half. The test bites, and it covers the edges I would want: 0 = none, exactly half is not cut, over half is cut,u64::MAXdoes not wrap, and a 1-byte PC asks for nothing.The design reads safely:
LEONIDA_MIN_WORKING_SET_MBis opt-in (unset or 0 → as before), parsed with a warning on a non-number, capped at half ofullTotalPhys, asked for once when the host device is made,QUOTA_LIMITS_HARDWS_MIN_ENABLE | QUOTA_LIMITS_HARDWS_MAX_DISABLE(a hard minimum, a soft maximum), and a refusal is atracing::warn!that changes nothing. The docs are the honest kind:findings.mdhas the 16 GB laptop case (RTX 5060, WARP capture, hard faults) and names the cost — that memory is not other programs' while the game runs, sopressuredcomes sooner.What I could not test
SetProcessWorkingSetSizeExcall on a real device: the test covers the arithmetic, not the API's acceptance on this machine (it would needLEONIDA_MIN_WORKING_SET_MBset at start and a device — not exercised).Written with an AI assistant.
@MoonEyes on GitHub · 2026-12-03 07:01 UTC · original
This pull request has a merge conflict with current
main(d9b618f10), so it can't be run in game or merged as it is. Could you merge the latestmaininto it (or rebase onto it) and resolve the conflict? Once the head is updated, the in-game gate run can be done on the new head.AI-assisted (Claude Code).
@fiestorra on GitHub · 2026-12-03 09:32 UTC · original
#3198rebasada y empujada:pr-3198-rebased=8903c6967— y las dos secciones defindings.mdque chocaban eran distintas, así que van las dosEs el primer conflicto de esta serie que no era una sola línea, y por eso lo resuelvo de otra forma y lo digo:
Y la decisión de
findings.mdno es una estrategia, es una lectura:findings.mdes un registro cronológico de medidas — cada sección es una medición con su fecha, su tarjeta y su driver — y dos entradas distintas no se pisan: se suman. Si hubieran sido el mismo título, habría tenido que leer cuál manda.Los números:
Y
716contra los715demain: un test nuevo, en los 2 ficheros.rsque toca.Rama
pr-3198-rebaseden el fork, y con esta van trece de los 22.Lo que me queda por delante, y es lo honesto: los cinco que chocan en código Rust de verdad (
#2567,#2856,#3115,#3197,#3205) y los cinco de varios commits con código (#2580,#3124,#3130,#3209,#3214) — esos no los toco con un script, y decir que «se rebasan» sin haberlos mirado sería exactamente el error de esta noche.@Lanworm on GitHub · 2026-12-03 17:47 UTC · original
RUN (in game, 8 alternating runs A B B A A B B A, 32 GB desktop): no gain here. Windows already keeps about 28 GB of the game in memory, and the tool's verdict is "B slower" by 0.4 ms (1 %), at the edge of the noise.
diagbuild (diagnostics,dlss,mimalloc,d3d12/scripts/build-nvidia.ps1) ofmainf99e479fwith this PR's head80a627bbmerged. The only conflict was ind3d12/docs/switches.md, which was taken frommain. The code merged cleanly.LEONIDA_MIN_WORKING_SET_MB=12288, the same share of RAM as your 6,144 of 16 GB. Every B log has the lineat least this much of the game is kept in the PC's memory ... mb=12288 cut_to_half_the_memory=false.-NoFrameGen.LEONIDA_KEYS_FILE, and each run was closed withWM_SYSCOMMAND/SC_CLOSE, asscripts/game-gate.ps1does.python -I tools/d3d12_ab_compare.py abba, world median frame time:Memory, sampled every ~5 s in the world. Each figure is a run's median, given as the range over that side's 4 runs:
Memory\Pages Input/secresidencyreported the PC's memory as under pressure in 98 % of its one-second looks on both sides (248 to 261 of 252 to 266 per run), with no difference between A and B.What this says:
residencyreports pressure equally often on both sides. The frame time also rose through the series (39.6 → 42.5 ms), and the ABBA order only removes a straight-line drift. So I read it as "no gain, at most about 1 % lost" rather than as a measured cost.Only numbers are quoted here: no logs, captures or game data.
AI-assisted: yes (Claude Code, Claude Opus 5.5). The runs were driven and analysed by the assistant on the submitter's machine.
@pranjalprateek6 on GitHub · 2026-12-03 17:54 UTC · original · edited 2026-12-03 18:01 UTC
Done in
d17b595b6, thank you. The limits are read first withGetProcessWorkingSetSizeEx, and only the minimum changes:Three new unit tests, one of them against Windows on a process of its own. The old call fails two of them; the third covers the read-back.
You are right that the measurements changed two settings: they were taken with the first form of the call and have not been taken again. The description,
findings.mdand the function's comment say so.main(09273248c) is merged.AI-assisted: yes (AI coding assistant).
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.