arm64 run: the recompiled title boots to its intro; recompiler fixes, main merged in #115
No reviewers
Labels
No labels
accessibility
bug
claimed
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
tester report
urgent
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/LakshanSivakumar--Native-Victory-macOS!115
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-115"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@thebcd69 on GitHub · 2026-11-26 17:15 UTC · original
thebcd69:arm64-recompile→native/arm64-run· +15960 −1481 · 131 files · 254 commits · openWhat this is
The arm64 run (
native/arm64-run,b11a2f2) brought up tomain(3fd73fd) and taken further on an M5 Max: the title's exe and DLLs lifted to C withvictory-recomp lift-split, built for arm64 (no Rosetta) and run withVICTORY_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.tablelistcompares two builds: 208 of the exe's 3434 tables changed (f_53bf950 went from 7 to 8 cases, the trap that stopped a run).jmp qword ptr [base + 8*idx], an interpreter's dispatch): one switch per function after its body.f_<rva>that enters the same body at its label.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 loopb ..pauselifts toyieldwith a memory clobber.Runtime, HLE, native host
extern "efiapi", method tables go throughfn_addr!, the x86-only dump and write-trap code is gated.Shader translator
ds_bpermute_b32stays 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.main: onev_mad_u32_u16lowering (main's) and ones_pack_*lowering; both branches had added them.Merging
mainConflicts: UCRT
ilogb(main's NaN case, inextern "efiapi"), and anative.rstest (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 withclang -arch arm64 -O2 -ffp-contract=off -mcpu=apple-m1 -mllvm -disable-machine-sink -mllvm -enable-misched=false -DRT_TSOand linked with-dynamiclib -Wl,-undefined,dynamic_lookup; the runtime isrt_host.cwith-DRT_MULTI. Title-specific seeds are not in the tree (escapesproduces them).🤖 Generated with Claude Code
https://claude.ai/code/session_01BotUDcRjHo3zJ1HWdpX4mk
f0e7e21' into release/main 19ca75acfe3573f82' into release/main 0826710436d48bb1b): sound through CoreAudio, live keys, dropped-work warnings 5999490a503d4ca18): late-DLL static TLS, remirror window, Rosetta test pools 7da7f7f2df- Resource heaps reach HEAP_VIEWS entries (when the title's entries and the contract's fit) with null views at its last two, and carry a view-stride table (a dword per entry: element size, integer-format bits; 0 for no buffer view), kept by `mirror` and bound as root SRV VIEW_STRIDES. Shaders taking buffer views at computed heap indices read it; without it their commands were left out ("root parameter 255 was never set", 40 a run) and the title's watchdog ended it 30 s later. - Translator: the thread-group info SGPR (TG_SIZE: wave count, wave index over console waves), s_sext_i32_i8/i16. - VICTORY_DUMP_THREADS=0 also dumps every thread at a write to address 0 (the title's watchdog crashes that way). Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01BotUDcRjHo3zJ1HWdpX4mkbda640d): permlane16/x16 upstream, computed-buffer subword loads, texture formats, hot-texture probing bound 75a69eb411Surface::read_last read the presented texture with 4-byte rows whatever its format. Once the scene presents a half-float (RGBA16Float) texture, Metal wrote twice the buffer, over the host heap where the title's own objects live: their pointers became half-float texels (+-inf, the cleared HDR target), and the title crashed a second or two after the scene's start ("AGX: Texture read/write assertion failed: bytes_per_row >= used_bytes_per_row" just before; n12, n13, n20, likely n18). Only runs that read frames (VICTORY_SHOTS) were hit. Rows are now the texel's size, and wider texels are clamped to 8 bits for the caller; unknown formats none. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01BotUDcRjHo3zJ1HWdpX4mkaf380ca): pool ranges across mappings, drop one command, fault dumps, stencil clears, BGRA sRGB da95423786af380ca) into the arm64 run 89495059f8escapeslists direct targets a linear sweep of each function finds outside every function 93dc8497c7Function discovery walks from each start and takes an in-range forward jmp as internal, stopping at `jmp reg`; so a thunk's target (a1: rva 0x9f6400) and a switch case that tail-calls (a2: rva 0x5b4c9f0, the case reached through a jump table in .rdata) were left out, and the lifted image aborted there ("rt: no fallback installed"). `discover::sweep` decodes each final extent linearly and keeps its direct call / jcc / jmp targets and executable `lea rip` targets; `escaping_targets` returns those that land in no function (to feed back as seeds) and those that land in the middle of one (reported only). `victory-recomp escapes <pe> [seeds]` prints the first to stdout, the second to stderr. On game_scarlett_master: 481 seeds, 61 targets into the middle of .pdata functions. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01BotUDcRjHo3zJ1HWdpX4mk- ds_bpermute_b32 in a wave of 64 permutes lanes 0..31 and 32..63 apart (RDNA 2 ISA 10.4.4): the lane read is the address modulo 32 in the reading lane's own half. It was lowered as a read across the whole console wave plus a 64-lane ballot, both exchange sites on a 32-lane host, so in divergent code it was refused ("cross-lane operation between host waves in divergent code", 34 programs in n28 with the others of that reason), and where the address wrapped past 31 it read the other half. It is now the host wave's own read and ballot. After VIctory-macOS 0665a0e8 (QB) and ka1qux f9a5034 (its test checked all 64 lanes against RDNA 2 hardware). Tests: the permute lowers with no barrier and no exchange, also under an EXEC branch. - An immediate sampler used with a comparison sample clears the reduction bits (0x180) before setting the comparison one (0x80): a minimum sampler (0x100) became a maximum one (0x180). After ka1qux 93b9b2f, port of Marvisak/VIctory #2983 (RVZO6). - SDWA destination WORD_0 with dst_unused 1 (sext) copies bit 15 upward: a 16-bit -1 came out as 0x0000ffff. After fxceless 58de9bf (upstream VIctory #3124). - BC7: the 2-bit rotation field exists in modes 4 and 5 only; in the other modes those bits are other fields, and reading them swapped a channel with alpha (wrong colours, a shift past the width in modes 0, 1, 3). After ka1qux 765d9fa (upstream VIctory pull request #3111). Test. The shader translator changed: its cache keys move with the build. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01BotUDcRjHo3zJ1HWdpX4mka3 trapped 25 s in ("jump table index out of range", f_53bf950): the table at rva 0x67694f4 has 8 cases, and the size came from `cmp r8d, 7` / `jae`, after which the index is `add r8d, 2` and a branch target joins. The size was taken from the last compare-and-ja within 40 instructions on any register a move connected to the index, whatever happened in between. Now `index_bound` reads forward to the table load with value numbers: a plain copy (`mov eax, r13d`, `movzx r10d, dl`, `movsxd rax, ecx`, `mov r8d, r8d`, `cdqe`) passes a value on, any other write (and a call, for the registers the Windows x64 convention gives the callee) makes a new one, a compare followed by ja/jae bounds the value it tests (the least of its checks), and a branch target forgets everything before it. The load's index is bounded by its value's check, or, for MSVC's two-level switch (`movzx eax, byte [base+idx+bytes]`, then `mov ecx, [base+4*rax+table]`), by the largest of the byte table's checked entries plus one. A table also ends where the function's next table starts (tables sit side by side in .rdata, MSVC's byte table right after its offsets); up to there an entry in other code is a tail-call case, as with a check. Over the exe's 3434 tables (`victory-recomp tablelist <pe> [seeds]` prints them, to compare builds): 208 change. 167 unchecked tables no longer run on into the next table's entries (21 -> 5 cases and the like); 10 MSVC switches go from 3-56 cases to their 2-47 real ones (the rest were bytes of the byte table read as offsets, one as rva 0x10100); 28 checks of another or a changed value no longer bound (2 of them had read one entry of the next table; f_53bf950's two tables go from 7 to 8 cases); 3 tables are newly bounded by the check of a copy made ahead of it (as at 0x22e39e3, where the looser outer check would give 41 cases running into other functions). Tests for each case. Functions entered in the middle: a direct jump, call or executable `lea rip` from one lifted function into the middle of another one (not its own chained parts) went to the dispatcher, which has no function there. Each such address that is an instruction of a function without landing pads is now an entry of its own, `f_<rva>`: the same body after the prologue, `goto` its label (`FuncIn::entries`, `inner_entries`); one that is no instruction start gets a function that traps, so the table always links. The exe has one. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01BotUDcRjHo3zJ1HWdpX4mkpauseis a compiler barrier 51035a88cca4 got past a3's trap, showed the intro (the first frame drawn by the arm64 build), presented black frames from then on and read nothing more from disk: title-main sat in 762 of 762 samples on one instruction of f_9dcac0, `b .`. The guest code there (rva 0x9dd0d7): lock inc dword ptr [rax] ; one more job handed out spin: mov eax, dword ptr [rsp + 0x48] ; the counter the workers raise cmp eax, 8 jne spin The counter lives on the waiter's stack and the workers write it through the address it handed them. Stack accesses are lifted as thread-local (plain), so clang took the read as loop-invariant, the loop as endless, and emitted a branch to itself. `spin_reads`: in a polling loop (a backward branch over at most 16 instructions that only load, compare, test and branch: no call, no store, no register arithmetic, so nothing of its own changes between turns) the reads of fixed stack slots are emitted as shared accesses (acquire under RT_TSO), which clang must repeat and which order what follows the exit. In the exe: 50 such reads in 27 units. And `pause`, a spin-wait hint, is lifted as ARM's `yield` with a memory clobber, so a waiting loop with it reads memory again on every turn whatever it reads (182 units have one). Tests: the spin above, a loop that writes its slot, one that calls, a search loop that counts, `pause`. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01BotUDcRjHo3zJ1HWdpX4mk3fd73fd) into the arm64 run: shader opcodes, SCC, sample/gather variants, root signatures, UCRT fixes 9fad133bd7jmp [r12 + 8*rbx]) 2b981d95c73fd73fd) by way of merge-main-1905: shader opcodes, SCC, sample/gather variants, root signatures, UCRT fixes 593bd829b2a6 trapped ("jump table index out of range", f_1ffa540): the function's switch is `movsxd rax, [r8 + 4*rax]` / `add rax, r8` / `jmp rax`, and one of its cases is a virtual call in tail position, `mov rax, [rcx]` / `mov rax, [rax + 0x78]` / `jmp rax`. The table finder took any `jmp reg` with a scaled load and an add of the base into the jump's register within 40 instructions before it for a switch, so the virtual call got the switch's five cases, and its real target trapped. `feeds_jump`: the load writes the offset, an `add off, base` (the jump takes off) or `add base, off` (the jump takes the base) follows, and on the way from the load to the jump nothing else writes the offset and the base (before the add) or the target (after it), no unconditional jump, indirect jump, return or interrupt breaks the flow, and no branch target (the jump included) joins another path. In the exe this takes the table from eight jumps, all virtual calls in tail position behind a switch (0x11e405d, 0x11e4096, 0x11e40ae, 0x11e40d4 behind the one at 0x11e4047, 0x1ffa572, 0x4c497d, 0x2e800c9, 0x43833c1), which now go to the dispatcher; no real switch loses its table. Test. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01BotUDcRjHo3zJ1HWdpX4mka7 aborted in bink2scarlett.dll: `rt: unresolved guest target ... rva 0x1751f`, a case of the switch at 0x1751d that the last change had taken the table from. Bink (MSVC) loads the offset over its base register and sets the base again in another one for the add: movzx ecx, byte ptr [rdx + rcx + 0x17a74] mov edx, dword ptr [rdx + 4*rcx + 0x17a5c] ; offset over the base lea rcx, [rip - 0x1751a] ; __ImageBase again add rdx, rcx jmp rdx `feeds_jump` now keeps the registers that hold the base: the load's base register (unless the load overwrites it) and any one an `lea` of the same address sets on the way; a write to one takes it out. The add must take one of them. Over the 17 images, against the table recovery before `feeds_jump`, only the eight virtual calls in tail position in the exe lose their tables; Bink's switch is back (6 cases). Test. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01BotUDcRjHo3zJ1HWdpX4mk@LakshanSivakumar on GitHub · 2026-11-26 18:57 UTC · original · requested changes
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:
Splitting the recompiler (victory-recomp and its fixtures) from the runtime/HLE/host changes would also help a lot.
@AnastasisKon on GitHub · 2026-11-27 09:36 UTC · original
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 on GitHub · 2026-11-27 10:32 UTC · original
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 on GitHub · 2026-11-27 13:47 UTC · original
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 on GitHub · 2026-11-27 20:38 UTC · original
@thebcd69, I ran FEX-Emu's x86-64 instruction tests (
unittests/ASM, MIT, checked out outside the repo) throughvictory-recompat4aae3061: 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.rstest that fails without it (branch: https://github.com/Hayyan612/Native-Victory-macOS/commits/recomp/fex-fixes, on top of4aae3061):cmpxchgwrote 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 whydiff_bits/diff_formsagreed with the lifter: they now compare operand-size values, anddiff_formswaivesCmpxchg_rm32_r32with the reason.insertq/extrqkept the destination's high qword; FEX's SSE4a tests (run on AMD hosts) expect it cleared.ldmxcsrwas ignored andstmxcsralways gave0x1f80. Now RC and FTZ/DAZ go to FPCR per thread,cvt*andvround*/vcvtps2phwith immediate bit 2 round through anfrintxasm clang cannot fold (with__builtin_rintit folded constants and turnedrint(-x)into-rint(x)), and a function containingldmxcsrgets#pragma STDC FENV_ACCESS ON(without it clang moved FP work above thert_ldmxcsrcall). Limits are written inrt_host.c.entrieswas missing from theFuncInliterals intests/common/difftest.rsandtests/diff_forms.rs(the tests did not compile), anddiff_forms' NaN canonicalisation computed32 - wfor 64-bit lanes (an overflow panic in debug builds).With these,
diff,diff_bits,diff_legacy,diff_vex,diff_forms(0 mismatches),katandlitmuspass here;e2eneeds 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/loopnenever end, 16-bit operand-size stack ops push 8 bytes. The runner istools/fex-asm/run.py(Python, so its own commit: not on the policy allowlist). Also seen at4aae3061, not touched: the Windows clippy gate stops onimage.rs:144,lib.rs:242andanalyze.rs:1335.Happy to open a PR into your branch with any of this.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.