perf(vk): the game's per-frame render targets are reused instead of made and destroyed twice a frame #994
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!994
Loading…
Reference in a new issue
No description provided.
Delete branch "GummiNaomi/Longshot:perf/target-pool-every-frame"
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: Linux; AMD; Intel; a Steam Deck; an 8 GB card
Why
In busy places the frame rate goes up and down: in Castle Town's market at night, frames over 25 ms come several times a second. One cause is in the renderer: the game makes its per-frame render targets (a 384 x 384 depth target, 1280 x 720, 640 x 360 and 2560 x 1440 ones) at a slightly different place in its memory every frame, and Longshot made a new Vulkan image for each of them and destroyed one, about twice a frame. Destroying and making images was about 20 % of the render thread's time there (vkDestroyImage 15 %, vmaCreateImage 5 %, sampled).
See #995.
What changed
The render target pool, meant to hand last frame's image to this frame's target of the same shape, now gets its dead targets in time and keeps enough of them. Measured in the market at night: of the images made new, 80 % had last frame's one of their shape alive and unused, and the pool destroyed 99 % of what it let go for being over its 256 MB bound (21,879 of 22,000 in 100 s): dead targets came back every 10 presents, three or more presents late, ten frames' worth at once, and went over the bound.
RX_VK_DEAD_EVERY10 -> 1) after one present unused (RX_VK_DEAD_MIN_UNUSED3 -> 1), intexture_frame(gpu/vk/vk_texture.cpp).gpu/vk/target_pool.h,pool_cap), two or three frames of these targets;RX_VK_TARGET_POOL_MBstill sets it. Under VRAM pressure the pool is given back as before (pool_pressed), and on a small card the bound stays near the old 256 MB.tests/test_target_pool_cap.py(the bound by allowance),tests/test_target_image_pool.py(the new defaults).docs/development.md.Measurements
Verdict: fewer slow frames and less render thread time, the average frame rate about the same or a little higher. The images made new fall by 62 % on this build, and by 65-79 % in earlier runs with the same settings.
Hardware: Windows 11 Pro 26200, RTX 4070 SUPER 12 GB (NVIDIA 617.42), Ryzen 9 9950X3D (16 cores, SMT off), 32 GB
Scene: Castle Town's market at night (save set "First Step into Hyrule Town",
!cheat 121at 40 s), 2560x1440, DLAA, uncapped, the render thread on (Auto)Method: headless runs on a wall-clock script (town-market.txt, 100 s), the two sides in turn in one build; fps is the median of the log's 120-present lines with 1,500-2,999 draws; slow frames and 1 % low from the frame trace's last two thirds; images from the log's
render target images:lineHow to reproduce: the save set above, the walk into the market at night;
RX_VK_TARGET_POOL_MB=256 RX_VK_DEAD_EVERY=10 RX_VK_DEAD_MIN_UNUSED=3against the defaultsa2cdf4e5a2cdf4e5Baseline: the same build with the old defaults set by switch (run with this change in the working tree on main
d9486a08, then rebased cleanly ontoa0be15b3); one round, the PC's time being short. The same three settings as switches on main14e165ab(with the play folder's other switches,RX_VK_MIRROR_SPARSE=0), three rounds in turn, gave:14e165ab)Played on the same PC with these settings: no visible change in the picture. A frame-by-frame check (a 320x180 picture of every present, counting one-frame flips over 1 % of the picture) gave 60 and 119 such frames against 17-60 on main's runs, all under 2.2 % of the picture and spread out (motion and lights), none of the concentrated kind a wrong image gives.
Flags and settings
Three defaults change; no new switch.
RX_VK_DEAD_EVERYRX_VK_DEAD_MIN_UNUSEDRX_VK_TARGET_POOL_MBTesting
Tested: Windows 11, RTX 4070 SUPER, NVIDIA 617.42: the runs above; played in Castle Town and Hyrule Field with the same three settings over two sessions ("seems good");
tests/test_target_pool_cap.pyandtests/test_target_image_pool.pypass;python -I -B tests/run_all.py: 359 passed, 88 failed, 205 skipped; maind9486a08on the same PC: 358 passed, 88 failed, the same 88 (this PC's toolchain: Windows line endings, fixtures needing gcc or compiling with-Werror).Not tested: AMD and Intel GPUs, Linux, a Steam Deck, an 8 GB card (where the bound is ~580 MB and the VRAM tighter).
Must be tested:
RX_VK_TARGET_POOL_MB=256 RX_VK_DEAD_EVERY=10 RX_VK_DEAD_MIN_UNUSED=3, expecting fewer dips with the defaults and no flicker (Test Farm: @Beanstalk linux)textures retiredlines) (by hand)Risks
What could break: a render target let go one present after its last use while the game still samples it later: it would come back empty (a flicker). The dead rule is unchanged (another target drawn over its storage since); only the wait and the sweep's interval are shorter. More VRAM held by idle pooled images on cards near their limit: given back under pressure as before.
Turning it off:
RX_VK_TARGET_POOL_MB=256 RX_VK_DEAD_EVERY=10 RX_VK_DEAD_MIN_UNUSED=3.Compatibility: Nothing changes.
Issues
See #995.
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
WIP: perf(vk): the game's per-frame render targets are reused instead of made and destroyed twice a frameto perf(vk): the game's per-frame render targets are reused instead of made and destroyed twice a frame@Beanstalk linux, any GPU: Castle Town's market at night (a save in town, night), walk into the market and turn the camera for a few minutes with the FPS counter on; then the same with RX_VK_TARGET_POOL_MB=256 RX_VK_DEAD_EVERY=10 RX_VK_DEAD_MIN_UNUSED=3 (the old behaviour). Expect fewer dips and slow frames with the defaults and no flicker. Please post both runs' 1 % low or slow-frame counts and whether anything flickered.
@Beanstalk amd, Windows or Linux: Castle Town's market at night (a save in town, night), walk into the market and turn the camera for a few minutes with the FPS counter on; then the same with RX_VK_TARGET_POOL_MB=256 RX_VK_DEAD_EVERY=10 RX_VK_DEAD_MIN_UNUSED=3 (the old behaviour). Expect fewer dips and slow frames with the defaults and no flicker. Please post both runs' 1 % low or slow-frame counts and whether anything flickered.
Beanstalk test farm
Commit
a2cdf4e· tier reviewed · approved by GummiNaomi · dashboardWhat will be tested · AI plan (
gpt-6.1-terra)On Linux and AMD PCs, the plan teleports a fresh child save to the market, moves and turns the camera, then measures for 100 seconds with default pool settings and again with the old-behavior switches. The requested nighttime town save is unavailable, so the plan cannot guarantee night or reproduce the walk into the market; the roughly 25-minute run measures 1% low frame time, hitches and VRAM and captures screenshots. Crashes, substantial frame-time regressions, device-loss logs or screenshot differences beyond tolerance fail the plan. The plan cannot automatically compare the two switch configurations against each other or detect flicker between screenshots. Neither requested target is online now, so both will wait for a matching PC. No tester online now matches linux, amd: those targets wait for one.
RX_VK_DEAD_EVERY=10,RX_VK_TARGET_POOL_MB=256,RX_VK_DEAD_MIN_UNUSED=3), then teleport to Market, 4 times: move the stick, take the picture market-first to compare with main, measure market for 100 s (after 10 s warm-up), take the picture market-last to compare with main; 1 run on each side.Done. Run 2: re-planned by GummiNaomi. Comment
@Beanstalkto run it again.madebyjordan referenced this pull request2026-11-16 01:50:05 +00:00