perf(agc): cheaper shader-memory captures per draw #1193

Merged
MichonGoddijn231849 merged 4 commits from upstream-pr/1193 into main 2026-10-15 09:34:10 +00:00
MichonGoddijn231849 commented 2026-10-07 17:04:12 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MichonGoddijn231849 on 2026-10-07T17:04:12Z.


What

The per-draw capture of a shader's memory (the SRT walk and the guest pages it reads) cost about 15 µs per draw packet in GTA V Performance mode. It now costs about 6.6 µs.

  • The SRT evaluator memoizes per plan value in a reused, stamped per-thread array, instead of a hash table allocated and grown on every walk (evaluate 5.3 to 3.6 µs per capture).
  • ExtractPlan also stores the plan's values as 32-byte records with argument ids, and the walk evaluates that compact copy. The IR walk spent most of its time in cache misses (3.6 to 2.7 µs). The evaluator is a template over the node view, so both walks share every opcode's semantics, memo, cycle and failure rules. A plan that cannot be expressed compactly keeps the IR walk. APS5_VERIFY_SRT_COMPACT=1 walks both and throws on any difference.
  • ShaderMemory's valid/read/recent marks are arrays of 64-bit words scanned with countr_zero, instead of bitsets tested bit by bit (about 1 µs per draw packet).
  • Captured pages come from a per-thread pool and are found through a short vector with a last-page shortcut. A page that no recorded GPU work writes gets the flush hook a whole-page read would make, then has each 64-byte block copied when a word of it is first read (about 0.3 µs per packet). Pages with pending GPU writes, and unmapped pages, are read as before.
  • APS5_PROFILE_DRAW splits the capture time into SRT evaluation and materialization, and prints the [capture] line once per 10 s instead of every 500 captures (it cost about 2 µs per capture).
  • Lazy pages count as accessible (they were checked whole when made), a read looks up the code and header snapshots only when it can touch them, and the capture counters run only under APS5_PROFILE_DRAW (@Raghav314's review, his commit as co-author; on Hades II, RTX 4090: capture_resources 2.48 -> 2.14 ms per frame).
  • The disk cache stores the plan's denseValueIds and rebuilds the compact plan on load (ResourceMaterializer::CompactPlan); format 31.

Tested

Windows 11 Pro, AMD Ryzen 5 7600, NVIDIA GeForce RTX 5080 (driver 32.0.16.1074), 32 GB, MinGW-w64 GCC 15.2.0.

  • Based on main 872f52320 (2026-10-14) on its own; it no longer depends on #1191.
  • The whole agc_* and shader* suite passes on Windows: 504 tests, 1 skipped (agc_driver_stencil_ref_export). Not run here: the relinker's Python tests (my local Python does not find their helper modules) and guest_gameupdate.
  • Summary lines of main and of this PR (GTA V PPSA04264 Performance mode, the same scene, warm caches, traces attached): to follow in a comment.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Unblocks: none (speed)
  • GPUs tested: NVIDIA GeForce RTX 5080, driver 32.0.16.1074 (595.97), Windows 11 Pro
  • AI-assisted: yes. Written with Claude (Anthropic) under my direction; I reviewed and tested it.

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4775847581 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1193). Originally posted by [MichonGoddijn231849](https://github.com/MichonGoddijn231849) on 2026-10-07T17:04:12Z. --- ### What The per-draw capture of a shader's memory (the SRT walk and the guest pages it reads) cost about 15 µs per draw packet in GTA V Performance mode. It now costs about 6.6 µs. - The SRT evaluator memoizes per plan value in a reused, stamped per-thread array, instead of a hash table allocated and grown on every walk (evaluate 5.3 to 3.6 µs per capture). - `ExtractPlan` also stores the plan's values as 32-byte records with argument ids, and the walk evaluates that compact copy. The IR walk spent most of its time in cache misses (3.6 to 2.7 µs). The evaluator is a template over the node view, so both walks share every opcode's semantics, memo, cycle and failure rules. A plan that cannot be expressed compactly keeps the IR walk. `APS5_VERIFY_SRT_COMPACT=1` walks both and throws on any difference. - `ShaderMemory`'s valid/read/recent marks are arrays of 64-bit words scanned with `countr_zero`, instead of bitsets tested bit by bit (about 1 µs per draw packet). - Captured pages come from a per-thread pool and are found through a short vector with a last-page shortcut. A page that no recorded GPU work writes gets the flush hook a whole-page read would make, then has each 64-byte block copied when a word of it is first read (about 0.3 µs per packet). Pages with pending GPU writes, and unmapped pages, are read as before. - `APS5_PROFILE_DRAW` splits the capture time into SRT evaluation and materialization, and prints the `[capture]` line once per 10 s instead of every 500 captures (it cost about 2 µs per capture). - Lazy pages count as accessible (they were checked whole when made), a read looks up the code and header snapshots only when it can touch them, and the capture counters run only under `APS5_PROFILE_DRAW` (@Raghav314's review, his commit as co-author; on Hades II, RTX 4090: `capture_resources` 2.48 -> 2.14 ms per frame). - The disk cache stores the plan's `denseValueIds` and rebuilds the compact plan on load (`ResourceMaterializer::CompactPlan`); format 31. ### Tested Windows 11 Pro, AMD Ryzen 5 7600, NVIDIA GeForce RTX 5080 (driver 32.0.16.1074), 32 GB, MinGW-w64 GCC 15.2.0. - Based on `main` 872f52320 (2026-10-14) on its own; it no longer depends on #1191. - The whole `agc_*` and `shader*` suite passes on Windows: 504 tests, 1 skipped (`agc_driver_stencil_ref_export`). Not run here: the relinker's Python tests (my local Python does not find their helper modules) and `guest_gameupdate`. - Summary lines of `main` and of this PR (GTA V PPSA04264 Performance mode, the same scene, warm caches, traces attached): to follow in a comment. ### Checklist - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Unblocks: none (speed) - [x] GPUs tested: NVIDIA GeForce RTX 5080, driver 32.0.16.1074 (595.97), Windows 11 Pro - [x] AI-assisted: yes. Written with Claude (Anthropic) under my direction; I reviewed and tested it. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
MichonGoddijn231849 commented 2026-10-09 08:32:55 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MichonGoddijn231849 on 2026-10-09T08:32:55Z.


Parked as a draft: the capture path changed a lot with #639 (captures now run against the prepared invocation), so this needs a rework rather than a rebase. I'll mark it ready again once it is ported.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6077389818 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1193#issuecomment-6077389818). Originally posted by [MichonGoddijn231849](https://github.com/MichonGoddijn231849) on 2026-10-09T08:32:55Z. --- Parked as a draft: the capture path changed a lot with #639 (captures now run against the prepared invocation), so this needs a rework rather than a rebase. I'll mark it ready again once it is ported.
MichonGoddijn231849 commented 2026-10-13 16:25:24 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MichonGoddijn231849 on 2026-10-13T16:25:24Z.


Rebased onto current main (a56c905df) on top of the rebased #1191 (thanks @gjonn: main's null-root and inaccessible-read reporting, signed min/less-than and zero out-of-range constant-buffer reads are now in the templated evaluator), and ready for review. The agc_* suite passes on Windows (483 tests, 1 skipped).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6150171697 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1193#issuecomment-6150171697). Originally posted by [MichonGoddijn231849](https://github.com/MichonGoddijn231849) on 2026-10-13T16:25:24Z. --- Rebased onto current `main` (a56c905df) on top of the rebased #1191 (thanks @gjonn: `main`'s null-root and inaccessible-read reporting, signed min/less-than and zero out-of-range constant-buffer reads are now in the templated evaluator), and ready for review. The `agc_*` suite passes on Windows (483 tests, 1 skipped).
oneandonlydean commented 2026-10-14 00:10:23 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-14T00:10:23Z.


This applies cleanly to main on its own. Could you base it on main instead of #1191, so it can go in first?
It also needs the summary lines of main and of this change from one machine and scene (CONTRIBUTING), and the GPUs tested line, since it changes the SRT evaluator in core/shader/.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6157891149 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1193#issuecomment-6157891149). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-14T00:10:23Z. --- This applies cleanly to main on its own. Could you base it on main instead of #1191, so it can go in first? It also needs the summary lines of main and of this change from one machine and scene (CONTRIBUTING), and the `GPUs tested` line, since it changes the SRT evaluator in `core/shader/`.
Raghav314 commented 2026-10-14 07:37:03 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Raghav314 on 2026-10-14T07:37:03Z.


I ran this on my machine (Linux, CachyOS, GCC, RTX 4090, NVIDIA 615.78.08) as part of a local stack with #494, #1201 and a few other draw PRs on top of main, with Hades II (PPSA36082) standing in the hub. One thing in the lazy pages costs more than it should.

ShaderMemory::page checks the whole page with GuestMemory::Accessible before it marks it lazy. But ShaderMemory::accessible only skips its own GuestMemory::Accessible call when page.valid.All(), and a lazy page has only the 64-byte blocks that were read marked valid. So almost every word read of the SRT walk (the evaluator asks accessible before each raw read) pays a page-state lookup again for a page already known to be readable. The lazy read path itself already relies on that first check when it copies a block straight from guest memory, so treating a lazy page as accessible is consistent with it:

// ShaderMemory::accessible
if (!page.wordwise && !page.lazy && !page.valid.All() && !GuestMemory::Accessible(...)) return false;

Two smaller things on the same path (they are on main too): ++CaptureTotals().reads and ++CaptureTotals().pages are atomic increments on every read and page, but the counts are only printed by the [capture] line under APS5_PROFILE_DRAW; and every read and accessible call does an upper_bound on initial even when the address is nowhere near the registered code and header. Gating the counters on CaptureProfiled() and checking the overall [begin, end) of initial before the lookup removes both.

With the three together, same machine and scene, one run after the other (APS5_PIPELINED_DRAWS=1, no profiling), Shader.DrawStage.capture_resources went from 2.48 to 2.14 ms per frame, the queue worker from 12.26 to 11.48 ms, and frame time p50 from 12.34 to 11.60 ms (1195 to 1277 presents in 15 s). Picture unchanged, agc_* tests pass.

LLM assistance used.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6163353956 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1193#issuecomment-6163353956). Originally posted by [Raghav314](https://github.com/Raghav314) on 2026-10-14T07:37:03Z. --- I ran this on my machine (Linux, CachyOS, GCC, RTX 4090, NVIDIA 615.78.08) as part of a local stack with #494, #1201 and a few other draw PRs on top of `main`, with Hades II (PPSA36082) standing in the hub. One thing in the lazy pages costs more than it should. `ShaderMemory::page` checks the whole page with `GuestMemory::Accessible` before it marks it `lazy`. But `ShaderMemory::accessible` only skips its own `GuestMemory::Accessible` call when `page.valid.All()`, and a lazy page has only the 64-byte blocks that were read marked valid. So almost every word read of the SRT walk (the evaluator asks `accessible` before each raw read) pays a page-state lookup again for a page already known to be readable. The lazy read path itself already relies on that first check when it copies a block straight from guest memory, so treating a lazy page as accessible is consistent with it: ```cpp // ShaderMemory::accessible if (!page.wordwise && !page.lazy && !page.valid.All() && !GuestMemory::Accessible(...)) return false; ``` Two smaller things on the same path (they are on `main` too): `++CaptureTotals().reads` and `++CaptureTotals().pages` are atomic increments on every read and page, but the counts are only printed by the `[capture]` line under `APS5_PROFILE_DRAW`; and every read and `accessible` call does an `upper_bound` on `initial` even when the address is nowhere near the registered code and header. Gating the counters on `CaptureProfiled()` and checking the overall `[begin, end)` of `initial` before the lookup removes both. With the three together, same machine and scene, one run after the other (`APS5_PIPELINED_DRAWS=1`, no profiling), `Shader.DrawStage.capture_resources` went from 2.48 to 2.14 ms per frame, the queue worker from 12.26 to 11.48 ms, and frame time p50 from 12.34 to 11.60 ms (1195 to 1277 presents in 15 s). Picture unchanged, `agc_*` tests pass. LLM assistance used.
MichonGoddijn231849 commented 2026-10-14 08:46:23 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MichonGoddijn231849 on 2026-10-14T08:46:23Z.


Rebased onto main (872f52320) on its own, so it no longer depends on #1191. Two changes on the way:

  • @Raghav314's three points are in as a second commit (co-author): a lazy page counts as accessible, a read looks up the code and header snapshots only when it can touch them, and the capture counters run only under APS5_PROFILE_DRAW.
  • main's plan encoder check caught the plan's new fields: the disk cache now stores denseValueIds and rebuilds the compact plan on load (format 31).

The agc_* and shader* suites pass on Windows (504 tests, RTX 5080), and the GPUs tested line is in the description. The summary lines of main and of this PR from one machine and scene (GTA V Performance mode, warm caches, traces attached) follow in a comment today.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6164501020 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1193#issuecomment-6164501020). Originally posted by [MichonGoddijn231849](https://github.com/MichonGoddijn231849) on 2026-10-14T08:46:23Z. --- Rebased onto `main` (872f52320) on its own, so it no longer depends on #1191. Two changes on the way: - @Raghav314's three points are in as a second commit (co-author): a lazy page counts as accessible, a read looks up the code and header snapshots only when it can touch them, and the capture counters run only under `APS5_PROFILE_DRAW`. - `main`'s plan encoder check caught the plan's new fields: the disk cache now stores `denseValueIds` and rebuilds the compact plan on load (format 31). The `agc_*` and `shader*` suites pass on Windows (504 tests, RTX 5080), and the `GPUs tested` line is in the description. The summary lines of `main` and of this PR from one machine and scene (GTA V Performance mode, warm caches, traces attached) follow in a comment today.
Raghav314 commented 2026-10-14 13:17:17 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Raghav314 on 2026-10-14T13:17:17Z.


Thanks for taking the three read-path points in. One thing for Linux: the rebased head doesn't build there. ShaderDiskCache.cpp checks sizeof(IrResourcePlan) == 584 inside the __linux__ && __x86_64__ && __GLIBCXX__ block, and with the compact plan the struct is 712 bytes with libstdc++ (I checked with a sizeof probe on my machine: Linux, CachyOS, GCC). The encoder already stores denseValueIds and the compact plan is rebuilt on load, so I think only the number needs to change:

static_assert(sizeof(IrResourcePlan) == 712, "IrResourcePlan changed: update EncodePlan and DecodePlan");

With that it builds, and the agc_* suite passes here on main 98541c674 with #1193 merged in (alongside #494, #1201, #1202 and #5687, so not on its own).

LLM assistance used.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6169266767 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1193#issuecomment-6169266767). Originally posted by [Raghav314](https://github.com/Raghav314) on 2026-10-14T13:17:17Z. --- Thanks for taking the three read-path points in. One thing for Linux: the rebased head doesn't build there. `ShaderDiskCache.cpp` checks `sizeof(IrResourcePlan) == 584` inside the `__linux__ && __x86_64__ && __GLIBCXX__` block, and with the compact plan the struct is 712 bytes with libstdc++ (I checked with a `sizeof` probe on my machine: Linux, CachyOS, GCC). The encoder already stores `denseValueIds` and the compact plan is rebuilt on load, so I think only the number needs to change: ```cpp static_assert(sizeof(IrResourcePlan) == 712, "IrResourcePlan changed: update EncodePlan and DecodePlan"); ``` With that it builds, and the `agc_*` suite passes here on `main` 98541c674 with #1193 merged in (alongside #494, #1201, #1202 and #5687, so not on its own). LLM assistance used.
adriadam10 commented 2026-10-15 09:17:59 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-15T09:17:59Z.


Rebased onto current main (0afa6a607e) and force-pushed; the previous head is kept at adriadam10/AnyPS5:backup/MichonGoddijn231849-perf-capture-plan-walk.

  • Conflicts with #5181 resolved: IrValueArena and the compact plan structs live side by side in ResourcePlan.hpp; MayEvaluate is a static member of the templated evaluator; the materializer clones through the arena. Shader cache FormatVersion bumped to 36.
  • sizeof(IrResourcePlan) assert set to 712 (libstdc++, as Raghav measured); fieldCount stays 23, denseValueIds is encoded and CompactPlan runs on decode.
  • ShaderMemory::readWords adapted to main's WordMask (new SetRun instead of a std::bitset shift), and the MayEvaluate test calls the evaluator through Detail::IrNode.

Tested on Linux (RADV 660M, -DANYPS5_ENABLE_SPIRV_TOOLS=ON, APS5_VERIFY_SRT_COMPACT=1): shader/agc/recompiler ctest 588/589; the one failure is agc_driver_tessellation, which segfaults the same way on main on this GPU. Windows build dispatched next. No title runs on this machine, so the before/after summary lines Dean asked for still need someone with a game.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6188725057 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1193#issuecomment-6188725057). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-15T09:17:59Z. --- Rebased onto current main (0afa6a607e) and force-pushed; the previous head is kept at `adriadam10/AnyPS5:backup/MichonGoddijn231849-perf-capture-plan-walk`. - Conflicts with #5181 resolved: `IrValueArena` and the compact plan structs live side by side in `ResourcePlan.hpp`; `MayEvaluate` is a static member of the templated evaluator; the materializer clones through the arena. Shader cache `FormatVersion` bumped to 36. - `sizeof(IrResourcePlan)` assert set to 712 (libstdc++, as Raghav measured); `fieldCount` stays 23, `denseValueIds` is encoded and `CompactPlan` runs on decode. - `ShaderMemory::readWords` adapted to main's `WordMask` (new `SetRun` instead of a `std::bitset` shift), and the `MayEvaluate` test calls the evaluator through `Detail::IrNode`. Tested on Linux (RADV 660M, `-DANYPS5_ENABLE_SPIRV_TOOLS=ON`, `APS5_VERIFY_SRT_COMPACT=1`): shader/agc/recompiler ctest 588/589; the one failure is `agc_driver_tessellation`, which segfaults the same way on main on this GPU. Windows build dispatched next. No title runs on this machine, so the before/after summary lines Dean asked for still need someone with a game.
github-actions[bot] commented 2026-10-15 09:26:20 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-15T09:26:20Z.


Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
#6032 core/shader/recompiler/ShaderDiskCache.hpp L16
#6053 core/shader/recompiler/Optimization/include/Optimization/SrtWalker/SrtEvaluator.hpp L78-80
core/shader/recompiler/Optimization/src/SrtWalker/SrtEvaluator.cpp L277
#6095 core/shader/recompiler/IntermediateRepresentation/include/IntermediateRepresentation/IrMetadata/ResourcePlan.hpp L132
core/shader/recompiler/Optimization/src/SrtWalker/SrtDescriptorEvaluation.cpp L7, L46-48, L203
core/shader/recompiler/ShaderDiskCache.cpp L148
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6188870960 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1193#issuecomment-6188870960). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-15T09:26:20Z. --- <!-- pr-overlap --> Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in **Depends on**. | Pull request | Conflicting files (lines on `main`) | Same exports | Same new files | |---|---|---|---| | #6032 | `core/shader/recompiler/ShaderDiskCache.hpp` [L16](https://github.com/boykopovar/AnyPS5/blob/042eb7c801869fe5a950e252d10c3ffca4b97602/core/shader/recompiler/ShaderDiskCache.hpp#L16) | | | | #6053 | `core/shader/recompiler/Optimization/include/Optimization/SrtWalker/SrtEvaluator.hpp` [L78-80](https://github.com/boykopovar/AnyPS5/blob/042eb7c801869fe5a950e252d10c3ffca4b97602/core/shader/recompiler/Optimization/include/Optimization/SrtWalker/SrtEvaluator.hpp#L78-L80)<br>`core/shader/recompiler/Optimization/src/SrtWalker/SrtEvaluator.cpp` [L277](https://github.com/boykopovar/AnyPS5/blob/042eb7c801869fe5a950e252d10c3ffca4b97602/core/shader/recompiler/Optimization/src/SrtWalker/SrtEvaluator.cpp#L277) | | | | #6095 | `core/shader/recompiler/IntermediateRepresentation/include/IntermediateRepresentation/IrMetadata/ResourcePlan.hpp` [L132](https://github.com/boykopovar/AnyPS5/blob/042eb7c801869fe5a950e252d10c3ffca4b97602/core/shader/recompiler/IntermediateRepresentation/include/IntermediateRepresentation/IrMetadata/ResourcePlan.hpp#L132)<br>`core/shader/recompiler/Optimization/src/SrtWalker/SrtDescriptorEvaluation.cpp` [L7](https://github.com/boykopovar/AnyPS5/blob/042eb7c801869fe5a950e252d10c3ffca4b97602/core/shader/recompiler/Optimization/src/SrtWalker/SrtDescriptorEvaluation.cpp#L7), [L46-48](https://github.com/boykopovar/AnyPS5/blob/042eb7c801869fe5a950e252d10c3ffca4b97602/core/shader/recompiler/Optimization/src/SrtWalker/SrtDescriptorEvaluation.cpp#L46-L48), [L203](https://github.com/boykopovar/AnyPS5/blob/042eb7c801869fe5a950e252d10c3ffca4b97602/core/shader/recompiler/Optimization/src/SrtWalker/SrtDescriptorEvaluation.cpp#L203)<br>`core/shader/recompiler/ShaderDiskCache.cpp` [L148](https://github.com/boykopovar/AnyPS5/blob/042eb7c801869fe5a950e252d10c3ffca4b97602/core/shader/recompiler/ShaderDiskCache.cpp#L148) | | |
EagleBearerYS commented 2026-10-15 09:57:34 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by EagleBearerYS on 2026-10-15T09:57:34Z.


One thing we noticed while porting #1201's version, in case it helps: since this merged, a shader-memory capture page that's marked lazy skips the multisample read guard.

Before (042eb7c801), a page a capture first touched was read whole with GuestMemory::Read (ShaderMemory.cpp L111), which runs the read guard before its flush (GuestMemory.cpp L2004). MultisampleTarget.cpp installs that guard so that a CPU read of a live multisample target throws (L233-L234, L344).

On main now (1db84d5748), the page only gets FlushGpuWrites and is marked lazy (ShaderMemory.cpp L191-L194), and each 64-byte block is later copied from guest memory with std::memcpy (L220-L223). So a capture whose first read lands on a live multisample target's memory now reads the guest bytes without that check.

We haven't seen a title hit it. Running the guard for the page when it's marked lazy would keep the check. Happy to send the small fix with a test if you'd like one.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6189410830 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1193#issuecomment-6189410830). Originally posted by [EagleBearerYS](https://github.com/EagleBearerYS) on 2026-10-15T09:57:34Z. --- One thing we noticed while porting #1201's version, in case it helps: since this merged, a shader-memory capture page that's marked lazy skips the multisample read guard. Before (042eb7c801), a page a capture first touched was read whole with `GuestMemory::Read` ([ShaderMemory.cpp L111](https://github.com/boykopovar/AnyPS5/blob/042eb7c801869fe5a950e252d10c3ffca4b97602/core/libs/prx/libSceAgcDriver/Execution/src/ShaderMemory.cpp#L111)), which runs the read guard before its flush ([GuestMemory.cpp L2004](https://github.com/boykopovar/AnyPS5/blob/1db84d5748573165ccb241618bf5e1ccd91095c4/core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp#L2004)). `MultisampleTarget.cpp` installs that guard so that a CPU read of a live multisample target throws ([L233-L234](https://github.com/boykopovar/AnyPS5/blob/1db84d5748573165ccb241618bf5e1ccd91095c4/core/libs/prx/libSceAgcDriver/Graphics/src/MultisampleTarget.cpp#L233-L234), [L344](https://github.com/boykopovar/AnyPS5/blob/1db84d5748573165ccb241618bf5e1ccd91095c4/core/libs/prx/libSceAgcDriver/Graphics/src/MultisampleTarget.cpp#L344)). On `main` now (1db84d5748), the page only gets `FlushGpuWrites` and is marked lazy ([ShaderMemory.cpp L191-L194](https://github.com/boykopovar/AnyPS5/blob/1db84d5748573165ccb241618bf5e1ccd91095c4/core/libs/prx/libSceAgcDriver/Execution/src/ShaderMemory.cpp#L191-L194)), and each 64-byte block is later copied from guest memory with `std::memcpy` ([L220-L223](https://github.com/boykopovar/AnyPS5/blob/1db84d5748573165ccb241618bf5e1ccd91095c4/core/libs/prx/libSceAgcDriver/Execution/src/ShaderMemory.cpp#L220-L223)). So a capture whose first read lands on a live multisample target's memory now reads the guest bytes without that check. We haven't seen a title hit it. Running the guard for the page when it's marked lazy would keep the check. Happy to send the small fix with a test if you'd like one.
MichonGoddijn231849 commented 2026-10-15 15:19:47 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MichonGoddijn231849 on 2026-10-15T15:19:47Z.


@EagleBearerYS you're right, thanks for catching it. On main the lazy page only gets FlushGpuWrites (ShaderMemory.cpp L191-L194) and its blocks are later copied with memcpy, so the read guard that GuestMemory::Read ran first is skipped for a capture's first touch of a page. Running the guard over the page when it is marked lazy keeps the check at no per-word cost. Yes please, send the fix with the test; I'll review it.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6195605546 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1193#issuecomment-6195605546). Originally posted by [MichonGoddijn231849](https://github.com/MichonGoddijn231849) on 2026-10-15T15:19:47Z. --- @EagleBearerYS you're right, thanks for catching it. On `main` the lazy page only gets `FlushGpuWrites` (ShaderMemory.cpp L191-L194) and its blocks are later copied with `memcpy`, so the read guard that `GuestMemory::Read` ran first is skipped for a capture's first touch of a page. Running the guard over the page when it is marked lazy keeps the check at no per-word cost. Yes please, send the fix with the test; I'll review it.
Sign in to join this conversation.
No reviewers
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!1193
No description provided.