Skip to content

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

Open
oVolkra wants to merge 1 commit into
Marvisak:mainfrom
oVolkra:fix/page-table-writes-beside-views
Open

oVolkra wants to merge 1 commit into
Marvisak:mainfrom
oVolkra:fix/page-table-writes-beside-views

Conversation

@oVolkra

@oVolkra oVolkra commented Nov 25, 2026

Copy link
Copy Markdown

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 GPU: capped view heaps keep the full dynamic range (NVIDIA) #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

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 <noreply@anthropic.com>

@catminou4 catminou4 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 DenRakEiw left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants