WIP: perf(host): the effect emitter matrix, the sounds' angle fraction and the audio reverb on host code, bit for bit (HOS_NATIVE_FXTRIGGERS, HOS_NATIVE_REVERB, on by default) #1903

Draft
snaildev99 wants to merge 13 commits from snaildev99/Longshot:perf/native-fxtriggers into main
Contributor

Summary

Three of the game's effect and audio routines run on host code with the game's exact results, behind two new switches, both on by default (=0 gives the lifted code):

  • HOS_NATIVE_FXTRIGGERS: the effect link's "set the emitter's matrix" (f_8012ba70, 88 instructions, a leaf: copies a matrix and makes its three axes unit length with their lengths) and a sound's angle against an axis as a fraction between two limits (f_806fe5f0, 338 instructions, a leaf of the per-sound update: one factor of a sound's volume by direction). Both only compute: they call nothing, take no lock and touch no queue, so they cannot change which effect or sound starts, or when. In the Market profile they hold 0.040 % and 0.019 % of the game's code time.
  • HOS_NATIVE_REVERB, a switch of its own so that it can be listened to alone: the audio engine's reverb (f_8372a5a0, 610 instructions, on the audio library's low-priority worker, one queued buffer a call) for six channels, and for two and four channels, where the game calls a one-sample routine (f_8372af30) for each sample. 1.14 % of the game's code time in the Market and 0.59 % on a Kakariko and trail route, off the frame (the audio worker). The profiles saw only the six-channel path (1,359 samples in f_8372a5a0, none in f_8372af30).

The goal is less CPU work for the same results. A call the host cannot prove exact runs the lifted routine with nothing written. The two leaves answer under the lift's own float gate (FPCR 0 or FZ alone, FPSR.IXC set) when every value is in a class where the PC's IEEE arithmetic gives Arm's bits (the matrix: every lane zero or of magnitude in [2^-31, 2^31); the angle: every float loaded and made zero or in [2^-63, 2^63), a hardware FMA). The reverb answers with FPCR 0 and FPSR.IXC set, every float loaded finite, no invalid operation or overflow on the host; it saves only the bytes the routine writes (about 19 KB for 240 samples) and puts them back on a decline.

How: nx2/oot_patches.py (patch_fxtriggers, the supported build only) puts a gate first in each lifted function, one load and an untaken branch when off; each gated function is declared at file scope (FXT_FWD), because nx2/split_giants.py may put a gate in a piece written before f_<addr>. host/oot_fxtriggers.c answers with host/fxt_kernels.c (FRSQRTE from the Arm pseudocode's table, FRSQRTS exactly in binary64, the angle routine's instructions in order on a copy of its registers). host/oot_reverb.c answers with host/reverb_kernel.c: one SSE4.1 / FMA operation per instruction in the game's order, every parameter read at the same point of each sample as the game reads it (nothing hoisted, so a setting changed mid-buffer is taken up at the sample the game takes it up at), the integer part (the slew, the taps' places and wraps) as the game's register arithmetic. For two and four channels it runs every sample but the last itself, then the translated f_8372af30 for the last sample, so the registers at the end are that routine's own.

Read first: host/oot_fxtriggers.c, host/fxt_kernels.c, host/oot_reverb.c, host/reverb_kernel.c, nx2/oot_patches.py (patch_fxtriggers), tests/test_native_fxtriggers.py, tests/test_native_reverb.py, the four rows in gpu/vk/switches.def.

Testing

Tested: Windows 11, RTX 3090 (NVIDIA 610.88), Ryzen 9 5900X. In the game, with the effect switch's code (at 952d42d0) merged with other rewrite branches into a test tree on main 068fb8eb, HOS_NATIVE_FXTRIGGERS=check, the Market and Hyrule Field for about five minutes: the emitter matrix answered 59,009 of 65,536 calls on the host with no DIFFERENT line. The angle fraction has not been checked in the game yet. The reverb has not been checked in the game and has not been listened to in the game: it was on (HOS_NATIVE_REVERB=1, the six-channel version at 85e4a89a) in the CPU measurement below, where its start line is in every log, but no counter was logged, so whether it answered any call there is not known. The two- and four-channel extension and this head (the rebase onto current main and the upkeep commit) are not built or played.

Exactness offline (Unicorn runs the game's own routine on the executable; a driver runs the real host files):

  • The emitter matrix, 1,000,000 calls (rotations times scales with a position, zero axes of both signs, fourth lanes, powers of two, single-lane axes, the class's edges and past them, NaN, infinities, subnormals, the matrix inside the object and across the word the routine stores early, seven FPCR settings, many FPSR): 603,700 answered natively, 0 mismatches in every x register, SP, every q register (128 bits), NZCV, FPSR and every byte of the object, the matrix and the stack, and 0 page-mark differences, with SQRTSS and with sqrtf; 0 blocks executed outside the routine. Eight broken versions are caught (102 to 2,301 calls of 4,000 each).
  • The angle fraction, 976,633 calls (a listener's matrix with sounds around it, whole-number positions on axes and diagonals, singular and scaled matrices, positions 1e-3 to 1e-16 from the listener, limits in order, equal, reversed and extreme, spreads -0.5 to 2, axis numbers in and out of range): 513,789 answered natively, 0 mismatches in the same registers and memory, the routine's own frame included; the build without FMA declines every call. Ten broken versions are caught (65 to 1,759 calls of 4,000).
  • The reverb, six channels: 34,000 consecutive calls on one effect object, nothing reset between calls, 7,146,403 samples, 29,633 calls answered natively, and after EVERY call 0 differences in any sample, any byte of the object's state, all fourteen delay lines, the frame, any register, NZCV or FPSR, and 0 page-mark differences. Sequences: loud, a tail decaying through the subnormal range to silence (FPSR.UFC set at the same call as the game's), tiny values, impulses of every length from 1 to 1,024 with delay targets, gains, levels, modes, stages and the mute and off bytes changed between calls, delay lines of 1 to 5 cells, clipping past s32 (declined as needed, every byte put back), NaN and infinity in the state, FPCR with FZ or another rounding, FPSR without IXC. Twelve broken versions are caught, one of them (one unit in the last place of a filter state, once in 257 calls) only because the comparison is made after every call.
  • The reverb, two and four channels: 34,000 consecutive buffers over two seeds, 2,705,538 samples, all answered natively, 0 mismatches after every call (samples, every byte of the object, the delay lines and the frame, every register, NZCV, FPSR, page marks), guest addresses in the 64 GB heap and near the top of the 39-bit window. The six-channel path re-run after that change: 900 buffers, 667 answered natively, 0 mismatches. Two broken versions are caught (the stage-2-off operand at call 5; the rear outputs swapped at call 0).
  • Run again on this branch's host files after the rebase (byte for byte the ones proven; the harnesses run the hooks against the stock lift's routines, so the gates' declarations are not in what they compile): the emitter matrix 250,000 calls, 151,044 answered natively, 0 mismatches in both builds, 0 page-mark differences, check mode 0 differences; the angle fraction 244,285 calls (5,715 the game's routine faults on, left out), 128,603 answered natively, 0 mismatches, the build without FMA declining all. The reverb's hook declaration did not change in the upkeep (it already took A64_NOESC), so its harness was not re-run.

Game-free checks at this head: tests/test_native_fxtriggers.py (24 PASS lines: both gates once each, first in their functions, the supported build only; both kernels against models written apart from them on 120,000 calls each; the declines; the hooks off, on, check and on another build; the 4 GB line; page marks; the build without FMA) and tests/test_native_reverb.py (the gate; the kernel through the hook against an independent model on six sequences of 400 consecutive six-channel buffers, 270,386 samples, and 2,720 two- and four-channel buffers at guest bases 0, 64 GB and near 2^39, every byte after every call; 17 kinds of decline with every byte put back; check mode with a difference in a sample, a delay line and a register; the build without SSE4.1 / FMA) pass, and so do tests/test_switch_table.py, tests/test_patch_hooks_defined.py and 36 of the other 41 tests that read nx2/oot_patches.py or nx2/entry_hooks.py. The other five fail here and on main a104182b alike: test_dev_packs, test_high_fps_fixes, test_libc_hooks, test_lift_cache, test_song_note_cue. tests/run_all.py was not run.

Still to test:

  • Linux, any GPU: the Market for a few minutes and Hyrule Field for a few minutes, this branch with HOS_NATIVE_FXTRIGGERS=0 and HOS_NATIVE_REVERB=0 against both unset (on; and each alone if there is time), and main against this branch with them unset; the game's CPU seconds with the frame rate capped at 60, and the frame times uncapped. Expecting less CPU time with the switches on, the same frame rate or better, no cost with them =0, the picture and the sound as without them (@Beanstalk linux).
  • Windows, the reverb: HOS_NATIVE_REVERB=check with HOS_NATIVE_FXTRIGGERS=0, indoors, in a cave and in the Market, expecting reverb: count lines with calls taken and no DIFFERENT ("parameters changed, not compared" is not a fault; every call declined for the float mode would mean the audio worker runs with flush to zero and the kernel is never used); then =1 with HOS_NATIVE_REVERB_LOG=1, listening after short loud sounds: the tail dies away at the same length and colour as with the switch unset, with no click, hiss or cut into silence, and no jump walking from one room to another while a tail sounds (by hand).
  • Windows, the effects and the angle: HOS_NATIVE_FXTRIGGERS=check, expecting count lines for both routines and no DIFFERENT; then =1: effects that follow a moving owner (torch flames, dust at Link's feet, splashes, sword sparks) in the same place, direction and size, and a directional sound fading in and out at the same places when walking around it (by hand).

Measurements

Verdict: less CPU work, measured together with the other rewrite branches, not yet alone, and not for the reverb. In a test tree that merges nine rewrite branches (named in the baseline below; the cloth and particle effect rewrites are not among them), at a 60 fps cap in the Market, the nine on used 2.7 % less CPU standing and 2.4 % less turning (the whole process) than main, and the hooks in with every switch off cost nothing measurable (-0.3 % / -0.2 %). The audio library's worker, where the reverb runs, used 0.038 to 0.039 cores in every variant: no saving from the reverb is claimed. The Test Farm request asks for this branch's own number.

Baseline: main 068fb8eb (#1802) against the test tree test/rewrites @ e614ef49 (main 068fb8eb with nine rewrite branches: the seven maths units, the maths library, animation, bounds, crowd, visibility, glue, the effect triggers with the six-channel reverb (this branch at 85e4a89a), and the solver; the cloth and particle effect rewrites, the two- and four-channel reverb and later pieces of other branches are not among them; this PR's two- and four-channel commit was not in it), lifted with A64_FPXKEEP=0 so that the lift is main's apart from the hooks. Not this PR alone: the run-time switches were all on together. Main has moved 28 commits since 068fb8eb; this branch was not measured on current main.
Setup: Windows 11, Ryzen 9 5900X, RTX 3090, 3840x2160; the child Market, hands-free; frame rate capped at 60 (all 15 runs held 60); each run 30 s standing, then 30 s turning the camera; five variants interleaved over three rounds, the PC otherwise idle. CPU seconds per second of play (cores busy on average), from the processor's cycle counter; the median of three runs (the three in brackets for the process).

Before: main @ 068fb8eb After, every switch off: test/rewrites @ e614ef49 After, the nine branches on: test/rewrites @ e614ef49 Δ off Δ on
the process, standing, cores 5.156 [5.144 5.156 5.161] 5.140 [5.303 5.140 5.125] 5.017 [5.007 5.017 5.049] -0.3 % -2.7 %
the process, turning, cores 5.639 [5.676 5.627 5.639] 5.630 [5.722 5.630 5.628] 5.504 [5.504 5.498 5.577] -0.2 % -2.4 %
the audio library's worker, standing, cores 0.038 0.038 0.039 0 within 0.001 cores
the audio library's worker, turning, cores 0.039 0.039 0.039 0 0

The off figures are inside the runs' spread. The process includes the renderer's threads (about 1.4 cores standing), which the rewrites do not touch.

Offline (CPU time, not the game; Ryzen 9 5900X with other jobs running, absolute times 15 to 50 % apart between runs, the ratios within a run closer). "Main's form" for the two leaves and the six-channel reverb is the lift with registers as C locals that main writes for these functions, approximated offline from the stock lift (not main's lifter); for the two- and four-channel reverb it is main's real lift (nx2/lift.py --standalone on a git archive of 068fb8eb). A gated function is written in the older context form; "switch off" is that form plus the gate.

routine main's form this PR, switch on factor switch off against main's form
f_8012ba70, the emitter matrix, ns a call 251-460 (approximated) 60-86 3.8x to 5x within the noise
f_806fe5f0, the angle fraction, ns a call 323-628 (approximated) 128-185 2.0x to 3.4x within the noise
f_8372a5a0, six channels, ns a sample 923 / 755 (loud / a decaying tail; approximated) 73 / 74 12x to 13x within the noise (0 to +6 %)
f_8372a5a0, two channels, stage 2 on / off, ns a sample 422.59 / 342.80 (main's lift) 47.69 / 36.51 8.86x / 9.39x +14.3 % / +9.4 %
f_8372a5a0, four channels, stage 2 on / off, ns a sample 423.44 / 345.09 (main's lift) 46.56 / 33.44 9.09x / 10.32x +16.3 % / +7.6 %

For these routines the old context form and main's form measure the same within the noise: their time is in the float operations, not the registers. The reverb's declines: before any work (FPCR, channel count) the lifted routine's time; after the whole buffer (a result past s32 in its last sample, which ordinary audio does not reach) about +8 % on that buffer; check mode +8 to +12 % over the lifted routine. The switch-off figures of the leaves and the six-channel reverb were measured before the leaves' hooks were declared with A64_NOESC (the upkeep commit); the game measurement above found no off cost at the process's scale.

The switches

HOS_NATIVE_FXTRIGGERS (new, run time, kill, on by default): 0 off; unset or 1 on (host code where exact, the rest lifted); check runs both, compares memory, registers and new FPSR flags, logs fxtriggers: f_<addr> DIFFERENT from the lifted routine: ... and keeps the lifted result. HOS_NATIVE_FXTRIGGERS_LOG=1 (always in check mode) logs fxtriggers: <routine> <n> calls: taken <k>, lifted for ... every 65,536 calls.

HOS_NATIVE_REVERB (new, run time, kill, on by default): 0 off; unset or 1 on; check runs the kernel, puts the saved bytes back, runs the lifted routine and compares every byte the routine writes, the registers and FPSR: reverb: f_8372a5a0 DIFFERENT from the lifted routine: ...; a parameter changed by another thread between the two runs is counted "parameters changed, not compared", neither a difference nor a pass. HOS_NATIVE_REVERB_LOG=1 logs reverb: f_8372a5a0 <n> calls: taken <k>, ... every 4,096 calls, also with =1 (that is how a run without check mode shows whether the reverb answers). Another game build leaves both off with a log line. Both ship off: neither has been measured alone yet.

Risks

What could break: the effect matrix places and sizes particle effects (a wrong one would show as an effect out of place); the angle fraction scales a sound's volume by direction (a step or click when moving around a source); the reverb shapes what is heard after sounds (a click, hiss or wrong tail). Offline every answered call is exact, after every call of long sequences for the reverb; in the game only the emitter matrix has been compared so far. The reverb takes no lock beyond the one its worker already holds, and one virtual method of the effect class can rewrite the mode and the two matrices on a live object without a lock (as the lifted routine reads them, the kernel reads each at the same point of each sample; a setting landing a few samples earlier or later is possible, as it is between two runs of the lifted routine). The reverb answers only with FPCR 0: the game's job worker threads were seen with FZ set in every call of the maths units; the audio worker's FPCR has not been observed, and if FZ is set there every reverb call declines (no gain, no harm). Open: in the CPU measurement the renderer's mkw_vk capture copy thread used 10 to 18 % more CPU (0.009 to 0.017 cores) in both variants with the nine on and in neither without; the native kernels mark what they write (HOS_WRITTEN, as these hooks do), possibly more coarsely than the lifted code; which rewrite causes it is not determined.

It ships on: docs/dev/standards.md has a switch ship at its value from the first push, never off because it is new, and the measurement with the rewrite branches together says on. =0 on each gives main's lifted code. This PR's own measurement (the farm request) can still turn it off before it leaves WIP.

Turning it off: HOS_NATIVE_FXTRIGGERS=0, HOS_NATIVE_REVERB=0.

After updating: the routines run on the host by default, with the game's exact results; saves, longshot_options.ini and the caches do not change.

Checklist

Ready for review

  • One topic, on current main; the title is a Conventional Commit.
  • Tested on my own PC, in the game for a change the game runs, as Testing says. (The emitter matrix checked in the game in a merged test tree; the angle fraction and the reverb not checked, the reverb not listened to; this head not built or played.)
  • mise run test passes (any failure that also fails on main is named). (The 40 tests that read the changed files pass, the five failures are main's; the whole suite not run.)
  • Measured against main, or Measurements says why there is nothing to measure. (Measured with nine rewrite branches merged; this branch alone not yet; the reverb's saving not seen.)
  • No game files, build output or hand-edited generated files; third_party/ untouched; nothing GPL-incompatible.

When it applies

  • A switch added or changed: it ships at the default the measurements chose, with its row in gpu/vk/switches.def. (The rows are there; on by default, =0 gives main's lifted code; this PR's own measurement can still turn it off.)
  • A check under tests/ that reads changed source is updated, not weakened. (tests/test_native_fxtriggers.py and tests/test_native_reverb.py, new; their "no other function was gated" slices find the functions by their head lines.)
  • Host code builds on Windows (llvm-mingw) and Linux, with UTF-8 paths. (Windows: in the merged test tree, without the two- and four-channel extension. Linux: not built.)
  • AI assistance recorded with Assisted-by: / Co-Authored-By: trailers. (Every commit but a2728964, the two- and four-channel extension, which has no trailer.)

Ready to merge

  • Everything in Still to test has run, its results in Tested.
  • Tier 1 hardware it can affect is tested (docs/dev/standards.md, "Hardware tiers").
  • Approved in review, every comment answered.
  • CI passes on the head; on current main, measured again or a comment says why the numbers still hold.

🤖 Generated with Claude Code

## Summary Three of the game's effect and audio routines run on host code with the game's exact results, behind two new switches, both on by default (`=0` gives the lifted code): - `HOS_NATIVE_FXTRIGGERS`: the effect link's "set the emitter's matrix" (f_8012ba70, 88 instructions, a leaf: copies a matrix and makes its three axes unit length with their lengths) and a sound's angle against an axis as a fraction between two limits (f_806fe5f0, 338 instructions, a leaf of the per-sound update: one factor of a sound's volume by direction). Both only compute: they call nothing, take no lock and touch no queue, so they cannot change which effect or sound starts, or when. In the Market profile they hold 0.040 % and 0.019 % of the game's code time. - `HOS_NATIVE_REVERB`, a switch of its own so that it can be listened to alone: the audio engine's reverb (f_8372a5a0, 610 instructions, on the audio library's low-priority worker, one queued buffer a call) for six channels, and for two and four channels, where the game calls a one-sample routine (f_8372af30) for each sample. 1.14 % of the game's code time in the Market and 0.59 % on a Kakariko and trail route, off the frame (the audio worker). The profiles saw only the six-channel path (1,359 samples in f_8372a5a0, none in f_8372af30). The goal is less CPU work for the same results. A call the host cannot prove exact runs the lifted routine with nothing written. The two leaves answer under the lift's own float gate (FPCR 0 or FZ alone, FPSR.IXC set) when every value is in a class where the PC's IEEE arithmetic gives Arm's bits (the matrix: every lane zero or of magnitude in [2^-31, 2^31); the angle: every float loaded and made zero or in [2^-63, 2^63), a hardware FMA). The reverb answers with FPCR 0 and FPSR.IXC set, every float loaded finite, no invalid operation or overflow on the host; it saves only the bytes the routine writes (about 19 KB for 240 samples) and puts them back on a decline. How: `nx2/oot_patches.py` (`patch_fxtriggers`, the supported build only) puts a gate first in each lifted function, one load and an untaken branch when off; each gated function is declared at file scope (`FXT_FWD`), because `nx2/split_giants.py` may put a gate in a piece written before `f_<addr>`. `host/oot_fxtriggers.c` answers with `host/fxt_kernels.c` (FRSQRTE from the Arm pseudocode's table, FRSQRTS exactly in binary64, the angle routine's instructions in order on a copy of its registers). `host/oot_reverb.c` answers with `host/reverb_kernel.c`: one SSE4.1 / FMA operation per instruction in the game's order, every parameter read at the same point of each sample as the game reads it (nothing hoisted, so a setting changed mid-buffer is taken up at the sample the game takes it up at), the integer part (the slew, the taps' places and wraps) as the game's register arithmetic. For two and four channels it runs every sample but the last itself, then the translated f_8372af30 for the last sample, so the registers at the end are that routine's own. Read first: `host/oot_fxtriggers.c`, `host/fxt_kernels.c`, `host/oot_reverb.c`, `host/reverb_kernel.c`, `nx2/oot_patches.py` (`patch_fxtriggers`), `tests/test_native_fxtriggers.py`, `tests/test_native_reverb.py`, the four rows in `gpu/vk/switches.def`. ## Testing **Tested:** Windows 11, RTX 3090 (NVIDIA 610.88), Ryzen 9 5900X. In the game, with the effect switch's code (at 952d42d0) merged with other rewrite branches into a test tree on main 068fb8eb, `HOS_NATIVE_FXTRIGGERS=check`, the Market and Hyrule Field for about five minutes: the emitter matrix answered 59,009 of 65,536 calls on the host with no `DIFFERENT` line. The angle fraction has not been checked in the game yet. The reverb has not been checked in the game and has not been listened to in the game: it was on (`HOS_NATIVE_REVERB=1`, the six-channel version at 85e4a89a) in the CPU measurement below, where its start line is in every log, but no counter was logged, so whether it answered any call there is not known. The two- and four-channel extension and this head (the rebase onto current main and the upkeep commit) are not built or played. Exactness offline (Unicorn runs the game's own routine on the executable; a driver runs the real host files): - The emitter matrix, 1,000,000 calls (rotations times scales with a position, zero axes of both signs, fourth lanes, powers of two, single-lane axes, the class's edges and past them, NaN, infinities, subnormals, the matrix inside the object and across the word the routine stores early, seven FPCR settings, many FPSR): 603,700 answered natively, 0 mismatches in every x register, SP, every q register (128 bits), NZCV, FPSR and every byte of the object, the matrix and the stack, and 0 page-mark differences, with SQRTSS and with `sqrtf`; 0 blocks executed outside the routine. Eight broken versions are caught (102 to 2,301 calls of 4,000 each). - The angle fraction, 976,633 calls (a listener's matrix with sounds around it, whole-number positions on axes and diagonals, singular and scaled matrices, positions 1e-3 to 1e-16 from the listener, limits in order, equal, reversed and extreme, spreads -0.5 to 2, axis numbers in and out of range): 513,789 answered natively, 0 mismatches in the same registers and memory, the routine's own frame included; the build without FMA declines every call. Ten broken versions are caught (65 to 1,759 calls of 4,000). - The reverb, six channels: 34,000 consecutive calls on one effect object, nothing reset between calls, 7,146,403 samples, 29,633 calls answered natively, and after EVERY call 0 differences in any sample, any byte of the object's state, all fourteen delay lines, the frame, any register, NZCV or FPSR, and 0 page-mark differences. Sequences: loud, a tail decaying through the subnormal range to silence (FPSR.UFC set at the same call as the game's), tiny values, impulses of every length from 1 to 1,024 with delay targets, gains, levels, modes, stages and the mute and off bytes changed between calls, delay lines of 1 to 5 cells, clipping past s32 (declined as needed, every byte put back), NaN and infinity in the state, FPCR with FZ or another rounding, FPSR without IXC. Twelve broken versions are caught, one of them (one unit in the last place of a filter state, once in 257 calls) only because the comparison is made after every call. - The reverb, two and four channels: 34,000 consecutive buffers over two seeds, 2,705,538 samples, all answered natively, 0 mismatches after every call (samples, every byte of the object, the delay lines and the frame, every register, NZCV, FPSR, page marks), guest addresses in the 64 GB heap and near the top of the 39-bit window. The six-channel path re-run after that change: 900 buffers, 667 answered natively, 0 mismatches. Two broken versions are caught (the stage-2-off operand at call 5; the rear outputs swapped at call 0). - Run again on this branch's host files after the rebase (byte for byte the ones proven; the harnesses run the hooks against the stock lift's routines, so the gates' declarations are not in what they compile): the emitter matrix 250,000 calls, 151,044 answered natively, 0 mismatches in both builds, 0 page-mark differences, check mode 0 differences; the angle fraction 244,285 calls (5,715 the game's routine faults on, left out), 128,603 answered natively, 0 mismatches, the build without FMA declining all. The reverb's hook declaration did not change in the upkeep (it already took `A64_NOESC`), so its harness was not re-run. Game-free checks at this head: `tests/test_native_fxtriggers.py` (24 PASS lines: both gates once each, first in their functions, the supported build only; both kernels against models written apart from them on 120,000 calls each; the declines; the hooks off, on, check and on another build; the 4 GB line; page marks; the build without FMA) and `tests/test_native_reverb.py` (the gate; the kernel through the hook against an independent model on six sequences of 400 consecutive six-channel buffers, 270,386 samples, and 2,720 two- and four-channel buffers at guest bases 0, 64 GB and near 2^39, every byte after every call; 17 kinds of decline with every byte put back; check mode with a difference in a sample, a delay line and a register; the build without SSE4.1 / FMA) pass, and so do `tests/test_switch_table.py`, `tests/test_patch_hooks_defined.py` and 36 of the other 41 tests that read `nx2/oot_patches.py` or `nx2/entry_hooks.py`. The other five fail here and on main a104182b alike: `test_dev_packs`, `test_high_fps_fixes`, `test_libc_hooks`, `test_lift_cache`, `test_song_note_cue`. `tests/run_all.py` was not run. **Still to test:** - Linux, any GPU: the Market for a few minutes and Hyrule Field for a few minutes, this branch with `HOS_NATIVE_FXTRIGGERS=0` and `HOS_NATIVE_REVERB=0` against both unset (on; and each alone if there is time), and main against this branch with them unset; the game's CPU seconds with the frame rate capped at 60, and the frame times uncapped. Expecting less CPU time with the switches on, the same frame rate or better, no cost with them `=0`, the picture and the sound as without them (@Beanstalk linux). - Windows, the reverb: `HOS_NATIVE_REVERB=check` with `HOS_NATIVE_FXTRIGGERS=0`, indoors, in a cave and in the Market, expecting `reverb:` count lines with calls taken and no `DIFFERENT` ("parameters changed, not compared" is not a fault; every call declined for the float mode would mean the audio worker runs with flush to zero and the kernel is never used); then `=1` with `HOS_NATIVE_REVERB_LOG=1`, listening after short loud sounds: the tail dies away at the same length and colour as with the switch unset, with no click, hiss or cut into silence, and no jump walking from one room to another while a tail sounds (by hand). - Windows, the effects and the angle: `HOS_NATIVE_FXTRIGGERS=check`, expecting count lines for both routines and no `DIFFERENT`; then `=1`: effects that follow a moving owner (torch flames, dust at Link's feet, splashes, sword sparks) in the same place, direction and size, and a directional sound fading in and out at the same places when walking around it (by hand). ## Measurements **Verdict:** less CPU work, measured together with the other rewrite branches, not yet alone, and not for the reverb. In a test tree that merges nine rewrite branches (named in the baseline below; the cloth and particle effect rewrites are not among them), at a 60 fps cap in the Market, the nine on used 2.7 % less CPU standing and 2.4 % less turning (the whole process) than main, and the hooks in with every switch off cost nothing measurable (-0.3 % / -0.2 %). The audio library's worker, where the reverb runs, used 0.038 to 0.039 cores in every variant: no saving from the reverb is claimed. The Test Farm request asks for this branch's own number. Baseline: main 068fb8eb (#1802) against the test tree `test/rewrites` @ e614ef49 (main 068fb8eb with nine rewrite branches: the seven maths units, the maths library, animation, bounds, crowd, visibility, glue, the effect triggers with the six-channel reverb (this branch at 85e4a89a), and the solver; the cloth and particle effect rewrites, the two- and four-channel reverb and later pieces of other branches are not among them; this PR's two- and four-channel commit was not in it), lifted with `A64_FPXKEEP=0` so that the lift is main's apart from the hooks. Not this PR alone: the run-time switches were all on together. Main has moved 28 commits since 068fb8eb; this branch was not measured on current main. Setup: Windows 11, Ryzen 9 5900X, RTX 3090, 3840x2160; the child Market, hands-free; frame rate capped at 60 (all 15 runs held 60); each run 30 s standing, then 30 s turning the camera; five variants interleaved over three rounds, the PC otherwise idle. CPU seconds per second of play (cores busy on average), from the processor's cycle counter; the median of three runs (the three in brackets for the process). | | Before: main @ 068fb8eb | After, every switch off: test/rewrites @ e614ef49 | After, the nine branches on: test/rewrites @ e614ef49 | Δ off | Δ on | |---|---|---|---|---|---| | the process, standing, cores | 5.156 [5.144 5.156 5.161] | 5.140 [5.303 5.140 5.125] | 5.017 [5.007 5.017 5.049] | -0.3 % | -2.7 % | | the process, turning, cores | 5.639 [5.676 5.627 5.639] | 5.630 [5.722 5.630 5.628] | 5.504 [5.504 5.498 5.577] | -0.2 % | -2.4 % | | the audio library's worker, standing, cores | 0.038 | 0.038 | 0.039 | 0 | within 0.001 cores | | the audio library's worker, turning, cores | 0.039 | 0.039 | 0.039 | 0 | 0 | The off figures are inside the runs' spread. The process includes the renderer's threads (about 1.4 cores standing), which the rewrites do not touch. Offline (CPU time, not the game; Ryzen 9 5900X with other jobs running, absolute times 15 to 50 % apart between runs, the ratios within a run closer). "Main's form" for the two leaves and the six-channel reverb is the lift with registers as C locals that main writes for these functions, approximated offline from the stock lift (not main's lifter); for the two- and four-channel reverb it is main's real lift (`nx2/lift.py --standalone` on a `git archive` of 068fb8eb). A gated function is written in the older context form; "switch off" is that form plus the gate. | routine | main's form | this PR, switch on | factor | switch off against main's form | |---|---|---|---|---| | f_8012ba70, the emitter matrix, ns a call | 251-460 (approximated) | 60-86 | 3.8x to 5x | within the noise | | f_806fe5f0, the angle fraction, ns a call | 323-628 (approximated) | 128-185 | 2.0x to 3.4x | within the noise | | f_8372a5a0, six channels, ns a sample | 923 / 755 (loud / a decaying tail; approximated) | 73 / 74 | 12x to 13x | within the noise (0 to +6 %) | | f_8372a5a0, two channels, stage 2 on / off, ns a sample | 422.59 / 342.80 (main's lift) | 47.69 / 36.51 | 8.86x / 9.39x | +14.3 % / +9.4 % | | f_8372a5a0, four channels, stage 2 on / off, ns a sample | 423.44 / 345.09 (main's lift) | 46.56 / 33.44 | 9.09x / 10.32x | +16.3 % / +7.6 % | For these routines the old context form and main's form measure the same within the noise: their time is in the float operations, not the registers. The reverb's declines: before any work (FPCR, channel count) the lifted routine's time; after the whole buffer (a result past s32 in its last sample, which ordinary audio does not reach) about +8 % on that buffer; check mode +8 to +12 % over the lifted routine. The switch-off figures of the leaves and the six-channel reverb were measured before the leaves' hooks were declared with `A64_NOESC` (the upkeep commit); the game measurement above found no off cost at the process's scale. ### The switches `HOS_NATIVE_FXTRIGGERS` (new, run time, `kill`, on by default): `0` off; unset or `1` on (host code where exact, the rest lifted); `check` runs both, compares memory, registers and new FPSR flags, logs `fxtriggers: f_<addr> DIFFERENT from the lifted routine: ...` and keeps the lifted result. `HOS_NATIVE_FXTRIGGERS_LOG=1` (always in check mode) logs `fxtriggers: <routine> <n> calls: taken <k>, lifted for ...` every 65,536 calls. `HOS_NATIVE_REVERB` (new, run time, `kill`, on by default): `0` off; unset or `1` on; `check` runs the kernel, puts the saved bytes back, runs the lifted routine and compares every byte the routine writes, the registers and FPSR: `reverb: f_8372a5a0 DIFFERENT from the lifted routine: ...`; a parameter changed by another thread between the two runs is counted "parameters changed, not compared", neither a difference nor a pass. `HOS_NATIVE_REVERB_LOG=1` logs `reverb: f_8372a5a0 <n> calls: taken <k>, ...` every 4,096 calls, also with `=1` (that is how a run without check mode shows whether the reverb answers). Another game build leaves both off with a log line. Both ship off: neither has been measured alone yet. ## Risks **What could break:** the effect matrix places and sizes particle effects (a wrong one would show as an effect out of place); the angle fraction scales a sound's volume by direction (a step or click when moving around a source); the reverb shapes what is heard after sounds (a click, hiss or wrong tail). Offline every answered call is exact, after every call of long sequences for the reverb; in the game only the emitter matrix has been compared so far. The reverb takes no lock beyond the one its worker already holds, and one virtual method of the effect class can rewrite the mode and the two matrices on a live object without a lock (as the lifted routine reads them, the kernel reads each at the same point of each sample; a setting landing a few samples earlier or later is possible, as it is between two runs of the lifted routine). The reverb answers only with FPCR 0: the game's job worker threads were seen with FZ set in every call of the maths units; the audio worker's FPCR has not been observed, and if FZ is set there every reverb call declines (no gain, no harm). Open: in the CPU measurement the renderer's `mkw_vk capture copy` thread used 10 to 18 % more CPU (0.009 to 0.017 cores) in both variants with the nine on and in neither without; the native kernels mark what they write (`HOS_WRITTEN`, as these hooks do), possibly more coarsely than the lifted code; which rewrite causes it is not determined. It ships on: docs/dev/standards.md has a switch ship at its value from the first push, never off because it is new, and the measurement with the rewrite branches together says on. `=0` on each gives main's lifted code. This PR's own measurement (the farm request) can still turn it off before it leaves WIP. **Turning it off:** `HOS_NATIVE_FXTRIGGERS=0`, `HOS_NATIVE_REVERB=0`. **After updating:** the routines run on the host by default, with the game's exact results; saves, `longshot_options.ini` and the caches do not change. ## Checklist ### Ready for review - [x] One topic, on current `main`; the title is a Conventional Commit. - [ ] Tested on my own PC, in the game for a change the game runs, as Testing says. (The emitter matrix checked in the game in a merged test tree; the angle fraction and the reverb not checked, the reverb not listened to; this head not built or played.) - [ ] `mise run test` passes (any failure that also fails on `main` is named). (The 40 tests that read the changed files pass, the five failures are main's; the whole suite not run.) - [ ] Measured against `main`, or Measurements says why there is nothing to measure. (Measured with nine rewrite branches merged; this branch alone not yet; the reverb's saving not seen.) - [x] No game files, build output or hand-edited generated files; `third_party/` untouched; nothing GPL-incompatible. ### When it applies - [ ] A switch added or changed: it ships at the default the measurements chose, with its row in `gpu/vk/switches.def`. (The rows are there; on by default, `=0` gives main's lifted code; this PR's own measurement can still turn it off.) - [x] A check under `tests/` that reads changed source is updated, not weakened. (`tests/test_native_fxtriggers.py` and `tests/test_native_reverb.py`, new; their "no other function was gated" slices find the functions by their head lines.) - [ ] Host code builds on Windows (llvm-mingw) and Linux, with UTF-8 paths. (Windows: in the merged test tree, without the two- and four-channel extension. Linux: not built.) - [ ] AI assistance recorded with `Assisted-by:` / `Co-Authored-By:` trailers. (Every commit but a2728964, the two- and four-channel extension, which has no trailer.) ### Ready to merge - [ ] Everything in Still to test has run, its results in Tested. - [ ] Tier 1 hardware it can affect is tested (docs/dev/standards.md, "Hardware tiers"). - [ ] Approved in review, every comment answered. - [ ] CI passes on the head; on current `main`, measured again or a comment says why the numbers still hold. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
f_8012ba70 is a leaf of the game's effect link (88 instructions, called by
the effect asset's update f_80128d70): it copies a matrix of four rows of
four floats into the asset's object and splits the three axes into unit
direction and length: L = (a2*a2 + a0*a0) + (a3*a3 + a1*a1), S = FSQRT(L),
and for S > 0 the axis times a reciprocal square root from FRSQRTE and two
FRSQRTS steps, else zero. It calls nothing, takes no lock and starts no
effect or sound.

fxt_mtx_8012ba70 does the same in plain C, in the same order, and returns
every register the routine leaves (x8..x14, v0..v7, v16..v19, NZCV) and the
80 bytes it stores. FRSQRTE is the Arm pseudocode's table, FRSQRTS one
rounding of (3 - a*b)/2 through binary64. It answers only inside a class
where the host's single precision is Arm's bit for bit and no flag but IXC is
raised: every lane of the three axes zero or of magnitude in [2^-31, 2^31);
anything else is declined with nothing written.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
nx2/oot_patches.py (supported build only) puts a gate first in the lifted
f_8012ba70, as the native maths units have: hos_fxt_on_8012ba70 is 1 until
the first call has read the switch, then 0 unless it is on, so off it costs
one load and an untaken branch. host/oot_fxtriggers.c answers with
host/fxt_kernels.c when HOS_NATIVE_FXTRIGGERS is on (off by default), the
lift's own float gate is open (RECOMP_FPX_OPEN: FPCR at its default but FZ,
FPSR.IXC set), the object and the matrix are inside the guest window and not
across a 4 GB line, the matrix does not lie across the word the routine
stores before it has read all of it, and the kernel takes the values. It
writes what the game's routine writes: the copy, the 80 result bytes (both
marked written) and the registers. HOS_NATIVE_FXTRIGGERS=check runs the
kernel and the lifted routine and logs a difference in memory or registers
or a new FPSR flag (the lifted result stays); HOS_NATIVE_FXTRIGGERS_LOG=1
counts calls taken and declined. Another game build leaves it off.

Only a routine that computes is taken: this one calls nothing, so it cannot
change which effect or sound starts, or when.

tests/test_native_fxtriggers.py: the gate (once, idempotent, supported build
only); the kernel against a model of the game's instructions on 120,000
matrices and its declines, with SQRTSS and with sqrtf; the hook off / on /
check / another build, a matrix inside the object, its declines, the 4 GB
line, the page marks.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
f_806fe5f0 is a leaf of the per-sound update (338 instructions, called from
f_806eefc0, f_806f5860 and f_806fc770): it inverts a 3x4 matrix by cofactors,
puts a position through the inverse, takes the angle against one of the three
axes as atan2(|q x axis|, q . axis) from the engine's table of 129 rows,
optionally divides it by a spread, and answers 0, 1 or the fraction between
two angle limits. It calls nothing, takes no lock, and writes only its own
frame below SP.

fxt_angle_806fe5f0 is the routine's instructions in their order on a copy of
its registers: every float it loads and every float it makes is tested to be
zero or in [2^-63, 2^63), where IEEE single precision with a fused
multiply-add gives Arm's bits and no flag but IXC; a zero determinant, an axis
number above 2 and a conversion out of range are declined. It returns every
register the routine leaves (x8..x11, v0..v7, v16..v24, NZCV) and the frame's
0x60 bytes, which the hook writes although they are dead after the return.
Without FMA on the host every call is declined. The gate, the switch and the
check mode are the emitter matrix routine's; check mode names a difference in
the answer first.

tests/test_native_fxtriggers.py: both gates; the kernel against a second,
differently written model on 120,000 calls over a stand-in table, its
declines, the hook on / check / off, and the build without FMA.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
f_8372a5a0 is the reverb the audio engine's low-priority worker runs on each
queued buffer of six channels: per sample a centre fold-down, a constant and a
set 4x4 mix, four delay lines read at slewed distances with a four-tap
interpolation table, a delay line of 4-float cells as an all-pass, a one-pole
filter and a 4x4 feedback, a second stage of a cell line and eight more delay
lines, and back through a mix and a level to s32. The six-channel path calls
nothing and takes no lock.

reverb_run is the same instructions in the same order, one SSE4.1 / FMA
operation an instruction (the scalar instructions as scalar operations), on
the guest's memory as it goes: every parameter is read at the same point of
each sample as the game's routine reads it, the integer part (the slew, the
taps' places and wraps, the places' advance) is the game's register arithmetic,
and the registers at the end are the game's. It is exact where the host's IEEE
arithmetic is Arm's: FPCR 0 (so subnormals are ordinary values and need no
care), every float loaded finite, no invalid operation or overflow; those it
reports instead of answering. FPSR.UFC comes from the host's underflow flag; the
two differ for an inexact result that rounds up to 2^-126, so a careful variant
(for a caller whose UFC is still clear) reports any result of that magnitude.
Without SSE4.1 and FMA it reports that it is not built.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
A switch of its own, apart from HOS_NATIVE_FXTRIGGERS, off by default: the
reverb can be listened to alone. nx2/oot_patches.py (supported build only)
puts a gate first in the lifted f_8372a5a0. host/oot_reverb.c takes a call
with six channels, FPCR 0 and FPSR.IXC set when every buffer it will touch is
guest memory and every delay line's place lies inside its length. It saves
only the bytes the routine itself writes (seven fields of the object, the
cells each delay line will write, the six sample buffers, three frame words),
never the object as a block: another thread may set a parameter meanwhile.
A reason the kernel reports (a NaN or an infinity loaded, a conversion past
s32, the 2^-126 boundary while UFC is clear) puts those bytes back and the
lifted routine runs. Two and four channels stay lifted.

HOS_NATIVE_REVERB=check runs the kernel, copies what it wrote, puts the saved
bytes back, runs the lifted routine and compares every byte the routine
writes, the registers and FPSR; a parameter of the object that changed between
the two runs makes the call "parameters changed, not compared", neither a
difference nor a pass. HOS_NATIVE_REVERB_LOG=1 counts calls by outcome.

tests/test_native_reverb.py: the gate; the kernel through the hook against a
second model of the routine on six sequences of 400 consecutive buffers that
carry the state (loud, decay into the subnormal range, parameters and delay
targets changed between calls, impulses, every length): every byte after every
call; the declines with every byte put back; check mode and a changed
parameter; off, another build, and the build without SSE4.1 and FMA.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
refactor(host): the effect and reverb hooks declared with A64_NOESC, their functions at file scope; the tests find a function by its head line
Some checks failed
Website / Website on Cloudflare (pull_request_target) Has been skipped
beanstalk/approval waiting for a BigBean's 👍 on the request
PR description / Description follows the template (pull_request_target) Successful in 16s
CI / Conventional Commit title (pull_request) Has been cancelled
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Has been cancelled
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Has been cancelled
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Has been cancelled
CI / Workflow lint (actionlint) (pull_request) Has been cancelled
CI / Website build and checks (pull_request) Has been cancelled
Guide screenshots / Guide images and local UI source review (pull_request) Has been cancelled
Third-party parts / As their notes say (pull_request) Has been cancelled
Third-party parts / The same as upstream (pull_request) Has been cancelled
d263d0deee
FXT_DECL declares hos_fxt_<addr>(Ctx *A64_NOESC c, A64Fn lifted), as REVERB_DECL already did: without it the
compiler takes the lifted function's context for escaped at the gate's call, which costs the gated function with
the switch off. Each gated function (f_8012ba70, f_806fe5f0, f_8372a5a0) is declared at file scope (FXT_FWD):
nx2/split_giants.py writes a giant function's pieces before f_<addr>, so a gate in the first piece must find it
declared. Only the declarations in the lifted code change; the host code does not.

tests/test_native_fxtriggers.py and tests/test_native_reverb.py found the functions that bound their "no other
function was gated" slices by "void f_<addr>(", which now first finds the declaration at the file's head; they look
for the head line "void f_<addr>(Ctx *__restrict A64_NOESC c) {". The reverb test's unused import of re is gone.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Author
Contributor

Tested in game: In a test tree of nine merged rewrite branches on main 068fb8eb (Windows, RTX 3090), check mode in the Market and Hyrule Field: the emitter matrix answered 59,009 of 65,536 calls with no difference from the lifted routine; the angle fraction and the reverb have not been checked in the game and the reverb has not been listened to (it was on in a 15-run CPU measurement at a 60 fps cap, every run held 60, with no counter logged); this head itself is not built or played.

Tested in game: In a test tree of nine merged rewrite branches on main 068fb8eb (Windows, RTX 3090), check mode in the Market and Hyrule Field: the emitter matrix answered 59,009 of 65,536 calls with no difference from the lifted routine; the angle fraction and the reverb have not been checked in the game and the reverb has not been listened to (it was on in a 15-run CPU measurement at a 60 fps cap, every run held 60, with no counter logged); this head itself is not built or played.
Author
Contributor

@Beanstalk linux: this branch with HOS_NATIVE_FXTRIGGERS and HOS_NATIVE_REVERB unset against both =1 (the same build, with HOS_NATIVE_FXTRIGGERS_LOG=1 and HOS_NATIVE_REVERB_LOG=1 on the =1 side), and main against this branch with them unset, each in the child Market for a few minutes and in Hyrule Field by day for a few minutes. Measure the game's CPU seconds with the frame rate capped at 60 (on a PC that holds 60 there), standing and turning the camera, per thread if you can (the reverb runs on aal::LowPrioWorkerThread), and the frame times uncapped. Expect less CPU time with the switches at 1, the same frame rate or better, no extra CPU time with them unset against main, the picture as without them, and "fxtriggers: ... calls: taken" and "reverb: f_8372a5a0 ... calls:" lines in the log; please report those lines (they say how many calls the host answered).

@Beanstalk linux: this branch with HOS_NATIVE_FXTRIGGERS and HOS_NATIVE_REVERB unset against both =1 (the same build, with HOS_NATIVE_FXTRIGGERS_LOG=1 and HOS_NATIVE_REVERB_LOG=1 on the =1 side), and main against this branch with them unset, each in the child Market for a few minutes and in Hyrule Field by day for a few minutes. Measure the game's CPU seconds with the frame rate capped at 60 (on a PC that holds 60 there), standing and turning the camera, per thread if you can (the reverb runs on aal::LowPrioWorkerThread), and the frame times uncapped. Expect less CPU time with the switches at 1, the same frame rate or better, no extra CPU time with them unset against main, the picture as without them, and "fxtriggers: ... calls: taken" and "reverb: f_8372a5a0 ... calls:" lines in the log; please report those lines (they say how many calls the host answered).
Member

@snaildev99 only members of BigBeans can start the farm.

One of them can approve this request by reacting 👍 to it or to this comment. This request was for d263d0d, and the PR has changed since (0bf0056), so a 👍 no longer approves it. Comment @Beanstalk again to ask for the new commit.

@snaildev99 only members of `BigBeans` can start the farm. ~~One of them can approve this request by reacting 👍 to it or to this comment.~~ This request was for `d263d0d`, and the PR has changed since (`0bf0056`), so a 👍 no longer approves it. Comment `@Beanstalk` again to ask for the new commit.
Member

Possibly related, for context:

  • PR #1644 WIP: feat(audio): the game's reverb, delay and biquad filter effects on its sub mixes — Adds game audio reverb effects; this PR native-optimizes the same reverb routine, with differing scope.
Possibly related, for context: - PR #1644 WIP: feat(audio): the game's reverb, delay and biquad filter effects on its sub mixes — Adds game audio reverb effects; this PR native-optimizes the same reverb routine, with differing scope.
BeanBot left a comment

Recommendation: Request changes. The default-off reverb gate has a recorded 7.6–16.3% cost in the two- and four-channel routines, and the emitter kernel has unsynchronized table initialization. The change also has no demonstrated in-game gain on its own.

This adds optional native implementations for effect placement, directional sound and reverb, with a lifted fallback and comparison modes. The potential CPU saving is not yet established in the game; the current implementation adds substantial instruction-level complexity and a measured cost even when reverb is off.

Does it help: Unproven. Three interleaved Windows runs of nine rewrite branches together showed 2.7% less process CPU while standing and 2.4% while turning, but do not isolate this PR; the audio worker showed no measurable saving and reverb call counts were not recorded. Offline, switch-off two- and four-channel reverb cost 7.6–16.3% more per sample than main's lift. This head has not been built or played.
Other systems: The changes affect particle placement, directional sound, reverb and guest-memory page marks. The emitter matrix was checked in a merged Windows test tree, but the angle and reverb were not checked in game or listened to. Linux, AMD, Steam Deck, frame pacing, the reported capture-copy CPU increase and the current head remain unverified. The PR reports extensive offline comparisons, including fallback and sequential reverb state, but those do not establish in-game behavior or performance.
Switches: HOS_NATIVE_FXTRIGGERS and HOS_NATIVE_REVERB are new runtime attempt switches, both off by default; each supports 1 and check. HOS_NATIVE_FXTRIGGERS_LOG and HOS_NATIVE_REVERB_LOG are new diagnostic switches, both off by default. All four have table rows. The attempt defaults have not been selected by the required platform measurements; off also does not avoid the measured reverb gate cost.

Reviewed: d263d0deee against a104182b40: Read AGENTS.md, CONTRIBUTING.md, the PR template, standards, the changes to switches and patch wiring, and the host hooks and kernels; skimmed the new test models and recorded results. Some long tool outputs were truncated, so the full changed code and tests were not reliably reviewed. docs/review-checklist.md and the adjacent Tooling/AGENTS.md were absent. No generated files or translations changed. The supplied comments and absence of earlier reviews were considered.; nothing run (a code review).
Checked and fine:

  • The four new switches have entries in switches.def, and the patch gates are restricted to the supported build.
  • The reported offline tests exercise declines, comparison mode, register and memory results, and multiple reverb channel counts.
  • The PR identifies the five reported test failures that also occur on main; third_party and generated shader files are unchanged.

Blocking (to change before merge)

  1. nx2/oot_patches.py:1236: The reverb gate changes the lifted function's form even when HOS_NATIVE_REVERB is unset. The PR's offline comparison reports 7.6–16.3% more time per sample on the two- and four-channel paths, so players using the default can pay for an optimization they have not enabled. Preserve main's fast lifted form when disabled or remove this cost, then measure the affected paths in game.
  2. host/fxt_kernels.c:45: Two threads entering the emitter kernel for the first time can both write rsq_tab while another initialization is in progress. Identical byte values do not make concurrent non-atomic writes defined in C; this can produce undefined behavior when the switch is enabled. Use a compile-time constant table or a single-writer initialization with proper synchronization, and cover concurrent initialization.

Suggestions (the author may take or leave)

  • Measure this branch alone against its current base, with switches off and individually on, including audio-worker CPU, frame times and taken counts; investigate the capture-copy increase.
  • Complete the stated in-game checks and listening on the head, Linux and applicable Tier 1 systems, and run the full required checks.
  • Record the missing AI-assistance trailer for the two- and four-channel commit as required by the checklist.

Testing: No code, scripts, builds or tests were run for this review. The PR reports passing targeted game-free checks and offline comparisons, with five tests also failing on main; the full suite and current-head game runs were not reported.
Overlaps and merge order: BeanBot identified Longshot PR #1644 as touching game reverb with a different scope. Its current diff and merge order could not be checked from the supplied material.


Automated code review by BeanBot (gpt-6.1-terra), on the pull request's opening. Nothing was run; a maintainer decides.

**Recommendation: Request changes.** The default-off reverb gate has a recorded 7.6–16.3% cost in the two- and four-channel routines, and the emitter kernel has unsynchronized table initialization. The change also has no demonstrated in-game gain on its own. This adds optional native implementations for effect placement, directional sound and reverb, with a lifted fallback and comparison modes. The potential CPU saving is not yet established in the game; the current implementation adds substantial instruction-level complexity and a measured cost even when reverb is off. **Does it help:** Unproven. Three interleaved Windows runs of nine rewrite branches together showed 2.7% less process CPU while standing and 2.4% while turning, but do not isolate this PR; the audio worker showed no measurable saving and reverb call counts were not recorded. Offline, switch-off two- and four-channel reverb cost 7.6–16.3% more per sample than main's lift. This head has not been built or played. **Other systems:** The changes affect particle placement, directional sound, reverb and guest-memory page marks. The emitter matrix was checked in a merged Windows test tree, but the angle and reverb were not checked in game or listened to. Linux, AMD, Steam Deck, frame pacing, the reported capture-copy CPU increase and the current head remain unverified. The PR reports extensive offline comparisons, including fallback and sequential reverb state, but those do not establish in-game behavior or performance. **Switches:** HOS_NATIVE_FXTRIGGERS and HOS_NATIVE_REVERB are new runtime attempt switches, both off by default; each supports 1 and check. HOS_NATIVE_FXTRIGGERS_LOG and HOS_NATIVE_REVERB_LOG are new diagnostic switches, both off by default. All four have table rows. The attempt defaults have not been selected by the required platform measurements; off also does not avoid the measured reverb gate cost. **Reviewed:** d263d0deee8a against a104182b4037: Read AGENTS.md, CONTRIBUTING.md, the PR template, standards, the changes to switches and patch wiring, and the host hooks and kernels; skimmed the new test models and recorded results. Some long tool outputs were truncated, so the full changed code and tests were not reliably reviewed. docs/review-checklist.md and the adjacent Tooling/AGENTS.md were absent. No generated files or translations changed. The supplied comments and absence of earlier reviews were considered.; nothing run (a code review). **Checked and fine:** - The four new switches have entries in switches.def, and the patch gates are restricted to the supported build. - The reported offline tests exercise declines, comparison mode, register and memory results, and multiple reverb channel counts. - The PR identifies the five reported test failures that also occur on main; third_party and generated shader files are unchanged. **Blocking** (to change before merge) 1. nx2/oot_patches.py:1236: The reverb gate changes the lifted function's form even when HOS_NATIVE_REVERB is unset. The PR's offline comparison reports 7.6–16.3% more time per sample on the two- and four-channel paths, so players using the default can pay for an optimization they have not enabled. Preserve main's fast lifted form when disabled or remove this cost, then measure the affected paths in game. 2. host/fxt_kernels.c:45: Two threads entering the emitter kernel for the first time can both write rsq_tab while another initialization is in progress. Identical byte values do not make concurrent non-atomic writes defined in C; this can produce undefined behavior when the switch is enabled. Use a compile-time constant table or a single-writer initialization with proper synchronization, and cover concurrent initialization. **Suggestions** (the author may take or leave) - Measure this branch alone against its current base, with switches off and individually on, including audio-worker CPU, frame times and taken counts; investigate the capture-copy increase. - Complete the stated in-game checks and listening on the head, Linux and applicable Tier 1 systems, and run the full required checks. - Record the missing AI-assistance trailer for the two- and four-channel commit as required by the checklist. **Testing:** No code, scripts, builds or tests were run for this review. The PR reports passing targeted game-free checks and offline comparisons, with five tests also failing on main; the full suite and current-head game runs were not reported. **Overlaps and merge order:** BeanBot identified Longshot PR #1644 as touching game reverb with a different scope. Its current diff and merge order could not be checked from the supplied material. --- <sub>Automated code review by BeanBot (gpt-6.1-terra), on the pull request's opening. Nothing was run; a maintainer decides.</sub>
@ -0,0 +42,4 @@
const uint32_t mid = (lo + hi) / 2;
if ((uint64_t)a * mid * mid < (UINT64_C(1) << 28)) lo = mid; else hi = mid;
}
rsq_tab[idx] = (uint8_t)(((lo + 1) / 2) & 255);
Member

Two first callers can write this table concurrently. Writing identical bytes is still a C data race; please use a constant table or synchronized single-writer initialization and cover concurrent entry.

Two first callers can write this table concurrently. Writing identical bytes is still a C data race; please use a constant table or synchronized single-writer initialization and cover concurrent entry.
@ -1226,0 +1233,4 @@
# The game's reverb (0x8372a5a0, the audio engine's low-priority worker) that host/oot_reverb.c answers natively, sample
# for sample (HOS_NATIVE_REVERB, a switch of its own, off by default; host/reverb_kernel.c): the same kind of gate
REVERB_GATES = ("8372a5a0",)
REVERB_GATE = (" if (__builtin_expect(hos_reverb_on_%s, 0) && hos_reverb_%s(c, f_%s, f_8372af30)) return; "
Member

This gate changes the lifted form even with the switch off. The reported two- and four-channel measurements show a 7.6–16.3% per-sample regression in that default; please preserve the fast disabled path and measure it in game.

This gate changes the lifted form even with the switch off. The reported two- and four-channel measurements show a 7.6–16.3% per-sample regression in that default; please preserve the fast disabled path and measure it in game.
Owner
@fix
Member

I changed this pull request as the review asked: the new head is 0bf0056778. I rebased it onto main (a764653726).

Conflicts resolved

  • gpu/vk/switches.def: Kept both new FXTRIGGERS switches and the base branch’s updated ZSTD switch.
  • gpu/vk/switches.def: Kept the pull request’s reverb switches and the base branch’s updated ZSTD switch.

Changed

  • Reverb gate and emitter initialization: Moved the reverb gate into a wrapper so the lifted body remains eligible for register locals (nx2/oot_patches.py:1233). Synchronized emitter table initialization and added a concurrent first-entry test (host/fxt_kernels.c:35; tests/test_native_fxtriggers.py:254). No builds or tests were run. The author must measure the affected two- and four-channel paths in game against the current base, including with reverb disabled, to establish whether the regression is gone.

Nothing was built or run: check the change. It will be reviewed again.


Automated fix by BeanBot (gpt-6.1-terra), asked for by HumanBean. Nothing was run; a maintainer decides.

I changed this pull request as the review asked: the new head is 0bf005677874. I rebased it onto `main` (a764653726ba). **Conflicts resolved** - gpu/vk/switches.def: Kept both new FXTRIGGERS switches and the base branch’s updated ZSTD switch. - gpu/vk/switches.def: Kept the pull request’s reverb switches and the base branch’s updated ZSTD switch. **Changed** - **Reverb gate and emitter initialization**: Moved the reverb gate into a wrapper so the lifted body remains eligible for register locals (nx2/oot_patches.py:1233). Synchronized emitter table initialization and added a concurrent first-entry test (host/fxt_kernels.c:35; tests/test_native_fxtriggers.py:254). No builds or tests were run. The author must measure the affected two- and four-channel paths in game against the current base, including with reverb disabled, to establish whether the regression is gone. Nothing was built or run: check the change. It will be reviewed again. --- <sub>Automated fix by BeanBot (gpt-6.1-terra), asked for by HumanBean. Nothing was run; a maintainer decides.</sub>
BeanBot force-pushed perf/native-fxtriggers from d263d0deee
Some checks failed
Website / Website on Cloudflare (pull_request_target) Has been skipped
beanstalk/approval waiting for a BigBean's 👍 on the request
PR description / Description follows the template (pull_request_target) Successful in 16s
CI / Conventional Commit title (pull_request) Has been cancelled
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Has been cancelled
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Has been cancelled
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Has been cancelled
CI / Workflow lint (actionlint) (pull_request) Has been cancelled
CI / Website build and checks (pull_request) Has been cancelled
Guide screenshots / Guide images and local UI source review (pull_request) Has been cancelled
Third-party parts / As their notes say (pull_request) Has been cancelled
Third-party parts / The same as upstream (pull_request) Has been cancelled
to 0bf0056778
Some checks failed
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Has been skipped
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Has been skipped
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Has been skipped
Third-party parts / The same as upstream (pull_request) Has been skipped
Website / Website on Cloudflare (pull_request) Has been skipped
beanstalk/approval changed since the request: ask again
CI / Conventional Commit title (pull_request) Successful in 9s
PR description / Description follows the template (pull_request_target) Successful in 12s
Guide screenshots / Guide images and local UI source review (pull_request) Failing after 13s
Third-party parts / As their notes say (pull_request) Successful in 15s
CI / Workflow lint (actionlint) (pull_request) Successful in 18s
CI / Website build and checks (pull_request) Failing after 15s
2026-11-21 00:15:36 +00:00
Compare
BeanBot left a comment

Recommendation: Request changes. Native reverb skips the lifted loop’s virtual-core checkpoints and can overwrite a pending scheduler request. The effect hooks also race during first-call setup, and the PR’s own in-game CPU gain and default-off cost are still unverified.

Adds optional CPU shortcuts for particle emitter placement, directional sound volume and reverb, with lifted fallbacks and comparison modes. The reported offline results show substantial routine-level speedups and broad numerical coverage. The tradeoff is three instruction-level implementations plus reverb rollback, with no isolated player-facing gain yet.

Does it help: Unproven. Three interleaved Windows runs of a nine-branch tree on older main showed 2.7% less process CPU standing and 2.4% less turning in the capped Market. The audio worker stayed at 0.038–0.039 cores, and the run recorded no reverb take counts. The older offline two- and four-channel paths cost 7.6–16.3% more per sample with reverb disabled. The current wrapper preserves eligibility for register locals, but there are no post-fix results. Compare 0bf0056778 alone against a764653726 with both switches off and each on, including take counts, thread CPU, average FPS, 1% lows and median and p99 frame times.
Other systems: Emitter placement, directional volume and audio tails depend on the changed paths. Native reverb also changes virtual-core scheduling and guest-memory write tracking. The nine-branch run saw capture-copy CPU rise 10–18% (0.009–0.017 cores), with attribution unresolved. Windows NVIDIA emitter evidence comes from an older merged tree. Current-head Windows and Linux builds, AMD and Steam Deck coverage, audio pacing and clean-build time and size are missing. The diff adds no save, settings-menu, input or shader changes. The lifter patch is included in the existing lift-key mechanism.
Switches: HOS_NATIVE_FXTRIGGERS and HOS_NATIVE_REVERB are new runtime attempt switches, off by default, with 1 and check modes. Off is the prudent value given the open correctness issues, but the project requires measured defaults and the default path still changes lifted code. HOS_NATIVE_FXTRIGGERS_LOG and HOS_NATIVE_REVERB_LOG are new diagnostics, off by default and implicit in check mode. That default is appropriate. All four have reference rows.

Reviewed: 0bf0056778 against a764653726: Read the full changed host kernels, hooks and headers, both test fixtures and drivers, and the changed switch and patch sections. Read AGENTS.md, CONTRIBUTING.md, the Forgejo template and developer standards. Traced the surrounding lifter, local-register, guest-memory, write-mark and virtual-core code. Read the supplied comments and stale review. Skimmed the profile entries and reported run summaries. Raw run logs and generated game output were unavailable. No local docs/review-checklist.md or adjacent Tooling/AGENTS.md was present.; nothing run (a code review).
Checked and fine:

  • The gates are supported-build-only, and the helper and effect entry declarations are at file scope.
  • The reciprocal-square-root table now uses single-writer initialization and release/acquire publication.
  • The fixtures cover output behavior, numerical declines, sequential delay state and full-width reverb addresses. Their build and execution steps are described and local.
  • The diff leaves vendor code, shaders, renderer ABI, menu keys and UTF-8 path handling untouched. It contains no game files or generated output.

Blocking (to change before merge)

  1. host/oot_reverb.c:318: Whole-context copies read and overwrite Ctx.poll, which another host thread sets atomically in vc_wake_holder. A virtual-core request posted while reverb processes a buffer can be replaced by the entry value of zero here or at the check-mode restore. The native loop also skips the lifted loop’s back-edge checkpoints. Copy only guest state the routine owns, and preserve checkpoints on the running context. Exercise a request posted during a buffer.
  2. host/oot_fxtriggers.c:122: A second worker can read fxt_mode after the first publishes it but before the release store to started, bypassing acquisition and reading fxt_log without synchronization. The generated volatile gate loads also race with initialization stores. Use atomic gates and acquire published configuration before reading it, or initialize before workers start. Apply the same fix to rv_mode and the reverb gate. The added concurrency test enters the kernel directly and misses these races.
  3. host/reverb_kernel.c:52: The plan checks delay-line allocation length and write place, but never bounds the read index produced by the slewed distance and wrap term. For example, with place zero and the current and target distance both larger than the wrap term, the first tap index is negative and can read before the allocation. Validate computed taps before dereferencing, or prove and enforce the distance and wrap invariants at entry. Add a decline case with a valid write place and an invalid tap.
  4. host/reverb_kernel.c:131: Ordinary C and intrinsic loads do not preserve the promised sample-time reads of parameters that the PR says a live setter updates without a lock. For example, a mode change halfway through the buffer has no defined synchronization with these loads. Establish a defined read/write protocol for the live fields, or keep those objects on the lifted path. Test a parameter update during a buffer, including what check mode reports.
  5. host/reverb_kernel.c:485: The fallback and FPSR result depend on observing the exceptions from every SIMD instruction before restoring MXCSR. Disabling contraction alone leaves the compiler free to optimize ordinary FP intrinsics without preserving their exception effects. Use an exception-aware implementation, as the existing fast FP path does with explicit ordered operations. Verify optimized Windows and Linux builds with an overflow and an underflow whose arithmetic result is otherwise dead.
  6. host/oot_reverb.c:296: Check mode saves the guest frame and then deliberately skips comparing it. A wrong saved register or two-channel scratch word can still count as taken. Compare the frame bytes the lifted routine defines and inject a frame-only mismatch in the fixture.
  7. host/oot_reverb.c:195: The two rollback buffers are heap allocations retained by raw thread-local pointers. When an audio worker exits, its pointers disappear without freeing the allocations, so recreating workers accumulates their high-water allocations. Give scratch space an owner with teardown and allocate the comparison buffer only in check mode.
  8. tests/test_native_reverb.py:683: The SIMD probe tests compiler acceptance, then executes a binary forced to use SSE4.1 and FMA. On a supported pre-FMA x86-64 machine the compiler accepts those flags and the fixture can fault with an illegal instruction. Detect execution support before running that variant and always exercise the fallback. The FX test has the same problem with its -mfma probe.

Waiting on the author (a run, a measurement or a decision; no edit does it)

  • nx2/oot_patches.py:1287: The new wrapper’s default-off cost is unmeasured. The old two- and four-channel path showed 7.6–16.3% more time per sample when disabled, and the effect gates still force their lifted bodies to keep registers in the context. Measure the affected paths on this head against the current base with the switches unset, including audio-worker CPU and frame pacing.
  • Establish an isolated in-game gain and verify the current head in the game on the affected Tier 1 systems. Complete the Windows and Linux builds with UTF-8 paths, required checks and CI. Include directional sound and reverb comparisons, listening tests and per-channel take counts. The previous farm request expired when the head changed.
  • The two- and four-channel commit and the automated head fix lack the required AI-assistance trailers. Record the applicable assistance and bring the PR description and checklist up to date with the wrapper and current-head evidence.

Testing: Read-only review. No build, fixture or game run was executed. The supplied offline comparisons and mutation checks predate the current head, and the fixtures use stand-ins instead of compiling the generated entry paths. The author reports five failures also present on the previously tested main commit. The full suite and current-head CI are unverified.
Overlaps and merge order: PR #1644 is related audio work. The checkout already has a separate I3DL2 submix implementation in host/nn_audio.c, and this diff changes the guest reverb path. No required merge order was established.


Automated code review by BeanBot (gpt-6.2-sol), asked for by BeanBot, after its fix. Nothing was run; a maintainer decides.

**Recommendation: Request changes.** Native reverb skips the lifted loop’s virtual-core checkpoints and can overwrite a pending scheduler request. The effect hooks also race during first-call setup, and the PR’s own in-game CPU gain and default-off cost are still unverified. Adds optional CPU shortcuts for particle emitter placement, directional sound volume and reverb, with lifted fallbacks and comparison modes. The reported offline results show substantial routine-level speedups and broad numerical coverage. The tradeoff is three instruction-level implementations plus reverb rollback, with no isolated player-facing gain yet. **Does it help:** Unproven. Three interleaved Windows runs of a nine-branch tree on older main showed 2.7% less process CPU standing and 2.4% less turning in the capped Market. The audio worker stayed at 0.038–0.039 cores, and the run recorded no reverb take counts. The older offline two- and four-channel paths cost 7.6–16.3% more per sample with reverb disabled. The current wrapper preserves eligibility for register locals, but there are no post-fix results. Compare 0bf005677874 alone against a764653726ba with both switches off and each on, including take counts, thread CPU, average FPS, 1% lows and median and p99 frame times. **Other systems:** Emitter placement, directional volume and audio tails depend on the changed paths. Native reverb also changes virtual-core scheduling and guest-memory write tracking. The nine-branch run saw capture-copy CPU rise 10–18% (0.009–0.017 cores), with attribution unresolved. Windows NVIDIA emitter evidence comes from an older merged tree. Current-head Windows and Linux builds, AMD and Steam Deck coverage, audio pacing and clean-build time and size are missing. The diff adds no save, settings-menu, input or shader changes. The lifter patch is included in the existing lift-key mechanism. **Switches:** HOS_NATIVE_FXTRIGGERS and HOS_NATIVE_REVERB are new runtime attempt switches, off by default, with 1 and check modes. Off is the prudent value given the open correctness issues, but the project requires measured defaults and the default path still changes lifted code. HOS_NATIVE_FXTRIGGERS_LOG and HOS_NATIVE_REVERB_LOG are new diagnostics, off by default and implicit in check mode. That default is appropriate. All four have reference rows. **Reviewed:** 0bf005677874 against a764653726ba: Read the full changed host kernels, hooks and headers, both test fixtures and drivers, and the changed switch and patch sections. Read AGENTS.md, CONTRIBUTING.md, the Forgejo template and developer standards. Traced the surrounding lifter, local-register, guest-memory, write-mark and virtual-core code. Read the supplied comments and stale review. Skimmed the profile entries and reported run summaries. Raw run logs and generated game output were unavailable. No local docs/review-checklist.md or adjacent Tooling/AGENTS.md was present.; nothing run (a code review). **Checked and fine:** - The gates are supported-build-only, and the helper and effect entry declarations are at file scope. - The reciprocal-square-root table now uses single-writer initialization and release/acquire publication. - The fixtures cover output behavior, numerical declines, sequential delay state and full-width reverb addresses. Their build and execution steps are described and local. - The diff leaves vendor code, shaders, renderer ABI, menu keys and UTF-8 path handling untouched. It contains no game files or generated output. **Blocking** (to change before merge) 1. host/oot_reverb.c:318: Whole-context copies read and overwrite Ctx.poll, which another host thread sets atomically in vc_wake_holder. A virtual-core request posted while reverb processes a buffer can be replaced by the entry value of zero here or at the check-mode restore. The native loop also skips the lifted loop’s back-edge checkpoints. Copy only guest state the routine owns, and preserve checkpoints on the running context. Exercise a request posted during a buffer. 2. host/oot_fxtriggers.c:122: A second worker can read fxt_mode after the first publishes it but before the release store to started, bypassing acquisition and reading fxt_log without synchronization. The generated volatile gate loads also race with initialization stores. Use atomic gates and acquire published configuration before reading it, or initialize before workers start. Apply the same fix to rv_mode and the reverb gate. The added concurrency test enters the kernel directly and misses these races. 3. host/reverb_kernel.c:52: The plan checks delay-line allocation length and write place, but never bounds the read index produced by the slewed distance and wrap term. For example, with place zero and the current and target distance both larger than the wrap term, the first tap index is negative and can read before the allocation. Validate computed taps before dereferencing, or prove and enforce the distance and wrap invariants at entry. Add a decline case with a valid write place and an invalid tap. 4. host/reverb_kernel.c:131: Ordinary C and intrinsic loads do not preserve the promised sample-time reads of parameters that the PR says a live setter updates without a lock. For example, a mode change halfway through the buffer has no defined synchronization with these loads. Establish a defined read/write protocol for the live fields, or keep those objects on the lifted path. Test a parameter update during a buffer, including what check mode reports. 5. host/reverb_kernel.c:485: The fallback and FPSR result depend on observing the exceptions from every SIMD instruction before restoring MXCSR. Disabling contraction alone leaves the compiler free to optimize ordinary FP intrinsics without preserving their exception effects. Use an exception-aware implementation, as the existing fast FP path does with explicit ordered operations. Verify optimized Windows and Linux builds with an overflow and an underflow whose arithmetic result is otherwise dead. 6. host/oot_reverb.c:296: Check mode saves the guest frame and then deliberately skips comparing it. A wrong saved register or two-channel scratch word can still count as taken. Compare the frame bytes the lifted routine defines and inject a frame-only mismatch in the fixture. 7. host/oot_reverb.c:195: The two rollback buffers are heap allocations retained by raw thread-local pointers. When an audio worker exits, its pointers disappear without freeing the allocations, so recreating workers accumulates their high-water allocations. Give scratch space an owner with teardown and allocate the comparison buffer only in check mode. 8. tests/test_native_reverb.py:683: The SIMD probe tests compiler acceptance, then executes a binary forced to use SSE4.1 and FMA. On a supported pre-FMA x86-64 machine the compiler accepts those flags and the fixture can fault with an illegal instruction. Detect execution support before running that variant and always exercise the fallback. The FX test has the same problem with its -mfma probe. **Waiting on the author** (a run, a measurement or a decision; no edit does it) - nx2/oot_patches.py:1287: The new wrapper’s default-off cost is unmeasured. The old two- and four-channel path showed 7.6–16.3% more time per sample when disabled, and the effect gates still force their lifted bodies to keep registers in the context. Measure the affected paths on this head against the current base with the switches unset, including audio-worker CPU and frame pacing. - Establish an isolated in-game gain and verify the current head in the game on the affected Tier 1 systems. Complete the Windows and Linux builds with UTF-8 paths, required checks and CI. Include directional sound and reverb comparisons, listening tests and per-channel take counts. The previous farm request expired when the head changed. - The two- and four-channel commit and the automated head fix lack the required AI-assistance trailers. Record the applicable assistance and bring the PR description and checklist up to date with the wrapper and current-head evidence. **Testing:** Read-only review. No build, fixture or game run was executed. The supplied offline comparisons and mutation checks predate the current head, and the fixtures use stand-ins instead of compiling the generated entry paths. The author reports five failures also present on the previously tested main commit. The full suite and current-head CI are unverified. **Overlaps and merge order:** PR #1644 is related audio work. The checkout already has a separate I3DL2 submix implementation in host/nn_audio.c, and this diff changes the guest reverb path. No required merge order was established. --- <sub>Automated code review by BeanBot (gpt-6.2-sol), asked for by BeanBot, after its fix. Nothing was run; a maintainer decides.</sub>
@ -0,0 +119,4 @@
}
int hos_fxt_8012ba70(Ctx *c, A64Fn lifted) {
if (fxt_mode < 0) fxt_start();
Member

Reading fxt_mode can bypass the acquire while another worker publishes it. Use atomic gate loads and synchronized configuration publication in both hooks.

Reading fxt_mode can bypass the acquire while another worker publishes it. Use atomic gate loads and synchronized configuration publication in both hooks.
@ -0,0 +192,4 @@
int ok = m.table && m.mono;
for (int i = 0; i < 6; i++) m.vec[i] = rv_range(vec_at[i], 16), ok = ok && m.vec[i];
if (!ok) return rv_count(WHY_RANGE), 0;
if (rv_save_n < pl.bytes) {
Member

These allocations outlive the thread that owns their pointers. Give the buffers teardown ownership and allocate the second buffer only for check mode.

These allocations outlive the thread that owns their pointers. Give the buffers teardown ownership and allocate the second buffer only for check mode.
@ -0,0 +293,4 @@
}
const uint8_t *k = rv_save[1];
int dm = 0, first = -1;
for (int i = 0; i < pl.n - 1; i++) {
Member

This stops before the saved frame segment. A frame-only mismatch counts as a pass. Compare defined frame bytes and test that case.

This stops before the saved frame segment. A frame-only mismatch counts as a pass. Compare defined frame bytes and test that case.
@ -0,0 +315,4 @@
const int on[3] = {1, o[0x300] && o[0x2a1] != 1, o[0x450] && o[0x2a1] != 1};
for (int i = 0; i < pl.n - 1; i++) if (on[pl.s[i].stage]) HOS_WRITTEN(pl.s[i].p, pl.s[i].n);
}
*c = got;
Member

Whole-context assignment can clear a concurrent virtual-core poll request. Preserve the live scheduler field and restore the lifted loop’s checkpoints on the native path.

Whole-context assignment can clear a concurrent virtual-core poll request. Preserve the live scheduler field and restore the lifted loop’s checkpoints on the native path.
@ -0,0 +49,4 @@
the length in w17 and length - 1 in w18), then the next line's target into w4 */
#define TAPS(V, POFF, TOFF) do { \
x3 = ld64(o + (POFF)); \
V = LDS(H(x3 + (SX(x4) << 2))); \
Member

A valid write place does not bound this tap. An excessive slewed distance can leave a negative index after wrapping. Validate the tap range before loading.

A valid write place does not bound this tap. An excessive slewed distance can leave a negative index after wrapping. Validate the tap range before loading.
@ -0,0 +128,4 @@
st32(H(x12), 0), st32(H(x16), 0);
}
v6 = I2F(ld32(H(x10)));
x17 = ld32(o + 0x2a4);
Member

The live mode load has no defined synchronization with the documented setter. Establish a protocol and cover a change during the buffer.

The live mode load has no defined synchronization with the documented setter. Establish a protocol and cover a change during the buffer.
@ -0,0 +482,4 @@
if (_mm_getcsr() & 0x0d) { status = REVERB_INVALID; break; }
}
}
const unsigned flags = _mm_getcsr();
Member

The fallback depends on FP exception side effects. Enforce their ordering inside the MXCSR window and test optimized code with otherwise-dead arithmetic.

The fallback depends on FP exception side effects. Enforce their ordering inside the MXCSR window and test optimized code with otherwise-dead arithmetic.
@ -1246,0 +1284,4 @@
at = _function(out, head)
end = at[1]
body = out[start:end].replace(head, "static __attribute__((noinline)) void reverb_lifted_%s(Ctx *__restrict A64_NOESC c) {\n" % addr, 1)
wrapper = "\n" + head + gate + " reverb_lifted_%s(c);\n}\n" % addr
Member

Measure this wrapper against current main with reverb unset. The earlier two- and four-channel default-off measurements showed 7.6–16.3% extra time per sample.

Measure this wrapper against current main with reverb unset. The earlier two- and four-channel default-off measurements showed 7.6–16.3% extra time per sample.
@ -0,0 +680,4 @@
(tmp / f).write_text((ROOT / "host" / f).read_text(encoding="utf-8"), encoding="utf-8")
simd = ["-msse4.1", "-mfma"]
if subprocess.run([cc, "-x", "c"] + simd + ["-fsyntax-only", str(tmp / "reverb_kernel.c")], capture_output=True).returncode:
simd = [] # (not an x86 host: the kernel is not built, the hook declines)
Member

Compiler acceptance does not establish CPU support. Guard execution of both new FMA fixtures on supported pre-FMA machines.

Compiler acceptance does not establish CPU support. Guard execution of both new FMA fixtures on supported pre-FMA machines.
Conflict resolved on this branch: the fork head had the reverb mark loop on one line; it is taken in the pick's two-line form with reverb_written (no change of meaning).

Co-Authored-By: Codex Sol <[email protected]>
(cherry picked from commit dc4d68658e3337410a315788afe55c8f3bf223ab)
Restore the filtered paired stack store mark. Preflight reverb bitmap uniformity before writes, then use a cheap bulk walk or skip unwatched spans; mixed spans run lifted.

Conflicts resolved on this branch (reverb extended to two and four channels, and the hook given the helper argument): the uniform-bitmap preflight goes after the fork's rv_plan(c, count, channels, ..., &frame, &frame_n) call, still over every segment but the frame; the fixture keeps both guest_base and watch_mode/unwatched_page; the new test block calls hos_reverb_8372a5a0 with (lifted, helper) and writes the crossing pointer through GP() at guest_base + IO.

Co-Authored-By: Codex (GPT-6) <[email protected]>
(cherry picked from commit f6507ccbd044bb8bfc2bdd79801e79760b8fc907)
fix(build): the host's native hooks test the watch bitmap too (A64_MARK_BITMAP)
Some checks failed
PR description / Description follows the template (pull_request_target) Successful in 8s
Website / Website on Cloudflare (pull_request_target) Has been skipped
beanstalk/approval approved by HumanBean (reviewed)
beanstalk/any 0/1 pass, 2 running, 0 queued
CI / Conventional Commit title (pull_request) Has been cancelled
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Has been cancelled
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Has been cancelled
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Has been cancelled
CI / Workflow lint (actionlint) (pull_request) Has been cancelled
CI / Website build and checks (pull_request) Has been cancelled
Guide screenshots / Guide images and local UI source review (pull_request) Has been cancelled
Third-party parts / As their notes say (pull_request) Has been cancelled
Third-party parts / The same as upstream (pull_request) Has been cancelled
16a54b23b7
Every host file is now compiled with MARK_BITMAP, the lifted code's own setting, instead of none (or, on the crowd
branch, only host/oot_crowd.c). A native hook's A64_MARK then tests the first page's watch bit exactly as the lifted
store it stands for does, and the hooks' #ifdef A64_GPU_PAGE guards (the uniform-bitmap preflights in reverb and
visibility) are compiled in. hos_mark_written / HOS_WRITTEN, the host's own marks, still mark every page.
RX_MARK_BITMAP=0 turns the bitmap off for the lifted code and the hooks alike.

tests/test_mark_bitmap_host.py reads nx2/build.py (no build) and fails if the lifted flags or a host compile job
lack an unconditional MARK_BITMAP.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Owner
@fix
Owner

@Beanstalk

@Beanstalk
Member
Beanstalk test farm · an earlier run: commit 16a54b2 (the newer results are in a comment below)

Commit 16a54b2 · approved by HumanBean (reviewed) · dashboard

⚠️ Note: Check mode retains the lifted result and adds comparison overhead, so its performance is not representative of native mode; periodic call counts may not appear during these short runs.
⚠️ Note: The farm cannot listen for audio artifacts or establish which reverb channel paths were exercised; check-mode logs also do not cover every possible state or scheduler race.

Started at 07:34 UTC.

Estimate: done in about 2 h 45 min, from the queue and the testers online now.

Target Result Reports Frame time p99 (ms), main → PR VRAM peak (MB) Crashes
any 🔄 running 0 of 1 — — —
What was tested

What will be tested · AI plan (gpt-6.1-terra)

The plan compares main and the PR in the Market and Hyrule Field, with the new routines off and in combinations of native and check modes. It measures frame time, process CPU, load time and images, and fails on crashes, material regressions or logged native-versus-lifted differences. Gameplay runs take about 50 minutes per tester, plus timed lift builds.

  • Where: any (any PC, 1-2 reports).
  • Matrix: 4 cells, each on main and the PR: HOS_NATIVE_REVERB 1 or check (PR only); HOS_NATIVE_FXTRIGGERS 1 or check (PR only).
  • default-off: from the repository's save market-entrance, then move the stick, measure market for 20 s (after 5 s warm-up), take the picture market to compare with main, teleport to Hyrule Field, measure field for 20 s (after 5 s warm-up), take the picture field to compare with main; 1 run on each side.
  • native-and-check: from the repository's save market-entrance, then move the stick, measure market for 20 s (after 5 s warm-up), take the picture market to compare with main, teleport to Hyrule Field, measure field for 20 s (after 5 s warm-up), take the picture field to compare with main; 1 run on each side for each of 4 cells (4 game starts a run).
  • Build times: main and the PR each built 2 times, alternating, each whole in a fresh folder: the lift again (no kept lift, main's compiled objects kept); every stage timed (shader preparation is not), and the lifted C compared.
  • Measured: crashes, frame times, stutters and hitches, memory and CPU time, load times, the game's log.
  • The PR fails if: CPU time is more than 20% above main; or it crashes; or a picture differs from main by more than 5%; or the lift's time is more than 15% above main; or longest load is more than 25% above main; or frame time (p99) is more than 20% above main; or forbidden log lines is above 0.
  • Time: about 59 min of game runs per tester (10 game starts), plus the two builds and 4 timed builds (about 80 min).
Every scenario and matrix cell
Scenario · matrix cell Target Frame time p99 (ms), main → PR Result
native-and-check · HOS_NATIVE_REVERB=1 (PR only), HOS_NATIVE_FXTRIGGERS=1 (PR only) any — —
native-and-check · HOS_NATIVE_REVERB=1 (PR only), HOS_NATIVE_FXTRIGGERS=check (PR only) any — —
native-and-check · HOS_NATIVE_REVERB=check (PR only), HOS_NATIVE_FXTRIGGERS=1 (PR only) any — —
native-and-check · HOS_NATIVE_REVERB=check (PR only), HOS_NATIVE_FXTRIGGERS=check (PR only) any — —
<!-- beanstalk:previous --> <details><summary>Beanstalk test farm · an earlier run: commit <code>16a54b2</code> (the newer results are in a comment below)</summary> Commit `16a54b2` · approved by HumanBean (reviewed) · [dashboard](https://beanstalk.magicbean.dev/prs/1903) ⚠️ **Note:** Check mode retains the lifted result and adds comparison overhead, so its performance is not representative of native mode; periodic call counts may not appear during these short runs. ⚠️ **Note:** The farm cannot listen for audio artifacts or establish which reverb channel paths were exercised; check-mode logs also do not cover every possible state or scheduler race. Started at 07:34 UTC. **Estimate:** done in about 2 h 45 min, from the queue and the testers online now. | Target | Result | Reports | Frame time p99 (ms), main → PR | VRAM peak (MB) | Crashes | | --- | --- | --- | --- | --- | --- | | `any` | 🔄 running | 0 of 1 | — | — | — | <details><summary>What was tested</summary> **What will be tested** · AI plan (`gpt-6.1-terra`) The plan compares main and the PR in the Market and Hyrule Field, with the new routines off and in combinations of native and check modes. It measures frame time, process CPU, load time and images, and fails on crashes, material regressions or logged native-versus-lifted differences. Gameplay runs take about 50 minutes per tester, plus timed lift builds. - **Where:** any (any PC, 1-2 reports). - **Matrix:** 4 cells, each on main and the PR: HOS_NATIVE_REVERB `1` or `check` (PR only); HOS_NATIVE_FXTRIGGERS `1` or `check` (PR only). - **default-off:** from the repository's save `market-entrance`, then move the stick, measure market for 20 s (after 5 s warm-up), take the picture market to compare with main, teleport to Hyrule Field, measure field for 20 s (after 5 s warm-up), take the picture field to compare with main; 1 run on each side. - **native-and-check:** from the repository's save `market-entrance`, then move the stick, measure market for 20 s (after 5 s warm-up), take the picture market to compare with main, teleport to Hyrule Field, measure field for 20 s (after 5 s warm-up), take the picture field to compare with main; 1 run on each side for each of 4 cells (4 game starts a run). - **Build times:** main and the PR each built 2 times, alternating, each whole in a fresh folder: the lift again (no kept lift, main's compiled objects kept); every stage timed (shader preparation is not), and the lifted C compared. - **Measured:** crashes, frame times, stutters and hitches, memory and CPU time, load times, the game's log. - **The PR fails if:** CPU time is more than 20% above main; or it crashes; or a picture differs from main by more than 5%; or the lift's time is more than 15% above main; or longest load is more than 25% above main; or frame time (p99) is more than 20% above main; or forbidden log lines is above 0. - **Time:** about 59 min of game runs per tester (10 game starts), plus the two builds and 4 timed builds (about 80 min). </details> <details><summary>Every scenario and matrix cell</summary> | Scenario · matrix cell | Target | Frame time p99 (ms), main → PR | Result | | --- | --- | --- | --- | | native-and-check · `HOS_NATIVE_REVERB=1 (PR only), HOS_NATIVE_FXTRIGGERS=1 (PR only)` | any | — | — | | native-and-check · `HOS_NATIVE_REVERB=1 (PR only), HOS_NATIVE_FXTRIGGERS=check (PR only)` | any | — | — | | native-and-check · `HOS_NATIVE_REVERB=check (PR only), HOS_NATIVE_FXTRIGGERS=1 (PR only)` | any | — | — | | native-and-check · `HOS_NATIVE_REVERB=check (PR only), HOS_NATIVE_FXTRIGGERS=check (PR only)` | any | — | — | </details> </details>
Member

I changed this pull request where an edit could (the rest needs runs, measurements or decisions): the new head is 20694421db. I rebased it onto main (7486869e64).

Conflicts resolved

  • tests/run_all.py: Kept support for compiler commands in CC and the expanded compiler fallback.
  • tests/test_native_fxtriggers.py: Kept compiler command arguments in all compiler invocations.
  • tests/test_native_reverb.py: Kept compiler command arguments in all compiler invocations.
  • Also changed, beyond the conflict: tests/test_native_fxtriggers.py, tests/test_native_reverb.py

Changed

  • Effect hook initialization, host/oot_fxtriggers.c:37: Made gate accesses atomic and made both hooks acquire completed initialization before reading mode or log state.
  • Reverb initialization, host/oot_reverb.c:35: Made gate accesses atomic and made every hook call acquire completed initialization.
  • Reverb scratch buffers, host/oot_reverb.c:218: Scoped scratch allocation to each call and freed it on every subsequent return path.
  • CPU feature checks, tests/test_native_fxtriggers.py:875: Both tests probe runtime CPU support before executing their FMA or SSE4.1/FMA variants.
  • C compiler selection, tests/run_all.py:137: Both tests accept --cc and honor CC; the runner resolves and passes the selected C compiler. Tests and builds were not run.

Not done this time (still open: the next @fix takes it)

  • Independent kernels and provenance: host/reverb_kernel.c:1, host/fxt_kernels.c:125: The instruction-level implementations remain. They need independently written replacements based on permissible behavioral facts, with documented provenance; the existing transcriptions do not establish that provenance.

Left for the author

  • AI-assistance trailer on commit 28941d0796: The author must add the appropriate Assisted-by or Co-Authored-By trailer to that commit by rewriting it. This task prohibits changing git history.
  • Isolated game measurements: Both switches already default off in gpu/vk/switches.def:108, and taken counters remain in host/oot_fxtriggers.c:75 and host/oot_reverb.c:73. The author must measure this head against its base with each switch alone and both off in representative scenes, including CPU time, uncapped frame times and the audio-worker taken count, and validate it in game.
  • Default-off and build-time measurements: nx2/build.py:1898: The narrower bitmap compilation and reverb wrapper remain in nx2/build.py:1898 and nx2/oot_patches.py:1282. The author must measure this head's default-off game path and build time against the base.

Still for the author (no edit does these)

  • L7: The two- and four-channel extension commit 28941d0796 has no AI-assistance trailer, although the PR says it received AI assistance. Add the required Assisted-by or Co-Authored-By trailer to that commit.

Nothing was built or run: check the change. It will be reviewed again.


Automated fix by BeanBot (gpt-6.1-terra), asked for by HumanBean. Nothing was run; a maintainer decides.

I changed this pull request where an edit could (the rest needs runs, measurements or decisions): the new head is 20694421db6d. I rebased it onto `main` (7486869e64b1). **Conflicts resolved** - tests/run_all.py: Kept support for compiler commands in CC and the expanded compiler fallback. - tests/test_native_fxtriggers.py: Kept compiler command arguments in all compiler invocations. - tests/test_native_reverb.py: Kept compiler command arguments in all compiler invocations. - Also changed, beyond the conflict: `tests/test_native_fxtriggers.py`, `tests/test_native_reverb.py` **Changed** - **Effect hook initialization, host/oot_fxtriggers.c:37**: Made gate accesses atomic and made both hooks acquire completed initialization before reading mode or log state. - **Reverb initialization, host/oot_reverb.c:35**: Made gate accesses atomic and made every hook call acquire completed initialization. - **Reverb scratch buffers, host/oot_reverb.c:218**: Scoped scratch allocation to each call and freed it on every subsequent return path. - **CPU feature checks, tests/test_native_fxtriggers.py:875**: Both tests probe runtime CPU support before executing their FMA or SSE4.1/FMA variants. - **C compiler selection, tests/run_all.py:137**: Both tests accept --cc and honor CC; the runner resolves and passes the selected C compiler. Tests and builds were not run. **Not done this time (still open: the next `@fix` takes it)** - **Independent kernels and provenance: host/reverb_kernel.c:1, host/fxt_kernels.c:125**: The instruction-level implementations remain. They need independently written replacements based on permissible behavioral facts, with documented provenance; the existing transcriptions do not establish that provenance. **Left for the author** - **AI-assistance trailer on commit 28941d0796cb**: The author must add the appropriate Assisted-by or Co-Authored-By trailer to that commit by rewriting it. This task prohibits changing git history. - **Isolated game measurements**: Both switches already default off in gpu/vk/switches.def:108, and taken counters remain in host/oot_fxtriggers.c:75 and host/oot_reverb.c:73. The author must measure this head against its base with each switch alone and both off in representative scenes, including CPU time, uncapped frame times and the audio-worker taken count, and validate it in game. - **Default-off and build-time measurements: nx2/build.py:1898**: The narrower bitmap compilation and reverb wrapper remain in nx2/build.py:1898 and nx2/oot_patches.py:1282. The author must measure this head's default-off game path and build time against the base. **Still for the author** (no edit does these) - **L7**: The two- and four-channel extension commit 28941d0796cb has no AI-assistance trailer, although the PR says it received AI assistance. Add the required Assisted-by or Co-Authored-By trailer to that commit. Nothing was built or run: check the change. It will be reviewed again. --- <sub>Automated fix by BeanBot (gpt-6.1-terra), asked for by HumanBean. Nothing was run; a maintainer decides.</sub>
BeanBot force-pushed perf/native-fxtriggers from 16a54b23b7
Some checks failed
PR description / Description follows the template (pull_request_target) Successful in 8s
Website / Website on Cloudflare (pull_request_target) Has been skipped
beanstalk/approval approved by HumanBean (reviewed)
beanstalk/any 0/1 pass, 2 running, 0 queued
CI / Conventional Commit title (pull_request) Has been cancelled
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Has been cancelled
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Has been cancelled
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Has been cancelled
CI / Workflow lint (actionlint) (pull_request) Has been cancelled
CI / Website build and checks (pull_request) Has been cancelled
Guide screenshots / Guide images and local UI source review (pull_request) Has been cancelled
Third-party parts / As their notes say (pull_request) Has been cancelled
Third-party parts / The same as upstream (pull_request) Has been cancelled
to 20694421db
Some checks failed
beanstalk/approval changed since the request: ask again
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Has been skipped
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Has been skipped
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Has been skipped
Third-party parts / The same as upstream (pull_request) Has been skipped
Website / Website on Cloudflare (pull_request) Has been skipped
PR description / Description follows the template (pull_request_target) Successful in 34s
CI / Conventional Commit title (pull_request) Successful in 21s
CI / Workflow lint (actionlint) (pull_request) Successful in 36s
Guide screenshots / Guide images and local UI source review (pull_request) Failing after 29s
Third-party parts / As their notes say (pull_request) Successful in 33s
CI / Website build and checks (pull_request) Has been cancelled
2026-11-21 07:39:51 +00:00
Compare
Member

Beanstalk test farm

Commit e3024b8 · approved by nobody yet · dashboard

A member of BigBeans can review this commit and comment @Beanstalk to test it.

<!-- beanstalk:sticky --> ### Beanstalk test farm Commit `e3024b8` · approved by nobody yet · [dashboard](https://beanstalk.magicbean.dev/prs/1903) A member of `BigBeans` can review this commit and comment `@Beanstalk` to test it.
BeanBot left a comment

Recommendation: Request changes. The new bitmap test fails against the current build script, and the tests include sampled lifted game instructions prohibited by the repository rules. The performance gain and in-game correctness of this head also remain unproven.

Adds opt-in host implementations for two effect and sound calculations and for reverb. The offline comparisons are extensive, but the added code and maintenance cost are not yet justified by a measured gain for this branch.

@fix will do (5)

  1. L1 tests/test_mark_bitmap_host.py:61: This test requires MARK_BITMAP as an unconditional top-level term in every host compile job, but build.py now supplies it through a conditional expression for selected files. (more on the line)
  2. L2 tests/test_native_fxtriggers.py:59: The LIFTED fixtures contain sampled lifted instructions from the game; the reverb fixture contains another such instruction. (more on the line)
  3. L3: The description says the head passed the bitmap test and identifies only one commit without an AI-assistance trailer, but the final commit changes the flag policy that the test checks, and several commits have no such trailer. Correct the description and record the required assistance for the affected commits.
  4. L4 (its part an edit can do) host/oot_reverb.c:218: Reuse bounded scratch storage with a thread-lifetime cleanup, or otherwise remove the per-buffer allocation.
  5. L5 (its part an edit can do): Remove an unhelpful kernel or leave its default safe until the measurements support enabling it.

For the author (2) (a run, a measurement or a decision)

  • L4 (minor) host/oot_reverb.c:218: The final commit replaces reusable scratch storage with a malloc and free on every accepted audio buffer, after the reported measurements. (more on the line)
  • L5 (minor): The nine-branch measurement cannot attribute a gain to either switch, and the current head has not been checked or listened to in game. Measure this branch alone against its base, with each switch on and off, and complete the listed game and Tier 1 hardware checks before choosing defaults.
More: does it help, other systems, switches, what was read

Does it help: Unproven. The reported 2.7% and 2.4% process CPU reductions compare main with nine rewrite branches enabled together, not this PR alone; the audio worker remained at 0.038–0.039 cores. The offline speedups do not establish an in-game gain, and this head was not played.

Other systems: The hooks affect effect placement, directional audio, the audio worker and GPU page tracking. The bitmap build-flag change also affects existing host hooks with both new switches off. Windows testing covered only an earlier merged tree; Linux, Steam Deck, AMD and the current head remain untested.

Switches: HOS_NATIVE_FXTRIGGERS and HOS_NATIVE_REVERB default off; their LOG switches also default off. All four have table rows. The safe performance default cannot yet be chosen from the available measurements. RX_MARK_BITMAP is unchanged in name and default, but its flag now reaches selected host files.

Reviewed: 20694421db against 7486869e64: Read the repository rules, standards, PR template, commits, diff, host hooks, kernel interfaces, build and patch changes, and relevant page-marking code. Skimmed portions of the long kernel implementations and test fixtures; no generated files or recorded runs were added. The network was unavailable, so overlapping PRs could not be checked.; nothing run (a code review).

Checked and fine:

  • The new switch names have entries in switches.def.
  • First-use mode publication and the emitter table initialization use atomic synchronization.
  • Reverb allocation failure declines to the lifted routine, and the allocated scratch is freed on the examined return paths.
  • No renderer API or shader files were changed.

Testing: Read-only review; no project code, scripts, builds or tests were run. The test failure is determined from the test's AST check and the build expression.

Overlaps and merge order: Unknown; the network was unavailable.


Automated code review by BeanBot (gpt-6.1-terra), asked for by BeanBot, after its fix. Nothing was run; a maintainer decides.

**Recommendation: Request changes.** The new bitmap test fails against the current build script, and the tests include sampled lifted game instructions prohibited by the repository rules. The performance gain and in-game correctness of this head also remain unproven. Adds opt-in host implementations for two effect and sound calculations and for reverb. The offline comparisons are extensive, but the added code and maintenance cost are not yet justified by a measured gain for this branch. **`@fix` will do (5)** 1. **L1** `tests/test_mark_bitmap_host.py:61`: This test requires MARK_BITMAP as an unconditional top-level term in every host compile job, but build.py now supplies it through a conditional expression for selected files. (more on the line) 2. **L2** `tests/test_native_fxtriggers.py:59`: The LIFTED fixtures contain sampled lifted instructions from the game; the reverb fixture contains another such instruction. (more on the line) 3. **L3**: The description says the head passed the bitmap test and identifies only one commit without an AI-assistance trailer, but the final commit changes the flag policy that the test checks, and several commits have no such trailer. Correct the description and record the required assistance for the affected commits. 4. **L4** (its part an edit can do) `host/oot_reverb.c:218`: Reuse bounded scratch storage with a thread-lifetime cleanup, or otherwise remove the per-buffer allocation. 5. **L5** (its part an edit can do): Remove an unhelpful kernel or leave its default safe until the measurements support enabling it. **For the author (2)** (a run, a measurement or a decision) - **L4** (minor) `host/oot_reverb.c:218`: The final commit replaces reusable scratch storage with a malloc and free on every accepted audio buffer, after the reported measurements. (more on the line) - **L5** (minor): The nine-branch measurement cannot attribute a gain to either switch, and the current head has not been checked or listened to in game. Measure this branch alone against its base, with each switch on and off, and complete the listed game and Tier 1 hardware checks before choosing defaults. <details> <summary>More: does it help, other systems, switches, what was read</summary> **Does it help:** Unproven. The reported 2.7% and 2.4% process CPU reductions compare main with nine rewrite branches enabled together, not this PR alone; the audio worker remained at 0.038–0.039 cores. The offline speedups do not establish an in-game gain, and this head was not played. **Other systems:** The hooks affect effect placement, directional audio, the audio worker and GPU page tracking. The bitmap build-flag change also affects existing host hooks with both new switches off. Windows testing covered only an earlier merged tree; Linux, Steam Deck, AMD and the current head remain untested. **Switches:** HOS_NATIVE_FXTRIGGERS and HOS_NATIVE_REVERB default off; their LOG switches also default off. All four have table rows. The safe performance default cannot yet be chosen from the available measurements. RX_MARK_BITMAP is unchanged in name and default, but its flag now reaches selected host files. **Reviewed:** 20694421db6d against 7486869e64b1: Read the repository rules, standards, PR template, commits, diff, host hooks, kernel interfaces, build and patch changes, and relevant page-marking code. Skimmed portions of the long kernel implementations and test fixtures; no generated files or recorded runs were added. The network was unavailable, so overlapping PRs could not be checked.; nothing run (a code review). **Checked and fine:** - The new switch names have entries in switches.def. - First-use mode publication and the emitter table initialization use atomic synchronization. - Reverb allocation failure declines to the lifted routine, and the allocated scratch is freed on the examined return paths. - No renderer API or shader files were changed. **Testing:** Read-only review; no project code, scripts, builds or tests were run. The test failure is determined from the test's AST check and the build expression. **Overlaps and merge order:** Unknown; the network was unavailable. </details> --- <sub>Automated code review by BeanBot (gpt-6.1-terra), asked for by BeanBot, after its fix. Nothing was run; a maintainer decides.</sub>
@ -0,0 +215,4 @@
int ok = m.table && m.mono;
for (int i = 0; i < 6; i++) m.vec[i] = rv_range(vec_at[i], 16), ok = ok && m.vec[i];
if (!ok) return rv_count(WHY_RANGE), 0;
uint8_t *save = (uint8_t *)malloc(pl.bytes * (rv_mode == RV_CHECK ? 2 : 1));
Member

L4 (minor): The final commit replaces reusable scratch storage with a malloc and free on every accepted audio buffer, after the reported measurements. Measure this head against the base and switches-off build, including audio-worker time and frame pacing, and establish whether the reverb actually takes calls.

**L4** (minor): The final commit replaces reusable scratch storage with a malloc and free on every accepted audio buffer, after the reported measurements. Measure this head against the base and switches-off build, including audio-worker time and frame pacing, and establish whether the reverb actually takes calls.
@ -0,0 +58,4 @@
tup = call.args[0] if call.args else None
if not isinstance(tup, ast.Tuple) or len(tup.elts) < 4:
bad.append("line %d: a host job that is not (cc, source, object, flags, ...)" % call.lineno)
elif not takes_mark_bitmap(tup.elts[3]):
Member

L1: This test requires MARK_BITMAP as an unconditional top-level term in every host compile job, but build.py now supplies it through a conditional expression for selected files. The new test therefore reports a failure on this head. Update the test to verify the intended selected-file policy and catch omissions, or restore an unconditional flag.

**L1**: This test requires MARK_BITMAP as an unconditional top-level term in every host compile job, but build.py now supplies it through a conditional expression for selected files. The new test therefore reports a failure on this head. Update the test to verify the intended selected-file policy and catch omissions, or restore an unconditional flag.
@ -0,0 +56,4 @@
LIFTED = ('#include "a64.h"\n'
"void f_8012ba70(Ctx *__restrict A64_NOESC c) {\n"
" c->x[11]=recomp_load64(c,c->x[1] + 8);\n"
Member

L2: The LIFTED fixtures contain sampled lifted instructions from the game; the reverb fixture contains another such instruction. CONTRIBUTING.md prohibits committing output made from the game, including lifted code. Replace these bodies with arbitrary synthetic statements that exercise the patch without reproducing game output.

**L2**: The LIFTED fixtures contain sampled lifted instructions from the game; the reverb fixture contains another such instruction. CONTRIBUTING.md prohibits committing output made from the game, including lifted code. Replace these bodies with arbitrary synthetic statements that exercise the patch without reproducing game output.
perf(host): HOS_NATIVE_FXTRIGGERS and HOS_NATIVE_REVERB on by default; =0 runs the effect trigger routines and the reverb lifted
Some checks are pending
CI / Conventional Commit title (pull_request) Blocked by required conditions
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Blocked by required conditions
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Blocked by required conditions
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Blocked by required conditions
CI / Workflow lint (actionlint) (pull_request) Blocked by required conditions
CI / Website build and checks (pull_request) Blocked by required conditions
Guide screenshots / Guide images and local UI source review (pull_request) Blocked by required conditions
Third-party parts / As their notes say (pull_request) Blocked by required conditions
Third-party parts / The same as upstream (pull_request) Blocked by required conditions
beanstalk/approval changed since the request: ask again
PR description / Description follows the template (pull_request_target) Successful in 20s
e3024b87e6
docs/dev/standards.md: a switch ships at its value from the branch's first push, never off because it is new.
The row's kind is kill, unset reads as 1 (env_on_or), and the test runs unset as on and 0 / off as off.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
snaildev99 changed title from WIP: perf(host): the effect emitter matrix, the sounds' angle fraction and the audio reverb on host code, bit for bit (HOS_NATIVE_FXTRIGGERS, HOS_NATIVE_REVERB, off by default) to WIP: perf(host): the effect emitter matrix, the sounds' angle fraction and the audio reverb on host code, bit for bit (HOS_NATIVE_FXTRIGGERS, HOS_NATIVE_REVERB, on by default) 2026-11-21 07:46:20 +00:00
Author
Contributor

HOS_NATIVE_FXTRIGGERS and HOS_NATIVE_REVERB are now on by default (e3024b87, on top of BeanBot's 20694421), as docs/dev/standards.md asks: a switch ships at its value from the first push, not off because it is new. HOS_NATIVE_FXTRIGGERS=0 / HOS_NATIVE_REVERB=0 gives main's lifted code. The row's kind is kill, unset reads as on (env_on_or), and the test runs it unset and =1 (on), =0 and =off (off) and check; it fails when the old read is put back. Title and description updated to match.

`HOS_NATIVE_FXTRIGGERS` and `HOS_NATIVE_REVERB` are now on by default (e3024b87, on top of BeanBot's 20694421), as docs/dev/standards.md asks: a switch ships at its value from the first push, not off because it is new. `HOS_NATIVE_FXTRIGGERS=0` / `HOS_NATIVE_REVERB=0` gives main's lifted code. The row's kind is `kill`, unset reads as on (`env_on_or`), and the test runs it unset and `=1` (on), `=0` and `=off` (off) and `check`; it fails when the old read is put back. Title and description updated to match.
HumanBean left a comment

Recommendation: Request changes. The two kernels are the game's routines carried over one Arm instruction at a time, with the disassembly's mnemonics and the game's code addresses in the comments. CONTRIBUTING.md's Licensing section forbids decompiled game code, so neither kernel can merge as written. There are also three things to fix in the code itself: the reverb hook loses virtual-core requests, the PR's own bitmap test fails at this head, and the gate fixtures are lines of the lifted game.

What it does: the emitter matrix, a sound's direction factor and the audio worker's reverb run as host code with the game's results. It has no measured gain of its own yet, and the reverb's gain looks like zero.

Does it help: Unproven. The only in-game number (-2.7 % process CPU standing, -2.4 % turning, three runs each, Windows / RTX 3090, 60 fps cap) comes from nine rewrite branches together, on main 068fb8eb and not this head. The audio worker, where the reverb runs, stayed at 0.038 to 0.039 cores in every variant, and no reverb: taken count was logged. Note that 1.14 % of the game's code time would be more than that whole thread's 0.039 cores, so it's quite possible every reverb call declined, for example on FPCR. The offline speed-ups (4 to 13 times per call) don't show a gain in the game.

Other systems:

  • Audio: the reverb runs on the audio library's low-priority worker. The tail, clicks and pacing haven't been listened to, and the angle fraction (directional volume) hasn't been checked in the game.
  • Virtual-core scheduling (*c = got, below).
  • The page marks: the build change now compiles every host file with A64_MARK_BITMAP, so the existing hooks' recomp_store* (hos_main.c, hos_wide_ui.c, oot_heap_retry.c, oot_shadow_fit.c, oot_text_size.c) mark only GPU pages, as the lifted stores already do. This applies with both switches off too.
  • Linux, AMD and the Steam Deck: not built or run. The kernels need SSE4.1 and FMA (x86-64-v3 has both) and decline without them.
  • The build: one extra noinline call a buffer for the reverb wrapper, and the two leaves keep their context form. The off cost was not measured at this head.

Switches:

  • HOS_NATIVE_FXTRIGGERS (kill, on by default) and HOS_NATIVE_REVERB (kill, on by default): shipping on matches docs/dev/standards.md (never off because new). The gain is Unproven, so I left the defaults alone. The Test Farm run of this branch alone decides them before WIP comes off.
  • HOS_NATIVE_FXTRIGGERS_LOG / HOS_NATIVE_REVERB_LOG (diag, off): right.
  • The description's Switches paragraph still ends "Both ship off: neither has been measured alone yet", which contradicts the title, the rows and e3024b87.

Reviewed: e3024b87e against 7486869e6 (its base). Read in full: host/oot_fxtriggers.c, host/fxt_kernels.c/.h, host/oot_reverb.c, host/reverb_kernel.c/.h, the nx2/oot_patches.py and nx2/build.py hunks, gpu/vk/switches.def, tests/test_mark_bitmap_host.py, tests/run_all.py. Read in part: the two native tests' fixtures and models. Nothing was run; this is a code review. The commits rebase onto main b62932a96 commit by commit with no conflict.
Fixed in this review: nothing pushed: the push to snaildev99's fork was refused here. The three fixes are below as suggestions, and the rebase onto b62932a96 is clean.
Checked and fine:

  • First-call setup: started's acquire/release covers fxt_mode, fxt_log, rv_mode and rv_log, and the gates are atomic loads. BeanBot's race is resolved.
  • rsq_tab uses single-writer initialisation with release/acquire.
  • The reverb gate sits in a wrapper, so the lifted body keeps main's register locals. The 7.6 to 16.3 % off cost was measured on the old form. The new cost is one call a buffer, not measured.
  • The reverb's writes: every place a write uses (+0x388, +0x3d4, +0x4a0, +0x4d8.., +0x540..) is checked against its length before the buffer, and the saved bytes cover them with the wrap.
  • Tap reads past a delay line (BeanBot's point) read the same guest address the lifted code reads (H() is A64_MEM + a as A64_PTR), so this is no new fault.
  • A live setter racing the kernel has the same plain-load race as the lifted routine.
  • The native loop skips the per-sample polls for at most 4,096 samples (about 0.3 ms).
  • The gates are on the supported build only, and both C files have the -ffast-math and contraction guards.

Blocking (to change before merge)

  1. Licensing: the kernels are transcriptions of the game's code. CONTRIBUTING.md's Licensing section allows the host's replacements to be written only from facts about how the game behaves. These files are written statement for statement from the disassembly:

    • host/reverb_kernel.c:1-2 says so itself: "The game's instructions in their order; the comments name the game's addresses".
    • host/reverb_kernel.h:30: "one host vector operation an instruction".
    • host/reverb_kernel.c:50-66 (TAPS) and :98-125 keep the game's register allocation (x3, x4, x5, x17, x18, v6, v7, v16..v24) and branch targets (0x8372a620, 0x8372ad80, 0x8372ad9c).
    • host/reverb_kernel.c:233: SUBS w2, w2, #2; CSEL w18, w18, w2, lt.
    • host/fxt_kernels.c:195: "the routine's instructions in their order on a copy of its registers".
    • host/fxt_kernels.c:244-313: the cofactor chain with the game's register numbers, at 806fe5f0 and 806fe6cc.
    • host/fxt_kernels.c:291 (FMSUB) and :339 (FCMP s3, #0.0; FCCMP s1, s4, #0, eq; CSET w9, eq).
    • host/fxt_kernels.c:155-158 (FMUL .4s, EXT #8, FADD .2s, FADDP) and the x_from table at :142.
    • host/oot_reverb.c:260-296 rebuilds the game's exact register and frame state (x8..x19, the saved-pair layout).
    • The tests' models ("the game's instructions one by one", test_native_fxtriggers.py's model) are written the same way.

    This is the same problem as on 1911. What would pass: kernels written from what the routines do (normalise three axes, the cone fraction, a feedback-delay reverb), in your own words and citing public sources, that return only the results the callers use. Keep the bit-for-bit check against the lifted routine in check mode, but drop the register-for-register reproduction.

  2. host/oot_reverb.c:344 (and :304 in check mode): *c = got / *c = entry write the whole context back as it was at entry. That includes poll, which vc_wake_holder (host/hos_thread.c:1902) sets on another thread to ask this thread to give up its virtual core. A request posted while a buffer runs is lost, and the waiter stalls until the worker's next SVC. Fix: copy back only x, vreg, NZCV and FPSR (suggested below).

  3. nx2/build.py:1898: BeanBot's 20694421 narrowed MARK_BITMAP to seven named host files. tests/test_mark_bitmap_host.py (this PR's) requires it unconditionally and fails at this head. A new hook using recomp_store* would also silently mark every page. Every sibling (1898, 1899, 1900, 1902, 1904, 1909, 1910) has the unconditional MARK_BITMAP +. Put that back.

  4. tests/test_native_fxtriggers.py:59,64 and tests/test_native_reverb.py:48,691: the fixture bodies are the routines' first lifted lines (recomp_load32(c,c->x[1] + 36) is the kernel's first load, mtx + 0x24). "The lifted C" is on the banned list. Use stand-in statements (for example c->x[9]=c->x[2] ^ 5;). The tests only check where the gate goes.

  5. The description: the Switches paragraph says "Both ship off" (see Switches). The checklist says one commit lacks a trailer, but a2728964 / 7ee2adf3 still has none.

Suggestions

  • The fixes for 2 to 4, ready to take (I made them as three commits on a rebase onto b62932a96 but couldn't push):
    • in oot_reverb.c, a regs_to(Ctx *c, const Ctx *from) that copies x, vreg, n/z/c/v and fpsr, used in place of both whole-struct assignments;
    • build.py back to MARK_BITMAP + with the "Every host file" comment;
    • the fixtures as above.
  • host/oot_reverb.c:221: the per-buffer malloc/free came after the measurements. A per-thread buffer that grows and is freed at thread exit would avoid a heap call a buffer. Minor next to the kernel.
  • host/reverb_kernel.c:95-96,485: the declines rely on MXCSR flags from intrinsics. Clang and GCC don't model FP exceptions without -ffp-exception-behavior=strict / #pragma STDC FENV_ACCESS ON, so in principle an operation could move past the _mm_getcsr. Worth the pragma for this file once rewritten.
  • Check mode doesn't compare the frame (pl.n - 1). That's harmless for the result (the frame is below SP), but say so in the comment.

Testing: no run at this head. The emitter matrix was checked in the game in an older merged tree (Windows, RTX 3090). The angle fraction and the reverb have not been checked or listened to in the game. Missing: this branch alone against main with each switch =0 and unset (with the _LOG counts), the reverb listening check, and Linux. The Test Farm request expired with the head (the sticky comment wants a BigBean @Beanstalk on e3024b8).
Overlaps and merge order:

  • The siblings above add the same build.py MARK_BITMAP hunk and tests/test_mark_bitmap_host.py, so whichever merges first carries it and the rest drop it on rebase. Each also adds rows to gpu/vk/switches.def and hooks in nx2/oot_patches.py (textual neighbours only).
  • 1644 is related audio reverb work with no file overlap.
**Recommendation: Request changes.** The two kernels are the game's routines carried over one Arm instruction at a time, with the disassembly's mnemonics and the game's code addresses in the comments. CONTRIBUTING.md's Licensing section forbids decompiled game code, so neither kernel can merge as written. There are also three things to fix in the code itself: the reverb hook loses virtual-core requests, the PR's own bitmap test fails at this head, and the gate fixtures are lines of the lifted game. What it does: the emitter matrix, a sound's direction factor and the audio worker's reverb run as host code with the game's results. It has no measured gain of its own yet, and the reverb's gain looks like zero. **Does it help:** Unproven. The only in-game number (-2.7 % process CPU standing, -2.4 % turning, three runs each, Windows / RTX 3090, 60 fps cap) comes from nine rewrite branches together, on main 068fb8eb and not this head. The audio worker, where the reverb runs, stayed at 0.038 to 0.039 cores in every variant, and no `reverb:` taken count was logged. Note that 1.14 % of the game's code time would be more than that whole thread's 0.039 cores, so it's quite possible every reverb call declined, for example on FPCR. The offline speed-ups (4 to 13 times per call) don't show a gain in the game. **Other systems:** - Audio: the reverb runs on the audio library's low-priority worker. The tail, clicks and pacing haven't been listened to, and the angle fraction (directional volume) hasn't been checked in the game. - Virtual-core scheduling (`*c = got`, below). - The page marks: the build change now compiles every host file with `A64_MARK_BITMAP`, so the existing hooks' `recomp_store*` (hos_main.c, hos_wide_ui.c, oot_heap_retry.c, oot_shadow_fit.c, oot_text_size.c) mark only GPU pages, as the lifted stores already do. This applies with both switches off too. - Linux, AMD and the Steam Deck: not built or run. The kernels need SSE4.1 and FMA (x86-64-v3 has both) and decline without them. - The build: one extra noinline call a buffer for the reverb wrapper, and the two leaves keep their context form. The off cost was not measured at this head. **Switches:** - `HOS_NATIVE_FXTRIGGERS` (kill, on by default) and `HOS_NATIVE_REVERB` (kill, on by default): shipping on matches docs/dev/standards.md (never off because new). The gain is Unproven, so I left the defaults alone. The Test Farm run of this branch alone decides them before WIP comes off. - `HOS_NATIVE_FXTRIGGERS_LOG` / `HOS_NATIVE_REVERB_LOG` (diag, off): right. - The description's Switches paragraph still ends "Both ship off: neither has been measured alone yet", which contradicts the title, the rows and e3024b87. **Reviewed:** e3024b87e against 7486869e6 (its base). Read in full: host/oot_fxtriggers.c, host/fxt_kernels.c/.h, host/oot_reverb.c, host/reverb_kernel.c/.h, the nx2/oot_patches.py and nx2/build.py hunks, gpu/vk/switches.def, tests/test_mark_bitmap_host.py, tests/run_all.py. Read in part: the two native tests' fixtures and models. Nothing was run; this is a code review. The commits rebase onto main b62932a96 commit by commit with no conflict. **Fixed in this review:** nothing pushed: the push to snaildev99's fork was refused here. The three fixes are below as suggestions, and the rebase onto b62932a96 is clean. **Checked and fine:** - First-call setup: `started`'s acquire/release covers `fxt_mode`, `fxt_log`, `rv_mode` and `rv_log`, and the gates are atomic loads. BeanBot's race is resolved. - `rsq_tab` uses single-writer initialisation with release/acquire. - The reverb gate sits in a wrapper, so the lifted body keeps main's register locals. The 7.6 to 16.3 % off cost was measured on the old form. The new cost is one call a buffer, not measured. - The reverb's writes: every place a write uses (+0x388, +0x3d4, +0x4a0, +0x4d8.., +0x540..) is checked against its length before the buffer, and the saved bytes cover them with the wrap. - Tap reads past a delay line (BeanBot's point) read the same guest address the lifted code reads (`H()` is `A64_MEM + a` as `A64_PTR`), so this is no new fault. - A live setter racing the kernel has the same plain-load race as the lifted routine. - The native loop skips the per-sample polls for at most 4,096 samples (about 0.3 ms). - The gates are on the supported build only, and both C files have the `-ffast-math` and contraction guards. **Blocking** (to change before merge) 1. **Licensing: the kernels are transcriptions of the game's code.** CONTRIBUTING.md's Licensing section allows the host's replacements to be written only from facts about how the game behaves. These files are written statement for statement from the disassembly: - `host/reverb_kernel.c:1-2` says so itself: "The game's instructions in their order; the comments name the game's addresses". - `host/reverb_kernel.h:30`: "one host vector operation an instruction". - `host/reverb_kernel.c:50-66` (`TAPS`) and `:98-125` keep the game's register allocation (x3, x4, x5, x17, x18, v6, v7, v16..v24) and branch targets (`0x8372a620`, `0x8372ad80`, `0x8372ad9c`). - `host/reverb_kernel.c:233`: `SUBS w2, w2, #2; CSEL w18, w18, w2, lt`. - `host/fxt_kernels.c:195`: "the routine's instructions in their order on a copy of its registers". - `host/fxt_kernels.c:244-313`: the cofactor chain with the game's register numbers, at `806fe5f0` and `806fe6cc`. - `host/fxt_kernels.c:291` (`FMSUB`) and `:339` (`FCMP s3, #0.0; FCCMP s1, s4, #0, eq; CSET w9, eq`). - `host/fxt_kernels.c:155-158` (`FMUL .4s`, `EXT #8`, `FADD .2s`, `FADDP`) and the `x_from` table at `:142`. - `host/oot_reverb.c:260-296` rebuilds the game's exact register and frame state (x8..x19, the saved-pair layout). - The tests' models ("the game's instructions one by one", test_native_fxtriggers.py's model) are written the same way. This is the same problem as on [1911](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/1911). What would pass: kernels written from what the routines do (normalise three axes, the cone fraction, a feedback-delay reverb), in your own words and citing public sources, that return only the results the callers use. Keep the bit-for-bit check against the lifted routine in check mode, but drop the register-for-register reproduction. 2. `host/oot_reverb.c:344` (and `:304` in check mode): `*c = got` / `*c = entry` write the whole context back as it was at entry. That includes `poll`, which `vc_wake_holder` (host/hos_thread.c:1902) sets on another thread to ask this thread to give up its virtual core. A request posted while a buffer runs is lost, and the waiter stalls until the worker's next SVC. Fix: copy back only x, vreg, NZCV and FPSR (suggested below). 3. `nx2/build.py:1898`: BeanBot's 20694421 narrowed `MARK_BITMAP` to seven named host files. `tests/test_mark_bitmap_host.py` (this PR's) requires it unconditionally and fails at this head. A new hook using `recomp_store*` would also silently mark every page. Every sibling ([1898](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/1898), [1899](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/1899), [1900](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/1900), [1902](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/1902), [1904](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/1904), [1909](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/1909), [1910](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/1910)) has the unconditional `MARK_BITMAP +`. Put that back. 4. `tests/test_native_fxtriggers.py:59,64` and `tests/test_native_reverb.py:48,691`: the fixture bodies are the routines' first lifted lines (`recomp_load32(c,c->x[1] + 36)` is the kernel's first load, `mtx + 0x24`). "The lifted C" is on the banned list. Use stand-in statements (for example `c->x[9]=c->x[2] ^ 5;`). The tests only check where the gate goes. 5. The description: the Switches paragraph says "Both ship off" (see Switches). The checklist says one commit lacks a trailer, but a2728964 / 7ee2adf3 still has none. **Suggestions** - The fixes for 2 to 4, ready to take (I made them as three commits on a rebase onto b62932a96 but couldn't push): - in oot_reverb.c, a `regs_to(Ctx *c, const Ctx *from)` that copies `x`, `vreg`, `n/z/c/v` and `fpsr`, used in place of both whole-struct assignments; - build.py back to `MARK_BITMAP +` with the "Every host file" comment; - the fixtures as above. - `host/oot_reverb.c:221`: the per-buffer `malloc`/`free` came after the measurements. A per-thread buffer that grows and is freed at thread exit would avoid a heap call a buffer. Minor next to the kernel. - `host/reverb_kernel.c:95-96,485`: the declines rely on MXCSR flags from intrinsics. Clang and GCC don't model FP exceptions without `-ffp-exception-behavior=strict` / `#pragma STDC FENV_ACCESS ON`, so in principle an operation could move past the `_mm_getcsr`. Worth the pragma for this file once rewritten. - Check mode doesn't compare the frame (`pl.n - 1`). That's harmless for the result (the frame is below SP), but say so in the comment. **Testing:** no run at this head. The emitter matrix was checked in the game in an older merged tree (Windows, RTX 3090). The angle fraction and the reverb have not been checked or listened to in the game. Missing: this branch alone against main with each switch `=0` and unset (with the `_LOG` counts), the reverb listening check, and Linux. The Test Farm request expired with the head (the sticky comment wants a BigBean `@Beanstalk` on e3024b8). **Overlaps and merge order:** - The siblings above add the same build.py `MARK_BITMAP` hunk and `tests/test_mark_bitmap_host.py`, so whichever merges first carries it and the rest drop it on rebase. Each also adds rows to gpu/vk/switches.def and hooks in nx2/oot_patches.py (textual neighbours only). - [1644](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/1644) is related audio reverb work with no file overlap.
@ -0,0 +192,4 @@
M(7, -S(1));
W(24, S(16) / S(5));
W(5, S(4) * S(24));
W(4, -(S(6) * S(2)));
Owner

Licensing (blocking): "the routine's instructions in their order on a copy of its registers". Lines 244-313 and 339 reproduce the disassembly (register numbers, FMSUB, FCMP/FCCMP/CSET). Write it from what it computes (the inverse, the angle, the cone fraction) instead.

Licensing (blocking): "the routine's instructions in their order on a copy of its registers". Lines 244-313 and 339 reproduce the disassembly (register numbers, FMSUB, FCMP/FCCMP/CSET). Write it from what it computes (the inverse, the angle, the cone fraction) instead.
@ -0,0 +341,4 @@
for (int i = 0; i < pl.n - 1; i++)
if (on[pl.s[i].stage]) reverb_written(pl.s[i].p, pl.s[i].n);
}
*c = got;
Owner

This writes back the whole Ctx from entry, poll included. A virtual-core request (vc_wake_holder) posted while the buffer ran is lost. Copy back only x, vreg, NZCV and FPSR. Line 304 (check mode) has the same problem.

This writes back the whole Ctx from entry, `poll` included. A virtual-core request (`vc_wake_holder`) posted while the buffer ran is lost. Copy back only x, vreg, NZCV and FPSR. Line 304 (check mode) has the same problem.
@ -0,0 +1,520 @@
/* (longshot) HOS_NATIVE_REVERB's kernel: see reverb_kernel.h. The game's instructions in their order; the comments
Owner

Licensing (blocking): by its own comment this file is the game's routine instruction by instruction, with the game's registers and code addresses. CONTRIBUTING.md forbids decompiled game code. Rewrite it from behaviour (a feedback-delay reverb), in your own words, and keep the bit-for-bit check in check mode.

Licensing (blocking): by its own comment this file is the game's routine instruction by instruction, with the game's registers and code addresses. CONTRIBUTING.md forbids decompiled game code. Rewrite it from behaviour (a feedback-delay reverb), in your own words, and keep the bit-for-bit check in check mode.
@ -0,0 +230,4 @@
x2 = S(x2) < 1 ? W(x17) : W(x2);
x3 = x1 + (SX(x2) << 2);
{
const int lt = S(x2) < 2; /* SUBS w2, w2, #2; CSEL w18, w18, w2, lt */
Owner

Licensing: SUBS w2, w2, #2; CSEL w18, w18, w2, lt is the disassembly carried over as-is.

Licensing: `SUBS w2, w2, #2; CSEL w18, w18, w2, lt` is the disassembly carried over as-is.
@ -1894,6 +1895,8 @@ def main():
(["-I" + os.path.join(FFMPEG, "include")] if FFMPEG else []) +
(FFMPEG_LX[0] if LINUX and FFMPEG_LX else []) +
([stamp_def] if os.path.basename(s) == "version.c" else []) +
(MARK_BITMAP if os.path.basename(s) in ("oot_fxtriggers.c", "oot_reverb.c", "hos_main.c",
Owner

tests/test_mark_bitmap_host.py fails with this conditional, and a new hook using recomp_store* would miss the bitmap. Put back the unconditional MARK_BITMAP +, as every sibling branch has it.

`tests/test_mark_bitmap_host.py` fails with this conditional, and a new hook using `recomp_store*` would miss the bitmap. Put back the unconditional `MARK_BITMAP +`, as every sibling branch has it.
@ -0,0 +61,4 @@
"void f_8012bbd0(Ctx *__restrict A64_NOESC c) {\n"
"}\n"
"void f_806fe5f0(Ctx *__restrict A64_NOESC c) {\n"
" c->x[8]=recomp_load32(c,c->x[1] + 36);\n"
Owner

This and line 59 (and test_native_reverb.py:48) are the routines' own first lifted lines. Use stand-in statements: the test only checks where the gate goes.

This and line 59 (and test_native_reverb.py:48) are the routines' own first lifted lines. Use stand-in statements: the test only checks where the gate goes.
Some checks are pending
CI / Conventional Commit title (pull_request) Blocked by required conditions
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Blocked by required conditions
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Blocked by required conditions
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Blocked by required conditions
CI / Workflow lint (actionlint) (pull_request) Blocked by required conditions
CI / Website build and checks (pull_request) Blocked by required conditions
Guide screenshots / Guide images and local UI source review (pull_request) Blocked by required conditions
Third-party parts / As their notes say (pull_request) Blocked by required conditions
Third-party parts / The same as upstream (pull_request) Blocked by required conditions
beanstalk/approval changed since the request: ask again
PR description / Description follows the template (pull_request_target) Successful in 20s
This pull request is marked as a work in progress.
Some workflows are waiting to be reviewed.
This branch is out-of-date with the base branch
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u 'perf/native-fxtriggers:snaildev99-perf/native-fxtriggers'
git switch 'snaildev99-perf/native-fxtriggers'
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
4 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
MagicBeanDev/Longshot!1903
No description provided.