Park emulated MONITORX/MWAITX waits on GPU fence signals #1018

Open
Lkxex wants to merge 1 commit from upstream-pr/1020 into main
Lkxex commented 2026-11-25 16:24:47 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by Lkxex on 2026-11-25T16:24:47Z.


The frame pacing notes in 465b94f report about 280,000 emulated MONITORX/MWAITX exceptions per second on Intel while the title polls a layer-owned graphics fence. The current handler spins at each MWAITX, so a thread that cannot advance keeps reentering the exception handler.

With VICTORY_MONITOR_FENCE_WAIT=1, the GPU layer registers the exact address it exposes for a fence. MONITORX captures a generation ticket for a registered address, and MWAITX consumes it and can use WaitOnAddress with a requested 1 ms timeout. Publishing a fence value advances the generation and wakes the waiters. Capturing the generation before the wait handles a signal between MONITORX and MWAITX. The ticket owns the wake word independently of the fence so release and address reuse are safe. The handler never reads the guest-supplied address, falls back to the existing hint for unknown addresses or a busy registry, preserves Windows last error across the wait, and leaves the title's condition check in place. The switch is off by default.

On Windows with a Ryzen 5 5600, a synthetic producer issued 64 signals per run. The benchmark invoked the actual emulation functions directly:

Run Emulated pairs, off Emulated pairs, on Wall time, off / on
1 374,629 78 210.7 / 212.3 ms
2 368,799 73 214.2 / 212.6 ms

Both modes observed all 64 signals. The test counts emulation calls, not OS exceptions, and there is no in-game FPS claim. Core tests cover multiple armed waiters, release/reuse, and last error. The GPU fence test with the switch enabled verifies that the actual fence API registers and wakes a ticket and removes it on release.

For an in-game Intel A/B, compare MONITORX/MWAITX exceptions per second in the existing log, the new emulated fence wait counters, and frame times with otherwise identical settings.

AI-assisted.

The diagnostics application also passed cargo check --locked -p victory --features diagnostics.

<!-- greyfinch-sync:fxceless/victory-fork:issue:6608847280 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/1020). Originally posted by [Lkxex](https://github.com/Lkxex) on 2026-11-25T16:24:47Z. --- The frame pacing notes in 465b94f report about 280,000 emulated MONITORX/MWAITX exceptions per second on Intel while the title polls a layer-owned graphics fence. The current handler spins at each MWAITX, so a thread that cannot advance keeps reentering the exception handler. With VICTORY_MONITOR_FENCE_WAIT=1, the GPU layer registers the exact address it exposes for a fence. MONITORX captures a generation ticket for a registered address, and MWAITX consumes it and can use WaitOnAddress with a requested 1 ms timeout. Publishing a fence value advances the generation and wakes the waiters. Capturing the generation before the wait handles a signal between MONITORX and MWAITX. The ticket owns the wake word independently of the fence so release and address reuse are safe. The handler never reads the guest-supplied address, falls back to the existing hint for unknown addresses or a busy registry, preserves Windows last error across the wait, and leaves the title's condition check in place. The switch is off by default. On Windows with a Ryzen 5 5600, a synthetic producer issued 64 signals per run. The benchmark invoked the actual emulation functions directly: | Run | Emulated pairs, off | Emulated pairs, on | Wall time, off / on | | --- | ---: | ---: | ---: | | 1 | 374,629 | 78 | 210.7 / 212.3 ms | | 2 | 368,799 | 73 | 214.2 / 212.6 ms | Both modes observed all 64 signals. The test counts emulation calls, not OS exceptions, and there is no in-game FPS claim. Core tests cover multiple armed waiters, release/reuse, and last error. The GPU fence test with the switch enabled verifies that the actual fence API registers and wakes a ticket and removes it on release. For an in-game Intel A/B, compare MONITORX/MWAITX exceptions per second in the existing log, the new emulated fence wait counters, and frame times with otherwise identical settings. AI-assisted. The diagnostics application also passed cargo check --locked -p victory --features diagnostics.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/1020:upstream-pr/1020'
git switch 'upstream-pr/1020'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/1020'
git switch 'upstream-pr/1020'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/1020'
git switch 'upstream-pr/1020'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/1020'
git switch 'main'
git merge --squash 'upstream-pr/1020'
git switch 'main'
git merge --ff-only 'upstream-pr/1020'
git switch 'main'
git merge 'upstream-pr/1020'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
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.

Reference
fxceless/victory-fork!1018
No description provided.