perf(shader): reuse the evaluator's requirement list across values #11719

Merged
milescoviello merged 1 commit from upstream-pr/11719 into main 2026-10-28 16:35:38 +00:00
milescoviello commented 2026-10-27 05:28:30 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-27T05:28:30Z.


What

BasicEvaluator::MayEvaluate (SrtEvaluator.cpp) builds a new std::vector of required arguments for every value it visits, and visits each expanded value twice: once to push the arguments, once to check them. In a DWARF profile of Crimson Desert's shader preparation, MayEvaluate and everything below it is 7.9 % of samples, and about half of that is malloc/free. This change keeps one requirement list per MayEvaluate call and refills it for each value instead of returning a new vector, so the list's storage is allocated once per call.

How

The requirements lambda now clears and fills a required vector declared before the work loop, and returns nothing. Its two uses read that vector right after calling it. The nested MayEvaluate for ReadFirstLane has its own list, so no list is shared across calls. The evaluation order and results are unchanged.

Changed: core/shader/recompiler/Optimization/src/SrtWalker/SrtEvaluator.cpp.

Tested

All on Linux, i7-13700K, GCC 15.2, Release with SPIR-V Tools off, main d093ea9ced and this commit.

  • Equivalence: agc_shader_replay --spv over 152 Crimson Desert (PPSA25286) registration requests and MXGP 26's (PPSA30839) 305 dumped requests gives byte-identical SPIR-V for all 65 and 302 outputs.
  • CPU time: agc_shader_replay --prepare over the 152 Crimson Desert requests, perf stat -e task-clock, 8 rounds with main and this change interleaved, ANYPS5_NO_SHADER_CACHE=1. main took 15.59 s on average (SD 0.12) and this change 15.34 s (SD 0.12), 1.6 % less, lower in all 8 rounds.
  • Tests: the 16 AGC driver tests for resource tables, user data and descriptors (agc_driver_compute_table_calls, compute_fs_table_calls, compute_user_data_calls(_registered), image_table*, buffer_descriptor_runtime, descriptor_web_faults, fragment_user_data_tail, draw_shader_failure_materialization*) pass 3 of 3 on an RTX 4070 Ti (NVIDIA 615.71.09).
  • Windows 11 VM (GT 1030 with NVIDIA R580, WinLibs GCC 15.2, Release): the same 16 tests pass 3 of 3 at this head (bf97894bc8) and on its base main d093ea9ced.

#11506 (hugodearaujo) cuts how often MayDecide is called, by deciding each branch condition once per plan. This PR makes each call cheaper, so the two add up. The two PRs don't touch the same lines.

Title captures: Super Meat Boy 3D, main 9af563f33d + #11580 (608dd76843) against the same + this PR (99e0ed0b22), 3 interleaved rounds, recompiler cache off. Shader.PrepareArtifact worker time is 12,443 ms → 12,250 ms (-1.6 %, lower in 2 of 3 rounds; within the run-to-run spread, and the title thread is +1.5 %) (table and traces). Round 2's summary lines:

{"commit":"608dd7684303","dirty":false,"env":{"APS5_PAD_INPUT_FILE":"<path>","APS5_TRACE_SECONDS":"0:60"},"gpu":"NVIDIA GeForce RTX 4070 Ti","driver":"NVIDIA 615.71.09","os":"Linux 7.0.0-38-generic","cpu":"13th Gen Intel(R) Core(TM) i7-13700K","cpu_threads":24,"memory_mib":30993,"title_id":"PPSA31162","title":"Super Meat Boy 3D","content_version":"02.000.001","resolution":"3840x2160","window":{"spec":"seconds 0:60","first_present":0,"ms":60103.630},"presents":412,"frame_ms":{"p50":127.311,"p90":141.599,"p99":1449.702,"max":4081.458},"gpu_busy_ms_per_present":88.914,"worker_busy_pct":{"queue worker 0x0":85.830,"queue worker 0x20":83.892},"top_phases_ms_per_frame":{"Driver.Packet":247.479,"Driver.Packet.memory_wait":122.137,"Driver.Packet.dispatch":58.758,"Driver.Dispatch":58.625,"Shader.PrepareArtifact":44.971,"Driver.Packet.pipeline_drain":40.257,"Recorder.Sync":39.859,"GpuMutex.wait.hook":37.881},"trace_dropped":true,"trace_dropped_threads":{"queue worker 0x0":{"events_full_after_s":39.148,"events_lost":326776,"totals_full":false}},"trace":"aps5-trace-608dd7684303-3.json.gz"}
{"commit":"99e0ed0b22e1","dirty":false,"env":{"APS5_PAD_INPUT_FILE":"<path>","APS5_TRACE_SECONDS":"0:60"},"gpu":"NVIDIA GeForce RTX 4070 Ti","driver":"NVIDIA 615.71.09","os":"Linux 7.0.0-38-generic","cpu":"13th Gen Intel(R) Core(TM) i7-13700K","cpu_threads":24,"memory_mib":30993,"title_id":"PPSA31162","title":"Super Meat Boy 3D","content_version":"02.000.001","resolution":"3840x2160","window":{"spec":"seconds 0:60","first_present":0,"ms":60046.580},"presents":407,"frame_ms":{"p50":127.515,"p90":145.986,"p99":1470.568,"max":4077.124},"gpu_busy_ms_per_present":88.427,"worker_busy_pct":{"queue worker 0x0":84.278,"queue worker 0x20":83.321},"top_phases_ms_per_frame":{"Driver.Packet":247.180,"Driver.Packet.memory_wait":122.112,"Driver.Packet.dispatch":58.010,"Driver.Dispatch":57.804,"Shader.PrepareArtifact":45.558,"Driver.Packet.pipeline_drain":40.848,"Recorder.Sync":40.056,"GpuMutex.wait.hook":37.265},"trace_dropped":true,"trace_dropped_threads":{"queue worker 0x0":{"events_full_after_s":39.307,"events_lost":312804,"totals_full":false}},"trace":"aps5-trace-99e0ed0b22e1-3.json.gz"}

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
  • Fixes: none
  • Unblocks: none
  • GPUs tested: NVIDIA RTX 4070 Ti (615.71.09, Linux)
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5029075146 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11719). Originally posted by [milescoviello](https://github.com/milescoviello) on 2026-10-27T05:28:30Z. --- ### What `BasicEvaluator::MayEvaluate` (`SrtEvaluator.cpp`) builds a new `std::vector` of required arguments for every value it visits, and visits each expanded value twice: once to push the arguments, once to check them. In a DWARF profile of Crimson Desert's shader preparation, `MayEvaluate` and everything below it is 7.9 % of samples, and about half of that is `malloc`/`free`. This change keeps one requirement list per `MayEvaluate` call and refills it for each value instead of returning a new vector, so the list's storage is allocated once per call. ### How The `requirements` lambda now clears and fills a `required` vector declared before the work loop, and returns nothing. Its two uses read that vector right after calling it. The nested `MayEvaluate` for `ReadFirstLane` has its own list, so no list is shared across calls. The evaluation order and results are unchanged. Changed: `core/shader/recompiler/Optimization/src/SrtWalker/SrtEvaluator.cpp`. ### Tested All on Linux, i7-13700K, GCC 15.2, Release with SPIR-V Tools off, `main` d093ea9ced and this commit. - **Equivalence:** `agc_shader_replay --spv` over 152 Crimson Desert (PPSA25286) registration requests and MXGP 26's (PPSA30839) 305 dumped requests gives byte-identical SPIR-V for all 65 and 302 outputs. - **CPU time:** `agc_shader_replay --prepare` over the 152 Crimson Desert requests, `perf stat -e task-clock`, 8 rounds with `main` and this change interleaved, `ANYPS5_NO_SHADER_CACHE=1`. `main` took 15.59 s on average (SD 0.12) and this change 15.34 s (SD 0.12), **1.6 % less**, lower in all 8 rounds. - **Tests:** the 16 AGC driver tests for resource tables, user data and descriptors (`agc_driver_compute_table_calls`, `compute_fs_table_calls`, `compute_user_data_calls(_registered)`, `image_table*`, `buffer_descriptor_runtime`, `descriptor_web_faults`, `fragment_user_data_tail`, `draw_shader_failure_materialization*`) pass 3 of 3 on an RTX 4070 Ti (NVIDIA 615.71.09). - **Windows 11 VM** (GT 1030 with NVIDIA R580, WinLibs GCC 15.2, Release): the same 16 tests pass 3 of 3 at this head (`bf97894bc8`) and on its base `main` `d093ea9ced`. #11506 (hugodearaujo) cuts how often `MayDecide` is called, by deciding each branch condition once per plan. This PR makes each call cheaper, so the two add up. The two PRs don't touch the same lines. **Title captures:** Super Meat Boy 3D, `main` `9af563f33d` + #11580 (`608dd76843`) against the same + this PR (`99e0ed0b22`), 3 interleaved rounds, recompiler cache off. `Shader.PrepareArtifact` worker time is 12,443 ms → 12,250 ms (-1.6 %, lower in 2 of 3 rounds; within the run-to-run spread, and the title thread is +1.5 %) ([table and traces](https://github.com/milescoviello/AnyPS5/releases/tag/pr11719-smb3d-captures)). Round 2's summary lines: ``` {"commit":"608dd7684303","dirty":false,"env":{"APS5_PAD_INPUT_FILE":"<path>","APS5_TRACE_SECONDS":"0:60"},"gpu":"NVIDIA GeForce RTX 4070 Ti","driver":"NVIDIA 615.71.09","os":"Linux 7.0.0-38-generic","cpu":"13th Gen Intel(R) Core(TM) i7-13700K","cpu_threads":24,"memory_mib":30993,"title_id":"PPSA31162","title":"Super Meat Boy 3D","content_version":"02.000.001","resolution":"3840x2160","window":{"spec":"seconds 0:60","first_present":0,"ms":60103.630},"presents":412,"frame_ms":{"p50":127.311,"p90":141.599,"p99":1449.702,"max":4081.458},"gpu_busy_ms_per_present":88.914,"worker_busy_pct":{"queue worker 0x0":85.830,"queue worker 0x20":83.892},"top_phases_ms_per_frame":{"Driver.Packet":247.479,"Driver.Packet.memory_wait":122.137,"Driver.Packet.dispatch":58.758,"Driver.Dispatch":58.625,"Shader.PrepareArtifact":44.971,"Driver.Packet.pipeline_drain":40.257,"Recorder.Sync":39.859,"GpuMutex.wait.hook":37.881},"trace_dropped":true,"trace_dropped_threads":{"queue worker 0x0":{"events_full_after_s":39.148,"events_lost":326776,"totals_full":false}},"trace":"aps5-trace-608dd7684303-3.json.gz"} {"commit":"99e0ed0b22e1","dirty":false,"env":{"APS5_PAD_INPUT_FILE":"<path>","APS5_TRACE_SECONDS":"0:60"},"gpu":"NVIDIA GeForce RTX 4070 Ti","driver":"NVIDIA 615.71.09","os":"Linux 7.0.0-38-generic","cpu":"13th Gen Intel(R) Core(TM) i7-13700K","cpu_threads":24,"memory_mib":30993,"title_id":"PPSA31162","title":"Super Meat Boy 3D","content_version":"02.000.001","resolution":"3840x2160","window":{"spec":"seconds 0:60","first_present":0,"ms":60046.580},"presents":407,"frame_ms":{"p50":127.515,"p90":145.986,"p99":1470.568,"max":4077.124},"gpu_busy_ms_per_present":88.427,"worker_busy_pct":{"queue worker 0x0":84.278,"queue worker 0x20":83.321},"top_phases_ms_per_frame":{"Driver.Packet":247.180,"Driver.Packet.memory_wait":122.112,"Driver.Packet.dispatch":58.010,"Driver.Dispatch":57.804,"Shader.PrepareArtifact":45.558,"Driver.Packet.pipeline_drain":40.848,"Recorder.Sync":40.056,"GpuMutex.wait.hook":37.265},"trace_dropped":true,"trace_dropped_threads":{"queue worker 0x0":{"events_full_after_s":39.307,"events_lost":312804,"totals_full":false}},"trace":"aps5-trace-99e0ed0b22e1-3.json.gz"} ``` ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [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] Fixes: none - [x] Unblocks: none - [x] GPUs tested: NVIDIA RTX 4070 Ti (615.71.09, Linux) - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
MarcZX10 commented 2026-10-27 05:35:50 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-27T05:35:50Z.

Review: CHANGES_REQUESTED


The evaluator change is a small reuse of the same per-call vector; after requirements(current) fills it, the existing loop consumes it before the next call, so I found no changed traversal order in this diff. I also syntax-checked the exact changed translation unit with the configured GCC flags, and git diff --check passes.

I cannot approve this performance PR without the required runtime report. The current evidence is from agc_shader_replay --prepare, not paired AnyPS5 captures for the same title, scene, and machine with both aps5-summary.jsonl lines, traces, and tools/trace_digest.py output. The automated label check has already requested those artifacts. Please add the required report before approval; the reported shader-equivalence and focused test results are useful but do not replace it. I did not rerun those runtime/GPU tests locally, and product CI is skipped by path policy.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5662677155 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11719#pullrequestreview-5662677155). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-27T05:35:50Z. **Review:** CHANGES_REQUESTED --- The evaluator change is a small reuse of the same per-call vector; after `requirements(current)` fills it, the existing loop consumes it before the next call, so I found no changed traversal order in this diff. I also syntax-checked the exact changed translation unit with the configured GCC flags, and `git diff --check` passes. I cannot approve this performance PR without the required runtime report. The current evidence is from `agc_shader_replay --prepare`, not paired AnyPS5 captures for the same title, scene, and machine with both `aps5-summary.jsonl` lines, traces, and `tools/trace_digest.py` output. The automated label check has already requested those artifacts. Please add the required report before approval; the reported shader-equivalence and focused test results are useful but do not replace it. I did not rerun those runtime/GPU tests locally, and product CI is skipped by path policy.
MarcZX10 commented 2026-10-27 06:42:51 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-27T06:42:51Z.

Review: APPROVED


The new evidence resolves my earlier concern about the performance report. This CPU-side shader-compilation change has paired replay timing and byte-identical SPIR-V, and I verified the closely analogous #9132 exception: collaborator oneandonlydean explicitly accepted CPU-only replay evidence for this kind of change and confirmed that acceptance stood. I therefore accept the replay measurements here without requiring a GPU capture. The automated perf numbers missing label may remain until a maintainer clears it, as happened on #9132.

The code change reuses a per-call requirements vector without changing traversal or evaluation order; my previous exact-head review and syntax check found no code issue. The author now reports the focused 16 AGC tests passing 3/3 on Windows as well as the reported Linux checks. I did not independently rerun the title/GPU tests or a full build; hosted product jobs are skipped by path policy. Approving based on the reviewed diff, paired CPU measurements, byte-identical shader output, and the accepted repository precedent.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5663187711 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11719#pullrequestreview-5663187711). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-27T06:42:51Z. **Review:** APPROVED --- The new evidence resolves my earlier concern about the performance report. This CPU-side shader-compilation change has paired replay timing and byte-identical SPIR-V, and I verified the closely analogous #9132 exception: collaborator oneandonlydean explicitly accepted CPU-only replay evidence for this kind of change and confirmed that acceptance stood. I therefore accept the replay measurements here without requiring a GPU capture. The automated `perf numbers missing` label may remain until a maintainer clears it, as happened on #9132. The code change reuses a per-call requirements vector without changing traversal or evaluation order; my previous exact-head review and syntax check found no code issue. The author now reports the focused 16 AGC tests passing 3/3 on Windows as well as the reported Linux checks. I did not independently rerun the title/GPU tests or a full build; hosted product jobs are skipped by path policy. Approving based on the reviewed diff, paired CPU measurements, byte-identical shader output, and the accepted repository precedent.
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!11719
No description provided.