WIP: perf(host): the submit walk's deferred binds resolved by an x86-64 kernel (lsasm_nvn_resolve) #2099
No reviewers
Labels
No labels
area/accessibility
area/audio
area/input
area/install
area/menu
area/renderer
area/saves
area/tooling
area/upscaling
beanstalk: approved
beanstalk: failed
beanstalk: needs approval
beanstalk: running
beanstalk: tested
ci: approved
good first issue
gpu/amd
gpu/igpu
gpu/intel
gpu/nvidia
help wanted
kind
bug
kind
chore
kind
docs
kind
feature
kind
performance
kind
question
needs measurements
platform/linux
platform/macos
platform/steam-deck
platform/windows
preview
priority
critical
priority
high
priority
low
regression
risk
high
risk
low
risk
medium
status
blocked
status
confirmed
status
duplicate
status
invalid
status
needs-info
status
wontfix
ci: approved
No milestone
No project
No assignees
4 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
MagicBeanDev/Longshot!2099
Loading…
Reference in a new issue
No description provided.
Delete branch "siantm/Longshot:perf/asm-nvn-resolve"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
At each submit
nvnQueueSubmitCommandswalks every submitted recording (resolve_deferredinhost/nvn_native.c) tocopy 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
gwand amemcpycall.This adds
host/asm/nvn.Son the asm kit:lsasm_nvn_resolvewalks the records itself up to the first one it leavesto 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 deferredbind takes no branch; a deferred bind's array is copied in place by 16-byte moves, the last one overlapping.
resolve_deferredkeeps its C loop for the records handed back: the same copies, the same stops (a corrupt record, asource outside the window). Static asserts hold the record layouts and
lsasm_nvn_walkto what the kernel reads. Theresult 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.Sandhost/asm/nvn.h, thenresolve_deferredinhost/nvn_native.c.Testing
Tested: Windows 11, i7-9700, RTX 4060, the builder's llvm-mingw clang 23 (
CC/CXX,RX_CPMset); headee821a37on #1947's head
cffa2f46(the asm kit, on main9dd41326). 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 jobpr-tb-AsmCut5-light,log
t-AsmCut5-asm-nvn-resolve):test_asm_nvn.pypass (1 of 1).--changed cffa2f46(build jobpr-tb-AsmCut5-build, logt-AsmCut5-chg-asm-nvn-resolve): 23 checks, 21 pass, 2 fail, each of which fails on #1947'shead @
cffa2f46too (a worktree atcffa2f46in the queue's jobs, logt-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), withno FATAL, device lost or Vulkan error in any run.
Still to test:
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 reporton its folder:resolve_deferred's share of the submitting thread), expecting the same picture, no FATAL, that share lower and fpsand 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)
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)
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_resolveis 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 shownwhere the kernel runs.
resolve_deferredruns innvnQueueSubmitCommandson the game's own thread, about 5 times aframe, 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 main9dd41326, which this PR depends on), not main itself: for the micro-benchmark, the C this PR replaces ascffa2f46has it; for the third party's run below, that head's whole build.The micro-benchmark:
resolve_deferredascffa2f46has it (the C walk) against the head's (withlsasm_nvn_resolve), both cut fromhost/nvn_native.cand 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).cffa2f46ee821a37zeldaootr's run on a Steam Deck OLED (#issuecomment-71565), a third party's run, not ours, as posted: #1947's head
cffa2f46against this PR atee821a37(merged into main9dd41326), Kokiri Forest, three interleaved pairs of 180 s.cffa2f46ee821a37(merged into main9dd41326)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. NoFATAL, device-lost,VK_ERRORor 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; noHOS_PROFILE=1run, soresolve_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 thishead
ee821a37(rt-nvr-ee821a37) and its parent, the asm kitcffa2f46(rt-kit-cffa2f46): a warm-up each, then kit andhead 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
nvnQueueSubmitCommandsjust before its handles go toresolve_deferred(whose first acton 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,000such 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).
cffa2f46(C walk), 8 runsee821a37, 8 runsa frame's replay time (ms): submit (render thread)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_deferredas the source has it against the originalC 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
main; the title is a Conventional Commit.mise run testpasses (any failure that also fails onmainis named).main, or Measurements says why there is nothing to measure.third_party/untouched; nothing GPL-incompatible.When it applies
Assisted-by:/Co-Authored-By:trailers.Ready to merge
main, measured again or a comment says why the numbers still hold.Possibly related, for context:
@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.@siantm only members of
BigBeanscan start the farm. One of them can approve this request by reacting 👍 to it or to this comment.Measurements: the micro-benchmark (trials script, run alone on this PC 2026-11-22, 3 rounds, SSE2 and AVX2): figures and Verdict
@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.
@siantm only members of
BigBeanscan start the farm. One of them can approve this request by reacting 👍 to it or to this comment.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.
cffa2f46ee821a37dev.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-gcffa2f46bin 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_ERRORor validation line in the 6 logs; every run exited normally. Every log readsvk: Threaded rendering: Auto: off.The PR's own check, on Linux (the PC that built it), on main
9dd41326with this PR merged:tests/test_asm_nvn.pypasses (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 main9dd41326) and main9dd41326with this PR's headee821a37merged 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 abstands Link still where the scene puts him, so this is not three minutes of play; noHOS_PROFILE=1run, soresolve_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.@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=1run, soresolve_deferred's share was not measured, no picture).@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.@siantm only members of
BigBeanscan start the farm. One of them can approve this request by reacting 👍 to it or to this comment.@zeldaootr the in-game comparison on our PC that I said would decide has now run (held job
fb-g2099, Measurements). It compared this headee821a37with #1947's headcffa2f46in the Market at a 2560x1440 output: 8 runs each, interleaved, every run loading its programs at create.resolve_deferredruns 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.So, as on your Deck, no difference is shown in play. Thanks again for your run; it is in Measurements beside this one.
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.