WIP: perf(vk): over the hold's line the render target pool is given back before any texture is evicted #1104
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!1104
Loading…
Reference in a new issue
No description provided.
Delete branch "GummiNaomi/Longshot:perf/pool-first-eviction"
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?
Type: perf · Risk: low · Tested on: Windows 11, RTX 4070 SUPER (NVIDIA 617.42) · Needs: an 8 GB card; a 6 GB card; Linux; AMD; a Steam Deck
Why
When VRAM runs short, Longshot throws out textures that the game is still using, while hundreds of MB of idle render target images sit in the render target pool. At a 9.5 GB allowance (a 12 GB card with a browser and Discord open), on Castle Town's gate route the compaction's hold evicted 2,538 textures in 140 s, and 1,876 of them (74 %) were needed again and made again, most within 30 s. Each one is read, decoded and uploaded again; a pooled render target image costs a fraction of a millisecond to make again.
The pool's bound grew from 256 MB to up to 768 MB in #994, so this matters more now: the hold (
RX_VK_COMPACT_PCT, 85 % of the allowance) counts its room from the free space in the texture blocks only, and the pool is only given back above 90 % (pool_pressed), after textures have already gone.Follows #994 (merged) and its issue #995.
What changed
When VRAM is short, the render target pool's idle images are now given back before any texture is evicted, and the room they hold counts toward what the hold needs. Textures are evicted only for what the pool can't cover.
texture_frame's compaction hold (gpu/vk/vk_texture.cpp), the pool's idle images count as room the hold need not take from the textures (reclaim += idle), and when the pressure is over the hold's line the pool is given back first (pool_pressed = true, as above 90 % today). Textures are evicted only for what the pool can't cover.RX_VK_POOL_FIRST=0turns it off (as before).tests/test_target_image_pool.pychecks the order (the pool counted beforevram_compact::held_budget).RX_VK_POOL_FIRSTindocs/development.md, in the pool's row.Measurements
Verdict: mixed, so a draft. Textures evicted fall 83-86 % in both rounds, and the ones made again from 1,876 to 1 (round 1). Slow frames fall in round 1 and stay about the same in round 2. The mean fps is 8-9 % lower with the change in both rounds. Part of that is the route's timing on a wall clock (the mean weighs the 200+ fps field against the 70 fps town), but the field right after the gate (40-50 s) is lower in both rounds, where giving the pool back makes more images again. So on a 12 GB card the pool's churn may cost about what the evictions saved. The open question is whether that holds on 6-8 GB cards, where evictions are far more common. Giving back only the hold's excess (see Overlap) should keep the eviction cut with less churn.
Hardware: Windows 11 Pro 26200, RTX 4070 SUPER 12 GB (NVIDIA 617.42), Ryzen 9 9950X3D (16 cores, SMT off), 32 GB
Scene: save set "First Step into Hyrule Town", Castle Town's gate into Hyrule Field and back (gate-bridge-wall.txt, wall clock, 140 s), 2560x1440, DLAA, uncapped, the render thread on (Auto),
RX_VK_TEST_ALLOWED_MB=9500(the allowance this PC's driver gives with the user's usual programs open)Method: headless runs, the two sides in turn in one build; slow frames, 1 % low and mean from the frame trace's last three quarters; textures evicted from the log's
textures retired … budget Nlines (summed); render target images from the log'srender target images:lineHow to reproduce: the save set and route above with
RX_VK_TEST_ALLOWED_MBset a little above what the game uses in town (9500 on a 12 GB card);RX_VK_POOL_FIRST=0against the defaulta2cdf4e5a2cdf4e5Baseline: the same build with
RX_VK_POOL_FIRST=0, which is main's behaviour, so both sides ran the same binary and only the order of giving back changed; a separate main build would add build-to-build noise to a 140 s route.Builds: round 1 on #994's branch
a2cdf4e5with this change (v3.0.0-rc.4-140-ga2cdf4e5-dirty, the eviction counts from a TEMP log not in this PR); round 2 on this PR's change on main02903b04(v3.0.0-rc.5-6-g1909c292, the same code as this PR's commit before a comment's numbers and thedocs/testedfiles were added; since rebased onto maind76feb2d, which doesn't touchgpu/vk/vk_texture.cpp). Both sides of a round are the same build, run in turn.fps by 10 s slice (wall clock), to show where the means differ:
Flags and settings
One new switch, on by default.
RX_VK_POOL_FIRST0if a card gets slowerOverlap with other PRs
pool_pressedrule in the other direction. Today the pool is emptied above 90 %; #1035 keeps half of it up to 97 % so render targets stay reusable on 6 GB cards. This PR gives it back earlier, from the hold's 85 % line, so no texture goes while idle pool images stay. They don't have to conflict: a version that gives back only as much of the pool as the hold is over (and halves rather than empties it when that is enough) would keep both aims. Happy to rework this one that way, or to fold it into #1035, whichever the maintainers and flix331 prefer. #1035 also predates #994, so it still assumes the fixed 256 MB bound.texture_frame), a different part of it. Likely a textual merge conflict, not a conflict of aims; whichever lands second rebases.Testing
Tested: Windows 11, RTX 4070 SUPER, NVIDIA 617.42: the runs above;
tests/test_target_image_pool.pypasses (10 tests);python -I -B tests/run_all.py: 223 passed, 62 failed, 379 skipped, and main02903b04on the same PC gives the same counts and the same failing tests (this PC's toolchain: Windows line endings, fixtures needing gcc or clang++, which weren't on the path for this run). The same change was in the build played in Castle Town and Hyrule Field on this PC (with #994's settings) without a visible change in the picture.Not tested: a real 6 or 8 GB card (only a lowered allowance on a 12 GB one), AMD and Intel GPUs, Linux, a Steam Deck.
Must be tested:
RX_VK_POOL_FIRST=0, expecting fewertextures retired … budgetlines in the log and no more dips (by hand)Risks
What could break: on a card at its limit the pool now empties earlier, from 85 % instead of 90 %, so some render targets that would have been reused are made new and the pool's images are destroyed (
pool_trim, up to 64 a present). On this 12 GB card that looks to cost about what the evictions saved (the mean fps above). If it costs more than the evictions on a given card, frames are slower there. Nothing changes below the hold's line. The picture can't change: an evicted texture or a destroyed pool image is made again the same way as before.Turning it off:
RX_VK_POOL_FIRST=0.Compatibility: Nothing changes.
Issues
Related: #995 (render target churn, fixed by #994). Overlaps #1035, #1057.
Checklist
Everyone
type(scope): description) of the status line's type.main.python -I -B tests/run_all.pypasses (any failure that also fails onmainis named).third_party/untouched (a new folder with aPROVENANCE.mdinstead).When it applies
Assisted-by:/Co-Authored-By:trailers.docs/tested/for each new measured run (format indocs/tested-configurations.md).tests/that reads changed source updated in this PR, not weakened.🤖 Generated with Claude Code
Nice, tight change. Giving idle pool images back before live textures is the right order, and the same-binary A/B makes the trade easy to see. Three things from the code:
pool_pressedis set again at every look from the 90 % rule (vk_texture.cpp:4492), and the new line raises it only whileidleis non-zero. Between 85 and 90 %, a look with idle > 0 gives the pool back andpool_trimempties it. The next look sees idle ≈ 0 and lowers the flag, so the pool refills, and the cycle repeats every 20 presents. On the idle-free looks the hold also evicts for the full excess as before. This may be where the extra images made new and the lower field fps come from. Trimming only the excess and holding it while over the line (your Overlap idea) would fix it.useddrops byidle. Pooled images share the render targets' 128 MB blocks with live targets (vk_vma.cpp:52-56), and VMA keeps a block until it is empty.reclaimableleaves that space out for this reason (vram_compact.h:93-97). Loggingusedbefore and after a give-back would show how much really comes off.Overlap with #875: no textual conflict in
vk_texture.cpp. They're complementary: this PR changes how much the hold takes, #875 how old a texture must be.This is a code read only. Nothing was built or run.
🤖 Generated with Claude Code
@ -4509,0 +4518,4 @@std::lock_guard lk(pool_mu);idle = pool_bytes;}if (idle && pressure > allowed / 100 * pct) pool_pressed = true;Because of the
idle &&, this only holds while the pool still has something in it.pool_pressedis reassigned from the 90 % rule at every look (line 4492). So oncepool_trimhas emptied the pool, the next look clears the flag, the pool refills over 10 presents, and the look after that sets it again. Between 85 and 90 % the give-back alternates every look. Could the flag key off the count alone (over the hold's line) andpool_trimtake a cap ofpool_bytes - overrather than 0? Then only the excess goes and it stays gone.@ -4509,0 +4519,4 @@idle = pool_bytes;}if (idle && pressure > allowed / 100 * pct) pool_pressed = true;reclaim += idle;This credits all of
idleas room. The pooled images sit intarget_image_pool's 128 MB blocks beside live render targets, and VMA keeps a block until it empties (vk_vma.cpp:224). Destroying them may not lowerusedby this much. That is whyreclaimableleaves other blocks' free space out (vram_compact.h:93-97). Worth loggingusedbefore and after a give-back, or crediting only what actually came off at the previous look.Tested on Linux, as asked under Must be tested for a 6–8 GB card: this PR's commit rebased onto
main@43f40b87(no conflicts), on a 6 GB card's rules.Hardware: RTX 3090, NVIDIA 620.70.06, CachyOS.
Settings: DLAA 2560x1440 with
RX_VK_TEST_VRAM_MB=6144 RX_VK_TEST_ALLOWED_MB=5233.RX_VK_TEST_VRAM_MBmakes the renderer size everything for a 6 GB card, including the starting blocks, texture budget and mirrors.Route: one session each: Hyrule Field, then the Market (teleports), walking and then turning. One build,
RX_VK_POOL_FIRSTdefault against=0, plus two main runs.RX_VK_POOL_FIRST=0budgetlines)On this route, with a 6 GB card's rules, the pool given back first cut the textures retired by 7% (50,582 to 47,082) on the same build. That is inside the spread between main's two runs, and nowhere near the 2,538 to 347 of the description. Render targets were made new as often either way, and GPU time and fps are the same within this PC's noise. This PC swaps heavily, so the frame-time tails are noisy, which is why I compare GPU time.
So it neither helps nor hurts here. The route is different from yours (Field and the Market rather than the gate), and the pressure on a real 6 GB card may differ. I didn't see the fps drop of your rounds either.
🤖 Generated with Claude Code
@Beanstalk
Beanstalk test farm
Commit
a416edb· tier reviewed · approved by HumanBean · dashboardWhat will be tested · AI plan (
gpt-6.1-terra)The plan compares the Market and Hyrule Field on 6 GB and 8 GB cards, Linux, AMD, and Steam Deck, taking roughly 25–30 minutes per tester. It lowers the compaction threshold to exercise memory pressure and tests the new pool-first switch both on and off. It measures frame times, FPS, VRAM and load times and compares screenshots; crashes, substantial performance or memory regressions, and visual differences fail the plan. The available probes do not verify eviction ordering or count texture recreations.
0or1(PR only).RX_VK_COMPACT_PCT=50), then teleport to Market, move the stick, measure market for 30 s (after 5 s warm-up), take the picture market to compare with main, teleport to Hyrule Field, measure field for 30 s (after 5 s warm-up), take the picture field to compare with main, measure return for 20 s (after 5 s warm-up); 1 run on each side for each of 2 cells (2 game starts a run).Started. Run 2: the farm's reports were cleared after its Windows and Linux fixes: started again.
AMD Custom GPU 0932 (RADV VANGOGH), 26.1.99NVIDIA GeForce RTX 3070 Laptop GPU, 621.24.0AMD Radeon RX 7900 XTX (RADV NAVI31), 26.2.7AMD Radeon RX 9070 XT, 2.0.416RX_VK_POOL_FIRST=0 (PR only)RX_VK_POOL_FIRST=0 (PR only)RX_VK_POOL_FIRST=0 (PR only)RX_VK_POOL_FIRST=0 (PR only)RX_VK_POOL_FIRST=0 (PR only)RX_VK_POOL_FIRST=1 (PR only)RX_VK_POOL_FIRST=1 (PR only)RX_VK_POOL_FIRST=1 (PR only)RX_VK_POOL_FIRST=1 (PR only)RX_VK_POOL_FIRST=1 (PR only)Measurements · vram6gb
Verdict: could not be judged on vram6gb (1/1 report).
Hardware: 1: linux+amd+radv+igpu+handheld
AMD Custom GPU 0932 (RADV VANGOGH), 26.1.99AMD Custom APU 0932, 16 GB RAMScene: market-field-pressure, from a new save (frame_rate_cap=6, RX_VK_COMPACT_PCT=50); each cell's settings and switches as the table names them
Method: the Beanstalk test farm: main and this PR built and run on the same PC in one session, game starts alternating (ABBA); market-field-pressure: 1 game start a side, market 30 s after 5 s warm-up, field 30 s after 5 s warm-up, return 20 s after 5 s warm-up; each number the median of the runs, then of 1 report
How to reproduce: the farm's plan above (
@Beanstalkon this PR runs it again)d76feb2a416edbRX_VK_POOL_FIRST=0 (PR only)· longest load (s)RX_VK_POOL_FIRST=1 (PR only)· longest load (s)Flags and settings
RX_VK_POOL_FIRST0,1Markdown for the PR description
Measurements · vram8gb
Verdict: fail on vram8gb (1/1 report):
market-field-pressure crashfailed.Hardware: 1: windows+nvidia+nvidia-proprietary+dgpu
NVIDIA GeForce RTX 3070 Laptop GPU, 621.24.0AMD Ryzen 9 5900HX with Radeon Graphics, 32 GB RAMScene: market-field-pressure, from a new save (frame_rate_cap=6, RX_VK_COMPACT_PCT=50); each cell's settings and switches as the table names them
Method: the Beanstalk test farm: main and this PR built and run on the same PC in one session, game starts alternating (ABBA); market-field-pressure: 1 game start a side, market 30 s after 5 s warm-up, field 30 s after 5 s warm-up, return 20 s after 5 s warm-up; each number the median of the runs, then of 1 report
How to reproduce: the farm's plan above (
@Beanstalkon this PR runs it again)d76feb2a416edbRX_VK_POOL_FIRST=1 (PR only)· field · frame rateRX_VK_POOL_FIRST=1 (PR only)· market · frame rateRX_VK_POOL_FIRST=1 (PR only)· return · frame rateRX_VK_POOL_FIRST=1 (PR only)· field · peak VRAM (MB)RX_VK_POOL_FIRST=1 (PR only)· market · peak VRAM (MB)RX_VK_POOL_FIRST=1 (PR only)· return · peak VRAM (MB)RX_VK_POOL_FIRST=1 (PR only)· longest load (s)RX_VK_POOL_FIRST=1 (PR only)· field · frame time (p99) (ms)RX_VK_POOL_FIRST=1 (PR only)· market · frame time (p99) (ms)RX_VK_POOL_FIRST=1 (PR only)· return · frame time (p99) (ms)Flags and settings
RX_VK_POOL_FIRST0,1Markdown for the PR description
Measurements · linux
Verdict: could not be judged on linux (1/1 report).
Hardware: 1: linux+amd+radv+dgpu
AMD Radeon RX 7900 XTX (RADV NAVI31), 26.2.7AMD Ryzen 7 5800X3D 8-Core Processor, 64 GB RAMScene: market-field-pressure, from a new save (frame_rate_cap=6, RX_VK_COMPACT_PCT=50); each cell's settings and switches as the table names them
Method: the Beanstalk test farm: main and this PR built and run on the same PC in one session, game starts alternating (ABBA); market-field-pressure: 1 game start a side, market 30 s after 5 s warm-up, field 30 s after 5 s warm-up, return 20 s after 5 s warm-up; each number the median of the runs, then of 1 report
How to reproduce: the farm's plan above (
@Beanstalkon this PR runs it again)d76feb2a416edbRX_VK_POOL_FIRST=0 (PR only)· longest load (s)RX_VK_POOL_FIRST=1 (PR only)· longest load (s)Flags and settings
RX_VK_POOL_FIRST0,1Markdown for the PR description
Measurements · amd
Verdict: fail on amd (1/1 report):
market-field-pressure screenshot.max_difffailed.Hardware: 1: windows+amd+amd-proprietary+dgpu
AMD Radeon RX 9070 XT, 2.0.416AMD Ryzen 7 5800X3D 8-Core Processor, 32 GB RAMScene: market-field-pressure, from a new save (frame_rate_cap=6, RX_VK_COMPACT_PCT=50); each cell's settings and switches as the table names them
Method: the Beanstalk test farm: main and this PR built and run on the same PC in one session, game starts alternating (ABBA); market-field-pressure: 1 game start a side, market 30 s after 5 s warm-up, field 30 s after 5 s warm-up, return 20 s after 5 s warm-up; each number the median of the runs, then of 1 report
How to reproduce: the farm's plan above (
@Beanstalkon this PR runs it again)d76feb2a416edbRX_VK_POOL_FIRST=0 (PR only)· field · frame rateRX_VK_POOL_FIRST=0 (PR only)· market · frame rateRX_VK_POOL_FIRST=0 (PR only)· return · frame rateRX_VK_POOL_FIRST=0 (PR only)· field · peak VRAM (MB)RX_VK_POOL_FIRST=0 (PR only)· market · peak VRAM (MB)RX_VK_POOL_FIRST=0 (PR only)· return · peak VRAM (MB)RX_VK_POOL_FIRST=0 (PR only)· longest load (s)RX_VK_POOL_FIRST=0 (PR only)· field · frame time (p99) (ms)RX_VK_POOL_FIRST=0 (PR only)· market · frame time (p99) (ms)RX_VK_POOL_FIRST=0 (PR only)· return · frame time (p99) (ms)RX_VK_POOL_FIRST=1 (PR only)· field · frame rateRX_VK_POOL_FIRST=1 (PR only)· market · frame rateRX_VK_POOL_FIRST=1 (PR only)· return · frame rateRX_VK_POOL_FIRST=1 (PR only)· field · peak VRAM (MB)RX_VK_POOL_FIRST=1 (PR only)· market · peak VRAM (MB)RX_VK_POOL_FIRST=1 (PR only)· return · peak VRAM (MB)RX_VK_POOL_FIRST=1 (PR only)· longest load (s)RX_VK_POOL_FIRST=1 (PR only)· field · frame time (p99) (ms)RX_VK_POOL_FIRST=1 (PR only)· market · frame time (p99) (ms)RX_VK_POOL_FIRST=1 (PR only)· return · frame time (p99) (ms)Flags and settings
RX_VK_POOL_FIRST0,1Markdown for the PR description
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.