perf(shader): define IrValue's trivial accessors in its header #9132

Merged
milescoviello merged 1 commit from upstream-pr/9132 into main 2026-11-02 07:57:14 +00:00
milescoviello commented 2026-10-21 12:57:29 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-21T12:57:29Z.


What

IrValue's Id, Arguments, Parent, ImmediateU32, IsPhi, HasUses and UseCount only return a member or compare one, but they were defined in IrValue.cpp. So every IR pass outside that file called them out of line. They are now defined inline in IrValue.hpp, next to Opcode, Type, ArgumentCount and the other accessors already there. Nothing else changes.

Why these: in a DWARF profile of shader preparation (agc_shader_replay --prepare over 152 Crimson Desert registration requests, main 2f161d4f33), calls into IrValue's out-of-line members were about 13 % of all leaf samples:

  • HasUses 3.1 %;
  • Parent 2.1 %;
  • Id 1.3 %;
  • IsPhi 0.3 %;
  • and others that this change doesn't touch.

ValidateProgram spent a quarter of its own 8.5 % in Parent, Id and Argument calls.

Tested

Ubuntu 24.04, GCC 13.3, Release (build-rel, SPIRV-Tools off), i7-13700K, on main 2f161d4f33 (rebased onto ce7d547175 afterwards, no conflict).

  • Output: agc_shader_replay --spv over the 409 draw-time requests of MXGP 26 and Super Meat Boy 3D writes 409 SPIR-V modules on both builds. All 409 are byte-identical.
  • Compile time: agc_shader_replay --prepare over the same 152 requests, task-clock, 8 interleaved runs per build, ANYPS5_NO_SHADER_CACHE=1:
build median range
main 17.47 s 17.41 to 17.65 s
this PR 17.16 s 17.05 to 17.29 s

That's 1.8 % less CPU, and the ranges don't overlap.

  • Tests: the 37 tests matching ^shader|^request_serializer$|^agc_shader pass.

  • No Vulkan call changes, and the SPIR-V is identical, so I didn't run a validation-layer comparison.

  • Windows 11 Enterprise 26300, NVIDIA GeForce GT 1030 (driver 582.78), WinLibs GCC 15.2.0 r7 (UCRT), Release: agc_validate_program, agc_masked_select and agc_ir_reclaim pass 3 of 3 on main and 3 of 3 with this change.

  • Windows 11 Home 10.0.26200, NVIDIA GeForce RTX 4070 Laptop GPU (driver 616.92), WinLibs GCC 15.2.0 r7, Release, run by JulesB40 (results): this head merged onto main d4cb89300f matches that main across all 1,125 agc_ tests with the Khronos validation layer on: 1,117 pass, the same 8 skip, and the same 18 VUID- lines, all of them #11990's.

Not tested: Clang.

Performance captures

The form asks for summary lines, so here are two from a title, with a caveat: this change speeds up shader compilation, and that doesn't show in frame time. The title whose start-up is compile-bound here, Crimson Desert, presents almost no frames then (2 in its first 600 s on 10-21), so it has no window to compare. These are from Super Meat Boy 3D (PPSA31162) start-up:

  • With ANYPS5_NO_SHADER_CACHE=1, every shader goes through the recompiler.
  • APS5_TRACE_SECONDS=10:60, 90 s runs, pad input, no other switch.
  • Release libraries of main 2816bd2754 and of this PR merged onto it, two rounds interleaved with the other recompiler PR.
  • Linux, RTX 4070 Ti, NVIDIA 615.71.09.

In that window the shader prepare threads are 1-4 % busy, so the frames show no difference, as expected:

presents frame p50
main 2816bd2754, run 1 513 134.2 ms
this PR merged onto it (1b4e4aa0f5), run 1 454 134.9 ms
main, run 2 459 138.6 ms
this PR, run 2 473 136.9 ms

The measurement of this change is the replay timing under Tested. Traces and digests for all runs are in a release on my fork.

{"commit":"2816bd275452","dirty":false,"env":{"APS5_PAD_INPUT_FILE":"<path>","APS5_TRACE_SECONDS":"10: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 10:60","first_present":24,"ms":60058.966},"presents":513,"frame_ms":{"p50":134.233,"p90":165.070,"p99":217.141,"max":2955.273},"gpu_busy_ms_per_present":89.154,"worker_busy_pct":{"queue worker 0x0":95.177,"queue worker 0x20":93.562},"top_phases_ms_per_frame":{"Driver.Packet":220.791,"Driver.Packet.memory_wait":106.956,"Driver.Packet.dispatch":63.396,"Driver.Dispatch":62.994,"Recorder.Sync":44.242,"GpuMutex.wait.hook":40.453,"Graphics.Draw":32.101,"Graphics.Draw.draw_and_resource_release":29.659},"trace_dropped":true,"trace_dropped_threads":{"queue worker 0x0":{"events_full_after_s":28.862,"events_lost":450991,"totals_full":false}},"trace":"aps5-trace-2816bd275452-3.json.gz"}
{"commit":"1b4e4aa0f5c9","dirty":false,"env":{"APS5_PAD_INPUT_FILE":"<path>","APS5_TRACE_SECONDS":"10: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 10:60","first_present":26,"ms":60009.942},"presents":454,"frame_ms":{"p50":134.899,"p90":215.696,"p99":743.552,"max":3015.552},"gpu_busy_ms_per_present":80.532,"worker_busy_pct":{"queue worker 0x0":92.895,"queue worker 0x20":89.774},"top_phases_ms_per_frame":{"Driver.Packet":241.358,"Driver.Packet.memory_wait":118.072,"Shader.PrepareArtifact":61.656,"Driver.Packet.dispatch":48.886,"Driver.Dispatch":48.721,"Graphics.Draw":37.864,"Driver.Packet.pipeline_drain":35.519,"Graphics.Draw.draw_and_resource_release":33.660},"trace_dropped":true,"trace_dropped_threads":{"queue worker 0x0":{"events_full_after_s":30.811,"events_lost":668152,"totals_full":false}},"trace":"aps5-trace-1b4e4aa0f5c9-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: none needed (shader recompiler only; replay on the CPU)
  • AI-assisted: yes (Claude Code)

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4951935513 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9132). Originally posted by [milescoviello](https://github.com/milescoviello) on 2026-10-21T12:57:29Z. --- ### What `IrValue`'s `Id`, `Arguments`, `Parent`, `ImmediateU32`, `IsPhi`, `HasUses` and `UseCount` only return a member or compare one, but they were defined in `IrValue.cpp`. So every IR pass outside that file called them out of line. They are now defined inline in `IrValue.hpp`, next to `Opcode`, `Type`, `ArgumentCount` and the other accessors already there. Nothing else changes. Why these: in a DWARF profile of shader preparation (`agc_shader_replay --prepare` over 152 Crimson Desert registration requests, `main` 2f161d4f33), calls into `IrValue`'s out-of-line members were about 13 % of all leaf samples: - `HasUses` 3.1 %; - `Parent` 2.1 %; - `Id` 1.3 %; - `IsPhi` 0.3 %; - and others that this change doesn't touch. `ValidateProgram` spent a quarter of its own 8.5 % in `Parent`, `Id` and `Argument` calls. ### Tested Ubuntu 24.04, GCC 13.3, Release (`build-rel`, SPIRV-Tools off), i7-13700K, on `main` 2f161d4f33 (rebased onto ce7d547175 afterwards, no conflict). - **Output:** `agc_shader_replay --spv` over the 409 draw-time requests of MXGP 26 and Super Meat Boy 3D writes 409 SPIR-V modules on both builds. All 409 are byte-identical. - **Compile time:** `agc_shader_replay --prepare` over the same 152 requests, task-clock, 8 interleaved runs per build, `ANYPS5_NO_SHADER_CACHE=1`: | build | median | range | |---|---|---| | `main` | 17.47 s | 17.41 to 17.65 s | | this PR | 17.16 s | 17.05 to 17.29 s | That's 1.8 % less CPU, and the ranges don't overlap. - **Tests:** the 37 tests matching `^shader|^request_serializer$|^agc_shader` pass. - No Vulkan call changes, and the SPIR-V is identical, so I didn't run a validation-layer comparison. - Windows 11 Enterprise 26300, NVIDIA GeForce GT 1030 (driver 582.78), WinLibs GCC 15.2.0 r7 (UCRT), Release: `agc_validate_program`, `agc_masked_select` and `agc_ir_reclaim` pass 3 of 3 on `main` and 3 of 3 with this change. - Windows 11 Home 10.0.26200, NVIDIA GeForce RTX 4070 Laptop GPU (driver 616.92), WinLibs GCC 15.2.0 r7, Release, run by JulesB40 ([results](https://github.com/boykopovar/AnyPS5/pull/9132#issuecomment-6473137945)): this head merged onto `main` `d4cb89300f` matches that `main` across all 1,125 `agc_` tests with the Khronos validation layer on: 1,117 pass, the same 8 skip, and the same 18 `VUID-` lines, all of them #11990's. Not tested: Clang. ### Performance captures The form asks for summary lines, so here are two from a title, with a caveat: this change speeds up shader compilation, and that doesn't show in frame time. The title whose start-up is compile-bound here, Crimson Desert, presents almost no frames then (2 in its first 600 s on 10-21), so it has no window to compare. These are from Super Meat Boy 3D (PPSA31162) start-up: - With `ANYPS5_NO_SHADER_CACHE=1`, every shader goes through the recompiler. - `APS5_TRACE_SECONDS=10:60`, 90 s runs, pad input, no other switch. - Release libraries of `main` 2816bd2754 and of this PR merged onto it, two rounds interleaved with the other recompiler PR. - Linux, RTX 4070 Ti, NVIDIA 615.71.09. In that window the shader prepare threads are 1-4 % busy, so the frames show no difference, as expected: | | presents | frame p50 | |---|---|---| | `main` 2816bd2754, run 1 | 513 | 134.2 ms | | this PR merged onto it (1b4e4aa0f5), run 1 | 454 | 134.9 ms | | `main`, run 2 | 459 | 138.6 ms | | this PR, run 2 | 473 | 136.9 ms | The measurement of this change is the replay timing under Tested. Traces and digests for all runs are in a [release on my fork](https://github.com/milescoviello/AnyPS5/releases/tag/traces-recompiler-perf-smb3d). ```json {"commit":"2816bd275452","dirty":false,"env":{"APS5_PAD_INPUT_FILE":"<path>","APS5_TRACE_SECONDS":"10: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 10:60","first_present":24,"ms":60058.966},"presents":513,"frame_ms":{"p50":134.233,"p90":165.070,"p99":217.141,"max":2955.273},"gpu_busy_ms_per_present":89.154,"worker_busy_pct":{"queue worker 0x0":95.177,"queue worker 0x20":93.562},"top_phases_ms_per_frame":{"Driver.Packet":220.791,"Driver.Packet.memory_wait":106.956,"Driver.Packet.dispatch":63.396,"Driver.Dispatch":62.994,"Recorder.Sync":44.242,"GpuMutex.wait.hook":40.453,"Graphics.Draw":32.101,"Graphics.Draw.draw_and_resource_release":29.659},"trace_dropped":true,"trace_dropped_threads":{"queue worker 0x0":{"events_full_after_s":28.862,"events_lost":450991,"totals_full":false}},"trace":"aps5-trace-2816bd275452-3.json.gz"} ``` ```json {"commit":"1b4e4aa0f5c9","dirty":false,"env":{"APS5_PAD_INPUT_FILE":"<path>","APS5_TRACE_SECONDS":"10: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 10:60","first_present":26,"ms":60009.942},"presents":454,"frame_ms":{"p50":134.899,"p90":215.696,"p99":743.552,"max":3015.552},"gpu_busy_ms_per_present":80.532,"worker_busy_pct":{"queue worker 0x0":92.895,"queue worker 0x20":89.774},"top_phases_ms_per_frame":{"Driver.Packet":241.358,"Driver.Packet.memory_wait":118.072,"Shader.PrepareArtifact":61.656,"Driver.Packet.dispatch":48.886,"Driver.Dispatch":48.721,"Graphics.Draw":37.864,"Driver.Packet.pipeline_drain":35.519,"Graphics.Draw.draw_and_resource_release":33.660},"trace_dropped":true,"trace_dropped_threads":{"queue worker 0x0":{"events_full_after_s":30.811,"events_lost":668152,"totals_full":false}},"trace":"aps5-trace-1b4e4aa0f5c9-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: none needed (shader recompiler only; replay on the CPU) - [x] AI-assisted: yes (Claude Code) 🤖 Generated with [Claude Code](https://claude.com/claude-code)
github-actions[bot] commented 2026-10-21 12:57:44 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-21T12:57:44Z.


This pull request is labeled perf, so it needs the summary line of a capture on main and one with the change, from the same title, scene and machine, as the Performance report form asks. Please paste both aps5-summary.jsonl lines, attach the two traces and add the output of tools/trace_digest.py.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6316610936 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9132#issuecomment-6316610936). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-21T12:57:44Z. --- <!-- pr-labels-perf --> This pull request is labeled `perf`, so it needs the summary line of a capture on `main` and one with the change, from the same title, scene and machine, as the Performance report form asks. Please paste both `aps5-summary.jsonl` lines, attach the two traces and add the output of `tools/trace_digest.py`.
milescoviello commented 2026-10-21 12:58:34 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-21T12:58:34Z.


About the perf label's capture request: this change only affects shader compile time on the CPU. A frame capture would show it only as part of a title's start-up stalls, mixed with everything else that varies there. So it is measured where it applies: the replay of 152 Crimson Desert registration requests, task-clock over 8 interleaved runs per build (median 17.47 → 17.16 s, ranges not overlapping), with byte-identical SPIR-V for the 409 draw-time requests. If the maintainers want a title capture anyway, I can record Crimson Desert's start-up on both builds.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6316633299 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9132#issuecomment-6316633299). Originally posted by [milescoviello](https://github.com/milescoviello) on 2026-10-21T12:58:34Z. --- About the perf label's capture request: this change only affects shader compile time on the CPU. A frame capture would show it only as part of a title's start-up stalls, mixed with everything else that varies there. So it is measured where it applies: the replay of 152 Crimson Desert registration requests, task-clock over 8 interleaved runs per build (median 17.47 → 17.16 s, ranges not overlapping), with byte-identical SPIR-V for the 409 draw-time requests. If the maintainers want a title capture anyway, I can record Crimson Desert's start-up on both builds. AI-assisted: yes (Claude Code)
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!9132
No description provided.