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

Closed
github-bot wants to merge 2 commits from github-bot/gh-3641 into main AGit
Owner

@⁠banaanpapa on GitHub · 2026-11-30 02:26 UTC · original
banaanpapa:port/view-marks → main · +434 −21 · 5 files · 2 commits · closed without merging

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 #4174, 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

**@⁠banaanpapa** on GitHub · 2026-11-30 02:26 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3641) `banaanpapa:port/view-marks` → `main` · +434 −21 · 5 files · 2 commits · closed without merging 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 #4174, 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)
When the host asks for it (`emit::set_view_marks`; nothing does yet, so
no program changes), every store and atomic a translated program makes
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 a bitmap of the host's, the
root UAV u249: one bit for each 64 KiB page of title memory, by a base bit
and a phase the host keeps for the view's slot in the root SRV t249. The
host can then know which pages shaders wrote, where today it compares on
the card all that a view could have written. The layer's half (the bits,
the table, the bitmap, and a compare that leaves unmarked pages out) is
to follow, with the switch.

- The bitmap's dword is read first and the atomic runs only for a bit
  still clear; of the lanes of a wave with the same bit one marks (in
  pixel programs the first that is no helper).
- Not marked: stores at computed addresses (they have their own page
  notes), through root unordered views, and into textures.
- The table is indexed as the stride tables are, by the title's slot
  (before the raw twin), and a typed store's byte is its element times
  the stride in the tables' stride table.

`stores_through_a_tables_view_mark_their_pages` runs a program on the card
and on WARP: exactly the bits of the pages written, across a page's end,
with only a write's last byte in the next page, and none for a view
without bits, with one lane marking and with every lane. It fails when
only the first byte is marked, when the phase is left out, and when a
view without bits marks. The crate's 463 tests pass as before.

(From VIctory cd94d353, "GPU: shaders mark the pages they write through
views; copy-backs compare only those", with 3cb308dd and 2b48889a of
neonbyte1/VIctory. Their tables live in a space of their own and are
indexed by the handle's slot; here they are root views beside the others,
and the host turns the marks on, not a switch of the translator's.)

Co-Authored-By: Claude Fable 5.2 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-30 02:26:37 +00:00
Conflicts in emit/lower.rs and emit/mod.rs: main gave heap_handle_noted a
key by which a sampled mark is made once along dominated paths (fc07cc51);
this branch gave it the title's slot for write marks. Both are kept.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
Author
Owner

@⁠mstrmoos on GitHub · 2026-11-30 19:22 UTC · original

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.

**@⁠mstrmoos** on GitHub · 2026-11-30 19:22 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3641#issuecomment-7289287689) 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.
Author
Owner

@⁠banaanpapa on GitHub · 2026-11-30 20:00 UTC · original

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

To set expectations for #4174: 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 #4174 shows a 15x cut of that compare work, so slower cards should gain more.

**@⁠banaanpapa** on GitHub · 2026-11-30 20:00 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3641#issuecomment-7290273634) Thank you for running it in the game. As you say, this half on its own changes nothing: the marks are read only with #4174 and `VICTORY_VIEW_MARKS=1`, and then the translations change, so the shader cache has to be filled again. To set expectations for #4174: 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 #4174 shows a 15x cut of that compare work, so slower cards should gain more.
Author
Owner

@⁠trustno1-coder on GitHub · 2026-12-01 18:50 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:50 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3641#issuecomment-7321641932) 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.
github-bot closed this pull request 2026-12-01 18:58:06 +00:00

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