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

Open
github-bot wants to merge 1 commit from github-bot/gh-2331 into main AGit
Owner

@⁠oVolkra on GitHub · 2026-11-25 10:46 UTC · original
oVolkra:fix/page-table-writes-beside-views → main · +277 −46 · 3 files · 1 commits · open

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

**@⁠oVolkra** on GitHub · 2026-11-25 10:46 UTC · [original](https://github.com/Marvisak/VIctory/pull/2331) `oVolkra:fix/page-table-writes-beside-views` → `main` · +277 −46 · 3 files · 1 commits · open ## 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)
What shaders wrote through the title memory page table was compared with
title memory after the submission's other write-backs. One of a smaller
buffer's copy in the same page marks the page changed, so the writes were
taken for the title's and lost; in memory that is not tracked the whole page
went back over the smaller buffer's bytes. They are now found before
anything goes back, and go back by their bytes after the rest.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:02:32 +00:00
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 15:23 UTC · original · edited 2026-11-26 03:22 UTC

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

**@⁠Marvisak** on GitHub · 2026-11-25 15:23 UTC · [original](https://github.com/Marvisak/VIctory/pull/2331#issuecomment-7166757825) · edited 2026-11-26 03:22 UTC <!-- 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)_
Author
Owner

@⁠oVolkra on GitHub · 2026-11-25 19:21 UTC · original · edited 2026-11-25 22:49 UTC

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.

**@⁠oVolkra** on GitHub · 2026-11-25 19:21 UTC · [original](https://github.com/Marvisak/VIctory/pull/2331#issuecomment-7172193433) · edited 2026-11-25 22:49 UTC 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 can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/2331/head:github-bot/gh-2331'
git switch 'github-bot/gh-2331'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2331'
git switch 'github-bot/gh-2331'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2331'
git switch 'github-bot/gh-2331'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2331'
git switch 'main'
git merge --squash 'github-bot/gh-2331'
git switch 'main'
git merge --ff-only 'github-bot/gh-2331'
git switch 'main'
git merge 'github-bot/gh-2331'
git push origin 'main'
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/Marvisak--VIctory!2331
No description provided.