d3d12/gpu: a texture limit no longer adds copies past the card's budget (D3D12-TEXTURE-BUDGET-OVER-GUARD) #3153
Open
github-bot
wants to merge 1 commit from
github-bot/gh-3153 into main
AGit
pull from: github-bot/gh-3153
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!3153
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-3153"
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?
@Jishnuraj07 on GitHub · 2026-12-02 14:30 UTC · original
Jishnuraj07:d3d12-texture-budget-over-guard→main· +89 −14 · 1 files · 1 commits · openClaimed in the coordination issue as:
D3D12-TEXTURE-BUDGET-OVER-GUARDRelated: #2658 (closed for a merge conflict only; this is its part 1, ported with credit to @olgundemirkan), #2607, #2611, #3121 (8 GB cards over their budget)
What and why
With
LEONIDA_TEXTURE_BUDGET_MBset,resource::room()returnedfilled < limitstraight away and never looked at the card's memory. 8 GB setups set that limit (4,000 MB in #2658's profile) so that characters keep their textures past nine tenths of the budget. As a side effect, host copies of title textures kept being made while the process was already over its DXGI budget: 7,823 MB of a 7,256 MB budget in #2658's 2026-11-29 runs, until the driver faulted.room_for()(d3d12/crates/leonida-gpu/src/resource.rs), so it can be unit-tested without the environmentOnceLocks or a device.filled < limitand the card is under its budget (used < budget). A budget of 0, from an adapter that reports none, counts as no budget there, so the limit alone decides as before.room_percent(). Using the 90 % line would bring back what the limit exists to avoid (untextured characters past nine tenths of the budget).Not in this PR, left to measure in game first: the guard could also count the room kept for render targets and buffer copies, as the share path does. On a ~7.2 GB budget, the 3,072 MB target reserve could starve textures, so that should be an A/B run, not a guess.
Tested
a_texture_limit_stops_at_the_cards_budgetandwithout_a_texture_limit_the_share_of_the_budget_decides.room_for, make the first line of theif let Some(limit) = limitbranchmain'sreturn filled < limit;(so the budget is never looked at).a_texture_limit_stops_at_the_cards_budgetthen fails at the "card at its budget" assert; with the fix it passes. Done by hand on the final code, not withred_green.py, because the new tests callroom_for, which does not exist onmain. (Putting the line back inroom()itself does not compile, sincelimitis anOptionthere and theroom_forcall is the tail expression; thanks @fiestorra.)leonida-gpucrate:cargo test -p leonida-gpu --lib --locked: 698 passed, 0 failed, 59 ignored.cargo test --workspace --exclude xtask --locked --no-fail-fast -- --skip depth_bounds_pipeline_loads_and_filters_draws: all 32 test binaries ok.leonida-loaderconsole_insn::tests::a_clzero_loop_becomes_plain_storesfailed once and then passed on rerun. That crate does not depend onleonida-gpu, so it is a flaky test unrelated to this change.python -I tools/d3d12_switches.py --check d3d12/docs/switches.mdandpython -I tests/test_d3d12_switches.pypass.python -I scripts/check_no_game_data.pyis clean on the changed file.main, andmainalone): not run yet. I will post it here from the RTX 5060 8 GB below, withLEONIDA_TEXTURE_BUDGET_MBset.GPUs tested: NVIDIA GeForce RTX 5060 8 GB, driver 621.47, Windows 11 Pro 26200 (unit tests; the in-game run will follow)
AI-assisted: yes. Claude Opus 5.5 (Claude Code) wrote the change and tests, and a separate read-only Claude Opus 5.5 reviewer agent audited the diff. Its findings (budget 0 blocking every copy, a doc claim to cite, the floor wording) are addressed in this head.
Checklist
main(69cd4106c) and merges cleanly.docs/design.md, with how it was confirmed. (n/a: no translator change)🤖 Generated with Claude Code
@merzleckeier on GitHub · 2026-12-02 14:35 UTC · original · reviewed
Independent check of
f854004donmain69cd4106c. Both stock texture-limit tests passed in the MSVC-target build under Wine 11.22.I also ran the same local probe against the production
resource::room()entry point on both revisions. WithLEONIDA_TEXTURE_BUDGET_MB=4000and a synthetic 7,256 MiB budget,mainstill returned true at exactly 7,256 MiB. The PR accepted 7,000 MiB and denied both 7,256 and 7,823 MiB. A zero budget and a missing memory query still honored the configured texture limit.This verifies the admission decision for a reported budget sample. The live 8 GB rendering run and budget behavior between samples remain unverified in this review. AI-assisted with OpenAI Codex.
@fiestorra on GitHub · 2026-12-02 15:47 UTC · original
Checked here, and the checker's verdict is not what it looks like:
red_green.pysaysgreen fails, and that is an artefact of the tests, not of the change.The red side cannot compile because the new tests call
room_for, which this pull request introduces - so there is no "red" result to compare and the tool stops atgreen fails. Anyone scanning verdicts will read that as "the pull request breaks the crate", and it does not.The green side is green, measured separately on
f854004db:And one thing in the body that does not work as written. It says "putting back only
main'sreturn filled < limit;makesa_texture_limit_stops_at_the_cards_budget[fail]". I tried that literally twice and neither compiles:room(), afterlet limit = texture_budget_bytes();->error[E0308]: mismatched types, because this branch'slimitis not a bare number any more;room_for(...)line ->error[E0317]: if may be missing an else clause, because that line is the function's tail expression.So the revert has to be made inside
room_for's body (make itreturn filled < limit;before the budget is looked at). Worth fixing in the body, because a reviewer will try exactly what it says - and I would rather report that I could not reproduce the red than claim it.What I did not run: the in-game gate. The body says it is not run yet, and this machine cannot run the title.
AI-assisted: yes - DeepSeek v4.1 (flash).
Written with an AI assistant.
@fiestorra on GitHub · 2026-12-02 15:49 UTC · original
Correction to what I said above:
green failsis right, and my explanation of it was wrong.It is this machine, not your change.
cargo test -p leonida-gpu --libonmainhere is 695 passed, 1 failed, and the failure is- the byte-comparison test that fails on this machine's integrated Radeon, because every device test still makes its device with
D3D12CreateDevice(None, ..)(that is what my #2995 fixes). So the green side's suite fails for a reason that has nothing to do withresource.rs, and the checker reports it as it should.What misled me: the tool has a
red does not buildverdict (scripts/red_green.py:541, with its own test attests/test_red_green.py:191), and it printedred does not build: ... cannot find function room_foras well - so the run says both things, and I read the verdict line as if it were about the helper. It was not: it was about the descriptor test. The tool was right and I was not.What stands from above: your two new tests pass individually on
f854004db(a_texture_limit_stops_at_the_cards_budgetandwithout_a_texture_limit..., 1 passed each), and the manual red in your body still does not compile as written -E0308insideroom(),E0317at the call site - so the revert belongs insideroom_for's body.If you want a clean
red then greenfrom the checker on a machine like this one,-p leonida-gpuneeds the device tests on the card (#2995) or--skipon that one test; on a machine without the iGPU it would have saidred then greenorred does not buildand nothing else.AI-assisted: yes - DeepSeek v4.1 (flash).
Written with an AI assistant.
@Jishnuraj07 on GitHub · 2026-12-02 16:06 UTC · original
Thanks @fiestorra, you're right about the red step: the line has to go inside
room_for, notroom(). The body now says to make the first line of theif let Some(limit) = limitbranchreturn filled < limit;. With that,a_texture_limit_stops_at_the_cards_budgetfails at the "card at its budget" assert, and with the fix it passes.Thanks also for tracking down the
green failsverdict to the device test on the integrated Radeon (#2995) and not this change.Thanks @merzleckeier for the probe against
room()itself, including the budget-0 and no-reading cases.The in-game gate on the RTX 5060 8 GB is still to come.
AI-assisted: yes, Claude Opus 5.5 (Claude Code).
@Kal0s-design on GitHub · 2026-12-02 17:53 UTC · original
Ran natively on Windows 11, head
f854004dbmerged into currentmain(45dc41f95, clean merge). Debug build.Suites and red on the merge
cargo test -p leonida-gpu --lib -- --test-threads=4room_for, the limit branch madereturn filled < limit;a_texture_limit_stops_at_the_cards_budgetfails at!room_for(Some((budget, budget)), ..)(card at its budget); the other test passescargo clippy -p leonida-gpu -p leonida-hle --all-targetsThe budget the guard reads, on the card and on WARP
room()gets the budget fromHost::video_memory()(QueryVideoMemoryInfo, local group). Throwaway test: made 24 committed 32 MiB default-heap buffers and readvideo_memory()before and after each.LEONIDA_D3D12_WARP=1,diagnostics)CurrentUsagegrew by what was madevideo_memory()costSo on both adapters the guard's
usedreflects a copy as soon as it is made, and WARP does not hit the "budget 0" path (only its shared group reports 0, whichroom()does not use). What bounds the overshoot past the budget is therefore how oftenroom()is asked, not the sample. Indraw.rsthat is once at the start of a pass and again every 32 MiB uploaded (reading), so a pass can still add up to about 32 MiB plus one copy onceusedreaches the budget.Edge values (
room_fordirectly, budget B = 8,000 MiB, percent 90)main:filled < 0is never true)u64::MAXThe last two rows are where the limit path and the share path disagree beyond the intended "past nine tenths":
pool::texture_room()because a texture placed in a free block adds nothing to the card's use. Under the new guard, onceusedreaches the budget, no copy is made even into blocks already allocated. Passing the sameheldinto the limit branch (used.saturating_sub(held) < budget) would keep the guard on new card memory only. That is my suggestion, not measured in a run.Reading vs measured
draw.rsand the overshoot bound that follows from it, and why the pool's free room matters.Not checked: any in-game run, a budget the system changes while copies are made (the table drives
room_forwith values, the OS budget did not move here), other GPU vendors,--features diagnosticssuites other than the WARP probe.GPUs tested: one NVIDIA desktop card + WARP.
AI-assisted: yes (Claude Code).
@Jishnuraj07 on GitHub · 2026-12-02 17:54 UTC · original
In-game gate on the RTX 5060 8 GB: all four runs PASS, none over the card's budget, but the PR's arm was slower in both of its runs.
Setup:
scripts/game-gate.ps1, 300 s in the world,-PlayArgs '-SeriesS -NoFrameGen',-More 'LEONIDA_TEXTURE_BUDGET_MB=4000'(shown in every run's settings line), default memory stops. A =main23a68aec3; B = this headf854004dbmerged onto that samemain(d8ebb8426). Both buildsdiagnostics,dlss,mimalloc, clean trees. Order A B B A, each arm with its own data folder (B's started from a copy of A's warm caches; this PR changes no shader). Same save, standing still where it loads. NVIDIA GeForce RTX 5060 8 GB, driver 621.47 (32.0.16.2147), Windows 11 Pro 26200.mainmainNo crash, device loss or missed pipeline wait in any run. *Runs 3 and 4 carry the warnings
killedandcache_not_saved: the gate found no window to sendSC_CLOSEto (noclose_sentevent) and killed the game 60 s after the stop request. The gate'sGateWindow.Closeskips a window with an empty client area, which is what a minimised window has; that is my guess at the cause, not checked. It happened on both arms, after the measured window.What this shows
mainstayed under the budget too in both of its runs (peaks 6.7–6.8 GB of 7.0–7.1 GB, 0 s over), so the case this PR guards against (#2658's 7,823 MB of 7,256 MB) did not come up here. An earlier run ofmainon this PC without the limit did go over (7,138 / 6,917 MB for 80 s, amemory_stop), so it can happen on this card, just not in these four.tools/d3d12_ab_compare.py abbaover the four: world median frame time A 43.28 ms, B 50.61 ms (run by run: A 43.74, B 49.85, B 51.36, A 42.81). Its verdict isnot enough runs(it needs 3 a side), so this is not a measured regression yet, but every B run is slower than every A run.A possible cause, not checked: with a limit set, the new guard stops copies whenever
used >= budgetat the momentroom()asks. The gate reads video memory every 5 s and saw no time over the budget, but these runs sat within ~100–300 MB of it, so short peaks between its readings could refuse copies thatmainmakes. I found no log line that counts copies made or refused, so I cannot tell from these runs. Next on this PC: two more A/B pairs (scripts/game-abba.ps1, so the comparison gives a verdict), and, if B stays slower, a count of copies refused by the budget guard.AI-assisted: yes, Claude Opus 5.5 (Claude Code) ran the gate runs and the comparison and drafted this comment.
@MoonEyes on GitHub · 2026-12-02 17:59 UTC · original
Triage of head
f854004db(merge base69cd4106c, 38 commits behind;git merge-treeagainst currentmain45dc41f95: no conflicts).1 file:
d3d12/crates/leonida-gpu/src/resource.rs(+89/-14).CI is at
action_requiredon this head (fork workflow approval).Existing verification: @fiestorra ran
scripts/red_green.py 3153on this head: red does not compile (the tests call the newroom_for), and the one green failure isdescriptor::host::tests::views_are_made_beside_the_heap_and_copied_in, which fails onmainon that machine's integrated Radeon too (#2995), not from this change. The author then put the manual red step in the body (make the limit branch ofroom_forreturnfilled < limit, anda_texture_limit_stops_at_the_cards_budgetfails at the at-budget assert).This check: Read the diff:
room()is split into a pureroom_for()so the decision is unit-testable, and withLEONIDA_TEXTURE_BUDGET_MBset it now also requiresused < budget(a budget of 0 is treated as none). Root cause, not a workaround: before, the limit short-circuited the card check entirely. One nit: on the limit path the budget check uses rawused, while the share path subtracts the texture pool's free room (held); with a large pool the limit path will stop a little earlier than the share path would. Probably intended (it is the hard ceiling), but worth a sentence in the doc comment.I did not build it: the crate is Windows-only (or the C++ runtime's Windows build), so no red/green was run here.
Verdict: ready (root-cause fix with pure-function tests; red shown by edit; green failure is a known machine issue (#2995)).
AI-assisted verification: Claude Opus (Claude Code), separate agent per batch.
Generated by Claude Code
@fiestorra on GitHub · 2026-12-02 23:09 UTC · original
RE-VERIFIED-3153 at
f854004db—red then green, and my first control was wrongYour new head (the one after my correction at 15:49) passes:
And the moved red step is the right one now: with
room_for's limit branch put back to the oldfilled < limit(no budget clause), it fails on the line you added:The fix reads right: "A limit stands in for the floor and the share of the budget … but not for the budget itself: while the card is at or over it, no copy is added." That is the one sentence the change needed, and it is in the doc comment.
One thing about my own method, since you may run the same check: my first control neutralised the limit at the call site and all 33 tests still passed — because the tests call
room_for(…)directly, so patching the caller changed nothing they exercise. A control that does not bite is not a control, and I moved it into the function before recording a verdict.Thanks for moving the red step where it belongs instead of arguing with it.
Written with an AI 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.