perf(hle): let the title's threads run on every processor and keep the scheduler's boost (VICTORY_TITLE_FREE) #329

Open
github-bot wants to merge 1 commit from github-bot/gh-329 into main AGit
Owner

@⁠PiloteCode on GitHub · 2026-12-02 12:27 UTC · original
PiloteCode:pr/title-free → main · +256 −0 · 3 files · 1 commits · open

Summary

The title pins each of its threads to a single logical processor (as on the console's seven cores) and turns the scheduler's priority boost off for the whole process. On a PC those threads share the processors with the layer's own pools (submitting thread, list translators, storage workers): a woken title thread waits for its processor while others sit idle ("woken, not running yet" was 6-10 ms of each frame's critical chain in a busy, crowded area), and the layer's threads lose the boost too.

This PR binds the title's imports of SetThreadAffinityMask, SetThreadGroupAffinity and SetProcessPriorityBoost to small wrappers: a pin becomes the process's whole affinity mask, and the boost stays on. Default on; VICTORY_TITLE_FREE=0 passes the title's calls to the system unchanged, as before.

After bigboss22869's fork (4c41be4f3, 07d08694e) and trustno1-coder/VIctory-NVIDIA pull request 2803; in our fork's play defaults since 1 Dec.

Changes

  • crates/victory-hle/src/modules/title_free.rs (new): the three wrappers; the process mask is read with GetProcessAffinityMask (if it cannot be read, the title's own mask is kept); one info line the first time a pin is widened. Diagnostics builds can switch it inside a run (VICTORY_AB=<s>,VICTORY_TITLE_FREE): a helper thread re-applies the remembered pins and the boost word at each phase change, so both arms are real.
  • crates/victory-hle/src/host.rs: one hook in HostPolicy::resolve, before the existing titlewrite hook (the same place our fork binds it).
  • crates/victory-hle/src/modules/mod.rs: the module (Windows only).
  • Unit tests: the mask choice, GROUP_AFFINITY layout, and that only these three imports are bound.

Rig Specs Tested On (our fork, not this tree)

  • CPU: Intel i9-14900KF (32 logical processors); also held to 12 logical processors as a 6-core/12-thread stand-in
  • GPU & VRAM: RTX 5090 32 GB; the 12-thread runs used an 8 GB card-budget stand-in at 1080p
  • System RAM: 128 GB
  • OS & GPU Driver: Windows 11; driver not recorded

Run Settings & Profile

  • Build: our fork's diagnostics build (same origin code as MiniVI's victory-hle/victory-gpu)
  • Profile: Series X, 1440p class output with DLSS on the full machine; 1080p on the 12-thread stand-in; RT off; FG off
  • Method: in-run A/B with VICTORY_AB (8-12 switches, 10 s phases in a mixed order, ~56 phases kept at the busiest place of a saved game), drift fitted by least squares; each phase's own frame median, p90, mean
  • Scene: a busy, crowded street area, ~15 min per run

Measurements & Verification

Run Machine Frame median Frame mean Frame p90 Submitting thread
big-forks-1 32 threads -1.49 +- 0.70 ms -2.91 +- 0.91 -2.35 +- 2.15 -1.70 +- 0.66
big-forks-3 32 threads -3.14 +- 0.67 ms -2.62 +- 0.85 -1.24 +- 2.24 -2.40 +- 0.45
both (inverse-variance) 32 threads -2.4 +- 0.5 ms -2.8 +- 0.6 n.s. -2.2 +- 0.4
big-forks-2 12 threads, 8 GB stand-in, 1080p -2.70 +- 1.51 ms -0.71 +- 1.05 +0.62 +- 2.45 -1.30 +- 1.22

The card was 2.5-2.7 points busier (the title's threads ran 0.75 processors a second more); pictures compared at fixed points: the same. No crash or device removal in these runs; in daily play since 1 Dec without a report against it.

  • Automated checks on this branch (rebased on main 3230974; offline, --locked, toolchain 1.98.1-msvc):
    • cargo clippy --workspace --all-targets --locked -- -D warnings
    • cargo clippy --workspace --all-targets --all-features --locked -- -D warnings
    • cargo test (not run by us on this tree)
    • cargo xtask policy (not run; the new file is a small .rs text file with no hex/base64 runs or title identifiers)

Limits

  • Measured on our fork, not on MiniVI; the hook site and HLE are the same code, but MiniVI's other defaults differ.
  • Our 12-thread result is a stand-in (process affinity held to 12 of 32), not a real 6-core PC; the 12-thread gain is 1.8 sigma.
  • No 8 GB card run of this tree, no AMD card run.
**@⁠PiloteCode** on GitHub · 2026-12-02 12:27 UTC · [original](https://github.com/Androtim/MiniVI/pull/329) `PiloteCode:pr/title-free` → `main` · +256 −0 · 3 files · 1 commits · open ## Summary The title pins each of its threads to a single logical processor (as on the console's seven cores) and turns the scheduler's priority boost off for the whole process. On a PC those threads share the processors with the layer's own pools (submitting thread, list translators, storage workers): a woken title thread waits for *its* processor while others sit idle ("woken, not running yet" was 6-10 ms of each frame's critical chain in a busy, crowded area), and the layer's threads lose the boost too. This PR binds the title's imports of `SetThreadAffinityMask`, `SetThreadGroupAffinity` and `SetProcessPriorityBoost` to small wrappers: a pin becomes the process's whole affinity mask, and the boost stays on. Default on; `VICTORY_TITLE_FREE=0` passes the title's calls to the system unchanged, as before. After bigboss22869's fork (`4c41be4f3`, `07d08694e`) and `trustno1-coder/VIctory-NVIDIA` pull request 2803; in our fork's play defaults since 1 Dec. ## Changes - `crates/victory-hle/src/modules/title_free.rs` (new): the three wrappers; the process mask is read with `GetProcessAffinityMask` (if it cannot be read, the title's own mask is kept); one info line the first time a pin is widened. Diagnostics builds can switch it inside a run (`VICTORY_AB=<s>,VICTORY_TITLE_FREE`): a helper thread re-applies the remembered pins and the boost word at each phase change, so both arms are real. - `crates/victory-hle/src/host.rs`: one hook in `HostPolicy::resolve`, before the existing `titlewrite` hook (the same place our fork binds it). - `crates/victory-hle/src/modules/mod.rs`: the module (Windows only). - Unit tests: the mask choice, `GROUP_AFFINITY` layout, and that only these three imports are bound. ## Rig Specs Tested On (our fork, not this tree) - **CPU:** Intel i9-14900KF (32 logical processors); also held to 12 logical processors as a 6-core/12-thread stand-in - **GPU & VRAM:** RTX 5090 32 GB; the 12-thread runs used an 8 GB card-budget stand-in at 1080p - **System RAM:** 128 GB - **OS & GPU Driver:** Windows 11; driver not recorded ## Run Settings & Profile - **Build:** our fork's diagnostics build (same origin code as MiniVI's `victory-hle`/`victory-gpu`) - **Profile:** Series X, 1440p class output with DLSS on the full machine; 1080p on the 12-thread stand-in; RT off; FG off - **Method:** in-run A/B with `VICTORY_AB` (8-12 switches, 10 s phases in a mixed order, ~56 phases kept at the busiest place of a saved game), drift fitted by least squares; each phase's own frame median, p90, mean - **Scene:** a busy, crowded street area, ~15 min per run ## Measurements & Verification | Run | Machine | Frame median | Frame mean | Frame p90 | Submitting thread | |---|---|---:|---:|---:|---:| | big-forks-1 | 32 threads | **-1.49 +- 0.70 ms** | -2.91 +- 0.91 | -2.35 +- 2.15 | -1.70 +- 0.66 | | big-forks-3 | 32 threads | **-3.14 +- 0.67 ms** | -2.62 +- 0.85 | -1.24 +- 2.24 | -2.40 +- 0.45 | | both (inverse-variance) | 32 threads | **-2.4 +- 0.5 ms** | -2.8 +- 0.6 | n.s. | -2.2 +- 0.4 | | big-forks-2 | 12 threads, 8 GB stand-in, 1080p | **-2.70 +- 1.51 ms** | -0.71 +- 1.05 | +0.62 +- 2.45 | -1.30 +- 1.22 | The card was 2.5-2.7 points busier (the title's threads ran 0.75 processors a second more); pictures compared at fixed points: the same. No crash or device removal in these runs; in daily play since 1 Dec without a report against it. - **Automated checks on this branch** (rebased on `main` `3230974`; offline, `--locked`, toolchain 1.98.1-msvc): - [x] `cargo clippy --workspace --all-targets --locked -- -D warnings` - [x] `cargo clippy --workspace --all-targets --all-features --locked -- -D warnings` - [ ] `cargo test` (not run by us on this tree) - [ ] `cargo xtask policy` (not run; the new file is a small `.rs` text file with no hex/base64 runs or title identifiers) ## Limits - Measured on our fork, not on MiniVI; the hook site and HLE are the same code, but MiniVI's other defaults differ. - Our 12-thread result is a stand-in (process affinity held to 12 of 32), not a real 6-core PC; the 12-thread gain is 1.8 sigma. - No 8 GB card run of this tree, no AMD card run.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-02 12:31:17 +00:00
Author
Owner

@⁠Androtim on GitHub · 2026-12-02 12:49 UTC · original

Read-only security & triage review on 527b51a9 (external author PiloteCode — awaiting manual owner approval per repository security allowlist policy; not built/executed locally and not auto-merged):

  • Security / Supply-Chain / Clean-Room: Clean. Touches only crates/victory-hle/src/{host.rs,modules/mod.rs,modules/title_free.rs} (+256/-0); no Cargo.toml, build.rs, .github/workflows/, binaries, shell/network calls, or clean-room violations. Uses Win32 thread-affinity/priority-boost APIs (SetThreadAffinityMask, SetThreadGroupAffinity, SetProcessPriorityBoost).
  • Architecture note: Substantive HLE scheduler optimization (default-on with VICTORY_TITLE_FREE=0 kill-switch). Needs manual owner approval to run CI + plain---release A/B verification.
**@⁠Androtim** on GitHub · 2026-12-02 12:49 UTC · [original](https://github.com/Androtim/MiniVI/pull/329#issuecomment-7345926041) Read-only security & triage review on `527b51a9` (external author `PiloteCode` — **awaiting manual owner approval** per repository security allowlist policy; not built/executed locally and not auto-merged): - **Security / Supply-Chain / Clean-Room:** Clean. Touches only `crates/victory-hle/src/{host.rs,modules/mod.rs,modules/title_free.rs}` (`+256/-0`); no `Cargo.toml`, `build.rs`, `.github/workflows/`, binaries, shell/network calls, or clean-room violations. Uses Win32 thread-affinity/priority-boost APIs (`SetThreadAffinityMask`, `SetThreadGroupAffinity`, `SetProcessPriorityBoost`). - **Architecture note:** Substantive HLE scheduler optimization (default-on with `VICTORY_TITLE_FREE=0` kill-switch). Needs manual owner approval to run CI + plain-`--release` A/B verification.
Author
Owner

@⁠Androtim on GitHub · 2026-12-02 13:04 UTC · original · edited 2026-12-02 14:03 UTC

Automated triage for the maintainers (not an approval).

Verdict: needs-gpu-test · CI (check): passing

Review Summary

Verdict: needs-gpu-test (CI passing; logic and FFI safety look solid, but this enables a default-on runtime scheduling change that has only been tested on the author's fork, not on main).

What was checked

  • crates/victory-hle/src/host.rs (HostPolicy::resolve) & crates/victory-hle/src/lib.rs (HleResolver::resolve): The hook is placed after imp::resolve(dll, symbol)? and before victory_gpu::titlewrite::import, so it only intercepts SetThreadAffinityMask, SetThreadGroupAffinity, and SetProcessPriorityBoost for allowed host DLLs that actually export them, without affecting HLE-registry overrides.
  • crates/victory-hle/src/modules/title_free.rs:
    • Win32 FFI signatures, GroupAffinity (#[repr(C)]), and THREAD_SET_QUERY (0x0020 | 0x0040) match the Windows API definitions.
    • process_mask() safely falls back to the title's requested mask when GetProcessAffinityMask fails or returns 0 (such as multi-group processes on >64-LP systems), and set_thread_group_affinity handles null pointers and non-zero groups cleanly.
    • VICTORY_TITLE_FREE=0 (outside a VICTORY_AB diagnostics run) makes bound() return false, bypassing the wrappers completely so imports resolve directly to the host DLLs.
    • Unit tests cover freed(), GroupAffinity layout, and import() filtering.

Minor non-blocking notes

  • PINS is locked and appended to in pinned() even in non-diagnostics builds where watch_turns() is a no-op and PINS is never read or pruned. Gating PINS updates on #[cfg(feature = "diagnostics")] (when VICTORY_AB switches VICTORY_TITLE_FREE) would avoid unnecessary mutex traffic and unbounded growth if a title spawns many short-lived pinned threads.
  • set_thread_affinity_mask does not guard asked == 0 (unlike set_thread_group_affinity), so a degenerate 0 mask would be widened rather than failing with ERROR_INVALID_PARAMETER (unlikely in practice).

Next step

Run a short local real-GPU smoke test on main (default VICTORY_TITLE_FREE vs VICTORY_TITLE_FREE=0) to confirm stability, frame pacing, and clean log output before merging.


Generated with Antigravity CLI (agy).

**@⁠Androtim** on GitHub · 2026-12-02 13:04 UTC · [original](https://github.com/Androtim/MiniVI/pull/329#issuecomment-7346306458) · edited 2026-12-02 14:03 UTC <!-- minivi-triage v1 head=527b51a98803a38041edd7e59406f42196328af0 verdict=needs-gpu-test ci=passing at=2026-12-02T14:04:13Z --> Automated triage for the maintainers (not an approval). **Verdict:** `needs-gpu-test` · **CI (`check`):** `passing` ### Review Summary **Verdict:** `needs-gpu-test` (CI passing; logic and FFI safety look solid, but this enables a default-on runtime scheduling change that has only been tested on the author's fork, not on `main`). #### What was checked - **`crates/victory-hle/src/host.rs` (`HostPolicy::resolve`) & `crates/victory-hle/src/lib.rs` (`HleResolver::resolve`):** The hook is placed after `imp::resolve(dll, symbol)?` and before `victory_gpu::titlewrite::import`, so it only intercepts `SetThreadAffinityMask`, `SetThreadGroupAffinity`, and `SetProcessPriorityBoost` for allowed host DLLs that actually export them, without affecting HLE-registry overrides. - **`crates/victory-hle/src/modules/title_free.rs`:** - Win32 FFI signatures, `GroupAffinity` (`#[repr(C)]`), and `THREAD_SET_QUERY` (`0x0020 | 0x0040`) match the Windows API definitions. - `process_mask()` safely falls back to the title's requested mask when `GetProcessAffinityMask` fails or returns `0` (such as multi-group processes on >64-LP systems), and `set_thread_group_affinity` handles null pointers and non-zero groups cleanly. - `VICTORY_TITLE_FREE=0` (outside a `VICTORY_AB` diagnostics run) makes `bound()` return `false`, bypassing the wrappers completely so imports resolve directly to the host DLLs. - Unit tests cover `freed()`, `GroupAffinity` layout, and `import()` filtering. #### Minor non-blocking notes - `PINS` is locked and appended to in `pinned()` even in non-`diagnostics` builds where `watch_turns()` is a no-op and `PINS` is never read or pruned. Gating `PINS` updates on `#[cfg(feature = "diagnostics")]` (when `VICTORY_AB` switches `VICTORY_TITLE_FREE`) would avoid unnecessary mutex traffic and unbounded growth if a title spawns many short-lived pinned threads. - `set_thread_affinity_mask` does not guard `asked == 0` (unlike `set_thread_group_affinity`), so a degenerate `0` mask would be widened rather than failing with `ERROR_INVALID_PARAMETER` (unlikely in practice). #### Next step Run a short local real-GPU smoke test on `main` (default `VICTORY_TITLE_FREE` vs `VICTORY_TITLE_FREE=0`) to confirm stability, frame pacing, and clean log output before merging. --- _Generated with Antigravity CLI (`agy`)._
Author
Owner

@⁠Androtim on GitHub · 2026-12-02 13:18 UTC · original

Allowlist & Architect Deep Review (PiloteCode is now on the trusted allowlist; CI 46881352350 is GREEN):

Win32 thread-hook audit (crates/victory-hle/src/modules/title_free.rs, crates/victory-hle/src/host.rs):

  • Sound & leak-free: GroupAffinity layout matches Win32 GROUP_AFFINITY (unit-tested), affinity.is_null() is guarded before read_unaligned(), OpenThread handles are always closed via CloseHandle, GetProcessAffinityMask failure/0 on multi-group (>64 logical CPU) hosts safely falls back to the title's requested mask, and VICTORY_TITLE_FREE=0 cleanly bypasses the hook.
  • Non-blocking cleanups worth doing:
    • Gate PINS (and GetThreadId) behind #[cfg(feature = "diagnostics")] (when VICTORY_AB is active) so plain --release builds do not lock/append exited thread IDs into a static Mutex<Vec> that is never read or pruned.
    • Guard asked != 0 in set_thread_affinity_mask to match set_thread_group_affinity.
    • Note for diagnostics VICTORY_AB: Windows can reuse exited TIDs for unrelated host/driver threads between phase flips (diagnostics-only caveat, does not affect release builds).

Next step (triage: needs gpu test): Ready for plain --release (no --features diagnostics) A/B on main (b0842d93+) verifying frame median/p90, audio/thread stability, and 0 crashes/DRED.

**@⁠Androtim** on GitHub · 2026-12-02 13:18 UTC · [original](https://github.com/Androtim/MiniVI/pull/329#issuecomment-7346664383) Allowlist & Architect Deep Review (`PiloteCode` is now on the trusted allowlist; CI `46881352350` is **GREEN**): **Win32 thread-hook audit (`crates/victory-hle/src/modules/title_free.rs`, `crates/victory-hle/src/host.rs`):** - Sound & leak-free: `GroupAffinity` layout matches Win32 `GROUP_AFFINITY` (unit-tested), `affinity.is_null()` is guarded before `read_unaligned()`, `OpenThread` handles are always closed via `CloseHandle`, `GetProcessAffinityMask` failure/`0` on multi-group (>64 logical CPU) hosts safely falls back to the title's requested mask, and `VICTORY_TITLE_FREE=0` cleanly bypasses the hook. - **Non-blocking cleanups worth doing:** - Gate `PINS` (and `GetThreadId`) behind `#[cfg(feature = "diagnostics")]` (when `VICTORY_AB` is active) so plain `--release` builds do not lock/append exited thread IDs into a static `Mutex<Vec>` that is never read or pruned. - Guard `asked != 0` in `set_thread_affinity_mask` to match `set_thread_group_affinity`. - Note for diagnostics `VICTORY_AB`: Windows can reuse exited TIDs for unrelated host/driver threads between phase flips (diagnostics-only caveat, does not affect release builds). **Next step (`triage: needs gpu test`):** Ready for plain `--release` (no `--features diagnostics`) A/B on `main` (`b0842d93`+) verifying frame median/p90, audio/thread stability, and 0 crashes/DRED.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
The changes on this branch are already on the target branch. This will be an empty commit.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/329/head:github-bot/gh-329'
git switch 'github-bot/gh-329'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-329'
git switch 'github-bot/gh-329'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-329'
git switch 'github-bot/gh-329'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-329'
git switch 'main'
git merge --squash 'github-bot/gh-329'
git switch 'main'
git merge --ff-only 'github-bot/gh-329'
git switch 'main'
git merge 'github-bot/gh-329'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
No milestone
No assignees
1 participant
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
github/Androtim--MiniVI!329
No description provided.