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

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

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by banaanpapa on 2026-11-30T17:02:51Z.


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 #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:5569903289 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4173). Originally posted by [banaanpapa](https://github.com/banaanpapa) on 2026-11-30T17:02:51Z. --- 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 #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)
paales commented 2026-11-30 20:52:02 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by paales on 2026-11-30T20:52:02Z.


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, #4206, #4138 and #720. The build with this PR also had #2504 and #4340. 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.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7291580726 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4173#issuecomment-7291580726). Originally posted by [paales](https://github.com/paales) on 2026-11-30T20:52:02Z. --- _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, #4206, #4138 and #720. The build with this PR also had #2504 and #4340. 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.
trustno1-coder commented 2026-12-01 18:46:16 +00:00 (Migrated from github.com)

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


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:7321511325 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4173#issuecomment-7321511325). Originally posted by [trustno1-coder](https://github.com/trustno1-coder) on 2026-12-01T18:46:16Z. --- 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!4173
No description provided.