Skip to content

perf(shader): allocate the evaluator's work sets from a per-call arena - #11755

Merged
oneandonlydean merged 2 commits into
boykopovar:mainfrom
milescoviello:perf/srt-evaluator-arena
Nov 2, 2026
Merged

oneandonlydean merged 2 commits into
boykopovar:mainfrom
milescoviello:perf/srt-evaluator-arena

Conversation

@milescoviello

@milescoviello milescoviello commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

What

Stacked on #11719: this branch contains its commit, and this PR adds only the second one (perf(shader): allocate the evaluator's work sets from a per-call arena).

After #11719, most of the remaining allocator time in BasicEvaluator::MayEvaluate (SrtEvaluator.cpp) comes from its per-call work sets. Those are the known map, the expanding set, the pending stack and the requirement list, and each node of an unordered_map/unordered_set is a separate malloc. This gives the four containers a std::pmr::monotonic_buffer_resource per MayEvaluate call, backed by a 2 KiB stack buffer, and switches them to their std::pmr forms. Allocations become pointer bumps, and everything is released at once when the call returns. A call that outgrows the buffer gets more memory from the default resource for the rest of that call. The containers, their contents and the evaluation order are unchanged.

How

std::array<std::byte, 2048> scratch and std::pmr::monotonic_buffer_resource arena(scratch.data(), scratch.size()) at the top of the four-argument MayEvaluate. known, expanding, pending and required become std::pmr::unordered_map, std::pmr::unordered_set and std::pmr::vector on &arena, and pending's initial element is now an emplace_back. Includes <array>, <cstddef> and <memory_resource>. The nested MayEvaluate call for ReadFirstLane gets its own arena on its own stack frame.

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

Tested

Linux, i7-13700K, GCC 15.2, Release with ANYPS5_ENABLE_SPIRV_TOOLS=OFF. Binaries built with cmake --build build-rel --target agc_shader_replay at main d093ea9, at #11719's bf97894bc8, and at this change. The timing runs used f7d299f9b7, which differs from this head only in include order.

  • Equivalence: ANYPS5_NO_SHADER_CACHE=1 agc_shader_replay --spv over the same 152 Crimson Desert (PPSA25286) and 305 MXGP 26 (PPSA30839) requests as perf(shader): reuse the evaluator's requirement list across values #11719 (hashes in #11719). Each binary ran in an empty directory per set, and the sha256sum * | sort -k2 lists were diffed. All 65 and 302 SPIR-V outputs are byte-identical to main's.
  • CPU time: ANYPS5_NO_SHADER_CACHE=1 perf stat -x, -e task-clock -o stat.txt agc_shader_replay --prepare <the 152 requests>, each run in a fresh empty directory, three binaries per round in the order shown:
Round Order main (ms) #11719 (ms) this PR (ms)
1 main, #11719, this 15423 15361 14715
2 main, #11719, this 15585 15269 15365
3 main, #11719, this 15524 15338 15966
4 main, #11719, this 15630 15357 14783
5 main, #11719, this 15571 15208 14818
6 main, #11719, this 15709 15259 15100
7 main, #11719, this 15804 15600 14812
8 main, #11719, this 15514 15319 14900
11 this, #11719, main 15726 15454 15038
12 this, #11719, main 15718 15469 14821
13 this, #11719, main 15663 15417 14850
14 this, #11719, main 15713 15408 14832
15 this, #11719, main 16124 16268 15409
16 this, #11719, main 15901 15542 14843
17 this, #11719, main 15877 15546 15233
18 this, #11719, main 15793 15615 15128
19 this, #11719, main 15677 15498 15018
20 this, #11719, main 15657 15413 14683

Over the 18 rounds the means are main 15.70 s, #11719 15.46 s and this PR 15.02 s (medians 15.69, 15.41 and 14.87 s). This PR is 2.9 % below #11719, lower in 16 of 18 rounds, and 4.35 % below main, lower in 17 of 18. Its spread is wider (SD 0.32 s against 0.16 and 0.23): rounds 2 and 3 were slower than #11719, and I haven't found why.

This is a CPU-only shader-compilation change with byte-identical SPIR-V, like #11719, #9132 and #9198, so it uses the paired CPU replay that oneandonlydean accepted for those (#11719) instead of title captures.

Title captures: Super Meat Boy 3D, main 9af563f33d + #11580 (608dd76843) against the same + this PR (9949c924e6), 3 interleaved rounds, recompiler cache off. Shader.PrepareArtifact worker time over each run's first 400 worker artifacts is 8,953 ms → 9,248 ms (+3.3 %, lower in 1 of 3) and title-thread time over the first 350 is 6,229 ms → 5,993 ms (-3.8 %, 3 of 3), so no clear change in the title (the full-window means aren't comparable: main reached a later scene in rounds 2 and 3) (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":60102.460},"presents":381,"frame_ms":{"p50":111.125,"p90":206.786,"p99":1639.442,"max":4312.934},"gpu_busy_ms_per_present":76.368,"worker_busy_pct":{"queue worker 0x0":82.369,"queue worker 0x20":80.529},"top_phases_ms_per_frame":{"Driver.Packet":256.904,"Driver.Packet.memory_wait":122.582,"Shader.PrepareArtifact":77.003,"Driver.Packet.dispatch":53.530,"Driver.Dispatch":53.053,"Driver.Packet.pipeline_drain":40.714,"Graphics.Draw":35.526,"Graphics.Draw.draw_and_resource_release":32.428},"trace_dropped":true,"trace_dropped_threads":{"queue worker 0x0":{"events_full_after_s":40.991,"events_lost":390042,"totals_full":false}},"trace":"aps5-trace-608dd7684303-3.json.gz"}
{"commit":"9949c924e618","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":60012.799},"presents":413,"frame_ms":{"p50":127.686,"p90":143.835,"p99":1436.839,"max":4135.961},"gpu_busy_ms_per_present":88.442,"worker_busy_pct":{"queue worker 0x0":86.340,"queue worker 0x20":84.179},"top_phases_ms_per_frame":{"Driver.Packet":247.676,"Driver.Packet.memory_wait":121.850,"Driver.Packet.dispatch":58.373,"Driver.Dispatch":58.244,"Shader.PrepareArtifact":44.839,"Driver.Packet.pipeline_drain":40.506,"Recorder.Sync":39.645,"GpuMutex.wait.hook":37.368},"trace_dropped":true,"trace_dropped_threads":{"queue worker 0x0":{"events_full_after_s":38.900,"events_lost":330703,"totals_full":false}},"trace":"aps5-trace-9949c924e618-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: perf(shader): reuse the evaluator's requirement list across values #11719
  • Fixes: none
  • Unblocks: none
  • GPUs tested: NVIDIA RTX 4070 Ti (615.71.09, Linux)
  • AI-assisted: yes

🤖 Generated with Claude Code

milescoviello and others added 2 commits October 27, 2026 05:15
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot added perf Performance change perf numbers missing perf pull request without a before and after summary line labels Oct 27, 2026
@github-actions

Copy link
Copy Markdown

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.

@github-actions

github-actions Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 5609 core/shader/recompiler/Optimization/src/SrtWalker/SrtEvaluator.cpp
PR 12548 core/shader/recompiler/Optimization/src/SrtWalker/SrtEvaluator.cpp

@milescoviello

Copy link
Copy Markdown
Contributor Author

Title captures for this change, with the same setup as the captures on #12039. The base is 608dd76843, which is main 9af563f33d + #11580: Super Meat Boy 3D needs #11580 to run past 11 s on main. The comparison is with this PR (head cfced2eda0) merged on top of it (9949c924e6).

Setup: Super Meat Boy 3D (PPSA31162 02.000.001), release libs, 100 s at a 12 GB cap with the same input script, recompiler cache off (ANYPS5_NO_SHADER_CACHE=1) so every shader is prepared, a warm driver cache, APS5_TRACE_SECONDS=0:60, and 3 rounds alternating which side goes first. Linux, RTX 4070 Ti, 615.71.09.

Shader.PrepareArtifact, summed over the trace window (total ms / slices):

Round main workers this PR workers main title thread this PR title thread
1 (main first) 12,149 / 482 12,821 / 489 6,901 / 387 6,468 / 386
2 (PR first) 21,650 / 631 12,605 / 490 7,687 / 524 5,912 / 375
3 (main first) 25,855 / 647 12,074 / 498 7,739 / 533 6,178 / 392
mean 19,885 12,500 (-37.1 %) 7,442 6,186 (-16.9 %)

That mean isn't a comparison of the same work. In rounds 2 and 3 the main run reached a later scene: 631 and 647 artifacts against 482 to 498 in the other four runs, with 304 and 318 of them prepared after the first 30 s against 11 to 74. The PR build here also carries #11719, which this PR is stacked on.

Boot prepares shaders in nearly the same order every run, so the same work can be compared by taking each run's first 400 worker artifacts and first 350 title-thread artifacts by start time (total ms):

Round main workers this PR workers main title thread this PR title thread
1 (main first) 9,470 9,653 6,623 6,270
2 (PR first) 8,590 9,584 6,092 5,770
3 (main first) 8,799 8,508 5,972 5,939
mean 8,953 9,248 (+3.3 %) 6,229 5,993 (-3.8 %)

Over the same work, the worker time is 3.3 % higher with this PR, lower in only 1 of 3 rounds, and the title-thread time is 3.8 % lower in 3 of 3. That is no clear change in the title. The replay task-clock measurement in the description remains the evidence for the change.

The summary lines of round 2:

{"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":60102.460},"presents":381,"frame_ms":{"p50":111.125,"p90":206.786,"p99":1639.442,"max":4312.934},"gpu_busy_ms_per_present":76.368,"worker_busy_pct":{"queue worker 0x0":82.369,"queue worker 0x20":80.529},"top_phases_ms_per_frame":{"Driver.Packet":256.904,"Driver.Packet.memory_wait":122.582,"Shader.PrepareArtifact":77.003,"Driver.Packet.dispatch":53.530,"Driver.Dispatch":53.053,"Driver.Packet.pipeline_drain":40.714,"Graphics.Draw":35.526,"Graphics.Draw.draw_and_resource_release":32.428},"trace_dropped":true,"trace_dropped_threads":{"queue worker 0x0":{"events_full_after_s":40.991,"events_lost":390042,"totals_full":false}},"trace":"aps5-trace-608dd7684303-3.json.gz"}
{"commit":"9949c924e618","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":60012.799},"presents":413,"frame_ms":{"p50":127.686,"p90":143.835,"p99":1436.839,"max":4135.961},"gpu_busy_ms_per_present":88.442,"worker_busy_pct":{"queue worker 0x0":86.340,"queue worker 0x20":84.179},"top_phases_ms_per_frame":{"Driver.Packet":247.676,"Driver.Packet.memory_wait":121.850,"Driver.Packet.dispatch":58.373,"Driver.Dispatch":58.244,"Shader.PrepareArtifact":44.839,"Driver.Packet.pipeline_drain":40.506,"Recorder.Sync":39.645,"GpuMutex.wait.hook":37.368},"trace_dropped":true,"trace_dropped_threads":{"queue worker 0x0":{"events_full_after_s":38.900,"events_lost":330703,"totals_full":false}},"trace":"aps5-trace-9949c924e618-3.json.gz"}

All six traces, summary lines and tools/trace_digest.py outputs are release assets on my fork: pr11755-smb3d-captures.

AI-assisted: yes (Claude Code)

@github-actions github-actions Bot removed the perf numbers missing perf pull request without a before and after summary line label Oct 28, 2026
@oneandonlydean oneandonlydean self-assigned this Oct 28, 2026
@TechLevelZero

Copy link
Copy Markdown
Contributor

✅ NVIDIA GPU test: passed

PR head cfced2e merged onto main f6fddd6 · tested 2026-10-30 08:36 UTC · 16 min

GPU NVIDIA RTX 2000 Ada Generation, driver 595.99.02, Vulkan 1.4.329
Host Ubuntu 26.04.1 LTS, kernel 7.0.0-38-generic, container ubuntu:24.04
Logs build and test logs for this run
Build ✅ passed (Release, -DANYPS5_ENABLE_SPIRV_TOOLS=ON)
Tests ✅ 2,262 passed · 3 failed (0 new, 2 also fail on main, 1 unstable on main) · 41 skipped (ANYPS5_REQUIRE_VULKAN=1)
Test setup CPU-only tests without a GPU; GPU tests (and any CPU-only test that failed or skipped without one) once on the GPU with VK_LAYER_KHRONOS_validation and ANYPS5_NO_SHADER_CACHE=1; main ran the same way
Test selection 2,306 of 2,950 tests run: the ones this change can reach, chosen by tools/select_tests.py from main's build graph
Vulkan validation ✅ no new validation IDs vs main (862 tests run on the GPU)
Slow tests (>30 s, GPU tests timed with validation layers) ⚠️ agc_driver_bda_device 72.7 s
Unstable on main (1, these also failed in recent main runs on this machine; not counted against this PR)
agc_driver_submit_progress: failed in 5 of the last 7 main runs
Failing on main too (2, not counted against this PR)
guest_mmap_executable
guest_socket_options_multicast
Validation IDs already present on main (4 IDs in 391 tests)
VUID-VkDeviceCreateInfo-pNext-pNext (391 tests): agc_compute_pipeline_replay, agc_driver, agc_driver_address_passes, agc_driver_address_passes_draw_transitions, agc_driver_address_passes_targets_split, agc_driver_alias_copy_label, agc_driver_array_layer_target_cpu, agc_driver_bda_span_reads_draw_pipeline, and 383 more
VUID-vkCmdCopyImage-srcImage-01548 (11 tests): agc_driver_depth_clear_hle, agc_driver_depth_plane_buffer_memory, agc_driver_depth_plane_cpu_write_after_memo, agc_driver_depth_plane_cpu_write_after_page_unwatch, agc_driver_depth_plane_cpu_write_after_partial_unwatch, agc_driver_depth_plane_partial_store, agc_driver_depth_plane_partial_store_unimported, agc_driver_depth_storage_dispatch, and 3 more
VUID-vkCmdCopyImage-srcImage-01551 (11 tests): agc_driver_depth_clear_hle, agc_driver_depth_plane_buffer_memory, agc_driver_depth_plane_cpu_write_after_memo, agc_driver_depth_plane_cpu_write_after_page_unwatch, agc_driver_depth_plane_cpu_write_after_partial_unwatch, agc_driver_depth_plane_partial_store, agc_driver_depth_plane_partial_store_unimported, agc_driver_depth_storage_dispatch, and 3 more
VUID-VkPipelineColorBlendStateCreateInfo-pAttachments-00605 (2 tests): agc_driver_prepared_exports, agc_driver_srgb8_color_target
Skipped (41)
agc_driver_bda_reads_shadowed_results: skipped, the device reports watched host memory written when it imports or reads it
agc_driver_bda_reads_shadowed_results_per_build: skipped, the device reports watched host memory written when it imports or reads it
agc_driver_msaa_dcc_compared_import_2: skipped, the device reports host imports that keep write protection, so the write-watch probe compares none of them
agc_driver_msaa_dcc_compared_import_4: skipped, the device reports host imports that keep write protection, so the write-watch probe compares none of them
agc_driver_msaa_dcc_compared_import_8: skipped, the device reports host imports that keep write protection, so the write-watch probe compares none of them
agc_driver_sample_order_grid_reference: skipped, the device does not keep depth drawn at custom sample locations at those locations, even after a transition that names them: the composite of uniform renders holds the guest's depth in 0 of 3005 sloped samples, so no path can be compared with it bit for bit
agc_driver_sparse_dma_buf_import: skipped, host imports are unavailable: /dev/udmabuf is not accessible
agc_driver_stencil_ref_export: skipped, the device lacks VK_EXT_shader_stencil_export
agc_driver_vertex_elected_atomic_max: skipped, the device runs vertex programs in subgroups, so they keep their cross-lane reductions
agc_host_import_sparse: skipped, host imports are unavailable: /dev/udmabuf is not accessible
agc_import_settle_initial_dcc: skipped, the device has no deferred settle of host imports: imports under 1 MiB wait for one only on Windows
agc_unit_shadow_completion_store: skipped, the device reports watched host memory written when it imports or reads it
guest_http_uri_locale: 
guest_net_ctl: skipped, the host has no IPv4 address
guest_video_out_color_space: skipped, no display or Vulkan device: SDL_InitSubSystem(VIDEO | GAMECONTROLLER) failed: wayland,x11 not available
guest_video_out_hdr: skipped, no display or Vulkan device: SDL_InitSubSystem(VIDEO | GAMECONTROLLER) failed: wayland,x11 not available
guest_video_out_high_frame_rate: skipped, no display or Vulkan device: SDL_InitSubSystem(VIDEO | GAMECONTROLLER) failed: wayland,x11 not available
guest_video_out_output_mode: skipped, no display or Vulkan device: SDL_InitSubSystem(VIDEO | GAMECONTROLLER) failed: wayland,x11 not available
guest_video_out_resolution_status: skipped, no display or Vulkan device: SDL_InitSubSystem(VIDEO | GAMECONTROLLER) failed: wayland,x11 not available
guest_video_out_wqhd_detection: skipped, no display or Vulkan device: SDL_InitSubSystem(VIDEO | GAMECONTROLLER) failed: wayland,x11 not available
video_out_flip_controls: skipped, no display or Vulkan device: DisplayWindow: Vulkan support is either not configured in SDL or not available in current SDL video driver (offscreen) or platform
video_out_flip_cpuflip: skipped, no display or Vulkan device: DisplayWindow: Vulkan support is either not configured in SDL or not available in current SDL video driver (offscreen) or platform
video_out_flip_cpuflip_in_order: skipped, no display or Vulkan device: DisplayWindow: Vulkan support is either not configured in SDL or not available in current SDL video driver (offscreen) or platform
video_out_flip_eop: skipped, no display or Vulkan device: DisplayWindow: Vulkan support is either not configured in SDL or not available in current SDL video driver (offscreen) or platform
video_out_flip_eop_aftergpu: skipped, no display or Vulkan device: DisplayWindow: Vulkan support is either not configured in SDL or not available in current SDL video driver (offscreen) or platform
video_out_flip_eop_main: skipped, no display or Vulkan device: DisplayWindow: Vulkan support is either not configured in SDL or not available in current SDL video driver (offscreen) or platform
video_out_flip_fresh: skipped, no display or Vulkan device: DisplayWindow: Vulkan support is either not configured in SDL or not available in current SDL video driver (offscreen) or plat
Reproduce
git fetch origin cfced2eda02f5733f592587d90b33b1866a2c703 f6fddd60d826831f70f7c62e25423610ee742bcc
git checkout f6fddd60d826831f70f7c62e25423610ee742bcc && git merge --no-ff cfced2eda02f5733f592587d90b33b1866a2c703
git submodule update --init --recursive
cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=ON -DANYPS5_ENABLE_SPIRV_TOOLS=ON
cmake --build build && cmake --build build --target libs
VK_DRIVER_FILES=/nonexistent/icd.json ctest --test-dir build -E '^(agc|shader|recompiler|videoout|video_out|guest_video_out|vulkan)|gpu' --timeout 120 --parallel 32 --output-on-failure
ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation \
  ctest --test-dir build -R '^(agc|shader|recompiler|videoout|video_out|guest_video_out|vulkan)|gpu' --timeout 120 --parallel 4 --output-on-failure
# failures are then re-run alone: --timeout 360 --parallel 2; new validation IDs: the test alone, twice, --parallel 1

Automated build and test on a contributor's NVIDIA machine; it does not replace upstream CI. A new comment is posted for each new push. Full logs.

@oneandonlydean
oneandonlydean merged commit 9d1b5c2 into boykopovar:main Nov 2, 2026
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

perf Performance change shader core/shader

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants