Shaders mark the pages they write, and the compare reads only those (VICTORY_VIEW_MARKS=1): the layer's half #4174

Closed
github-bot wants to merge 4 commits from github-bot/gh-4173 into main AGit
Owner

@⁠banaanpapa on GitHub · 2026-11-30 17:02 UTC · original
banaanpapa:port/view-marks-layer → main · +1360 −38 · 15 files · 4 commits · closed without merging

Part 2 of 2, stacked on #3641 (its commits are the first here; the last commit is this one's). Off unless VICTORY_VIEW_MARKS=1; with it off nothing changes. No game was run: the figures are from the card alone (RTX 5080, driver 621.24).

Why

A copy in the card's memory whose shader writes are declared is compared on the card after every submission, every declared piece of 64 KiB: for the title's heap of 174 MB, "2.2 GB of the card's reads a frame to find about 2.6 MB that shaders wrote" (host/lazy.rs). The launcher now sets VICTORY_LAZY_COMPARE_MB=64, which compares fewer pieces by guessing which were written lately and can lose bytes (its own header says where). With write marks the shaders say which pages they wrote, and the compare reads those and no others: nothing is guessed.

What this half adds

  • view_marks.rs: the switch (it is in the shader cache's key, and its first asking tells the translator), a run of bits for each copy in the card's memory (one for each piece the compare cuts, so bit base + piece is that piece), and the bitmap, 512 KiB in the card's own memory.
  • The table: a view's base bit and phase are written where its stride is, into two dwords a slot after the strides and the view addresses in the same buffer. A slot whose stride is written has no marks until a view with bits is made there.
  • Who is believed: a stage that has u<SLOT_VIEW_WRITES> declares what it writes through tables' views as marked. Everything else that declares a write (the layer's own copies, stores at computed addresses, root views, picked) notes the copy as having an unmarked writer in that list, and the submission's compare then takes that copy's ranges whole, as before. So do copies with no bits left, ranges lazy picked, two queues, and windows that grow.
  • card_compare_marks: the batch compare with one more constant (the copy's base bit) and the bitmap. A piece whose bit is clear is not read: its dword of differs is 0 and its stored hash stays, as that of a piece lazy leaves out does. A piece whose bit is set is compared as ever and its bit cleared. Its source is made from CARD_COMPARE_BATCH's by five replacements that are checked to match once each, so the two cannot drift apart unseen.
  • With VICTORY_UNIFIED_BACK the pieces a class keeps for the copy-back are declared the same way, so the two work together.

A bit that is set and should not be costs a compare. Nothing clears a bit but the compare that read it.

Measured

indirect::tests::what_the_compare_by_marks_saves_the_card (ignored; run by name): the heap of 174 MB declared whole, 2,784 pieces, compared after each of 12 submissions. Best of six, three runs:

The card's time
Every piece (CARD_COMPARE_BATCH) 2.45 ms
By marks, none marked, the bitmap in the card's memory (as the layer has it) 0.16 ms
By marks, 40 pieces marked, the bitmap in the PC's memory 1.43 to 1.44 ms
By marks, none marked, the bitmap in the PC's memory 1.47 to 1.49 ms

The last two rows are why the bitmap is in the card's memory: every thread reads a dword of it, and over the bus that is most of the pass.

Tests

  • the_compare_by_marks_reads_the_marked_pieces_and_clears_their_bits, on WARP and on the card: against the batch compare, a marked piece gets the same dword and the same stored hash and its bit is cleared; an unmarked piece gets 0 though its bytes changed and keeps its hash; other copies' bits around this one's stay; a pass that stores hashes reads every piece; a piece marked later is found by its stale hash. It fails when a clear bit is compared all the same, when the base is left out, and when the bit read is not cleared.
  • a_views_bits_are_the_pieces_the_compare_cuts: for 20,000 copies and views, the bit of a view's first byte is the first piece of its range as the compare cuts it, the bit a program computes for its last byte is the last piece, and a copy takes as many bits as it has pieces.
  • runs_of_bits_are_apart_and_come_back: the bits' allocator.
  • a_copy_is_left_to_its_marks_only_while_every_writer_marks (added after the first push; run with the switch and without): through real host lists, what a marking shader, a shader that does not mark and a copy of the layer's own each declare is declared; with the switch a copy in the card's memory has a run of bits and a view's entry is its first byte's piece and offset; the copy is left to its marks only while every writer of the submission marks; a list's reset forgets what it noted. Without the switch no copy has bits and nothing is left to the marks. It fails when a writer that does not mark is not noted, and when every shader is taken to mark.
  • cargo test -p victory-gpu --release --lib with the switch off and with it on: 1,116 pass both ways; the three that fail are main's (shader_cache's key test, list::thin::tests::bindings_record_no_work, and the uav_pool lifecycle test now and then). Run with #4115 applied and not committed here (the crate's tests do not compile on main without it).
  • Clippy, with and without the diagnostics feature: nothing on a line this adds.

Limits

  • No title run. What the marks cost the title's own programs on the card, and how much of what is compared today is written through tables' views, is for a run to say. LEFT_TO_MARKS counts the pieces given to the compare by marks.
  • No test here takes a translated program through the layer from its store to the compare: #3641 shows on a device that a program sets the right bits, this one that the compare reads them, and the arithmetic test that the two mean the same piece. Who is believed to mark is tested through real lists (above); the table's filling at a slot and the binding of the two root views are exercised only by the crate's tests passing with the switch on.
  • With the switch on, a copy is made when an unordered view's slot is written (its bits are asked for there), not at its first draw.
  • Only the batched compare knows the marks; with VICTORY_CARD_BATCH=0 ranges are compared whole.

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 17:02 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4173) `banaanpapa:port/view-marks-layer` → `main` · +1360 −38 · 15 files · 4 commits · closed without merging Part 2 of 2, stacked on #3641 (its commits are the first here; the last commit is this one's). Off unless `VICTORY_VIEW_MARKS=1`; with it off nothing changes. No game was run: the figures are from the card alone (RTX 5080, driver 621.24). ## Why A copy in the card's memory whose shader writes are declared is compared on the card after every submission, every declared piece of 64 KiB: for the title's heap of 174 MB, "2.2 GB of the card's reads a frame to find about 2.6 MB that shaders wrote" (`host/lazy.rs`). The launcher now sets `VICTORY_LAZY_COMPARE_MB=64`, which compares fewer pieces by guessing which were written lately and can lose bytes (its own header says where). With write marks the shaders say which pages they wrote, and the compare reads those and no others: nothing is guessed. ## What this half adds - **`view_marks.rs`**: the switch (it is in the shader cache's key, and its first asking tells the translator), a run of bits for each copy in the card's memory (one for each piece the compare cuts, so bit `base + piece` is that piece), and the bitmap, 512 KiB in the card's own memory. - **The table**: a view's base bit and phase are written where its stride is, into two dwords a slot after the strides and the view addresses in the same buffer. A slot whose stride is written has no marks until a view with bits is made there. - **Who is believed**: a stage that has `u<SLOT_VIEW_WRITES>` declares what it writes through tables' views as marked. Everything else that declares a write (the layer's own copies, stores at computed addresses, root views, `picked`) notes the copy as having an unmarked writer in that list, and the submission's compare then takes that copy's ranges whole, as before. So do copies with no bits left, ranges `lazy` picked, two queues, and windows that grow. - **`card_compare_marks`**: the batch compare with one more constant (the copy's base bit) and the bitmap. A piece whose bit is clear is not read: its dword of `differs` is 0 and its stored hash stays, as that of a piece `lazy` leaves out does. A piece whose bit is set is compared as ever and its bit cleared. Its source is made from `CARD_COMPARE_BATCH`'s by five replacements that are checked to match once each, so the two cannot drift apart unseen. - With `VICTORY_UNIFIED_BACK` the pieces a class keeps for the copy-back are declared the same way, so the two work together. A bit that is set and should not be costs a compare. Nothing clears a bit but the compare that read it. ## Measured `indirect::tests::what_the_compare_by_marks_saves_the_card` (ignored; run by name): the heap of 174 MB declared whole, 2,784 pieces, compared after each of 12 submissions. Best of six, three runs: | | The card's time | |---|---| | Every piece (`CARD_COMPARE_BATCH`) | 2.45 ms | | By marks, none marked, the bitmap in the card's memory (as the layer has it) | 0.16 ms | | By marks, 40 pieces marked, the bitmap in the PC's memory | 1.43 to 1.44 ms | | By marks, none marked, the bitmap in the PC's memory | 1.47 to 1.49 ms | The last two rows are why the bitmap is in the card's memory: every thread reads a dword of it, and over the bus that is most of the pass. ## Tests - `the_compare_by_marks_reads_the_marked_pieces_and_clears_their_bits`, on WARP and on the card: against the batch compare, a marked piece gets the same dword and the same stored hash and its bit is cleared; an unmarked piece gets 0 though its bytes changed and keeps its hash; other copies' bits around this one's stay; a pass that stores hashes reads every piece; a piece marked later is found by its stale hash. It fails when a clear bit is compared all the same, when the base is left out, and when the bit read is not cleared. - `a_views_bits_are_the_pieces_the_compare_cuts`: for 20,000 copies and views, the bit of a view's first byte is the first piece of its range as the compare cuts it, the bit a program computes for its last byte is the last piece, and a copy takes as many bits as it has pieces. - `runs_of_bits_are_apart_and_come_back`: the bits' allocator. - `a_copy_is_left_to_its_marks_only_while_every_writer_marks` (added after the first push; run with the switch and without): through real host lists, what a marking shader, a shader that does not mark and a copy of the layer's own each declare is declared; with the switch a copy in the card's memory has a run of bits and a view's entry is its first byte's piece and offset; the copy is left to its marks only while every writer of the submission marks; a list's reset forgets what it noted. Without the switch no copy has bits and nothing is left to the marks. It fails when a writer that does not mark is not noted, and when every shader is taken to mark. - `cargo test -p victory-gpu --release --lib` with the switch off and with it on: 1,116 pass both ways; the three that fail are `main`'s (`shader_cache`'s key test, `list::thin::tests::bindings_record_no_work`, and the `uav_pool` lifecycle test now and then). Run with #4115 applied and not committed here (the crate's tests do not compile on `main` without it). - Clippy, with and without the diagnostics feature: nothing on a line this adds. ## Limits - No title run. What the marks cost the title's own programs on the card, and how much of what is compared today is written through tables' views, is for a run to say. `LEFT_TO_MARKS` counts the pieces given to the compare by marks. - No test here takes a translated program through the layer from its store to the compare: #3641 shows on a device that a program sets the right bits, this one that the compare reads them, and the arithmetic test that the two mean the same piece. Who is believed to mark is tested through real lists (above); the table's filling at a slot and the binding of the two root views are exercised only by the crate's tests passing with the switch on. - With the switch on, a copy is made when an unordered view's slot is written (its bits are asked for there), not at its first draw. - Only the batched compare knows the marks; with `VICTORY_CARD_BATCH=0` ranges are compared whole. ## 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]>
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]>
Off unless `VICTORY_VIEW_MARKS=1`. With it the layer asks the translator
for write marks (the half before this one), and a declared range every
writer of which marks is compared on the card only where its bit is set.

- `view_marks.rs`: the switch (it is in the shader cache's key), a run of
  bits for each copy in the card's memory (a bit for each 64 KiB piece the
  compare cuts), and the bitmap, in the card's own memory.
- A view's base bit and phase are written beside its stride, into a table
  after the strides and the view addresses in the same buffer; a slot whose
  stride is written has none until a view with bits is made there.
- A draw's stage that has `u<SLOT_VIEW_WRITES>` declares what it writes
  through tables' views as marked; everything else that declares a write
  (the layer's own copies, stores by address, root views) says the copy has
  an unmarked writer in that list, and the submission's compare then takes
  the whole of its ranges, as before.
- `card_compare_marks`: the batch compare with one more constant and the
  bitmap. A piece whose bit is clear is not read (its dword of `differs`
  is 0, its stored hash stays); one whose bit is set is compared as ever
  and its bit cleared.

On an RTX 5080 (`what_the_compare_by_marks_saves_the_card`, ignored): 12
compares of the title's heap of 174 MB, declared whole, take 2.45 ms with
every piece read and 0.16 ms by marks with the bitmap in the card's
memory (1.43 to 1.49 ms with it in the PC's: a dword over the bus for
every thread).

Tests: the compare by marks on WARP and on the card against the batch
compare (it fails when a clear bit is compared, when the base is left out,
and when the bit read is not cleared); a view's bits against the pieces
the compare cuts, for 20,000 copies and views; the runs of bits.

Not run: a title, and no test here takes a translated program through the
layer from its store to the compare. With the switch on a copy is made
when an unordered view's slot is written, not at its first draw.

(The idea and the translator's half from VIctory cd94d353 and
neonbyte1/VIctory; they compare the marked pages on the CPU, under guards
this tree has not. Here the marks feed the compare on the card.)

Co-Authored-By: Claude Fable 5.2 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-30 17:03:34 +00:00
`a_copy_is_left_to_its_marks_only_while_every_writer_marks` takes a copy
in the card's memory through real host lists: what a marking shader, a
shader that does not mark and a copy of the layer's own each declare is
declared; with `VICTORY_VIEW_MARKS=1` the copy has a run of bits and a
view's entry is its first byte's piece and offset, the copy is left to
its marks only while every writer in the submission marks, and a list's
reset forgets what it noted; without the switch no copy has bits and
nothing is left to the marks. Run both ways. With the switch it fails
when a writer that does not mark is not noted, and when every shader is
taken to mark.

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

@⁠paales on GitHub · 2026-11-30 20:52 UTC · original

Written by 🤖:

In-game numbers with VICTORY_VIEW_MARKS=1. PC: RTX 5070 Ti 16 GB, Ryzen 9 5900X, 32 GB, Windows 11. Series X, 1440p, DLSS Performance, frame generation off, 30 fps cap. Each run: a new game (settings save, no story save), one A press, the first cutscene for 60 s from its first frame. On this PC the same build's submitting thread took 24 ms a frame in one run and 35 ms in another half an hour later, so only large differences count.

Base: main 84bd61e2 with #3918, #1727, #3553, #3043, #4207, #4138 and #720. The build with this PR also had #2504 and #4341. One run each, back to back:

base with this PR, VICTORY_VIEW_MARKS=1
the submitting thread per frame 35.4 ms 32.6 ms
copies in the card's memory 7.6 ms 6.0 ms
of it, refreshes 12.9 ms 10.9 ms
seconds with a frame over 40 ms 40 55
median frame 33.4 ms 35.7 ms

Less work on the submitting thread, but more frames over 40 ms: the marks seem to move the time to the card on this setup. The build needed one run first to translate the changed shaders.

**@⁠paales** on GitHub · 2026-11-30 20:52 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4173#issuecomment-7291580726) _Written by 🤖:_ In-game numbers with `VICTORY_VIEW_MARKS=1`. PC: RTX 5070 Ti 16 GB, Ryzen 9 5900X, 32 GB, Windows 11. Series X, 1440p, DLSS Performance, frame generation off, 30 fps cap. Each run: a new game (settings save, no story save), one A press, the first cutscene for 60 s from its first frame. On this PC the same build's submitting thread took 24 ms a frame in one run and 35 ms in another half an hour later, so only large differences count. Base: `main` 84bd61e2 with #3918, #1727, #3553, #3043, #4207, #4138 and #720. The build with this PR also had #2504 and #4341. One run each, back to back: | | base | with this PR, `VICTORY_VIEW_MARKS=1` | | --- | --- | --- | | the submitting thread per frame | 35.4 ms | 32.6 ms | | copies in the card's memory | 7.6 ms | 6.0 ms | | of it, refreshes | 12.9 ms | 10.9 ms | | seconds with a frame over 40 ms | 40 | 55 | | median frame | 33.4 ms | 35.7 ms | Less work on the submitting thread, but more frames over 40 ms: the marks seem to move the time to the card on this setup. The build needed one run first to translate the changed shaders.
github-bot closed this pull request 2026-12-01 18:50:37 +00:00
Author
Owner

@⁠trustno1-coder on GitHub · 2026-12-01 18:46 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:46 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4173#issuecomment-7321511325) 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!4174
No description provided.