GPU → CPU: let the GPU mark the pages that need a read-back #1303

Open
opened 2026-11-26 13:31:58 +00:00 by liuycsbxbxn · 2 comments
liuycsbxbxn commented 2026-11-26 13:31:58 +00:00 (Migrated from github.com)
Contributor

Imported from fxceless/victory-fork. Originally posted by liuycsbxbxn on 2026-11-26T13:31:58Z.


Split out of #1273.

Suggested labels: performance / gpu
Verification cost: [GPU] [TITLE]

What the meta-issue asks

GPU -> CPU pages on change (GPU marks page dirty) … Why not track these writes in the shader as they happen? … Could the GPU simply set a flag that a specific page needs to be guarded so the CPU only tries to readback when the page has changed (instead of being downloaded directly)?

Current shape

  • PR #1014 (card compare / dirty pages) is the clever version of this already in flight.
  • #1238 tracks the CPU side of the same cost.

Acceptance

  1. Name the shaders that write into these pages (the meta-issue asks exactly this) and where their writes are detected today.
  2. A switch (VICTORY_*) that reads back only flagged pages, off by default.
  3. Numbers on one scene: bytes downloaded per frame before/after, and frame time unchanged or better.

<!-- greyfinch-sync:fxceless/victory-fork:issue:6627753128 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/issues/1306). Originally posted by [liuycsbxbxn](https://github.com/liuycsbxbxn) on 2026-11-26T13:31:58Z. --- Split out of #1273. **Suggested labels:** performance / gpu **Verification cost:** `[GPU]` `[TITLE]` ### What the meta-issue asks > GPU -> CPU pages on change (GPU marks page dirty) … Why not track these writes in the shader as they happen? … Could the GPU simply set a flag that a specific page needs to be guarded so the CPU only tries to readback when the page has changed (instead of being downloaded directly)? ### Current shape - PR #1014 (card compare / dirty pages) is the clever version of this already in flight. - #1238 tracks the CPU side of the same cost. ### Acceptance 1. Name the shaders that write into these pages (the meta-issue asks exactly this) and where their writes are detected today. 2. A switch (`VICTORY_*`) that reads back only flagged pages, off by default. 3. Numbers on one scene: bytes downloaded per frame before/after, and frame time unchanged or better. ---
JayFoxRox commented 2026-11-26 16:42:54 +00:00 (Migrated from github.com)
Author
Contributor

Imported from fxceless/victory-fork. Originally posted by JayFoxRox on 2026-11-26T16:42:54Z.


Some information was lost in transition from #1273.

Currently, my understanding is that the GPU hasher communicates which pages changed, and then changed pages get downloaded to the CPU / system-RAM again (periodically?). Even if there is already on-demand page fetching (by using guard-pages) the following should still be a performance improvement.

When the CPU reads from (the guard page system-RAM copy of) a GPU resource, currently a guard page exception occurs which eventually triggers a redownload of the GPU side memory to the CPU. However, page-exceptions are slow and the current approach requires unlocking and relocking pages.

The proposals are

  1. Only download the GPU resource if the CPU actually attempts to read from the read-only copy resource
  2. Avoid the guard page exception after the first encounter of game-code which accesses it (by identifying and patching the game-code on the fly). The idea is to use https://github.com/fxceless/victory-fork/issues/1305 to handle this (avoiding page exception and page re-locking, which takes 1000x than doing it the proposed way)
<!-- greyfinch-sync:fxceless/victory-fork:comment:7198002266 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/issues/1306#issuecomment-7198002266). Originally posted by [JayFoxRox](https://github.com/JayFoxRox) on 2026-11-26T16:42:54Z. --- Some information was lost in transition from #1273. Currently, my understanding is that the GPU hasher communicates which pages changed, and then changed pages get downloaded to the CPU / system-RAM again (periodically?). Even if there is already on-demand page fetching (by using guard-pages) the following should still be a performance improvement. When the CPU reads from (the guard page system-RAM copy of) a GPU resource, currently a guard page exception occurs which eventually triggers a redownload of the GPU side memory to the CPU. However, page-exceptions are slow and the current approach requires unlocking and relocking pages. The proposals are 1. Only download the GPU resource if the CPU actually attempts to read from the read-only copy resource 2. Avoid the guard page exception after the first encounter of game-code which accesses it (by identifying and patching the game-code on the fly). The idea is to use https://github.com/fxceless/victory-fork/issues/1305 to handle this (avoiding page exception and page re-locking, which takes 1000x than doing it the proposed way)
liuycsbxbxn commented 2026-11-26 17:02:46 +00:00 (Migrated from github.com)
Author
Contributor

Imported from fxceless/victory-fork. Originally posted by liuycsbxbxn on 2026-11-26T17:02:46Z.


Fair point — the split dropped the rationale. Restoring it so this stands on its own:

today the GPU hasher reports which pages changed, and the changed ranges are copied back to system RAM on a schedule, whether or not the CPU ever touches them. On-demand fetch already exists via guard pages, so this is an optimisation on top of that, not a replacement — and it is still worth doing, because when the CPU does read, avoiding the fault + re-lock path is where the win is.

Agreed that #1305 is the prerequisite: without the trampoline, any on-demand path still pays the exception and the re-lock cost you cite. So the order I would propose is #1305 first, then this as a switch that gates the download on an actual CPU read. #1307 is the mirror case, on the write side.

<!-- greyfinch-sync:fxceless/victory-fork:comment:7198419424 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/issues/1306#issuecomment-7198419424). Originally posted by [liuycsbxbxn](https://github.com/liuycsbxbxn) on 2026-11-26T17:02:46Z. --- Fair point — the split dropped the rationale. Restoring it so this stands on its own: today the GPU hasher reports which pages changed, and the changed ranges are copied back to system RAM on a schedule, whether or not the CPU ever touches them. On-demand fetch already exists via guard pages, so this is an optimisation on top of that, not a replacement — and it is still worth doing, because when the CPU *does* read, avoiding the fault + re-lock path is where the win is. Agreed that #1305 is the prerequisite: without the trampoline, any on-demand path still pays the exception and the re-lock cost you cite. So the order I would propose is #1305 first, then this as a switch that gates the download on an actual CPU read. #1307 is the mirror case, on the write side.
Sign in to join this conversation.
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
fxceless/victory-fork#1303
No description provided.