WIP: perf(vk): reuse matching live shader stages on first use #1596

Draft
HumanBean wants to merge 1 commit from HumanBean/Longshot:perf/reuse-live-shader-stages into main
Owner

Type: perf · Risk: medium · Tested on: CachyOS Linux, Ryzen 9 7900X, 32 GiB, GeForce RTX 3090, NVIDIA 620.70.06

TL;DR

Share identical live shader stages between programs. Across 271 matched first uses at the Field entrance, total first-use time changed from 27.36 to 26.48 ms. This is one instrumented comparison.

Why and what changed

Recent stages occupy 32 bounded lookup slots. Reuse requires identical control and code bytes plus matching native MMA mode. A weak reference permits eviction while queued compilation work retains its own input. Previously each program lowered its stage independently.

Measurements

Both runs used a cache prepared by their own translator. Of the first uses inside the Field loading bracket, 271 matched by shader program, draw/dispatch, cache outcome and occurrence count. Those uses had median times of 0.030 ms on stock and 0.020 ms with reuse. Startup and route history differed. Overall FPS and stutter gains remain unproven.

Testing

The game completed the headless Market-to-Field route. A synthetic delayed-job regression covers releasing the source serial and displacing the lookup slot before running queued compilation. The full suite reported 721 passed, 41 failed and 19 skipped. All 41 failures reproduced on the control.

Risks and remaining work

The source change invalidates the translator stamp on first launch and can require substantial recompilation. Payloads up to 64 KiB are eligible per entry. Fresh preparations on both translators produced 47,867 common program keys. Every translated stage fingerprint matched. Four additional fixed-marker headless runs exercised independently prepared, stage-verified caches. The application pipeline cache was disabled and the NVIDIA driver cache was warm. Each run indexed 32,390 notes for 20,411 programs.

Run order Market FPS Market p99 ms Field FPS Field p99 ms Worst Field crossing frame ms Outside builds flagged
stock-a 64.64 27.22 64.88 22.05 401.04 1
reuse-a 64.02 30.07 78.55 19.40 366.69 0
reuse-b 69.62 25.24 77.72 19.96 354.87 0
stock-b 66.53 24.55 79.23 18.36 369.89 0

The GPU and route matched across arms. The first stock run coincided with an outside build detected by the local queue. The final stock run was faster in Field than either candidate run. Market p99 increased in both pairs and the Market FPS deltas changed sign. These runs leave an overall gameplay gain unproven.

Checklist

  • The changed path was exercised locally in the game.
  • The branch is based on main at 876dc360. Measurements were taken before the cold-install packaging change on that revision.
  • Project source, tests and measurement summaries only. Third-party sources are untouched.
  • Codex assistance recorded in the commit.
  • Completed both timing orders and documented the outside build in the first control run.
  • Additional hardware and residual first-use hitches still need coverage.
Checks also failing on the control

tests/test_bug_report_defaults.py, tests/test_capture_readback_visibility.py, tests/test_cpu_report.py, tests/test_crt_options.py, tests/test_damage_debug_menu.py, tests/test_dev_packs.py, tests/test_display_startup_failure.py, tests/test_dlss_feature_size.py, tests/test_draw_stream_visibility.py, tests/test_failed_compile_keeps_objects.py, tests/test_fsr_image_retirement.py, tests/test_fsr_uniform_ownership.py, tests/test_guest_imported.py, tests/test_hud_layout_row.py, tests/test_invalidate_quick.py, tests/test_invalidate_vcore.py, tests/test_libc_hooks.py, tests/test_linux_preflight.py, tests/test_linux_pressure.py, tests/test_linux_update.py, tests/test_log_open_failure.py, tests/test_mirror_budget.py, tests/test_missing_nup.py, tests/test_mods_size_table.py, tests/test_nonuniform_image_arrays.py, tests/test_parallel_init_order.py, tests/test_pending_guest_import.py, tests/test_pipeline_play_cache.py, tests/test_present_source_crop.py, tests/test_present_thread.py, tests/test_profiling_mode.py, tests/test_psychov35_fsr3_fg.py, tests/test_readback_timeout_source.py, tests/test_replay_write_order.py, tests/test_run_all_changed.py, tests/test_slow_frames.py, tests/test_staging_burst.py, tests/test_switch_table.py, tests/test_upscaler_rows.py, tests/test_vk_occlusion_queries.py, tests/test_walk_key.py

**Type:** perf · **Risk:** medium · **Tested on:** CachyOS Linux, Ryzen 9 7900X, 32 GiB, GeForce RTX 3090, NVIDIA 620.70.06 ## TL;DR Share identical live shader stages between programs. Across 271 matched first uses at the Field entrance, total first-use time changed from 27.36 to 26.48 ms. This is one instrumented comparison. ## Why and what changed Recent stages occupy 32 bounded lookup slots. Reuse requires identical control and code bytes plus matching native MMA mode. A weak reference permits eviction while queued compilation work retains its own input. Previously each program lowered its stage independently. ## Measurements Both runs used a cache prepared by their own translator. Of the first uses inside the Field loading bracket, 271 matched by shader program, draw/dispatch, cache outcome and occurrence count. Those uses had median times of 0.030 ms on stock and 0.020 ms with reuse. Startup and route history differed. Overall FPS and stutter gains remain unproven. ## Testing The game completed the headless Market-to-Field route. A synthetic delayed-job regression covers releasing the source serial and displacing the lookup slot before running queued compilation. The full suite reported 721 passed, 41 failed and 19 skipped. All 41 failures reproduced on the control. ## Risks and remaining work The source change invalidates the translator stamp on first launch and can require substantial recompilation. Payloads up to 64 KiB are eligible per entry. Fresh preparations on both translators produced 47,867 common program keys. Every translated stage fingerprint matched. Four additional fixed-marker headless runs exercised independently prepared, stage-verified caches. The application pipeline cache was disabled and the NVIDIA driver cache was warm. Each run indexed 32,390 notes for 20,411 programs. | Run order | Market FPS | Market p99 ms | Field FPS | Field p99 ms | Worst Field crossing frame ms | Outside builds flagged | |---|---:|---:|---:|---:|---:|---:| | stock-a | 64.64 | 27.22 | 64.88 | 22.05 | 401.04 | 1 | | reuse-a | 64.02 | 30.07 | 78.55 | 19.40 | 366.69 | 0 | | reuse-b | 69.62 | 25.24 | 77.72 | 19.96 | 354.87 | 0 | | stock-b | 66.53 | 24.55 | 79.23 | 18.36 | 369.89 | 0 | The GPU and route matched across arms. The first stock run coincided with an outside build detected by the local queue. The final stock run was faster in Field than either candidate run. Market p99 increased in both pairs and the Market FPS deltas changed sign. These runs leave an overall gameplay gain unproven. ## Checklist - [x] The changed path was exercised locally in the game. - [x] The branch is based on main at `876dc360`. Measurements were taken before the cold-install packaging change on that revision. - [x] Project source, tests and measurement summaries only. Third-party sources are untouched. - [x] Codex assistance recorded in the commit. - [x] Completed both timing orders and documented the outside build in the first control run. - [ ] Additional hardware and residual first-use hitches still need coverage. <details><summary>Checks also failing on the control</summary> `tests/test_bug_report_defaults.py`, `tests/test_capture_readback_visibility.py`, `tests/test_cpu_report.py`, `tests/test_crt_options.py`, `tests/test_damage_debug_menu.py`, `tests/test_dev_packs.py`, `tests/test_display_startup_failure.py`, `tests/test_dlss_feature_size.py`, `tests/test_draw_stream_visibility.py`, `tests/test_failed_compile_keeps_objects.py`, `tests/test_fsr_image_retirement.py`, `tests/test_fsr_uniform_ownership.py`, `tests/test_guest_imported.py`, `tests/test_hud_layout_row.py`, `tests/test_invalidate_quick.py`, `tests/test_invalidate_vcore.py`, `tests/test_libc_hooks.py`, `tests/test_linux_preflight.py`, `tests/test_linux_pressure.py`, `tests/test_linux_update.py`, `tests/test_log_open_failure.py`, `tests/test_mirror_budget.py`, `tests/test_missing_nup.py`, `tests/test_mods_size_table.py`, `tests/test_nonuniform_image_arrays.py`, `tests/test_parallel_init_order.py`, `tests/test_pending_guest_import.py`, `tests/test_pipeline_play_cache.py`, `tests/test_present_source_crop.py`, `tests/test_present_thread.py`, `tests/test_profiling_mode.py`, `tests/test_psychov35_fsr3_fg.py`, `tests/test_readback_timeout_source.py`, `tests/test_replay_write_order.py`, `tests/test_run_all_changed.py`, `tests/test_slow_frames.py`, `tests/test_staging_burst.py`, `tests/test_switch_table.py`, `tests/test_upscaler_rows.py`, `tests/test_vk_occlusion_queries.py`, `tests/test_walk_key.py` </details>
perf(vk): reuse matching live shader stages on first use
Some checks failed
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Has been skipped
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Has been skipped
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Has been skipped
Third-party parts / The same as upstream (pull_request) Has been skipped
Website / Website on Cloudflare (pull_request) Has been skipped
PR description / Description follows the template (pull_request_target) Successful in 15s
CI / Conventional Commit title (pull_request) Successful in 13s
Guide screenshots / Guide images and local UI source review (pull_request) Failing after 22s
CI / Workflow lint (actionlint) (pull_request) Successful in 25s
Third-party parts / As their notes say (pull_request) Successful in 25s
Website / Website on Cloudflare (pull_request_target) Has been skipped
0a1c900364
Assisted-by: OpenAI Codex
Author
Owner

Tested in game: Linux, Ryzen 9 7900X, RTX 3090, NVIDIA 620.70.06. Completed the headless route from Market into Field. Compared 271 matched first shader uses at Field entry with matching keys and outcomes.

Tested in game: Linux, Ryzen 9 7900X, RTX 3090, NVIDIA 620.70.06. Completed the headless route from Market into Field. Compared 271 matched first shader uses at Field entry with matching keys and outcomes.
Collaborator

Possibly related, for context:

  • PR #1564 perf(vk): defer speculative pipeline probes when a draw needs its shader — Related Vulkan first-use shader/pipeline performance change; already merged.
  • issue #1510 The shader cache key includes the size of the program struct, so adding any member to it makes every player prepare all shaders again — Shader cache stamp issue; this PR also changes translator stamp and causes re-preparation.
Possibly related, for context: - PR #1564 perf(vk): defer speculative pipeline probes when a draw needs its shader — Related Vulkan first-use shader/pipeline performance change; already merged. - issue #1510 The shader cache key includes the size of the program struct, so adding any member to it makes every player prepare all shaders again — Shader cache stamp issue; this PR also changes translator stamp and causes re-preparation.
HumanBean force-pushed perf/reuse-live-shader-stages from 0a1c900364
Some checks failed
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Has been skipped
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Has been skipped
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Has been skipped
Third-party parts / The same as upstream (pull_request) Has been skipped
Website / Website on Cloudflare (pull_request) Has been skipped
PR description / Description follows the template (pull_request_target) Successful in 15s
CI / Conventional Commit title (pull_request) Successful in 13s
Guide screenshots / Guide images and local UI source review (pull_request) Failing after 22s
CI / Workflow lint (actionlint) (pull_request) Successful in 25s
Third-party parts / As their notes say (pull_request) Successful in 25s
Website / Website on Cloudflare (pull_request_target) Has been skipped
to ae5ff24ac1
Some checks failed
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Has been skipped
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Has been skipped
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Has been skipped
Third-party parts / The same as upstream (pull_request) Has been skipped
Website / Website on Cloudflare (pull_request) Has been skipped
CI / Conventional Commit title (pull_request) Successful in 13s
CI / Workflow lint (actionlint) (pull_request) Successful in 20s
Guide screenshots / Guide images and local UI source review (pull_request) Failing after 20s
Third-party parts / As their notes say (pull_request) Successful in 26s
PR description / Description follows the template (pull_request_target) Successful in 4s
2026-11-18 15:14:19 +00:00
Compare
Author
Owner

Corrected author and committer attribution to HumanBean. Verified identical file contents before and after the metadata change. Fresh preparations had identical stage fingerprints for all 47,867 indexed program keys. The GCC and Clang delayed-job checks also passed.

Corrected author and committer attribution to HumanBean. Verified identical file contents before and after the metadata change. Fresh preparations had identical stage fingerprints for all 47,867 indexed program keys. The GCC and Clang delayed-job checks also passed.
Author
Owner

Finished both headless timing orders with matching prepared stage fingerprints. Market FPS changed sign between pairs. Field 78.55 and 77.72 FPS with reuse overlaps the controls at 64.88 and 79.23 FPS. The queue detected an outside build in the first control. Full timings and p99 are now in the description.

Finished both headless timing orders with matching prepared stage fingerprints. Market FPS changed sign between pairs. Field 78.55 and 77.72 FPS with reuse overlaps the controls at 64.88 and 79.23 FPS. The queue detected an outside build in the first control. Full timings and p99 are now in the description.
Some checks failed
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Has been skipped
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Has been skipped
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Has been skipped
Third-party parts / The same as upstream (pull_request) Has been skipped
Website / Website on Cloudflare (pull_request) Has been skipped
CI / Conventional Commit title (pull_request) Successful in 13s
CI / Workflow lint (actionlint) (pull_request) Successful in 20s
Guide screenshots / Guide images and local UI source review (pull_request) Failing after 20s
Third-party parts / As their notes say (pull_request) Successful in 26s
PR description / Description follows the template (pull_request_target) Successful in 4s
This pull request is marked as a work in progress.
This branch is out-of-date with the base branch
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u 'perf/reuse-live-shader-stages:HumanBean-perf/reuse-live-shader-stages'
git switch 'HumanBean-perf/reuse-live-shader-stages'
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
MagicBeanDev/Longshot!1596
No description provided.