WIP: perf(vk): sparse mirror binds stop holding frames: unbinds unwaited, give-back capped, new mirrors bound together #2892
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!2892
Loading…
Reference in a new issue
No description provided.
Delete branch "(deleted):perf/sparse-bind-smoothing"
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
Sparse VRAM mirrors held frames in two ways (symbolized samples, AMD's Windows driver):
vkQueueBindSparse(mirror_make->sparse_fill->sparse_bind_infos, underdev.present_mu). That cost about 65 ms per arrival; one frame spent 65 ms inNtGdiDdDDIUpdateGpuVirtualAddress.mirrors_give_backfreed every mirror idle pastkLongIdleat once (one log line:171 mirrors given back (1475 MB)).sparse_reapthen unbound their spares in one bind, andmemory_sparse_waitmade every following submission wait for it: 40-110 ms frames with the replay idle.This PR:
sparse_tl_need), not for a freed mirror's spare unbind. A bind into a reused spare waits on the queue for that spare's unbind.RX_VK_SPARSE_UNBIND_ASYNC=0is the old path whole.RX_VK_MIRROR_GIVE_BACK_MB(256) of long-idle mirrors per sweep, oldest first, and always at least one. Mirrors given back for room are never held. 0 gives them all back at once, as before.RX_VK_SPARSE_BIND_BATCH_MB(64) per bind, sent at the end of themirror_makeloop. A refused batch is retried per mirror. 0 binds each alone, as before.Read first:
gpu/vk/sparse_smooth.h, thenmemory_sparse_wait,mirrors_give_backandsparse_reapingpu/vk/vk_memory.cpp.Testing
Tested: Windows 11, AMD Radeon RX 6800, driver 26.10.1, with the other two PRs (Measurements); no visual differences seen.
Checks:
tests/test_sparse_smooth.py(new).test_sparse_bind_ranges.py(the wait value, the spare's wait, the switch off),test_sparse_mirror.pyandtest_sparse_spare.pypass.clang++ -fsyntax-onlywith the builder's flags onvk_memory.cpp.Still to test:
Measurements
Verdict: each change does the work it targets (below), but on its own none moves total stutter at area changes beyond run-to-run noise. Together with its two sibling PRs, the worst frame at an arrival is 15-25% shorter. An earlier claim here of "-20% stutter in the loads" was mostly how long each load took: the loads' length alone varies from 3,300 to 4,900 frames between runs of the same build.
Setup:
kokiri-start, then teleports to Market (child), Hyrule Field (child), Kakariko Village, Kokiri Forest, Hyrule Field (adult) and Lake Hylia (adult). 25 s in each with the camera turning, plus 20 s walking in circles in Hyrule Field.RX_VK_FRAME_TRACE=1).28cb22b9(5)In play (the walk and the camera turns, outside the arrivals), every run of every build has a median frame of 9.8-10.0 ms and 0-1 frames of 33 ms or more.
What the worst arrival frames are spent on, in the runs with all three: draw 100-440 ms, mostly in the recording's commands (up to 396 ms: the first bindings of vertex and index buffers, which import host memory and make mirrors) and descriptors. A change that imports pools ahead of their first binding is being measured on top of these three.
Risks
VK_ERROR_OUT_OF_DEVICE_MEMORYshortly after arriving in Market (7.8 of 15.5 GB of VRAM in use), and the game stopped drawing. It has not come back in nine runs since, and no run of main or the nightly (about 20) has refused a submit. Until it is explained, treat this PR as a possible cause.RX_VK_SPARSE_UNBIND_ASYNC=0 RX_VK_SPARSE_BIND_BATCH_MB=0 RX_VK_MIRROR_GIVE_BACK_MB=0.Checklist
Ready for review
main; the title is a Conventional Commit.mise run testpasses (any failure that also fails onmainis named). (Not run yet: the checks reading the changed files pass, apart from failures they share with main.)main, or Measurements says why there is nothing to measure. (Measured: no stutter gain on its own beyond the noise.)third_party/untouched; nothing GPL-incompatible.When it applies
gpu/vk/switches.def. (Rows added; defaults to be confirmed by this PR's own A/B.)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.🤖 Generated with Claude Code
Tested in game: Windows 11, AMD Radeon RX 6800, driver 26.10.1, i7-13700: a pack over main
28cb22b9with the texture block reserve, shader parse cache and sparse bind PRs together, six teleport tours through Market, Hyrule Field (child and adult), Kakariko, Kokiri Forest and Lake Hylia with the player's settings; no visual differences, loads stutter about 20% less, frame rate in play unchanged. One run (the first after the build) froze with refused submits (VK_ERROR_OUT_OF_DEVICE_MEMORY), not seen again in nine runs: under investigation, see Risks.Possibly related, for context:
Measurements corrected: each change built alone over main (two runs each), against five runs of main. The earlier '-20% stutter in the loads' was mostly load length varying between runs. On its own this change does not move visible stutter at arrivals beyond the noise; with its two siblings the worst arrival frame is 15-25% shorter. Staying WIP while the next change (imports made ahead of their first binding) is measured on top.
Closing as not significant: the stutter a player sees at an area change is not measurably lower with this change, alone or together with its siblings (#2890, #2891, #2892) and three further fixes. Each does the work it targets; the frames that stutter just move to other work.
Setup: Windows 11, RX 6800, driver 26.10.1, the player's settings, uncapped. A six-teleport tour, each run a separate launch in timing mode. Visible stutter is what frames of 25 ms or more spend over 16.7 ms, from 1 s before control returns to 2 s after, summed over the six arrivals.
28cb22b9(8 runs)What did show:
What holds an arrival frame now, from symbolized samples: host-memory imports of the game's re-created area pools (39% of the replay thread), and mirrors rebuilt after the loading screen (~16%). The first frame of an area pays for whatever is first used in it; moving one cost earlier did not shorten that frame overall.
The branches stay on conongnang's fork in case someone picks this up.
🤖 Generated with Claude Code
Pull request closed