GPU: page-table writes go back beside those through views in one page #2329

Open
oVolkra wants to merge 1 commit from upstream-pr/2331 into main
oVolkra commented 2026-11-25 10:46:51 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by oVolkra on 2026-11-25T10:46:51Z.


Problem

A small title buffer lies inside a bigger one, and each has its own host copy. Shaders write the small one's copy through a view and the bigger one's through the title memory page table, in the same 64 KiB page. After the submission one of the two writes is lost:

  • Tracked memory: the small copy's write-back marks the page changed in every tracker. copy_back_page, which runs after it, takes that for a title write and keeps title memory: the page-table write is lost. Marked writes (copy_back_marked) and declared ranges (copy_back) both do it.
  • Untracked memory: copy_back_page puts the bigger copy's whole page back over what the small one just wrote.

Change

  • What shaders wrote through the page table is now found before anything goes back (Shadow::page_before, run by a new defer_before). The title-write check is made there, so only title writes trip it. It is made after title memory is read, so a title write during the read is not taken for a shader's.
  • After the other write-backs, copy_back_page puts back only the copy's bytes that differ from that, and takes title memory's other bytes, as the other two write-backs do (the shared loop is now merge).
  • A page the copy holds only in part is no longer reported as taken, as in copy_back_marked.

Withheld lists still put no page-table writes back, and a list named twice in a submission is still processed once.

Cost, per marked page whose copy differs from title memory: up to 64 KiB of title memory kept (pooled) until the write-back, and a second read and compare.

Tests

Three synthetic tests write 1 into the small buffer's copy and 2 through the page table, then submit twice in one submission after the title wrote the page, and check that the title's other bytes stay.

Test Expected main
Unmarked, tracked [1, 2] [1, 0]
Marked, tracked [1, 2] [1, 0]
Unmarked, untracked [1, 2] [0, 2]

A fourth (page_writes_go_back_beside_what_reached_the_page_meanwhile) covers a title write between the two steps, in tracked and untracked memory. The shaders reach the small copy through a root descriptor; its write is declared as a view's (gpu_writes).

On an RTX 3060 (Windows 11):

  • cargo test -p victory-gpu --locked -- --test-threads=1: 145 passed, 2 failed, 2 ignored. The 2 also fail with the fix off and are fixed by #1751 (dynamic_slots_are_held_until_released, lists_share_a_table_and_copies_keep_their_views).
  • Both clippy runs and cargo xtask policy pass.

Not verified

  • Not run with the title, and no frame time measured.
  • No test through an actual descriptor-table view.

Not covered

Pages the title wrote while the submission ran still keep the title's bytes, as before. Nor does it change which pages Map::precise leaves out: that is #1963, which this does not depend on.

#2242 changes copy_back_page too, but not the order this fixes; #1963 touches the same parts of memory.rs. Both conflict with this textually and I can rebase on whichever lands. #1865 and #1869 merge without conflicts (not built together).

AI-assisted (Claude Code).

🤖 Generated with Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:issue:6602713506 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2331). Originally posted by [oVolkra](https://github.com/oVolkra) on 2026-11-25T10:46:51Z. --- ## Problem A small title buffer lies inside a bigger one, and each has its own host copy. Shaders write the small one's copy through a view and the bigger one's through the title memory page table, in the same 64 KiB page. After the submission one of the two writes is lost: - **Tracked memory:** the small copy's write-back marks the page changed in every tracker. `copy_back_page`, which runs after it, takes that for a title write and keeps title memory: the page-table write is lost. Marked writes (`copy_back_marked`) and declared ranges (`copy_back`) both do it. - **Untracked memory:** `copy_back_page` puts the bigger copy's whole page back over what the small one just wrote. ## Change - What shaders wrote through the page table is now found before anything goes back (`Shadow::page_before`, run by a new `defer_before`). The title-write check is made there, so only title writes trip it. It is made after title memory is read, so a title write during the read is not taken for a shader's. - After the other write-backs, `copy_back_page` puts back only the copy's bytes that differ from that, and takes title memory's other bytes, as the other two write-backs do (the shared loop is now `merge`). - A page the copy holds only in part is no longer reported as taken, as in `copy_back_marked`. Withheld lists still put no page-table writes back, and a list named twice in a submission is still processed once. Cost, per marked page whose copy differs from title memory: up to 64 KiB of title memory kept (pooled) until the write-back, and a second read and compare. ## Tests Three synthetic tests write 1 into the small buffer's copy and 2 through the page table, then submit twice in one submission after the title wrote the page, and check that the title's other bytes stay. | Test | Expected | `main` | |---|---|---| | Unmarked, tracked | `[1, 2]` | `[1, 0]` | | Marked, tracked | `[1, 2]` | `[1, 0]` | | Unmarked, untracked | `[1, 2]` | `[0, 2]` | A fourth (`page_writes_go_back_beside_what_reached_the_page_meanwhile`) covers a title write between the two steps, in tracked and untracked memory. The shaders reach the small copy through a root descriptor; its write is declared as a view's (`gpu_writes`). On an RTX 3060 (Windows 11): - `cargo test -p victory-gpu --locked -- --test-threads=1`: 145 passed, 2 failed, 2 ignored. The 2 also fail with the fix off and are fixed by #1751 (`dynamic_slots_are_held_until_released`, `lists_share_a_table_and_copies_keep_their_views`). - Both clippy runs and `cargo xtask policy` pass. ## Not verified - Not run with the title, and no frame time measured. - No test through an actual descriptor-table view. ## Not covered Pages the title wrote while the submission ran still keep the title's bytes, as before. Nor does it change which pages `Map::precise` leaves out: that is #1963, which this does not depend on. #2242 changes `copy_back_page` too, but not the order this fixes; #1963 touches the same parts of `memory.rs`. Both conflict with this textually and I can rebase on whichever lands. #1865 and #1869 merge without conflicts (not built together). AI-assisted (Claude Code). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
catminou4 commented 2026-11-25 11:04:58 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-25T10:54:13Z.

Review: COMMENTED


Page-table writes go back beside those through views, ordered before copy-backs (new before-stage). Static review only: victory-gpu/victory-hle are Windows-only (D3D12/windows-sys); not compiled or tested on this macOS arm64 host. rustc 1.98.1. Ordering fix; correctness depends on Windows execution timing — hardware validation advised.

<!-- greyfinch-sync:Marvisak/VIctory:review:6056245810 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2331#pullrequestreview-6056245810). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-25T10:54:13Z. **Review:** COMMENTED --- Page-table writes go back beside those through views, ordered before copy-backs (new before-stage). Static review only: victory-gpu/victory-hle are Windows-only (D3D12/windows-sys); not compiled or tested on this macOS arm64 host. rustc 1.98.1. Ordering fix; correctness depends on Windows execution timing — hardware validation advised.
DenRakEiw commented 2026-11-25 12:03:19 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by DenRakEiw on 2026-11-25T11:32:12Z.

Review: COMMENTED


Tested against origin/main (940d32f) on Windows 11 + NVIDIA GeForce RTX 5090 and WARP:

  • cargo test -p victory-gpu shadow::: 5/5 passed on RTX 5090 and 5/5 on WARP (including page_writes_go_back_beside_what_reached_the_page_meanwhile).
  • cargo clippy -p victory-gpu --all-targets -- -D warnings: 0 warnings.
  • cargo xtask policy: 183 files ok.
  • Crash in new memory::tests on both RTX 5090 and WARP: Running cargo test -p victory-gpu memory::tests -- --skip lists_share_a_table_and_copies_keep_their_views (excluding the pre-existing NVIDIA #1744 test) passes the 2 existing memory::tests (addresses_find_the_copy_holding_them, a_full_table_names_the_largest_copies) and then aborts the test process with exit code: 0xc0000409, STATUS_STACK_BUFFER_OVERRUN on both RTX 5090 and VICTORY_WARP=1 during the newly added memory::tests.

AI-assisted (Gemini 4 Neon).

<!-- greyfinch-sync:Marvisak/VIctory:review:6056833919 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2331#pullrequestreview-6056833919). Originally posted by [DenRakEiw](https://github.com/DenRakEiw) on 2026-11-25T11:32:12Z. **Review:** COMMENTED --- Tested against `origin/main` (`940d32f`) on Windows 11 + NVIDIA GeForce RTX 5090 and WARP: - `cargo test -p victory-gpu shadow::`: 5/5 passed on RTX 5090 and 5/5 on WARP (including `page_writes_go_back_beside_what_reached_the_page_meanwhile`). - `cargo clippy -p victory-gpu --all-targets -- -D warnings`: 0 warnings. - `cargo xtask policy`: 183 files ok. - **Crash in new `memory::tests` on both RTX 5090 and WARP:** Running `cargo test -p victory-gpu memory::tests -- --skip lists_share_a_table_and_copies_keep_their_views` (excluding the pre-existing NVIDIA `#1744` test) passes the 2 existing `memory::tests` (`addresses_find_the_copy_holding_them`, `a_full_table_names_the_largest_copies`) and then aborts the test process with `exit code: 0xc0000409, STATUS_STACK_BUFFER_OVERRUN` on both RTX 5090 and `VICTORY_WARP=1` during the newly added `memory::tests`. AI-assisted (Gemini 4 Neon).
Marvisak commented 2026-11-25 16:09:34 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T15:23:04Z.


Automated triage for the maintainers.

Verdict: needs work. Thanks for the rebase (eba5a8b, merges cleanly). The split into Shadow::page_before (run from the new HostList::defer_before, before any write-back) and copy_back_page(page, before) (merging only the bytes that differ, after the other write-backs) matches the problem described, and the new tests cover the three orderings.

The point left open at the last triage is still unanswered. Please run the new memory::tests and shadow::tests::page_writes_go_back_beside_what_reached_the_page_meanwhile on WARP, both alone and with the default thread count, and post the result. An earlier report saw them abort with 0xc0000409. The rebase reply covers only the two pre-existing failures. This reworks the order of title-memory write-backs for every submission, so the maintainers need that result before taking it.

CI: check passing.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7166757825 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2331#issuecomment-7166757825). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T15:23:04Z. --- <!-- victory-triage v1 head=eba5a8b449de06e0842fffce3961ce27bc6c05c2 verdict=needs-work at=2026-11-26T03:22:11Z --> Automated triage for the maintainers. **Verdict: needs work.** Thanks for the rebase (`eba5a8b`, merges cleanly). The split into `Shadow::page_before` (run from the new `HostList::defer_before`, before any write-back) and `copy_back_page(page, before)` (merging only the bytes that differ, after the other write-backs) matches the problem described, and the new tests cover the three orderings. The point left open at the last triage is still unanswered. Please run the new `memory::tests` and `shadow::tests::page_writes_go_back_beside_what_reached_the_page_meanwhile` on WARP, both alone and with the default thread count, and post the result. An earlier report saw them abort with `0xc0000409`. The rebase reply covers only the two pre-existing failures. This reworks the order of title-memory write-backs for every submission, so the maintainers need that result before taking it. CI: `check` passing. --- _Generated by [Claude Code](https://claude.ai/code)_
oVolkra commented 2026-11-25 20:06:13 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by oVolkra on 2026-11-25T19:21:56Z.


Rebased onto main (219878a) to resolve the merge conflicts.

The two failing GPU tests (dynamic_slots_are_held_until_released and lists_share_a_table_and_copies_keep_their_views) also fail on main without these changes.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7172193433 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2331#issuecomment-7172193433). Originally posted by [oVolkra](https://github.com/oVolkra) on 2026-11-25T19:21:56Z. --- Rebased onto `main` (219878a) to resolve the merge conflicts. The two failing GPU tests (`dynamic_slots_are_held_until_released` and `lists_share_a_table_and_copies_keep_their_views`) also fail on `main` without these changes.
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/2331:upstream-pr/2331'
git switch 'upstream-pr/2331'

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/2331'
git switch 'upstream-pr/2331'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/2331'
git switch 'upstream-pr/2331'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/2331'
git switch 'main'
git merge --squash 'upstream-pr/2331'
git switch 'main'
git merge --ff-only 'upstream-pr/2331'
git switch 'main'
git merge 'upstream-pr/2331'
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
Marvisak/VIctory!2329
No description provided.