Skip to content

leonida-gpu: LEONIDA_VRAM_BUDGET_MB sets the card's budget in place of the system's - #2765

Open
ajussak wants to merge 2 commits into
ProjectLeonida:mainfrom
ajussak:feat/vram-budget
Open

ajussak wants to merge 2 commits into
ProjectLeonida:mainfrom
ajussak:feat/vram-budget

Conversation

@ajussak

@ajussak ajussak commented Nov 30, 2026

Copy link
Copy Markdown

What and why

Under Wine or Proton the budget DXGI reports for the card is what Vulkan reports as left to the process,
not what the card has free, and above the card's free memory NVIDIA's driver fails allocations instead of
moving them to the PC's memory as Windows does (GPU faults, Xid). LEONIDA_VRAM_BUDGET_MB sets the budget
the runtime works to instead: Host::video_memory hands it to every decision on the card's memory (the
texture queue's room, the card copies of title buffers, the staging per frame). Unset, empty or not a
number of MB: the system's, as before. The log says it once, with the system's budget beside it.

Tests

  • cargo xwin test -p leonida-gpu --target x86_64-pc-windows-msvc under Wine 11.21, RTX 3060 Ti
    (NVIDIA 620.73.4): 569 passed, 3 failed, 52 ignored. The resource tests are 21/21, including
    resource::tests::a_fixed_card_budget_is_a_size_in_mb (failing before, passing after) and
    resource::tests::texture_floor_scales_with_vram_budget. The three failures are watch::
    (holes_are_known_until_the_runtime_tells, no_mapping_is_lost_between_askers,
    what_is_left_alone_is_no_known_hole), the ones that fail under Wine on main without this change.
  • A run with LEONIDA_VRAM_BUDGET_MB=7000 on an RTX 3060 Ti 8 GB (NVIDIA 620.73.4, GE-Proton11-14): no
    Xid, the card held about 600 MB more.
  • d3d12/docs/switches.md regenerated with tools/d3d12_switches.py; --check passes. The page also
    lists the three names main added since it was last made (LEONIDA_CAPTURE_SHOWN,
    LEONIDA_FG_RESET_STALE, LEONIDA_TIMELINE_STALL_MS).

Notes

Rebased onto main at 35e75b7a9; no other change. Independent of the Linux launcher work: nothing here
touches scripts/, and the variable is read where the card's budget is decided, so the two merge in either
order.

Item: LEONIDA-GPU-VRAM-BUDGET-MB, claimed in
#2570.
AI-assisted (Claude Code).

@ajussak
ajussak marked this pull request as ready for review November 30, 2026 16:55
@github-actions github-actions Bot added the needs rebase Conflicts with the base branch: rebase it on main label Nov 30, 2026
@Kal0s-design

Copy link
Copy Markdown
Contributor

Native Windows check of bd0114806 (on its base 35e75b7a9). Windows 11, MSVC x64, Rust 1.98.1, hardware GPU, cargo test -p leonida-gpu --lib, native rather than xwin/Wine.

  • 572 passed, 0 failed, 52 ignored. The three watch:: tests that fail in your Wine run (holes_are_known_until_the_runtime_tells, no_mapping_is_lost_between_askers, what_is_left_alone_is_no_known_hole) pass here, which supports your reading that they're Wine-only and not this change.
  • resource::tests: 19 passed, including a_fixed_card_budget_is_a_size_in_mb, texture_floor_scales_with_vram_budget and budget_capped_keep_evicts_before_vram_pressure.
  • Red as a run isn't possible here: against the base without the change the new test doesn't build (fixed_card_budget is new, E0425).
  • Heads-up: this branch no longer merges cleanly into current main (d8ca18240). git merge conflicts in d3d12/docs/switches.md only. Since that page is generated, regenerating it with tools/d3d12_switches.py after merging main should be enough.

Not covered: a run with LEONIDA_VRAM_BUDGET_MB in the title (native Windows wasn't the case it's for).

AI-assisted: yes

@ajussak

ajussak commented Nov 30, 2026

Copy link
Copy Markdown
Author

Thanks — that closes the two things I could not check here: the three watch:: failures are Wine-only, and resource:: is green on plain MSVC.

The conflict you flagged is handled: rebased onto d8ca18240 and, as you suggested, d3d12/docs/switches.md regenerated with tools/d3d12_switches.py (--check passes). It also picks up LEONIDA_FRAME_TIMES, LEONIDA_MERGE_CARD_COPIES, LEONIDA_MERGE_PC_COPIES, LEONIDA_PIPELINE_AWAIT_FIRST and the LEONIDA_AB column of LEONIDA_HOST_RDNA and LEONIDA_NAN_EXACT, which main added after the page was last made. cargo xwin test -p leonida-gpu resource:: under Wine on the new base: 21 passed; the PR is mergeable again (5122c6a).

Agreed on the last point: the one number I have for the title with the variable set is a Wine run (7,000 MB on an RTX 3060 Ti 8 GB, no Xid). A native Windows run is the case the variable was written for, if you or anyone can try it.

@github-actions github-actions Bot added needs rebase Conflicts with the base branch: rebase it on main and removed needs rebase Conflicts with the base branch: rebase it on main labels Nov 30, 2026
@ajussak
ajussak force-pushed the feat/vram-budget branch 2 times, most recently from f49a9eb to cba289a Compare November 30, 2026 23:03
@github-actions github-actions Bot added needs rebase Conflicts with the base branch: rebase it on main and removed needs rebase Conflicts with the base branch: rebase it on main labels Nov 30, 2026
@fiestorra

Copy link
Copy Markdown
Contributor

The code is fine and its test passes; the docs table is what conflicts, and the branch is carrying commits main does not have - so it needs a rebase before it can be merged.

Measured on main d920d850d:

git merge-tree --write-tree origin/main <head>
  CONFLICT (content): Merge conflict in d3d12/docs/switches.md

And the tree pieces:

d3d12/docs/switches.md
  merge-base (eec86d0fa): 7cb7061
  main (d920d850d):       86e60d6
  this head:              e5b8f5c

git rev-list --count eec86d0fa..origin/main   ->  0

0 commits from the merge base to main while the file differs at both ends means the merge base is not behind main - the branch contains commits main does not have, and switches.md is where they meet. That is a rebase, not a code problem.

The code, applied on its own to main, is clean and its test passes:

cargo test -p leonida-gpu --lib fixed_card_budget
  ok. 1 passed; 0 failed; 636 filtered out

So fixed_card_budget(setting: Option<&str>) -> Option<u64> lands and answers: mb << 20 for a whole number of MB in 256..=1 << 20, None otherwise or unset - and the doc comment's claim that an unset value means the system's budget is the behaviour the test covers.

What I could not verify: the part of the comment that matters most - "set above what the card has free, allocations fail rather than move to the PC's memory" - needs a title allocating against a constrained budget, which needs the game. I did test that shape once from the outside (VK_EXT_memory_budget, where heapBudget was 23,370 MiB on a 24,138 MiB heap), so the switch is aimed at something real; whether it behaves as described under Wine is not something this machine can show.

AI-assisted: yes - DeepSeek v4.1 (flash), which applied the code alone after the full cherry-pick conflicted.

Written with an AI assistant.

@ajussak

ajussak commented Dec 1, 2026

Copy link
Copy Markdown
Author

Thanks for the trace. The conflict is the generated page, and that is the only thing in this branch that moves: d3d12/docs/switches.md comes from the sources (tools/d3d12_switches.py), and main has rewritten it four times in the last 59 commits, so it conflicts on every rebase. Regenerating it on the new base is the whole resolution, and --check passes afterwards.

Rebased onto 90c514437 and pushed (94c3507): cargo xwin test -p leonida-gpu resource:: under Wine, 21 passed; the PR is mergeable again. The page's diff is now LEONIDA_VRAM_BUDGET_MB plus what main changed in it since it was last made (LEONIDA_WC_SUBRANGE_NO_BACK, the source cells of LEONIDA_TAKE_BLOCKS and LEONIDA_WC_NO_BACK).

One correction on the merge base: rev-list --count eec86d0fa..origin/main returning 0 only means your origin/main was at eec86d0fa. A PR branch being ahead of main is normal; what blocks the merge is the page, and regenerating it clears it.

On what you could not verify: yes, that is the gap. VK_EXT_memory_budget reporting a heap budget below the heap's size is exactly the shape the switch uses. A native Windows run that sets the variable against a title load would close it.

@fiestorra

Copy link
Copy Markdown
Contributor

finding: this now conflicts with main, and the merge that did it landed ten minutes ago.

gh pr view 2765 --json mergeable,mergeStateStatus   ->  CONFLICTING DIRTY

git merge-tree --write-tree origin/main <head>
  CONFLICT (content): Merge conflict in d3d12/crates/leonida-gpu/src/resource.rs
  CONFLICT (content): Merge conflict in d3d12/docs/switches.md

The merge is #2589 (5dd6d444f, "nv-vram-target-reserve-settle"), and it touched the same file this does: d3d12/crates/leonida-gpu/src/resource.rs, 165 lines added and 1 removed. Before it, the conflict was only in docs/switches.md - I noted that when I verified this pull request, along with the fact that the code half applied cleanly and fixed_card_budget passed its test.

So this needs one rebase and the two conflicts are probably in different functions: resource.rs gained a VRAM target/reserve path, and this adds fixed_card_budget beside it. switches.md conflicts the way that table always does.

What I verified before the conflict, so it is on record (main 90c514437, the code half only):

cargo test -p leonida-gpu --lib fixed_card_budget
  ok. 1 passed; 0 failed; 636 filtered out

And what I could not: "set above what the card has free, allocations fail rather than move to the PC's memory" needs a title allocating, which needs the game.

AI-assisted: yes - DeepSeek v4.1 (flash), which re-checked after a merge to that file.

Written with an AI assistant.

@KelboLive KelboLive left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified on this machine (RTX 4070 Ti SUPER, 621.01): system own budget 15,293 MB; with LEONIDA_VRAM_BUDGET_MB=7000 the runtime's Host::video_memory()[0] is 7000 while the system query and video_memory_groups stay 15,293; 256 gives 256, 20000 gives 20000, and 0/abc keep 15,293. It lands only in the runtime accessor (host.rs:13645-13665) — no SetVideoMemoryReservation — so Windows still enforces its own budget, which is the right shape for a Wine/Proton measure. 590/0 lib tests, switches --check clean.

Three things:

  1. The wiring is untested: ignoring the fixed value in video_memory (fixed.unwrap_or(own.Budget) -> own.Budget) leaves all 590 tests green; only the parser is covered. A small effective_budget(own, setting) helper tested directly would fix that without fighting the process-global OnceLock.
  2. Warn when fixed > own.Budget. Both numbers are in hand at the first call; on Windows the runtime's own guards will then allow over-commit, and room's comment records that paging past the budget ended runs 20/24. Clamping would defeat the Wine use — a warning is the right compromise.
  3. Say what happens below the current usage. With fixed < own.CurrentUsage the card is permanently over budget: vram_keep evicts, room (with no texture budget) refuses, and if LEONIDA_TEXTURE_BUDGET_MB is also set, room allows exactly what vram_keep then evicts — a make/evict churn. The docs sentence should also say this is a Wine/Proton measure rather than a Windows tuning knob.

Cosmetic: the F1 panel and the memory line now read the fixed budget while the "as the system counts it" line shows the real one, so a 7,000 MB budget on a 15,293 MB card reads oddly; the one-time log helps, but a note in the panel would too.

…f the system's

Host::video_memory hands every decision on the card's memory (the texture queue's room, the card
copies of title buffers, the staging per frame) the budget LEONIDA_VRAM_BUDGET_MB names, in MB from
256 up, instead of the one DXGI reports; unset, empty or not a number of MB: the system's, as before.
The log says it once, with the system's budget beside it. Under Wine the system's budget is what
Vulkan reports as left to the process, and above what the card has free the NVIDIA driver fails
allocations rather than moving memory to the PC's.

Tested: resource::tests::a_fixed_card_budget_is_a_size_in_mb (failing before, passing after) and the
resource tests, as Windows executables under Wine 11.21 (cargo xwin test); the leonida-gpu suite
gives 568 passed and 3 failed, the same three watch:: tests that fail under Wine on main without
this change. A run with 7000 on an RTX 3060 Ti (NVIDIA 620.73, GE-Proton11-14): no Xid, the card
held about 600 MB more.

Rebased onto main at 90c5144; the only conflict was d3d12/docs/switches.md, which is generated, so
it is regenerated (tools/d3d12_switches.py --check passes). It carries what main changed in the page
since it was last made too: LEONIDA_WC_SUBRANGE_NO_BACK, and the source cells of LEONIDA_TAKE_BLOCKS
and LEONIDA_WC_NO_BACK.

AI-assisted (Claude Code).

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
ajussak added a commit to ajussak/mandy that referenced this pull request Dec 1, 2026
…ns above the system's

From the review of ProjectLeonida#2765 (KelboLive): the setting's wiring was not covered, since replacing the
choice in `Host::video_memory` with the system's budget left every test green; above the system's
budget the runtime's own guards then allow more than the system gives, which on Windows ended runs
20 and 24; and the doc sentence said nothing of what happens below what the card has in use.

The choice is now `resource::effective_budget(system, setting)`, a function of its own, tested by
`a_fixed_card_budget_wins_over_the_systems_and_the_system_otherwise`: 7,000, 20,000 and 256 MB over
15,293 MB as the system reports an RTX 4070 Ti SUPER, and the system's for unset, empty, "7 GB" and
0. The environment is read once and in one place (`resource::card_budget_setting`), so the log, the
choice and the panel see the same answer; the once-only log moves to a `std::sync::Once` and the
setting is parsed per call rather than cached.

Above the system's budget the one-time log adds a warning with both numbers. Clamping would defeat
the Wine use the setting is for, so it says so and goes on.

The doc sentence now says what the setting is for: a measure for Wine and Proton rather than a knob
for Windows, and below what the card has in use it keeps the card over budget, the copies the keep
rule evicts being made again as fast as the texture budget lets them be.

switches.md regenerated for it (`tools/d3d12_switches.py --check` passes): the row carries the whole
comment now, the Wine/Proton framing included.

The F1 panel's VRAM line marks a fixed budget (`FIXED`), so a 7,000 MB budget on a 15,293 MB card
does not read as the card's own beside the log's "as the system counts it".

Tested under Wine 11.21 on the machine of ProjectLeonida#2765 (RTX 3060 Ti, NVIDIA 620.73.4), against main at
653f60d: `cargo xwin test -p leonida-gpu --target x86_64-pc-windows-msvc` gives 601 passed, the
same three `watch::` failures as before and 57 ignored; `resource::` alone, 23 passed. With the choice
mutated to ignore the setting the new test fails (16,035,872,768 bytes against 7,340,032,000), so the
wiring it covers is the one `video_memory` takes. `cargo xwin check -p leonida-gpu --features
diagnostics --target x86_64-pc-windows-msvc` compiles the panel's line.

AI-assisted (Claude Code).

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
@github-actions github-actions Bot removed the needs rebase Conflicts with the base branch: rebase it on main label Dec 1, 2026
@ajussak

ajussak commented Dec 1, 2026

Copy link
Copy Markdown
Author

Point 3, measured below the current usage: the ceiling holds and nothing faults.

LEONIDA_VRAM_BUDGET_MB=4000 on a card whose own budget reads 6 967 MB, through the Linux launcher (scripts/play-linux-proton.sh, GE-Proton11-14-viewtree), RTX 3060 Ti 8 192 MiB / driver 620.73.04, Fedora 45 kernel 7.3.4, 16 cores.

budget_mb=4000  system_mb=6967
the card: 3999 MB in use of a budget of 4000 MB      <- peak over 2 min 18 s at that spot

Never above 4 000 MB, no VK_ERROR_OUT_OF_DEVICE_MEMORY, no Xid in dmesg, no fault of the title; I stopped it after those 2 min 18 s while it was still logging pipeline creation.

What replaces an allocation past the ceiling, at the same spot:

  • room refuses and vram_keep evicts, and a draw that wants a texture the card cannot hold refreshes the copy already resident - a texture already on the card is brought up to date although the card has no room for new ones.
  • The evictions do not churn: host copies stay flat (666 alive, 1 180 MB at the end) with 148 pipelines still being made. LEONIDA_TEXTURE_BUDGET_MB was unset in both runs, so the "room allows what vram_keep then evicts" path you describe is not the one exercised here.
  • Cost: 7.5-10.9 fps, 9 208 draws/frame, against 11.6-14.0 fps at the launcher's own 6 400 MB (peak 5 441 MB of a 6 978 MB system budget). The second run reused the same prefix and its pipeline cache, so part of that gap is the cache and not the budget.

Unrelated to this switch: thread 'leonida-pipelines-*' has overflowed its stack appears in both runs (5 workers at 4 000 MB, 6 at 6 400 MB).

…ns above the system's

From the review of ProjectLeonida#2765 (KelboLive): the setting's wiring was not covered, since replacing the
choice in `Host::video_memory` with the system's budget left every test green; above the system's
budget the runtime's own guards then allow more than the system gives, which on Windows ended runs
20 and 24; and the doc sentence said nothing of what happens below what the card has in use.

The choice is now `resource::effective_budget(system, setting)`, a function of its own, tested by
`a_fixed_card_budget_wins_over_the_systems_and_the_system_otherwise`: 7,000, 20,000 and 256 MB over
15,293 MB as the system reports an RTX 4070 Ti SUPER, and the system's for unset, empty, "7 GB" and
0. The environment is read once and in one place (`resource::card_budget_setting`), so the log, the
choice and the panel see the same answer; the once-only log moves to a `std::sync::Once` and the
setting is parsed per call rather than cached.

Above the system's budget the one-time log adds a warning with both numbers. Clamping would defeat
the Wine use the setting is for, so it says so and goes on.

The doc sentence now says what the setting is for: a measure for Wine and Proton rather than a knob
for Windows, and below what the card has in use it keeps the card over budget, the copies the keep
rule evicts being made again as fast as the texture budget lets them be.

switches.md regenerated for it (`tools/d3d12_switches.py --check` passes): the row carries the whole
comment now, the Wine/Proton framing included.

The F1 panel's VRAM line marks a fixed budget (`FIXED`), so a 7,000 MB budget on a 15,293 MB card
does not read as the card's own beside the log's "as the system counts it".

Tested under Wine 11.21 on the machine of ProjectLeonida#2765 (RTX 3060 Ti, NVIDIA 620.73.4), against main at
653f60d: `cargo xwin test -p leonida-gpu --target x86_64-pc-windows-msvc` gives 601 passed, the
same three `watch::` failures as before and 57 ignored; `resource::` alone, 23 passed. With the choice
mutated to ignore the setting the new test fails (16,035,872,768 bytes against 7,340,032,000), so the
wiring it covers is the one `video_memory` takes. `cargo xwin check -p leonida-gpu --features
diagnostics --target x86_64-pc-windows-msvc` compiles the panel's line.

AI-assisted (Claude Code).

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
@ajussak

ajussak commented Dec 1, 2026

Copy link
Copy Markdown
Author

For the record: at 89% of the card's own budget the picture loses the avatar's head.

Seen in the run that checked the pipeline-worker supervisor, whose build comes from main and has no LEONIDA_VRAM_BUDGET_MB in it - so those numbers are the system's own budget, not this switch's:

the card: 4849 MB in use of a budget of 5576 MB        <- the panel read VRAM 4.7/5.6 GB
12.6 fps, 79.2 ms/frame, 10 888 draws/frame

The avatar stands headless, its eyes and teeth floating above the collar, while the panel read MESH TEXTURES 1 BACK 1, TEXTURES PENDING 0 MADE 25, QUEUE 0.0. The same seconds in the log:

  • 6 x a texture already on the card is brought up to date although the card has no room for new ones
  • 1 x textures picked by index: the card has no room for more; they wait
  • host copies 694 alive 1 239 MB; 27 993 title textures with no host copy (11 868 MB)

So this is not evidence that the switch makes the picture wrong - it was not in that build. What it does say is that a card held at its ceiling already drops something the title needs, and the frame shows it, so the switch is worth documenting as costing pixels as well as frame rate, with vram_keep and room the path to read for it.

Not attributed yet: a texture that could not be made resident, or a mesh path with MESH TEXTURES 1 BACK 1 still in flight. The controlled check is the same spot and the same build with LEONIDA_VRAM_BUDGET_MB=4000 and then with the system's budget: if the head is missing in both, the switch is not the cause.

@github-actions github-actions Bot added the needs rebase Conflicts with the base branch: rebase it on main label Dec 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs rebase Conflicts with the base branch: rebase it on main

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants