d3d12/gpu: a texture limit no longer adds copies past the card's budget (D3D12-TEXTURE-BUDGET-OVER-GUARD) #3153
Code
Clone this repository
Checkout
From your project repository, check out a new branch and test the changes.
git fetch -u origin "github-pr/3153:github-pr/3153" git switch "github-pr/3153"
Open
leonida/mandy
Jishnuraj07 wants to merge 1 commit from
github-pr/3153 into main
pull from: github-pr/3153
merge into: leonida:main
leonida:main
leonida:github-pr/3295
leonida:beta
leonida:docs/changelog-3483-3500
leonida:github-pr/3294
leonida:github-pr/2975
leonida:github-pr/2815
leonida:feat/gate-driver-start
leonida:feat/skip-pipelines-release
leonida:perf/lazy-compare
leonida:perf/mwaitx-wait
leonida:test/prio-ceiling-main
leonida:fix/ab-cpu-stdout
leonida:fix/gate-old-crashes
leonida:diag/ab-cpu
leonida:test/main-0312
leonida:github-pr/3291
leonida:diag/indirect-clamp-census
leonida:feat/barrier-enhanced
leonida:perf/texture-frame-ceiling
leonida:perf/dstorage-threads
leonida:fix/console-queue-dma-tables
leonida:fix/port-descriptors-record-parts
leonida:fix/frame-waits-fence
leonida:fix/console-sampler-words
leonida:fix/graphics-userdata-spill
leonida:fix/xg-reserved-layout-rotation
leonida:fix/barrier-console-flags
leonida:fix/switches-wait-test-child
leonida:test/list-value-waits
leonida:test/lot-gxdk-0412
leonida:fix/bvh-compacted-size
leonida:docs/i18n-quickstarts
leonida:feat/native-pipeline-slots
leonida:fix/clippy-leonida-gpu
leonida:fix/list-value-producers
leonida:fix/descriptor-page-straddle
leonida:fix/xmem-low-window
leonida:fix/ffx-jitter-never-zero
leonida:fix/run-stdout-closed
leonida:github-pr/2892
leonida:github-pr/2896
leonida:feat/warm-save-every
leonida:github-pr/2980
leonida:github-pr/2994
leonida:github-pr/3005
leonida:github-pr/3010
leonida:github-pr/3136
leonida:github-pr/3303
leonida:github-pr/3220
leonida:github-pr/3143
leonida:github-pr/3330
leonida:github-pr/3226
leonida:github-pr/3187
leonida:carry/3395
leonida:github-pr/2946
leonida:github-pr/2947
leonida:github-pr/2945
leonida:github-pr/2983
leonida:github-pr/3001
leonida:github-pr/3372
leonida:github-pr/3128
leonida:github-pr/3296
leonida:github-pr/2588
leonida:github-pr/3119
leonida:github-pr/3378
leonida:fix/crash-diagnostics
leonida:feat/dlss-mip-bias
leonida:fix/retired-out-of-order
leonida:fix/dxr-postbuild-barrier
leonida:fix/amd-relay-default
leonida:fix/removed-report-wait
leonida:feat/heap-twin
leonida:feat/vram-margin
leonida:github-pr/2472
leonida:github-pr/3123
leonida:github-pr/3088
leonida:assets/annonce-v1
leonida:github-pr/2794
leonida:github-pr/3300
leonida:github-pr/3304
leonida:github-pr/3308
leonida:github-pr/3367
leonida:github-pr/3369
leonida:fix/launcher-dlss-diagnostics
leonida:github-pr/3269
leonida:github-pr/2957
leonida:github-pr/3205
leonida:fix/crash-zero-guard
leonida:github-pr/3185
leonida:github-pr/3099
leonida:github-pr/3104
leonida:github-pr/3348
leonida:github-pr/3379
leonida:github-pr/3377
leonida:perf/darner-title-priority-ceiling
leonida:github-pr/3376
leonida:gh-readonly-queue/main/pr-3311-b5c45b663dbc5a9c3532bb3f307e5f81b32faefa
leonida:gh-readonly-queue/main/pr-3088-af22e7847ff5808f72d1a1881c24be2fafd20b54
leonida:gh-readonly-queue/main/pr-3123-7f3fa026a94c6646e89244f28e1ce22290361867
leonida:github-pr/3373
leonida:github-pr/3368
leonida:github-pr/3198
leonida:gh-readonly-queue/main/pr-3354-637baa0b77ba47222e7280b17c1a59c6a1781d57
leonida:gh-readonly-queue/main/pr-3365-d7a0e0196a43834813014b4bd3aa5502a8263b14
leonida:gh-readonly-queue/main/pr-3361-5dfe8bbd05ed12fb2f2e1718d9af77a7c5f46fd8
leonida:gh-readonly-queue/main/pr-3366-8da9148204e9d12c585efa9ac2b7cc1ab08c7682
leonida:github-pr/3346
leonida:github-pr/3375
leonida:github-pr/2958
leonida:github-pr/3151
leonida:github-pr/3307
leonida:github-pr/3278
leonida:github-pr/3374
leonida:fix/runtime-test-conservative-fixtures
leonida:github-pr/3366
leonida:ci/shard-semantic-linux
leonida:github-pr/3354
leonida:docs/fg-limit-fps-switch
leonida:github-pr/3365
leonida:fix/read-file-hard-link
leonida:github-pr/3364
leonida:fix/book-slot-heap-never-read
leonida:github-pr/3361
leonida:github-pr/3263
leonida:github-pr/3360
leonida:github-pr/3353
leonida:github-pr/3331
leonida:fix/alias-later-queued-submissions
leonida:github-pr/3352
leonida:github-pr/3228
leonida:github-pr/3349
leonida:claude/gallant-sagan-aamatr
leonida:github-pr/3200
leonida:github-pr/3132
leonida:github-pr/3323
leonida:github-pr/3332
leonida:github-pr/3340
leonida:github-pr/3311
leonida:github-pr/3334
leonida:github-pr/3297
leonida:github-pr/3256
leonida:github-pr/2567
leonida:github-pr/2851
leonida:d3d12/agility-sdk-621
leonida:github-pr/3164
leonida:github-pr/3114
leonida:github-pr/3050
leonida:github-pr/3113
leonida:github-pr/3326
leonida:github-pr/3144
leonida:github-pr/2642
leonida:github-pr/3072
leonida:github-pr/2789
leonida:github-pr/2643
leonida:github-pr/3009
leonida:github-pr/3035
leonida:github-pr/3031
leonida:github-pr/2686
leonida:github-pr/2834
leonida:github-pr/3321
leonida:github-pr/3325
leonida:github-pr/3290
leonida:github-pr/3324
leonida:github-pr/3130
leonida:claude/fervent-curie-m19lnr
leonida:github-pr/3309
leonida:github-pr/3305
leonida:github-pr/3306
leonida:github-pr/3302
leonida:github-pr/3301
leonida:github-pr/3345
leonida:github-pr/3211
leonida:github-pr/3027
leonida:github-pr/3286
leonida:github-pr/3235
leonida:github-pr/3265
leonida:github-pr/3275
leonida:codex/skip-no-hit-ray-passes
leonida:github-pr/2823
leonida:github-pr/2911
leonida:github-pr/3262
leonida:github-pr/3125
leonida:github-pr/3206
leonida:github-pr/3250
leonida:github-pr/3238
leonida:github-pr/3188
leonida:github-pr/2952
leonida:github-pr/3217
leonida:github-pr/3168
leonida:t3/preserve-fsr-sdk-restart-path
leonida:t3/propagate-host-failure-hresult
leonida:github-pr/3209
leonida:t3/launcher-custom-parameters
leonida:github-pr/3207
leonida:github-pr/3183
leonida:github-pr/3160
leonida:github-pr/3201
leonida:ci/less-to-run
leonida:github-pr/2930
leonida:github-pr/2797
leonida:github-pr/2999
leonida:perf/native-compute-shader-forms
leonida:github-pr/3191
leonida:github-pr/3011
leonida:github-pr/3019
leonida:github-pr/2996
leonida:gh-readonly-queue/main/pr-2789-45dc41f95c1cd0dcc29c2c50582e0e9af8a77259
leonida:claude/blissful-franklin-ukp7ag
leonida:github-pr/3141
leonida:github-pr/3156
leonida:github-pr/3150
leonida:github-pr/3163
leonida:github-pr/3142
leonida:github-pr/3139
leonida:github-pr/2841
leonida:github-pr/3069
leonida:github-pr/3098
leonida:github-pr/3107
leonida:github-pr/3071
leonida:github-pr/2774
leonida:github-pr/2889
leonida:github-pr/3075
leonida:github-pr/2661
leonida:github-pr/3064
leonida:github-pr/3054
leonida:github-pr/3049
leonida:github-pr/2855
leonida:github-pr/2943
leonida:github-pr/3016
leonida:github-pr/2887
leonida:github-pr/3006
leonida:github-pr/3003
leonida:github-pr/2993
leonida:notes/card-time-and-plant-flicker
leonida:github-pr/2989
leonida:feat/vulkan-rs
leonida:github-pr/2985
leonida:github-pr/2951
leonida:github-pr/2982
leonida:github-pr/752
leonida:github-pr/792
leonida:github-pr/2877
leonida:github-pr/2654
leonida:github-pr/2893
leonida:github-pr/2948
leonida:github-pr/2944
leonida:github-pr/2919
leonida:github-pr/2915
leonida:archive/ci/less-to-run/20261202T1121Z
leonida:github-pr/2800
leonida:github-pr/2822
leonida:github-pr/2833
leonida:github-pr/2840
leonida:github-pr/2831
leonida:github-pr/2832
leonida:github-pr/2801
leonida:github-pr/2890
leonida:github-pr/2891
leonida:github-pr/2664
leonida:github-pr/2807
leonida:rt-call-trace
leonida:github-pr/2755
leonida:perf/ahead-split
leonida:github-pr/2587
leonida:github-pr/2698
leonida:github-pr/2609
leonida:github-pr/3219
leonida:docs/readme-runtime-proposal
leonida:github-pr/2017
leonida:github-pr/1741
leonida:github-pr/1667
leonida:codex/coord-claim-check-20261124-7e48
No reviewers
Assignees
Clear assignees
No assignees
Labels
Clear labels
bug
Something isn't working
dependencies
Pull requests that update a dependency file
documentation
Improvements or additions to documentation
enhancement
New feature or request
missing claim
Needs a claim in #14
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
No labels
bug
dependencies
documentation
enhancement
missing claim
needs rebase
needs-triage
question
ready-for-agent
submodules
Projects
Clear projects
No items
No project
Milestone
Clear milestone
No items
No milestone
Dependencies
No dependencies set
Notifications
1 participant
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".
No due date set.
Reference
leonida/mandy!3153
Loading…
Reference in a new issue
No description provided.
Delete branch "github-pr/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?
This branch is out-of-date with the base branch
Reviewers 0 approvals
Details
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Claimed 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
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.
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.
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).
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).
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.
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
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.