Skip to content

Rosetta direct path: run the guest off the main thread so the game window opens - #425

Merged
RINNECODER merged 1 commit into
mainfrom
rosetta/game-window
Oct 12, 2026
Merged

RINNECODER merged 1 commit into
mainfrom
rosetta/game-window

Conversation

@RINNECODER

Copy link
Copy Markdown
Owner

Root cause

Aps5StartGuest (libkernel, Rosetta runtime) called the guest entry point on the process main thread, and the guest never returns to the run loop. DirectDisplayWindow (#397) creates its AppKit window + CAMetalLayer with dispatch_async(dispatch_get_main_queue(), ...), so that block never ran. Frames went to the offscreen layer forever, which is why frame capture still saw them. Nothing set up NSApplication either, so the process had no Dock icon and no menu bar. A launched title ran with zero windows (CGWindowList).

Fix (Apple x86_64 direct path only; fork-only files or the Darwin runtime)

  • libkernel Aps5StartGuest: if Aps5RunHostApplication_nid_no_patch is loaded (libSceVideoOut), it takes over the main thread and the guest starts on a detached thread. That thread gets the main thread's stack size (at least 8 MiB) and user-interactive QoS. Guest TLS is allocated lazily per thread and the fault handler's alternate stack is per thread, so nothing depends on the main thread (pthread_main_np is unused in the runtime, and thread stacks come from pthread_get_stack*_np). Titles without VideoOut, such as the runtime test fixtures, still run on the main thread. APS5_ROSETTA_GUEST_ON_MAIN_THREAD=1 brings back the old behaviour.
  • libSceVideoOut DirectHostApplication.mm (new, fork-only): sets up NSApplication. The activation policy is regular, or accessory under ANYPS5_UNOBTRUSIVE_WINDOWS. The title and icon0 come from the app metadata, read on the main thread before the guest starts. The menu bar has Hide, Quit (Cmd-Q), Toggle Full Screen (Ctrl-Cmd-F), Minimize and Zoom. Then the AppKit run loop starts. A quit that arrives before the window exists ends the game. ANYPS5_ROSETTA_HEADLESS=1 only services the main queue.
  • DirectDisplayWindow: the window still opens when VideoOut opens (presentLoop Ensure). It is now titled with the game's title and sized to the output at one point per backing pixel, scaled to fit the screen, so the drawable is Retina-sized. It is centred, aspect-locked, full-screen capable (green button / Ctrl-Cmd-F) and activated ([NSApp activate] on macOS 14+). Closing the window, or Cmd-Q (the window delegate turns it into a close request), ends the game with exit code 0, and the launcher forwards that exit.
  • NativeHostWindow: adds an opt-in WindowConfiguration::gameWindow (centre, FullScreenPrimary, content aspect ratio). Existing callers are unchanged.

Evidence (reference title through bin/anyps5_rosetta_run, run the way MacPS runs it)

  • Cold (relink included): the guest entered at 55.7 s and a window owned by the eboot PID was on screen 1.1 s later (56.7 s after launch). It had the game's title, activation policy regular, and was active.
  • Warm: window on screen 1.7 s after launch, 0.3 s after guest entry.
  • Window-only screenshots (screencapture -l <id>) show the game's "Choose Your Display Options" screen in the window from about 45 s after it opened.
  • Quit (the quit Apple event, the same terminate: path as Cmd-Q) logged [videoout] the game window was closed: ending the game. The eboot was gone 0.23 s later, with guest_exit exit_code 0 and launcher exit 0.
  • Frame capture still writes frames.
  • New rosetta_direct_host_window test (x86_64): it opens VideoOut from a guest thread while the main thread is in the host application. It checks that a window owned by the process is on screen (CGWindowList, about 0.12 s), that the title, full-screen behaviour, activation policy and Quit / Toggle Full Screen items are right, and that closing the window and quitting each exit 0 (checked in child processes). It passes under ctest (unobtrusive) and when run directly (default etiquette).
  • ctest -L rosetta (threads, fault, launcher smoke, launcher tests, lib binds) and rosetta_direct_graphics pass.

Not covered: the full-screen toggle was not exercised on the title, only its menu item and the window behaviour. Input in the window is unchanged; separate work covers it.

🤖 Generated with Claude Code

https://claude.ai/code/session_01DgW4n3qYgi5jAAohEmXRQj

…ndow opens

A relinked title ran its guest entry on the process main thread, which never
returned to the run loop, so DirectDisplayWindow's main-queue window creation
never ran and the process never became a GUI app: no window, no Dock icon.

- libkernel Aps5StartGuest: when libSceVideoOut is loaded, hand the main thread
  to its host application and start the guest on a detached thread with the
  main thread's stack size (>= 8 MiB) and user-interactive QoS; guest TLS and
  fault reports are per thread already. APS5_ROSETTA_GUEST_ON_MAIN_THREAD=1
  keeps the old behaviour; titles without VideoOut are unchanged.
- libSceVideoOut DirectHostApplication (fork-only): NSApplication with a
  regular activation policy (accessory under ANYPS5_UNOBTRUSIVE_WINDOWS), the
  game's title and icon, a menu bar with Quit, Toggle Full Screen
  (Ctrl-Cmd-F) and Minimize, then the AppKit run loop. Headless runs only
  service the main queue.
- DirectDisplayWindow: the window opens with VideoOut, titled with the game's
  title, sized to the output at one point per backing pixel (scaled to fit
  the screen), centred, full-screen capable, aspect-locked, activated; closing
  it or quitting ends the game with exit code 0.
- rosetta_direct_host_window test: VideoOut opened from a guest thread with
  the main thread in the host application puts a window on screen
  (CGWindowList); closing it and quitting each exit 0.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DgW4n3qYgi5jAAohEmXRQj
@coderabbitai

coderabbitai Bot commented Oct 12, 2026

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 67ca3872-be2c-45ac-be8a-1b775041857a

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 12, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-12T07:17:55.584176Z 7d093d7 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@RINNECODER
RINNECODER merged commit cc4fb5e into main Oct 12, 2026
6 checks passed
@RINNECODER
RINNECODER deleted the rosetta/game-window branch October 12, 2026 07:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant