Skip to content

perf(vk): a buffer binding checks the left-out ranges without the shared lock - #119

Merged
Sacrappy merged 1 commit into
Sacrappy:mainfrom
Mooseca:perf-cap-excl-local
Nov 21, 2026
Merged

Sacrappy merged 1 commit into
Sacrappy:mainfrom
Mooseca:perf-cap-excl-local

Conversation

@Mooseca

@Mooseca Mooseca commented Nov 21, 2026

Copy link
Copy Markdown
Contributor

With RX_VK_CAP_ONLY_GPU on (the default), every gpu_buffer_bind calls cap_excl_note, which asks cap_excl_hit whether the binding reaches into memory left out of the captures (engine/gpu/vk/vk_memory.cpp). It asks before its per-thread memo, so it runs on every binding: uniform, storage, vertex and index buffers, about ten a draw, on each of the parallel replay's recording threads. Each ask took cap_excl_mu, one mutex shared by all of them.

The ranges change in only two places: the capture list's rebuild (cap_excl.swap) and a new pool (cap_pool_born_now). Both now bump cap_excl_gen under the lock. cap_excl_hit keeps a thread-local copy of the ranges and takes it again under the lock only when the generation has moved. The answers, and the counts and log lines cap_excl_note makes from them, are unchanged.

docs/SWITCHES.md and engine/docs/switches.json are regenerated (python -I engine/scripts/list_switches.py): their "Read at" line numbers in vk_memory.cpp moved.

Measured (Linux, RX 9070 XT, RADV Mesa 26.2.6, Ryzen 5 5500X3D 6 cores / 12 threads)

Interleaved A/B, 4 rounds per area, order rotated each round, 60 s windows, uncapped, scratch saves, power profile performance, no contaminated runs. A = main 6b7fde7, B = this branch (same code as the build measured):

area (teleport) fps A → B B−A fps replay ms A → B B−A replay ms
Zora's Domain (cheat 1013) 94.14 → 96.72 +2.58 ± 0.30, B ahead in 4/4 7.93 → 7.24 −0.69 ± 0.03, 4/4
Kokiri Forest (cheat 1000) 113.06 → 112.72 −0.33 ± 0.93, 2/4 (noise) 5.54 → 5.41 −0.13 ± 0.07, 3/4

Zora's replay, where the most buffers are bound, is ~9% shorter; Kokiri's frame rate is within noise. Not measured: Windows, NVIDIA, or other CPUs (the gain should be larger with more recording threads contending, but that is a guess).

Tests: python -I -B tests/run_all.py in engine/: 489 passed; tests/test_switches_documented.py passes after the regeneration; nx2/test_nup_read_name.py fails here and on main alike (no zstandard module on this PC).

🤖 Generated with Claude Code

…red lock

With RX_VK_CAP_ONLY_GPU on (the default) every gpu_buffer_bind asks
cap_excl_hit whether the binding reaches into memory left out of the
captures, before its per-thread memo: about ten times a draw on each of
the parallel replay's recording threads, and each ask took cap_excl_mu,
one mutex for all of them. The ranges change only when the capture list
is rebuilt or a pool is made; each thread now keeps its own copy and takes
it again under the lock only when cap_excl_gen, bumped at both changes,
has moved. The answers and the diagnostics they feed are unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Sacrappy

Copy link
Copy Markdown
Owner

Thanks, I read the whole diff: the generation bump under the lock at both change sites and the per-thread copy look right. It touches the Windows renderer, so I'll build it and test it in game on Windows before merging; the machines are busy with measurements right now, so it'll be a little later.

@Sacrappy
Sacrappy merged commit 410d80e into Sacrappy:main Nov 21, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants