Shaders can mark the pages they write through views: the translator's half (from VIctory and neonbyte1; off until the layer asks) #3641

Closed
banaanpapa wants to merge 2 commits from upstream-pr/3641 into main
banaanpapa commented 2026-11-30 02:26:17 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by banaanpapa on 2026-11-30T02:26:17Z.


Part 1 of 2: the shader translator's half of write marks, a port from Marvisak/VIctory (cd94d353) and neonbyte1/VIctory (GPL-3.0-or-later, as this tree). It changes nothing by itself: the marks are emitted only when the host asks (emit::set_view_marks), and nothing asks yet. The layer's half follows as its own pull request. No game was run.

Why

A copy in the card's memory whose shader writes are declared is compared on the card after every submission, every declared 64 KiB piece, to find what shaders wrote. host/lazy.rs has the figure for one copy: "2.2 GB of the card's reads a frame to find about 2.6 MB that shaders wrote", and its answer (VICTORY_LAZY_COMPARE_MB) is off because it can lose bytes. On the RTX 5080 here the compare reads 680 to 850 GB/s (indirect::tests::card_compare_costs), so those 2.2 GB are about 3 ms of the card a frame for that one heap; on a card a third as fast, three times that.

VIctory answered the same question on 2026-11-25 by having the shaders say what they write ("2.8-4.5 GB a frame, 98 % unchanged" before it). That mechanism is what this ports.

What a program does with marks on

Every store and atomic through an unordered buffer view it takes from the view heap (a table's, or one picked at an index) also sets a bit in the host's bitmap, the root UAV u249 (SLOT_VIEW_WRITES, 2^22 bits). The bit comes from the root SRV t249 (SLOT_VIEW_MARKS), two dwords for each title slot: a base bit and a phase. A write of byte x of the view sets bit base + ((phase + x) >> 16), for its first and its last byte. A base of VIEW_MARK_NONE marks nothing.

  • The bitmap's dword is read first, and the atomic runs only for a bit still clear (neonbyte1 3cb308dd).
  • Of the lanes of a wave with the same bit, one marks; in pixel programs the first that is no helper (neonbyte1 2b48889a).
  • Not marked: stores at computed addresses (they have their own page notes), through root unordered views, and into textures. The layer's half keeps comparing those in full.

What differs from VIctory's

  • The table and the bitmap are root views of ROOT_CBV_SPACE beside this tree's others (strides, sampled marks), not views of a space of their own.
  • The table is indexed as the stride tables are, by the title's slot (before the raw twin), so the layer can fill it where it writes a slot's stride.
  • A typed store's byte is its element times the stride in the tables' stride table (SLOT_TABLE_STRIDES); structured stores go through structured handles here, so their byte is the index times the stride, computed only with marks on.
  • The host turns the marks on (set_view_marks), not a switch of the translator's: a program with the two root views under a layer that does not bind them would read and write what is not there.

What was run

  • emit::waterfall_tests::stores_through_a_tables_view_mark_their_pages, on the RTX 5080 and on WARP, validated by dxil.dll: a program that stores 24 dwords through a table's unordered view sets exactly the bits of the pages it writes: one page; two, with the view beginning 40 bytes before a page's end; two, with only the last byte of the last write in the next page; one, a view that begins three pages in; and none for a view without bits (the whole bitmap is read back, its last bit too). The stored dwords are as without marks. All of it with one lane marking for the wave and with every lane marking, to the same bits.
  • It fails when only a write's first byte is marked, when the phase is left out, and when a view without bits marks.
  • cargo test -p victory-shader --release --lib: 463 pass, none fail, with the marks off (the default). Forced on for the whole suite, no program fails validation; the tests that then fail are those whose host does not bind the two views, which is what the host's flag is there to prevent.
  • Clippy on the crate: nothing on a line this adds.

Limits

  • Atomics, typed stores, stores of bytes and halves, and views picked per lane are emitted by the same function and validated, but only a raw store through a table's view is run on a device here.
  • What a mark costs on the card across the title's own programs is not known; VIctory has it on with no switch. That, and how much of what is compared today is written through views at all, is for the layer's half and a run to say.
  • The branch is on f72cec77; it was built and tested merged with 41adb551, and the merge is clean.

The check

The check job fails here as it does on main: Clippy stops at crates/victory-loader/src/crash.rs:804 (unwind_copy is never used), a file this branch does not touch.

Merged with main (2026-11-30, c71899d9)

Two files conflicted: main gave heap_handle_noted a key by which a sampled mark is made once along dominated paths (fc07cc51), and this branch gave it the title's slot. Both are kept. Run again on the merged branch: the write-marks test passes on the card and on WARP; of the crate's 546 tests 535 pass and one fails, emit::bitcode::opt::tests::hw_tests::split_lds_wave32_read_after_read_barrier_coalescing_and_parity, which fails the same way on main built by itself (opt.rs:7736, a file this branch does not touch).

Measured in play: the marks cost more card time than they save (2026-11-30)

One 9-minute session in the title's world on an RTX 5080 (driver 621.40, e1251c31 with #3641 and #4173, about 4,800 draws a frame, the card 99 % busy), compared with sessions in the same scene without marks:

without marks VICTORY_VIEW_MARKS=1
card time of the title's lists 25.0 ms 31.8 ms
frame median 27.1 ms 33.8 ms
our compare lists (what the marks save) 0.2 ms 0.2 ms

The extra card time holds through the session (31-32 ms in each quarter, no pipelines being made). Coverage was high: per frame 300 compared copies were left to their marks and 18 were compared whole. But on a card that is the frame's limit, the work each marked store does costs about 27 % more card time, and the compare it saves is only 0.2 ms. So on this card the marks are a loss as built, and should stay off. A slower card whose compare costs milliseconds might come out differently; that hasn't been measured.

🤖 Generated with Claude Code

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:issue:5557870718 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3641). Originally posted by [banaanpapa](https://github.com/banaanpapa) on 2026-11-30T02:26:17Z. --- Part 1 of 2: the shader translator's half of write marks, a port from Marvisak/VIctory (cd94d353) and neonbyte1/VIctory (GPL-3.0-or-later, as this tree). It changes nothing by itself: the marks are emitted only when the host asks (`emit::set_view_marks`), and nothing asks yet. The layer's half follows as its own pull request. No game was run. ## Why A copy in the card's memory whose shader writes are declared is compared on the card after every submission, every declared 64 KiB piece, to find what shaders wrote. `host/lazy.rs` has the figure for one copy: "2.2 GB of the card's reads a frame to find about 2.6 MB that shaders wrote", and its answer (`VICTORY_LAZY_COMPARE_MB`) is off because it can lose bytes. On the RTX 5080 here the compare reads 680 to 850 GB/s (`indirect::tests::card_compare_costs`), so those 2.2 GB are about 3 ms of the card a frame for that one heap; on a card a third as fast, three times that. VIctory answered the same question on 2026-11-25 by having the shaders say what they write ("2.8-4.5 GB a frame, 98 % unchanged" before it). That mechanism is what this ports. ## What a program does with marks on Every store and atomic through an unordered buffer view it takes from the view heap (a table's, or one picked at an index) also sets a bit in the host's bitmap, the root UAV `u249` (`SLOT_VIEW_WRITES`, 2^22 bits). The bit comes from the root SRV `t249` (`SLOT_VIEW_MARKS`), two dwords for each title slot: a base bit and a phase. A write of byte `x` of the view sets bit `base + ((phase + x) >> 16)`, for its first and its last byte. A base of `VIEW_MARK_NONE` marks nothing. - The bitmap's dword is read first, and the atomic runs only for a bit still clear (neonbyte1 3cb308dd). - Of the lanes of a wave with the same bit, one marks; in pixel programs the first that is no helper (neonbyte1 2b48889a). - Not marked: stores at computed addresses (they have their own page notes), through root unordered views, and into textures. The layer's half keeps comparing those in full. ## What differs from VIctory's - The table and the bitmap are root views of `ROOT_CBV_SPACE` beside this tree's others (strides, sampled marks), not views of a space of their own. - The table is indexed as the stride tables are, by the title's slot (before the raw twin), so the layer can fill it where it writes a slot's stride. - A typed store's byte is its element times the stride in the tables' stride table (`SLOT_TABLE_STRIDES`); structured stores go through structured handles here, so their byte is the index times the stride, computed only with marks on. - The host turns the marks on (`set_view_marks`), not a switch of the translator's: a program with the two root views under a layer that does not bind them would read and write what is not there. ## What was run - `emit::waterfall_tests::stores_through_a_tables_view_mark_their_pages`, on the RTX 5080 and on WARP, validated by `dxil.dll`: a program that stores 24 dwords through a table's unordered view sets exactly the bits of the pages it writes: one page; two, with the view beginning 40 bytes before a page's end; two, with only the last byte of the last write in the next page; one, a view that begins three pages in; and none for a view without bits (the whole bitmap is read back, its last bit too). The stored dwords are as without marks. All of it with one lane marking for the wave and with every lane marking, to the same bits. - It fails when only a write's first byte is marked, when the phase is left out, and when a view without bits marks. - `cargo test -p victory-shader --release --lib`: 463 pass, none fail, with the marks off (the default). Forced on for the whole suite, no program fails validation; the tests that then fail are those whose host does not bind the two views, which is what the host's flag is there to prevent. - Clippy on the crate: nothing on a line this adds. ## Limits - Atomics, typed stores, stores of bytes and halves, and views picked per lane are emitted by the same function and validated, but only a raw store through a table's view is run on a device here. - What a mark costs on the card across the title's own programs is not known; VIctory has it on with no switch. That, and how much of what is compared today is written through views at all, is for the layer's half and a run to say. - The branch is on `f72cec77`; it was built and tested merged with `41adb551`, and the merge is clean. ## The check The `check` job fails here as it does on `main`: Clippy stops at `crates/victory-loader/src/crash.rs:804` (`unwind_copy` is never used), a file this branch does not touch. ## Merged with `main` (2026-11-30, `c71899d9`) Two files conflicted: `main` gave `heap_handle_noted` a key by which a sampled mark is made once along dominated paths (fc07cc51), and this branch gave it the title's slot. Both are kept. Run again on the merged branch: the write-marks test passes on the card and on WARP; of the crate's 546 tests 535 pass and one fails, `emit::bitcode::opt::tests::hw_tests::split_lds_wave32_read_after_read_barrier_coalescing_and_parity`, which fails the same way on `main` built by itself (`opt.rs:7736`, a file this branch does not touch). ## Measured in play: the marks cost more card time than they save (2026-11-30) One 9-minute session in the title's world on an RTX 5080 (driver 621.40, `e1251c31` with #3641 and #4173, about 4,800 draws a frame, the card 99 % busy), compared with sessions in the same scene without marks: | | without marks | `VICTORY_VIEW_MARKS=1` | |---|---|---| | card time of the title's lists | 25.0 ms | 31.8 ms | | frame median | 27.1 ms | 33.8 ms | | our compare lists (what the marks save) | 0.2 ms | 0.2 ms | The extra card time holds through the session (31-32 ms in each quarter, no pipelines being made). Coverage was high: per frame 300 compared copies were left to their marks and 18 were compared whole. But on a card that is the frame's limit, the work each marked store does costs about 27 % more card time, and the compare it saves is only 0.2 ms. So on this card the marks are a loss as built, and should stay off. A slower card whose compare costs milliseconds might come out differently; that hasn't been measured. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
mstrmoos commented 2026-11-30 19:22:29 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by mstrmoos on 2026-11-30T19:22:29Z.


Picked together with #3626 on the RTX 5080 16 GB, Ryzen 7 9800X3D, Windows 11, Series X profile, same save and 90 s bench route each run.

The frame median was 40.0 ms before and 40.4 ms after, which is within noise. That's expected: this is the translator's half, and nothing reads its marks until the layer's half lands.

cargo test -p victory-gpu and -p victory-shader passed after a one-line fix in a land.rs test: jobs was shadowed. That fix came from the merge with #3626, not from this PR.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7289287689 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3641#issuecomment-7289287689). Originally posted by [mstrmoos](https://github.com/mstrmoos) on 2026-11-30T19:22:29Z. --- Picked together with #3626 on the RTX 5080 16 GB, Ryzen 7 9800X3D, Windows 11, Series X profile, same save and 90 s bench route each run. The frame median was 40.0 ms before and 40.4 ms after, which is within noise. That's expected: this is the translator's half, and nothing reads its marks until the layer's half lands. `cargo test -p victory-gpu` and `-p victory-shader` passed after a one-line fix in a `land.rs` test: `jobs` was shadowed. That fix came from the merge with #3626, not from this PR.
banaanpapa commented 2026-11-30 20:00:50 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by banaanpapa on 2026-11-30T20:00:50Z.


Thank you for running it in the game. As you say, this half on its own changes nothing: the marks are read only with #4173 and VICTORY_VIEW_MARKS=1, and then the translations change, so the shader cache has to be filled again.

To set expectations for #4173: on my RTX 5080 the in-game logs put our compare lists at about 0.3 ms of card time a frame. That's all the marks can save on a card that fast, and that PC is limited by the submitting thread, not the card. The bench in #4173 shows a 15x cut of that compare work, so slower cards should gain more.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7290273634 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3641#issuecomment-7290273634). Originally posted by [banaanpapa](https://github.com/banaanpapa) on 2026-11-30T20:00:50Z. --- Thank you for running it in the game. As you say, this half on its own changes nothing: the marks are read only with #4173 and `VICTORY_VIEW_MARKS=1`, and then the translations change, so the shader cache has to be filled again. To set expectations for #4173: on my RTX 5080 the in-game logs put our compare lists at about 0.3 ms of card time a frame. That's all the marks can save on a card that fast, and that PC is limited by the submitting thread, not the card. The bench in #4173 shows a 15x cut of that compare work, so slower cards should gain more.
trustno1-coder commented 2026-12-01 18:50:13 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by trustno1-coder on 2026-12-01T18:50:13Z.


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.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7321641932 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3641#issuecomment-7321641932). Originally posted by [trustno1-coder](https://github.com/trustno1-coder) on 2026-12-01T18:50:13Z. --- 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

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!3641
No description provided.