Skip to content

feat(aot): run source-built graphics on native Apple ARM64 - #3891

Closed
yabanana wants to merge 46 commits into
boykopovar:mainfrom
yabanana:feature/aot-native-graphics
Closed

yabanana wants to merge 46 commits into
boykopovar:mainfrom
yabanana:feature/aot-native-graphics

Conversation

@yabanana

@yabanana yabanana commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

What

Run the public SDK's source-built gpu_cube through the AOT compiler and a native Apple ARM64 runtime, with a reproducible graphics comparison. The generated program contains the translated CPU functions and native import implementations; it has no Rosetta dependency, x86 interpreter, runtime decoder or JIT. Graphics continues to use Vulkan/MoltenVK.

This is a draft follow-up to #1835, kept separate from that PR. It contains:

  • Hash-bound ABI, layout and memory contracts for the fixture, with native pointer checks and conservative alias invalidation.
  • Whole-program AOT compilation of all 14 declared functions and linking against the required native providers.
  • The native graphics runtime built from the existing system libraries and shader recompiler, with native clock/TLS support and platform regressions.
  • A source builder, an independent C-compiled ARM64 reference, and one acceptance target checking 600 completed flips, teardown and eight exact 1920x1080 RGB comparisons. Missing, stale, blank or frozen captures fail. Link manifests bind both binaries to their objects and runtime archives.

The shared macOS foundation is reused from mugurc/AnyPS5 macos-port at 21930ce5045b900282855fdc55d19714b155659d, with its provenance retained. Its fresh-page write-watch behavior and regression cases depend on #3703. The remaining integration changes include macOS stdio macros/socket polling and the missing shared-pointer compare/exchange operation. @mugurc: the intent is to keep this platform code shared, not establish another macOS implementation.

The fixture explicitly corrects SDK API/layout declarations, depth setup and buffer-reuse synchronization. Its licensed, pinned .sb shader containers are reused, not regenerated from PSSL. The reference retains the source compiler's contracted constant folding while separating runtime multiply/add operations to match the input's SSE2 arithmetic. This avoids a 2-ULP projection difference without relaxing image equality. All changes and the reproduction command are documented in docs/dev/BUILD.md under “Source-built native ARM64 graphics fixture”.

The generic compiler/runtime changes are separate from the hash-qualified example annotations. This establishes one homebrew graphics path, not general ABI recovery, PS5 game compatibility, a complete ARM64 port or a speedup. The in-tree architecture decision remains with the maintainers; this draft provides runnable evidence for that discussion.

Current-main integration

Head 798fb84e2 is a consolidated commit directly on main b42ef24e0. It replaces the historical macOS merge chain; the required macOS library/runtime changes that have not landed upstream are still present and will be removed from the diff as their focused PRs land. #1835 remains a prerequisite. The merged #3703 implementation comes from main.

The overlapping constant-folder change preserves both upstream starting-quad folding and the qualified wave64 vertex/32-lane-host rule. Shader validation remains unchanged. The cube's atexit/exit source evidence has been requalified against the new Process.cpp delegation, with RuntimeSupport.cpp pinned as an additional dependency. Registration changes only private host state and invokes callbacks later at finalization.

Upstream now asserts x87 long-double storage in Math.cpp. The optional ARM64 graphics closure excludes this translation unit rather than weaken that ABI assertion; its other math providers are also unavailable until the x87 code is separated. The qualified cube does not import them. macOS guest-image flexible-memory accounting remains explicitly unsupported and throws; the cube uses direct memory.

Tested

Latest integration checkpoint (12 October): aligned with main 2f4cc8983, including the new component technical-debt layout. The final combined stack with the separate C++ follow-up #4718 passed 588 compiler/relinker/runtime checks and 26 native integrations on Apple Silicon. Rebuilt cube AOT/reference still match all eight RGB frames after 600 flips each; controller and typed module-bundle acceptance pass. These are local results; hosted CI is running on the updated head. Full Linux/Windows builds still require maintainer dispatch.

Integration checkpoint, 12 October: merged main fe66af13e through the dependency stack and requalified affected provider identities after reviewing their implementations. The final combined stack passed 526 compiler/relinker/runtime cases, 26 native integration cases, the rebuilt graphics pair (600 flips each, teardown, eight exact RGB frames), controller O2 and SHA/memcmp O0/O2 checks on Apple Silicon. Hosted checks refer to the new head and remain separate from these local results. Full Linux/Windows builds require maintainer dispatch.

Apple M5 Max, macOS 27.2, Apple clang 21.0.0 (clang-2100.3.34.2), MoltenVK 1.4.2:

  • Runtime rebuilt from source in a fresh build directory with the pinned dependencies already checked out.
  • AOT and reference: ARM64-only binaries, sysctl.proc_translated=0, 600 completed flips each, exit 0 and teardown.
  • Eight captures per executable, 1920x1080, zero differing RGB pixels in all eight comparisons.
  • 441 compiler/relinker/minimal-runtime CTest cases passed; all 18 native integration cases passed. The graphics runtime was rebuilt in a fresh build directory on the current main base.
  • Shared-pointer ownership/aliasing and 80,000 concurrent updates pass in this run; the earlier ASan/UBSan and ThreadSanitizer evidence is unchanged and was not rerun for this rebase.
  • Conventions and native test registration checks passed.

CI for the rewritten head is pending. Earlier green checks do not validate this head. The graphical desktop acceptance is local evidence; full Linux/Windows runtime jobs require a maintainer to dispatch Build on main with pr=3891.

After the documented dependency/environment setup:

cmake -S . -B build-graphics -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_OSX_ARCHITECTURES=arm64 -DANYPS5_NATIVE_AOT=ON -DANYPS5_NATIVE_GRAPHICS=ON -DBUILD_TESTING=OFF
cmake --build build-graphics --target native_gpu_cube_check --parallel 6

Checklist

This was referenced Oct 15, 2026
@yabanana

Copy link
Copy Markdown
Contributor Author

Superseded by #5021, which now contains the consolidated native ARM64 AOT implementation and verified consumers. #1835 remains the architecture discussion. Closing this stacked PR to keep one implementation review; its branch and review history are retained. This is not a merge into main.

@yabanana yabanana closed this Oct 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agc libSceAgc* build ci .github docs libc libkernel needs rebase Conflicts with main, rebase needed prx relinker shader core/shader

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants