WIP: perf(vk): the small pools' capture ranges rebuilt in one x86-64 assembly pass #2135
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
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
MagicBeanDev/Longshot!2135
Loading…
Reference in a new issue
No description provided.
Delete branch "siantm/Longshot:perf/asm-pool-ranges"
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
Before each capture the renderer rebuilds the list of the host's small pools to capture
(
refresh_pool_ranges_lockedingpu/vk/vk_memory.cpp): it copied the pools, sorted them withstd::sortand mergedthe ones that overlap or touch.
This adds
gpu/vk/asm/memory.Son the asm kit:lsasm_pool_rangeskeeps the pools of 1 toRX_VK_CAPTURE_POOL_MBbytes below 1 TB, rounds them to whole pages and merges those that overlap or touch, in one branch-free pass over the
list in address order (
hos_gpu_poolsgives its mappings that way); it answers -1 when a pool starts below the openrange or an end wraps.
refresh_pool_ranges_lockedtakes that pass (pool_ranges: the kernel on x86-64, the same loopin C elsewhere) without
RX_VK_CAPTURE_EAGER, in place of the copy, sort and merge; with it, or for a list the passrefuses, the path below runs as before. The version moves only when the ranges did, as before. Main's own part: #1553
already keeps no map of the pools' ages without
RX_VK_CAPTURE_EAGER. The result expected: the same ranges, therefresh faster.
No switch: the same ranges either way.
From 12168bb8 on
exp/x86-asm-sync(only its pass; the retired pools' list there is another change). 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:
gpu/vk/asm/memory.S, thenpool_rangesandrefresh_pool_ranges_lockedingpu/vk/vk_memory.cpp.Testing
Tested: Windows 11, i7-9700, RTX 4060, the builder's llvm-mingw clang 23 (
CC/CXX,RX_CPMset); head8df7cd73on #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-pool-ranges):test_asm_memory.py,test_capture_pool_refresh.pypass (2 of 2).--changed cffa2f46(build jobpr-tb-AsmCut5-build, logt-AsmCut5-chg-asm-pool-ranges): 78 checks, 70 pass, 8 fail, each ofwhich fails on #1947's head @
cffa2f46too (a worktree atcffa2f46in the queue's jobs, logst-AsmCut5-base-kit-changedandt-AsmCut5-base-kit-more):test_capture_read_once.py,test_frame_overlap.py,test_guest_imported.py,test_linux_pressure.py,test_pending_guest_import.py,test_replay_write_order.py,test_sparse_mirror.py,test_texel_buffer_ownership.py.It has run in the game on this PC once: the in-play A/B in Measurements (held job
fb-g2135, the Market, 19 runs), withno FATAL, device lost or Vulkan error in any run.
Still to test:
uncapped (
HOS_FPS_MAX=240), on #1947's head and on this PR, each warmed a minute, then at least three interleavedthree-minute runs of each (AB AB AB), and one run of each with
HOS_PROFILE=1(python -I scripts/perf.py reporton its folder: the share of
refresh_pool_ranges_lockedon its threads), expecting the same picture, no FATAL, thatshare 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)
this PR, warmed and interleaved, expecting the same picture 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_memory.py --cxx g++and--cxx clang++, expecting PASS (by hand)Measurements
Verdict: a gain: a rebuild of the ranges takes 3.2-3.3× less time over 1,465 pools listed by address, 4.3-4.5×
when eight lists alternate with other work between refreshes, 4.7× over 200 pools and 7.0-7.1× over 6,000. Slower,
0.81-0.84×, when the list is not by address: the pass refuses it and the sort runs after it (hos_gpu_pools lists its
mappings by address). The pass in C (other CPUs) is 2.1-5.6× faster than the sort, and behind the kernel where the
lists alternate and over 6,000 pools. A micro-benchmark on authored input.
In play (the Market, this head against its parent, the asm kit
cffa2f46, below): the rebuild's own stage is faster inthe loads, -26 % (p = 0.002 in a test that swaps runs between the sides). In steady play it is not shown; the saving
there is about 4 µs a frame. Nothing is shown in frame time.
Baseline: the C this PR replaces, as #1947's head
cffa2f46has it (the asm kit on main9dd41326, which this PR depends on), not main itself.The micro-benchmark:
refresh_pool_ranges_lockedascffa2f46has it (copy, sort, merge) against this PR's (the pass,lsasm_pool_ranges), with this PR's C pass beside them, each cut fromgpu/vk/vk_memory.cppwith the host's list and generation stubbed; every refresh timed is a rebuild;RX_VK_CAPTURE_EAGERunset, a 64 MB cap; authored lists by address (~70% pools of 1-256 pages, ~25% of 1-64 MB, the rest larger). A script on this PC, not in this PR (asm_pool_ranges_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 µs per refresh. Change: before ÷ after (above 1: this PR faster).cffa2f468df7cd738df7cd73In play (held job
fb-g2135, 06:22 to 07:15 UTC on 2026-11-23): the Market, 60 s a run. The two builds are thishead
8df7cd73(rt-apr-8df7cd73) and its parent, the asm kitcffa2f46(rt-kit-cffa2f46): a warm-up each, then kitand head interleaved (kit head head kit, four times), every run loading at create. The output was pinned at 2560x1440,
on a desktop at 800x600 at 30 Hz (the PC's only screen then), so the swapchain and refresh are not those of a
2560x1440 desktop; the runs are alike among themselves. One head run (head6) is held: in it the game's first uses
waited 2,081 ms in all for shader loads (the longest wait 239 ms), so it wrote the load marker. Its draw figures are the
lowest of the 16 runs, and it has 2 bursts. The marker was moved out before the next run, and every later run logged
loading at create. That leaves 8 kit runs against 7 head runs.
Reach, from a diagnostic build of this head that is local and never pushed (one uncounted Market run, a counter added in
the capture's 600-submit line): in its last 24,000 submits (about 4,000 frames)
pool_rangesrebuilt the ranges 640times over about 3,700 pools each, about once every 6 frames. 627 of the rebuilds changed the ranges, and none fell back
to the sort, so the host's list always came by address: the micro-benchmark's 3.2× case, never its 0.82× one. The
rebuild runs at the start of each capture, before its lock is taken. The capture's 600-submit line times that part as
"lock" (ms a submit, printed to two decimals, so its averages are coarse). That part is the figure for this change's
stage.
cffa2f46(C sort and merge), 8 runs8df7cd73, 7 runsa frame's replay time (ms): submitSo the kernel's stage is faster where the rebuilds cluster, in the loads. In steady play, at about 23 µs saved a
rebuild and one rebuild every 6 frames, the saving is about 4 µs a frame, too small for any frame figure to show. In the
same loads the capture's other parts were slower with this head, at the edge (scan +5.1 %, copying +7.0 %, the whole
capture +5.3 %). They are code this pull request does not touch, and the head's loads copied 3.3 % more pages a
submit. That is not claimed either way. 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).
Risks
What could break: a range left out of the list would leave that pool's writes uncaptured (stale data on the GPU); the
test runs
pool_rangesandrefresh_pool_ranges_lockedcut from the source against main's refresh and its sort andmerge over lists with gaps, overlaps, touching and repeated starts, empty and too large pools, starts at and past 1 TB,
lists out of order and ends that wrap, between pages that fault, with and without
RX_VK_CAPTURE_EAGER. A revert isenough. Renderer 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
tests/that reads changed source is updated, not weakened.Assisted-by:/Co-Authored-By:trailers.Ready to merge
main, measured again or a comment says why the numbers still hold.@Beanstalk This rebuilds the capture's ranges of small pools, when the pools change, with a hand-written x86-64 kernel (gpu/vk), mostly while loading. 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 for two minutes and go into Hyrule Field (one scene load) and play it for two minutes; at least two starts a side, interleaved, the PR against main on the same PC, on Windows with an RTX 4070, Windows with an Arc B580, Linux with an RX 6600 (RADV) 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, device lost or validation error line.@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 69767 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.@Beanstalk This replaces my request 69767 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 rebuilds the capture's ranges of small pools, when the pools change, with a hand-written x86-64 kernel (gpu/vk), mostly while loading. 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 for two minutes and go into Hyrule Field (one scene load) and play it for two minutes; at least two starts a side, interleaved, the PR against main on the same PC, on Windows with an RTX 4070, Windows with an Arc B580, Linux with an RX 6600 (RADV) 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, device lost or validation error line.@siantm only members of
BigBeanscan start the farm. One of them can approve this request by reacting 👍 to it or to this comment.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.