Windows: whole-surface compares of imported render targets dominate GTA V's draw path (measurement) #4432

Closed
opened 2026-10-12 10:59:27 +00:00 by tibzejoker · 2 comments
tibzejoker commented 2026-10-12 10:59:27 +00:00 (Migrated from github.com)
Contributor

Imported from boykopovar/AnyPS5. Originally posted by tibzejoker on 2026-10-12T10:59:27Z.


docs/dev/TechnicalDebt.md says that on Windows, host-pointer imports of the guest mapping are compared instead of write-watched, and that "measuring the comparison cost" is not done yet. Here is a measurement from one title, where this cost is most of the frame.

Setup. GTA V (PPSA04264), Windows 11, RTX 4090 (NVIDIA), WinLibs GCC 15.2.0, Release, write watch on. Tree: main 325e0a8bd plus the PRs the title needs to reach Story, plus #2802. The scene is the first minutes of the Story prologue.

Where the time goes. I added local timers inside StorageTexture::Refresh (summed over all threads, per 10 s):

  • The draws bind resident render targets (3840x2160 and 1920x1080). Their memory is imported, so GuestMemory::ChangedBlocks reports it untracked and Refresh ends in compareUntracked over the whole surface.
  • Without #2802: 11k to 15k refreshes, 8.3 to 8.6 s of whole-surface compare, 0.2 to 0.6 FPS.
  • With #2802: 26k to 36k refreshes, about 7 s of compare, 1.1 to 1.35 FPS. The compare is still the largest cost by far.

Why the memo still misses with #2802. Out of 420k compareUntracked calls:

Outcome Calls
memo hit 365k (87%)
miss because CollectEpoch changed 40k
miss because ForgetSerial changed 4.1k
miss because NewestStamp changed 0.8k
no memo entry yet 5.6k
not memoizable (memoize false or epoch 0) 8.3k

So almost every remaining compare is the one that guards against a CPU store into unwatched memory at a new ordering point. Splitting the compare into 64 KiB units would not change that, because at a new epoch every unit is a candidate. In this scene the compared surfaces were found unchanged about 98% of the time.

I don't have a proposal for how to keep these imports watched on Windows; the TechnicalDebt entry explains why the driver can dirty imported pages after the import window. I'm posting this so the cost is on record for whoever picks it up. Happy to run a branch on this title and report numbers.

AI-assisted (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5812569526 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/4432). Originally posted by [tibzejoker](https://github.com/tibzejoker) on 2026-10-12T10:59:27Z. --- `docs/dev/TechnicalDebt.md` says that on Windows, host-pointer imports of the guest mapping are compared instead of write-watched, and that "measuring the comparison cost" is not done yet. Here is a measurement from one title, where this cost is most of the frame. **Setup.** GTA V (PPSA04264), Windows 11, RTX 4090 (NVIDIA), WinLibs GCC 15.2.0, Release, write watch on. Tree: main 325e0a8bd plus the PRs the title needs to reach Story, plus #2802. The scene is the first minutes of the Story prologue. **Where the time goes.** I added local timers inside `StorageTexture::Refresh` (summed over all threads, per 10 s): - The draws bind resident render targets (3840x2160 and 1920x1080). Their memory is imported, so `GuestMemory::ChangedBlocks` reports it untracked and `Refresh` ends in `compareUntracked` over the whole surface. - Without #2802: 11k to 15k refreshes, 8.3 to 8.6 s of whole-surface compare, 0.2 to 0.6 FPS. - With #2802: 26k to 36k refreshes, about 7 s of compare, 1.1 to 1.35 FPS. The compare is still the largest cost by far. **Why the memo still misses with #2802.** Out of 420k `compareUntracked` calls: | Outcome | Calls | |---|---| | memo hit | 365k (87%) | | miss because `CollectEpoch` changed | 40k | | miss because `ForgetSerial` changed | 4.1k | | miss because `NewestStamp` changed | 0.8k | | no memo entry yet | 5.6k | | not memoizable (`memoize` false or epoch 0) | 8.3k | So almost every remaining compare is the one that guards against a CPU store into unwatched memory at a new ordering point. Splitting the compare into 64 KiB units would not change that, because at a new epoch every unit is a candidate. In this scene the compared surfaces were found unchanged about 98% of the time. I don't have a proposal for how to keep these imports watched on Windows; the TechnicalDebt entry explains why the driver can dirty imported pages after the import window. I'm posting this so the cost is on record for whoever picks it up. Happy to run a branch on this title and report numbers. AI-assisted (Claude Code).
tibzejoker commented 2026-10-13 21:25:36 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by tibzejoker on 2026-10-13T21:25:36Z.


Update: #4878 (nikowolf123) addresses this. On GTA V's Story prologue, the whole-surface compares go from 7 s to about 4 s per 10 s, and the frame rate from 0.60 to 1.09 FPS. Numbers are in https://github.com/boykopovar/AnyPS5/pull/4878#issuecomment-6153620579. I will close this issue once #4878 is merged.

AI-assisted (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6155531760 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/4432#issuecomment-6155531760). Originally posted by [tibzejoker](https://github.com/tibzejoker) on 2026-10-13T21:25:36Z. --- Update: #4878 (nikowolf123) addresses this. On GTA V's Story prologue, the whole-surface compares go from 7 s to about 4 s per 10 s, and the frame rate from 0.60 to 1.09 FPS. Numbers are in https://github.com/boykopovar/AnyPS5/pull/4878#issuecomment-6153620579. I will close this issue once #4878 is merged. AI-assisted (Claude Code).
tibzejoker commented 2026-10-14 06:30:21 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by tibzejoker on 2026-10-14T06:30:21Z.


Closing: #4878 is merged. On GTA V's Story prologue, the frame time went from 1372 to 856 ms (p50) on the same tree (traces in https://github.com/boykopovar/AnyPS5/pull/4878#issuecomment-6158242409). The whole-surface compare is still the largest single cost; a follow-up would get its own issue.

AI-assisted (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6162378055 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/4432#issuecomment-6162378055). Originally posted by [tibzejoker](https://github.com/tibzejoker) on 2026-10-14T06:30:21Z. --- Closing: #4878 is merged. On GTA V's Story prologue, the frame time went from 1372 to 856 ms (p50) on the same tree (traces in https://github.com/boykopovar/AnyPS5/pull/4878#issuecomment-6158242409). The whole-surface compare is still the largest single cost; a follow-up would get its own issue. AI-assisted (Claude Code).
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
boykopovar/AnyPS5#4432
No description provided.