arm64 run: the recompiled title boots to its intro; recompiler fixes, main merged in #115

Open
thebcd69 wants to merge 254 commits from upstream-pr/115 into native/arm64-run
thebcd69 commented 2026-11-26 17:15:14 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by thebcd69 on 2026-11-26T17:15:14Z.


What this is

The arm64 run (native/arm64-run, b11a2f2) brought up to main (3fd73fd) and taken further on an M5 Max: the title's exe and DLLs lifted to C with victory-recomp lift-split, built for arm64 (no Rosetta) and run with VICTORY_LIFT_DIR. It now boots, reads its packs through DirectStorage, translates its shaders ahead and presents the intro at 30 fps (the first frame drawn by the arm64 build). Each run stopped at a recompiler gap; the fixes are below, each with its own test.

Recompiler (crates/victory-recomp)

  • escapes <pe> [seeds]: direct targets that a linear sweep of each function finds outside every function (a thunk's target, a switch case that tail-calls), to feed back as seeds (lift-split <pe> <dir> 2000 <seeds>). 481 for the title's exe.
  • Jump-table sizes: the range check counts only when it tests the index's own value (value numbering through plain copies; a check of a value changed after it, of another register, or across a branch target no longer bounds the table); MSVC two-level switches are bounded by their byte table; a table ends where the function's next table starts. tablelist compares two builds: 208 of the exe's 3434 tables changed (f_53bf950 went from 7 to 8 cases, the trap that stopped a run).
  • A jump through a register is a table's only if the table's load and add reach it: virtual calls in tail position right after a switch got the switch's cases (8 in the exe) and trapped.
  • Tables of 64-bit addresses (jmp qword ptr [base + 8*idx], an interpreter's dispatch): one switch per function after its body.
  • Inner entries: a direct jump or call into the middle of another function gets an f_<rva> that enters the same body at its label.
  • Polling loops on a stack slot (mov eax, [rsp + 0x48] / cmp eax, 8 / jne: a waiter spinning on a counter its workers raise through its address) read the slot as a shared access; as a plain stack access clang had made the loop b .. pause lifts to yield with a memory clobber.

Runtime, HLE, native host

  • arm64 ABI: HLE functions are extern "efiapi", method tables go through fn_addr!, the x86-only dump and write-trap code is gated.
  • Native host: page tables are kept current in place from the pool's change journal instead of being rebuilt on every mapping change (the rebuilds stalled submissions, and a retired table could still be read by the GPU). Title-lock holds over 200 ms are logged.
  • From the earlier Rosetta work: pool spans across contiguous mappings, crash reports outside the title lock, fewer pool snapshots per submission, shaders translated ahead on threads of their own, indirect dispatch fixes, live keyboard, mouse and pads.

Shader translator

  • wave64 ds_bpermute_b32 stays inside its 32-lane half (RDNA2 ISA 10.4.4), so it needs no exchange between host waves and is no longer refused in divergent code.
  • Comparison immediate samplers clear the reduction bits; SDWA sign extension of 16-bit results; BC7 rotation is read only in modes 4 and 5.
  • After merging main: one v_mad_u32_u16 lowering (main's) and one s_pack_* lowering; both branches had added them.

Merging main

Conflicts: UCRT ilogb (main's NaN case, in extern "efiapi"), and a native.rs test (this branch accepts root constants in compute shaders, so type 0 is left out of main's refused-types list).

Tests

victory-recomp lib 13/13, victory-shader 235/235, victory-hle 233/235 (the GameInput live-controller and XPackage completed-installation tests fail the same way without these changes).

Building the lift

victory-recomp lift-split <exe> <dir> 2000 [seeds], each unit built with clang -arch arm64 -O2 -ffp-contract=off -mcpu=apple-m1 -mllvm -disable-machine-sink -mllvm -enable-misched=false -DRT_TSO and linked with -dynamiclib -Wl,-undefined,dynamic_lookup; the runtime is rt_host.c with -DRT_MULTI. Title-specific seeds are not in the tree (escapes produces them).

🤖 Generated with Claude Code

https://claude.ai/code/session_01BotUDcRjHo3zJ1HWdpX4mk

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:issue:5514344393 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/115). Originally posted by [thebcd69](https://github.com/thebcd69) on 2026-11-26T17:15:14Z. --- ## What this is The arm64 run (`native/arm64-run`, b11a2f2) brought up to `main` (3fd73fd) and taken further on an M5 Max: the title's exe and DLLs lifted to C with `victory-recomp lift-split`, built for arm64 (no Rosetta) and run with `VICTORY_LIFT_DIR`. It now boots, reads its packs through DirectStorage, translates its shaders ahead and presents the intro at 30 fps (the first frame drawn by the arm64 build). Each run stopped at a recompiler gap; the fixes are below, each with its own test. ## Recompiler (`crates/victory-recomp`) - **`escapes <pe> [seeds]`**: direct targets that a linear sweep of each function finds outside every function (a thunk's target, a switch case that tail-calls), to feed back as seeds (`lift-split <pe> <dir> 2000 <seeds>`). 481 for the title's exe. - **Jump-table sizes**: the range check counts only when it tests the index's own value (value numbering through plain copies; a check of a value changed after it, of another register, or across a branch target no longer bounds the table); MSVC two-level switches are bounded by their byte table; a table ends where the function's next table starts. `tablelist` compares two builds: 208 of the exe's 3434 tables changed (f_53bf950 went from 7 to 8 cases, the trap that stopped a run). - **A jump through a register is a table's only if the table's load and add reach it**: virtual calls in tail position right after a switch got the switch's cases (8 in the exe) and trapped. - **Tables of 64-bit addresses** (`jmp qword ptr [base + 8*idx]`, an interpreter's dispatch): one switch per function after its body. - **Inner entries**: a direct jump or call into the middle of another function gets an `f_<rva>` that enters the same body at its label. - **Polling loops on a stack slot** (`mov eax, [rsp + 0x48]` / `cmp eax, 8` / `jne`: a waiter spinning on a counter its workers raise through its address) read the slot as a shared access; as a plain stack access clang had made the loop `b .`. `pause` lifts to `yield` with a memory clobber. ## Runtime, HLE, native host - arm64 ABI: HLE functions are `extern "efiapi"`, method tables go through `fn_addr!`, the x86-only dump and write-trap code is gated. - Native host: page tables are kept current in place from the pool's change journal instead of being rebuilt on every mapping change (the rebuilds stalled submissions, and a retired table could still be read by the GPU). Title-lock holds over 200 ms are logged. - From the earlier Rosetta work: pool spans across contiguous mappings, crash reports outside the title lock, fewer pool snapshots per submission, shaders translated ahead on threads of their own, indirect dispatch fixes, live keyboard, mouse and pads. ## Shader translator - wave64 `ds_bpermute_b32` stays inside its 32-lane half (RDNA2 ISA 10.4.4), so it needs no exchange between host waves and is no longer refused in divergent code. - Comparison immediate samplers clear the reduction bits; SDWA sign extension of 16-bit results; BC7 rotation is read only in modes 4 and 5. - After merging `main`: one `v_mad_u32_u16` lowering (main's) and one `s_pack_*` lowering; both branches had added them. ## Merging `main` Conflicts: UCRT `ilogb` (main's NaN case, in `extern "efiapi"`), and a `native.rs` test (this branch accepts root constants in compute shaders, so type 0 is left out of main's refused-types list). ## Tests victory-recomp lib 13/13, victory-shader 235/235, victory-hle 233/235 (the GameInput live-controller and XPackage completed-installation tests fail the same way without these changes). ## Building the lift `victory-recomp lift-split <exe> <dir> 2000 [seeds]`, each unit built with `clang -arch arm64 -O2 -ffp-contract=off -mcpu=apple-m1 -mllvm -disable-machine-sink -mllvm -enable-misched=false -DRT_TSO` and linked with `-dynamiclib -Wl,-undefined,dynamic_lookup`; the runtime is `rt_host.c` with `-DRT_MULTI`. Title-specific seeds are not in the tree (`escapes` produces them). 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01BotUDcRjHo3zJ1HWdpX4mk
LakshanSivakumar commented 2026-11-26 18:57:16 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by LakshanSivakumar on 2026-11-26T18:57:16Z.

Review: CHANGES_REQUESTED


Thanks, getting the intro drawn by the arm64 build is a big step. This branch is now 137 commits behind main and conflicts with it, so I can't test it as it stands. Could you merge main again? While you're at it:

  • The page-table change (kept current in place from the pool's change journal) touches the native host's core path for everyone, not only arm64. If it can go in as its own PR with a test that shows a retired table is no longer read, it will be much easier to review and land first.
  • The description says victory-hle is 233/235 with the GameInput and XPackage tests failing "the same way without these changes". On main those pass on macOS x86_64 here, so please check them again after the merge.

Splitting the recompiler (victory-recomp and its fixtures) from the runtime/HLE/host changes would also help a lot.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:review:6079238390 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/115#pullrequestreview-6079238390). Originally posted by [LakshanSivakumar](https://github.com/LakshanSivakumar) on 2026-11-26T18:57:16Z. **Review:** CHANGES_REQUESTED --- Thanks, getting the intro drawn by the arm64 build is a big step. This branch is now 137 commits behind main and conflicts with it, so I can't test it as it stands. Could you merge main again? While you're at it: - The page-table change (kept current in place from the pool's change journal) touches the native host's core path for everyone, not only arm64. If it can go in as its own PR with a test that shows a retired table is no longer read, it will be much easier to review and land first. - The description says victory-hle is 233/235 with the GameInput and XPackage tests failing "the same way without these changes". On main those pass on macOS x86_64 here, so please check them again after the merge. Splitting the recompiler (victory-recomp and its fixtures) from the runtime/HLE/host changes would also help a lot.
AnastasisKon commented 2026-11-27 09:36:13 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by AnastasisKon on 2026-11-27T09:36:13Z.


Answers to the review: (1) the texture view is created eagerly per typed/structured entry in write_typed_buffer (gfx.rs), but zero-copy — it shares the pool MTLBuffer's pages and is not added to the residency set, so GPU-memory cost is one small MTLTexture object per entry, not per-entry pages; count/time/footprint measurement needs a Mac run, which I'll do before merge. Lazy creation would need the translator to mark format-accessed entries and an entry rewrite before bind — possible follow-up, not done here. (2) A view whose offset is not a multiple of minimumTextureBufferAlignmentForPixelFormat(pf).max(elem_bytes) falls back to a plain buffer entry (no textureViewID); nothing crashes, the store is lost as before. (3) The view's texture_buffer format carries only lane width; SINT→UINT there is deliberate (same 32-bit lanes). The converter takes the integer kind from the DXIL type (the GFX10 format field, buffer_format → Numeric), not from the view. (4) Scanned the diff: no converter listings or application content in the repo or comments; test descriptors are synthetic.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7214875464 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/115#issuecomment-7214875464). Originally posted by [AnastasisKon](https://github.com/AnastasisKon) on 2026-11-27T09:36:13Z. --- Answers to the review: (1) the texture view is created eagerly per typed/structured entry in write_typed_buffer (gfx.rs), but zero-copy — it shares the pool MTLBuffer's pages and is not added to the residency set, so GPU-memory cost is one small MTLTexture object per entry, not per-entry pages; count/time/footprint measurement needs a Mac run, which I'll do before merge. Lazy creation would need the translator to mark format-accessed entries and an entry rewrite before bind — possible follow-up, not done here. (2) A view whose offset is not a multiple of minimumTextureBufferAlignmentForPixelFormat(pf).max(elem_bytes) falls back to a plain buffer entry (no textureViewID); nothing crashes, the store is lost as before. (3) The view's texture_buffer format carries only lane width; SINT→UINT there is deliberate (same 32-bit lanes). The converter takes the integer kind from the DXIL type (the GFX10 format field, buffer_format → Numeric), not from the view. (4) Scanned the diff: no converter listings or application content in the repo or comments; test descriptors are synthetic.
LakshanSivakumar commented 2026-11-27 10:32:07 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by LakshanSivakumar on 2026-11-27T10:32:07Z.


This comment is on #115, but its text answers my review of #278 (typed and structured buffer views). Please post it on #278, and note that #278 belongs to Sheffy007: if you are not its author, please say that these are your reading and not the author's.

It is also not the measurement I asked for there. "I'll measure before merge" is not a count of the entries that get a texture in a world run, the time to mirror, and the process footprint before and after.

For #115 itself my questions from yesterday are still open: merge main again, split the page-table change into its own pull request, check the victory-hle tests again after the merge, and split the recompiler from the runtime.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7216000124 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/115#issuecomment-7216000124). Originally posted by [LakshanSivakumar](https://github.com/LakshanSivakumar) on 2026-11-27T10:32:07Z. --- This comment is on #115, but its text answers my review of #278 (typed and structured buffer views). Please post it on #278, and note that #278 belongs to Sheffy007: if you are not its author, please say that these are your reading and not the author's. It is also not the measurement I asked for there. "I'll measure before merge" is not a count of the entries that get a texture in a world run, the time to mirror, and the process footprint before and after. For #115 itself my questions from yesterday are still open: merge main again, split the page-table change into its own pull request, check the victory-hle tests again after the merge, and split the recompiler from the runtime.
Hayyan612 commented 2026-11-27 13:47:49 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by Hayyan612 on 2026-11-27T13:47:49Z.


Hi @thebcd69, a note on the review's first point, in case it saves you work: since that review, main fixed the retired-table read itself in 1c6bee8f ("a page table lives until the GPU ran the work submitted with it": tables are backend-owned buffers that submissions keep alive). So what's left to split out of this PR is the in-place update from the pool's change journal and the title-lock hold logging, which is the performance part.

If it helps with the merge of main (it conflicts in about 30 files now), I'm happy to help; I'd only start if you're OK with that, so we don't collide with your own update.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7219954850 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/115#issuecomment-7219954850). Originally posted by [Hayyan612](https://github.com/Hayyan612) on 2026-11-27T13:47:49Z. --- Hi @thebcd69, a note on the review's first point, in case it saves you work: since that review, main fixed the retired-table read itself in 1c6bee8f ("a page table lives until the GPU ran the work submitted with it": tables are backend-owned buffers that submissions keep alive). So what's left to split out of this PR is the in-place update from the pool's change journal and the title-lock hold logging, which is the performance part. If it helps with the merge of main (it conflicts in about 30 files now), I'm happy to help; I'd only start if you're OK with that, so we don't collide with your own update.
Hayyan612 commented 2026-11-27 20:38:01 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by Hayyan612 on 2026-11-27T20:38:01Z.


@thebcd69, I ran FEX-Emu's x86-64 instruction tests (unittests/ASM, MIT, checked out outside the repo) through victory-recomp at 4aae3061: each test is assembled, lifted, built for arm64 and its registers compared with the values FEX expects, so no Rosetta is involved. 1,211 of 1,796 eligible tests pass (x87/MMX/3DNow! left out).

Fixes it led to, each with a kat.rs test that fails without it (branch: https://github.com/Hayyan612/Native-Victory-macOS/commits/recomp/fex-fixes, on top of 4aae3061):

  • 32-bit cmpxchg wrote EAX (zero-extending RAX) when the compare succeeded, and a failed register form rewrote its destination; x86 writes the accumulator only on a miss. Rosetta 2 does both writes, which is why diff_bits/diff_forms agreed with the lifter: they now compare operand-size values, and diff_forms waives Cmpxchg_rm32_r32 with the reason.
  • SSE4a insertq/extrq kept the destination's high qword; FEX's SSE4a tests (run on AMD hosts) expect it cleared.
  • MXCSR: ldmxcsr was ignored and stmxcsr always gave 0x1f80. Now RC and FTZ/DAZ go to FPCR per thread, cvt* and vround*/vcvtps2ph with immediate bit 2 round through an frintx asm clang cannot fold (with __builtin_rint it folded constants and turned rint(-x) into -rint(x)), and a function containing ldmxcsr gets #pragma STDC FENV_ACCESS ON (without it clang moved FP work above the rt_ldmxcsr call). Limits are written in rt_host.c.
  • Test code: entries was missing from the FuncIn literals in tests/common/difftest.rs and tests/diff_forms.rs (the tests did not compile), and diff_forms' NaN canonicalisation computed 32 - w for 64-bit lanes (an overflow panic in debug builds).

With these, diff, diff_bits, diff_legacy, diff_vex, diff_forms (0 mismatches), kat and litmus pass here; e2e needs the MinGW toolchain I don't have installed.

Gaps left (tools/fex-asm/FINDINGS.md): a locked read-modify-write whose access crosses 16 bytes raises SIGBUS (no fallback), AF is not computed, loope/loopne never end, 16-bit operand-size stack ops push 8 bytes. The runner is tools/fex-asm/run.py (Python, so its own commit: not on the policy allowlist). Also seen at 4aae3061, not touched: the Windows clippy gate stops on image.rs:144, lib.rs:242 and analyze.rs:1335.

Happy to open a PR into your branch with any of this.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7227693163 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/115#issuecomment-7227693163). Originally posted by [Hayyan612](https://github.com/Hayyan612) on 2026-11-27T20:38:01Z. --- @thebcd69, I ran FEX-Emu's x86-64 instruction tests (`unittests/ASM`, MIT, checked out outside the repo) through `victory-recomp` at `4aae3061`: each test is assembled, lifted, built for arm64 and its registers compared with the values FEX expects, so no Rosetta is involved. **1,211 of 1,796 eligible tests pass** (x87/MMX/3DNow! left out). Fixes it led to, each with a `kat.rs` test that fails without it (branch: https://github.com/Hayyan612/Native-Victory-macOS/commits/recomp/fex-fixes, on top of `4aae3061`): - **32-bit `cmpxchg`** wrote EAX (zero-extending RAX) when the compare succeeded, and a failed register form rewrote its destination; x86 writes the accumulator only on a miss. Rosetta 2 does both writes, which is why `diff_bits`/`diff_forms` agreed with the lifter: they now compare operand-size values, and `diff_forms` waives `Cmpxchg_rm32_r32` with the reason. - **SSE4a `insertq`/`extrq`** kept the destination's high qword; FEX's SSE4a tests (run on AMD hosts) expect it cleared. - **MXCSR:** `ldmxcsr` was ignored and `stmxcsr` always gave `0x1f80`. Now RC and FTZ/DAZ go to FPCR per thread, `cvt*` and `vround*`/`vcvtps2ph` with immediate bit 2 round through an `frintx` asm clang cannot fold (with `__builtin_rint` it folded constants and turned `rint(-x)` into `-rint(x)`), and a function containing `ldmxcsr` gets `#pragma STDC FENV_ACCESS ON` (without it clang moved FP work above the `rt_ldmxcsr` call). Limits are written in `rt_host.c`. - **Test code:** `entries` was missing from the `FuncIn` literals in `tests/common/difftest.rs` and `tests/diff_forms.rs` (the tests did not compile), and `diff_forms`' NaN canonicalisation computed `32 - w` for 64-bit lanes (an overflow panic in debug builds). With these, `diff`, `diff_bits`, `diff_legacy`, `diff_vex`, `diff_forms` (0 mismatches), `kat` and `litmus` pass here; `e2e` needs the MinGW toolchain I don't have installed. Gaps left (`tools/fex-asm/FINDINGS.md`): a locked read-modify-write whose access crosses 16 bytes raises SIGBUS (no fallback), AF is not computed, `loope`/`loopne` never end, 16-bit operand-size stack ops push 8 bytes. The runner is `tools/fex-asm/run.py` (Python, so its own commit: not on the policy allowlist). Also seen at `4aae3061`, not touched: the Windows clippy gate stops on `image.rs:144`, `lib.rs:242` and `analyze.rs:1335`. Happy to open a PR into your branch with any of this.
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/115:upstream-pr/115'
git switch 'upstream-pr/115'

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 'native/arm64-run'
git merge --no-ff 'upstream-pr/115'
git switch 'upstream-pr/115'
git rebase 'native/arm64-run'
git switch 'native/arm64-run'
git merge --ff-only 'upstream-pr/115'
git switch 'upstream-pr/115'
git rebase 'native/arm64-run'
git switch 'native/arm64-run'
git merge --no-ff 'upstream-pr/115'
git switch 'native/arm64-run'
git merge --squash 'upstream-pr/115'
git switch 'native/arm64-run'
git merge --ff-only 'upstream-pr/115'
git switch 'native/arm64-run'
git merge 'upstream-pr/115'
git push origin 'native/arm64-run'
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
LakshanSivakumar/Native-Victory-macOS!115
No description provided.