GPU, shaders: shaders mark the pages they write by address; landings look there only #229

Open
murillojndem wants to merge 2 commits from upstream-pr/229 into main
murillojndem commented 2026-11-29 17:10:37 +00:00 (Migrated from github.com)

Imported from DexNom/VIctory. Originally posted by murillojndem on 2026-11-29T17:10:37Z.


When a shader writes title memory by address and the host cannot bound where (Writes::All in draw.rs), every visible host copy is declared written: snapshotted at submission and compared after it. In a run on an RX 7900 XT with the ray-tracing builder running (one such writer is InitHeaders), the log shows:

  • about 3.9 GB a frame compared in windows outside buffers, with nothing written back;
  • the submitting thread waiting 1.0 to 1.8 s a frame in settles ("a wait for a memory value"). With the relay, a settle waits for the copy-back thread to land everything (relay_wait), and that landing was 1.0 to 2.0 s a frame of compares.

Upstream's 27c3dc9 had shaders mark the 64 KiB pages they write in a bitmap per list, and looked only at those pages after the run. This repository's 570a941 removed that bitmap; the directory design that replaced it declares every copy instead.

Change, in two halves:

  • Translator (emit): with with_write_marks, every raw-address store and atomic (memory_flat) that runs on a page with a copy sets, in a new root UAV u251 (SLOT_MARKS), the bits of the directory pages of its first and last byte. Lanes EXEC leaves out and pages without a copy set none. Without the option a translation is byte for byte as before.
  • Host:
    • The shader cache translates with marks unless VICTORY_WRITE_MARKS=0 (part of the cache key).
    • Each host list has a 256 KiB bitmap in the PC's memory, zeroed when the list is submitted and bound as u251 (HostList::marks). A list that cannot get one binds a sink, and its submission looks through every range whole.
    • When a marking stage's list has its own bitmap, the ranges Writes::All declares are flagged. Pending state and snapshots are as before.
    • When a submission lands, on the waited path, the relay and settles, flagged ranges are looked through only at the pages marked in the bitmaps of every list landing at that time. Ranges declared plainly, by the same or another shader, are looked through whole. Every declared range is released as before, in the same order.
    • VICTORY_MARKS_VERIFY=1 looks through everything as before and counts the pieces that differ in parts no shader marked; there should be none.
    • The frame-rate log gains a line with the bytes left out.

Why it is exact: a marking shader cannot write a byte of a page with a copy without marking that page, since both ends of every store are marked. Atomics mark too, and writes to pages without a copy are dropped by the shader. A range left out is therefore one that no marking shader of those submissions wrote. Other writers' ranges are declared plainly and looked through whole, except where the host guesses that a shader does not write (see Limits).

Relation to #153: same symptom (InitHeaders is one Writes::All writer), different mechanism. Nothing is replayed after the copy-back, and the declarations and the order of the landing are unchanged.

Tests:

  • emit::intersect_tests::warp_write_marks_name_the_pages_raw_stores_and_atomics_write covers:
    • stores in a page;
    • a store that crosses into a page without a copy, whose bit can only come from its last byte;
    • a lane EXEC leaves out;
    • a page without a copy;
    • an atomic.
      It fails under each of four mutants: marking only the first byte, ignoring whether the page has a copy, not marking atomics, and marking outside EXEC. Without the option, the DXIL of stores, an atomic and a load is byte for byte the same as on main.
  • host::relay_tests::declared_ranges_for_marking_shaders_are_looked_through_at_marked_pages writes two pages of a copy and the bitmap with copies on the card, as a shader would. It checks three things, on the waited path and with the relay:
    • the marked page reaches title memory;
    • the unmarked one is not looked for and is counted as left out;
    • a range declared plainly as well is looked through whole.
  • host::marked_compare_tests (cutting ranges to pages, the directory's last page, plain ranges never left out) and host::raw_copy_coverage_tests (a shader that does not mark, after marked declarations of the same copies, still gets a plain declaration).
  • victory-gpu --lib: 224 passed, 0 failed, 4 ignored on WARP, with and without VICTORY_RELAY=1, and on the RX 7900 XT (main: 219, 0, 4). victory-shader --lib on WARP: 235 passed, 5 failed, 4 ignored (main: 234, 5, 4; the same five fail). Clippy with -D warnings, with and without --all-features, and cargo xtask policy pass. The touched files are not rustfmt-formatted on main (victory-gpu has 1,156 rustfmt differences there), so the new code follows the style around it rather than rustfmt.
  • An independent review traced every landing path. It found two cases where bytes could differ, both fixed here with tests: a non-marking shader after a marking one on the same list, and a list that marks into the sink. Its other risks are below.

Limits:

  • The snapshots stay: this saves the compares and the waits on them, not the copy taken at submission (#228 is about its allocations).
  • The frame-time effect in a title is not measured here. VICTORY_WRITE_MARKS=0 against the default gives the A/B; VICTORY_MARKS_VERIFY=1 checks that nothing is left out that a shader wrote.
  • Writes::All used to look through, by chance, writes the host does not declare (the write_skip guesses in draw.rs) when they fell in a declared copy. Those are no longer looked for unless their pages are marked; VICTORY_MARKS_VERIFY=1 counts them.
  • Each marking stage binds one more root UAV (2 DWORDs). A root signature that was already at 64 DWORDs fails to serialize (logged as "root signature: ..."); VICTORY_WRITE_MARKS=0 avoids it.
  • Each executed raw-address store or atomic does two atomic ORs into the bitmap, and each list that marks zeroes 256 KiB of shared memory at every submission.
  • It conflicts with #136 in memory.rs (both change how ready declares), with #149 in shader_cache.rs (both add to the translation's cache key) and with #153 in emit/mod.rs (both add translation options next to the raw-store probe). Of the other open PRs that touch these files, those that do not merge already conflict with main.

Generated with Claude Code

<!-- greyfinch-sync:DexNom/VIctory:issue:5553081701 --> Imported from [DexNom/VIctory](https://github.com/DexNom/VIctory/pull/229). Originally posted by [murillojndem](https://github.com/murillojndem) on 2026-11-29T17:10:37Z. --- When a shader writes title memory by address and the host cannot bound where (`Writes::All` in `draw.rs`), every visible host copy is declared written: snapshotted at submission and compared after it. In a run on an RX 7900 XT with the ray-tracing builder running (one such writer is InitHeaders), the log shows: - about 3.9 GB a frame compared in windows outside buffers, with nothing written back; - the submitting thread waiting 1.0 to 1.8 s a frame in settles ("a wait for a memory value"). With the relay, a settle waits for the copy-back thread to land everything (`relay_wait`), and that landing was 1.0 to 2.0 s a frame of compares. Upstream's 27c3dc9 had shaders mark the 64 KiB pages they write in a bitmap per list, and looked only at those pages after the run. This repository's 570a941 removed that bitmap; the directory design that replaced it declares every copy instead. Change, in two halves: - Translator (`emit`): with `with_write_marks`, every raw-address store and atomic (`memory_flat`) that runs on a page with a copy sets, in a new root UAV `u251` (`SLOT_MARKS`), the bits of the directory pages of its first and last byte. Lanes EXEC leaves out and pages without a copy set none. Without the option a translation is byte for byte as before. - Host: - The shader cache translates with marks unless `VICTORY_WRITE_MARKS=0` (part of the cache key). - Each host list has a 256 KiB bitmap in the PC's memory, zeroed when the list is submitted and bound as `u251` (`HostList::marks`). A list that cannot get one binds a sink, and its submission looks through every range whole. - When a marking stage's list has its own bitmap, the ranges `Writes::All` declares are flagged. Pending state and snapshots are as before. - When a submission lands, on the waited path, the relay and settles, flagged ranges are looked through only at the pages marked in the bitmaps of every list landing at that time. Ranges declared plainly, by the same or another shader, are looked through whole. Every declared range is released as before, in the same order. - `VICTORY_MARKS_VERIFY=1` looks through everything as before and counts the pieces that differ in parts no shader marked; there should be none. - The frame-rate log gains a line with the bytes left out. Why it is exact: a marking shader cannot write a byte of a page with a copy without marking that page, since both ends of every store are marked. Atomics mark too, and writes to pages without a copy are dropped by the shader. A range left out is therefore one that no marking shader of those submissions wrote. Other writers' ranges are declared plainly and looked through whole, except where the host guesses that a shader does not write (see Limits). Relation to #153: same symptom (InitHeaders is one `Writes::All` writer), different mechanism. Nothing is replayed after the copy-back, and the declarations and the order of the landing are unchanged. Tests: - `emit::intersect_tests::warp_write_marks_name_the_pages_raw_stores_and_atomics_write` covers: - stores in a page; - a store that crosses into a page without a copy, whose bit can only come from its last byte; - a lane EXEC leaves out; - a page without a copy; - an atomic. It fails under each of four mutants: marking only the first byte, ignoring whether the page has a copy, not marking atomics, and marking outside EXEC. Without the option, the DXIL of stores, an atomic and a load is byte for byte the same as on main. - `host::relay_tests::declared_ranges_for_marking_shaders_are_looked_through_at_marked_pages` writes two pages of a copy and the bitmap with copies on the card, as a shader would. It checks three things, on the waited path and with the relay: - the marked page reaches title memory; - the unmarked one is not looked for and is counted as left out; - a range declared plainly as well is looked through whole. - `host::marked_compare_tests` (cutting ranges to pages, the directory's last page, plain ranges never left out) and `host::raw_copy_coverage_tests` (a shader that does not mark, after marked declarations of the same copies, still gets a plain declaration). - `victory-gpu --lib`: 224 passed, 0 failed, 4 ignored on WARP, with and without `VICTORY_RELAY=1`, and on the RX 7900 XT (main: 219, 0, 4). `victory-shader --lib` on WARP: 235 passed, 5 failed, 4 ignored (main: 234, 5, 4; the same five fail). Clippy with `-D warnings`, with and without `--all-features`, and `cargo xtask policy` pass. The touched files are not rustfmt-formatted on main (victory-gpu has 1,156 rustfmt differences there), so the new code follows the style around it rather than rustfmt. - An independent review traced every landing path. It found two cases where bytes could differ, both fixed here with tests: a non-marking shader after a marking one on the same list, and a list that marks into the sink. Its other risks are below. Limits: - The snapshots stay: this saves the compares and the waits on them, not the copy taken at submission (#228 is about its allocations). - The frame-time effect in a title is not measured here. `VICTORY_WRITE_MARKS=0` against the default gives the A/B; `VICTORY_MARKS_VERIFY=1` checks that nothing is left out that a shader wrote. - `Writes::All` used to look through, by chance, writes the host does not declare (the `write_skip` guesses in `draw.rs`) when they fell in a declared copy. Those are no longer looked for unless their pages are marked; `VICTORY_MARKS_VERIFY=1` counts them. - Each marking stage binds one more root UAV (2 DWORDs). A root signature that was already at 64 DWORDs fails to serialize (logged as "root signature: ..."); `VICTORY_WRITE_MARKS=0` avoids it. - Each executed raw-address store or atomic does two atomic ORs into the bitmap, and each list that marks zeroes 256 KiB of shared memory at every submission. - It conflicts with #136 in `memory.rs` (both change how `ready` declares), with #149 in `shader_cache.rs` (both add to the translation's cache key) and with #153 in `emit/mod.rs` (both add translation options next to the raw-store probe). Of the other open PRs that touch these files, those that do not merge already conflict with main. Generated with [Claude Code](https://claude.com/claude-code)
murillojndem commented 2026-11-30 22:10:37 +00:00 (Migrated from github.com)

Imported from DexNom/VIctory. Originally posted by murillojndem on 2026-11-30T22:10:37Z.


Pushed 65cb797d. VICTORY_MARKS_VERIFY=1 now says how much it checked.

Before, the verify branch of marked_compare added nothing to the counters the frame-rate line prints, and that line was printed only when a count was not zero. A run whose check found no difference therefore printed nothing, which cannot be told from a run where no submission had a range for marking shaders. A run of this branch on an RX 7900 XT with the switch on had exactly that.

With the switch on, the frame-rate line now gives, for the frames since the last line and zeros included, the submissions checked, the MB of unmarked declared ranges looked through, and the pieces that differed there. These are counts, not per-frame rates (one piece a second would read 0.0 a frame). They are exact with VICTORY_RELAY=0; with the relay, a flight still in the air can add or hide a piece, which the line and the doc of marks_verify now state.

The test turns the check on for its own landing through a thread key that exists only in tests, and asserts the whole look-through and the three counts. With the new counters taken out it fails at "the checked submission is counted"; with the key ignored it fails at "checked, the page nothing marked is looked through too". It now also fails, instead of returning, when no D3D12 device opens.

Checks:

  • victory-gpu library tests on the RX 7900 XT: 224 passed, 0 failed, 4 ignored. This was the tree before the last review fixes, which changed only the log line's format, a doc comment and an expect message; no test reads those.
  • The same tests for the pushed tree, on WARP with --features diagnostics: 244 passed, 0 failed, 4 ignored.
  • cargo clippy -p victory-gpu --all-targets --locked -- -D warnings, with and without --all-features: clean.
<!-- greyfinch-sync:DexNom/VIctory:comment:7293468089 --> Imported from [DexNom/VIctory](https://github.com/DexNom/VIctory/pull/229#issuecomment-7293468089). Originally posted by [murillojndem](https://github.com/murillojndem) on 2026-11-30T22:10:37Z. --- Pushed 65cb797d. `VICTORY_MARKS_VERIFY=1` now says how much it checked. Before, the verify branch of `marked_compare` added nothing to the counters the frame-rate line prints, and that line was printed only when a count was not zero. A run whose check found no difference therefore printed nothing, which cannot be told from a run where no submission had a range for marking shaders. A run of this branch on an RX 7900 XT with the switch on had exactly that. With the switch on, the frame-rate line now gives, for the frames since the last line and zeros included, the submissions checked, the MB of unmarked declared ranges looked through, and the pieces that differed there. These are counts, not per-frame rates (one piece a second would read 0.0 a frame). They are exact with `VICTORY_RELAY=0`; with the relay, a flight still in the air can add or hide a piece, which the line and the doc of `marks_verify` now state. The test turns the check on for its own landing through a thread key that exists only in tests, and asserts the whole look-through and the three counts. With the new counters taken out it fails at "the checked submission is counted"; with the key ignored it fails at "checked, the page nothing marked is looked through too". It now also fails, instead of returning, when no D3D12 device opens. Checks: - `victory-gpu` library tests on the RX 7900 XT: 224 passed, 0 failed, 4 ignored. This was the tree before the last review fixes, which changed only the log line's format, a doc comment and an `expect` message; no test reads those. - The same tests for the pushed tree, on WARP with `--features diagnostics`: 244 passed, 0 failed, 4 ignored. - `cargo clippy -p victory-gpu --all-targets --locked -- -D warnings`, with and without `--all-features`: clean.
murillojndem commented 2026-11-30 22:50:34 +00:00 (Migrated from github.com)

Imported from DexNom/VIctory. Originally posted by murillojndem on 2026-11-30T22:50:34Z.


The pushed tree (65cb797d) on the RX 7900 XT as well: victory-gpu library tests 224 passed, 0 failed, 4 ignored.

<!-- greyfinch-sync:DexNom/VIctory:comment:7294373698 --> Imported from [DexNom/VIctory](https://github.com/DexNom/VIctory/pull/229#issuecomment-7294373698). Originally posted by [murillojndem](https://github.com/murillojndem) on 2026-11-30T22:50:34Z. --- The pushed tree (65cb797d) on the RX 7900 XT as well: `victory-gpu` library tests 224 passed, 0 failed, 4 ignored.
murillojndem commented 2026-11-30 23:10:10 +00:00 (Migrated from github.com)

Imported from DexNom/VIctory. Originally posted by murillojndem on 2026-11-30T23:10:10Z.


A coverage check of this change in a game run on an RX 7900 XT: a diagnostics build of main 4ad86927 with this branch and #228 merged, ray tracing on, VICTORY_MARKS_VERIFY=1 and VICTORY_RELAY=0 (so the counts are exact).

Over about 5.5 minutes of play from the start of the story, 96 submissions were checked. 342,566 MB of declared ranges in pages no shader marked were looked through whole, 1,380 to 4,512 MB per submission. 0 pieces differed there, and the "pages they did not mark" warning never appeared. In that stretch, every write the check could see landed in a marked page.

That is one stretch of one title, not every scene, and the run was not a frame-rate measurement (verification on and the relay off make frames slower by design).

<!-- greyfinch-sync:DexNom/VIctory:comment:7294793815 --> Imported from [DexNom/VIctory](https://github.com/DexNom/VIctory/pull/229#issuecomment-7294793815). Originally posted by [murillojndem](https://github.com/murillojndem) on 2026-11-30T23:10:10Z. --- A coverage check of this change in a game run on an RX 7900 XT: a diagnostics build of main 4ad86927 with this branch and #228 merged, ray tracing on, `VICTORY_MARKS_VERIFY=1` and `VICTORY_RELAY=0` (so the counts are exact). Over about 5.5 minutes of play from the start of the story, 96 submissions were checked. 342,566 MB of declared ranges in pages no shader marked were looked through whole, 1,380 to 4,512 MB per submission. 0 pieces differed there, and the "pages they did not mark" warning never appeared. In that stretch, every write the check could see landed in a marked page. That is one stretch of one title, not every scene, and the run was not a frame-rate measurement (verification on and the relay off make frames slower by design).
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/229:upstream-pr/229'
git switch 'upstream-pr/229'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/229'
git switch 'upstream-pr/229'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/229'
git switch 'upstream-pr/229'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/229'
git switch 'main'
git merge --squash 'upstream-pr/229'
git switch 'main'
git merge --ff-only 'upstream-pr/229'
git switch 'main'
git merge 'upstream-pr/229'
git push origin 'main'
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
DexNom/VIctory!229
No description provided.