HLE: constrain the title before suspending it (window close never suspended) #1080

Merged
giusepperainone merged 1 commit from upstream-pr/1080 into main 2026-11-25 00:09:30 +00:00
giusepperainone commented 2026-11-24 15:34:37 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by giusepperainone on 2026-11-24T15:34:37Z.


Closing the title's window never suspended Grand Theft Auto VI: every close logged title did not finish suspending in time; ending the title, one second later, so the title was always killed before its suspend completed (seen in passing in the logs of #417 and #784).

Cause

The title registers two life-cycle routines with the same context:

  • a suspend routine, through RegisterAppStateChangeNotification (HLE'd here);
  • a constrained-change routine, through RegisterAppConstrainedChangeNotification (api-ms-win-core-psm-appnotify-l1-1-1), which we did not HLE, so it bound to the host's version, which never calls it: a desktop app is never constrained.

On the console a title that is suspended is constrained first. The title relies on that: its suspend routine blocks until the title reaches a state that only its constrained routine starts (the constrained routine posts an event that the title's own loop turns into that state). Called alone, the suspend routine never returns.

How I narrowed it down, on a diagnostics build with local logging only:

  • with the deadline raised to 15 s the suspend routine still never returned while the title kept presenting at 30 fps, so it was waiting, not slow;
  • calling the two registered suspend routines in parallel instead of in turn changed nothing (the second one returns at once);
  • the stacks at the deadline showed the suspend routine's thread waiting on a semaphore of the title's state object, and following who signals it led to the routine registered through RegisterAppConstrainedChangeNotification.

Change

  • RegisterAppConstrainedChangeNotification / UnregisterAppConstrainedChangeNotification are HLE'd in lifecycle, with their own registry (same shape as the suspend one; the registration code is shared).
  • end_title runs the constrained-change routines (constrained) and then the suspend routines (quiesced), under the existing one-second deadline.

Results

Windows 11 26200, RTX 4060 Ti, ffe310e + this change, window closed from the account screen:

before after
close logged window closed: suspending the title routines=2 window closed: suspending the title constrained=1 routines=2
outcome title did not finish suspending in time after 1.0 s (also with the deadline at 15 s) title suspended after ~0.1 s

With the suspend completing, the title now reaches the command queue's suspend method (method not implemented object="command queue" slot=0xb8, already noted in queue.rs). It returns E_NOTIMPL and the title still finishes suspending; implementing it is left for a follow-up.

Testing

  • New: constrained_registrations_come_and_go, constrained_routines_run_before_suspend_routines (synthetic routines, no game data).
  • cargo clippy --workspace --all-targets --locked -- -D warnings, the same with --all-features, and cargo test --workspace --locked: all pass. cargo xtask policy: 154 files ok.
  • Not tested: resume (VIctory does not resume titles), relaunch through end_title, and other titles.

🤖 Generated with Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:issue:6585451644 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1080). Originally posted by [giusepperainone](https://github.com/giusepperainone) on 2026-11-24T15:34:37Z. --- Closing the title's window never suspended Grand Theft Auto VI: every close logged `title did not finish suspending in time; ending the title`, one second later, so the title was always killed before its suspend completed (seen in passing in the logs of #417 and #784). ## Cause The title registers two life-cycle routines with the same context: - a suspend routine, through `RegisterAppStateChangeNotification` (HLE'd here); - a constrained-change routine, through `RegisterAppConstrainedChangeNotification` (`api-ms-win-core-psm-appnotify-l1-1-1`), which we did not HLE, so it bound to the host's version, which never calls it: a desktop app is never constrained. On the console a title that is suspended is constrained first. The title relies on that: its suspend routine blocks until the title reaches a state that only its constrained routine starts (the constrained routine posts an event that the title's own loop turns into that state). Called alone, the suspend routine never returns. How I narrowed it down, on a diagnostics build with local logging only: - with the deadline raised to 15 s the suspend routine still never returned while the title kept presenting at 30 fps, so it was waiting, not slow; - calling the two registered suspend routines in parallel instead of in turn changed nothing (the second one returns at once); - the stacks at the deadline showed the suspend routine's thread waiting on a semaphore of the title's state object, and following who signals it led to the routine registered through `RegisterAppConstrainedChangeNotification`. ## Change - `RegisterAppConstrainedChangeNotification` / `UnregisterAppConstrainedChangeNotification` are HLE'd in `lifecycle`, with their own registry (same shape as the suspend one; the registration code is shared). - `end_title` runs the constrained-change routines (constrained) and then the suspend routines (quiesced), under the existing one-second deadline. ## Results Windows 11 26200, RTX 4060 Ti, `ffe310e` + this change, window closed from the account screen: | | before | after | |---|---|---| | close logged | `window closed: suspending the title routines=2` | `window closed: suspending the title constrained=1 routines=2` | | outcome | `title did not finish suspending in time` after 1.0 s (also with the deadline at 15 s) | `title suspended` after ~0.1 s | With the suspend completing, the title now reaches the command queue's suspend method (`method not implemented object="command queue" slot=0xb8`, already noted in `queue.rs`). It returns `E_NOTIMPL` and the title still finishes suspending; implementing it is left for a follow-up. ## Testing - New: `constrained_registrations_come_and_go`, `constrained_routines_run_before_suspend_routines` (synthetic routines, no game data). - `cargo clippy --workspace --all-targets --locked -- -D warnings`, the same with `--all-features`, and `cargo test --workspace --locked`: all pass. `cargo xtask policy`: 154 files ok. - Not tested: resume (VIctory does not resume titles), relaunch through `end_title`, and other titles. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
MichaelSmithAI commented 2026-11-24 16:05:22 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by MichaelSmithAI on 2026-11-24T15:47:06Z.


We tested the window-close path on Wine/GE 3.2 with a test-only fixture over a7847a5. A child process resolved both notification registrations through the guest HLE resolver with host fallback disabled. It registered the suspend callback first, then the constrained callback, and sent WM_SYSCOMMAND / SC_CLOSE to a hooked Win32 window.

The parent verified that the child exited successfully and that its trace contained exactly two callbacks, in this order: constrained with flag 1, then suspend with the quiesced flag 1. Registering them in the opposite order to delivery checks that the close path enforces the lifecycle order. All seven focused tests passed. On ffe310e, the same fixture stopped before creating the window because the guest resolver lacked RegisterAppConstrainedChangeNotification. This exercises synthetic guest callbacks; the account-screen shutdown timing comes from your native title run.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7136606320 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1080#issuecomment-7136606320). Originally posted by [MichaelSmithAI](https://github.com/MichaelSmithAI) on 2026-11-24T15:47:06Z. --- We tested the window-close path on Wine/GE 3.2 with a test-only fixture over `a7847a5`. A child process resolved both notification registrations through the guest HLE resolver with host fallback disabled. It registered the suspend callback first, then the constrained callback, and sent `WM_SYSCOMMAND / SC_CLOSE` to a hooked Win32 window. The parent verified that the child exited successfully and that its trace contained exactly two callbacks, in this order: constrained with flag 1, then suspend with the quiesced flag 1. Registering them in the opposite order to delivery checks that the close path enforces the lifecycle order. All seven focused tests passed. On `ffe310e`, the same fixture stopped before creating the window because the guest resolver lacked `RegisterAppConstrainedChangeNotification`. This exercises synthetic guest callbacks; the account-screen shutdown timing comes from your native title run.
Zipettte commented 2026-11-24 17:04:30 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Zipettte on 2026-11-24T16:29:53Z.


Tested on AMD Radeon RX 7700 XT (RDNA3, gfx1101), driver 32.0.32029.2010, Windows 11, Rust 1.98.1 MSVC at a7847a5: cargo test -p victory-hle passes, 97 passed / 0 failed. Workspace baseline on main (ffe310e) is green on the same machine (342 passed).

Tested with AI assistance (Claude).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7137757652 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1080#issuecomment-7137757652). Originally posted by [Zipettte](https://github.com/Zipettte) on 2026-11-24T16:29:53Z. --- Tested on AMD Radeon RX 7700 XT (RDNA3, gfx1101), driver 32.0.32029.2010, Windows 11, Rust 1.98.1 MSVC at a7847a5: `cargo test -p victory-hle` passes, 97 passed / 0 failed. Workspace baseline on main (ffe310e) is green on the same machine (342 passed). _Tested with AI assistance (Claude)._
mercuryVM commented 2026-11-24 21:01:54 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by mercuryVM on 2026-11-24T20:38:29Z.

Review: APPROVED


Tested a7847a52 on Windows 11, RTX 5070, MSVC:

  • cargo test -p victory-hle passes on the head (96 passed).
  • Merged into our fork: workspace tests and shader tests are clean.
  • I didn't close a running title to watch the suspend itself.

The change is right:

  • RegisterAppConstrainedChangeNotification lives in the same api-ms-win-core-psm-appnotify-* set the module already binds, so the wildcard picks the new exports up.
  • Running the constrained routines before the suspend routines matches the order the console uses.
  • Sharing one id counter between the two lists keeps the unregistration ids distinct.

AI-assisted (Claude Code).

<!-- greyfinch-sync:Marvisak/VIctory:review:6047019691 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1080#pullrequestreview-6047019691). Originally posted by [mercuryVM](https://github.com/mercuryVM) on 2026-11-24T20:38:29Z. **Review:** APPROVED --- Tested a7847a52 on Windows 11, RTX 5070, MSVC: - `cargo test -p victory-hle` passes on the head (96 passed). - Merged into our fork: workspace tests and shader tests are clean. - I didn't close a running title to watch the suspend itself. The change is right: - `RegisterAppConstrainedChangeNotification` lives in the same `api-ms-win-core-psm-appnotify-*` set the module already binds, so the wildcard picks the new exports up. - Running the constrained routines before the suspend routines matches the order the console uses. - Sharing one id counter between the two lists keeps the unregistration ids distinct. AI-assisted (Claude Code).
upstream-sync closed this pull request 2026-11-25 01:05:29 +00:00
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
Marvisak/VIctory!1080
No description provided.