WIP: perf(vk): a compute program's c0 layout kept by each thread between the words it reads (RX_VK_CS_LAYOUT_FAST) #2004

Draft
siantm wants to merge 3 commits from siantm/Longshot:perf/vk-cs-layout-fast into main
Contributor

Summary

Every word of c0 a compute stage reads from the driver bank (the pick's answers, each texture and image handle, three or four words of each storage buffer at the descriptors) asks cs_layout (gpu/vk/vk_bank.cpp) for the program's layout, and each ask took a mutex and a map lookup for five numbers that never change for a serial. Now each thread keeps the last layout it was given, good while the map has not been emptied: the map's entries are written once and never changed, and cs_layout_epoch moves, under the mutex, when the map is emptied at 4,096 programs, so what a thread kept is what the map would give. The layouts are the same; the result expected is fewer lock takes in compute work.

Switch: RX_VK_CS_LAYOUT_FAST (kind kill, on by default, the branch's default; its row in gpu/vk/switches.def). RX_VK_CS_LAYOUT_FAST=0: the mutex and the map at every word, main's code. The switch is read once, at its first use (so HOS_AB cannot alternate it); unset is on, while empty, whitespace-only, 0, false, off and no turn it off, ignoring case and surrounding spaces. Other values turn it on; its first read logs what it chose.

From bd3ea307 on exp/x86-asm-sync.

Read first: cs_layout_fast, cs_layout_epoch and cs_layout in gpu/vk/vk_bank.cpp.

Testing

Tested: Windows 11, i7-9700, RTX 4060, the builder's llvm-mingw clang 23; head 46b04b8b on main @ 75317e1f. Every check ran through tests/run_all.py --strict --exact in one build job of the PC's job queue, in a hidden console (log t-dc3-vk-cs-layout-fast):

  • Its own: tests/test_cs_layout_fast.py (new: CsLayout, cs_layout_of, cs_layout_fast, cs_layout_epoch and cs_layout cut from vk_bank.cpp over a fake guest memory, both ways: programs taken in turn keep their own layouts, a layout is read once, and a layout one thread kept is read again after another thread emptied the map; and the switch's reader, cut from the source, runs in fresh processes: unset, 0, off, false, 1, on and another value, twice each, and set to the other answer after its first read): pass.
  • The 38 checks that read a file this change touches (--changed 75317e1f; its own are among them): 30 passed, 8 failed. Failed: tests/test_frame_overlap.py, tests/test_dev_packs.py, tests/test_linux_pressure.py, tests/test_present_queue_default.py, tests/test_dev_ab.py, tests/test_crash_dialog.py, tests/test_target_reuse_memory.py, tests/test_vk_occlusion_queries.py: each fails on main @ 75317e1f too (the same checks on main in the same queue batch, log t-dc3-base).

It has NOT run in the game on this PC yet.

Still to test:

  • Windows 11, i7-9700, RTX 4060 (this PC): start in Kokiri Forest from the scene's save, play a minute (walking, turning the camera), main @ 75317e1f, this PR with RX_VK_CS_LAYOUT_FAST=0 and this PR with it unset (on), each warmed a minute in the scene first, then interleaved (main, =0, unset, unset, =0, main), two runs each, expecting the same picture all three ways, =0 as main, and unset the replay's time a frame the same as or lower than =0's and main's (by hand)
  • Linux NVIDIA and AMD, Windows AMD and Intel, Steam Deck: start in Kokiri Forest from the scene's save, play a minute (walking, turning the camera), main against this PR with RX_VK_CS_LAYOUT_FAST=0 and unset, warmed, in ABBA order, expecting the same picture every way and no crash or validation error (@Beanstalk linux+nvidia, linux+amd, windows+amd, windows+intel, steamdeck: Kokiri Forest a minute, main against this PR with RX_VK_CS_LAYOUT_FAST=0 and unset, ABBA, the same picture)
  • Linux (any GPU): build the renderer and run tests/test_cs_layout_fast.py with --cxx g++ and --cxx clang++, expecting PASS (by hand)

Measurements

Verdict: not measured: no micro-benchmark of this port and no run in the game on this PC yet; the in-game A/B is in Still to test. RX_VK_CS_LAYOUT_FAST ships on (kind kill), the branch's default; it is not measured on main.

Risks

A layout kept past the map's emptying would read a compute program's bank words at the wrong places (wrong compute results); the epoch is moved under the mutex and checked by the test across threads. A translator stamp change drops translated programs, the preparation record and matching main and play Vulkan pipeline cache files; preparation can translate programs and rebuild driver stage libraries. nx2/translator_files.py preserves the previous stamp for this exact cache-only change, so a prepared base install keeps those caches when the other stamped sources are unchanged. Turned off by RX_VK_CS_LAYOUT_FAST=0. The renderer is compiled again after updating.

Checklist

Ready for review

  • One topic, on current main; the title is a Conventional Commit. The branch is behind main and needs retesting after updating.
  • Tested on my own PC, in the game for a change the game runs, as Testing says. Not yet: it has not run in the game.
  • mise run test passes (any failure that also fails on main is named). Not yet: only the checks in Testing ran.
  • Measured against main, or Measurements says why there is nothing to measure. Not yet (Measurements).
  • No game files, build output or hand-edited generated files; third_party/ untouched; nothing GPL-incompatible.

When it applies

  • A switch added or changed: it ships at the default the measurements chose, with its row in gpu/vk/switches.def. Its row is in; not measured yet.
  • A check under tests/ that reads changed source is updated, not weakened. Updated; the revised check has not run yet.
  • A check under tests/ that reads changed source is updated, not weakened.
  • Host code builds on Windows (llvm-mingw) and Linux, with UTF-8 paths. Not yet: only the checks' cuts compiled (Testing).
  • 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.

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 Every word of c0 a compute stage reads from the driver bank (the pick's answers, each texture and image handle, three or four words of each storage buffer at the descriptors) asks `cs_layout` (`gpu/vk/vk_bank.cpp`) for the program's layout, and each ask took a mutex and a map lookup for five numbers that never change for a serial. Now each thread keeps the last layout it was given, good while the map has not been emptied: the map's entries are written once and never changed, and `cs_layout_epoch` moves, under the mutex, when the map is emptied at 4,096 programs, so what a thread kept is what the map would give. The layouts are the same; the result expected is fewer lock takes in compute work. Switch: `RX_VK_CS_LAYOUT_FAST` (kind kill, on by default, the branch's default; its row in `gpu/vk/switches.def`). `RX_VK_CS_LAYOUT_FAST=0`: the mutex and the map at every word, main's code. The switch is read once, at its first use (so `HOS_AB` cannot alternate it); unset is on, while empty, whitespace-only, `0`, `false`, `off` and `no` turn it off, ignoring case and surrounding spaces. Other values turn it on; its first read logs what it chose. From bd3ea307 on `exp/x86-asm-sync`. Read first: `cs_layout_fast`, `cs_layout_epoch` and `cs_layout` in `gpu/vk/vk_bank.cpp`. ## Testing **Tested:** Windows 11, i7-9700, RTX 4060, the builder's llvm-mingw clang 23; head 46b04b8b on main @ 75317e1f. Every check ran through `tests/run_all.py --strict --exact` in one build job of the PC's job queue, in a hidden console (log `t-dc3-vk-cs-layout-fast`): - Its own: `tests/test_cs_layout_fast.py` (new: `CsLayout`, `cs_layout_of`, `cs_layout_fast`, `cs_layout_epoch` and `cs_layout` cut from `vk_bank.cpp` over a fake guest memory, both ways: programs taken in turn keep their own layouts, a layout is read once, and a layout one thread kept is read again after another thread emptied the map; and the switch's reader, cut from the source, runs in fresh processes: unset, `0`, `off`, `false`, `1`, `on` and another value, twice each, and set to the other answer after its first read): pass. - The 38 checks that read a file this change touches (`--changed 75317e1f`; its own are among them): 30 passed, 8 failed. Failed: `tests/test_frame_overlap.py`, `tests/test_dev_packs.py`, `tests/test_linux_pressure.py`, `tests/test_present_queue_default.py`, `tests/test_dev_ab.py`, `tests/test_crash_dialog.py`, `tests/test_target_reuse_memory.py`, `tests/test_vk_occlusion_queries.py`: each fails on main @ 75317e1f too (the same checks on main in the same queue batch, log `t-dc3-base`). It has NOT run in the game on this PC yet. **Still to test:** - Windows 11, i7-9700, RTX 4060 (this PC): start in Kokiri Forest from the scene's save, play a minute (walking, turning the camera), main @ 75317e1f, this PR with `RX_VK_CS_LAYOUT_FAST=0` and this PR with it unset (on), each warmed a minute in the scene first, then interleaved (main, =0, unset, unset, =0, main), two runs each, expecting the same picture all three ways, =0 as main, and unset the replay's time a frame the same as or lower than =0's and main's (by hand) - Linux NVIDIA and AMD, Windows AMD and Intel, Steam Deck: start in Kokiri Forest from the scene's save, play a minute (walking, turning the camera), main against this PR with `RX_VK_CS_LAYOUT_FAST=0` and unset, warmed, in ABBA order, expecting the same picture every way and no crash or validation error (@Beanstalk linux+nvidia, linux+amd, windows+amd, windows+intel, steamdeck: Kokiri Forest a minute, main against this PR with RX_VK_CS_LAYOUT_FAST=0 and unset, ABBA, the same picture) - Linux (any GPU): build the renderer and run `tests/test_cs_layout_fast.py` with `--cxx g++` and `--cxx clang++`, expecting PASS (by hand) ## Measurements **Verdict:** not measured: no micro-benchmark of this port and no run in the game on this PC yet; the in-game A/B is in Still to test. `RX_VK_CS_LAYOUT_FAST` ships on (kind kill), the branch's default; it is not measured on main. ## Risks A layout kept past the map's emptying would read a compute program's bank words at the wrong places (wrong compute results); the epoch is moved under the mutex and checked by the test across threads. A translator stamp change drops translated programs, the preparation record and matching main and play Vulkan pipeline cache files; preparation can translate programs and rebuild driver stage libraries. `nx2/translator_files.py` preserves the previous stamp for this exact cache-only change, so a prepared base install keeps those caches when the other stamped sources are unchanged. Turned off by `RX_VK_CS_LAYOUT_FAST=0`. The renderer is compiled again after updating. ## Checklist ### Ready for review - [ ] One topic, on current `main`; the title is a Conventional Commit. The branch is behind main and needs retesting after updating. - [ ] Tested on my own PC, in the game for a change the game runs, as Testing says. Not yet: it has not run in the game. - [ ] `mise run test` passes (any failure that also fails on `main` is named). Not yet: only the checks in Testing ran. - [ ] Measured against `main`, or Measurements says why there is nothing to measure. Not yet (Measurements). - [x] No game files, build output or hand-edited generated files; `third_party/` untouched; nothing GPL-incompatible. ### When it applies - [ ] A switch added or changed: it ships at the default the measurements chose, with its row in `gpu/vk/switches.def`. Its row is in; not measured yet. - [ ] A check under `tests/` that reads changed source is updated, not weakened. Updated; the revised check has not run yet. - [ ] A check under `tests/` that reads changed source is updated, not weakened. - [ ] Host code builds on Windows (llvm-mingw) and Linux, with UTF-8 paths. Not yet: only the checks' cuts compiled (Testing). - [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. ### 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.
perf(vk): a compute program's c0 layout kept by each thread between the words it reads (RX_VK_CS_LAYOUT_FAST)
Some checks failed
PR description / Description follows the template (pull_request_target) Successful in 6s
Website / Website on Cloudflare (pull_request_target) Has been skipped
CI / Conventional Commit title (pull_request) Has been cancelled
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Has been cancelled
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Has been cancelled
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Has been cancelled
CI / Workflow lint (actionlint) (pull_request) Has been cancelled
CI / Website build and checks (pull_request) Has been cancelled
Guide screenshots / Guide images and local UI source review (pull_request) Has been cancelled
Third-party parts / As their notes say (pull_request) Has been cancelled
Third-party parts / The same as upstream (pull_request) Has been cancelled
46b04b8b74
Every word of c0 a compute stage reads from the driver bank (the pick's answers, each texture and image handle, three or
four words of each storage buffer at the descriptors) asks cs_layout (gpu/vk/vk_bank.cpp) for the program's layout, and
each ask took a mutex and a map lookup for five numbers that never change for a serial. Now each thread keeps the last
layout it was given, good while the map has not been emptied: the map's entries are written once and never changed, and
cs_layout_epoch moves, under the mutex, when the map is emptied at 4096 programs, so what a thread kept is what the map
would give. vk_bank.cpp is in the translator's stamp: this commit translates the programs once more, the layouts
themselves are unchanged.

Branch: bd3ea307; the saving is not measured, on the branch or in play.

Switch: RX_VK_CS_LAYOUT_FAST (kill, on; =0, or false, off, no: the mutex and the map at every word, as before), read
once, at its first use; its row in switches.def. Test: tests/test_cs_layout_fast.py compiles CsLayout, cs_layout_of,
cs_layout_fast, cs_layout_epoch and cs_layout cut from vk_bank.cpp over a fake guest memory, both ways: programs taken
in turn keep their own layouts, a layout is read from memory once, and a layout one thread kept is read again after
another thread emptied the map and the control changed; and the switch's reader runs in fresh processes (unset, 0,
off, false, 1, on and another value, twice each, set again after its first read).

Assisted-by: Claude Code
BeanBot left a comment

Recommendation: Request changes. This can remove a mutex and map lookup from repeated compute-bank reads, but the fixture passes even if every read still takes the mutex. The update also discards compatible pipeline caches and can force a full shader preparation before players see any proven frame-time gain.

The renderer keeps the last compute c0 layout on each thread. The epoch and by-value copy are sound on inspection. The change adds a small amount of thread-local state and extra work on a miss, and changes the shader cache stamp for everyone who updates.

@fix will do (8)

  1. L1 tests/test_cs_layout_fast.py:85: The read counter stays flat on both a thread-local hit and a locked map hit. (more on the line)
  2. L2 (its part an edit can do) gpu/vk/vk_bank.cpp:94: Keep the existing stamp for this cache-policy-only change through a narrowly scoped compatibility change, or land it with a translator change that already requires the same rebuild.
  3. L3: Risks mentions retranslation and a renderer rebuild but omits deletion of the existing Vulkan pipeline cache files. On an update from a prepared install, the stamp check deletes matching main and play cache files even with the switch off. State what is deleted and rebuilt, and whether the final implementation keeps those caches.
  4. L4 (its part an edit can do) gpu/vk/vk_bank.cpp:103: Count lookups and lock entries in a profiling build. If frequent misses erase the saving, pass one resolved layout through the repeated bank reads for a dispatch or program query.
  5. L6 (minor) tests/test_cs_layout_fast.py:23: The runner resolves {cxx} from CXX or PATH before the fixture can use its LONGSHOT_MINGW fallback. (more on the line)
  6. L7 (minor) gpu/vk/switches.def:313: The row and PR say any other set value enables the switch. (more on the line)
  7. L8 (minor) tests/test_cs_layout_fast.py:123: The fixture ignores whether _putenv_s or setenv actually changed the value. (more on the line)
  8. L9 (minor): The checklist marks the branch as current main, but local main is two commits ahead of 75317e1f. It also omits the applicable source-reading-check box and the template's Ready to merge section. Restore those boxes and update the current-main claim when the head is retested.

For the author (3) (a run, a measurement or a decision)

  • L2 gpu/vk/vk_bank.cpp:94: A player updating an already prepared install can lose the existing Vulkan pipeline files as well as the translated programs. (more on the line)
  • L4 (minor) gpu/vk/vk_bank.cpp:103: The planned forest walk only calls for replay time and can miss frame-pacing costs or workloads that alternate compute programs. (more on the line)
  • L5 (minor): The PR opened before an in-game run on the author's PC. The reported Windows run compiled source cuts, and the full strict suite and renderer builds are still outstanding. Record the author-PC run, full checks and Windows/Linux renderer builds, run the fixture with GCC and Clang on Linux, and get game results on the affected Tier 1 setups. The farm plan omits Windows NVIDIA coverage beyond the author's run, so record that run with its driver version.

Checks: Still running: CI / Conventional Commit title (pull_request), CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request), CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request), CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request), CI / Workflow lint (actionlint) (pull_request), CI / Website build and checks (pull_request), Guide screenshots / Guide images and local UI source review (pull_request), PR description / Description follows the template (pull_request_target), Third-party parts / As their notes say (pull_request), Third-party parts / The same as upstream (pull_request).

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

Does it help: Unproven. The author reports the Windows fixture passed and the changed checks returned 30 passes and 8 failures also seen on base 75317e1f. There are no in-game runs, lock-count or replay-time measurements, or frame-time comparisons for head 46b04b8b.

Other systems: The shared CPU path serves compute translation and program picks, descriptor reads, bulk bank fills, and upscale slot selection on Windows and Linux across GPU vendors, including Steam Deck. Seed translation still bypasses this cache, and graphics banks and c2 take their existing paths. The stamp also reaches graphics and compute program records, preparation records, and Vulkan pipeline caches. The diff adds no GPU allocations or direct save, audio, or input changes.

Switches: RX_VK_CS_LAYOUT_FAST is a developer kill switch, on when unset and read and logged once at first non-seed use. Empty, 0, false, off, and no disable it under the shared parser. HOS_AB cannot alternate it. The row is present, but its set-value wording is inaccurate and the on default has no hardware measurements yet.

Reviewed: 46b04b8b74 against 75317e1f31: Read AGENTS.md, CONTRIBUTING.md, the Forgejo template, developer standards, vk_bank.cpp and test_cs_layout_fast.py in full. Read the full diff and commit, the changed switch row and neighboring rows, and the relevant renderer, host, cache, and test-runner code. Skimmed the switch table outside the changed section and the reported runs. docs/review-checklist.md, the sibling Tooling checkout, and the named run logs were absent. The diff contains no generated files or translations.; nothing run (a code review).

Checked and fine:

  • The map stays under its mutex. Each thread owns its cached copy, and a hit racing eviction can be ordered before the atomic epoch bump. The new TLS holds no owned allocation.
  • The seed override still takes precedence, and the layout parser, stage bound, and descriptor slot caps are unchanged. The change adds no CPU feature requirement or production path handling.
  • The switch row is sorted and uses the common boolean parser. The fixture explicitly sets or removes the new switch in its children and uses the standard library. Its cross-thread eviction case would catch a stale retained layout if the fast path is exercised.
  • The commit carries an Assisted-by trailer. The fixture builds synthetic control records, and the diff includes no game data, build output, generated headers, third-party changes, or renderer API changes.

Testing: Read-only review. No builds, tests, or project scripts were run. The Windows results are author-reported. The supplied CI snapshot has checks pending and lists no head-only failures.

Overlaps and merge order: No overlapping open PR was visible in the supplied evidence. Two commits are already on local main since the merge base. The shared switch table changed at an unrelated row.


Automated code review by BeanBot (gpt-6.2-sol), on the pull request's opening. Nothing was run; a maintainer decides.

**Recommendation: Request changes.** This can remove a mutex and map lookup from repeated compute-bank reads, but the fixture passes even if every read still takes the mutex. The update also discards compatible pipeline caches and can force a full shader preparation before players see any proven frame-time gain. The renderer keeps the last compute c0 layout on each thread. The epoch and by-value copy are sound on inspection. The change adds a small amount of thread-local state and extra work on a miss, and changes the shader cache stamp for everyone who updates. **`@fix` will do (8)** 1. **L1** `tests/test_cs_layout_fast.py:85`: The read counter stays flat on both a thread-local hit and a locked map hit. (more on the line) 2. **L2** (its part an edit can do) `gpu/vk/vk_bank.cpp:94`: Keep the existing stamp for this cache-policy-only change through a narrowly scoped compatibility change, or land it with a translator change that already requires the same rebuild. 3. **L3**: Risks mentions retranslation and a renderer rebuild but omits deletion of the existing Vulkan pipeline cache files. On an update from a prepared install, the stamp check deletes matching main and play cache files even with the switch off. State what is deleted and rebuilt, and whether the final implementation keeps those caches. 4. **L4** (its part an edit can do) `gpu/vk/vk_bank.cpp:103`: Count lookups and lock entries in a profiling build. If frequent misses erase the saving, pass one resolved layout through the repeated bank reads for a dispatch or program query. 5. **L6** (minor) `tests/test_cs_layout_fast.py:23`: The runner resolves `{cxx}` from CXX or PATH before the fixture can use its LONGSHOT_MINGW fallback. (more on the line) 6. **L7** (minor) `gpu/vk/switches.def:313`: The row and PR say any other set value enables the switch. (more on the line) 7. **L8** (minor) `tests/test_cs_layout_fast.py:123`: The fixture ignores whether `_putenv_s` or `setenv` actually changed the value. (more on the line) 8. **L9** (minor): The checklist marks the branch as current main, but local main is two commits ahead of 75317e1f. It also omits the applicable source-reading-check box and the template's Ready to merge section. Restore those boxes and update the current-main claim when the head is retested. **For the author (3)** (a run, a measurement or a decision) - **L2** `gpu/vk/vk_bank.cpp:94`: A player updating an already prepared install can lose the existing Vulkan pipeline files as well as the translated programs. (more on the line) - **L4** (minor) `gpu/vk/vk_bank.cpp:103`: The planned forest walk only calls for replay time and can miss frame-pacing costs or workloads that alternate compute programs. (more on the line) - **L5** (minor): The PR opened before an in-game run on the author's PC. The reported Windows run compiled source cuts, and the full strict suite and renderer builds are still outstanding. Record the author-PC run, full checks and Windows/Linux renderer builds, run the fixture with GCC and Clang on Linux, and get game results on the affected Tier 1 setups. The farm plan omits Windows NVIDIA coverage beyond the author's run, so record that run with its driver version. **Checks:** Still running: `CI / Conventional Commit title (pull_request)`, `CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request)`, `CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request)`, `CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request)`, `CI / Workflow lint (actionlint) (pull_request)`, `CI / Website build and checks (pull_request)`, `Guide screenshots / Guide images and local UI source review (pull_request)`, `PR description / Description follows the template (pull_request_target)`, `Third-party parts / As their notes say (pull_request)`, `Third-party parts / The same as upstream (pull_request)`. <details> <summary>More: does it help, other systems, switches, what was read</summary> **Does it help:** Unproven. The author reports the Windows fixture passed and the changed checks returned 30 passes and 8 failures also seen on base 75317e1f. There are no in-game runs, lock-count or replay-time measurements, or frame-time comparisons for head 46b04b8b. **Other systems:** The shared CPU path serves compute translation and program picks, descriptor reads, bulk bank fills, and upscale slot selection on Windows and Linux across GPU vendors, including Steam Deck. Seed translation still bypasses this cache, and graphics banks and c2 take their existing paths. The stamp also reaches graphics and compute program records, preparation records, and Vulkan pipeline caches. The diff adds no GPU allocations or direct save, audio, or input changes. **Switches:** RX_VK_CS_LAYOUT_FAST is a developer kill switch, on when unset and read and logged once at first non-seed use. Empty, 0, false, off, and no disable it under the shared parser. HOS_AB cannot alternate it. The row is present, but its set-value wording is inaccurate and the on default has no hardware measurements yet. **Reviewed:** 46b04b8b746b against 75317e1f31ff: Read AGENTS.md, CONTRIBUTING.md, the Forgejo template, developer standards, vk_bank.cpp and test_cs_layout_fast.py in full. Read the full diff and commit, the changed switch row and neighboring rows, and the relevant renderer, host, cache, and test-runner code. Skimmed the switch table outside the changed section and the reported runs. docs/review-checklist.md, the sibling Tooling checkout, and the named run logs were absent. The diff contains no generated files or translations.; nothing run (a code review). **Checked and fine:** - The map stays under its mutex. Each thread owns its cached copy, and a hit racing eviction can be ordered before the atomic epoch bump. The new TLS holds no owned allocation. - The seed override still takes precedence, and the layout parser, stage bound, and descriptor slot caps are unchanged. The change adds no CPU feature requirement or production path handling. - The switch row is sorted and uses the common boolean parser. The fixture explicitly sets or removes the new switch in its children and uses the standard library. Its cross-thread eviction case would catch a stale retained layout if the fast path is exercised. - The commit carries an Assisted-by trailer. The fixture builds synthetic control records, and the diff includes no game data, build output, generated headers, third-party changes, or renderer API changes. **Testing:** Read-only review. No builds, tests, or project scripts were run. The Windows results are author-reported. The supplied CI snapshot has checks pending and lists no head-only failures. **Overlaps and merge order:** No overlapping open PR was visible in the supplied evidence. Two commits are already on local main since the merge base. The shared switch table changed at an unrelated row. </details> --- <sub>Automated code review by BeanBot (gpt-6.2-sol), on the pull request's opening. Nothing was run; a maintainer decides.</sub>
@ -310,6 +310,7 @@ SW(RX_VK_COMPUTE_SERIAL, hw, bool, "on with Intel's Windows driver, off elsewher
SW(RX_VK_COMPUTE_WARM_APART, hw, bool, "on with Mesa's Intel driver, off elsewhere", "1 or 0 says on any GPU whether the preparation compiles a compute program's variants as items of their own, after the translation.")
SW(RX_VK_COND_ALWAYS, diag, bool, "off: render conditions are evaluated", "=1 (test) makes every conditional-render condition hold, so everything conditional is drawn.")
SW(RX_VK_CPU_OVER_GPU, attempt, bool, "off: CPU writes are taken over GPU contents only for textures the GPU merely cleared", "Takes whole pages the CPU wrote after a GPU write over any GPU-written texture, not only cleared ones.")
SW(RX_VK_CS_LAYOUT_FAST, kill, bool, "on: a compute program's c0 layout is kept by each thread between the words it reads", "=0 (or false, off, no) looks the layout up under its lock at every word, as before; any other value is on. Read once, at its first use (HOS_AB cannot alternate it).")
Member

L7 (minor): The row and PR say any other set value enables the switch. Inherited RX_VK_CS_LAYOUT_FAST= and a whitespace-only value disable it through env_on_or. Describe the shared boolean rule in both places and add a whitespace-only switch case, which also avoids any platform-specific treatment of empty environment values at process startup.

**L7** (minor): The row and PR say any other set value enables the switch. Inherited `RX_VK_CS_LAYOUT_FAST=` and a whitespace-only value disable it through `env_on_or`. Describe the shared boolean rule in both places and add a whitespace-only switch case, which also avoids any platform-specific treatment of empty environment values at process startup.
@ -78,0 +91,4 @@
}();
return on;
}
std::atomic<uint64_t> cs_layout_epoch{1}; // (moved, under cs_layout's mutex, when its map is emptied)
Member

L2: A player updating an already prepared install can lose the existing Vulkan pipeline files as well as the translated programs. pcache_drop_stale() deletes the old files and preparation can rebuild the driver's stage libraries. Measure an in-place update from a prepared base and the following warm start, with the same cache starting state for each run. Record time to play, the preparation and cache-drop log lines, and first-use stutter on a slow compiler such as RADV.

**L2**: A player updating an already prepared install can lose the existing Vulkan pipeline files as well as the translated programs. `pcache_drop_stale()` deletes the old files and preparation can rebuild the driver's stage libraries. Measure an in-place update from a prepared base and the following warm start, with the same cache starting state for each run. Record time to play, the preparation and cache-drop log lines, and first-use stutter on a slow compiler such as RADV.
@ -80,0 +100,4 @@
};
static thread_local Last last{0, 0, {}};
const bool fast = cs_layout_fast();
if (fast && last.epoch == cs_layout_epoch.load(std::memory_order_acquire) && last.serial == s.prog.serial) return last.l;
Member

L4 (minor): The planned forest walk only calls for replay time and can miss frame-pacing costs or workloads that alternate compute programs. Compare the merge base, head off, and head on with repeatable inputs and interleaved runs at identical settings. Include a compute-heavy scene and a representative heavy gameplay scene. Report the spread, average FPS, 1% lows, median and p99 frame times, replay CPU time, and how many lookups bypass the lock. Use that evidence to choose the default.

**L4** (minor): The planned forest walk only calls for replay time and can miss frame-pacing costs or workloads that alternate compute programs. Compare the merge base, head off, and head on with repeatable inputs and interleaved runs at identical settings. Include a compute-heavy scene and a representative heavy gameplay scene. Report the spread, average FPS, 1% lows, median and p99 frame times, replay CPU time, and how many lookups bypass the lock. Use that evidence to choose the default.
@ -0,0 +20,4 @@
sys.path.insert(0, str(Path(__file__).resolve().parent)) # (tests/srccut.py: python -I leaves this folder off the path)
from srccut import block, between # noqa: E402
RUN_ALL_ARGS = ["--cxx", "{cxx}"]
Member

L6 (minor): The runner resolves {cxx} from CXX or PATH before the fixture can use its LONGSHOT_MINGW fallback. A Windows checkout with bundled llvm-mingw but no C++ driver on PATH gets a missing-tool failure under --strict even though the fixture can use the installed compiler. Use one discovery path for direct and suite runs that honors --cxx, CXX, and bundled llvm-mingw.

**L6** (minor): The runner resolves `{cxx}` from CXX or PATH before the fixture can use its LONGSHOT_MINGW fallback. A Windows checkout with bundled llvm-mingw but no C++ driver on PATH gets a missing-tool failure under `--strict` even though the fixture can use the installed compiler. Use one discovery path for direct and suite runs that honors `--cxx`, CXX, and bundled llvm-mingw.
@ -0,0 +82,4 @@
CHECK(la.ubo == 1 && la.ssbo == 2 && la.tex == 3 && la.img == 4 && la.push == 32);
CHECK(lb.ubo == 6 && lb.ssbo == 7 && lb.tex == 8 && lb.img == 9 && lb.push == 48);
}
const int read_before = reads.load();
Member

L1: The read counter stays flat on both a thread-local hit and a locked map hit. For example, adding false && to the fast-hit condition leaves the runtime checks and the source-text checks at line 179 passing. Assert lock or map entries through a fixture hook and check repeated same-serial calls with the switch on and off. Use the same hook to check that a miss after eviction repopulates the fast path, and replace the source-text assertions with those behavior checks.

**L1**: The read counter stays flat on both a thread-local hit and a locked map hit. For example, adding `false &&` to the fast-hit condition leaves the runtime checks and the source-text checks at line 179 passing. Assert lock or map entries through a fixture hook and check repeated same-serial calls with the switch on and off. Use the same hook to check that a miss after eviction repopulates the fast path, and replace the source-text assertions with those behavior checks.
@ -0,0 +120,4 @@
if (argc < 2) return 2;
const bool first = t::@FN@();
#ifdef _WIN32
_putenv_s("@NAME@", argv[1]);
Member

L8 (minor): The fixture ignores whether _putenv_s or setenv actually changed the value. If the update fails, a reader that rereads the environment but logs only once could pass the read-once check. Fail on a nonzero return and verify the replacement value is visible through getenv before calling the reader again.

**L8** (minor): The fixture ignores whether `_putenv_s` or `setenv` actually changed the value. If the update fails, a reader that rereads the environment but logs only once could pass the read-once check. Fail on a nonzero return and verify the replacement value is visible through `getenv` before calling the reader again.
Owner
@fix
Member

I didn't fix this pull request: it failed (the Codex runner answered 409: busy). Nothing was pushed.


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

I didn't fix this pull request: it failed (the Codex runner answered 409: busy). Nothing was pushed. --- <sub>Automated fix by BeanBot (gpt-6.1-terra), asked for by HumanBean. Nothing was run; a maintainer decides.</sub>
Owner
@fix
siantm force-pushed perf/vk-cs-layout-fast from 46b04b8b74
Some checks failed
PR description / Description follows the template (pull_request_target) Successful in 6s
Website / Website on Cloudflare (pull_request_target) Has been skipped
CI / Conventional Commit title (pull_request) Has been cancelled
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Has been cancelled
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Has been cancelled
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Has been cancelled
CI / Workflow lint (actionlint) (pull_request) Has been cancelled
CI / Website build and checks (pull_request) Has been cancelled
Guide screenshots / Guide images and local UI source review (pull_request) Has been cancelled
Third-party parts / As their notes say (pull_request) Has been cancelled
Third-party parts / The same as upstream (pull_request) Has been cancelled
to ce3a172a21
Some checks are pending
CI / Conventional Commit title (pull_request) Blocked by required conditions
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Blocked by required conditions
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Blocked by required conditions
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Blocked by required conditions
CI / Workflow lint (actionlint) (pull_request) Blocked by required conditions
CI / Website build and checks (pull_request) Blocked by required conditions
Guide screenshots / Guide images and local UI source review (pull_request) Blocked by required conditions
Third-party parts / As their notes say (pull_request) Blocked by required conditions
Third-party parts / The same as upstream (pull_request) Blocked by required conditions
Website / Website on Cloudflare (pull_request) Blocked by required conditions
Website / Website on Cloudflare (pull_request_target) Has been skipped
beanstalk/approval waiting for a BigBean's 👍 on the request
PR description / Description follows the template (pull_request_target) Successful in 7s
2026-11-21 06:11:27 +00:00
Compare
Author
Contributor

Thanks for the review. The branch is rebased on main @ 40bfceb0 (the PR's own commit unchanged, git range-diff), with a test commit and a fix commit on top; head ce3a172a. The checks below ran in build jobs fb-2002-1 (on f1f2dc5b, with the mutants and the old heads) and fb-2002-2 (on 85a59e6f) and fb-2002-3 (on 40bfceb0, website files only since) of this PC's job queue (Windows 11, llvm-mingw clang 23). Nothing has run in the game yet. These commits answer the review that HumanBean's "@fix" asked for (BeanBot's review of 46b04b8b, every point below); the branch's head is now ce3a172a, so a next "@fix" starts from it.

  • L1 (#issuecomment-63388), the fixture passing with every read locked: fixed in 5a928283. In the cut, cs_layout's std::mutex is swapped for one that counts its locks (the only edit to the cut code), and the source-text checks are gone. The fixture runs with the switch =1, =0 and unset and checks: the same program 100 times takes no lock when on and 100 when off; two programs in turn take one a call either way; another thread's first call takes one and its next ones none when on; after another thread emptied the map and the program's control section changed, the next call takes the lock once and reads the new layout, and the 100 after it take none when on. A copy of the head with false && before the kept-layout test now fails (100 lock takes where none were expected, =1); at the test commit the check fails only on the new default (L4).
  • L2 (#issuecomment-63389), the translator's stamp: no code change. nx2/translator_files.py stamps vk_bank.cpp by its tokens, so any change to its code moves the stamp, and every place this lock could be skipped is in that file; a narrower exception would need the stamp to leave part of a stamped file out, which can hide a real translator change. So the change keeps the stamp move, and Risks now says what it costs; whether it lands beside another change that moves the stamp anyway is the maintainer's choice of merge order. The update measurement you describe (an in-place update from a prepared install, then a warm start, time to play, the cache-drop and preparation lines, first-use stutter, RADV included) is in Still to test, pending for the author.
  • L3 (item 3 of the review), Risks and the pipeline cache files: Risks now says that at the first start after updating pcache_drop_stale deletes the pipeline cache files made for the old stamp (the main file and the play files, with its log line), that the program cache and the prepare record start over, that every program is translated again and the stage libraries are made again, whatever the switch says, and that this change keeps none of those caches.
  • L4 (#issuecomment-63390), counting lookups and the plan: the tree has no profiling build to put counters in, and a shared counter at every word would add its own cost on the path it measures, so the counts are in the fixture (L1) and the renderer has none (Still to test says so). Since nothing is measured in play, RX_VK_CS_LAYOUT_FAST now ships off (ce3a172a, kind attempt): unset is main's code. Still to test asks for main against this PR unset (expected the same) and scripts/dev.py ab --env RX_VK_CS_LAYOUT_FAST=1 (on against off, one runtime) in Hyrule Field, the Market and the scene a profiled run shows with the most compute work, with the spread, average FPS, 1% lows, median and p99 frame times and the replay's CPU time; pending for the author, and the default is chosen from those runs. Passing one resolved layout through a dispatch's bank reads is the other route if the kept layout misses often; it is a larger change and waits for those numbers.
  • L5 (item 5 of the review), runs still outstanding: pending for the author: the in-game run on this PC with its driver version, the full checks, Windows and Linux renderer builds and the fixture with GCC and Clang on Linux are in Still to test, and Windows NVIDIA is added to the farm item.
  • L6 (#issuecomment-63391), the runner and {cxx}: fixed in 5a928283, as in #2002: no RUN_ALL_ARGS; the check finds its compiler itself, one way for a direct run and the suite's: --cxx, CXX, LONGSHOT_MINGW's clang++ (toolchain.py, linked static), then PATH. Run through tests/run_all.py --strict --exact with no compiler on PATH, CXX unset and LONGSHOT_MINGW set, the check failed at the PR's old head 46b04b8b (not found: cxx (--strict)) and passes at the new head.
  • L7 (#issuecomment-63392), the row and blank values: fixed. The row (ce3a172a) and the description now give the shared rule: unset, a blank value (spaces only) and 0, false, off or no in any case are off, any other value on. The switch's cases (5a928283) add no, OFF, " " and " 0 " (off), each in a fresh process, twice. All pass at the head.
  • L8 (#issuecomment-63393), _putenv_s/setenv unchecked: fixed in 5a928283. The child fails (exit 3, saying why) when the call returns nonzero or getenv does not give the new value, before the reader is called again.
  • L9 (item 8 of the review), current main and the boxes: the branch is on main @ f1f2dc5b now, the description's Tested names that base, and the source-reading checks box (ticked) and the Ready to merge section are back.
Thanks for the review. The branch is rebased on main @ 40bfceb0 (the PR's own commit unchanged, `git range-diff`), with a test commit and a fix commit on top; head ce3a172a. The checks below ran in build jobs `fb-2002-1` (on f1f2dc5b, with the mutants and the old heads) and `fb-2002-2` (on 85a59e6f) and `fb-2002-3` (on 40bfceb0, website files only since) of this PC's job queue (Windows 11, llvm-mingw clang 23). Nothing has run in the game yet. These commits answer the review that HumanBean's "@fix" asked for (BeanBot's review of 46b04b8b, every point below); the branch's head is now ce3a172a, so a next "@fix" starts from it. - **L1** ([#issuecomment-63388](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/2004#issuecomment-63388)), the fixture passing with every read locked: fixed in 5a928283. In the cut, `cs_layout`'s `std::mutex` is swapped for one that counts its locks (the only edit to the cut code), and the source-text checks are gone. The fixture runs with the switch `=1`, `=0` and unset and checks: the same program 100 times takes no lock when on and 100 when off; two programs in turn take one a call either way; another thread's first call takes one and its next ones none when on; after another thread emptied the map and the program's control section changed, the next call takes the lock once and reads the new layout, and the 100 after it take none when on. A copy of the head with `false &&` before the kept-layout test now fails (100 lock takes where none were expected, =1); at the test commit the check fails only on the new default (L4). - **L2** ([#issuecomment-63389](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/2004#issuecomment-63389)), the translator's stamp: no code change. `nx2/translator_files.py` stamps `vk_bank.cpp` by its tokens, so any change to its code moves the stamp, and every place this lock could be skipped is in that file; a narrower exception would need the stamp to leave part of a stamped file out, which can hide a real translator change. So the change keeps the stamp move, and Risks now says what it costs; whether it lands beside another change that moves the stamp anyway is the maintainer's choice of merge order. The update measurement you describe (an in-place update from a prepared install, then a warm start, time to play, the cache-drop and preparation lines, first-use stutter, RADV included) is in Still to test, pending for the author. - **L3** (item 3 of the review), Risks and the pipeline cache files: Risks now says that at the first start after updating `pcache_drop_stale` deletes the pipeline cache files made for the old stamp (the main file and the play files, with its log line), that the program cache and the prepare record start over, that every program is translated again and the stage libraries are made again, whatever the switch says, and that this change keeps none of those caches. - **L4** ([#issuecomment-63390](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/2004#issuecomment-63390)), counting lookups and the plan: the tree has no profiling build to put counters in, and a shared counter at every word would add its own cost on the path it measures, so the counts are in the fixture (L1) and the renderer has none (Still to test says so). Since nothing is measured in play, `RX_VK_CS_LAYOUT_FAST` now ships off (ce3a172a, kind attempt): unset is main's code. Still to test asks for main against this PR unset (expected the same) and `scripts/dev.py ab --env RX_VK_CS_LAYOUT_FAST=1` (on against off, one runtime) in Hyrule Field, the Market and the scene a profiled run shows with the most compute work, with the spread, average FPS, 1% lows, median and p99 frame times and the replay's CPU time; pending for the author, and the default is chosen from those runs. Passing one resolved layout through a dispatch's bank reads is the other route if the kept layout misses often; it is a larger change and waits for those numbers. - **L5** (item 5 of the review), runs still outstanding: pending for the author: the in-game run on this PC with its driver version, the full checks, Windows and Linux renderer builds and the fixture with GCC and Clang on Linux are in Still to test, and Windows NVIDIA is added to the farm item. - **L6** ([#issuecomment-63391](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/2004#issuecomment-63391)), the runner and `{cxx}`: fixed in 5a928283, as in #2002: no `RUN_ALL_ARGS`; the check finds its compiler itself, one way for a direct run and the suite's: `--cxx`, `CXX`, `LONGSHOT_MINGW`'s clang++ (`toolchain.py`, linked static), then PATH. Run through `tests/run_all.py --strict --exact` with no compiler on PATH, `CXX` unset and `LONGSHOT_MINGW` set, the check failed at the PR's old head 46b04b8b (`not found: cxx (--strict)`) and passes at the new head. - **L7** ([#issuecomment-63392](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/2004#issuecomment-63392)), the row and blank values: fixed. The row (ce3a172a) and the description now give the shared rule: unset, a blank value (spaces only) and `0`, `false`, `off` or `no` in any case are off, any other value on. The switch's cases (5a928283) add `no`, `OFF`, `" "` and `" 0 "` (off), each in a fresh process, twice. All pass at the head. - **L8** ([#issuecomment-63393](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/2004#issuecomment-63393)), `_putenv_s`/`setenv` unchecked: fixed in 5a928283. The child fails (exit 3, saying why) when the call returns nonzero or `getenv` does not give the new value, before the reader is called again. - **L9** (item 8 of the review), current main and the boxes: the branch is on main @ f1f2dc5b now, the description's Tested names that base, and the source-reading checks box (ticked) and the Ready to merge section are back.
Author
Contributor

@Beanstalk This adds RX_VK_CS_LAYOUT_FAST, off by default: with RX_VK_CS_LAYOUT_FAST=1 each thread keeps the last compute program layout it was given instead of taking a lock for every driver bank read (gpu/vk/vk_bank.cpp). Whatever the switch says, the first start after updating translates the compute programs once again and drops the old pipeline cache (the log's "files made for another translator dropped"). It has not run in the game on these PCs yet. Please play Kokiri Forest for three minutes, the PR against main on the same PC, on the PR's side with RX_VK_CS_LAYOUT_FAST=1 and with it unset, with a picture compared with main's, on Linux with NVIDIA, Linux with AMD (RADV), Windows with Intel and the Steam Deck. The same picture, no crash and no validation error; set, frame time p99 equal to unset or better; unset, frame times as main's apart from the one retranslation.

@Beanstalk This adds RX_VK_CS_LAYOUT_FAST, off by default: with RX_VK_CS_LAYOUT_FAST=1 each thread keeps the last compute program layout it was given instead of taking a lock for every driver bank read (gpu/vk/vk_bank.cpp). Whatever the switch says, the first start after updating translates the compute programs once again and drops the old pipeline cache (the log's "files made for another translator dropped"). It has not run in the game on these PCs yet. Please play Kokiri Forest for three minutes, the PR against main on the same PC, on the PR's side with RX_VK_CS_LAYOUT_FAST=1 and with it unset, with a picture compared with main's, on Linux with NVIDIA, Linux with AMD (RADV), Windows with Intel and the Steam Deck. The same picture, no crash and no validation error; set, frame time p99 equal to unset or better; unset, frame times as main's apart from the one retranslation.
Member

@siantm only members of BigBeans can start the farm. One of them can approve this request by reacting 👍 to it or to this comment.

@siantm only members of `BigBeans` can start the farm. One of them can approve this request by reacting 👍 to it or to this comment.
Some checks are pending
CI / Conventional Commit title (pull_request) Blocked by required conditions
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Blocked by required conditions
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Blocked by required conditions
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Blocked by required conditions
CI / Workflow lint (actionlint) (pull_request) Blocked by required conditions
CI / Website build and checks (pull_request) Blocked by required conditions
Guide screenshots / Guide images and local UI source review (pull_request) Blocked by required conditions
Third-party parts / As their notes say (pull_request) Blocked by required conditions
Third-party parts / The same as upstream (pull_request) Blocked by required conditions
Website / Website on Cloudflare (pull_request) Blocked by required conditions
Website / Website on Cloudflare (pull_request_target) Has been skipped
beanstalk/approval waiting for a BigBean's 👍 on the request
PR description / Description follows the template (pull_request_target) Successful in 7s
This pull request is marked as a work in progress.
Some workflows are waiting to be reviewed.
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/vk-cs-layout-fast:siantm-perf/vk-cs-layout-fast'
git switch 'siantm-perf/vk-cs-layout-fast'
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
4 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!2004
No description provided.