Textures picked by index: shaders mark the slots they sample (VICTORY_SAMPLED_MARKS=1, off by default) #1074

Merged
psttt432454 merged 1 commit from upstream-pr/1074 into main 2026-11-28 19:39:38 +00:00
psttt432454 commented 2026-11-28 12:44:58 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by psttt432454 on 2026-11-28T12:44:58Z.


Why

Slot eviction (VICTORY_SLOT_EVICT=1, on in the launchers) can't take a texture if a slot that shaders pick by index shows it, because nothing says whether a shader still reads it. On an RTX 5070 Laptop 8 GB, #943 measured that 7,904 of 7,918 idle-looking textures were left out for that reason, and only 5 MB were freed in a whole session. The card stays full, no room, new textures wait, and textures come in late or not at all (houses without textures here; #1030, #984 and #955 look related).

This is step 1: measure whether shaders could tell us. Nothing that eviction does changes.

The change

VICTORY_SAMPLED_MARKS=1 turns it on. It's off by default; unset, no shader and no draw changes.

  • Translator: every texture read or sample (image_*, not stores) through a slot picked from the view heap sets that slot's bit in a root UAV of ours, u251 in space 1 (SLOT_SAMPLED, 2^22 bits, 512 KiB).
    • The dword is read first, and the atomic OR runs only for a bit that isn't set yet, so the pixels of a draw don't all queue on one address.
    • The mark is emitted after the image instruction, because image emits into the block it began in. Branching inside it broke block order ("forward reference outside a phi"), which the new test caught.
    • The switch is read in the shader crate, so it enters translation_fingerprint and translations are cached apart.
  • Host:
    • SLOT_SAMPLED is one of our root descriptors, like SLOT_FAULTS, and draw.rs binds it.
    • The buffer lies in card memory the CPU maps (mapped_card_buffer, GPU_UPLOAD) where there is some, and in the PC's memory otherwise (slow, see below; logged with in_card).
    • The CPU takes a 32nd of the buffer each frame with streaming loads: reading all 512 KiB took 20 ms on this machine. Each bit goes into the frame its slot was last marked in.
  • Slot eviction's pass (evictable_slots) also notes, of the textures it may not take, those that no shader marked and no table showed since its idle cutoff. A line every 5 s:
texture slots shaders sampled (VICTORY_SAMPLED_MARKS=1): 2919 marked over the last 32 frames; slot eviction's last pass: of 13682 textures it may not take as a slot shaders pick by index shows them, 12009 were marked by no shader within its idle time (1181 MB)

Measured

RTX 5070 Laptop 8 GB (DXGI budget ~7.1 GB), Ryzen 9 HX, 32 GB, Windows 11. victory play --series-s, same save and spot, shader cache warm, about 3 minutes in the world each.

main 63b902fe marks, buffer in the PC's memory marks, buffer in card memory
fps (5 s lines) 17.9-18.7 3.8-4.6 17.9-21.2
on the GPU per frame 1.4-3.5 ms 188-208 ms 3.0-17.3 ms
frame 53-56 ms 216-264 ms 47-56 ms

GPU time rises by a few ms, but the frame waits for preparing (25-30 ms), so the frame rate doesn't move. The picture had no new faults, and no new errors were logged. The one shader that does not translate (6b82bc7d22016cb5, wave64) is the same on main.

What the marks say (three runs, lines from the world):

textures eviction may not take of them marked by no shader within its idle time (30 s)
run 1 12,757-14,281 10,386-12,858 (75-91 %), 960-1,226 MB
run 2 13,512-13,715 11,389-12,825 (84-94 %), 1,035-1,282 MB
run 3 5,956-9,350 5,439-7,982 (85-91 %), 535-979 MB

Shaders sample about 2,000-3,500 of those slots in a sweep of 32 frames. So on this card, about 0.5-1.2 GB is held by textures that nothing reads.

Next step (not in this PR)

Let slot eviction take those textures too: a texture picked by index whose slots no shader marked within the idle time. A texture taken this way and then sampled again reads its null slot until it is made again, so step 2 needs that path, and it has to be measured with the picture watched. One caveat for it: a shared slot index across two heaps reads as marked for both, which only keeps a texture longer. A mark lost between the CPU's read and its clear waits for the next read, at most one sweep later.

Tests

  • New emit::waterfall_tests::a_picked_texture_marks_its_slot_with_sampled_marks: with marks on, a sample through a picked slot adds u251, and the shader passes the DXIL validator; with marks off, nothing changes.
  • New sampled::tests::a_stamp_counts_from_the_cutoff_on (including the wrap of the low 32 bits), and the ignored marks_read_cost (by hand: whether card memory the CPU maps is there, and what reading the buffer costs).
  • cargo test -p victory-shader -p victory-gpu --lib --locked: all pass (victory-gpu 454 passed, 36 ignored; victory-shader 294 passed, 5 ignored).
  • Clippy --all-targets: nothing in the changed lines. It stops on main's own manual_is_multiple_of (shadow.rs:1708) and let_and_return (emit/mod.rs).

Not tested: other cards (AMD, Intel, cards without a resizable BAR, where the buffer falls back to the PC's memory and costs a lot), Series X, frame generation.

No game files, dumps or extracted data are included.

🤖 Generated with Claude Code

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:issue:5540247220 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/1074). Originally posted by [psttt432454](https://github.com/psttt432454) on 2026-11-28T12:44:58Z. --- ## Why Slot eviction (`VICTORY_SLOT_EVICT=1`, on in the launchers) can't take a texture if a slot that shaders pick by index shows it, because nothing says whether a shader still reads it. On an RTX 5070 Laptop 8 GB, #943 measured that 7,904 of 7,918 idle-looking textures were left out for that reason, and only 5 MB were freed in a whole session. The card stays full, `no room, new textures wait`, and textures come in late or not at all (houses without textures here; #1030, #984 and #955 look related). This is step 1: measure whether shaders could tell us. Nothing that eviction does changes. ## The change `VICTORY_SAMPLED_MARKS=1` turns it on. It's off by default; unset, no shader and no draw changes. - **Translator:** every texture read or sample (`image_*`, not stores) through a slot picked from the view heap sets that slot's bit in a root UAV of ours, `u251` in space 1 (`SLOT_SAMPLED`, 2^22 bits, 512 KiB). - The dword is read first, and the atomic OR runs only for a bit that isn't set yet, so the pixels of a draw don't all queue on one address. - The mark is emitted after the image instruction, because `image` emits into the block it began in. Branching inside it broke block order ("forward reference outside a phi"), which the new test caught. - The switch is read in the shader crate, so it enters `translation_fingerprint` and translations are cached apart. - **Host:** - `SLOT_SAMPLED` is one of our root descriptors, like `SLOT_FAULTS`, and `draw.rs` binds it. - The buffer lies in card memory the CPU maps (`mapped_card_buffer`, `GPU_UPLOAD`) where there is some, and in the PC's memory otherwise (slow, see below; logged with `in_card`). - The CPU takes a 32nd of the buffer each frame with streaming loads: reading all 512 KiB took 20 ms on this machine. Each bit goes into the frame its slot was last marked in. - **Slot eviction's pass** (`evictable_slots`) also notes, of the textures it may not take, those that no shader marked and no table showed since its idle cutoff. A line every 5 s: ``` texture slots shaders sampled (VICTORY_SAMPLED_MARKS=1): 2919 marked over the last 32 frames; slot eviction's last pass: of 13682 textures it may not take as a slot shaders pick by index shows them, 12009 were marked by no shader within its idle time (1181 MB) ``` ## Measured RTX 5070 Laptop 8 GB (DXGI budget ~7.1 GB), Ryzen 9 HX, 32 GB, Windows 11. `victory play --series-s`, same save and spot, shader cache warm, about 3 minutes in the world each. | | main `63b902fe` | marks, buffer in the PC's memory | **marks, buffer in card memory** | |---|---:|---:|---:| | fps (5 s lines) | 17.9-18.7 | 3.8-4.6 | **17.9-21.2** | | on the GPU per frame | 1.4-3.5 ms | 188-208 ms | 3.0-17.3 ms | | frame | 53-56 ms | 216-264 ms | 47-56 ms | GPU time rises by a few ms, but the frame waits for preparing (25-30 ms), so the frame rate doesn't move. The picture had no new faults, and no new errors were logged. The one shader that does not translate (`6b82bc7d22016cb5`, wave64) is the same on main. What the marks say (three runs, lines from the world): | | textures eviction may not take | of them marked by no shader within its idle time (30 s) | |---|---:|---:| | run 1 | 12,757-14,281 | 10,386-12,858 (75-91 %), 960-1,226 MB | | run 2 | 13,512-13,715 | 11,389-12,825 (84-94 %), 1,035-1,282 MB | | run 3 | 5,956-9,350 | 5,439-7,982 (85-91 %), 535-979 MB | Shaders sample about 2,000-3,500 of those slots in a sweep of 32 frames. So on this card, about 0.5-1.2 GB is held by textures that nothing reads. ## Next step (not in this PR) Let slot eviction take those textures too: a texture picked by index whose slots no shader marked within the idle time. A texture taken this way and then sampled again reads its null slot until it is made again, so step 2 needs that path, and it has to be measured with the picture watched. One caveat for it: a shared slot index across two heaps reads as marked for both, which only keeps a texture longer. A mark lost between the CPU's read and its clear waits for the next read, at most one sweep later. ## Tests - New `emit::waterfall_tests::a_picked_texture_marks_its_slot_with_sampled_marks`: with marks on, a sample through a picked slot adds `u251`, and the shader passes the DXIL validator; with marks off, nothing changes. - New `sampled::tests::a_stamp_counts_from_the_cutoff_on` (including the wrap of the low 32 bits), and the ignored `marks_read_cost` (by hand: whether card memory the CPU maps is there, and what reading the buffer costs). - `cargo test -p victory-shader -p victory-gpu --lib --locked`: all pass (victory-gpu 454 passed, 36 ignored; victory-shader 294 passed, 5 ignored). - Clippy `--all-targets`: nothing in the changed lines. It stops on main's own `manual_is_multiple_of` (`shadow.rs:1708`) and `let_and_return` (`emit/mod.rs`). Not tested: other cards (AMD, Intel, cards without a resizable BAR, where the buffer falls back to the PC's memory and costs a lot), Series X, frame generation. No game files, dumps or extracted data are included. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
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
trustno1-coder/VIctory-NVIDIA!1074
No description provided.