WIP: perf(host): the submit walk's deferred binds resolved by an x86-64 kernel (lsasm_nvn_resolve) #2099

Draft
siantm wants to merge 24 commits from siantm/Longshot:perf/asm-nvn-resolve into main
Contributor

Summary

At each submit nvnQueueSubmitCommands walks every submitted recording (resolve_deferred in host/nvn_native.c) to
copy each deferred bind's array from the game's memory into its record. The C walk branched on each record's op being
a bind, a mispredict whenever the ops came in no pattern, and copied each array through gw and a memcpy call.

This adds host/asm/nvn.S on the asm kit: lsasm_nvn_resolve walks the records itself up to the first one it leaves
to C (END, a malformed record, or a bind whose copy is not plain: past its record, or a source outside the guest
window). On the way, each record's source word, or a zero word, is chosen by cmov, so a record that is no deferred
bind takes no branch; a deferred bind's array is copied in place by 16-byte moves, the last one overlapping.
resolve_deferred keeps its C loop for the records handed back: the same copies, the same stops (a corrupt record, a
source outside the window). Static asserts hold the record layouts and lsasm_nvn_walk to what the kernel reads. The
result expected: the same stream bytes, the submit's walk faster on mixed streams.

No switch: the copies are the same, so a revert is enough.

From 981d2d8c on exp/x86-asm-sync. Depends on #1947 (the asm kit, which now carries the GPU-visible ranges' sort,
lsasm_sort_ranges): its commits show in this diff until #1947 merges.

Read first: host/asm/nvn.S and host/asm/nvn.h, then resolve_deferred in host/nvn_native.c.

Testing

Tested: Windows 11, i7-9700, RTX 4060, the builder's llvm-mingw clang 23 (CC/CXX, RX_CPM set); head ee821a37
on #1947's head cffa2f46 (the asm kit, on main 9dd41326). Through the PC's job queue, each run in a hidden console,
tests/run_all.py --strict --exact --jobs 2 --timeout 1200: the change's own checks (light job pr-tb-AsmCut5-light,
log t-AsmCut5-asm-nvn-resolve): test_asm_nvn.py pass (1 of 1). --changed cffa2f46 (build job
pr-tb-AsmCut5-build, log t-AsmCut5-chg-asm-nvn-resolve): 23 checks, 21 pass, 2 fail, each of which fails on #1947's
head @ cffa2f46 too (a worktree at cffa2f46 in the queue's jobs, log t-AsmCut5-base-kit-changed): test_dev_packs.py,
test_host_guest_writes.py.

It has run in the game on this PC once: the in-play A/B in Measurements (held job fb-g2099, the Market, 18 runs), with
no FATAL, device lost or Vulkan error in any run.

Still to test:

  • Windows 11, i7-9700, RTX 4060 (this PC): Kokiri Forest, turning the camera, uncapped (HOS_FPS_MAX=240), on
    #1947's head and on this PR, each warmed a minute, then at least three interleaved three-minute runs of each (AB AB
    AB), and one run of each with HOS_PROFILE=1 (python -I scripts/perf.py report on its folder:
    resolve_deferred's share of the submitting thread), expecting the same picture, no FATAL, that share lower and fps
    and frame times of this PR at least the base's; a difference beyond the runs' spread is a gain or a loss, one within
    it is no difference measured (by hand)
  • Linux NVIDIA and AMD, Windows AMD and Intel, Steam Deck: Kokiri Forest, play three minutes on #1947's head and on
    this PR, warmed and interleaved, expecting the same picture, no FATAL, and frame times within the runs' spread or
    better on this PR (@Beanstalk linux+nvidia, linux+amd, windows+amd, windows+intel, steamdeck: Kokiri Forest three
    minutes, #1947's head against this PR, warmed and interleaved, frame times and a screenshot)
  • Linux: python3 -I -B tests/test_asm_nvn.py --cxx g++ and --cxx clang++, expecting PASS (by hand)

Measurements

Verdict: a small gain on mixed record streams, none or a loss elsewhere: lsasm_nvn_resolve is 1.07× (SSE2)
and 1.10× (AVX2) the C walk's speed per record on the mixed stream, 1.25-1.27× where binds have no source and
1.05-1.06× on patterned runs of deferred binds; slower where deferred binds are sparse (0.91-0.93×) or copy full
32-handle or 16-range arrays (0.95-0.96×). A micro-benchmark on authored input. A third party's Steam Deck run is
below.

In play on this PC (the Market, this head against its parent, the asm kit cffa2f46, 8 runs each, below): no gain shown
where the kernel runs. resolve_deferred runs in nvnQueueSubmitCommands on the game's own thread, about 5 times a
frame, and that thread's calm-stretch game time is the same (-0.1 %, p = 0.95). The render thread's replay figures lean
6-10 % to this head, at p 0.04 to 0.06. They move together, at the edge with 14 figures read, and in a stage the kernel
does not run in, so they are not claimed.

Baseline: #1947's head cffa2f46 (the asm kit on main 9dd41326, which this PR depends on), not main itself: for the micro-benchmark, the C this PR replaces as cffa2f46 has it; for the third party's run below, that head's whole build.

The micro-benchmark: resolve_deferred as cffa2f46 has it (the C walk) against the head's (with lsasm_nvn_resolve), both cut from host/nvn_native.c and compiled as C, over authored recordings of 8,000 records and a 1 MB guest window of authored bytes. A script on this PC, not in this PR (asm_nvn_bench.py, PrTrials' trials/tools/bench), run alone in the PC's job queue on 2026-11-22: 3 rounds of 201 repetitions per case and arm, i7-9700, llvm-mingw clang 23.1.5 -O2 -ffp-contract=off, arms SSE2 (-march=x86-64) and AVX2 (-march=x86-64-v3, what the release builds the back end for). The arms take turns at going first; their outputs were compared at every repetition and were equal. Each cell: the median of the three rounds' medians, [lowest–highest round median], in ns per record. Change: before ÷ after (above 1: this PR faster).

Case (8,000 records), arm Before: C walk @ cffa2f46 After: this PR @ ee821a37 Change
mixed: a third binds, 3 in 4 deferred, ops in no pattern, SSE2 8.35 [8.34–9.37] 7.80 [7.79–8.34] 1.07×
mixed: a third binds, 3 in 4 deferred, ops in no pattern, AVX2 8.51 [8.45–8.99] 7.75 [7.74–7.94] 1.10×
sparse: 1 in 20 a deferred bind, SSE2 6.41 [6.27–6.44] 7.02 [6.82–7.15] 0.91×
sparse: 1 in 20 a deferred bind, AVX2 6.57 [6.50–6.60] 7.06 [6.90–7.21] 0.93×
a third binds, none with a source, SSE2 6.45 [6.42–6.49] 5.07 [5.07–5.21] 1.27×
a third binds, none with a source, AVX2 6.34 [6.32–6.37] 5.07 [5.06–5.15] 1.25×
a third deferred binds of 32 handles or 16 ranges, SSE2 9.37 [9.24–9.64] 9.86 [9.84–9.92] 0.95×
a third deferred binds of 32 handles or 16 ranges, AVX2 9.50 [9.49–9.71] 9.91 [9.90–10.1] 0.96×
every record a deferred bind, patterned, SSE2 4.34 [4.32–4.54] 4.14 [4.12–4.29] 1.05×
every record a deferred bind, patterned, AVX2 4.41 [4.37–4.64] 4.16 [4.12–4.39] 1.06×

zeldaootr's run on a Steam Deck OLED (#issuecomment-71565), a third party's run, not ours, as posted: #1947's head cffa2f46 against this PR at ee821a37 (merged into main 9dd41326), Kokiri Forest, three interleaved pairs of 180 s.

Before: #1947 @ cffa2f46 After: this PR @ ee821a37 (merged into main 9dd41326) Δ
fps (each run) 44.0 / 43.8 / 44.3 (median 44.0) 44.3 / 43.9 / 44.0 (median 44.0) -0.1%
1% low fps (1000 / p99) 35.0 33.9 -3.0%
median frame time 22.39 ms 22.32 ms -0.07 ms
p99 frame time 28.57 ms 29.47 ms +0.90 ms
frames of 50 ms or more (each run) 0 / 0 / 0 1 / 2 / 1

dev.py ab's verdict: no difference shown, within the runs' spread. The p99 (+0.90 ms) and the frames of 50 ms or more (1 / 2 / 1 against 0 / 0 / 0) lean against this pull request on his Deck; he would not read either as a change: "The p99 and the 1 % low moved by less than the runs' own p99s differ (27.2 to 30.6 ms across the six), and the long frames are 1-2 a run in three minutes". Not measured by us in play: an in-game comparison on this PC (Still to test) is to decide; it has not run yet. No FATAL, device-lost, VK_ERROR or validation line in his 6 logs.

Hardware and settings: Steam Deck OLED, SteamOS 3.9.5, RADV VANGOGH, Mesa 26.2.0-devel, GPU clock set to 1600 MHz, headless; Minimum, render 50 % (640x400), output 1280x800, uncapped, V-Sync and frame generation off; x86-64-v3 builds. Method: dev.py ab (with a local change to compare two prebuilt runtimes), Kokiri Forest, three interleaved pairs of 180 s after the warm-up, the median. Its own stated limits: Link standing where the scene puts him, not three minutes of play; no HOS_PROFILE=1 run, so resolve_deferred's share of the submitting thread was not measured; no picture judged and no screenshot (headless); in this scene the Deck's runs agree within about 1 %, so a change of a percent or two would show only as a hint.

In play (held job fb-g2099, 01:41 to 02:28 UTC on 2026-11-23): the Market, at 60 s a run. The two builds are this
head ee821a37 (rt-nvr-ee821a37) and its parent, the asm kit cffa2f46 (rt-kit-cffa2f46): a warm-up each, then kit and
head interleaved (kit head head kit, four times), every run loading at create, at the game's 2560x1440 output on a
2560x1440 desktop at 60 Hz. No run was left out, and no load marker or strike file appeared. Reach: main's own submit
line, logged every 20,000th nvnQueueSubmitCommands just before its handles go to resolve_deferred (whose first act
on x86-64 is lsasm_nvn_resolve), shows 1 handle a submit in the head's warm-up (3 lines). A run makes 60,000 to 80,000
such submits in about 12,400-12,700 presents, so the kernel runs about 5 to 6 times a frame, on one recording each. No
log line times the walk or counts a recording's deferred binds, so the play stream cannot be placed between the
micro-benchmark's mixed case (1.07-1.10×) and its sparse one (0.91-0.93×). The figure that holds the kernel's work is
the game thread's own time (calm-stretch game_ms).

a side: median (range), the measured stretch Before: the kit @ cffa2f46 (C walk), 8 runs After: this PR @ ee821a37, 8 runs change of the means p (swap test)
calm-stretch game_ms (the submitting thread) 12.56 (12.19 to 12.89) 12.49 (12.17 to 12.89) -0.1 % 0.95
main_blocked_ms 10.69 (10.18 to 10.89) 10.47 (9.93 to 11.18) -0.9 % 0.56
frames a second 69.5 (61.0 to 72.5) 69.7 (61.5 to 72.3) -0.9 % 0.79
p99 frame time, ms 23.8 (20.4 to 50.6) 25.4 (20.1 to 48.8) +7.9 % 0.73
frames of 50 ms or more, all runs 109 127 +16 % 0.71
a frame's replay time (ms): submit (render thread) 8.47 (7.16 to 9.02) 7.63 (6.99 to 8.33) -7.9 % 0.047
replay draw / descriptors 4.15 / 1.76 3.63 / 1.58 -9.9 % / -9.0 % 0.059 / 0.054
draw_ms / desc_ms (frame trace) 4.16 / 1.81 4.06 / 1.71 -6.1 % / -7.0 % 0.044 / 0.050
memory sync, ms a frame 0.61 (0.59 to 0.65) 0.63 (0.60 to 0.68) +2.2 % 0.36

This is this head against its parent: two builds, not one build's switch (this PR has none). The play profile the back
end is built with was recorded before this change, so functions this change edits can build without their profile in
the head's build (a compile with clang's profile warnings on showed that for #1994's file; not checked for this PR's).
A difference between the builds, such as the render thread's lean, can come from that as well as from chance. It is not
where the kernel runs. What is shown in play: nothing in the game thread's time, which holds the kernel's work. This
agrees with the Steam Deck run above.

Risks

What could break: a bind copied wrong would bind the wrong buffers or textures for a draw; a stop that no longer
happens would let a corrupt record through. The test runs resolve_deferred as the source has it against the original
C walk on random streams of every op (counts 0, in range, at and past the limits, negative; copies past their record;
sources outside the window; malformed records), expecting the same stream bytes and the same end or stop, and the
kernel alone against a C model of it. A revert is enough. Host files: the runtime is rebuilt; nothing changes for
players' saves, options or caches.

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.
  • mise run test passes (any failure that also fails on main is named).
  • Measured against main, or Measurements says why there is nothing to measure.
  • No game files, build output or hand-edited generated files; third_party/ untouched; nothing GPL-incompatible.

When it applies

  • Host code builds on Windows (llvm-mingw) and Linux, with UTF-8 paths.
  • AI assistance recorded with Assisted-by: / Co-Authored-By: trailers.

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.
## Summary At each submit `nvnQueueSubmitCommands` walks every submitted recording (`resolve_deferred` in `host/nvn_native.c`) to copy each deferred bind's array from the game's memory into its record. The C walk branched on each record's op being a bind, a mispredict whenever the ops came in no pattern, and copied each array through `gw` and a `memcpy` call. This adds `host/asm/nvn.S` on the asm kit: `lsasm_nvn_resolve` walks the records itself up to the first one it leaves to C (END, a malformed record, or a bind whose copy is not plain: past its record, or a source outside the guest window). On the way, each record's source word, or a zero word, is chosen by `cmov`, so a record that is no deferred bind takes no branch; a deferred bind's array is copied in place by 16-byte moves, the last one overlapping. `resolve_deferred` keeps its C loop for the records handed back: the same copies, the same stops (a corrupt record, a source outside the window). Static asserts hold the record layouts and `lsasm_nvn_walk` to what the kernel reads. The result expected: the same stream bytes, the submit's walk faster on mixed streams. No switch: the copies are the same, so a revert is enough. From 981d2d8c on `exp/x86-asm-sync`. Depends on #1947 (the asm kit, which now carries the GPU-visible ranges' sort, `lsasm_sort_ranges`): its commits show in this diff until #1947 merges. Read first: `host/asm/nvn.S` and `host/asm/nvn.h`, then `resolve_deferred` in `host/nvn_native.c`. ## Testing **Tested:** Windows 11, i7-9700, RTX 4060, the builder's llvm-mingw clang 23 (`CC`/`CXX`, `RX_CPM` set); head ee821a37 on #1947's head cffa2f46 (the asm kit, on main 9dd41326). Through the PC's job queue, each run in a hidden console, `tests/run_all.py --strict --exact --jobs 2 --timeout 1200`: the change's own checks (light job `pr-tb-AsmCut5-light`, log `t-AsmCut5-asm-nvn-resolve`): `test_asm_nvn.py` pass (1 of 1). `--changed cffa2f46` (build job `pr-tb-AsmCut5-build`, log `t-AsmCut5-chg-asm-nvn-resolve`): 23 checks, 21 pass, 2 fail, each of which fails on #1947's head @ cffa2f46 too (a worktree at cffa2f46 in the queue's jobs, log `t-AsmCut5-base-kit-changed`): `test_dev_packs.py`, `test_host_guest_writes.py`. It has run in the game on this PC once: the in-play A/B in Measurements (held job `fb-g2099`, the Market, 18 runs), with no FATAL, device lost or Vulkan error in any run. **Still to test:** - Windows 11, i7-9700, RTX 4060 (this PC): Kokiri Forest, turning the camera, uncapped (`HOS_FPS_MAX=240`), on #1947's head and on this PR, each warmed a minute, then at least three interleaved three-minute runs of each (AB AB AB), and one run of each with `HOS_PROFILE=1` (`python -I scripts/perf.py report` on its folder: `resolve_deferred`'s share of the submitting thread), expecting the same picture, no FATAL, that share lower and fps and frame times of this PR at least the base's; a difference beyond the runs' spread is a gain or a loss, one within it is no difference measured (by hand) - Linux NVIDIA and AMD, Windows AMD and Intel, Steam Deck: Kokiri Forest, play three minutes on #1947's head and on this PR, warmed and interleaved, expecting the same picture, no FATAL, and frame times within the runs' spread or better on this PR (@Beanstalk linux+nvidia, linux+amd, windows+amd, windows+intel, steamdeck: Kokiri Forest three minutes, #1947's head against this PR, warmed and interleaved, frame times and a screenshot) - Linux: `python3 -I -B tests/test_asm_nvn.py --cxx g++` and `--cxx clang++`, expecting PASS (by hand) ## Measurements **Verdict:** a small gain on mixed record streams, none or a loss elsewhere: `lsasm_nvn_resolve` is 1.07× (SSE2) and 1.10× (AVX2) the C walk's speed per record on the mixed stream, 1.25-1.27× where binds have no source and 1.05-1.06× on patterned runs of deferred binds; slower where deferred binds are sparse (0.91-0.93×) or copy full 32-handle or 16-range arrays (0.95-0.96×). A micro-benchmark on authored input. A third party's Steam Deck run is below. In play on this PC (the Market, this head against its parent, the asm kit cffa2f46, 8 runs each, below): no gain shown where the kernel runs. `resolve_deferred` runs in `nvnQueueSubmitCommands` on the game's own thread, about 5 times a frame, and that thread's calm-stretch game time is the same (-0.1 %, p = 0.95). The render thread's replay figures lean 6-10 % to this head, at p 0.04 to 0.06. They move together, at the edge with 14 figures read, and in a stage the kernel does not run in, so they are not claimed. **Baseline:** #1947's head cffa2f46 (the asm kit on main 9dd41326, which this PR depends on), not main itself: for the micro-benchmark, the C this PR replaces as cffa2f46 has it; for the third party's run below, that head's whole build. The micro-benchmark: `resolve_deferred` as cffa2f46 has it (the C walk) against the head's (with `lsasm_nvn_resolve`), both cut from `host/nvn_native.c` and compiled as C, over authored recordings of 8,000 records and a 1 MB guest window of authored bytes. A script on this PC, not in this PR (`asm_nvn_bench.py`, PrTrials' `trials/tools/bench`), run alone in the PC's job queue on 2026-11-22: 3 rounds of 201 repetitions per case and arm, i7-9700, llvm-mingw clang 23.1.5 `-O2 -ffp-contract=off`, arms SSE2 (`-march=x86-64`) and AVX2 (`-march=x86-64-v3`, what the release builds the back end for). The arms take turns at going first; their outputs were compared at every repetition and were equal. Each cell: the median of the three rounds' medians, [lowest–highest round median], in ns per record. Change: before ÷ after (above 1: this PR faster). | Case (8,000 records), arm | Before: C walk @ cffa2f46 | After: this PR @ ee821a37 | Change | |---|---|---|---| | mixed: a third binds, 3 in 4 deferred, ops in no pattern, SSE2 | 8.35 [8.34–9.37] | 7.80 [7.79–8.34] | 1.07× | | mixed: a third binds, 3 in 4 deferred, ops in no pattern, AVX2 | 8.51 [8.45–8.99] | 7.75 [7.74–7.94] | 1.10× | | sparse: 1 in 20 a deferred bind, SSE2 | 6.41 [6.27–6.44] | 7.02 [6.82–7.15] | 0.91× | | sparse: 1 in 20 a deferred bind, AVX2 | 6.57 [6.50–6.60] | 7.06 [6.90–7.21] | 0.93× | | a third binds, none with a source, SSE2 | 6.45 [6.42–6.49] | 5.07 [5.07–5.21] | 1.27× | | a third binds, none with a source, AVX2 | 6.34 [6.32–6.37] | 5.07 [5.06–5.15] | 1.25× | | a third deferred binds of 32 handles or 16 ranges, SSE2 | 9.37 [9.24–9.64] | 9.86 [9.84–9.92] | 0.95× | | a third deferred binds of 32 handles or 16 ranges, AVX2 | 9.50 [9.49–9.71] | 9.91 [9.90–10.1] | 0.96× | | every record a deferred bind, patterned, SSE2 | 4.34 [4.32–4.54] | 4.14 [4.12–4.29] | 1.05× | | every record a deferred bind, patterned, AVX2 | 4.41 [4.37–4.64] | 4.16 [4.12–4.39] | 1.06× | zeldaootr's run on a Steam Deck OLED ([#issuecomment-71565](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/2099#issuecomment-71565)), a third party's run, not ours, as posted: #1947's head cffa2f46 against this PR at ee821a37 (merged into main 9dd41326), Kokiri Forest, three interleaved pairs of 180 s. | | Before: #1947 @ cffa2f46 | After: this PR @ ee821a37 (merged into main 9dd41326) | Δ | |---|---|---|---| | fps (each run) | 44.0 / 43.8 / 44.3 (median 44.0) | 44.3 / 43.9 / 44.0 (median 44.0) | -0.1% | | 1% low fps (1000 / p99) | 35.0 | 33.9 | -3.0% | | median frame time | 22.39 ms | 22.32 ms | -0.07 ms | | p99 frame time | 28.57 ms | 29.47 ms | +0.90 ms | | frames of 50 ms or more (each run) | 0 / 0 / 0 | 1 / 2 / 1 | | `dev.py ab`'s verdict: no difference shown, within the runs' spread. The p99 (+0.90 ms) and the frames of 50 ms or more (1 / 2 / 1 against 0 / 0 / 0) lean against this pull request on his Deck; he would not read either as a change: "The p99 and the 1 % low moved by less than the runs' own p99s differ (27.2 to 30.6 ms across the six), and the long frames are 1-2 a run in three minutes". Not measured by us in play: an in-game comparison on this PC (Still to test) is to decide; it has not run yet. No `FATAL`, device-lost, `VK_ERROR` or validation line in his 6 logs. Hardware and settings: Steam Deck OLED, SteamOS 3.9.5, RADV VANGOGH, Mesa 26.2.0-devel, GPU clock set to 1600 MHz, headless; Minimum, render 50 % (640x400), output 1280x800, uncapped, V-Sync and frame generation off; x86-64-v3 builds. Method: `dev.py ab` (with a local change to compare two prebuilt runtimes), Kokiri Forest, three interleaved pairs of 180 s after the warm-up, the median. Its own stated limits: Link standing where the scene puts him, not three minutes of play; no `HOS_PROFILE=1` run, so `resolve_deferred`'s share of the submitting thread was not measured; no picture judged and no screenshot (headless); in this scene the Deck's runs agree within about 1 %, so a change of a percent or two would show only as a hint. **In play** (held job `fb-g2099`, 01:41 to 02:28 UTC on 2026-11-23): the Market, at 60 s a run. The two builds are this head ee821a37 (`rt-nvr-ee821a37`) and its parent, the asm kit cffa2f46 (`rt-kit-cffa2f46`): a warm-up each, then kit and head interleaved (kit head head kit, four times), every run loading at create, at the game's 2560x1440 output on a 2560x1440 desktop at 60 Hz. No run was left out, and no load marker or strike file appeared. Reach: main's own submit line, logged every 20,000th `nvnQueueSubmitCommands` just before its handles go to `resolve_deferred` (whose first act on x86-64 is `lsasm_nvn_resolve`), shows 1 handle a submit in the head's warm-up (3 lines). A run makes 60,000 to 80,000 such submits in about 12,400-12,700 presents, so the kernel runs about 5 to 6 times a frame, on one recording each. No log line times the walk or counts a recording's deferred binds, so the play stream cannot be placed between the micro-benchmark's mixed case (1.07-1.10×) and its sparse one (0.91-0.93×). The figure that holds the kernel's work is the game thread's own time (calm-stretch game_ms). | a side: median (range), the measured stretch | Before: the kit @ cffa2f46 (C walk), 8 runs | After: this PR @ ee821a37, 8 runs | change of the means | p (swap test) | |---|---|---|---|---| | calm-stretch game_ms (the submitting thread) | 12.56 (12.19 to 12.89) | 12.49 (12.17 to 12.89) | -0.1 % | 0.95 | | main_blocked_ms | 10.69 (10.18 to 10.89) | 10.47 (9.93 to 11.18) | -0.9 % | 0.56 | | frames a second | 69.5 (61.0 to 72.5) | 69.7 (61.5 to 72.3) | -0.9 % | 0.79 | | p99 frame time, ms | 23.8 (20.4 to 50.6) | 25.4 (20.1 to 48.8) | +7.9 % | 0.73 | | frames of 50 ms or more, all runs | 109 | 127 | +16 % | 0.71 | | `a frame's replay time (ms)`: submit (render thread) | 8.47 (7.16 to 9.02) | 7.63 (6.99 to 8.33) | -7.9 % | 0.047 | | replay draw / descriptors | 4.15 / 1.76 | 3.63 / 1.58 | -9.9 % / -9.0 % | 0.059 / 0.054 | | draw_ms / desc_ms (frame trace) | 4.16 / 1.81 | 4.06 / 1.71 | -6.1 % / -7.0 % | 0.044 / 0.050 | | memory sync, ms a frame | 0.61 (0.59 to 0.65) | 0.63 (0.60 to 0.68) | +2.2 % | 0.36 | This is this head against its parent: two builds, not one build's switch (this PR has none). The play profile the back end is built with was recorded before this change, so functions this change edits can build without their profile in the head's build (a compile with clang's profile warnings on showed that for #1994's file; not checked for this PR's). A difference between the builds, such as the render thread's lean, can come from that as well as from chance. It is not where the kernel runs. What is shown in play: nothing in the game thread's time, which holds the kernel's work. This agrees with the Steam Deck run above. ## Risks What could break: a bind copied wrong would bind the wrong buffers or textures for a draw; a stop that no longer happens would let a corrupt record through. The test runs `resolve_deferred` as the source has it against the original C walk on random streams of every op (counts 0, in range, at and past the limits, negative; copies past their record; sources outside the window; malformed records), expecting the same stream bytes and the same end or stop, and the kernel alone against a C model of it. A revert is enough. Host files: the runtime is rebuilt; nothing changes for players' saves, options or caches. ## 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. - [ ] `mise run test` passes (any failure that also fails on `main` is named). - [ ] Measured against `main`, or Measurements says why there is nothing to measure. - [x] No game files, build output or hand-edited generated files; `third_party/` untouched; nothing GPL-incompatible. ### When it applies - [ ] Host code builds on Windows (llvm-mingw) and Linux, with UTF-8 paths. - [x] AI assistance recorded with `Assisted-by:` / `Co-Authored-By:` trailers. ### 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.
The ground the hand-written kernels stand on, without any kernel yet:

- gpu/asm/lsasm.h: a kernel is written once, in Intel syntax against the System V registers; the macros make the
  Win64 convention with its SEH unwind data on Windows (an epilogue laid out as Windows' unwinder recognises one:
  the vzeroupper and the frees before the pops) and the DWARF CFI on Linux, and LSASM_ABI for the declarations.
- tests/asm_kit.py: a kernel's check builds its fixture with the kernels at SSE2 and AVX2 (where the CPU has it),
  on Windows also the System V body through sysv_abi, and assembles every kernel with clang for ELF and COFF.
- tests/test_asm_abi.py with tests/asm_abi_probe.S: probes that use every part of the frame: six arguments arrive,
  every callee-saved register comes back, a fault inside one unwinds to the caller (Windows), and every single step
  of each probe is unwound by Windows' own unwinder to its caller.
- nx2/build.py asm_jobs: every .S of host/asm goes into the game, of gpu/vk/asm into the renderer, of gpu/asm into
  both, preprocessed with the build's CPU flags and keyed by the headers beside them and lsasm.h. No folder, no job.
- scripts/devtools/packs.py takes a .S as a source (it shows in its module's objects) and nx2/version.py counts it in
  the sources' fingerprint.
- tests/test_asm_build.py, tests/test_dev_packs.py: the jobs, their keys, the fingerprint and the packs' rules.

Assisted-by: Claude Code
tests/asm_abi_probe.S has three more probes that return rsp modulo 16 in their body: scratch alone, one push and
scratch, two pushes and the xmm saves, an even and an odd count of pushes in both conventions (Win64's LSASM_ARGS
pushes two). Win64 asks a function with a frame to keep rsp 16-byte aligned in its body, and LSASM_ALLOC's scratch
at [rsp] is aligned only so. On Windows each is stepped and unwound as the others are. tests/test_asm_abi.py also
assembles a kernel with LSASM_ALLOC 3072 (it must assemble) and 4096 (a page and a push: it must stop the assembly,
as the macros probe no stack page and its first store could skip Windows' guard page).

Both fail on this commit: lsasm.h leaves rsp at 8 modulo 16 with an even count of pushes, and takes any scratch size.

Assisted-by: Claude Code
Win64 asks a function with a frame to keep rsp 16-byte aligned in its body, and the macros did not: with an even
count of pushes (LSASM_ARGS's two included) the body ran at 8 modulo 16, so an aligned store to LSASM_ALLOC's
scratch could fault. The macros now count the pushes and take 8 bytes more below them where the count leaves rsp
misaligned, before the first xmm save or scratch (or at the prologue's end), in the SEH codes and the CFI alike; the
epilogue gives them back with its one add (Windows) or at the first pop (Linux). A push after the xmm saves or the
scratch stops the assembly, as the padding could not count it.

The macros probe no stack page, so a frame of more than a page could skip Windows' guard page with its first store:
LSASM_END_PROLOGUE stops the assembly of a frame (pushes, padding, xmm saves and scratch) over 4096 bytes.

The header also says what LSASM_ARGS maps: six integer or pointer arguments; a float argument is in another register
in each convention. The fifth and sixth stay loaded on every call: their slots lie inside the caller's own frame.

Assisted-by: Claude Code
tests/test_asm_build.py checks the kernels' object keys as compile_one names them: a header renamed with its contents or
removed changes the key (a clean compile of the kernel would fail), a .inc edit changes it, and a kernel whose depfile
exists is keyed by the headers it names (an edit to another header keeps it). A gpu/asm kernel's second job publishing
the same key after the first must leave the first job's object (the cache entry is a hard link to it) as it was. A
renderer file whose depfile names a gpu/asm declaration is keyed by it, through main()'s own vdeps_roots statement.

They fail on this commit: the key joins the folders' .h contents alone, cache_put copies over an entry that
os.link found there, and the renderer's roots leave gpu/asm out.

Assisted-by: Claude Code
asm_jobs keyed a kernel's object by the .h contents of its folder and gpu/asm joined: a header renamed with its
contents kept an object a clean compile no longer makes, and a .inc edit was not seen. A kernel is now compiled with
-MD and keyed as the host's and the back end's own files are (renderer_deps, DEPFILE_JOBS, rekey_depfiles): by the
names and contents of the headers its last compile read under its folder and gpu/asm, or by every header of the two
folders (tree_headers) before it has a depfile.

A gpu/asm kernel is compiled for each module with one key, and on a cold build both jobs could publish it: the second's
os.link failed on the first's entry, and its copyfile then wrote into that entry, a hard link to the first job's object.
cache_put leaves an entry it finds (FileExistsError), and a copy across volumes goes in whole by a rename.

The back end's own objects are keyed by gpu/asm's headers too (vdeps_roots), so a Vulkan caller of a shared kernel
compiles again when the kernel's declaration changes.

Assisted-by: Claude Code
tests/test_appimage_source_headers.py runs the AppImage script's copy block and checks that every file of gpu/asm
(lsasm.h, which every kernel includes) is carried and that every kernel's includes are, for host/asm, gpu/asm and
gpu/vk/asm (gpu/vk itself is copied whole after the block). tests/test_dev_packs.py routes the three kernel folders: a
host/asm kernel is the game's alone, so its pack builds the game without the renderer (renderer_untouched), a gpu/vk/asm
kernel builds the renderer alone, a gpu/asm kernel both.

They fail on this commit: the AppImage copies host/ and gpu/vk but not gpu/asm (a player's build with a host/asm kernel
stops listing it), and renderer_untouched takes only a host/ .c for the game's alone.

Assisted-by: Claude Code
scripts/linux/appimage.sh copied host/ and gpu/vk whole but not gpu/asm: a player's build with a host/asm kernel
stopped at asm_jobs listing the missing folder, and a gpu/asm kernel was left out of both modules. The source-copy
block now carries gpu/asm whole; tests/test_appimage_headers.py takes it for a host include of a kernel's declaration.

scripts/devtools/packs.py renderer_untouched took a host/ .c alone for the game's: a pack whose change was a host/asm
kernel, which only the game links, built and linked the renderer again. A host/asm .S is the game's alone now; a
header beside it, a gpu/asm kernel and a gpu/vk/asm kernel still build the renderer.

Assisted-by: Claude Code
tests/test_asm_kit.py records the commands tests/asm_kit.py would run, with no compiler: its CPU probe must read the
whole x86-64-v3 level (leaf 7, the extended leaf's LZCNT, the OS's ymm state through xgetbv) and a probe that crashed
must fail the check rather than read as a CPU without AVX2; two kernels of one name in two folders must be two
objects, natively and in the cross assembly, each linked once; a run with no clang found must fail instead of skipping
the cross assembly, an explicit clang must be the one used, and tests/test_asm_abi.py must take CXX without --cxx.

They fail on this commit: the probe reads AVX2, BMI2 and FMA alone and counts any exit but 0 as no AVX2, the objects
are named by the source's stem, a run without clang skips the cross assembly, and --cxx defaults to g++.

Assisted-by: Claude Code
tests/asm_kit.py ran the x86-64-v3 fixture where the CPU had AVX2, BMI2 and FMA, but a VM can mask MOVBE or LZCNT,
which the compiler emits at that level, and any exit of the probe but 0 read as no AVX2, a crash too. Its probe, built
for the baseline, now reads the whole level from CPUID (leaf 1, leaf 7, the extended leaf) and the OS's ymm state
(xgetbv), and an exit other than 0 or 1 fails the check.

The objects were named by the source's stem, so gpu/asm/hash.S and gpu/vk/asm/hash.S wrote one object and linked it
twice: each source's index is in its name now, natively and in the cross assembly.

Without clang on PATH the cross assembly (clang's assembler, the build's, for ELF and COFF) was skipped without a word,
and a CPU without AVX2 was then told its AVX2 bodies had been assembled. The clang is now the one given (--clang in
tests/test_asm_abi.py), else the one beside the compiler, else the one on PATH, and without one the check fails; its
PASS line names it. tests/test_asm_abi.py takes CXX when --cxx is not given. The unused os import is gone (Ruff F401).

Assisted-by: Claude Code
tests/test_asm_abi.py left the DWARF CFI unconsumed: removing the CFA adjustment after LSASM_ALLOC kept Linux green. A
Linux probe now stops in its body, with its scratch and padding in place, and calls the fixture, which unwinds from
there with the system's unwinder (_Unwind_Backtrace): the probe's frame must return to the harness's call, with rbx,
rbp and r12-r15 as the harness set them. A probe reads a table in LSASM_RODATA RIP-relative, so that macro is
assembled (ELF and COFF) and run.

On Windows each single step's unwind is now compared with the whole nonvolatile state of the entry: rsi, rdi and
xmm6-xmm15 as well in Win64, not the six other GPRs alone. A fault in a kernel is also taken by Windows' own dispatch
to a caller's __except, built with the game's -fms-extensions as guarded_copy is (clang; a gcc build says it skipped
this), besides the vectored handler that unwinds the one frame by hand.

Assisted-by: Claude Code
tests/asm_abi_probe.S calls a kernel of one argument on a stack that ends at its 32-byte home area, all a one-argument
Win64 call owes its callee, with the page above it left unreadable (tests/test_asm_abi.py, before any handler is set):
lsasm_probe_clobber and lsasm_probe_table must return their results there.

It fails on this commit: LSASM_ARGS reads the fifth and sixth slots on every call, so the first read lands in the
unreadable page.

Assisted-by: Claude Code
On Win64 LSASM_ARGS loaded the fifth and sixth arguments from the caller's stack on every call. A call of fewer owes
its callee the 32-byte home area alone, so the slots above it can lie past the stack's top. LSASM_ARGS now takes the
kernel's count of arguments (0 to 6; another count stops the assembly) and moves or loads only those: a one-argument
kernel reads no stack slot. The header says the mapping is for integer and pointer arguments; the probes give their
counts (6 for lsasm_probe_args, 1 for the others).

Assisted-by: Claude Code
tests/test_asm_build.py looked for asm_jobs' calls in main()'s text: it passed if a guard kept a call from running or
its jobs from a link list. main() now plans through plan_modules (nx2/build.py): the game's other jobs and the
renderer's in, the kernels joined (host/asm's and gpu/asm's to the game when it compiles the runtime, gpu/vk/asm's and
gpu/asm's to the renderer when it is built), RX_VK_ONLY's renderer-only jobs, and out the jobs and the two link lists
objs.rsp and vk_objs.rsp are written from. The build is the same as before; the kernels' jobs come after the game's
other jobs instead of after the runtime's files.

The test runs it on synthetic sources (two kernels in host/asm, one in gpu/asm, one of the same name in gpu/vk/asm)
and checks the compiled jobs and both modules' link inputs in full for a full build, a game-only build (no renderer
folder, as main() passes for RX_GAME_ONLY) and a renderer-only build (RX_VK_ONLY), and that main() plans and links
through it. tests/test_link_skip.py, test_renderer_depfiles.py and test_third_party_objects.py anchor on the planner's
line now, the lines they named being gone. docs/dev/reference/build.md names it.

Assisted-by: Claude Code
Importing nx2/build.py took the machine's build settings: RX_MARCH=native, or a CPU with x86-64-v3 and no RX_MARCH,
has clang say what -march=native is while the module loads, and RX_MARCH=native with no working clang stopped the
import before unittest started, in a check that says it runs no compiler. The test now imports it with the build's own
variables (RX_*, LONGSHOT_*, OOT_*) cleared and RX_MARCH=x86-64-v3, and with subprocess.Popen and os.system failing
while it loads: a process started by the import fails it instead of running. A test checks the CPU flags are the
fixed level's.

Assisted-by: Claude Code
hos_gpu_guest_ranges (host/nvdrv.c) sorts every GPU mapping's and native NVN pool's guest range by start before it
merges them, each time the mappings change: qsort with a comparison function call per compare. On x86-64 it now sorts
with host/asm/ranges.S's lsasm_sort_ranges, a hand-written merge sort on gpu/asm/lsasm.h: runs of 16 pairs by
insertion, then merges of runs twice as long a pass between the list and a second one (kept beside merged, grown with
it); two runs already in order (the mappings come mostly in address order) are copied, not merged, and the merge picks
its side with cmov, no branch. One body for both CPU levels: the pairs move in xmm registers. Other CPUs keep qsort
with cmp_range, under #if defined(__x86_64__). Both lists grow through hos_xrealloc (an allocation refused for 5 s
ends the run with the out-of-memory notice), where realloc's NULL was used as the list before.

It is stable where qsort is not: ranges that start together come out of qsort in any order, and the merge after the
sort makes the same ranges from any such order (one starts the merged range, the others only reach to their ends), so
the result is the same. No switch: the ranges merged are the same.

From 971f8074 on exp/x86-asm-sync, where the sort was collect.S's second kernel; here it is its own file. A
micro-benchmark there (i7-9700) found the kernel faster than qsort, more so in near order; not measured on this commit,
nor in play.

Test: tests/test_asm_ranges.py, through tests/asm_kit.py at SSE2 and AVX2, both conventions, clang ELF/COFF assembly:
the kernel against qsort with cmp_range (cut from the source) for 22 sizes around its runs and merges up to 10000 pairs
and 8 key patterns, between faulting pages: same order, stable, and hos_gpu_guest_ranges' merge makes the same ranges
from either order. The whole hos_gpu_guest_ranges, cut from the source, is compiled with its x86-64 test taken both
ways: the two give the same ranges for every case, one sorting with the kernel and the other with qsort, once a call.
scripts/profiling/cpu_functions.json describes lsasm_sort_ranges, and cmp_range as the other CPUs' comparison.

Assisted-by: Claude Code
The review asked for one shared kernel and one private kernel per module through a cold build, a cached rebuild after
an included file's rename, developer packs and the Linux AppImage's staging. tests/test_asm_end_to_end.py authors them
in a tree of its own (gpu/asm/e2e.S, host/asm/game.S, gpu/vk/asm/vk.S, each with an include, on the real lsasm.h) and
runs the build's own code on them with clang: plan_modules, plan_jobs with the hash record a build loads and saves,
compile_one on four threads (the shared kernel's two jobs at once), rekey_depfiles and main()'s own statements that
write the link lists. Each module's link list is linked with a caller and run, where this CPU runs x86-64-v3.

- a cold build compiles every kernel; a second build compiles nothing, nor does a new work folder made from its
  object cache (packs.link_objects), whose modules are the first's (module_changed);
- an include renamed while its kernel still names it compiles that kernel again and fails, as a clean build would; with
  the kernel naming the new file it compiles again, alone of the kernels;
- an include's edit compiles the kernels that read it, and its revert compiles nothing and links the cold build's
  objects, unchanged;
- packs one after another on one base (route, link_inputs_changed, renderer_untouched, link_objects, module_changed as
  cmd_pack runs them): a game kernel builds the game alone, a renderer kernel the renderer alone, a shared one both;
  each compiles the kernels that changed, and the base's objects and cache stay as they were;
- the AppImage's source-copy block, run with bash on the tree, carries the kernels and their includes, and a cold
  build of the staged tree compiles and links them.

nx2/build.py is imported as tests/test_asm_build.py imports it. The compiler is --cxx (CXX, else g++), clang beside it
(tests/asm_kit.py find_clang). The staging check needs bash: Git for Windows' on Windows, else it is skipped.

Assisted-by: Claude Code
compile_one hard-links each object into the object cache (cache_put), and links an object from the cache the same way;
a pack's work folder links the base's cache too (scripts/devtools/packs.py link_objects). clang's assembler, which
compiles the hand-written kernels (asm_jobs), writes its output in place (cc1as opens the -o path itself; clang's C and
C++ compiles write a temporary file and rename it over the object). A kernel compiled again therefore wrote through the
link: the cache's entry under the old key became the new object, and in a pack's work folder the base's cache entry and
its object did too. A build back at the old key (an edit reverted, a pack on that base) linked the edited kernel without
a word. compile_one now removes the object before it starts the compiler, so the compiler writes a new file and the
entries linked to the old one keep it. Every compile goes through it; for the C and C++ ones nothing changes, as their
compiler replaced the file anyway.

Test: tests/test_asm_end_to_end.py, which failed at the test commit: an include's edit and its revert linked the edited
kernel (the cache's entry under the cold build's key was the edited object), and a shared kernel's pack on a base wrote
into the base's objects and cache.

Assisted-by: Claude Code
The review: compile_one removes the old object but leaves its stamp (<object>.sha1) while clang's assembler writes the
new object in place. A build whose process tree is terminated during that write leaves part of an object under the old
stamp; once the edit is reverted the stamp matches the key again, and the first check (the object and its stamp) takes
the partial object before the object cache's valid entry is looked at.

tests/test_asm_end_to_end.py builds the kernels cold, edits the game kernel's include, and runs the next build with a
stand-in assembler for that kernel: a process that writes the first 64 bytes of the object at its own path and is
killed, and the build stops there (as its process tree terminated). The include is then reverted: the next build must
compile nothing and link the cold build's objects, unchanged, and the game's caller must give the cold build's values.

Assisted-by: Claude Code
The review: compile_one removed the object before it started the compiler but left its stamp (<object>.sha1). clang's
assembler, which compiles the hand-written kernels, writes its object in place, so a build whose process tree ended
during that write left part of an object under the old stamp. Once the edit was reverted the stamp matched the key
again, and the first check (the object and a stamp of its key) took the partial object before it looked in the object
cache, where the valid one is.

compile_one now removes the stamp as soon as it does not match: the object is replaced after that (linked from the
cache, or compiled), and only a finished one is stamped again. Without a stamp the next build links the cache's entry
or compiles again. The same holds for a link from the cache that stops before its stamp is written.

Test: tests/test_asm_end_to_end.py, test_a_stopped_replacement_and_its_revert, which failed at the test commit (the
revert linked the 64 bytes the stopped assembler had written).

Assisted-by: Claude Code
The review: main() sorts each compile's seconds into "renderer" or "host and game" by vk_job_objects, built from the
renderer's jobs before plan_modules joined the kernels to them (a new list), so a gpu/vk/asm or gpu/asm kernel of the
renderer was counted as host and game time.

tests/test_asm_build.py runs main()'s own statement (found in its syntax tree) on a plan of synthetic kernels: every
object the renderer links, its kernels included, is renderer time.

Assisted-by: Claude Code
vk_job_objects, by which main() counts each compile's seconds as renderer or host and game time, is now the set of the
renderer's link inputs plan_modules gives (vk_objs), its kernels included. It was built from the renderer's jobs before
the plan joined the kernels to them, so a renderer kernel was counted as host and game time.

Test: tests/test_asm_build.py, test_the_compile_time_breakdown_counts_the_renderer_kernels, which failed at the test
commit (vk_vk_draw.o alone was renderer time).

Assisted-by: Claude Code
The review: hos_gpu_guest_ranges grows the kernel's scratch list (one pair per range) through hos_xrealloc while it
holds the mapping lock. At the commit limit hos_xrealloc tries again for up to 5 s before the out-of-memory stop, and
every mapping change and lookup waits on the lock for as long.

tests/test_asm_ranges.py's fixture now holds a flag for the lock (LOCK, UNLOCK) and can refuse the scratch list: its
hos_xrealloc fails the check when asked for the sort's list while it is refused (the 5 s of tries), and the plain
realloc returns NULL. A call whose ranges outgrow every list the other cases grew, with the scratch refused, must sort
with qsort in place, not with the kernel, and leave the lock; the next call, with the scratch allowed, sorts with the
kernel, and both give the same ranges.

Assisted-by: Claude Code
fix(asm): a refused scratch list for the ranges' sort is not waited for with the mapping lock held
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 5s
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
Website / Website on Cloudflare (pull_request) Has been cancelled
cffa2f46ba
hos_gpu_guest_ranges grew lsasm_sort_ranges' scratch list (one pair per range) through hos_xrealloc with the mapping
lock held: refused at the commit limit, hos_xrealloc tries again for up to 5 s before the out-of-memory stop, and every
mapping change and lookup waited on the lock as long. The list is only the sort's; the ranges can be sorted without it.

It now grows through plain realloc, with a capacity of its own. When it is refused the call sorts with qsort and
cmp_range in place (as other CPUs do), and the next change of the mappings asks for it again. The merged list still
grows through hos_xrealloc: the call cannot go on without it (on main its realloc's NULL was used as the list).

Test: tests/test_asm_ranges.py, which failed at the test commit (the refused scratch went through hos_xrealloc's tries
with the lock held).

Assisted-by: Claude Code
perf(host): the submit walk's deferred binds resolved by an x86-64 kernel (lsasm_nvn_resolve)
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
Website / Website on Cloudflare (pull_request) Blocked by required conditions
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 4s
ee821a37a3
nvnQueueSubmitCommands walks every submitted recording (resolve_deferred, host/nvn_native.c) to copy each deferred
bind's array from the game's memory into its record. host/asm/nvn.S's lsasm_nvn_resolve, a hand-written x86-64 kernel
on gpu/asm/lsasm.h, now walks the records itself up to the first one it leaves to C: END, a malformed record, or a bind
whose copy is not plain (past its record, or a source outside the guest window). On the way, each record's word at +24
(a bind's source) or a zero word is chosen by cmov, so a record that is no deferred bind takes no branch; a deferred
bind's array is copied in place by 16-byte moves, the last one overlapping. The C walk branched on each record's op
being a bind, a mispredict whenever the ops came in no pattern, and copied each array through gw and a memcpy call.

resolve_deferred keeps its C loop for the records handed back: the same copies, the same die paths (corrupt record,
gw outside the window). Static asserts hold the record layouts and lsasm_nvn_walk to what the kernel reads. No switch:
the copies are the same. Only resolve_deferred and the include change in nvn_native.c.

Not measured on this port: the branch's micro-benchmark timed the branch's code (there the kernel lost only with most
binds deferred in patterned streams). Not measured in play. (Left in C on the branch, where its micro-benchmarks showed
no win: obj_lookup's probe, the object cache, check_handle, the op stream's memcpys.)

Test: tests/test_asm_nvn.py (the branch's, cutting the source with tests/srccut.py, through tests/asm_kit.py at SSE2
and AVX2, both conventions, clang ELF/COFF assembly): resolve_deferred as the source has it against the original C
walk on random streams of every op (deferred binds with and without a source, counts 0, in range, at and past the
limits, negative; copies past their record; sources outside the window; malformed records): the same stream bytes and
the same end or die message; and the kernel alone against a C model of it from every record, windows ending inside a
source too.

Assisted-by: Claude Code
Member

Possibly related, for context:

  • PR #2018 WIP: fix(nvn): the array binds check the count and the whole guest array before reading it — Open deferred-bind change in same NVN host code
Possibly related, for context: - PR #2018 WIP: fix(nvn): the array binds check the count and the whole guest array before reading it — Open deferred-bind change in same NVN host code
Author
Contributor

@Beanstalk This resolves NVN submits' deferred binds with a hand-written x86-64 kernel in the submit walk (host), in every scene. It sits on #1947 (cffa2f46, the asm kit), so its diff against its merge base includes that PR's commits; the farm cannot take it as the comparison, so please compare with main. No switch: a revert gives back main's code. Please start from the kokiri-start save and take the picture right after it loads and settles, before any input, with a main-against-itself picture on the same PC at that point; then, for frame times only, play Kokiri Forest and Hyrule Field, two minutes each; at least two starts a side, interleaved, the PR against main on the same PC, on Windows with a Ryzen 9 7900X, Windows with a Core i9-12900K, Linux with a Ryzen 5 5600X and the Steam Deck. The same picture as main within main's own difference from itself; frame time p99 equal to main's or better, within the run-to-run spread. The log must have no FATAL line and no corrupt-record stop.

@Beanstalk This resolves NVN submits' deferred binds with a hand-written x86-64 kernel in the submit walk (host), in every scene. It sits on #1947 (cffa2f46, the asm kit), so its diff against its merge base includes that PR's commits; the farm cannot take it as the comparison, so please compare with main. No switch: a revert gives back main's code. Please start from the kokiri-start save and take the picture right after it loads and settles, before any input, with a main-against-itself picture on the same PC at that point; then, for frame times only, play Kokiri Forest and Hyrule Field, two minutes each; at least two starts a side, interleaved, the PR against main on the same PC, on Windows with a Ryzen 9 7900X, Windows with a Core i9-12900K, Linux with a Ryzen 5 5600X and the Steam Deck. The same picture as main within main's own difference from itself; frame time p99 equal to main's or better, within the run-to-run spread. The log must have no FATAL line and no corrupt-record stop.
Member

@siantm only members of BigBeans can start the farm. One of them can approve this request by reacting 👍 to it or to this comment.

@siantm only members of `BigBeans` can start the farm. One of them can approve this request by reacting 👍 to it or to this comment.
Author
Contributor

Measurements: the micro-benchmark (trials script, run alone on this PC 2026-11-22, 3 rounds, SSE2 and AVX2): figures and Verdict

Measurements: the micro-benchmark (trials script, run alone on this PC 2026-11-22, 3 rounds, SSE2 and AVX2): figures and Verdict
Author
Contributor

@Beanstalk One correction to my request 69727 above, for its picture point: please take each picture 5 s (300 frames at 60 fps) after the first frame whose picture is not a single uniform colour, with no input in between, and take the main-against-itself picture from the same point. A picture taken during the load's fade-in from black is not comparable: run 70269 on #2156 caught the fade in 3 of 4 starts.

@Beanstalk One correction to my request 69727 above, for its picture point: please take each picture 5 s (300 frames at 60 fps) after the first frame whose picture is not a single uniform colour, with no input in between, and take the main-against-itself picture from the same point. A picture taken during the load's fade-in from black is not comparable: run 70269 on #2156 caught the fade in 3 of 4 starts.
Member

@siantm only members of BigBeans can start the farm. One of them can approve this request by reacting 👍 to it or to this comment.

@siantm only members of `BigBeans` can start the farm. One of them can approve this request by reacting 👍 to it or to this comment.
Contributor

Steam Deck result: I ran this PR against #1947's head, as the PR asks, on a Steam Deck OLED standing in Kokiri Forest, three pairs of three minutes. It showed no difference the Deck can resolve (-0.1 % on the median, the runs overlapping), and no errors in any log.

Before: #1947 @ cffa2f46 After: this PR @ ee821a37 Δ
fps (each run) 44.0 / 43.8 / 44.3 (median 44.0) 44.3 / 43.9 / 44.0 (median 44.0) -0.1%
1% low fps (1000 / p99) 35.0 33.9 -3.0%
median frame time 22.39 ms 22.32 ms -0.07 ms
p99 frame time 28.57 ms 29.47 ms +0.90 ms
frames of 50 ms or more (each run) 0 / 0 / 0 1 / 2 / 1

dev.py ab's verdict: no difference shown: -0.1% fps (median 44.0 against 44.0), within the runs' spread (A 43.8 to 44.3, B 43.9 to 44.3). (The tool's column header says "main @ cffa2f46" because its labels are main and the PR; side A is #1947's head, longshot v3.0.0-166-gcffa2f46b in its logs, side B this PR's, v3.0.0-168-gead923dd5.) Run order A1 B1 A2 B2 A3 B3. The p99 and the 1 % low moved by less than the runs' own p99s differ (27.2 to 30.6 ms across the six), and the long frames are 1-2 a run in three minutes, so I wouldn't read either as a change.

No FATAL, device-lost, VK_ERROR or validation line in the 6 logs; every run exited normally. Every log reads vk: Threaded rendering: Auto: off.

The PR's own check, on Linux (the PC that built it), on main 9dd41326 with this PR merged: tests/test_asm_nvn.py passes (run once, with the build's default compiler; I didn't run it with both --cxx g++ and --cxx clang++).

Hardware: Steam Deck OLED, SteamOS 3.9.5, RADV VANGOGH, Mesa 26.2.0-devel, GPU clock manual 1600 MHz, headless.
Settings: Minimum, Render 50 % (640x400), output 1280x800, uncapped, V-Sync and frame generation off.
Game data: complete (the dump, with the three damaged textures replaced).
Built: #1947's head cffa2f46 (23 commits on main 9dd41326) and main 9dd41326 with this PR's head ee821a37 merged in (1947's 23 commits plus this PR's one, no conflicts), x86-64-v3 (the kernel's code has no AVX-512 instruction), shaders prepared on the Deck; both builds' host and renderer differ from main's.
Measured: dev.py ab, Kokiri Forest, 3 interleaved pairs of 180 s after the warm-up (until no frame waits for a pipeline, at least 10 s), the median (the project's tool, with a local change to compare two prebuilt runtimes, since the Deck does not build).

Limits: dev.py ab stands Link still where the scene puts him, so this is not three minutes of play; no HOS_PROFILE=1 run, so resolve_deferred's share of the submitting thread wasn't measured; the picture can't be judged headless, and there's no screenshot. In this standing scene the Deck's runs agree within about 1 %, so a change of a percent or two would show only as a hint.

Steam Deck result: I ran this PR against https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/1947's head, as the PR asks, on a Steam Deck OLED standing in Kokiri Forest, three pairs of three minutes. It showed no difference the Deck can resolve (-0.1 % on the median, the runs overlapping), and no errors in any log. | | Before: https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/1947 @ cffa2f46 | After: this PR @ ee821a37 | Δ | |---|---|---|---| | fps (each run) | 44.0 / 43.8 / 44.3 (median 44.0) | 44.3 / 43.9 / 44.0 (median 44.0) | -0.1% | | 1% low fps (1000 / p99) | 35.0 | 33.9 | -3.0% | | median frame time | 22.39 ms | 22.32 ms | -0.07 ms | | p99 frame time | 28.57 ms | 29.47 ms | +0.90 ms | | frames of 50 ms or more (each run) | 0 / 0 / 0 | 1 / 2 / 1 | | `dev.py ab`'s verdict: **no difference shown: -0.1% fps (median 44.0 against 44.0), within the runs' spread (A 43.8 to 44.3, B 43.9 to 44.3).** (The tool's column header says "main @ cffa2f46" because its labels are main and the PR; side A is https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/1947's head, `longshot v3.0.0-166-gcffa2f46b` in its logs, side B this PR's, `v3.0.0-168-gead923dd5`.) Run order A1 B1 A2 B2 A3 B3. The p99 and the 1 % low moved by less than the runs' own p99s differ (27.2 to 30.6 ms across the six), and the long frames are 1-2 a run in three minutes, so I wouldn't read either as a change. No `FATAL`, device-lost, `VK_ERROR` or validation line in the 6 logs; every run exited normally. Every log reads `vk: Threaded rendering: Auto: off`. The PR's own check, on Linux (the PC that built it), on main 9dd41326 with this PR merged: `tests/test_asm_nvn.py` passes (run once, with the build's default compiler; I didn't run it with both `--cxx g++` and `--cxx clang++`). Hardware: Steam Deck OLED, SteamOS 3.9.5, RADV VANGOGH, Mesa 26.2.0-devel, GPU clock manual 1600 MHz, headless. Settings: Minimum, Render 50 % (640x400), output 1280x800, uncapped, V-Sync and frame generation off. Game data: complete (the dump, with the three damaged textures replaced). Built: https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/1947's head cffa2f46 (23 commits on main 9dd41326) and main 9dd41326 with this PR's head ee821a37 merged in (1947's 23 commits plus this PR's one, no conflicts), x86-64-v3 (the kernel's code has no AVX-512 instruction), shaders prepared on the Deck; both builds' host and renderer differ from main's. Measured: `dev.py ab`, Kokiri Forest, 3 interleaved pairs of 180 s after the warm-up (until no frame waits for a pipeline, at least 10 s), the median (the project's tool, with a local change to compare two prebuilt runtimes, since the Deck does not build). Limits: `dev.py ab` stands Link still where the scene puts him, so this is not three minutes of play; no `HOS_PROFILE=1` run, so `resolve_deferred`'s share of the submitting thread wasn't measured; the picture can't be judged headless, and there's no screenshot. In this standing scene the Deck's runs agree within about 1 %, so a change of a percent or two would show only as a hint.
Author
Contributor

@zeldaootr thank you for running it against #1947's head, as the pull request asks. Your fps shows no difference (-0.1 %), but your p99 (29.47 against 28.57 ms) and frames of 50 ms or more (1 / 2 / 1 against 0 / 0 / 0) lean against this pull request on the Deck; you would not read them as a change, since the p99 moved less than the six runs' own p99s differ (27.2 to 30.6 ms), and an in-game comparison on our PC, which has not run yet, is to decide. Your run is now in Measurements as yours, with its limits (Link standing, no HOS_PROFILE=1 run, so resolve_deferred's share was not measured, no picture).

@zeldaootr thank you for running it against #1947's head, as the pull request asks. Your fps shows no difference (-0.1 %), but your p99 (29.47 against 28.57 ms) and frames of 50 ms or more (1 / 2 / 1 against 0 / 0 / 0) lean against this pull request on the Deck; you would not read them as a change, since the p99 moved less than the six runs' own p99s differ (27.2 to 30.6 ms), and an in-game comparison on our PC, which has not run yet, is to decide. Your run is now in Measurements as yours, with its limits (Link standing, no `HOS_PROFILE=1` run, so `resolve_deferred`'s share was not measured, no picture).
Author
Contributor

@Beanstalk This replaces my request 69727 on this head and the corrections under it, in a form the farm can run: it cannot time a picture from the first frame that is not a uniform colour (its answer on #2131), so each picture here follows a fixed wait after the map event. This resolves NVN submits' deferred binds with a hand-written x86-64 kernel in the submit walk (host), in every scene. It sits on #1947 (cffa2f46, the asm kit), so its diff against its merge base includes that PR's commits; the farm cannot take it as the comparison, so please compare with main. No switch: a revert gives back main's code. Please start from the kokiri-start save and take the picture 10 s (600 frames at 60 fps) after the map event that ends the load, a fixed wait with no input in between (the farm cannot time it from the first frame that is not a uniform colour), with a main-against-itself picture on the same PC from the same point; then, for frame times only, play Kokiri Forest and Hyrule Field, two minutes each; at least two starts a side, interleaved, the PR against main on the same PC, on Windows with a Ryzen 9 7900X, Windows with a Core i9-12900K, Linux with a Ryzen 5 5600X and the Steam Deck. The same picture as main within main's own difference from itself; frame time p99 equal to main's or better, within the run-to-run spread. The log must have no FATAL line and no corrupt-record stop.

@Beanstalk This replaces my request 69727 on this head and the corrections under it, in a form the farm can run: it cannot time a picture from the first frame that is not a uniform colour (its answer on #2131), so each picture here follows a fixed wait after the map event. This resolves NVN submits' deferred binds with a hand-written x86-64 kernel in the submit walk (host), in every scene. It sits on #1947 (cffa2f46, the asm kit), so its diff against its merge base includes that PR's commits; the farm cannot take it as the comparison, so please compare with main. No switch: a revert gives back main's code. Please start from the kokiri-start save and take the picture 10 s (600 frames at 60 fps) after the map event that ends the load, a fixed wait with no input in between (the farm cannot time it from the first frame that is not a uniform colour), with a main-against-itself picture on the same PC from the same point; then, for frame times only, play Kokiri Forest and Hyrule Field, two minutes each; at least two starts a side, interleaved, the PR against main on the same PC, on Windows with a Ryzen 9 7900X, Windows with a Core i9-12900K, Linux with a Ryzen 5 5600X and the Steam Deck. The same picture as main within main's own difference from itself; frame time p99 equal to main's or better, within the run-to-run spread. The log must have no FATAL line and no corrupt-record stop.
Member

@siantm only members of BigBeans can start the farm. One of them can approve this request by reacting 👍 to it or to this comment.

@siantm only members of `BigBeans` can start the farm. One of them can approve this request by reacting 👍 to it or to this comment.
Author
Contributor

@zeldaootr the in-game comparison on our PC that I said would decide has now run (held job fb-g2099, Measurements). It compared this head ee821a37 with #1947's head cffa2f46 in the Market at a 2560x1440 output: 8 runs each, interleaved, every run loading its programs at create.

  • resolve_deferred runs on the game's own thread, about 5 to 6 times a frame (one recording a submit). That thread's calm game time did not move: 12.56 against 12.49 ms, -0.1 %, p = 0.95 in a test that swaps runs between the sides. The frame rate (p 0.79), p99 (p 0.73) and the frames of 50 ms or more (109 against 127, p 0.71) do not differ either.
  • The render thread's replay figures lean 6-10 % towards this head (p 0.04 to 0.06). The kernel doesn't run there, and two builds differ in more than the kernel, so I don't read that as this change.

So, as on your Deck, no difference is shown in play. Thanks again for your run; it is in Measurements beside this one.

@zeldaootr the in-game comparison on our PC that I said would decide has now run (held job `fb-g2099`, Measurements). It compared this head ee821a37 with #1947's head cffa2f46 in the Market at a 2560x1440 output: 8 runs each, interleaved, every run loading its programs at create. - `resolve_deferred` runs on the game's own thread, about 5 to 6 times a frame (one recording a submit). That thread's calm game time did not move: 12.56 against 12.49 ms, -0.1 %, p = 0.95 in a test that swaps runs between the sides. The frame rate (p 0.79), p99 (p 0.73) and the frames of 50 ms or more (109 against 127, p 0.71) do not differ either. - The render thread's replay figures lean 6-10 % towards this head (p 0.04 to 0.06). The kernel doesn't run there, and two builds differ in more than the kernel, so I don't read that as this change. So, as on your Deck, no difference is shown in play. Thanks again for your run; it is in Measurements beside this one.
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
Website / Website on Cloudflare (pull_request) Blocked by required conditions
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 4s
This pull request has changes conflicting with the target branch.
  • nx2/build.py
Some workflows are waiting to be reviewed.
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u 'perf/asm-nvn-resolve:siantm-perf/asm-nvn-resolve'
git switch 'siantm-perf/asm-nvn-resolve'
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!2099
No description provided.