Texture eviction: count as room only what is room (VICTORY_ROOM_BY_BLOCKS, opt-in) #3754

Closed
github-bot wants to merge 3 commits from github-bot/gh-3754 into main AGit
Owner

@⁠Trillazill on GitHub · 2026-11-30 06:01 UTC · original
Trillazill:fix/eviction-room-by-blocks → main · +111 −6 · 2 files · 3 commits · closed without merging

What this changes

The idle sweep (resource.rs, the card's rule in the idle-copy sweep) and slot eviction both take pool::texture_room() off the card's use before comparing it with their lines. texture_room() is every free byte in the texture blocks, however scattered. A block goes back to the system only when it is completely empty (Pool::reclaim), so a copy freed inside a sparse block lowers the counted use by its size and leaves the real use unchanged. Eviction reaches its low line and stops while DXGI still reports the card over budget. This is the fault #3680 describes from reading the code at 41adb551 (RTX 3070: the pool grew ~1.5 GB from minute 30 to 60 while the copies alive in it grew ~70 MB).

With VICTORY_ROOM_BY_BLOCKS=1 the two eviction sites use a new pool::texture_room_reusable() instead, which counts:

  • all of an empty block (it goes back under pressure), and
  • the holes of a block at least half held (fullest-first placement, VICTORY_POOL_FULLEST, fills those before a new block is made),

and nothing for the holes of a block less than half held, which the card keeps for its last copy.

The room for new textures (resource::room, room_for_first_upload, first_upload_headroom) is unchanged: a new texture that fits a hole does take it, and VICTORY_ROOM_REAL already guards that side.

Why opt-in

Not measured in a run yet. Counting less room makes the sweeps evict more, so on a card that is fine today it could cost re-uploads. It needs a before/after on an 8 GB card (the #3680, #3688 and #3683 setups) before it can be on by default. What to compare, with VICTORY_POOL_STATS=1: the pool's blocks and free bytes over 30–60 minutes, DXGI use against budget, and the "no room, new textures wait" count.

Tests

  • New: pool::tests::only_empty_blocks_and_holes_in_half_held_ones_count_as_room (a full block, a sparse one, an empty one; holes stop counting once a block falls under half held; an emptied block counts whole again).
  • cargo test -p victory-gpu --lib pool::: all 32 pass, the new one included.
  • cargo test -p victory-gpu --no-fail-fast: 922 pass; 1 fails, shader_cache::tests::every_switch_of_the_translator_is_in_the_key, and it fails the same way on 41adb551 without this change.
  • Clippy, both CI configurations: they stop in victory-shader on 41adb551 already (unused imports PAIR_MEETINGS and analysis::lane_regions, a loop condition never mutated), before reaching victory-gpu. Without -D warnings, clippy reports nothing in the lines this change adds or touches.
  • cargo test --workspace: victory-formats fails three bcpack::tests::oracle_parity_* tests on 41adb551 already.
  • cargo xtask policy --staged: ok (2 files).

Main's own failures are not touched here, to keep this change to one thing.

No game data, logs or other files from the title are in this change.

🤖 Generated with Claude Code

**@⁠Trillazill** on GitHub · 2026-11-30 06:01 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3754) `Trillazill:fix/eviction-room-by-blocks` → `main` · +111 −6 · 2 files · 3 commits · closed without merging ## What this changes The idle sweep (`resource.rs`, the card's rule in the idle-copy sweep) and slot eviction both take `pool::texture_room()` off the card's use before comparing it with their lines. `texture_room()` is every free byte in the texture blocks, however scattered. A block goes back to the system only when it is completely empty (`Pool::reclaim`), so a copy freed inside a sparse block lowers the *counted* use by its size and leaves the *real* use unchanged. Eviction reaches its low line and stops while DXGI still reports the card over budget. This is the fault #3680 describes from reading the code at 41adb551 (RTX 3070: the pool grew ~1.5 GB from minute 30 to 60 while the copies alive in it grew ~70 MB). With `VICTORY_ROOM_BY_BLOCKS=1` the two eviction sites use a new `pool::texture_room_reusable()` instead, which counts: - all of an empty block (it goes back under pressure), and - the holes of a block at least half held (fullest-first placement, `VICTORY_POOL_FULLEST`, fills those before a new block is made), and nothing for the holes of a block less than half held, which the card keeps for its last copy. The room for *new* textures (`resource::room`, `room_for_first_upload`, `first_upload_headroom`) is unchanged: a new texture that fits a hole does take it, and `VICTORY_ROOM_REAL` already guards that side. ## Why opt-in Not measured in a run yet. Counting less room makes the sweeps evict more, so on a card that is fine today it could cost re-uploads. It needs a before/after on an 8 GB card (the #3680, #3688 and #3683 setups) before it can be on by default. What to compare, with `VICTORY_POOL_STATS=1`: the pool's blocks and free bytes over 30–60 minutes, DXGI use against budget, and the "no room, new textures wait" count. ## Tests - New: `pool::tests::only_empty_blocks_and_holes_in_half_held_ones_count_as_room` (a full block, a sparse one, an empty one; holes stop counting once a block falls under half held; an emptied block counts whole again). - `cargo test -p victory-gpu --lib pool::`: all 32 pass, the new one included. - `cargo test -p victory-gpu --no-fail-fast`: 922 pass; 1 fails, `shader_cache::tests::every_switch_of_the_translator_is_in_the_key`, and it fails the same way on 41adb551 without this change. - Clippy, both CI configurations: they stop in `victory-shader` on 41adb551 already (unused imports `PAIR_MEETINGS` and `analysis::lane_regions`, a loop condition never mutated), before reaching `victory-gpu`. Without `-D warnings`, clippy reports nothing in the lines this change adds or touches. - `cargo test --workspace`: `victory-formats` fails three `bcpack::tests::oracle_parity_*` tests on 41adb551 already. - `cargo xtask policy --staged`: ok (2 files). Main's own failures are not touched here, to keep this change to one thing. No game data, logs or other files from the title are in this change. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
The idle sweep and slot eviction took every free byte of the texture
blocks off the card's use. A copy freed in a sparse block lowered that
count while the card kept the whole block, so eviction stopped while
the card stayed over budget. With VICTORY_ROOM_BY_BLOCKS=1 they count
only empty blocks and the holes of blocks at least half held
(pool::texture_room_reusable). The room for new textures is unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-30 06:02:51 +00:00
Author
Owner

@⁠tyr0nsur on GitHub · 2026-11-30 07:05 UTC · original

I tested a cherry-pickable follow-up on top of ba47955. Under the pool mutex, each block's held bytes include pieces still in REST, so an eligible block's currently reusable bytes are BLOCK - held. This keeps the same empty and half-held rules while replacing the free-range walk with one calculation per block. The test covers exactly half held, just before REST expires, and after the block falls below half held.

On this Windows rig, an optimized synthetic test with 96 half-held blocks and 49,152 free ranges returned the same byte count in both implementations. Median compute-only time went from 57.4 µs to 0.057 µs per call over five alternating batches. The final patch passed 29 pool tests (3 ignored) and the staged asset-policy check. Claude Opus 5.5 reviewed the accounting invariant.

A three-way merge with #3454 conflicts in the assignment to used in slot_evict. If both land, use raw DXGI usage at/over budget as #3454 intends, and call eviction_room() below budget to preserve this PR's opt-in there. The idle sweep can keep this PR's existing change. #3766 merged cleanly in a local three-way merge.

**@⁠tyr0nsur** on GitHub · 2026-11-30 07:05 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3754#issuecomment-7271338187) I tested a [cherry-pickable follow-up](https://github.com/tyr0nsur/VIctory-NVIDIA/commit/bba051d02f011552d9fd76966bbc1d6ff7014dc6) on top of `ba47955`. Under the pool mutex, each block's held bytes include pieces still in REST, so an eligible block's currently reusable bytes are `BLOCK - held`. This keeps the same empty and half-held rules while replacing the free-range walk with one calculation per block. The test covers exactly half held, just before REST expires, and after the block falls below half held. On this Windows rig, an optimized synthetic test with 96 half-held blocks and 49,152 free ranges returned the same byte count in both implementations. Median compute-only time went from 57.4 µs to 0.057 µs per call over five alternating batches. The final patch passed 29 pool tests (3 ignored) and the staged asset-policy check. Claude Opus 5.5 reviewed the accounting invariant. A three-way merge with #3454 conflicts in the assignment to `used` in `slot_evict`. If both land, use raw DXGI usage at/over budget as #3454 intends, and call `eviction_room()` below budget to preserve this PR's opt-in there. The idle sweep can keep this PR's existing change. #3766 merged cleanly in a local three-way merge.
Each block's held bytes include resting pieces. Subtract them from its capacity instead of walking every free range in the eviction pass. Account for a cut before tracing so an unwind does not leave that range counted as reusable.

Keep the existing half-held rule and test the exact threshold and retirement delay.
Author
Owner

@⁠Trillazill on GitHub · 2026-11-30 10:36 UTC · original

Thanks. I cherry-picked bba051d (now 6fbe09a, authorship kept). BLOCK - held is the right count, since held already includes resting pieces, and moving the accounting ahead of the trace is a good catch. All 29 pool:: tests pass here (3 ignored), and clippy reports nothing in pool.rs.

On the #3454 overlap in slot_evict: agreed. At or over the DXGI budget use the raw usage, as #3454 intends, and below it use eviction_room(). Whichever of the two lands second should take that resolution.

**@⁠Trillazill** on GitHub · 2026-11-30 10:36 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3754#issuecomment-7275834804) Thanks. I cherry-picked bba051d (now `6fbe09a`, authorship kept). `BLOCK - held` is the right count, since `held` already includes resting pieces, and moving the accounting ahead of the trace is a good catch. All 29 `pool::` tests pass here (3 ignored), and clippy reports nothing in `pool.rs`. On the #3454 overlap in `slot_evict`: agreed. At or over the DXGI budget use the raw usage, as #3454 intends, and below it use `eviction_room()`. Whichever of the two lands second should take that resolution.
Author
Owner

@⁠ffaddd-ddd on GitHub · 2026-11-30 19:11 UTC · original

Tested VICTORY_ROOM_BY_BLOCKS=1 here: an 8 GB RTX 4060 Laptop. Both runs used the same cache and the same settings, so the only difference is the switch.

Caveat first: neither run finished compiling. The exe built from 6fbe09a9 found 5,187 pipelines the previous build's cache did not cover, and 800+ of them were still being made during play. So the frame rates are not comparable — but the pool figures are, since the pool grows from texture requests and the no room verdict reads DXGI's figures, neither of which depends on compiling.

GPU      RTX 4060 Laptop 8 GB (8188 MiB), driver 610.88
CPU/RAM  Ryzen 9 7945HX, 32 GB (31.2 visible), Windows 11 23H2 22631.6199
Build    your head 6fbe09a9, built locally (SHA256 22CFDE40...)
Cache    89002 of 93799 pipelines (94.9%), same for both runs
Settings series-s 1280x720, DLSS off, no frame generation, cap 30

The three things you asked for

PR off (48 min) PR on (17 min)
pool blocks 72 / 4608 MB 71 / 4544 MB flat
blocks under 3/4 held 0 12 (2 under 1/2, 10 under 3/4) appeared
free inside the blocks 0-50 MB 364-406 MB headroom appeared
no room, new textures wait 98.7% (512/519) 93.1% (161/173) -5.6 points

The block distribution is the clearest part:

PR off:  <1/4: 0   <1/2: 0   <3/4: 0    >3/4: 72
PR on:   <1/4: 0   <1/2: 2   <3/4: 10   >3/4: 59

That is what reusable_free() should do: counting only the holes of blocks at least half held makes the sweeps evict sooner, so the pool stops being packed to the brim. Before, every one of the 72 blocks sat above three quarters.

It ended in a device removal, but I do not think it is this PR

19:01:23 ERROR host GPU device removed after 3 submissions sent ahead (VICTORY_RELAY=1)
  0x887A0004; device removed: The GPU device instance has been suspended (0x887A0005)

Just before it, six pipelines were made in 34-54 s and every one failed to load with 0x80070057:

42,872 ms / 46,772 ms / 39,354 ms / 34,335 ms / 53,702 ms / 38,582 ms

Process private bytes were 23,030 MB with 3.4-3.9 GB free on the PC.

That looks like the path compilemem.rs warns about — several workers compiling at once, the driver's compiler finds no memory, and a failure inside a driver library cannot be caught. The PR-off run had the same 94.9% cache and the same compiling, reached 25.3 GB private and 3.1 fps, and simply did not get as far. So it is the compile-side memory, not VICTORY_ROOM_BY_BLOCKS.

(Mentioning it here rather than filing anew: #3347 is the admission switch, and #3230 carries the same error string. I can add the logs there if useful.)

What I take from it

  1. The direction is right, and measurable — sparse blocks appear, the blocks end with real free space in them, no room falls.
  2. The size is modest here (5.6 points). On an 8 GB card the title's texture demand may simply exceed the budget, so counting room correctly removes some of the pressure but not all of it.
  3. It is opt-in and off by default, so merging it costs an existing user nothing.
  4. The pressing problem on 8 GB is the compile-side memory. That is separate and probably wants its own thread.

Happy to produce the per-second CSVs from both runs (time, fps, frame ms, preparing, GPU, copy-back, VramInUse, queue due) if you want to plot them — say the word.

**@⁠ffaddd-ddd** on GitHub · 2026-11-30 19:11 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3754#issuecomment-7288990560) Tested `VICTORY_ROOM_BY_BLOCKS=1` here: an 8 GB RTX 4060 Laptop. Both runs used the same cache and the same settings, so the only difference is the switch. **Caveat first:** neither run finished compiling. The exe built from `6fbe09a9` found 5,187 pipelines the previous build's cache did not cover, and 800+ of them were still being made during play. So **the frame rates are not comparable** — but the pool figures are, since the pool grows from texture requests and the `no room` verdict reads DXGI's figures, neither of which depends on compiling. ``` GPU RTX 4060 Laptop 8 GB (8188 MiB), driver 610.88 CPU/RAM Ryzen 9 7945HX, 32 GB (31.2 visible), Windows 11 23H2 22631.6199 Build your head 6fbe09a9, built locally (SHA256 22CFDE40...) Cache 89002 of 93799 pipelines (94.9%), same for both runs Settings series-s 1280x720, DLSS off, no frame generation, cap 30 ``` ## The three things you asked for | | PR off (48 min) | PR on (17 min) | | |---|---|---|---| | pool blocks | 72 / 4608 MB | 71 / 4544 MB | flat | | **blocks under 3/4 held** | **0** | **12** (2 under 1/2, 10 under 3/4) | appeared | | **free inside the blocks** | **0-50 MB** | **364-406 MB** | headroom appeared | | **`no room, new textures wait`** | **98.7%** (512/519) | **93.1%** (161/173) | -5.6 points | The block distribution is the clearest part: ``` PR off: <1/4: 0 <1/2: 0 <3/4: 0 >3/4: 72 PR on: <1/4: 0 <1/2: 2 <3/4: 10 >3/4: 59 ``` That is what `reusable_free()` should do: counting only the holes of blocks at least half held makes the sweeps evict sooner, so the pool stops being packed to the brim. Before, every one of the 72 blocks sat above three quarters. ## It ended in a device removal, but I do not think it is this PR ``` 19:01:23 ERROR host GPU device removed after 3 submissions sent ahead (VICTORY_RELAY=1) 0x887A0004; device removed: The GPU device instance has been suspended (0x887A0005) ``` Just before it, six pipelines were made in 34-54 s and every one failed to load with `0x80070057`: ``` 42,872 ms / 46,772 ms / 39,354 ms / 34,335 ms / 53,702 ms / 38,582 ms ``` Process private bytes were **23,030 MB** with 3.4-3.9 GB free on the PC. That looks like the path `compilemem.rs` warns about — several workers compiling at once, the driver's compiler finds no memory, and a failure inside a driver library cannot be caught. **The PR-off run had the same 94.9% cache and the same compiling, reached 25.3 GB private and 3.1 fps, and simply did not get as far.** So it is the compile-side memory, not `VICTORY_ROOM_BY_BLOCKS`. (Mentioning it here rather than filing anew: #3347 is the admission switch, and #3230 carries the same error string. I can add the logs there if useful.) ## What I take from it 1. The direction is right, and measurable — sparse blocks appear, the blocks end with real free space in them, `no room` falls. 2. The size is modest here (5.6 points). On an 8 GB card the title's texture demand may simply exceed the budget, so counting room correctly removes some of the pressure but not all of it. 3. It is opt-in and off by default, so merging it costs an existing user nothing. 4. The pressing problem on 8 GB is the compile-side memory. That is separate and probably wants its own thread. Happy to produce the per-second CSVs from both runs (time, fps, frame ms, preparing, GPU, copy-back, VramInUse, queue due) if you want to plot them — say the word.
github-bot changed title from Texture eviction: count as room only what is room (VICTORY_ROOM_BY_BLOCKS, opt-in) (#3680) to Texture eviction: count as room only what is room (VICTORY_ROOM_BY_BLOCKS, opt-in) 2026-12-01 06:26:12 +00:00
github-bot force-pushed github-bot/gh-3754 from 6fbe09a98d to e350295376 2026-12-01 06:26:14 +00:00 Compare
Author
Owner

@⁠Trillazill on GitHub · 2026-12-01 06:21 UTC · original

Rebased onto main 5fabb46e. Conflict in resource.rs: main's slot eviction now counts through queue_use; the free-room part goes through eviction_room() there, which is texture_room() unless VICTORY_ROOM_BY_BLOCKS=1, so the default is unchanged. One added commit: pool.add(0, BLOCK, 0) in the test, since Pool::add takes the block's size on main. Tests on the rebased branch: cargo test -p victory-gpu --lib -- pool:: resource:: 96 pass (4 ignored); cargo clippy -p victory-gpu --lib --tests no errors.

**@⁠Trillazill** on GitHub · 2026-12-01 06:21 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3754#issuecomment-7302780945) Rebased onto main 5fabb46e. Conflict in `resource.rs`: main's slot eviction now counts through `queue_use`; the free-room part goes through `eviction_room()` there, which is `texture_room()` unless `VICTORY_ROOM_BY_BLOCKS=1`, so the default is unchanged. One added commit: `pool.add(0, BLOCK, 0)` in the test, since `Pool::add` takes the block's size on main. Tests on the rebased branch: `cargo test -p victory-gpu --lib -- pool:: resource::` 96 pass (4 ignored); `cargo clippy -p victory-gpu --lib --tests` no errors.
github-bot closed this pull request 2026-12-01 18:51:21 +00:00
Author
Owner

@⁠trustno1-coder on GitHub · 2026-12-01 18:49 UTC · original

Closing this as part of moving main to the texture and video-memory rework (v2026.12.01.01-test). A lot of the code changed, and this pull request no longer applies cleanly to it; it would need to be rewritten against the new main rather than rebased. Thank you for the work. If the change is still needed, please open a new pull request based on the current main.

**@⁠trustno1-coder** on GitHub · 2026-12-01 18:49 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3754#issuecomment-7321601930) Closing this as part of moving main to the texture and video-memory rework (v2026.12.01.01-test). A lot of the code changed, and this pull request no longer applies cleanly to it; it would need to be rewritten against the new main rather than rebased. Thank you for the work. If the change is still needed, please open a new pull request based on the current main.

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/trustno1-coder--VIctory-NVIDIA!3754
No description provided.