fix(vk): avoid unrelated PsychoV35 shader variants #3138

Merged
HumanBean merged 2 commits from futondestroyer/Longshot:codex/psychov35-curve-filter into main 2026-12-04 02:32:29 +00:00
Member

Summary

TL;DR PsychoV35 was giving thousands of unrelated shaders their own curve variants and compiling them during play. This change checks aligned shader words with a filter sized to the shader. In the paired Native HDR runs, Field-to-Market shader pipeline wait fell from 2.50 seconds to zero.

The hitch shows up on first entry into Market or Zora’s Domain with Native HDR and PsychoV35 active. The four-byte scan and the larger filter keep unrelated programs on their ordinary keys. The minimum filter size preserves the order of hooks for small shaders. The renderer reports a curve with no candidates after 100,000 checks in one hook generation.

Start with Words::of and Curve::may_take in gpu/vk/program_hooks.h, and the regression in tests/program_hooks_test.cpp. Reconstructed from the original PsychoV35 stutter handoff and its unpublished test and fix, 0f68f7072 and 2d09245a9.

Testing

Tested: Windows 11, GeForce RTX 4070, driver 621.01, 2560×1440 Native HDR10/PQ and PsychoV35. Two interleaved repetitions took the same child save from Hyrule Field into Market and then the Zora River entrance to Zora’s Domain. Both builds reached both scenes and applied the PsychoV35 curve. The candidate logged two applied hooks and zero refusals in each run. Stock logged one application and 63 refusals per run, filling the 64-entry diagnostic sample. Both current Windows runtimes passed Builder verification. All seven focused program-hook checks passed on 82929aa0. The game-free regression failed on stock and passed on the fix with Windows Clang and GCC. Removing the small-shader floor also failed the targeted regression.

The earlier full Windows strict comparison on the same feature diff returned 831 passes, 51 platform skips and these nine shared failures on each side: test_cursor_hidden_linux.py, test_dev_update.py, test_float_add_subgroup.py, test_helpers_extract.py, test_lifter.py, test_longshot_builder.py, test_native_zstd.py, test_run_all_junit.py, and test_utf8_paths.py. The full suite at the final comparison revisions is pending.

Still to test:

  • RTX 5080 with DLSS and Native HDR/PsychoV35 at the original Zora hotspot, expecting the same curve output with fewer shader-related hitches (by hand).
  • Linux Vulkan with Native HDR and PsychoV35, expecting the curve to apply and first-entry rendering to remain correct (by hand).

Measurements

Verdict: Median Field-to-Market p99 frame time fell from 94.05 ms to 32.00 ms. Recorded shader pipeline wait fell from 2.50 s to zero. At the Zora entrance it fell from 2.52 s to 2.2 ms.

Setup: RTX 4070, driver 621.01, Windows 11, 2560×1440 Native HDR10/PQ, PsychoV35, 60 FPS cap, game upscaler, frame generation off. Both sides prepared 70,273 graphics and 5,087 compute pipelines. Each prepared set contained 35,105 graphics notes with RGBA16F attachments and used its own NVIDIA cache. The reverse-order pair used independently copied, hash-checked caches. Rows are medians over two runs per side. The route measurements start at the transition and include 600 presentations in the destination.

Measurement Before: main @ 5be6ba30 After: this PR @ 82929aa0
Field → Market p99 frame time 94.05 ms 32.00 ms
Field → Market 1% low 3.33 FPS 9.43 FPS
Field → Market hitches ≥50 ms 15.5 7.5
Field → Market pipeline wait 2,497.9 ms 0 ms
Field → Market draws left out 557.5 0
Zora entrance p99 frame time 58.70 ms 35.71 ms
Zora entrance hitches ≥50 ms 10.5 5.0
Zora entrance pipeline wait 2,521.6 ms 2.2 ms
Zora entrance draws left out 476.5 1
Distinct graphics translation keys logged across the run 520 2
Private process memory at Market 19.05 GiB 19.44 GiB

The game-free shader corpus check separately inspected 22,356 fragment stages. Stock admitted 8,528 stages. This filter admitted all 330 aligned constant matches and zero unrelated stages in that corpus.

Risks

A short shader can contain both constants in unrelated instructions. The pass still verifies that the curve it replaces is present. Larger shaders use a larger membership bitmap. The two Market private-memory snapshots per build varied by up to 0.46 GiB. Reverting the change restores the previous filter.

Checklist

Ready for review

  • One topic, on current main; the title is a Conventional Commit. The published head is the exact head used for gameplay. Main has since advanced.
  • Tested on my own PC, in the game for a change the game runs, as Testing says.
  • mise run test passes (any failure that also fails on main is named). The exact-head focused tests pass.
  • Measured against main, or Measurements says why there is nothing to measure.
  • No game files, build output or hand-edited generated files; third_party/ untouched; nothing GPL-incompatible.

When it applies

  • A fix: a game-free test that fails on main and passes here.
  • Docs updated.
  • AI assistance recorded with Assisted-by: / Co-Authored-By: trailers.

Ready to merge

  • Everything in Still to test has run, its results in Tested.
  • Tier 1 hardware it can affect is tested (docs/dev/standards.md, “Hardware tiers”).
  • Approved in review, every comment answered.
  • CI passes on the head; on current main, measured again or a comment says why the numbers still hold.
## Summary **TL;DR** PsychoV35 was giving thousands of unrelated shaders their own curve variants and compiling them during play. This change checks aligned shader words with a filter sized to the shader. In the paired Native HDR runs, Field-to-Market shader pipeline wait fell from 2.50 seconds to zero. The hitch shows up on first entry into Market or Zora’s Domain with Native HDR and PsychoV35 active. The four-byte scan and the larger filter keep unrelated programs on their ordinary keys. The minimum filter size preserves the order of hooks for small shaders. The renderer reports a curve with no candidates after 100,000 checks in one hook generation. Start with `Words::of` and `Curve::may_take` in `gpu/vk/program_hooks.h`, and the regression in `tests/program_hooks_test.cpp`. Reconstructed from the original PsychoV35 stutter handoff and its unpublished test and fix, `0f68f7072` and `2d09245a9`. ## Testing **Tested:** Windows 11, GeForce RTX 4070, driver 621.01, 2560×1440 Native HDR10/PQ and PsychoV35. Two interleaved repetitions took the same child save from Hyrule Field into Market and then the Zora River entrance to Zora’s Domain. Both builds reached both scenes and applied the PsychoV35 curve. The candidate logged two applied hooks and zero refusals in each run. Stock logged one application and 63 refusals per run, filling the 64-entry diagnostic sample. Both current Windows runtimes passed Builder verification. All seven focused program-hook checks passed on `82929aa0`. The game-free regression failed on stock and passed on the fix with Windows Clang and GCC. Removing the small-shader floor also failed the targeted regression. The earlier full Windows strict comparison on the same feature diff returned 831 passes, 51 platform skips and these nine shared failures on each side: `test_cursor_hidden_linux.py`, `test_dev_update.py`, `test_float_add_subgroup.py`, `test_helpers_extract.py`, `test_lifter.py`, `test_longshot_builder.py`, `test_native_zstd.py`, `test_run_all_junit.py`, and `test_utf8_paths.py`. The full suite at the final comparison revisions is pending. **Still to test:** - RTX 5080 with DLSS and Native HDR/PsychoV35 at the original Zora hotspot, expecting the same curve output with fewer shader-related hitches (by hand). - Linux Vulkan with Native HDR and PsychoV35, expecting the curve to apply and first-entry rendering to remain correct (by hand). ## Measurements **Verdict:** Median Field-to-Market p99 frame time fell from 94.05 ms to 32.00 ms. Recorded shader pipeline wait fell from 2.50 s to zero. At the Zora entrance it fell from 2.52 s to 2.2 ms. Setup: RTX 4070, driver 621.01, Windows 11, 2560×1440 Native HDR10/PQ, PsychoV35, 60 FPS cap, game upscaler, frame generation off. Both sides prepared 70,273 graphics and 5,087 compute pipelines. Each prepared set contained 35,105 graphics notes with RGBA16F attachments and used its own NVIDIA cache. The reverse-order pair used independently copied, hash-checked caches. Rows are medians over two runs per side. The route measurements start at the transition and include 600 presentations in the destination. | Measurement | Before: main @ `5be6ba30` | After: this PR @ `82929aa0` | |---|---:|---:| | Field → Market p99 frame time | 94.05 ms | 32.00 ms | | Field → Market 1% low | 3.33 FPS | 9.43 FPS | | Field → Market hitches ≥50 ms | 15.5 | 7.5 | | Field → Market pipeline wait | 2,497.9 ms | 0 ms | | Field → Market draws left out | 557.5 | 0 | | Zora entrance p99 frame time | 58.70 ms | 35.71 ms | | Zora entrance hitches ≥50 ms | 10.5 | 5.0 | | Zora entrance pipeline wait | 2,521.6 ms | 2.2 ms | | Zora entrance draws left out | 476.5 | 1 | | Distinct graphics translation keys logged across the run | 520 | 2 | | Private process memory at Market | 19.05 GiB | 19.44 GiB | The game-free shader corpus check separately inspected 22,356 fragment stages. Stock admitted 8,528 stages. This filter admitted all 330 aligned constant matches and zero unrelated stages in that corpus. ## Risks A short shader can contain both constants in unrelated instructions. The pass still verifies that the curve it replaces is present. Larger shaders use a larger membership bitmap. The two Market private-memory snapshots per build varied by up to 0.46 GiB. Reverting the change restores the previous filter. ## Checklist ### Ready for review - [ ] One topic, on current `main`; the title is a Conventional Commit. The published head is the exact head used for gameplay. Main has since advanced. - [x] Tested on my own PC, in the game for a change the game runs, as Testing says. - [ ] `mise run test` passes (any failure that also fails on `main` is named). The exact-head focused tests pass. - [x] Measured against `main`, or Measurements says why there is nothing to measure. - [x] No game files, build output or hand-edited generated files; `third_party/` untouched; nothing GPL-incompatible. ### When it applies - [x] A fix: a game-free test that fails on `main` and passes here. - [x] Docs updated. - [x] AI assistance recorded with `Assisted-by:` / `Co-Authored-By:` trailers. ### Ready to merge - [ ] Everything in Still to test has run, its results in Tested. - [ ] Tier 1 hardware it can affect is tested (docs/dev/standards.md, “Hardware tiers”). - [ ] Approved in review, every comment answered. - [ ] CI passes on the head; on current `main`, measured again or a comment says why the numbers still hold.
fix(vk): keep large shaders out of unrelated curve variants
Some checks failed
CI / What the change needs (pull_request) Successful in 7s
CI / Third-party parts and guide screenshots (pull_request) Successful in 10s
PR description / Title and description (pull_request_target) Failing after 5s
CI / Lint (pre-commit, ShellCheck, actionlint) (pull_request) Successful in 21s
CI / Host C for Windows (llvm-mingw, compile only) (pull_request) Failing after 1m25s
CI / Rust (rustfmt, clippy, cargo test, end to end) (pull_request) Failing after 11m45s
CI / Renderer build check (Windows, compile --only renderer, without and with FSR 4) (pull_request) Successful in 17m22s
CI / Renderer build check (Linux, compile --only renderer, without and with FSR 4) (pull_request) Successful in 16m40s
CI / Website build and checks (pull_request) Failing after 1m12s
CI / Game-free checks (run_all.py, part 1/2) (pull_request) Failing after 15m3s
CI / Game-free checks (run_all.py, part 2/2) (pull_request) Failing after 52m1s
82929aa0d7
Reconstructed from the original PsychoV35 stutter handoff and its unpublished test and fix (0f68f7072 and 2d09245a9).

Assisted-by: OpenAI Codex
Author
Member

Tested in game: Windows 11, RTX 4070, driver 621.01. Two interleaved Field-to-Market and Zora Domain runs in 2560x1440 Native HDR10/PQ with PsychoV35. Both builds completed both routes and applied the curve. Field-to-Market median p99 was 94.05 ms on 5be6ba30 and 32.00 ms on 82929aa0. The candidate recorded zero pipeline wait on that stretch.

Tested in game: Windows 11, RTX 4070, driver 621.01. Two interleaved Field-to-Market and Zora Domain runs in 2560x1440 Native HDR10/PQ with PsychoV35. Both builds completed both routes and applied the curve. Field-to-Market median p99 was 94.05 ms on 5be6ba30 and 32.00 ms on 82929aa0. The candidate recorded zero pipeline wait on that stretch.
Author
Member
@review
BeanBot left a comment

Recommendation: Approve. The code is ready: only testing is left. The paired Windows runs show a substantial reduction in shader waits and transition frame times. The renderer change still needs the stated Linux and other Tier 1 hardware coverage, plus a check of its startup and memory costs. Recommend approval; not approved on the forge.

The change filters fragment shaders by aligned words using a size-scaled bitmap, reducing unnecessary PsychoV35 variants and translations. It adds per-shader bitmap allocation and retains larger summaries in memory.

Testing before merging (2) (runs on the systems it can change; it doesn't hold the recommendation)

  • L1 gpu/vk/program_hooks.h:71: The size-scaled summary is allocated for every fragment stage, including when no curve is active; its startup and retained-memory cost has not been isolated. (more on the line) Do: Compare cold and warm startup or preparation time, process memory and cache size on the base and this head, including a run with the curve disabled. (@fix does its part first: Avoid constructing or retaining the summary when curve matching is not needed, while ensuring it is available if hooks change later.)
  • L2 gpu/vk/program_hooks.h:69: The changed shader-selection path needs gameplay coverage on the other Tier 1 systems it can affect. (more on the line) Do: Run Native HDR and PsychoV35 through the affected transitions on Linux and representative AMD and Steam Deck Tier 1 hardware, checking output and first-entry behavior; also complete the stated RTX 5080/DLSS run.

@fix can do L1.

Checks: Still running: 11 checks.

More: does it help, other systems, switches, what was read

Does it help: Yes, on the tested Windows RTX 4070: two interleaved runs per build report median Field-to-Market p99 falling from 94.05 ms to 32.00 ms and pipeline wait from 2.50 s to zero. The same comparison reports Zora entrance p99 falling from 58.70 ms to 35.71 ms.

Other systems: The filter is built for fragment stages regardless of whether a curve is active, and is used in live and prepared shader paths on both Windows and Linux. The RTX 4070 runs show the curve applying; Linux, AMD, Steam Deck, and the stated RTX 5080/DLSS case remain untested.

Switches: None.

Reviewed: 82929aa0d7 against 5be6ba309e: Read AGENTS.md, CONTRIBUTING.md, the PR template, standards, all changed code files and the diff, commit messages, and the relevant shader parsing, hook selection, cache-key and test-runner code. Reviewed the changed documentation passages and skimmed related decoder and cache references. docs/review-checklist.md and the adjacent Tooling checkout were absent. No recorded run files or generated files were changed.; nothing run (a code review).

Checked and fine:

  • The filter retains the former minimum bitmap size and its larger power-of-two masks preserve the old low hash bits.
  • The diagnostic counter uses atomic operations, and the regression exercises both a large unrelated shader and a later matching curve.
  • The changed files contain no game-derived output, generated files, third-party changes, API version changes or new switches; the implementation commit records AI assistance.

Testing: No code or tests were run as requested. The author reports focused game-free checks and paired Windows gameplay runs; CI and the final full-suite comparison are still pending.

Overlaps and merge order: Not established; the network is closed.


Automated code review by BeanBot (gpt-6.1-terra), asked for by futondestroyer. Nothing was run; a maintainer decides.

**Recommendation: Approve.** The code is ready: only testing is left. The paired Windows runs show a substantial reduction in shader waits and transition frame times. The renderer change still needs the stated Linux and other Tier 1 hardware coverage, plus a check of its startup and memory costs. Recommend approval; not approved on the forge. The change filters fragment shaders by aligned words using a size-scaled bitmap, reducing unnecessary PsychoV35 variants and translations. It adds per-shader bitmap allocation and retains larger summaries in memory. **Testing before merging (2)** (runs on the systems it can change; it doesn't hold the recommendation) - **L1** `gpu/vk/program_hooks.h:71`: The size-scaled summary is allocated for every fragment stage, including when no curve is active; its startup and retained-memory cost has not been isolated. (more on the line) **Do:** Compare cold and warm startup or preparation time, process memory and cache size on the base and this head, including a run with the curve disabled. *(`@fix` does its part first: Avoid constructing or retaining the summary when curve matching is not needed, while ensuring it is available if hooks change later.)* - **L2** `gpu/vk/program_hooks.h:69`: The changed shader-selection path needs gameplay coverage on the other Tier 1 systems it can affect. (more on the line) **Do:** Run Native HDR and PsychoV35 through the affected transitions on Linux and representative AMD and Steam Deck Tier 1 hardware, checking output and first-entry behavior; also complete the stated RTX 5080/DLSS run. `@fix` can do L1. **Checks:** Still running: 11 checks. <details> <summary>More: does it help, other systems, switches, what was read</summary> **Does it help:** Yes, on the tested Windows RTX 4070: two interleaved runs per build report median Field-to-Market p99 falling from 94.05 ms to 32.00 ms and pipeline wait from 2.50 s to zero. The same comparison reports Zora entrance p99 falling from 58.70 ms to 35.71 ms. **Other systems:** The filter is built for fragment stages regardless of whether a curve is active, and is used in live and prepared shader paths on both Windows and Linux. The RTX 4070 runs show the curve applying; Linux, AMD, Steam Deck, and the stated RTX 5080/DLSS case remain untested. **Switches:** None. **Reviewed:** 82929aa0d746 against 5be6ba309e5e: Read AGENTS.md, CONTRIBUTING.md, the PR template, standards, all changed code files and the diff, commit messages, and the relevant shader parsing, hook selection, cache-key and test-runner code. Reviewed the changed documentation passages and skimmed related decoder and cache references. docs/review-checklist.md and the adjacent Tooling checkout were absent. No recorded run files or generated files were changed.; nothing run (a code review). **Checked and fine:** - The filter retains the former minimum bitmap size and its larger power-of-two masks preserve the old low hash bits. - The diagnostic counter uses atomic operations, and the regression exercises both a large unrelated shader and a later matching curve. - The changed files contain no game-derived output, generated files, third-party changes, API version changes or new switches; the implementation commit records AI assistance. **Testing:** No code or tests were run as requested. The author reports focused game-free checks and paired Windows gameplay runs; CI and the final full-suite comparison are still pending. **Overlaps and merge order:** Not established; the network is closed. </details> --- <sub>Automated code review by BeanBot (gpt-6.1-terra), asked for by futondestroyer. Nothing was run; a maintainer decides.</sub>
@ -80,2 +67,3 @@
Words s;
for (size_t i = 0; i + 4 <= n; i++) {
const size_t count = n / sizeof(uint32_t);
if (!count) return s;
Member

L2 (should fix): The changed shader-selection path needs gameplay coverage on the other Tier 1 systems it can affect.

When: The only reported gameplay runs are on Windows with an RTX 4070. Linux Vulkan, AMD and Steam Deck have not demonstrated correct curve output and first-entry rendering with this filter.

Do: Run Native HDR and PsychoV35 through the affected transitions on Linux and representative AMD and Steam Deck Tier 1 hardware, checking output and first-entry behavior; also complete the stated RTX 5080/DLSS run.

**L2** (should fix): The changed shader-selection path needs gameplay coverage on the other Tier 1 systems it can affect. *When:* The only reported gameplay runs are on Windows with an RTX 4070. Linux Vulkan, AMD and Steam Deck have not demonstrated correct curve output and first-entry rendering with this filter. **Do:** Run Native HDR and PsychoV35 through the affected transitions on Linux and representative AMD and Steam Deck Tier 1 hardware, checking output and first-entry behavior; also complete the stated RTX 5080/DLSS run.
@ -82,0 +68,4 @@
const size_t count = n / sizeof(uint32_t);
if (!count) return s;
// Eight bits per input word, rounded up to a power of two. Preserve the old 4096-bit floor so a small shader
// cannot newly match an earlier curve and shadow a later one.
Member

L1 (should fix): The size-scaled summary is allocated for every fragment stage, including when no curve is active; its startup and retained-memory cost has not been isolated.

When: A player without PsychoV35 still builds and retains these bitmaps as stages are parsed. Large stages use more memory than the former fixed 512-byte summary, and the reported Market snapshots vary enough that they do not settle the cost.

Do: Compare cold and warm startup or preparation time, process memory and cache size on the base and this head, including a run with the curve disabled.

**L1** (should fix): The size-scaled summary is allocated for every fragment stage, including when no curve is active; its startup and retained-memory cost has not been isolated. *When:* A player without PsychoV35 still builds and retains these bitmaps as stages are parsed. Large stages use more memory than the former fixed 512-byte summary, and the reported Market snapshots vary enough that they do not settle the cost. **Do:** Compare cold and warm startup or preparation time, process memory and cache size on the base and this head, including a run with the curve disabled.
Owner

I ran one local 60-second pair on Linux with an RTX 3090 and NVIDIA driver 620.70.06. Both builds used a nested Gamescope HDR10 surface at 2560×1440, Native HDR with PsychoV35, the game's upscaler, a 60 FPS cap, and V-Sync and frame generation off. I used the same Castle Town gate save and scripted entry into the Market, with matching copies of the warmed caches.

First 600 frames from the transition input Stock 5be6ba309e5e PR 82929aa0d746
Shader pipeline wait 1,377.13 ms 47.75 ms
Pipeline waits 212 11
p99 frame time 115.20 ms 63.33 ms
Frames at or above 50 ms 8 8
Draws left out 1,379 1,374

Both builds logged an applied PsychoV35 curve. Stock logged 63 curve refusals in the diagnostic sample and the PR logged zero. Across the full 60 seconds, average FPS was 58.3 vs 59.4 and p99 was 19.27 vs 19.85 ms. The queue reported no noise flags during either measured window. All seven focused program-hook checks passed on the PR head.

I ran one local 60-second pair on Linux with an RTX 3090 and NVIDIA driver 620.70.06. Both builds used a nested Gamescope HDR10 surface at 2560×1440, Native HDR with PsychoV35, the game's upscaler, a 60 FPS cap, and V-Sync and frame generation off. I used the same Castle Town gate save and scripted entry into the Market, with matching copies of the warmed caches. | First 600 frames from the transition input | Stock `5be6ba309e5e` | PR `82929aa0d746` | | --- | ---: | ---: | | Shader pipeline wait | 1,377.13 ms | 47.75 ms | | Pipeline waits | 212 | 11 | | p99 frame time | 115.20 ms | 63.33 ms | | Frames at or above 50 ms | 8 | 8 | | Draws left out | 1,379 | 1,374 | Both builds logged an applied PsychoV35 curve. Stock logged 63 curve refusals in the diagnostic sample and the PR logged zero. Across the full 60 seconds, average FPS was 58.3 vs 59.4 and p99 was 19.27 vs 19.85 ms. The queue reported no noise flags during either measured window. All seven focused program-hook checks passed on the PR head.
HumanBean changed title from WIP: fix(vk): avoid unrelated PsychoV35 shader variants to fix(vk): avoid unrelated PsychoV35 shader variants 2026-12-04 02:32:24 +00:00
HumanBean deleted branch codex/psychov35-curve-filter 2026-12-04 02:32:29 +00:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
3 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!3138
No description provided.