d3d12/gpu: a texture limit no longer adds copies past the card's budget (D3D12-TEXTURE-BUDGET-OVER-GUARD) #3153

Open
Jishnuraj07 wants to merge 1 commit from upstream-pr/3153 into main
Jishnuraj07 commented 2026-12-02 14:30:57 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by Jishnuraj07 on 2026-12-02T14:30:57Z.


Claimed in the coordination issue as: D3D12-TEXTURE-BUDGET-OVER-GUARD

Related: #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_MB set, resource::room() returned filled < limit straight 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.

  • The decision moves into a pure room_for() (d3d12/crates/leonida-gpu/src/resource.rs), so it can be unit-tested without the environment OnceLocks or a device.
  • With a limit, a copy is now made only while filled < limit and 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.
  • Without a limit, nothing changes: same order (floor, then the share of the budget, then 4 GiB with no budget), same arithmetic. The pool's free room and the kept room are still read only where the share decides.
  • The guard uses the budget itself, not 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

  • New tests (pass): a_texture_limit_stops_at_the_cards_budget and without_a_texture_limit_the_share_of_the_budget_decides.
  • Red: inside room_for, make the first line of the if let Some(limit) = limit branch main's return filled < limit; (so the budget is never looked at). a_texture_limit_stops_at_the_cards_budget then fails at the "card at its budget" assert; with the fix it passes. Done by hand on the final code, not with red_green.py, because the new tests call room_for, which does not exist on main. (Putting the line back in room() itself does not compile, since limit is an Option there and the room_for call is the tail expression; thanks @fiestorra.)
  • leonida-gpu crate: cargo test -p leonida-gpu --lib --locked: 698 passed, 0 failed, 59 ignored.
  • Full suite: cargo test --workspace --exclude xtask --locked --no-fail-fast -- --skip depth_bounds_pipeline_loads_and_filters_draws: all 32 test binaries ok.
    • In an earlier run of the same suite, leonida-loader console_insn::tests::a_clzero_loop_becomes_plain_stores failed once and then passed on rerun. That crate does not depend on leonida-gpu, so it is a flaky test unrelated to this change.
  • Other checks: python -I tools/d3d12_switches.py --check d3d12/docs/switches.md and python -I tests/test_d3d12_switches.py pass. python -I scripts/check_no_game_data.py is clean on the changed file.
  • In-game gate (300 s in the world, this head merged onto main, and main alone): not run yet. I will post it here from the RTX 5060 8 GB below, with LEONIDA_TEXTURE_BUDGET_MB set.

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

  • Based on current main (69cd4106c) and merges cleanly.
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (n/a: no translator change)

🤖 Generated with Claude Code

<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5608502173 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/3153). Originally posted by [Jishnuraj07](https://github.com/Jishnuraj07) on 2026-12-02T14:30:57Z. --- Claimed in the coordination issue as: [`D3D12-TEXTURE-BUDGET-OVER-GUARD`](https://github.com/ProjectLeonida/mandy/issues/2570#issuecomment-7348703314) Related: #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_MB` set, `resource::room()` returned `filled < limit` straight 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. - The decision moves into a pure `room_for()` (`d3d12/crates/leonida-gpu/src/resource.rs`), so it can be unit-tested without the environment `OnceLock`s or a device. - **With a limit**, a copy is now made only while `filled < limit` **and** 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. - **Without a limit, nothing changes**: same order (floor, then the share of the budget, then 4 GiB with no budget), same arithmetic. The pool's free room and the kept room are still read only where the share decides. - The guard uses the budget itself, not `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 - **New tests (pass):** `a_texture_limit_stops_at_the_cards_budget` and `without_a_texture_limit_the_share_of_the_budget_decides`. - **Red:** inside `room_for`, make the first line of the `if let Some(limit) = limit` branch `main`'s `return filled < limit;` (so the budget is never looked at). `a_texture_limit_stops_at_the_cards_budget` then fails at the "card at its budget" assert; with the fix it passes. Done by hand on the final code, not with `red_green.py`, because the new tests call `room_for`, which does not exist on `main`. (Putting the line back in `room()` itself does not compile, since `limit` is an `Option` there and the `room_for` call is the tail expression; thanks @fiestorra.) - **`leonida-gpu` crate:** `cargo test -p leonida-gpu --lib --locked`: 698 passed, 0 failed, 59 ignored. - **Full suite:** `cargo test --workspace --exclude xtask --locked --no-fail-fast -- --skip depth_bounds_pipeline_loads_and_filters_draws`: all 32 test binaries ok. - In an earlier run of the same suite, `leonida-loader` `console_insn::tests::a_clzero_loop_becomes_plain_stores` failed once and then passed on rerun. That crate does not depend on `leonida-gpu`, so it is a flaky test unrelated to this change. - **Other checks:** `python -I tools/d3d12_switches.py --check d3d12/docs/switches.md` and `python -I tests/test_d3d12_switches.py` pass. `python -I scripts/check_no_game_data.py` is clean on the changed file. - **In-game gate (300 s in the world, this head merged onto `main`, and `main` alone): not run yet.** I will post it here from the RTX 5060 8 GB below, with `LEONIDA_TEXTURE_BUDGET_MB` set. 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 - [x] Based on current `main` (`69cd4106c`) and merges cleanly. - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. - [ ] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed. (n/a: no translator change) 🤖 Generated with [Claude Code](https://claude.com/claude-code)
merzleckeier commented 2026-12-02 14:35:12 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by merzleckeier on 2026-12-02T14:35:12Z.

Review: COMMENTED


Independent check of f854004d on main 69cd4106c. 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. With LEONIDA_TEXTURE_BUDGET_MB=4000 and a synthetic 7,256 MiB budget, main still 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.

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6152881505 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/3153#pullrequestreview-6152881505). Originally posted by [merzleckeier](https://github.com/merzleckeier) on 2026-12-02T14:35:12Z. **Review:** COMMENTED --- Independent check of `f854004d` on `main` `69cd4106c`. 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. With `LEONIDA_TEXTURE_BUDGET_MB=4000` and a synthetic 7,256 MiB budget, `main` still 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 commented 2026-12-02 15:47:12 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by fiestorra on 2026-12-02T15:47:12Z.


Checked here, and the checker's verdict is not what it looks like: red_green.py says green fails, and that is an artefact of the tests, not of the change.

python -I scripts/red_green.py 3153

base origin/main 3c106eb2f, head 3153 f854004db, merge base 69cd4106c
ran: cargo -p leonida-gpu
red does not build: error[E0425]: cannot find function `room_for` in this scope
only on green (757): ...
pass on both: 0
verdict: green fails

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 at green 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:

cargo test -p leonida-gpu --lib -- --test-threads=1 a_texture_limit_stops
    test result: ok. 1 passed
cargo test -p leonida-gpu --lib -- --test-threads=1 without_a_texture_limit
    test result: ok. 1 passed

And one thing in the body that does not work as written. It says "putting back only main's return filled < limit; makes a_texture_limit_stops_at_the_cards_budget [fail]". I tried that literally twice and neither compiles:

  • inside room(), after let limit = texture_budget_bytes(); -> error[E0308]: mismatched types, because this branch's limit is not a bare number any more;
  • at the call site, replacing the 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 it return 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.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7350916167 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/3153#issuecomment-7350916167). Originally posted by [fiestorra](https://github.com/fiestorra) on 2026-12-02T15:47:12Z. --- **Checked here, and the checker's verdict is not what it looks like: `red_green.py` says `green fails`, and that is an artefact of the tests, not of the change.** ``` python -I scripts/red_green.py 3153 base origin/main 3c106eb2f, head 3153 f854004db, merge base 69cd4106c ran: cargo -p leonida-gpu red does not build: error[E0425]: cannot find function `room_for` in this scope only on green (757): ... pass on both: 0 verdict: green fails ``` **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 at `green 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`: ``` cargo test -p leonida-gpu --lib -- --test-threads=1 a_texture_limit_stops test result: ok. 1 passed cargo test -p leonida-gpu --lib -- --test-threads=1 without_a_texture_limit test result: ok. 1 passed ``` **And one thing in the body that does not work as written.** It says *"putting back only `main`'s `return filled < limit;` makes `a_texture_limit_stops_at_the_cards_budget` [fail]"*. **I tried that literally twice and neither compiles**: - **inside `room()`**, after `let limit = texture_budget_bytes();` -> **`error[E0308]: mismatched types`**, because this branch's `limit` is not a bare number any more; - **at the call site**, replacing the `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 it `return 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 commented 2026-12-02 15:49:09 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by fiestorra on 2026-12-02T15:49:09Z.


Correction to what I said above: green fails is right, and my explanation of it was wrong.

It is this machine, not your change. cargo test -p leonida-gpu --lib on main here is 695 passed, 1 failed, and the failure is

---- descriptor::host::tests::views_are_made_beside_the_heap_and_copied_in

- 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 with resource.rs, and the checker reports it as it should.

What misled me: the tool has a red does not build verdict (scripts/red_green.py:541, with its own test at tests/test_red_green.py:191), and it printed red does not build: ... cannot find function room_for as 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_budget and without_a_texture_limit..., 1 passed each), and the manual red in your body still does not compile as written - E0308 inside room(), E0317 at the call site - so the revert belongs inside room_for's body.

If you want a clean red then green from the checker on a machine like this one, -p leonida-gpu needs the device tests on the card (#2995) or --skip on that one test; on a machine without the iGPU it would have said red then green or red does not build and nothing else.

AI-assisted: yes - DeepSeek v4.1 (flash).

Written with an AI assistant.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7350974018 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/3153#issuecomment-7350974018). Originally posted by [fiestorra](https://github.com/fiestorra) on 2026-12-02T15:49:09Z. --- **Correction to what I said above: `green fails` is right, and my explanation of it was wrong.** **It is this machine, not your change.** `cargo test -p leonida-gpu --lib` on `main` here is **695 passed, 1 failed**, and the failure is ``` ---- descriptor::host::tests::views_are_made_beside_the_heap_and_copied_in ``` **- 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 with `resource.rs`, and the checker reports it as it should.** **What misled me**: the tool has a `red does not build` verdict (`scripts/red_green.py:541`, with its own test at `tests/test_red_green.py:191`), **and it printed `red does not build: ... cannot find function room_for` as 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_budget` and `without_a_texture_limit...`, 1 passed each), and **the manual red in your body still does not compile as written** - `E0308` inside `room()`, `E0317` at the call site - **so the revert belongs inside `room_for`'s body.** **If you want a clean `red then green` from the checker on a machine like this one**, `-p leonida-gpu` needs the device tests on the card (#2995) or `--skip` on that one test; **on a machine without the iGPU it would have said `red then green` or `red does not build` and nothing else.** **AI-assisted:** yes - DeepSeek v4.1 (flash). Written with an AI assistant.
Jishnuraj07 commented 2026-12-02 16:06:08 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by Jishnuraj07 on 2026-12-02T16:06:08Z.


Thanks @fiestorra, you're right about the red step: the line has to go inside room_for, not room(). The body now says to make the first line of the if let Some(limit) = limit branch return filled < limit;. With that, a_texture_limit_stops_at_the_cards_budget fails at the "card at its budget" assert, and with the fix it passes.

Thanks also for tracking down the green fails verdict 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).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7351437908 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/3153#issuecomment-7351437908). Originally posted by [Jishnuraj07](https://github.com/Jishnuraj07) on 2026-12-02T16:06:08Z. --- Thanks @fiestorra, you're right about the red step: the line has to go inside `room_for`, not `room()`. The body now says to make the first line of the `if let Some(limit) = limit` branch `return filled < limit;`. With that, `a_texture_limit_stops_at_the_cards_budget` fails at the "card at its budget" assert, and with the fix it passes. Thanks also for tracking down the `green fails` verdict 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 commented 2026-12-02 17:53:37 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by Kal0s-design on 2026-12-02T17:53:37Z.


Ran natively on Windows 11, head f854004db merged into current main (45dc41f95, clean merge). Debug build.

Suites and red on the merge

Command Result
cargo test -p leonida-gpu --lib -- --test-threads=4 705 passed, 0 failed, 59 ignored (+2 ignored throwaway probes of mine)
Red as the body now describes it: inside room_for, the limit branch made return filled < limit; a_texture_limit_stops_at_the_cards_budget fails at !room_for(Some((budget, budget)), ..) (card at its budget); the other test passes
cargo clippy -p leonida-gpu -p leonida-hle --all-targets no warnings

The budget the guard reads, on the card and on WARP

room() gets the budget from Host::video_memory() (QueryVideoMemoryInfo, local group). Throwaway test: made 24 committed 32 MiB default-heap buffers and read video_memory() before and after each.

Card WARP (LEONIDA_D3D12_WARP=1, diagnostics)
Local budget reported non-zero non-zero
Shared (non-local) budget reported non-zero 0
CurrentUsage grew by what was made 1.00x, 24 of 24 at once 1.00x, 24 of 24 at once
Budget changed during the test no no
video_memory() cost 1.1 us 0.8 us

So on both adapters the guard's used reflects a copy as soon as it is made, and WARP does not hit the "budget 0" path (only its shared group reports 0, which room() does not use). What bounds the overshoot past the budget is therefore how often room() is asked, not the sample. In draw.rs that 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 once used reaches the budget.

Edge values (room_for directly, budget B = 8,000 MiB, percent 90)

Case Result
limit 0, card empty no copy (as on main: filled < 0 is never true)
limit 2B, filled 1.2B, used 0.5B copy
limit 2B, used = B - 1 byte copy
limit 2B, used = B no copy
limit, budget 0 copy (limit alone, as the body says)
limit, used = u64::MAX no copy
limit 4,000 MiB, used 7,000 MiB, budget 7,256 → 7,000 → 6,999 → 7,001 → 9,000 MiB copy, no, no, copy, copy (follows the budget both ways)
limit, used 0.95B, 0.4B kept for render targets and buffer copies copy (no limit: no copy)
limit, used = B, 0.2B of our texture pool's blocks free no copy (no limit: copy)

The last two rows are where the limit path and the share path disagree beyond the intended "past nine tenths":

  • The kept room is not counted under a limit. The body already names this as left for an A/B run.
  • Our own pool's free blocks count as used under a limit. The share path subtracts pool::texture_room() because a texture placed in a free block adds nothing to the card's use. Under the new guard, once used reaches the budget, no copy is made even into blocks already allocated. Passing the same held into 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

  • Measured: the suite, the red, both adapters' readings, every row of the edge table.
  • Reading: the 32 MiB re-ask in draw.rs and 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_for with values, the OS budget did not move here), other GPU vendors, --features diagnostics suites other than the WARP probe.

GPUs tested: one NVIDIA desktop card + WARP.

AI-assisted: yes (Claude Code).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7353747282 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/3153#issuecomment-7353747282). Originally posted by [Kal0s-design](https://github.com/Kal0s-design) on 2026-12-02T17:53:37Z. --- Ran natively on Windows 11, head `f854004db` merged into current `main` (`45dc41f95`, clean merge). Debug build. **Suites and red on the merge** | Command | Result | |---|---| | `cargo test -p leonida-gpu --lib -- --test-threads=4` | 705 passed, 0 failed, 59 ignored (+2 ignored throwaway probes of mine) | | Red as the body now describes it: inside `room_for`, the limit branch made `return filled < limit;` | `a_texture_limit_stops_at_the_cards_budget` fails at `!room_for(Some((budget, budget)), ..)` (card at its budget); the other test passes | | `cargo clippy -p leonida-gpu -p leonida-hle --all-targets` | no warnings | **The budget the guard reads, on the card and on WARP** `room()` gets the budget from `Host::video_memory()` (`QueryVideoMemoryInfo`, local group). Throwaway test: made 24 committed 32 MiB default-heap buffers and read `video_memory()` before and after each. | | Card | WARP (`LEONIDA_D3D12_WARP=1`, `diagnostics`) | |---|---|---| | Local budget reported | non-zero | non-zero | | Shared (non-local) budget reported | non-zero | **0** | | `CurrentUsage` grew by what was made | 1.00x, 24 of 24 at once | 1.00x, 24 of 24 at once | | Budget changed during the test | no | no | | `video_memory()` cost | 1.1 us | 0.8 us | So on both adapters the guard's `used` reflects a copy as soon as it is made, and WARP does not hit the "budget 0" path (only its shared group reports 0, which `room()` does not use). What bounds the overshoot past the budget is therefore how often `room()` is asked, not the sample. In `draw.rs` that 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 once `used` reaches the budget. **Edge values (`room_for` directly, budget B = 8,000 MiB, percent 90)** | Case | Result | |---|---| | limit 0, card empty | no copy (as on `main`: `filled < 0` is never true) | | limit 2B, filled 1.2B, used 0.5B | copy | | limit 2B, used = B - 1 byte | copy | | limit 2B, used = B | no copy | | limit, budget 0 | copy (limit alone, as the body says) | | limit, used = `u64::MAX` | no copy | | limit 4,000 MiB, used 7,000 MiB, budget 7,256 → 7,000 → 6,999 → 7,001 → 9,000 MiB | copy, no, no, copy, copy (follows the budget both ways) | | limit, used 0.95B, 0.4B kept for render targets and buffer copies | **copy** (no limit: no copy) | | limit, used = B, 0.2B of our texture pool's blocks free | **no copy** (no limit: copy) | The last two rows are where the limit path and the share path disagree beyond the intended "past nine tenths": - The kept room is not counted under a limit. The body already names this as left for an A/B run. - Our own pool's free blocks count as used under a limit. The share path subtracts `pool::texture_room()` because a texture placed in a free block adds nothing to the card's use. Under the new guard, once `used` reaches the budget, no copy is made even into blocks already allocated. Passing the same `held` into 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** - Measured: the suite, the red, both adapters' readings, every row of the edge table. - Reading: the 32 MiB re-ask in `draw.rs` and 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_for` with values, the OS budget did not move here), other GPU vendors, `--features diagnostics` suites other than the WARP probe. GPUs tested: one NVIDIA desktop card + WARP. AI-assisted: yes (Claude Code).
Jishnuraj07 commented 2026-12-02 17:54:02 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by Jishnuraj07 on 2026-12-02T17:54:02Z.


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 = main 23a68aec3; B = this head f854004db merged onto that same main (d8ebb8426). Both builds diagnostics,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.

Run Arm Verdict World s Median fps p5 fps VRAM peak / budget (MB) Over budget Shared peak (MB) Private peak (MB)
1 A main PASS 301 22.86 16.94 6,706 / 6,968 0 s 5,481 22,431
2 B PR PASS 307 20.06 15.47 6,744 / 7,060 0 s 5,245 22,280
3 B PR PASS* 303 19.47 12.26 6,837 / 6,955 0 s 5,199 22,258
4 A main PASS* 301 23.36 18.02 6,765 / 7,060 0 s 5,347 22,201

No crash, device loss or missed pipeline wait in any run. *Runs 3 and 4 carry the warnings killed and cache_not_saved: the gate found no window to send SC_CLOSE to (no close_sent event) and killed the game 60 s after the stop request. The gate's GateWindow.Close skips 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

  • No regression in the gate: the head passes 300 s in the world twice with the texture limit set.
  • It does not show the fix itself: main stayed 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 of main on this PC without the limit did go over (7,138 / 6,917 MB for 80 s, a memory_stop), so it can happen on this card, just not in these four.
  • The PR's arm was slower in both its runs. tools/d3d12_ab_compare.py abba over 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 is not 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 >= budget at the moment room() 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 that main makes. 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.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7353753757 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/3153#issuecomment-7353753757). Originally posted by [Jishnuraj07](https://github.com/Jishnuraj07) on 2026-12-02T17:54:02Z. --- **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 = `main` `23a68aec3`; B = this head `f854004db` merged onto that same `main` (`d8ebb8426`). Both builds `diagnostics,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. | Run | Arm | Verdict | World s | Median fps | p5 fps | VRAM peak / budget (MB) | Over budget | Shared peak (MB) | Private peak (MB) | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 1 | A `main` | PASS | 301 | 22.86 | 16.94 | 6,706 / 6,968 | 0 s | 5,481 | 22,431 | | 2 | B PR | PASS | 307 | 20.06 | 15.47 | 6,744 / 7,060 | 0 s | 5,245 | 22,280 | | 3 | B PR | PASS* | 303 | 19.47 | 12.26 | 6,837 / 6,955 | 0 s | 5,199 | 22,258 | | 4 | A `main` | PASS* | 301 | 23.36 | 18.02 | 6,765 / 7,060 | 0 s | 5,347 | 22,201 | No crash, device loss or missed pipeline wait in any run. \*Runs 3 and 4 carry the warnings `killed` and `cache_not_saved`: the gate found no window to send `SC_CLOSE` to (no `close_sent` event) and killed the game 60 s after the stop request. The gate's `GateWindow.Close` skips 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** - **No regression in the gate:** the head passes 300 s in the world twice with the texture limit set. - **It does not show the fix itself:** `main` stayed 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 of `main` on this PC without the limit did go over (7,138 / 6,917 MB for 80 s, a `memory_stop`), so it can happen on this card, just not in these four. - **The PR's arm was slower in both its runs.** `tools/d3d12_ab_compare.py abba` over 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 is `not 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 >= budget` at the moment `room()` 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 that `main` makes. 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 commented 2026-12-02 17:59:59 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-12-02T17:59:59Z.


Triage of head f854004db (merge base 69cd4106c, 38 commits behind; git merge-tree against current main 45dc41f95: no conflicts).

1 file: d3d12/crates/leonida-gpu/src/resource.rs (+89/-14).

CI is at action_required on this head (fork workflow approval).

Existing verification: @fiestorra ran scripts/red_green.py 3153 on this head: red does not compile (the tests call the new room_for), and the one green failure is descriptor::host::tests::views_are_made_beside_the_heap_and_copied_in, which fails on main on 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 of room_for return filled < limit, and a_texture_limit_stops_at_the_cards_budget fails at the at-budget assert).

This check: Read the diff: room() is split into a pure room_for() so the decision is unit-testable, and with LEONIDA_TEXTURE_BUDGET_MB set it now also requires used < 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 raw used, 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

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7353846652 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/3153#issuecomment-7353846652). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-12-02T17:59:59Z. --- **Triage of head `f854004db` (merge base `69cd4106c`, 38 commits behind; `git merge-tree` against current `main` `45dc41f95`: no conflicts).** 1 file: `d3d12/crates/leonida-gpu/src/resource.rs` (+89/-14). CI is at `action_required` on this head (fork workflow approval). **Existing verification:** @fiestorra ran `scripts/red_green.py 3153` on this head: red does not compile (the tests call the new `room_for`), and the one green failure is `descriptor::host::tests::views_are_made_beside_the_heap_and_copied_in`, which fails on `main` on 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 of `room_for` return `filled < limit`, and `a_texture_limit_stops_at_the_cards_budget` fails at the at-budget assert). **This check:** Read the diff: `room()` is split into a pure `room_for()` so the decision is unit-testable, and with `LEONIDA_TEXTURE_BUDGET_MB` set it now also requires `used < 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 raw `used`, 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](https://claude.ai/code)_
fiestorra commented 2026-12-02 23:09:15 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by fiestorra on 2026-12-02T23:09:15Z.


RE-VERIFIED-3153 at f854004db — red then green, and my first control was wrong

Your new head (the one after my correction at 15:49) passes:

cargo test -p leonida-gpu --lib resource     33 passed; 0 failed; 1 ignored
  resource::tests::a_texture_limit_stops_at_the_cards_budget ... ok
  resource::tests::without_a_texture_limit_the_share_of_the_budget_decides ... ok

And the moved red step is the right one now: with room_for's limit branch put back to the old filled < limit (no budget clause), it fails on the line you added:

assertion failed: !room_for(Some((budget, budget)), 3_000 * MIB, limit, 90, unused)

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.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7361631285 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/3153#issuecomment-7361631285). Originally posted by [fiestorra](https://github.com/fiestorra) on 2026-12-02T23:09:15Z. --- ## RE-VERIFIED-3153 at `f854004db` — `red then green`, and my first control was wrong **Your new head** (the one after my correction at 15:49) passes: ``` cargo test -p leonida-gpu --lib resource 33 passed; 0 failed; 1 ignored resource::tests::a_texture_limit_stops_at_the_cards_budget ... ok resource::tests::without_a_texture_limit_the_share_of_the_budget_decides ... ok ``` **And the moved red step is the right one now**: with `room_for`'s limit branch put back to the old `filled < limit` (no budget clause), it fails **on the line you added**: ``` assertion failed: !room_for(Some((budget, budget)), 3_000 * MIB, limit, 90, unused) ``` **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.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/3153:upstream-pr/3153'
git switch 'upstream-pr/3153'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/3153'
git switch 'upstream-pr/3153'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/3153'
git switch 'upstream-pr/3153'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/3153'
git switch 'main'
git merge --squash 'upstream-pr/3153'
git switch 'main'
git merge --ff-only 'upstream-pr/3153'
git switch 'main'
git merge 'upstream-pr/3153'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
No milestone
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.

Reference
ProjectLeonida/mandy!3153
No description provided.