perf(hle): let the title's threads run on every processor and keep the scheduler's boost (VICTORY_TITLE_FREE) #329
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/329"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from Androtim/MiniVI. Originally posted by PiloteCode on 2026-12-02T12:27:51Z.
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,SetThreadGroupAffinityandSetProcessPriorityBoostto small wrappers: a pin becomes the process's whole affinity mask, and the boost stays on. Default on;VICTORY_TITLE_FREE=0passes the title's calls to the system unchanged, as before.After bigboss22869's fork (
4c41be4f3,07d08694e) andtrustno1-coder/VIctory-NVIDIApull 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 withGetProcessAffinityMask(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 inHostPolicy::resolve, before the existingtitlewritehook (the same place our fork binds it).crates/victory-hle/src/modules/mod.rs: the module (Windows only).GROUP_AFFINITYlayout, and that only these three imports are bound.Rig Specs Tested On (our fork, not this tree)
Run Settings & Profile
victory-hle/victory-gpu)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, meanMeasurements & Verification
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.
main3230974; offline,--locked, toolchain 1.98.1-msvc):cargo clippy --workspace --all-targets --locked -- -D warningscargo clippy --workspace --all-targets --all-features --locked -- -D warningscargo test(not run by us on this tree)cargo xtask policy(not run; the new file is a small.rstext file with no hex/base64 runs or title identifiers)Limits
Imported from Androtim/MiniVI. Originally posted by Androtim on 2026-12-02T12:49:01Z.
Read-only security & triage review on
527b51a9(external authorPiloteCode— awaiting manual owner approval per repository security allowlist policy; not built/executed locally and not auto-merged):crates/victory-hle/src/{host.rs,modules/mod.rs,modules/title_free.rs}(+256/-0); noCargo.toml,build.rs,.github/workflows/, binaries, shell/network calls, or clean-room violations. Uses Win32 thread-affinity/priority-boost APIs (SetThreadAffinityMask,SetThreadGroupAffinity,SetProcessPriorityBoost).VICTORY_TITLE_FREE=0kill-switch). Needs manual owner approval to run CI + plain---releaseA/B verification.Imported from Androtim/MiniVI. Originally posted by Androtim on 2026-12-02T13:04:19Z.
Automated triage for the maintainers (not an approval).
Verdict:
needs-gpu-test· CI (check):passingReview 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 onmain).What was checked
crates/victory-hle/src/host.rs(HostPolicy::resolve) &crates/victory-hle/src/lib.rs(HleResolver::resolve): The hook is placed afterimp::resolve(dll, symbol)?and beforevictory_gpu::titlewrite::import, so it only interceptsSetThreadAffinityMask,SetThreadGroupAffinity, andSetProcessPriorityBoostfor allowed host DLLs that actually export them, without affecting HLE-registry overrides.crates/victory-hle/src/modules/title_free.rs:GroupAffinity(#[repr(C)]), andTHREAD_SET_QUERY(0x0020 | 0x0040) match the Windows API definitions.process_mask()safely falls back to the title's requested mask whenGetProcessAffinityMaskfails or returns0(such as multi-group processes on >64-LP systems), andset_thread_group_affinityhandles null pointers and non-zero groups cleanly.VICTORY_TITLE_FREE=0(outside aVICTORY_ABdiagnostics run) makesbound()returnfalse, bypassing the wrappers completely so imports resolve directly to the host DLLs.freed(),GroupAffinitylayout, andimport()filtering.Minor non-blocking notes
PINSis locked and appended to inpinned()even in non-diagnosticsbuilds wherewatch_turns()is a no-op andPINSis never read or pruned. GatingPINSupdates on#[cfg(feature = "diagnostics")](whenVICTORY_ABswitchesVICTORY_TITLE_FREE) would avoid unnecessary mutex traffic and unbounded growth if a title spawns many short-lived pinned threads.set_thread_affinity_maskdoes not guardasked == 0(unlikeset_thread_group_affinity), so a degenerate0mask would be widened rather than failing withERROR_INVALID_PARAMETER(unlikely in practice).Next step
Run a short local real-GPU smoke test on
main(defaultVICTORY_TITLE_FREEvsVICTORY_TITLE_FREE=0) to confirm stability, frame pacing, and clean log output before merging.Generated with Antigravity CLI (
agy).Imported from Androtim/MiniVI. Originally posted by Androtim on 2026-12-02T13:18:18Z.
Allowlist & Architect Deep Review (
PiloteCodeis now on the trusted allowlist; CI46881352350is GREEN):Win32 thread-hook audit (
crates/victory-hle/src/modules/title_free.rs,crates/victory-hle/src/host.rs):GroupAffinitylayout matches Win32GROUP_AFFINITY(unit-tested),affinity.is_null()is guarded beforeread_unaligned(),OpenThreadhandles are always closed viaCloseHandle,GetProcessAffinityMaskfailure/0on multi-group (>64 logical CPU) hosts safely falls back to the title's requested mask, andVICTORY_TITLE_FREE=0cleanly bypasses the hook.PINS(andGetThreadId) behind#[cfg(feature = "diagnostics")](whenVICTORY_ABis active) so plain--releasebuilds do not lock/append exited thread IDs into a staticMutex<Vec>that is never read or pruned.asked != 0inset_thread_affinity_maskto matchset_thread_group_affinity.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 onmain(b0842d93+) verifying frame median/p90, audio/thread stability, and 0 crashes/DRED.