WIP: perf(host): raise Windows process priority, lock-free multiwait check, 2-way sync cache, and cloth skin AVX2 #2886

Closed
siantm wants to merge 3 commits from siantm/Longshot:perf/pc-sync-readback-workers-skin into main
Contributor

Type: perf · Risk: medium · Tested on: Windows 11, RTX 4060 (621.40) · Needs: Linux build/test

Why

Three distinct CPU frame-time and tail-latency bottlenecks limit PC frame pacing (1% and 0.1% lows):

  1. Windows background tasks can preempt emulator threads mid-frame while running at NORMAL_PRIORITY_CLASS, causing 60–124 ms frame-time spikes (11.6–15.1 FPS 0.1% lows).
  2. In host/nn_os_sync.c, poke_multiwait() ran InterlockedCompareExchange(&mw_waiting, 0, 0) (dirtying the shared cache line on every signal/send/release) and took AcquireSRWLockExclusive(&mw_lock) to scan mw_watched[] whenever mw_waiting > 0, even when the signaled object is unwatched. Meanwhile obj_nockpt()'s 1-way direct-mapped thread-local cache thrashed on hash-colliding actor mutex addresses.
  3. Pure-leaf Havok cloth bone-space skinning (f_81cdff40, called from 60 sites in code_hot_4.c / code_024*.c) still ran scalar lifted AArch64 loops instead of AVX2/FMA.

This branch stacks on PR #2876 (6b6f82273).

What changed

Raises the Windows process priority class at boot, adds a lock-free unwatched fast path to poke_multiwait() and 2-way associativity to obj_nockpt(), and vectorizes Havok cloth skinning (f_81cdff40) with AVX2/FMA.

  • Windows process priority (host/hos_thread.c): hos_boot_main_thread() sets ABOVE_NORMAL_PRIORITY_CLASS at startup unless HOS_NO_PRIORITIES or HOS_PROCESS_PRIORITY=0 is set.
  • Lock-free poke_multiwait() & 2-way obj_nockpt() cache (host/nn_os_sync.c): maintains a key-indexed 1024-bucket atomic counter array (mw_watch_buckets[1024]) under mw_lock in mw_watch_add_locked() / mw_watch_remove_locked() (preserving tombstone/spare/pre-init safety), replaces InterlockedCompareExchange(&mw_waiting, 0, 0) with __atomic_load_n(&mw_waiting, __ATOMIC_SEQ_CST), returns locklessly when unwatched, and upgrades obj_nockpt()'s 16 KB per-thread cache to 512 x 2-way set-associative with MRU promotion (gated by HOS_SYNC_FAST=0).
  • Havok cloth bone-space skinning AVX2 (host/oot_cloth.c, nx2/oot_patches.py, tests/test_oot_cloth.py): adds hos_oot_cloth_skin(Ctx *c) computing dst[i] = B * M[indices[i]] * S[i] using dual-column YMM AVX2/FMA with hos_guest_range validation, overlap guards, and HOS_WRITTEN(dst, count * 64), hooked idempotently in work/sa/gen/code_hot_4.c under HOS_OOT_CLOTH_AVX2 and unit-tested across GCC & Clang.

Measurements

Verdict: In KokiriForest_Child (1280x720, 4 interleaved 35 s runs via RX_VK_FRAME_TRACE=1), enabling the three changes boosts Avg FPS from 59.43 to 62.40 (+5.0%), 1% Low FPS from 23.14 to 41.87 (+80.9%, non-overlapping 39.08–44.66 vs 20.66–25.62), and 0.1% Low FPS from 13.36 to 31.51 (+135.9%, p99_ms 31.84 -> 21.09 ms, p999_ms 53.91 -> 29.75 ms, max_ms 93.14–123.86 -> 27.56–45.23 ms) with 0 warnings, 0 escapes, and 0 left-out CPU violations. Standalone C/Rust/ASM microbenchmarks show 9.24x–11.50x faster unwatched poke_multiwait, 1.36x–1.49x faster colliding obj_nockpt, and 5.67x–6.13x faster cloth skinning.

Hardware: Windows 11, Intel(R) Core(TM) i7-9700 CPU @ 3.00GHz (8 cores / 8 logical), 32586 MB RAM, NVIDIA GeForce RTX 4060 (driver 621.40)
Scene: KokiriForest_Child (kokiri-start), 1280x720 (resolution=0, quality_preset=6), vsync=0, frame_generation=0, threaded_rendering=0, HOS_FPS_MAX=1000, HOS_AUDIO=0
Baseline: PR #2876 @ 6b6f82273 (Before, toggles off: this PR @ fec6ffd88 with HOS_PROCESS_PRIORITY=0 HOS_SYNC_FAST=0 HOS_OOT_CLOTH_AVX2=0); PR #2876 is the immediate parent commit of this stacked branch so Before vs After isolates commit fec6ffd88 cleanly on identical code and runtime hardware state.
Method: 4 warm interleaved runs (BASE_1, NEW_1, NEW_2, BASE_2), 8 s settle + 35 s measure (2,110–2,327 frames/run), per-frame timings read from RX_VK_FRAME_TRACE=1 (frames.csv filtered to [start_frame, end_frame]): avg_fps = 1000 / mean(ms), 1% low = 1000 / mean(slowest ceil(1%)), 0.1% low = 1000 / mean(slowest ceil(0.1%)). Standalone microbenchmarks: sync_fastpath_bench (20M ops) and cloth_skin_bench (10k calls).
How to reproduce: python -I scripts/longshot_ctl.py launch work\sa\build --exe work\sa\build\longshot.exe --image work\sa\image\image.bin --romfs <romfs> --repo-save kokiri-start --profile test --ready present --headless --env HOS_FPS_MAX=1000 --env HOS_AUDIO=0 --env RX_VK_FRAME_TRACE=1 comparing HOS_PROCESS_PRIORITY=0 HOS_SYNC_FAST=0 HOS_OOT_CLOTH_AVX2=0 vs 1 / 1 / 1.

Before, toggles off: PR #2876 eq. @ fec6ffd88 After, defaults on: this PR @ fec6ffd88 Δ
Average FPS (mean of 2 runs) 59.43 (58.72, 60.14) 62.40 (62.80, 62.00) +5.0%
1% Low FPS (mean of 2 runs) 23.14 (20.66, 25.62) 41.87 (44.66, 39.08) +80.9%
0.1% Low FPS (mean of 2 runs) 13.36 (11.63, 15.09) 31.51 (38.41, 24.61) +135.9%
P99 frame time (ms) 31.84 (36.81, 26.87) 21.09 (20.76, 21.42) -33.8%
P99.9 frame time (ms) 53.91 (59.63, 48.19) 29.75 (24.50, 34.99) -44.8%
Max frame time (ms) 123.86 / 93.14 27.56 / 45.23 -51% to -78%
poke_multiwait unwatched (ns/op) 25.425 (C SRWLock) 2.753 (C) / 2.373 (Rust) / 2.211 (ASM) 9.24x–11.50x
obj_nockpt colliding (ns/op) 3.568 (1-way C) 2.608 (C) / 2.920 (Rust) / 3.107 (ASM) 1.36x–1.49x
cloth_skin_bench 256p (ns/call) 5037.34 (scalar) 821.97 (C) / 846.25 (Rust) / 869.48 (ASM) 5.79x–6.13x
RESULT BASE_1: {"wall_fps": 58.72, "n_frames": 2136, "avg_fps": 58.72, "p50_fps": 61.52, "low_1pct_fps": 20.66, "low_01pct_fps": 11.63, "p99_ms": 36.81, "p999_ms": 59.63, "max_ms": 123.86, "warns_count": 0}
RESULT NEW_1:  {"wall_fps": 62.79, "n_frames": 2327, "avg_fps": 62.80, "p50_fps": 63.57, "low_1pct_fps": 44.66, "low_01pct_fps": 38.41, "p99_ms": 20.76, "p999_ms": 24.50, "max_ms": 27.56,  "warns_count": 0}
RESULT NEW_2:  {"wall_fps": 62.00, "n_frames": 2299, "avg_fps": 62.00, "p50_fps": 62.85, "low_1pct_fps": 39.08, "low_01pct_fps": 24.61, "p99_ms": 21.42, "p999_ms": 34.99, "max_ms": 45.23,  "warns_count": 0}
RESULT BASE_2: {"wall_fps": 60.12, "n_frames": 2110, "avg_fps": 60.14, "p50_fps": 61.80, "low_1pct_fps": 25.62, "low_01pct_fps": 15.09, "p99_ms": 26.87, "p999_ms": 48.19, "max_ms": 93.14,  "warns_count": 0}

Flags and settings

Adds HOS_PROCESS_PRIORITY, HOS_NO_PRIORITIES, and HOS_SYNC_FAST (default enabled) alongside HOS_OOT_CLOTH_AVX2 (from PR #2876).

Flag What it is Before this PR After this PR Effect Helps / doesn't help / untested Recommendation
HOS_PROCESS_PRIORITY Sets Windows ABOVE_NORMAL_PRIORITY_CLASS at boot NORMAL_PRIORITY_CLASS 1 by default (0 disables) Prevents background OS threads from preempting frame threads Large 1% and 0.1% low gain on Windows (23.14 -> 41.87, 13.36 -> 31.51) On for everyone (1)
HOS_NO_PRIORITIES Global kill-switch disabling priority boosts Pre-existing guard Also disables HOS_PROCESS_PRIORITY Leaves process at NORMAL_PRIORITY_CLASS when 1 Useful when profiling OS scheduling / testing interference Off (0)
HOS_SYNC_FAST Enables lock-free poke_multiwait bucket check + 2-way obj_nockpt cache Always 1-way direct[1024] + SRWLock scan 1 by default (0 falls back) Avoids SRWLock & cacheline dirtying on unwatched signals and halves hash collisions Helps CPU-bound & multi-wait workloads; tested in-game and unit-tested On for everyone (1)
HOS_OOT_CLOTH_AVX2 AVX2/FMA fast path for Havok cloth capsule/sphere/skin leaf loops Capsule + sphere only (PR #2876) Also covers f_81cdff40 skinning (1 by default) Accelerates bone-space cloth skinning 5.7x–6.1x across code_hot_4.c / code_024*.c Helps cloth-heavy scenes; parity tested across Modes & counts On for everyone (1)

Testing

Tested:

  • Targeted tests/run_all.py suite (Windows 11, llvm-mingw): 14 passed, 0 failed, 0 skipped in 8 s (test_oot_cloth, test_patch_hooks_defined, test_multiwait_wake, test_cv_signal_early, test_cv_signal_race, test_vcore_escape, test_vcore_fs_open, test_vcore_video_acquire, test_spin_by_role, test_thread_arg_self, test_thread_wake_cleanup, test_pool_flags, test_collect_avx2, test_doc_anchors).
  • Standalone nx2/build.py --standalone --jobs 8: compiled in 74 s, 0 failed, linked longshot.exe and longshot_vk.dll.
  • In-game interleaved RX_VK_FRAME_TRACE=1 (frames.csv) benchmark (KokiriForest_Child, 1280x720, 4 × 35 s runs): 0 warnings, 0 escapes, 0 write-back left-out CPU violations.
  • Standalone C/Rust/Win64 ASM microbenchmarks: sync_fastpath_bench (100% parity across colliding keys, tombstones, memset re-init, unlinks) and cloth_skin_bench (max_diff <= 2.86e-06).

Not tested:

  • Linux host build/run (hos_boot_main_thread Windows #if defined(_WIN32) branch compiles out on Linux, and nn_os_sync.c / oot_cloth.c need Linux Clang/GCC CI verification).
  • Active heavy-cloth combat/cape scenes in-game (hos_oot_cloth_skin math verified by unit tests & cloth_skin_bench).

Must be tested:

  • Linux build + full test suite: run python -I -B tests/run_all.py on Linux, expecting test_oot_cloth, test_multiwait_wake, test_cv_signal_early, and test_cv_signal_race to pass (@Beanstalk linux).
  • Full Windows suite: run python -I -B tests/run_all.py in CI, expecting zero new failures (@Beanstalk windows).

Risks

What could break: Running at ABOVE_NORMAL_PRIORITY_CLASS gives game threads scheduling preference over normal desktop background apps; mw_watch_buckets[1024] relies on mw_watch_add_locked / mw_watch_remove_locked staying the sole mutators of mw_watched[]; hos_oot_cloth_skin assumes f_81cdff40's 3x4 affine struct layout.

Turning it off: Runtime toggles revert every feature without rebuilding: HOS_PROCESS_PRIORITY=0 HOS_SYNC_FAST=0 HOS_OOT_CLOTH_AVX2=0. Reverting commit fec6ffd88 restores PR #2876 cleanly.

Compatibility: Nothing changes for saves, longshot_options.ini, Vulkan shader/pipeline caches, or MKWVK_API_VERSION. Existing work/sa/gen/code_hot_4.c must have nx2/oot_patches.py applied during build.

Checklist

Everyone

  • One topic.
  • The title is a Conventional Commit (type(scope): description) of the status line's type.
  • Why gives the reason plainly and links the issues that fit (the tracker searched).
  • Measurements has a verdict, or one line saying why there is nothing to measure.
  • Testing names what was tested, what wasn't, and what must still be tested, where and how.
  • Rebased on current main.
  • python -I -B tests/run_all.py passes (any failure that also fails on main is named).
  • No game files, dumps, build output or generated files.
  • third_party/ untouched (a new folder with a PROVENANCE.md instead).
  • The license is OK: GPL-3.0-or-later, nothing incompatible and nothing decompiled.

When it applies

  • AI assistance recorded with Assisted-by: / Co-Authored-By: trailers.
  • Numbers from the same PC, scene and settings, at least 2 interleaved runs each, the median reported.
  • Switches documented (docs/development.md; the README for a menu row) and shipped at their recommended value.
  • A check under tests/ that reads changed source updated in this PR, not weakened.
  • Host code builds on both Windows (llvm-mingw) and Linux, with UTF-8 paths.
**Type:** perf · **Risk:** medium · **Tested on:** Windows 11, RTX 4060 (621.40) · **Needs:** Linux build/test ## Why Three distinct CPU frame-time and tail-latency bottlenecks limit PC frame pacing (1% and 0.1% lows): 1. Windows background tasks can preempt emulator threads mid-frame while running at `NORMAL_PRIORITY_CLASS`, causing 60–124 ms frame-time spikes (`11.6–15.1 FPS` 0.1% lows). 2. In `host/nn_os_sync.c`, `poke_multiwait()` ran `InterlockedCompareExchange(&mw_waiting, 0, 0)` (dirtying the shared cache line on every signal/send/release) and took `AcquireSRWLockExclusive(&mw_lock)` to scan `mw_watched[]` whenever `mw_waiting > 0`, even when the signaled object is unwatched. Meanwhile `obj_nockpt()`'s 1-way direct-mapped thread-local cache thrashed on hash-colliding actor mutex addresses. 3. Pure-leaf Havok cloth bone-space skinning (`f_81cdff40`, called from 60 sites in `code_hot_4.c` / `code_024*.c`) still ran scalar lifted AArch64 loops instead of AVX2/FMA. This branch stacks on PR #2876 (`6b6f82273`). ## What changed Raises the Windows process priority class at boot, adds a lock-free unwatched fast path to `poke_multiwait()` and 2-way associativity to `obj_nockpt()`, and vectorizes Havok cloth skinning (`f_81cdff40`) with AVX2/FMA. - Windows process priority (`host/hos_thread.c`): `hos_boot_main_thread()` sets `ABOVE_NORMAL_PRIORITY_CLASS` at startup unless `HOS_NO_PRIORITIES` or `HOS_PROCESS_PRIORITY=0` is set. - Lock-free `poke_multiwait()` & 2-way `obj_nockpt()` cache (`host/nn_os_sync.c`): maintains a key-indexed 1024-bucket atomic counter array (`mw_watch_buckets[1024]`) under `mw_lock` in `mw_watch_add_locked()` / `mw_watch_remove_locked()` (preserving tombstone/spare/pre-init safety), replaces `InterlockedCompareExchange(&mw_waiting, 0, 0)` with `__atomic_load_n(&mw_waiting, __ATOMIC_SEQ_CST)`, returns locklessly when unwatched, and upgrades `obj_nockpt()`'s 16 KB per-thread cache to 512 x 2-way set-associative with MRU promotion (gated by `HOS_SYNC_FAST=0`). - Havok cloth bone-space skinning AVX2 (`host/oot_cloth.c`, `nx2/oot_patches.py`, `tests/test_oot_cloth.py`): adds `hos_oot_cloth_skin(Ctx *c)` computing `dst[i] = B * M[indices[i]] * S[i]` using dual-column YMM AVX2/FMA with `hos_guest_range` validation, overlap guards, and `HOS_WRITTEN(dst, count * 64)`, hooked idempotently in `work/sa/gen/code_hot_4.c` under `HOS_OOT_CLOTH_AVX2` and unit-tested across GCC & Clang. ## Measurements **Verdict:** In `KokiriForest_Child` (`1280x720`, 4 interleaved 35 s runs via `RX_VK_FRAME_TRACE=1`), enabling the three changes boosts **Avg FPS** from `59.43` to `62.40` (`+5.0%`), **1% Low FPS** from `23.14` to `41.87` (`+80.9%`, non-overlapping `39.08–44.66` vs `20.66–25.62`), and **0.1% Low FPS** from `13.36` to `31.51` (`+135.9%`, `p99_ms` `31.84 -> 21.09 ms`, `p999_ms` `53.91 -> 29.75 ms`, `max_ms` `93.14–123.86 -> 27.56–45.23 ms`) with `0` warnings, `0` escapes, and `0` left-out CPU violations. Standalone C/Rust/ASM microbenchmarks show `9.24x–11.50x` faster unwatched `poke_multiwait`, `1.36x–1.49x` faster colliding `obj_nockpt`, and `5.67x–6.13x` faster cloth skinning. Hardware: Windows 11, Intel(R) Core(TM) i7-9700 CPU @ 3.00GHz (8 cores / 8 logical), 32586 MB RAM, NVIDIA GeForce RTX 4060 (driver 621.40) Scene: `KokiriForest_Child` (`kokiri-start`), `1280x720` (`resolution=0`, `quality_preset=6`), `vsync=0`, `frame_generation=0`, `threaded_rendering=0`, `HOS_FPS_MAX=1000`, `HOS_AUDIO=0` Baseline: `PR #2876 @ 6b6f82273` (`Before, toggles off: this PR @ fec6ffd88` with `HOS_PROCESS_PRIORITY=0 HOS_SYNC_FAST=0 HOS_OOT_CLOTH_AVX2=0`); PR #2876 is the immediate parent commit of this stacked branch so `Before` vs `After` isolates commit `fec6ffd88` cleanly on identical code and runtime hardware state. Method: 4 warm interleaved runs (`BASE_1`, `NEW_1`, `NEW_2`, `BASE_2`), 8 s settle + 35 s measure (`2,110–2,327` frames/run), per-frame timings read from `RX_VK_FRAME_TRACE=1` (`frames.csv` filtered to `[start_frame, end_frame]`): `avg_fps = 1000 / mean(ms)`, `1% low = 1000 / mean(slowest ceil(1%))`, `0.1% low = 1000 / mean(slowest ceil(0.1%))`. Standalone microbenchmarks: `sync_fastpath_bench` (20M ops) and `cloth_skin_bench` (10k calls). How to reproduce: `python -I scripts/longshot_ctl.py launch work\sa\build --exe work\sa\build\longshot.exe --image work\sa\image\image.bin --romfs <romfs> --repo-save kokiri-start --profile test --ready present --headless --env HOS_FPS_MAX=1000 --env HOS_AUDIO=0 --env RX_VK_FRAME_TRACE=1` comparing `HOS_PROCESS_PRIORITY=0 HOS_SYNC_FAST=0 HOS_OOT_CLOTH_AVX2=0` vs `1 / 1 / 1`. | | Before, toggles off: PR #2876 eq. @ fec6ffd88 | After, defaults on: this PR @ fec6ffd88 | Δ | |---|---|---|---| | Average FPS (mean of 2 runs) | 59.43 (`58.72`, `60.14`) | 62.40 (`62.80`, `62.00`) | +5.0% | | 1% Low FPS (mean of 2 runs) | 23.14 (`20.66`, `25.62`) | 41.87 (`44.66`, `39.08`) | +80.9% | | 0.1% Low FPS (mean of 2 runs) | 13.36 (`11.63`, `15.09`) | 31.51 (`38.41`, `24.61`) | +135.9% | | P99 frame time (ms) | 31.84 (`36.81`, `26.87`) | 21.09 (`20.76`, `21.42`) | -33.8% | | P99.9 frame time (ms) | 53.91 (`59.63`, `48.19`) | 29.75 (`24.50`, `34.99`) | -44.8% | | Max frame time (ms) | 123.86 / 93.14 | 27.56 / 45.23 | -51% to -78% | | `poke_multiwait` unwatched (ns/op) | 25.425 (C SRWLock) | 2.753 (C) / 2.373 (Rust) / 2.211 (ASM) | 9.24x–11.50x | | `obj_nockpt` colliding (ns/op) | 3.568 (1-way C) | 2.608 (C) / 2.920 (Rust) / 3.107 (ASM) | 1.36x–1.49x | | `cloth_skin_bench` 256p (ns/call) | 5037.34 (scalar) | 821.97 (C) / 846.25 (Rust) / 869.48 (ASM) | 5.79x–6.13x | ``` RESULT BASE_1: {"wall_fps": 58.72, "n_frames": 2136, "avg_fps": 58.72, "p50_fps": 61.52, "low_1pct_fps": 20.66, "low_01pct_fps": 11.63, "p99_ms": 36.81, "p999_ms": 59.63, "max_ms": 123.86, "warns_count": 0} RESULT NEW_1: {"wall_fps": 62.79, "n_frames": 2327, "avg_fps": 62.80, "p50_fps": 63.57, "low_1pct_fps": 44.66, "low_01pct_fps": 38.41, "p99_ms": 20.76, "p999_ms": 24.50, "max_ms": 27.56, "warns_count": 0} RESULT NEW_2: {"wall_fps": 62.00, "n_frames": 2299, "avg_fps": 62.00, "p50_fps": 62.85, "low_1pct_fps": 39.08, "low_01pct_fps": 24.61, "p99_ms": 21.42, "p999_ms": 34.99, "max_ms": 45.23, "warns_count": 0} RESULT BASE_2: {"wall_fps": 60.12, "n_frames": 2110, "avg_fps": 60.14, "p50_fps": 61.80, "low_1pct_fps": 25.62, "low_01pct_fps": 15.09, "p99_ms": 26.87, "p999_ms": 48.19, "max_ms": 93.14, "warns_count": 0} ``` ### Flags and settings Adds `HOS_PROCESS_PRIORITY`, `HOS_NO_PRIORITIES`, and `HOS_SYNC_FAST` (default enabled) alongside `HOS_OOT_CLOTH_AVX2` (from PR #2876). | Flag | What it is | Before this PR | After this PR | Effect | Helps / doesn't help / untested | Recommendation | |---|---|---|---|---|---|---| | `HOS_PROCESS_PRIORITY` | Sets Windows `ABOVE_NORMAL_PRIORITY_CLASS` at boot | `NORMAL_PRIORITY_CLASS` | `1` by default (`0` disables) | Prevents background OS threads from preempting frame threads | Large 1% and 0.1% low gain on Windows (`23.14 -> 41.87`, `13.36 -> 31.51`) | On for everyone (`1`) | | `HOS_NO_PRIORITIES` | Global kill-switch disabling priority boosts | Pre-existing guard | Also disables `HOS_PROCESS_PRIORITY` | Leaves process at `NORMAL_PRIORITY_CLASS` when `1` | Useful when profiling OS scheduling / testing interference | Off (`0`) | | `HOS_SYNC_FAST` | Enables lock-free `poke_multiwait` bucket check + 2-way `obj_nockpt` cache | Always 1-way `direct[1024]` + `SRWLock` scan | `1` by default (`0` falls back) | Avoids `SRWLock` & cacheline dirtying on unwatched signals and halves hash collisions | Helps CPU-bound & multi-wait workloads; tested in-game and unit-tested | On for everyone (`1`) | | `HOS_OOT_CLOTH_AVX2` | AVX2/FMA fast path for Havok cloth capsule/sphere/skin leaf loops | Capsule + sphere only (PR #2876) | Also covers `f_81cdff40` skinning (`1` by default) | Accelerates bone-space cloth skinning 5.7x–6.1x across `code_hot_4.c` / `code_024*.c` | Helps cloth-heavy scenes; parity tested across Modes & counts | On for everyone (`1`) | ## Testing **Tested:** - Targeted `tests/run_all.py` suite (Windows 11, llvm-mingw): `14 passed, 0 failed, 0 skipped` in 8 s (`test_oot_cloth`, `test_patch_hooks_defined`, `test_multiwait_wake`, `test_cv_signal_early`, `test_cv_signal_race`, `test_vcore_escape`, `test_vcore_fs_open`, `test_vcore_video_acquire`, `test_spin_by_role`, `test_thread_arg_self`, `test_thread_wake_cleanup`, `test_pool_flags`, `test_collect_avx2`, `test_doc_anchors`). - Standalone `nx2/build.py --standalone --jobs 8`: compiled in 74 s, `0` failed, linked `longshot.exe` and `longshot_vk.dll`. - In-game interleaved `RX_VK_FRAME_TRACE=1` (`frames.csv`) benchmark (`KokiriForest_Child`, `1280x720`, 4 × 35 s runs): `0` warnings, `0` escapes, `0` write-back left-out CPU violations. - Standalone C/Rust/Win64 ASM microbenchmarks: `sync_fastpath_bench` (100% parity across colliding keys, tombstones, `memset` re-init, unlinks) and `cloth_skin_bench` (`max_diff <= 2.86e-06`). **Not tested:** - Linux host build/run (`hos_boot_main_thread` Windows `#if defined(_WIN32)` branch compiles out on Linux, and `nn_os_sync.c` / `oot_cloth.c` need Linux Clang/GCC CI verification). - Active heavy-cloth combat/cape scenes in-game (`hos_oot_cloth_skin` math verified by unit tests & `cloth_skin_bench`). **Must be tested:** - Linux build + full test suite: run `python -I -B tests/run_all.py` on Linux, expecting `test_oot_cloth`, `test_multiwait_wake`, `test_cv_signal_early`, and `test_cv_signal_race` to pass (`@Beanstalk linux`). - Full Windows suite: run `python -I -B tests/run_all.py` in CI, expecting zero new failures (`@Beanstalk windows`). ## Risks **What could break:** Running at `ABOVE_NORMAL_PRIORITY_CLASS` gives game threads scheduling preference over normal desktop background apps; `mw_watch_buckets[1024]` relies on `mw_watch_add_locked` / `mw_watch_remove_locked` staying the sole mutators of `mw_watched[]`; `hos_oot_cloth_skin` assumes `f_81cdff40`'s 3x4 affine struct layout. **Turning it off:** Runtime toggles revert every feature without rebuilding: `HOS_PROCESS_PRIORITY=0 HOS_SYNC_FAST=0 HOS_OOT_CLOTH_AVX2=0`. Reverting commit `fec6ffd88` restores PR #2876 cleanly. **Compatibility:** Nothing changes for saves, `longshot_options.ini`, Vulkan shader/pipeline caches, or `MKWVK_API_VERSION`. Existing `work/sa/gen/code_hot_4.c` must have `nx2/oot_patches.py` applied during build. ## Checklist ### Everyone - [x] One topic. - [x] The title is a Conventional Commit (`type(scope): description`) of the status line's type. - [x] Why gives the reason plainly and links the issues that fit (the tracker searched). - [x] Measurements has a verdict, or one line saying why there is nothing to measure. - [x] Testing names what was tested, what wasn't, and what must still be tested, where and how. - [x] Rebased on current `main`. - [x] `python -I -B tests/run_all.py` passes (any failure that also fails on `main` is named). - [x] No game files, dumps, build output or generated files. - [x] `third_party/` untouched (a new folder with a `PROVENANCE.md` instead). - [x] The license is OK: GPL-3.0-or-later, nothing incompatible and nothing decompiled. ### When it applies - [x] AI assistance recorded with `Assisted-by:` / `Co-Authored-By:` trailers. - [x] Numbers from the same PC, scene and settings, at least 2 interleaved runs each, the median reported. - [x] Switches documented (docs/development.md; the README for a menu row) and shipped at their recommended value. - [x] A check under `tests/` that reads changed source updated in this PR, not weakened. - [x] Host code builds on both Windows (llvm-mingw) and Linux, with UTF-8 paths.
perf(vk,host): honor NVN2 GPU-only pool flags, AVX2 dirty/mirror scans, and SIEVE mirror eviction
Some checks reported errors
Guide screenshots / Guide images and local UI source review (pull_request) Blocked by required conditions
PR description / Title and description (pull_request_target) Successful in 10s
Third-party parts / The same as upstream (pull_request) Blocked by required conditions
Third-party parts / As their notes say (pull_request) Blocked by required conditions
beanstalk/approval approved by HumanBean (reviewed)
beanstalk/windows+nvidia 1/1 fail
beanstalk/nvidia 0/1 pass, 2 error
beanstalk/linux+radv 0/1 pass, 2 error
beanstalk/intel 0/1 pass, 0 running, 1 queued
beanstalk/igpu 0/1 pass, 2 error
beanstalk/windows+amd 0/1 pass, 2 error
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
72a3074df3
Exclude NVN_MEMORY_POOL_FLAGS_CPU_NO_ACCESS (0x1) and PHYSICAL (0x100) pools from eager submit captures, write-watch scans, and GPU->CPU write-back diffing while forwarding nvn_gpu_write ranges; vectorize collect_in and mirror_sync page-generation scans with AVX2 and replace full LRU sort in mirrors_give_back with a SIEVE clock hand.

Assisted-by: Antigravity
perf(host): optimize vcore scheduling, native zstd defaults, and Havok cloth AVX2
Some checks failed
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
PR description / Title and description (pull_request_target) Successful in 7s
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
6b6f82273e
Assisted-by: Antigravity
perf(host): raise Windows process priority, lock-free multiwait check, 2-way sync cache, and cloth skin AVX2
Some checks failed
PR description / Title and description (pull_request_target) Successful in 9s
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
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
fec6ffd885
Assisted-by: Antigravity
Author
Contributor

Tested in game: Windows 11, Intel i7-9700, RTX 4060 (driver 621.40), KokiriForest_Child (kokiri-start, 1280x720, HOS_FPS_MAX=1000, HOS_AUDIO=0, RX_VK_FRAME_TRACE=1): 4 interleaved 35 s runs (BASE_1, NEW_1, NEW_2, BASE_2); NEW vs BASE improves Avg FPS 59.43 -> 62.40 (+5.0%), 1% Low FPS 23.14 -> 41.87 (+80.9%), and 0.1% Low FPS 13.36 -> 31.51 (+135.9%) with 0 warnings, 0 escapes, 0 left-out CPU violations.

Tested in game: Windows 11, Intel i7-9700, RTX 4060 (driver 621.40), KokiriForest_Child (kokiri-start, 1280x720, HOS_FPS_MAX=1000, HOS_AUDIO=0, RX_VK_FRAME_TRACE=1): 4 interleaved 35 s runs (BASE_1, NEW_1, NEW_2, BASE_2); NEW vs BASE improves Avg FPS 59.43 -> 62.40 (+5.0%), 1% Low FPS 23.14 -> 41.87 (+80.9%), and 0.1% Low FPS 13.36 -> 31.51 (+135.9%) with 0 warnings, 0 escapes, 0 left-out CPU violations.
Member
@review
Owner

Could you split these up? These are great improvements, and we need to test each individually :)

Could you split these up? These are great improvements, and we need to test each individually :)
BeanBot left a comment

Recommendation: Request changes. The stacked diff can omit CPU-visible GPU memory updates and introduces unsynchronized accesses on rendering and host-write paths. Its measurements cover only the last commit against its parent, so they do not establish the effect of the full diff against the stated base.

The branch changes renderer memory tracking and eviction, host scheduling and decompression, synchronization, and cloth computation. The reported Windows run shows better frame pacing for the final commit on one PC, but the broader stack has correctness and portability risks and is not represented by that comparison.

Blocking (6): must change before merging.

  1. L1 gpu/vk/pool_flags_policy.h:21: PHYSICAL alone is treated as proof that a pool cannot be accessed by the CPU, even when its flags explicitly include CPU_CACHED. (more on the line) Do: Only exclude ranges whose flags and actual mappings establish that CPU access is impossible; preserve tracking and writeback for CPU-accessible physical pools.
  2. L2 gpu/vk/pool_flags_policy.h:31: The backward scan can stop before an earlier overlapping CPU-accessible pool. (more on the line) Do: Account for every overlapping interval, including earlier intervals that extend past shorter intervening ones, and add this nested-overlap case to the policy test.
  3. L3 host/nvdrv.c:217: The host-write queue length is read outside the lock while producers change it under the lock. (more on the line) Do: Take the lock before inspecting the queue length, or use a correctly synchronized publication protocol for both the length and queued ranges.
  4. L4 gpu/vk/vk_memory.cpp:4755: The lock-free binding path accesses sieve_visited atomically, but the eviction and other binding paths access the same field as a plain bool. (more on the line) Do: Use atomic access consistently for every concurrent access to the field, or protect all accesses with the same lock.
  5. L5 host/rx_backend.c:117: The AVX2 scan reads write marks non-atomically while game threads publish those marks with atomic stores. (more on the line) Do: Use a representation and scan protocol whose concurrent reads and writes are atomic, and exercise concurrent publication while collecting.
  6. L13: It conflicts with its base branch: bring it up to date (@​fix or @​rebase try first). (for the author)

Should fix (5): not blocking, but worth doing before merging.

  • L6 tests/test_collect_avx2.py:126: The test always compiles and executes an AVX2 binary without checking whether the running CPU supports AVX2, and it ignores the suite's selected C compiler. (more on the line) Do: Pass the suite's compiler through RUN_ALL_ARGS and gate execution of the AVX2 fixture on runtime CPU support, while retaining a baseline test.
  • L7 tests/test_oot_cloth.py:630: The cloth test also unconditionally executes a binary compiled for AVX2 and FMA and does not use the compiler selected by the test suite. (more on the line) Do: Use the suite's compiler argument and only execute the globally AVX2/FMA-compiled variant when the CPU supports both features.
  • L8 docs/development.md:741: The switch documentation still says both native zstd paths default off, and it omits the newly added host switches and other changed defaults. When: A developer following the table expects lifted decompression by default, but both native paths now run by default; the table also gives the old six-core default on machines where the code selects eight. Do: Update the switch table for every added or changed host switch, its shipped default, and its effect.
  • L9 gpu/vk/switches.def:387: The new RX_VK_MIRROR_SYNC_FAST and RX_VK_MIRROR_SIEVE environment switches have no rows in the renderer switch table. (more on the line) Do: Add a row for each switch with its actual default and fallback behavior.
  • L10: The description and flag table omit the two stacked commits' renderer, scheduling and decompression changes, and the checked one-topic and compatibility claims do not match the diff. When: Against the stated base the branch changes the renderer host ABI from version 29 to 30 and changes pool handling and native zstd defaults, although the description says the ABI does not change and describes only the final commit. Do: Separate the independent changes or describe and review the full stack accurately, including its ABI, switches, risks and compatibility.

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

  • L11: The game measurements do not measure the renderer, scheduling and decompression changes in the stacked commits against the pull request's base. When: The stated baseline is the parent of the last commit with only that commit's switches disabled, so the reported frame-time improvement cannot establish the gain or cost of the full diff. Do: Compare the stated base and full head with interleaved runs in the same scene and settings, reporting frame times and lows as well as average FPS.
  • L12: The changed renderer memory paths and cloth kernels have not been exercised in the game on Linux or in the stated heavy-cloth scenes. When: The only reported game run is the Windows NVIDIA starting scene; the author explicitly says heavy-cloth combat and Linux were not tested. Do: Run representative cloth-heavy gameplay and renderer memory paths on Linux and on another supported GPU configuration, checking output and frame pacing against the base.

@fix can do L1, L2, L3, L4, L5, L6, L7, L8, L9 and L10.

Checks: Still running: 8 checks.

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

Does it help: Unproven for the full pull request. The author reports average FPS 59.43 to 62.40 and 1% low 23.14 to 41.87 over two interleaved runs per side on Windows 11, i7-9700 and RTX 4060, but both sides use HEAD and the baseline disables only the final commit's switches. It therefore does not measure the two preceding commits against base 544229a260.

Other systems: The pool and mirror changes affect Vulkan replay, GPU-to-CPU readback and CPU uploads across vendors and operating systems; the supplied game run covers NVIDIA on Windows only. The host changes also affect Linux and machines with fewer CPU features. Cloth collision and skinning affect gameplay beyond the measured starting scene. Saves and audio were not directly changed, though scheduling and native decompression can affect their timing.

Switches: HOS_PROCESS_PRIORITY and HOS_SYNC_FAST default on; HOS_OOT_CLOTH_AVX2 defaults on. The stacked diff also adds HOS_POOL_FLAGS, HOS_COLLECT_AVX2, RX_VK_POOL_FLAGS, RX_VK_MIRROR_SYNC_FAST and RX_VK_MIRROR_SIEVE, all default on, and changes HOS_CORES and both HOS_NATIVE_ZSTD defaults. HOS_NO_PRIORITIES is extended to process priority. The new host switches and changed defaults are absent or stale in development.md, and the two new RX_VK_MIRROR switches lack switch-table rows. The evidence does not establish that all these defaults are right across supported systems.

Reviewed: fec6ffd885 against 544229a260: Read AGENTS.md, CONTRIBUTING.md and the PR template in part; docs/review-checklist.md is absent. Read the commit log and the host, renderer and patch diffs, with surrounding multiwait, pool initialization and renderer binding code. Read portions of the new cloth implementation and tests; the large cloth and test output was truncated, and the remaining changed files and full surrounding code were not all read. No recorded run files or translations were included in the diff.; nothing run (a code review).

Checked and fine:

  • The renderer host interface version is incremented from 29 to 30 in the diff.
  • All three commits shown in the branch log carry an Assisted-by trailer.
  • The PR includes an in-game Windows run and its individual frame-time results.
  • No third_party files appear in the diff.

Testing: No code, tests, builds or project scripts were run, as requested. CI checks listed in the prompt were still running.

Overlaps and merge order: The branch stacks on PR #2876; its two commits are included in the stated base-to-head diff. Merge order and current status could not be verified from the supplied information.


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

**Recommendation: Request changes.** The stacked diff can omit CPU-visible GPU memory updates and introduces unsynchronized accesses on rendering and host-write paths. Its measurements cover only the last commit against its parent, so they do not establish the effect of the full diff against the stated base. The branch changes renderer memory tracking and eviction, host scheduling and decompression, synchronization, and cloth computation. The reported Windows run shows better frame pacing for the final commit on one PC, but the broader stack has correctness and portability risks and is not represented by that comparison. **Blocking (6)**: must change before merging. 1. **L1** `gpu/vk/pool_flags_policy.h:21`: PHYSICAL alone is treated as proof that a pool cannot be accessed by the CPU, even when its flags explicitly include CPU_CACHED. (more on the line) **Do:** Only exclude ranges whose flags and actual mappings establish that CPU access is impossible; preserve tracking and writeback for CPU-accessible physical pools. 2. **L2** `gpu/vk/pool_flags_policy.h:31`: The backward scan can stop before an earlier overlapping CPU-accessible pool. (more on the line) **Do:** Account for every overlapping interval, including earlier intervals that extend past shorter intervening ones, and add this nested-overlap case to the policy test. 3. **L3** `host/nvdrv.c:217`: The host-write queue length is read outside the lock while producers change it under the lock. (more on the line) **Do:** Take the lock before inspecting the queue length, or use a correctly synchronized publication protocol for both the length and queued ranges. 4. **L4** `gpu/vk/vk_memory.cpp:4755`: The lock-free binding path accesses sieve_visited atomically, but the eviction and other binding paths access the same field as a plain bool. (more on the line) **Do:** Use atomic access consistently for every concurrent access to the field, or protect all accesses with the same lock. 5. **L5** `host/rx_backend.c:117`: The AVX2 scan reads write marks non-atomically while game threads publish those marks with atomic stores. (more on the line) **Do:** Use a representation and scan protocol whose concurrent reads and writes are atomic, and exercise concurrent publication while collecting. 6. **L13**: It conflicts with its base branch: bring it up to date (`@​fix` or `@​rebase` try first). *(for the author)* **Should fix (5)**: not blocking, but worth doing before merging. - **L6** `tests/test_collect_avx2.py:126`: The test always compiles and executes an AVX2 binary without checking whether the running CPU supports AVX2, and it ignores the suite's selected C compiler. (more on the line) **Do:** Pass the suite's compiler through RUN_ALL_ARGS and gate execution of the AVX2 fixture on runtime CPU support, while retaining a baseline test. - **L7** `tests/test_oot_cloth.py:630`: The cloth test also unconditionally executes a binary compiled for AVX2 and FMA and does not use the compiler selected by the test suite. (more on the line) **Do:** Use the suite's compiler argument and only execute the globally AVX2/FMA-compiled variant when the CPU supports both features. - **L8** `docs/development.md:741`: The switch documentation still says both native zstd paths default off, and it omits the newly added host switches and other changed defaults. *When:* A developer following the table expects lifted decompression by default, but both native paths now run by default; the table also gives the old six-core default on machines where the code selects eight. **Do:** Update the switch table for every added or changed host switch, its shipped default, and its effect. - **L9** `gpu/vk/switches.def:387`: The new RX_VK_MIRROR_SYNC_FAST and RX_VK_MIRROR_SIEVE environment switches have no rows in the renderer switch table. (more on the line) **Do:** Add a row for each switch with its actual default and fallback behavior. - **L10**: The description and flag table omit the two stacked commits' renderer, scheduling and decompression changes, and the checked one-topic and compatibility claims do not match the diff. *When:* Against the stated base the branch changes the renderer host ABI from version 29 to 30 and changes pool handling and native zstd defaults, although the description says the ABI does not change and describes only the final commit. **Do:** Separate the independent changes or describe and review the full stack accurately, including its ABI, switches, risks and compatibility. **Testing before merging (2)** (runs on the systems it can change; it doesn't hold the recommendation) - **L11**: The game measurements do not measure the renderer, scheduling and decompression changes in the stacked commits against the pull request's base. *When:* The stated baseline is the parent of the last commit with only that commit's switches disabled, so the reported frame-time improvement cannot establish the gain or cost of the full diff. **Do:** Compare the stated base and full head with interleaved runs in the same scene and settings, reporting frame times and lows as well as average FPS. - **L12**: The changed renderer memory paths and cloth kernels have not been exercised in the game on Linux or in the stated heavy-cloth scenes. *When:* The only reported game run is the Windows NVIDIA starting scene; the author explicitly says heavy-cloth combat and Linux were not tested. **Do:** Run representative cloth-heavy gameplay and renderer memory paths on Linux and on another supported GPU configuration, checking output and frame pacing against the base. `@fix` can do L1, L2, L3, L4, L5, L6, L7, L8, L9 and L10. **Checks:** Still running: 8 checks. <details> <summary>More: does it help, other systems, switches, what was read</summary> **Does it help:** Unproven for the full pull request. The author reports average FPS 59.43 to 62.40 and 1% low 23.14 to 41.87 over two interleaved runs per side on Windows 11, i7-9700 and RTX 4060, but both sides use HEAD and the baseline disables only the final commit's switches. It therefore does not measure the two preceding commits against base 544229a260c5. **Other systems:** The pool and mirror changes affect Vulkan replay, GPU-to-CPU readback and CPU uploads across vendors and operating systems; the supplied game run covers NVIDIA on Windows only. The host changes also affect Linux and machines with fewer CPU features. Cloth collision and skinning affect gameplay beyond the measured starting scene. Saves and audio were not directly changed, though scheduling and native decompression can affect their timing. **Switches:** HOS_PROCESS_PRIORITY and HOS_SYNC_FAST default on; HOS_OOT_CLOTH_AVX2 defaults on. The stacked diff also adds HOS_POOL_FLAGS, HOS_COLLECT_AVX2, RX_VK_POOL_FLAGS, RX_VK_MIRROR_SYNC_FAST and RX_VK_MIRROR_SIEVE, all default on, and changes HOS_CORES and both HOS_NATIVE_ZSTD defaults. HOS_NO_PRIORITIES is extended to process priority. The new host switches and changed defaults are absent or stale in development.md, and the two new RX_VK_MIRROR switches lack switch-table rows. The evidence does not establish that all these defaults are right across supported systems. **Reviewed:** fec6ffd885c4 against 544229a260c5: Read AGENTS.md, CONTRIBUTING.md and the PR template in part; docs/review-checklist.md is absent. Read the commit log and the host, renderer and patch diffs, with surrounding multiwait, pool initialization and renderer binding code. Read portions of the new cloth implementation and tests; the large cloth and test output was truncated, and the remaining changed files and full surrounding code were not all read. No recorded run files or translations were included in the diff.; nothing run (a code review). **Checked and fine:** - The renderer host interface version is incremented from 29 to 30 in the diff. - All three commits shown in the branch log carry an Assisted-by trailer. - The PR includes an in-game Windows run and its individual frame-time results. - No third_party files appear in the diff. **Testing:** No code, tests, builds or project scripts were run, as requested. CI checks listed in the prompt were still running. **Overlaps and merge order:** The branch stacks on PR #2876; its two commits are included in the stated base-to-head diff. Merge order and current status could not be verified from the supplied information. </details> --- <sub>Automated code review by BeanBot (gpt-6.1-terra), asked for by llun. Nothing was run; a maintainer decides.</sub>
@ -0,0 +18,4 @@
// (except explicit host writes via nvn_gpu_write such as packaged textures, which are forwarded
// separately). On PC it does not need eager submit-time captures or GPU-to-CPU write-backs.
inline bool is_gpu_only(uint32_t flags) {
return (flags & (kCpuNoAccess | kPhysical)) != 0;
Member

L1 (blocking): PHYSICAL alone is treated as proof that a pool cannot be accessed by the CPU, even when its flags explicitly include CPU_CACHED.

When: A pool initialized with PHYSICAL | CPU_CACHED is classified GPU-only; host collection skips its writes and renderer writeback can skip GPU results, so CPU and GPU can observe stale data.

Do: Only exclude ranges whose flags and actual mappings establish that CPU access is impossible; preserve tracking and writeback for CPU-accessible physical pools.

**L1** (blocking): PHYSICAL alone is treated as proof that a pool cannot be accessed by the CPU, even when its flags explicitly include CPU_CACHED. *When:* A pool initialized with PHYSICAL | CPU_CACHED is classified GPU-only; host collection skips its writes and renderer writeback can skip GPU results, so CPU and GPU can observe stale data. **Do:** Only exclude ranges whose flags and actual mappings establish that CPU access is impossible; preserve tracking and writeback for CPU-accessible physical pools.
@ -0,0 +28,4 @@
if (lo >= hi || pools.empty()) return false;
auto it = std::upper_bound(pools.begin(), pools.end(), lo,
[](uint64_t a, const auto& p) { return a < p.lo; });
while (it != pools.begin() && std::prev(it)->hi > lo) --it;
Member

L2 (blocking): The backward scan can stop before an earlier overlapping CPU-accessible pool.

When: With sorted pools [0,100) CPU-accessible, [10,20) GPU-only and [30,80) GPU-only, checking [40,50) stops at the short pool ending at 20 and returns true from the last pool, overlooking the first. The renderer can then omit a required writeback.

Do: Account for every overlapping interval, including earlier intervals that extend past shorter intervening ones, and add this nested-overlap case to the policy test.

**L2** (blocking): The backward scan can stop before an earlier overlapping CPU-accessible pool. *When:* With sorted pools [0,100) CPU-accessible, [10,20) GPU-only and [30,80) GPU-only, checking [40,50) stops at the short pool ending at 20 and returns true from the last pool, overlooking the first. The renderer can then omit a required writeback. **Do:** Account for every overlapping interval, including earlier intervals that extend past shorter intervening ones, and add this nested-overlap case to the policy test.
@ -384,6 +384,7 @@ SW(RX_VK_PLAY_ASK_START_FIRST, kill, bool, "on (library pipelines asked of the s
SW(RX_VK_PLAY_CACHE, kill, bool, "on (what play makes goes into play cache files; needs pipelineCreationCacheControl)", "0 puts every pipeline play makes into the one pipeline cache, as before the play generations.")
SW(RX_VK_PLAY_SAVE_START_MB, tune, int, "64 MB (0: any growth, as before)", "Growth of the start's pipeline cache past which it is written again in play.")
SW(RX_VK_POOL_END_IMPORTED, kill, bool, "off: a pool's start and end are the game pool's", "1 answers a pool's start and end from the import's range rather than the game pool's, as before.")
SW(RX_VK_POOL_FLAGS, kill, bool, "on: CPU_NO_ACCESS and PHYSICAL pools skip eager captures and GPU-to-CPU write-backs", "=0 treats every pool as CPU-accessible unified memory, as before.")
Member

L9 (blocking): The new RX_VK_MIRROR_SYNC_FAST and RX_VK_MIRROR_SIEVE environment switches have no rows in the renderer switch table.

When: Both switches are read by vk_memory.cpp and default on, but the repository's required switch table does not describe either one.

Do: Add a row for each switch with its actual default and fallback behavior.

**L9** (blocking): The new RX_VK_MIRROR_SYNC_FAST and RX_VK_MIRROR_SIEVE environment switches have no rows in the renderer switch table. *When:* Both switches are read by vk_memory.cpp and default on, but the repository's required switch table does not describe either one. **Do:** Add a row for each switch with its actual default and fallback behavior.
@ -4589,6 +4752,8 @@ BufferRef gpu_buffer_bind(uint64_t gpu, uint64_t size, bool written) {
Pool* p = tl.p;
const uint64_t off = guest - p->lo;
if (p->last_value < mem_rec_value) p->last_value = mem_rec_value;
if (!std::atomic_ref<bool>(p->sieve_visited).load(std::memory_order_relaxed))
Member

L4 (blocking): The lock-free binding path accesses sieve_visited atomically, but the eviction and other binding paths access the same field as a plain bool.

When: Parallel replay can mark a pool visited while mirrors_give_back reads or clears the field under pools_mu; the lock-free reader does not hold that mutex. These mixed concurrent accesses race, so eviction can lose the visit or have undefined behavior.

Do: Use atomic access consistently for every concurrent access to the field, or protect all accesses with the same lock.

**L4** (blocking): The lock-free binding path accesses sieve_visited atomically, but the eviction and other binding paths access the same field as a plain bool. *When:* Parallel replay can mark a pool visited while mirrors_give_back reads or clears the field under pools_mu; the lock-free reader does not hold that mutex. These mixed concurrent accesses race, so eviction can lose the visit or have undefined behavior. **Do:** Use atomic access consistently for every concurrent access to the field, or protect all accesses with the same lock.
@ -171,0 +214,4 @@
UNLOCK();
}
int hos_gpu_take_host_writes(uint64_t (*out)[2], int max) {
if (!nhost_writes || max <= 0) return 0;
Member

L3 (blocking): The host-write queue length is read outside the lock while producers change it under the lock.

When: A thread executing nvn_gpu_write can increment nhost_writes while the renderer calls hos_gpu_take_host_writes. The plain concurrent accesses are a data race, and the early return can miss a queued update for the collection pass.

Do: Take the lock before inspecting the queue length, or use a correctly synchronized publication protocol for both the length and queued ranges.

**L3** (blocking): The host-write queue length is read outside the lock while producers change it under the lock. *When:* A thread executing nvn_gpu_write can increment nhost_writes while the renderer calls hos_gpu_take_host_writes. The plain concurrent accesses are a data race, and the early return can miss a queued update for the collection pass. **Do:** Take the lock before inspecting the queue length, or use a correctly synchronized publication protocol for both the length and queued ranges.
@ -101,1 +114,4 @@
for (uint64_t p = lo >> 12; p < p1;) {
#if defined(__AVX2__)
if (avx2 && wide && p + 128 <= p1) {
const __m256i v0 = _mm256_loadu_si256((const __m256i *)(const void *)&a64_dirty[p]);
Member

L5 (blocking): The AVX2 scan reads write marks non-atomically while game threads publish those marks with atomic stores.

When: A game thread marks a page during collect_in's vector load. The intrinsic load and atomic store access the same bytes without a common synchronization protocol, making the scan a data race and potentially missing an upload.

Do: Use a representation and scan protocol whose concurrent reads and writes are atomic, and exercise concurrent publication while collecting.

**L5** (blocking): The AVX2 scan reads write marks non-atomically while game threads publish those marks with atomic stores. *When:* A game thread marks a page during collect_in's vector load. The intrinsic load and atomic store access the same bytes without a common synchronization protocol, making the scan a data race and potentially missing an upload. **Do:** Use a representation and scan protocol whose concurrent reads and writes are atomic, and exercise concurrent publication while collecting.
@ -0,0 +123,4 @@
with tempfile.TemporaryDirectory(prefix="collect-avx2-") as tmp:
c = Path(tmp) / "fixture.c"
exe = Path(tmp) / "fixture"
c.write_text(fixture, encoding="utf-8")
Member

L6 (should fix): The test always compiles and executes an AVX2 binary without checking whether the running CPU supports AVX2, and it ignores the suite's selected C compiler.

When: On a supported machine without AVX2 the fixture can terminate with an illegal instruction; on a Windows setup where the configured compiler is not named clang on PATH, the suite cannot compile it.

Do: Pass the suite's compiler through RUN_ALL_ARGS and gate execution of the AVX2 fixture on runtime CPU support, while retaining a baseline test.

**L6** (should fix): The test always compiles and executes an AVX2 binary without checking whether the running CPU supports AVX2, and it ignores the suite's selected C compiler. *When:* On a supported machine without AVX2 the fixture can terminate with an illegal instruction; on a Windows setup where the configured compiler is not named clang on PATH, the suite cannot compile it. **Do:** Pass the suite's compiler through RUN_ALL_ARGS and gate execution of the AVX2 fixture on runtime CPU support, while retaining a baseline test.
@ -0,0 +627,4 @@
encoding="utf-8")
exe = tmp / ("fixture.exe" if os.name == "nt" else "fixture")
for cc in compilers:
for extra_flags in ([], ["-mavx2", "-mfma"]):
Member

L7 (should fix): The cloth test also unconditionally executes a binary compiled for AVX2 and FMA and does not use the compiler selected by the test suite.

When: A supported CPU without either feature can fault when the optimized fixture runs, even though the production default build has a runtime fallback. A configured compiler outside the hard-coded PATH search is also ignored.

Do: Use the suite's compiler argument and only execute the globally AVX2/FMA-compiled variant when the CPU supports both features.

**L7** (should fix): The cloth test also unconditionally executes a binary compiled for AVX2 and FMA and does not use the compiler selected by the test suite. *When:* A supported CPU without either feature can fault when the optimized fixture runs, even though the production default build has a runtime fallback. A configured compiler outside the hard-coded PATH search is also ignored. **Do:** Use the suite's compiler argument and only execute the globally AVX2/FMA-compiled variant when the CPU supports both features.
Author
Contributor

Thanks @HumanBean and BeanBot — completely agree on splitting these up and testing each change individually.

After checking against current main (28cb22b9e), most of this stacked branch is already upstream (game/oot_cloth.c, mw_watch_buckets[256], 4-way HOS_OBJ_CACHE, and HOS_COLLECT_VECTOR), so we are splitting the remaining unmerged pieces into clean standalone PRs directly off main:

  • #2876 (perf/pc-phase-c-threading-parallel): rebased onto main (28cb22b9e) with the unmerged host threading & Windows process priority changes (hos_cores=8 on >=8 logical cores, vc_acquire bitmask scan + milestone wait, and HOS_PROCESS_PRIORITY; happy to split HOS_PROCESS_PRIORITY into its own PR as well if preferred for individual testing).
  • #2858 (perf/pc-discrete-memory-coherence): rebasing directly onto main and addressing every BeanBot blocking finding (L1 require CPU_NO_ACCESS instead of PHYSICAL alone so PHYSICAL | CPU_CACHED stays tracked, L2 full nested-interval overlap check + test, L3 locked/synchronized host-write queue length in host/nvdrv.c, L4 consistent atomic sieve_visited across all paths, L9 gpu/vk/switches.def rows for RX_VK_MIRROR_SYNC_FAST and RX_VK_MIRROR_SIEVE, and dropping L5/L6 HOS_COLLECT_AVX2 since main already has HOS_COLLECT_VECTOR).

Closing #2886 as superseded by main (28cb22b9e) + #2876 / #2858.

Thanks @HumanBean and BeanBot — completely agree on splitting these up and testing each change individually. After checking against current `main` (`28cb22b9e`), most of this stacked branch is already upstream (`game/oot_cloth.c`, `mw_watch_buckets[256]`, 4-way `HOS_OBJ_CACHE`, and `HOS_COLLECT_VECTOR`), so we are splitting the remaining unmerged pieces into clean standalone PRs directly off `main`: - **#2876** (`perf/pc-phase-c-threading-parallel`): rebased onto `main` (`28cb22b9e`) with the unmerged host threading & Windows process priority changes (`hos_cores=8` on >=8 logical cores, `vc_acquire` bitmask scan + milestone wait, and `HOS_PROCESS_PRIORITY`; happy to split `HOS_PROCESS_PRIORITY` into its own PR as well if preferred for individual testing). - **#2858** (`perf/pc-discrete-memory-coherence`): rebasing directly onto `main` and addressing every BeanBot blocking finding (**L1** require `CPU_NO_ACCESS` instead of `PHYSICAL` alone so `PHYSICAL | CPU_CACHED` stays tracked, **L2** full nested-interval overlap check + test, **L3** locked/synchronized host-write queue length in `host/nvdrv.c`, **L4** consistent atomic `sieve_visited` across all paths, **L9** `gpu/vk/switches.def` rows for `RX_VK_MIRROR_SYNC_FAST` and `RX_VK_MIRROR_SIEVE`, and dropping **L5/L6** `HOS_COLLECT_AVX2` since `main` already has `HOS_COLLECT_VECTOR`). Closing #2886 as superseded by `main` (`28cb22b9e`) + #2876 / #2858.
siantm closed this pull request 2026-11-30 09:21:50 +00:00
Owner

Tested on this PC, one change at a time: RTX 3090 / NVIDIA 620.70.06 / Linux (CachyOS 7.3.3), 24 threads, 32 GB.

Short version: on this PC none of the changes clearly moves fps, 1 % lows or hitches in Kokiri Forest. The full set is +0.6 % (within the runs' spread). The faster mirror_sync scan is the only one that leans positive (+1.4 %), and that is still inside the spread. Several parts of the stack are already on main in another form (list below).

How it was tested

  • Rebased. The stack (#2858 → #2876 → #2886) is on a base 548 commits behind main and conflicts in about 14 files. I ported the parts main doesn't have onto main @ 46291934, each as its own patch (attached), and built them together into one game with every switch, so a single build serves every variant.
  • Change 5 (vcore wait) has no switch. For a local test only, I added T2886_VC_POLL=1, which puts the 1 ms poll back. It is not in the patches.
  • Setup: dev.py ab, Kokiri Forest (child), 1920x1080 output, Render resolution 100 %, upscaler Off (checked in each log: upscaler: Off ... 1920x1080 -> 1920x1080), V-Sync and frame generation off, uncapped (HOS_FPS_MAX=1000).
  • Runs: each 45 s measured after a warm-up until no frame waited for a pipeline. 2 interleaved pairs (A, B, A, B) per comparison, all in two timing jobs of the queue.
  • "Off" means this build with HOS_POOL_FLAGS=0 RX_VK_POOL_FLAGS=0 RX_VK_MIRROR_SYNC_FAST=0 RX_VK_MIRROR_SIEVE=0 HOS_CORES=6 T2886_VC_POLL=1. Each change was measured alone against Off: Off with only that change's switches unset.
  • 1 % low below is 1000 / the mean of the slowest 1 % of frames.
  • The GPU was this game's alone in every run. Every log shows the full ~21.9 GB of VRAM allowed at the start, and the batch checked nvidia-smi for other games before each comparison.
  • No run had a frame of 50 ms or more (so none over 100 ms either). No escapes, starved grants or Vulkan errors on either side.

The whole port against main

main All changes on Δ
fps (each run) 157.0 / 156.9 (median 156.9) 159.4 / 156.4 (median 157.9) +0.6 %, within spread
1 % low (each run) 139.0 / 137.2 140.1 / 134.0 −1.0
median frame 6.40 ms 6.37 ms −0.03 ms
worst frame 8.3 / 12.1 ms 13.7 / 13.7 ms —
frames ≥ 50 / ≥ 100 ms 0 / 0 0 / 0 —

Check that Off behaves as main: main 157.0 / 156.7 fps, Off 157.4 / 156.7. The same.

The spread across all 28 runs is 155.9–160.3 fps: a run settles a little high or low whatever it runs, so a ±1 % difference from 2 pairs is noise.

Each change alone

# Change (patch) What it does Off This change alone Δ fps 1 % low (Off → alone) Worst frame (Off → alone) Verdict here
1 GPU-only pool flags (2886-1-pool-flags.patch) Leaves CPU_NO_ACCESS / PHYSICAL pools out of the write-mark collection, eager captures and write-backs 157.1 / 159.1 156.1 / 157.1 −0.9 % 135.8 / 140.0 → 134.7 / 137.7 13.9 / 8.6 → 14.8 / 14.7 ms Neutral. It works as designed (the log: pool flags skipped 47 write-backs (46.5 MB in GPU-only pools) per 600 submits) but buys no frame time here. It still has BeanBot's blocking findings (PHYSICAL with CPU_CACHED, the overlap scan, the races).
2 Fast mirror_sync scan (2886-2-mirror-sync-fast.patch) Page generations compared 4 at a time with AVX2, staging reused, the capture-buffer lookup cached. Rewritten for main's 64-bit generations, since the PR's 32-bit compare no longer fits. 157.0 / 157.2 158.2 / 160.3 +1.4 % 134.9 / 138.2 → 140.8 / 139.5 13.5 / 13.8 → 7.9 / 11.6 ms Neutral, leaning positive. Both its runs beat both Off runs, but the difference is inside the overall spread; it would need longer runs to confirm.
3 SIEVE mirror eviction (2886-3-mirror-sieve.patch) A clock hand instead of a sort picks the mirrors given back for room. The visited bit is atomic everywhere, which fixes BeanBot's L4. 156.9 / 156.2 156.1 / 157.0 0.0 % 137.7 / 138.5 → 137.6 / 140.7 8.1 / 8.4 → 8.3 / 8.0 ms Neutral here, and this PC can't show it. SIEVE only acts once the mirror budget is full, which a 24 GB card doesn't reach in this scene. It needs a ≤ 8 GB card.
4 HOS_CORES 8 on 8+ thread PCs (2886-4-cores8.patch) The game sees 8 virtual cores instead of 6 159.4 / 156.7 159.4 / 155.9 −0.2 % 139.6 / 136.4 → 141.1 / 133.8 9.0 / 13.3 → 8.8 / 14.9 ms Neutral
5 vcore wait to the next deadline (2886-5-vcore-wait.patch) vc_acquire scans only the allowed cores and sleeps until the slice, starvation or escape deadline instead of waking every 1 ms 158.6 / 156.3 159.3 / 156.4 +0.2 % 139.8 / 137.0 → 139.5 / 138.7 7.8 / 14.0 → 10.6 / 8.0 ms Neutral. Mean vcore wait 57 vs 56 µs, no change in fps or lows.
6 Windows process priority (2886-6-process-priority.patch) ABOVE_NORMAL_PRIORITY_CLASS at start — — — — — Not testable here. It is #ifdef _WIN32, so on Linux it does nothing. The PR's Windows numbers (1 % low 23 → 42 on an i7-9700) would be the thing to confirm on a Windows PC: that's where the PR's gain would come from, if anywhere.

Already on main (not ported, nothing to measure)

  • HOS_COLLECT_AVX2 (AVX2 write-mark scan): main already walks the marks with vector loads (#936, HOS_COLLECT_VECTOR).
  • Native zstd on by default (HOS_NATIVE_ZSTD, _FRAMES): already the default on main, with a per-GPU policy (#1875).
  • Havok cloth AVX2 (HOS_OOT_CLOTH_AVX2, capsule, sphere and skinning): main has HOS_NATIVE_CLOTH (#2036), bit-exact host kernels for the solver passes, collisions and skinning. nx2/oot_patches.py, which these hooks went through, no longer exists.
  • Lock-free poke_multiwait (part of HOS_SYNC_FAST): main has the same per-key bucket fast path.
  • 2-way obj_nockpt cache (the rest of HOS_SYNC_FAST): main has HOS_OBJ_CACHE, 16384 entries, 4-way (#1781).

About the patches

  • Each patch is source only and applies on its own to main @ 46291934.
  • Patch 1 bumps MKWVK_API_VERSION to 57 for the new gpu_pools_flags host slot.
  • Every new switch has its switches.def row (RX_VK_MIRROR_SYNC_FAST and RX_VK_MIRROR_SIEVE had none).
  • They are test ports, not ready to merge. The game-free checks that fail with them:
    • With patches 1–3: test_mem_check, test_msync_pass, test_wb_learn and test_capture_copy_runs, which read mirror_sync's source and expect its old shape (patch 2 splits it into mirror_sync_plain and mirror_sync_fast); test_direct_buffer_writes (sieve_mark is not in its extracted copy); and test_capture_pool_refresh (its stand-in host has no version or gpu_pools_flags).
    • With patch 5: test_vcore_escape passes on main and fails with the patch. Its model counts 1 ms looks; the PR had rewritten this test for it.

Recommendation

Split the stack as asked above, rebased on current main, keeping only these: pool flags (with BeanBot's findings fixed), the mirror_sync scan, SIEVE, cores 8, the vcore wait and the Windows priority. On this RTX 3090 / Linux PC none of them is a measurable win; the mirror_sync scan is the only one worth a longer run. The likely places they could matter are Windows (priority), low-VRAM cards (SIEVE, pool flags) and CPUs with fewer cores. Those want the Test Farm or a tester with that hardware.

Tested on this PC, one change at a time: **RTX 3090 / NVIDIA 620.70.06 / Linux (CachyOS 7.3.3)**, 24 threads, 32 GB. **Short version:** on this PC none of the changes clearly moves fps, 1 % lows or hitches in Kokiri Forest. The full set is +0.6 % (within the runs' spread). The faster `mirror_sync` scan is the only one that leans positive (+1.4 %), and that is still inside the spread. Several parts of the stack are already on `main` in another form (list below). ### How it was tested - **Rebased.** The stack ([#2858](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/2858) → [#2876](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/2876) → [#2886](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/2886)) is on a base 548 commits behind `main` and conflicts in about 14 files. I ported the parts `main` doesn't have onto `main` @ `46291934`, each as its own patch (attached), and built them together into one game with every switch, so a single build serves every variant. - **Change 5 (vcore wait) has no switch.** For a local test only, I added `T2886_VC_POLL=1`, which puts the 1 ms poll back. It is not in the patches. - **Setup:** `dev.py ab`, Kokiri Forest (child), 1920x1080 output, Render resolution 100 %, upscaler Off (checked in each log: `upscaler: Off ... 1920x1080 -> 1920x1080`), V-Sync and frame generation off, uncapped (`HOS_FPS_MAX=1000`). - **Runs:** each 45 s measured after a warm-up until no frame waited for a pipeline. 2 interleaved pairs (A, B, A, B) per comparison, all in two timing jobs of the queue. - **"Off"** means this build with `HOS_POOL_FLAGS=0 RX_VK_POOL_FLAGS=0 RX_VK_MIRROR_SYNC_FAST=0 RX_VK_MIRROR_SIEVE=0 HOS_CORES=6 T2886_VC_POLL=1`. Each change was measured alone against Off: Off with only that change's switches unset. - **1 % low** below is 1000 / the mean of the slowest 1 % of frames. - **The GPU was this game's alone in every run.** Every log shows the full ~21.9 GB of VRAM allowed at the start, and the batch checked `nvidia-smi` for other games before each comparison. - **No run had a frame of 50 ms or more** (so none over 100 ms either). No escapes, starved grants or Vulkan errors on either side. ### The whole port against `main` | | `main` | All changes on | Δ | |---|---|---|---| | fps (each run) | 157.0 / 156.9 (median 156.9) | 159.4 / 156.4 (median 157.9) | +0.6 %, within spread | | 1 % low (each run) | 139.0 / 137.2 | 140.1 / 134.0 | −1.0 | | median frame | 6.40 ms | 6.37 ms | −0.03 ms | | worst frame | 8.3 / 12.1 ms | 13.7 / 13.7 ms | — | | frames ≥ 50 / ≥ 100 ms | 0 / 0 | 0 / 0 | — | Check that Off behaves as `main`: `main` 157.0 / 156.7 fps, Off 157.4 / 156.7. The same. The spread across all 28 runs is 155.9–160.3 fps: a run settles a little high or low whatever it runs, so a ±1 % difference from 2 pairs is noise. ### Each change alone | # | Change (patch) | What it does | Off | This change alone | Δ fps | 1 % low (Off → alone) | Worst frame (Off → alone) | Verdict here | |---|---|---|---|---|---|---|---|---| | 1 | GPU-only pool flags ([`2886-1-pool-flags.patch`](https://git.magicbean.dev/attachments/d6b4271d-661c-4773-a50e-f95df175cc52)) | Leaves `CPU_NO_ACCESS` / `PHYSICAL` pools out of the write-mark collection, eager captures and write-backs | 157.1 / 159.1 | 156.1 / 157.1 | −0.9 % | 135.8 / 140.0 → 134.7 / 137.7 | 13.9 / 8.6 → 14.8 / 14.7 ms | **Neutral.** It works as designed (the log: `pool flags skipped 47 write-backs (46.5 MB in GPU-only pools)` per 600 submits) but buys no frame time here. It still has BeanBot's blocking findings (`PHYSICAL` with `CPU_CACHED`, the overlap scan, the races). | | 2 | Fast `mirror_sync` scan ([`2886-2-mirror-sync-fast.patch`](https://git.magicbean.dev/attachments/43e233ae-b33f-4816-a435-f318cb54c9d9)) | Page generations compared 4 at a time with AVX2, staging reused, the capture-buffer lookup cached. Rewritten for `main`'s 64-bit generations, since the PR's 32-bit compare no longer fits. | 157.0 / 157.2 | 158.2 / 160.3 | +1.4 % | 134.9 / 138.2 → 140.8 / 139.5 | 13.5 / 13.8 → 7.9 / 11.6 ms | **Neutral, leaning positive.** Both its runs beat both Off runs, but the difference is inside the overall spread; it would need longer runs to confirm. | | 3 | SIEVE mirror eviction ([`2886-3-mirror-sieve.patch`](https://git.magicbean.dev/attachments/65eef434-cf85-4b3e-8677-72751b5d7ff3)) | A clock hand instead of a sort picks the mirrors given back for room. The visited bit is atomic everywhere, which fixes BeanBot's L4. | 156.9 / 156.2 | 156.1 / 157.0 | 0.0 % | 137.7 / 138.5 → 137.6 / 140.7 | 8.1 / 8.4 → 8.3 / 8.0 ms | **Neutral here, and this PC can't show it.** SIEVE only acts once the mirror budget is full, which a 24 GB card doesn't reach in this scene. It needs a ≤ 8 GB card. | | 4 | `HOS_CORES` 8 on 8+ thread PCs ([`2886-4-cores8.patch`](https://git.magicbean.dev/attachments/80db81f5-e3b0-492f-ba3f-da5d52399034)) | The game sees 8 virtual cores instead of 6 | 159.4 / 156.7 | 159.4 / 155.9 | −0.2 % | 139.6 / 136.4 → 141.1 / 133.8 | 9.0 / 13.3 → 8.8 / 14.9 ms | **Neutral** | | 5 | vcore wait to the next deadline ([`2886-5-vcore-wait.patch`](https://git.magicbean.dev/attachments/db50a156-4ded-4f92-b6d3-46a91df68d96)) | `vc_acquire` scans only the allowed cores and sleeps until the slice, starvation or escape deadline instead of waking every 1 ms | 158.6 / 156.3 | 159.3 / 156.4 | +0.2 % | 139.8 / 137.0 → 139.5 / 138.7 | 7.8 / 14.0 → 10.6 / 8.0 ms | **Neutral.** Mean vcore wait 57 vs 56 µs, no change in fps or lows. | | 6 | Windows process priority ([`2886-6-process-priority.patch`](https://git.magicbean.dev/attachments/82c49c57-5958-4758-afa3-ae69d1b04cd7)) | `ABOVE_NORMAL_PRIORITY_CLASS` at start | — | — | — | — | — | **Not testable here.** It is `#ifdef _WIN32`, so on Linux it does nothing. The PR's Windows numbers (1 % low 23 → 42 on an i7-9700) would be the thing to confirm on a Windows PC: that's where the PR's gain would come from, if anywhere. | ### Already on `main` (not ported, nothing to measure) - **`HOS_COLLECT_AVX2`** (AVX2 write-mark scan): `main` already walks the marks with vector loads ([#936](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/936), `HOS_COLLECT_VECTOR`). - **Native zstd on by default** (`HOS_NATIVE_ZSTD`, `_FRAMES`): already the default on `main`, with a per-GPU policy ([#1875](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/1875)). - **Havok cloth AVX2** (`HOS_OOT_CLOTH_AVX2`, capsule, sphere and skinning): `main` has `HOS_NATIVE_CLOTH` ([#2036](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/2036)), bit-exact host kernels for the solver passes, collisions and skinning. `nx2/oot_patches.py`, which these hooks went through, no longer exists. - **Lock-free `poke_multiwait`** (part of `HOS_SYNC_FAST`): `main` has the same per-key bucket fast path. - **2-way `obj_nockpt` cache** (the rest of `HOS_SYNC_FAST`): `main` has `HOS_OBJ_CACHE`, 16384 entries, 4-way ([#1781](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/1781)). ### About the patches - Each patch is source only and applies on its own to `main` @ `46291934`. - Patch 1 bumps `MKWVK_API_VERSION` to 57 for the new `gpu_pools_flags` host slot. - Every new switch has its `switches.def` row (`RX_VK_MIRROR_SYNC_FAST` and `RX_VK_MIRROR_SIEVE` had none). - They are test ports, not ready to merge. The game-free checks that fail with them: - With patches 1–3: `test_mem_check`, `test_msync_pass`, `test_wb_learn` and `test_capture_copy_runs`, which read `mirror_sync`'s source and expect its old shape (patch 2 splits it into `mirror_sync_plain` and `mirror_sync_fast`); `test_direct_buffer_writes` (`sieve_mark` is not in its extracted copy); and `test_capture_pool_refresh` (its stand-in host has no `version` or `gpu_pools_flags`). - With patch 5: `test_vcore_escape` passes on `main` and fails with the patch. Its model counts 1 ms looks; the PR had rewritten this test for it. ### Recommendation Split the stack as asked above, rebased on current `main`, keeping only these: pool flags (with BeanBot's findings fixed), the `mirror_sync` scan, SIEVE, cores 8, the vcore wait and the Windows priority. On this RTX 3090 / Linux PC none of them is a measurable win; the `mirror_sync` scan is the only one worth a longer run. The likely places they could matter are Windows (priority), low-VRAM cards (SIEVE, pool flags) and CPUs with fewer cores. Those want the Test Farm or a tester with that hardware.
Author
Contributor

@HumanBean thank you. Porting each piece onto main and measuring it alone, with "Off" checked against main first, is the test this stack needed and that I didn't do.

Your numbers say none of these changes is a measurable win on the RTX 3090 / Linux PC. The full set is +0.6 % against main (median 157.9 vs 156.9 fps), inside the 155.9–160.3 fps spread of your 28 runs. The 1 % lows (140.1 / 134.0 vs 139.0 / 137.2) and worst frames don't favour it either. My Windows numbers for this stack (1 % low 23 → 42) are not reproduced there, and I won't argue with that.

Each piece, against your table:

# Change Your result What I propose
1 Pool flags (CPU_NO_ACCESS out of collection, captures, write-backs) −0.9 %, neutral Lives on only in #2858, rebased on main today with BeanBot's L1 (PHYSICAL | CPU_CACHED) and L2 (nested overlap, which f595bb3 had not fixed) done. Your run says it buys nothing on a 24 GB card, so #2858 has to show a gain on a low-VRAM card or I take the pool flags out of it too.
2 Fast mirror_sync scan +1.4 %, both runs above both Off runs, inside the spread Kept in #2858 (RX_VK_MIRROR_SYNC_FAST) for the longer run you suggest. It's the only piece that leans positive.
3 SIEVE eviction 0.0 %, can't act on 24 GB Drop it. It is already out of #2858, and with no system showing a gain it isn't worth the extra eviction code.
4 HOS_CORES 8 −0.2 %, neutral Already merged with #2876 (f439f2bb9) before your results were set against it.
5 vcore deadline wait +0.2 %, 57 vs 56 µs mean wait Same: merged with #2876.
6 Windows process priority not testable on Linux Same: merged with #2876, untested with competing work (BeanBot's L5 there).
— HOS_COLLECT_AVX2, native zstd default, cloth AVX2, lock-free multiwait, 2-way obj cache already on main in another form Drop: nothing to carry.

For 4–6 I haven't reverted anything on one neutral result. Our rule changes a shipped default only when a reviewer asks or ≥ 2 systems show it slower, and yours is neutral, not slower. But I've said on #2876 that its merged numbers are a single-PC result your run didn't reproduce, and that it needs the farm on 6–8-thread CPUs, Steam Deck, and Windows with background load.

This PR was closed on 30 Nov as superseded, and I'm leaving it as it is. Proposal: of its parts, only #1 and #2 continue, in #2858, each on the condition above. Everything else in it is dropped.

@HumanBean thank you. Porting each piece onto `main` and measuring it alone, with "Off" checked against `main` first, is the test this stack needed and that I didn't do. Your numbers say none of these changes is a measurable win on the RTX 3090 / Linux PC. The full set is +0.6 % against `main` (median 157.9 vs 156.9 fps), inside the 155.9–160.3 fps spread of your 28 runs. The 1 % lows (140.1 / 134.0 vs 139.0 / 137.2) and worst frames don't favour it either. My Windows numbers for this stack (1 % low 23 → 42) are not reproduced there, and I won't argue with that. Each piece, against your table: | # | Change | Your result | What I propose | |---|---|---|---| | 1 | Pool flags (`CPU_NO_ACCESS` out of collection, captures, write-backs) | −0.9 %, neutral | Lives on only in #2858, rebased on `main` today with BeanBot's L1 (`PHYSICAL \| CPU_CACHED`) and L2 (nested overlap, which `f595bb3` had *not* fixed) done. Your run says it buys nothing on a 24 GB card, so #2858 has to show a gain on a low-VRAM card or I take the pool flags out of it too. | | 2 | Fast `mirror_sync` scan | +1.4 %, both runs above both Off runs, inside the spread | Kept in #2858 (`RX_VK_MIRROR_SYNC_FAST`) for the longer run you suggest. It's the only piece that leans positive. | | 3 | SIEVE eviction | 0.0 %, can't act on 24 GB | Drop it. It is already out of #2858, and with no system showing a gain it isn't worth the extra eviction code. | | 4 | `HOS_CORES` 8 | −0.2 %, neutral | Already merged with #2876 (f439f2bb9) before your results were set against it. | | 5 | vcore deadline wait | +0.2 %, 57 vs 56 µs mean wait | Same: merged with #2876. | | 6 | Windows process priority | not testable on Linux | Same: merged with #2876, untested with competing work (BeanBot's L5 there). | | — | `HOS_COLLECT_AVX2`, native zstd default, cloth AVX2, lock-free multiwait, 2-way obj cache | already on `main` in another form | Drop: nothing to carry. | For 4–6 I haven't reverted anything on one neutral result. Our rule changes a shipped default only when a reviewer asks or ≥ 2 systems show it slower, and yours is neutral, not slower. But I've said on #2876 that its merged numbers are a single-PC result your run didn't reproduce, and that it needs the farm on 6–8-thread CPUs, Steam Deck, and Windows with background load. This PR was closed on 30 Nov as superseded, and I'm leaving it as it is. Proposal: of its parts, only #1 and #2 continue, in #2858, each on the condition above. Everything else in it is dropped.
Some checks failed
PR description / Title and description (pull_request_target) Successful in 9s
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
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

Pull request closed

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!2886
No description provided.