Proposal: copy shader writes back only when the title's CPU touches them (page guards), not after every flight #2583

Open
opened 2026-11-26 05:09:45 +00:00 by github-bot · 2 comments
Owner

@⁠shawshanker18 on GitHub · 2026-11-25 16:13 UTC · original

Idea

Today every flight's shader writes come back to title memory after the flight: the layer snapshots or hashes the ranges, fetches the changed pieces, and merges them. Separately, a submission whose preparation reads title memory that a flight may write waits for that flight to land (a "settle").

Proposal: leave GPU-written ranges on the card and copy them back only when the title's CPU actually touches them:

  1. When a flight declares writes to a range, protect those title pages (PAGE_NOACCESS, the same guard machinery watch.rs already uses for writes).
  2. When the title's CPU reads or writes a protected page, the fault handler fetches just that page from the host copy (waiting only for the flight that wrote it, if it has not landed), merges it, unprotects it, and resumes.
  3. Pages the CPU never touches are never copied back. Culling results, indirect arguments, particle and skinning buffers are written by shaders and read by shaders.
  4. The layer's own CPU reads of such ranges (buffer copies done on the CPU, upload fills) go through the same path, or move to the card, so they stop forcing settles.

Other emulators reach their speed the same way: Yuzu/Ryujinx ("GPU accuracy: normal" skips most readbacks), Xenia (resolve readbacks off by default), Dolphin (skip EFB access from CPU).

Why (measured, fxceless fork 9376fd6, RTX 4050 Laptop, Series X, lit world)

  • Copy-back thread: 300 ms a frame before its fetches got a copy queue, still 60-85 ms after. About 60 MB a frame of GPU writes merged into title memory.
  • Settles: the submitting thread waits 110-135 ms a frame. Each time the trigger was the layer's own CPU read (480-byte constant fills in the 174 MB heap, then a title buffer copy done on the CPU), not the title reading results.
  • With all barriers removed (VICTORY_BARRIER_TEST=both) the frame does not change, and the card sits at about 60% load and 40 W (nvidia-smi). The card is waiting on the layer, not working.

Risks / open questions

  • Fault cost: a page fault per first touch per frame. Fine if the CPU touches few GPU-written pages; measure that first (count first touches of declared ranges per frame).
  • Pages the title writes while a flight's shaders also write them: same race as today, resolved the same way (title bytes merged under writes).
  • Guard interplay with physical-page views (aliases), as in #2414.

No game data in this proposal.

**@⁠shawshanker18** on GitHub · 2026-11-25 16:13 UTC · [original](https://github.com/Marvisak/VIctory/issues/2583) ## Idea Today every flight's shader writes come back to title memory after the flight: the layer snapshots or hashes the ranges, fetches the changed pieces, and merges them. Separately, a submission whose preparation reads title memory that a flight may write waits for that flight to land (a "settle"). Proposal: **leave GPU-written ranges on the card and copy them back only when the title's CPU actually touches them**: 1. When a flight declares writes to a range, protect those title pages (`PAGE_NOACCESS`, the same guard machinery `watch.rs` already uses for writes). 2. When the title's CPU reads or writes a protected page, the fault handler fetches just that page from the host copy (waiting only for the flight that wrote it, if it has not landed), merges it, unprotects it, and resumes. 3. Pages the CPU never touches are never copied back. Culling results, indirect arguments, particle and skinning buffers are written by shaders and read by shaders. 4. The layer's own CPU reads of such ranges (buffer copies done on the CPU, upload fills) go through the same path, or move to the card, so they stop forcing settles. Other emulators reach their speed the same way: Yuzu/Ryujinx ("GPU accuracy: normal" skips most readbacks), Xenia (resolve readbacks off by default), Dolphin (skip EFB access from CPU). ## Why (measured, fxceless fork `9376fd6`, RTX 4050 Laptop, Series X, lit world) - Copy-back thread: 300 ms a frame before its fetches got a copy queue, still 60-85 ms after. About 60 MB a frame of GPU writes merged into title memory. - Settles: the submitting thread waits 110-135 ms a frame. Each time the trigger was the layer's own CPU read (480-byte constant fills in the 174 MB heap, then a title buffer copy done on the CPU), not the title reading results. - With all barriers removed (`VICTORY_BARRIER_TEST=both`) the frame does not change, and the card sits at about 60% load and 40 W (nvidia-smi). The card is waiting on the layer, not working. ## Risks / open questions - Fault cost: a page fault per first touch per frame. Fine if the CPU touches few GPU-written pages; measure that first (count first touches of declared ranges per frame). - Pages the title writes while a flight's shaders also write them: same race as today, resolved the same way (title bytes merged under writes). - Guard interplay with physical-page views (aliases), as in #2414. No game data in this proposal.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:09:45 +00:00
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 18:45 UTC · original

Automated triage for the maintainers.

This is a performance proposal for the GPU layer: copy shader writes back to title memory only when the title's CPU first touches them, using page guards. It fits the project's scope, and it is labelled and kept as a request.

The measurements quoted come from a fork, not from main, so a count of first CPU touches of declared ranges per frame on main would be the useful first data point, as the proposal itself suggests.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 18:45 UTC · [original](https://github.com/Marvisak/VIctory/issues/2583#issuecomment-7171364363) <!-- victory-issue-triage v1 verdict=tracked seen=2026-11-25T16:13:37Z at=2026-11-25T19:05:00Z --> Automated triage for the maintainers. This is a performance proposal for the GPU layer: copy shader writes back to title memory only when the title's CPU first touches them, using page guards. It fits the project's scope, and it is labelled and kept as a request. The measurements quoted come from a fork, not from main, so a count of first CPU touches of declared ranges per frame on main would be the useful first data point, as the proposal itself suggests. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠Fran-co-F on GitHub · 2026-11-26 20:57 UTC · original

Data point for the first-touch count asked for here. This is only a counter: copy-back still runs as on main, then the declared pages are re-armed PAGE_NOACCESS and the first touch is recorded.

Setup: main 63bcca4 plus the diagnostic, Linux, Wine 11.17 (patched wineserver) + vkd3d-proton, RX 9070 XT, 32 GB RAM, Series X profile. One run, one scene: in 3D at about 2 fps, character faces missing (as I have seen on other builds here). 64 KiB pages.

Per frame, across the 16 five-second windows of the run:

  • title code touches 2.5–5.5 % of the declared pages (about 65 of 1,900 in the heavier windows), more writes than reads
  • about a third of those title touches are in neighbouring bytes of the 64 KiB page, outside the declared range
  • the layer's own reads (almost all copy_mapped) touch 30–44 % of the declared pages
  • in one of the later windows, three title sites account for about half of the title touches: +0x35a3d6c (writes), +0x75885 (writes), +0x4e4b680 (reads)

So for the title itself the idea looks promising; the layer's reads are the larger obstacle and would need to move to the card or fetch on demand. This does not measure any speedup, nor fault cost under demand copy-back. The run ended in an abort in dxil-spirv (Invalid type ID in cast<T>), which looks specific to the Linux translation path; I have not checked whether the diagnostic plays a part.

AI-assisted (patch and summary).

**@⁠Fran-co-F** on GitHub · 2026-11-26 20:57 UTC · [original](https://github.com/Marvisak/VIctory/issues/2583#issuecomment-7203242723) Data point for the first-touch count asked for here. This is only a counter: copy-back still runs as on main, then the declared pages are re-armed `PAGE_NOACCESS` and the first touch is recorded. Setup: main `63bcca4` plus the diagnostic, **Linux, Wine 11.17 (patched wineserver) + vkd3d-proton**, RX 9070 XT, 32 GB RAM, Series X profile. One run, one scene: in 3D at about 2 fps, character faces missing (as I have seen on other builds here). 64 KiB pages. Per frame, across the 16 five-second windows of the run: - title code touches **2.5–5.5 %** of the declared pages (about 65 of 1,900 in the heavier windows), more writes than reads - about a third of those title touches are in neighbouring bytes of the 64 KiB page, outside the declared range - the layer's own reads (almost all `copy_mapped`) touch **30–44 %** of the declared pages - in one of the later windows, three title sites account for about half of the title touches: `+0x35a3d6c` (writes), `+0x75885` (writes), `+0x4e4b680` (reads) So for the title itself the idea looks promising; the layer's reads are the larger obstacle and would need to move to the card or fetch on demand. This does not measure any speedup, nor fault cost under demand copy-back. The run ended in an abort in dxil-spirv (`Invalid type ID in cast<T>`), which looks specific to the Linux translation path; I have not checked whether the diagnostic plays a part. AI-assisted (patch and summary).
This discussion has been locked. Commenting is limited to contributors.
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#2583
No description provided.