WIP: perf(vk): give the VRAM mirrors to the pools the GPU reads most on 4-6 GB cards #1141
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!1141
Loading…
Reference in a new issue
No description provided.
Delete branch "mage_92/Longshot:perf/mirrors-by-heat"
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?
Why
On 4-6 GB cards the VRAM mirror budget (256-512 MB) goes to the pools bound first. On an RTX 3050 Ti Laptop (4 GB), dozens of small pools bound every frame held the whole budget, while one or two large pools the GPU reads most (160 MB and 132 MB, 96% of the 21.9 GB read over PCIe in 600 submissions) stayed in system memory for good. The GPU read them over PCIe every frame: slower frames and more stutter on small cards.
What changed
Pool::heatingpu/vk/vk_memory.cpp: the bytes bound from each pool (at most 1 MB a binding,RX_VK_MIRROR_HEAT_CAP_KB), decayed by a quarter every 16 submissions, added without the lock (__atomic), read under it.mirrors_by_heat(): every 64 submissions, the hottest wanted pool that does not fit takes the room of mirrored pools bound at least four times less, coldest per MB first. GPU-written and GPU-only pools are never taken, and pools with an inheritance pending are left alone. Pools only go if their combined heat is at most half of the newcomer's, so they cannot take the room back.RX_VK_MIRROR_SMALL_PCT(70) % of the budget, so a big hot pool always finds room.mirror_budget()addsmirror_heat_extra: room past the budget for the one hottest pool the full mirrors left out, while VRAM has it (RX_VK_MIRROR_HEAT_EXTRA).mirror_budget()keeps readingmirror_budget.halone (tests/test_mirror_budget.pypasses).Flags and settings
RX_VK_MIRROR_HEATRX_VK_MIRROR_HEAT_CAP_KBRX_VK_MIRROR_SMALL_PCTRX_VK_MIRROR_HEAT_EXTRA=0)RX_VK_MIRROR_HOT_MBMeasurements
Not measured on Longshot
mainyet (this PR stays WIP until it is). The numbers below are from the same change applied to an earlier Longshot nightly and to Hookshot 2.3.1, which shares this renderer.Hardware: Dell XPS 15 9520, NVIDIA RTX 3050 Ti Laptop 4 GB (driver 580.196.07), Intel i9-12900HK (PL1 held at 25 W), 16 GB DDR5-4800, Fedora 43, kernel 7.2.15, KDE Plasma 6 Wayland.
Scene: Hyrule Field, child Link, daytime. Handheld profile (1536×864 output), render resolution 75%, the game's own upscaler, built-in frame generation 2× with
HOS_FPS_MAX=30, Reflex on, fullscreen.Method: a scripted run. Link runs 9 s straight, looks left and right, turns around and repeats. There are 30 s of settling, then 60 s measured from
RX_VK_FRAME_LOG(the frames shown), runs interleaved.How to reproduce: a save in Hyrule Field, the settings above,
HOS_INPUT_LIVEdriving the same inputs. The scripts are available on request.Baseline: Hookshot 2.3.1 with the same environment switches but without this change. This change was applied together with two small unrelated patches (range-list versioning, a diagnostic). main wasn't the comparison because the A/B was run on Hookshot during a night of tests; a main A/B is the next step.
Earlier, on Longshot (Kokiri Forest, standing): with the 132 MB pool mirrored, the game's indirect dispatches took 2.8 ms a frame instead of 4.6, and the frame rate was 59.5 instead of 55. The GPU took 12.3-13.6 ms per frame instead of 15.0.
Testing
Tested: On the laptop above, many hours of play and scripted runs in Kokiri Forest, Hyrule Field and Castle Town market on earlier nightlies and on Hookshot 2.3.1. No visual problem was noticed and there were no device losses. On this branch:
tests/run_all.pygives 586 passed, 17 failed, 74 skipped. The 17 failures are the same 17 that fail onmain@71b1edd8on this PC (environment: missing Vulkan/SPIR-V headers and packaging tests).gpu/vk/vk_memory.cppcompiles with the AppImage's clang.Not tested: This exact commit in the game, on
main(rebased today). Cards above 4 GB, AMD, Intel and Windows.Needs other testers:
RX_VK_MIRROR_HEAT=0against default, expecting equal or better (request to open).Screenshots
Nothing on screen.
Risk and rollback
A pool read from system memory instead of VRAM is slower, not wrong, so a bad choice costs speed, not correctness. GPU-written pools are never taken.
RX_VK_MIRROR_HEAT=0restores the previous first-come-first-served behaviour; reverting the commit is enough.Reviewer notes
Start with
mirrors_by_heat()and thePool::heataccounting inmemory_bind.RX_VK_MIRROR_HEAT_EXTRAis the part I trust least: it is off-worthy until measured on more cards.Checklist
For everyone
type(scope): description).main.python -I -B tests/run_all.pyrun and passing (any failure that also fails onmainis named above).third_party/untouched (a new folder with aPROVENANCE.mdinstead).If applicable
Assisted-by:/Co-Authored-By:trailers.🤖 Generated with Claude Code
Possibly related, for context:
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.