WIP: feat(vk): opt-in mirror syncs by changed 256-byte blocks (RX_VK_SLOW_LINK=1) #3162
No reviewers
Labels
No labels
area/accessibility
area/audio
area/input
area/install
area/menu
area/mods
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!3162
Loading…
Reference in a new issue
No description provided.
Delete branch "neotoxic/Longshot:perf/slow-link-blocks"
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
Draft, stacked on #3161 (the PCIe link line): review that one first. This PR's own change is the last commit.
Every submission, a mirror sync sends each page the CPU wrote to VRAM whole, about 4.9 MB a frame in Hyrule Field, while most of each page has not changed. This adds an opt-in experiment, off for everyone: with
RX_VK_SLOW_LINK=1, the game hashes each page's sixteen 256-byte blocks while it already copies the page, and sends only the blocks that changed since that page's last sync. Neighbouring changed blocks go as one copy, and a page with no changed block costs nothing. Without the switch, nothing changes: no hashing, no new log line.It is meant for testers whose GPU sits behind a slower link than the one it was measured on: a Thunderbolt eGPU (about 3 GB/s), a x4 slot, a hybrid laptop. The
vk: pcie link:line from #3161 says how fast a player's link is.Correctness comes first, since a block wrongly skipped would show as a wrong picture:
mem_check.hexplains why: a sync of only the changed words lost the game's counter resets).RX_VK_MEM_CHECK=1, each page synced by blocks is also read back from VRAM after its sync and compared with the capture's bytes.A
vk: a frame: mirror syncs by blocksline every 120 presents gives the bytes copied against the bytes the dirty pages cover:The idea of copying only changed blocks on a slow link comes from HeyListen (Sacrappy). No code was taken; the code is Longshot's own.
Read first:
gpu/vk/msync_diff.h(the hashes, the per-pool state, one page's sync), thenmirror_syncandmsync_diff_poolingpu/vk/vk_memory.cpp.Testing
Tested:
dev.py ab --env RX_VK_SLOW_LINK=1 --runs 2in Hyrule Field on8b6944d2. Unset, the logs have no block line (0 in either run). With the switch, the counter shows 1.98 MB copied of 4.83 MB covered (41 %). No FATAL line in any run.RX_VK_MEM_CHECK=1and the switch: 2,038,131 pages read back after their sync, 0 differing. The check's ownsync_over_gpucounter showed 0 replaced.RX_VK_MEM_CHECK=1: 2,166,836 pages read back, 0 differing. Counter: 2.00 MB copied of 4.91 MB covered (41 %).tests/test_msync_diff.pycovers the block hashes, the merging, the fall-backs to whole pages, the state's key and its forgetting, and a 2000-sync random run where the mirror always matches the source. It also checks the source: the pool exclusions, the late pages, and every other writer of a mirror forgetting. It fails onmain. The five fixtures that copyPool,CopyPartorcopy_pagesnow include the header.run_all.py --changed origin/maingives 282 passed, 5 failed, 17 skipped. The 5 that fail, test_pad_speaker (nocchere), test_tex_desc_memo, test_thinlto_tls, test_recorder_sync (runtime part) and test_prepare_stall, fail the same way onmainee9e1ed7on this PC.Still to test:
vk: pcie link:line and the two runs' fps would settle it (by hand, a tester).dev.py ab --a RX_VK_SLOW_LINK=0 --b RX_VK_SLOW_LINK=1in Hyrule Field. A gain is expected only if thevk: pcie link:line shows well under 6.7 GB/s host to device; post that line and the table (by hand, a tester)RX_VK_MEM_CHECK=1and the switch: thesyncs by blocksmem check line, expecting 0 pages that differ (by hand)Measurements
RX_VK_PCIE_PROBEin this diff comes from #3161, which ships it on (the probe costs nothing in a frame: measured there). This PR addsRX_VK_SLOW_LINK, which ships off, for the reason in the Verdict.Verdict: correct, and 59 % fewer upload bytes, but no gain where it was measured: -3 % fps on a PCIe 3.0 x8 laptop, where the hashing costs more than that link saves, and +0 on an x16 desktop. Hence off by default, for testers on slower links.
Baseline: the same build with the switch unset (
RX_VK_SLOW_LINK=0), notmain. The change is off unless the switch is set, so the switch alone is what the comparison isolates. 3213db7f is this commit's code before it moved onto #3161, where a policy flag turned it on instead of the switch.Setup: an RTX 3060 Laptop on CachyOS with its display wired straight to the dGPU (MUX), PCIe 3.0 x8, the probe measuring 6.7 / 6.6 GB/s. Hyrule Field,
dev.py ab --a RX_VK_SLOW_LINK=0 --b RX_VK_SLOW_LINK=1 --set RX_VK_WB_OBSERVE=1 --runs 3, on the same build. The medians of 3 interleaved runs, each run in brackets.On this PC (RTX 5080, x16, Windows 11,
8b6944d2,--runs 2): 173.3 / 172.8 fps unset against 172.1 / 172.3 with the switch. Unset, it matches the probe's own headc9a29ba7on this PC, 172.2 / 173.6 fps (one 15 s run each, so a loose comparison).Risks
RX_VK_SLOW_LINK=1is set: a player who does not set it runs the same code as before, with no hashing and no extra memory.RX_VK_MEM_CHECK=1reads each such page back to prove it, and unsetting the switch turns it all off.Checklist
Ready for review
main; the title is a Conventional Commit.mise run testpasses (any failure that also fails onmainis named).python -I -B tests/run_all.py --stricton Windows, on this head: 689 passed, 160 failed, 51 skipped; onmain@ee9e1ed7: 687, 160, 51, the same 160 failing checks and none new (Windows ones: missing Linux tools, paths, file locking). Linux CI runs the lot.main, or Measurements says why there is nothing to measure.third_party/untouched; nothing GPL-incompatible.When it applies
gpu/vk/switches.def.tests/that reads changed source is updated, not weakened.8b6944d2.Assisted-by:/Co-Authored-By:trailers.Ready to merge
main, measured again or a comment says why the numbers still hold.🤖 Generated with Claude Code
Tested in game: yes, on Windows 11 (RTX 5080) and CachyOS (RTX 3060 Laptop, PCIe 3.0 x8), with RX_VK_SLOW_LINK=1 and without; RX_VK_MEM_CHECK=1 read back every page synced by blocks, none differed. Off by default: nothing changes without the switch.
b77c2f4b) into perf/pcie-probe 60f62f7deab77c2f4b) into perf/slow-link-blocks fdf6ba10c0e345b3cab) into perf/pcie-probee345b3cab) into perf/slow-link-blocksBrought up to current
main(e345b3ca) by a merge, nothing rewritten. It also carries #3161 brought up to date the same way. Windows,run_all.py --changed origin/main: 288 passed, 3 failed:test_dlssg,test_sync_watch_eventandtest_turf_budget, which fail onmainitself too (checked in a checkout ofmainon the same PC).18edd509) into perf/slow-link-blocksBrought up to current
main(18edd509) by a merge,d41ec0ad, nothing rewritten.mainnow holds #3161 merged with changes of its own, so its three files met this branch's copy as add/add conflicts: each was merged three ways from #3161's last head here, which leavespcie_link.handvk_pcie_link.cppasmainhas them and keeps this branch's one change totest_pcie_link.py. Windows,run_all.py --changed origin/main: 247 passed, 7 failed (test_dlssg, fourtest_present_*,test_sync_watch_event,test_turf_budget): all of them fail onmainat18edd509too, on this PC, run there with the same toolchain.3a0f7d8f7) into perf/slow-link-blocksThanks for the PR! I'd like to test
RX_VK_SLOW_LINKon Linux, but I'm not able to build it myself. Could you provide a Linux binary or CI artifact for testing? I can report back thevk: pcie link:log line and FPS results.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.