Repository navigation
Rosetta direct path: build libSceAgc, libSceAgcDriver and libSceVideoOut on Metal for x86_64 - #397
Conversation
… Metal for x86_64 Phase 3 (graphics) of the Rosetta direct path. Under ANYPS5_ROSETTA_LIBS the three graphics libraries now build for x86_64 and are NID-patched like the rest; they are no longer in ANYPS5_ROSETTA_EXCLUDED_LIBS. A fork-only cmake/RosettaGraphics.cmake defines libSceAgcDriver from the upstream exports that do not need the Vulkan driver (Eq, Resource, State, Submit) plus the fork's native Metal execution, the SPIR-V to MSL bridge (SPIRV-Cross) and the shader recompiler, all built for x86_64. libSceVideoOut keeps its upstream sources except the SDL window; libSceAgc builds from its upstream CMakeLists. AnyPS5Utilities.metallib is copied next to the libraries. Guest pointers are host pointers on this path, so there is no TCG translation: - DirectDriver.mm configures the Metal driver on first use (system device, utility metallib, EOP interrupts to the AGC event queues) and hands it the libc guest allocation registry as identity BorrowedRanges, refreshed when the registry generation changes. - NativeGuestMemory gets an optional process-wide range provider, so guest threads validating buffers outside a driver scope resolve against the same identity ranges. Without a provider (core/cpu) nothing changes. - Submission descriptors are read as host pointers; host-built command words (VideoOut's flip packet on a thread stack) are staged in a driver-owned range. - DirectDisplayWindow.mm replaces the SDL window with the native host window (AppKit + CAMetalLayer), created and pumped on the main dispatch queue, with an offscreen CAMetalLayer until it exists. SDL keeps game controllers on its offscreen video driver. Frame capture (ANYPS5_FRAME_CAPTURE_DIR) is unchanged. rosetta_direct_graphics_tests (arch -x86_64) maps direct memory through libkernel, checks it is an identity range, submits a DMA_DATA clear through sceAgcDriverSubmitMultiDcbs, flips it into the native window through libSceVideoOut and checks the captured PNG shows the clear colour. metal_utility_tests is built x86_64 in the same configuration. The CI Rosetta job initializes the graphics submodules and runs both. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DgW4n3qYgi5jAAohEmXRQj
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars. ⚙️ Run configuration
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. Comment |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
…stroy Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1e9c19ced0
ℹ️ 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".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if (!state.configured) { | ||
| Configure(state, driver, ranges); | ||
| } else if (ranges != state.applied) { | ||
| driver.ReplaceBorrowedRanges(*ranges, ++state.driverGeneration); |
There was a problem hiding this comment.
Synchronize registry mutations before replacing borrowed ranges
When guest memory is unmapped or protected after a submission, this refresh happens only on the next non-worker driver entry, after the CPU mapping mutation has already completed. IdentityRanges() discards the GuestAllocationsAcquire_nid_postfix() lease and retains only raw spans, so GuestAllocationsRequireUnpinned_nid_postfix() cannot detect pending Metal work; a worker can consequently access pages that have already been unmapped or had their permissions changed. Mapping changes need to enter the driver through the mutation transaction before the host mapping is modified, with the allocation owner/lease retained until prior work drains.
Useful? React with 👍 / 👎.
| std::lock_guard lock(live->mutex); | ||
| if (!live->window) return; | ||
| try { | ||
| live->window->PumpMainThread(std::chrono::milliseconds(0)); |
There was a problem hiding this comment.
Drain native events into the input and close flow
For a non-headless direct-path window, this timer pumps AppKit but never calls NativeHostWindow::DrainEvents(). NativeHostWindow stores keyboard, mouse, and CloseRequested events in its private queue, while the existing VideoOut loop only consumes SDL events from the offscreen SDL driver; therefore keyboard/mouse input never reaches the guest, and clicking the close button is ineffective because windowShouldClose returns NO after merely enqueueing the request. The pumped native events must be drained and routed to the guest input and process-exit handling.
Useful? React with 👍 / 👎.
| std::lock_guard lock(state->mutex); | ||
| state->window = std::move(window); |
There was a problem hiding this comment.
Recheck destruction before publishing the async window
If Destroy() runs after the initial destroyed check but while CreateMainThread() is creating the window, it marks the state destroyed, observes no installed window, and returns; this code then installs and resumes a window in the abandoned state without rechecking the flag. Once the queued block releases its last shared_ptr, destruction of that still-open NativeHostWindow invokes its terminate guard, so a rapid startup/shutdown can abort the process. Recheck destroyed under this lock and close the newly created window instead of publishing it.
Useful? React with 👍 / 👎.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Summary
Phase 3 (graphics) of the Rosetta direct path (
docs/design/rosetta-direct-execution.md). With-DANYPS5_ROSETTA_LIBS=ON -DCMAKE_OSX_ARCHITECTURES=x86_64, libSceAgc, libSceAgcDriver and libSceVideoOut now build for x86_64 on the fork's Metal backend and are NID-patched. They are removed fromANYPS5_ROSETTA_EXCLUDED_LIBS(first line only).cmake/RosettaGraphics.cmake(fork-only, included byRosettaLibs.cmake):libSceAgcDriveris built from the upstream exports that do not need the Vulkan driver (Eq, Resource, State, Submit), plus the native Metal execution set (the same oneMetalReplaylinks), the SPIR-V to MSL bridge (SPIRV-Cross) and the shader recompiler, all built for x86_64.libSceVideoOutkeeps its upstream sources except the SDL window.libSceAgcbuilds from its upstream CMakeLists through the generic loop.AnyPS5Utilities.metallibis copied next to the libraries.Execution/Metal/DirectDriver.mm, fork-only):BorrowedRanges. The ranges are refreshed when the registry generation changes.MetalGuestHostAliasesthen aliases those host pages with no copy.NativeGuestMemorygets an optional process-wide range provider. Guest threads that validate buffers outside a driver scope (for example VideoOut buffer registration or multi-submit arrays) resolve against the same identity ranges. There is no provider in core/cpu, so its behaviour is unchanged.libSceVideoOut/src/DirectDisplayWindow.mm(fork-only) replaces the SDL window:CAMetalLayer), created and pumped asynchronously on the main dispatch queue.CAMetalLayer.ANYPS5_FRAME_CAPTURE_DIRcapture works unchanged.EntryPoints.cpphas new lines inside the existingANYPS5_METAL_BACKENDblocks, underANYPS5_ROSETTA_DIRECT.MetalHostExports.cpphas itsmmapstub guarded.MetalDrivergetsOnDriverWorkerThread().metal_utility_testsandrosetta_direct_graphics_testsand runs them.Evidence (local, macOS arm64 host, x86_64 build, run under
arch -x86_64)Build:
cmake --build … --target libSceAgcDriver libSceAgc libSceVideoOut rosetta_patch_libSceAgcDriver rosetta_patch_libSceAgc rosetta_patch_libSceVideoOut rosetta_metallibsucceeded, with no undefined symbols in the three libraries:New direct-path test (
ctest -R rosetta_direct_graphics: Passed):Existing Metal fixtures built for x86_64 in this configuration:
metal_utility_testspassed. That covers texture detile, colour transfer, mesh arguments, sample counter, presentation, guest memory, converted shader pipeline and shader alignment.Not in this PR / blocked elsewhere
libc.prxis missingGuestArenaCommit/Reset_nid_postfix; unitdepsis fixing this.libkernel.prxhas an inline-asm call toAps5GetcontextFinish_nid_no_patchthat is missing the Mach-O_prefix (UserContext.cpp).libkernel.prxandlibScePad.prx, failsdlopenwithSymbol not found: ___stack_chk_guard(bound tolibc.prx, whose export the patcher renames). That is runtime/patcher work. The in-process test links the unpatched builds.ANYPS5_METAL_GUEST_REPLAY) belong to the utilities-only build mode and are not built here.🤖 Generated with Claude Code
https://claude.ai/code/session_01DgW4n3qYgi5jAAohEmXRQj