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

Open
opened 2026-11-26 13:36:52 +00:00 by github-bot · 2 comments
Owner

@⁠liuycsbxbxn on GitHub · 2026-11-26 13:31 UTC · original

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.

**@⁠liuycsbxbxn** on GitHub · 2026-11-26 13:31 UTC · [original](https://github.com/fxceless/victory-fork/issues/1306) 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. ---
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 13:36:53 +00:00
Author
Owner

@⁠JayFoxRox on GitHub · 2026-11-26 16:42 UTC · original · edited 2026-11-26 16:49 UTC

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 #1305 to handle this (avoiding page exception and page re-locking, which takes 1000x than doing it the proposed way)
**@⁠JayFoxRox** on GitHub · 2026-11-26 16:42 UTC · [original](https://github.com/fxceless/victory-fork/issues/1306#issuecomment-7198002266) · edited 2026-11-26 16:49 UTC 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://git.gtahub.st/github/fxceless--victory-fork/issues/1305 to handle this (avoiding page exception and page re-locking, which takes 1000x than doing it the proposed way)
Author
Owner

@⁠liuycsbxbxn on GitHub · 2026-11-26 17:02 UTC · original

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.

**@⁠liuycsbxbxn** on GitHub · 2026-11-26 17:02 UTC · [original](https://github.com/fxceless/victory-fork/issues/1306#issuecomment-7198419424) 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.
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/fxceless--victory-fork#1306
No description provided.