perf(vk): cut Market 1536x864 GPU time 2.9% (-80 MB VRAM, +1.0% FPS) across GPUs by keeping stock simulated turf on game buffers #2328
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!2328
Loading…
Reference in a new issue
No description provided.
Delete branch "Jer9/Longshot:perf/vk-sim-turf-stock-passthrough"
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
Longshot's simulated-turf system keeps a private GPU copy of the game's grass buffers so it can grow them when dense grass overflows the Switch 2's stock buffer size (
#2174). Previously, it allocated those private buffers (~28 MB) immediately at stock size and copied~14.4 MBof grass data back into the game's buffers every single frame with a full-GPU barrier — even in areas with almost no grass (like cobblestone Market,0–197blades) or normal Hyrule Field (~17,000blades, well under the143,360-blade stock limit).This PR lets simulated turf write directly into the game's own buffers whenever demand fits within stock capacity, eliminating the per-frame
~14.4 MBmirror copy, the full-GPU barrier, and the duplicate VRAM allocation game-wide (Hyrule Field, Market, Kokiri Forest, dungeons — every scene that uses simulated turf within stock capacity). If dense grass ever approaches the stock limit (>= 7/8 * stock), it seamlessly promotes to a larger private buffer just as before and retires it back to the game's buffer after 600 quiet frames.Where this helps vs. where it doesn't:
+0.3%to+1.0%FPS is too small to feel without an FPS counter). Its real value is quiet, zero-downside efficiency — stopping~14.4 MB/frameof wasted GPU memory bandwidth and freeing48–80 MBof VRAM everywhere in the game, which gives extra headroom on tight 6–8 GB GPUs and iGPU laptops/handhelds (Steam Deck, 780M/860M/890M) sitting near a frame-rate or VRAM edge.~54,000blades and Market at100% render scale). Eliminates the0.422 msturf mirror-copy span (< 0.093 ms, totalm dispatch-10.1%), cuts GPU frame time-0.47 ms(-2.9%) at Market100% render scale(1536x864) and-0.50 ms(-2.5%) at Hyrule Field100% render scale(1382x864), saves-80 MBsteady VRAM in Market100% render scale(from avoiding the~28 MBprivate buffers plus VMA64/32 MBblock granularity), and lifts Median FPS+1.0%in Market100% render scaleand+0.3%in Hyrule Field100% render scale(all 3 rounds non-overlapping in both zones).67% render scale,1024x576, on this 8-CU iGPU, where GPU time sits around12.4–12.8 msinside an~18.4 msframe, so FPS/VRAM deltas fall within run-to-run variance) and extreme dense-turf settings that exceed7/8 * stock(which intentionally promote to a private buffer likemain).Technical details:
policy.target() <= stockin adaptive mode (gpu/vk/vk_draw.cpp:sim_turf_private_binding()andsim_turf_bound_result()), leavingsim_turf_bound()empty somirrorsis empty (0 MB/framecopied).sim_turf_sample_demand()'s post-copy barrier fromALL_COMMANDS_BIT | MEMORY_READ_BITtoHOST_BIT | HOST_READ_BITwhenmirrors.empty()(only the 4-byte demand readback copies ran).RX_VK_SIM_TURF_ADAPTIVE=0as a runtime A/B and kill switch (want_private = !sim_turf_adaptive() || g.policy.target() > stock;gpu/vk/switches.defupdated) and guard the stock-passthrough descriptor fallback againstRX_VK_SSBO_STRETCH=1andRX_VK_SSBO_WIDE(&& !Shader::IsSimTurfStorage(d)).Read first:
sim_turf_private_binding()andsim_turf_sample_demand()ingpu/vk/vk_draw.cpp.See #2174, #2093.
Testing
How to test:
python -I -B tests/test_sim_turf_stock_passthrough.py(fails onmain, passes here) plustests/test_sim_turf_floor.py,tests/test_sim_turf_capacity_policy.py,tests/test_sim_turf_pools.py, andtests/test_switch_table.py.longshot_log.txtforvk: simulated turf: prog 3de6d86ec7e6720e— it should log: the game's owninstead of: the private one.RX_VK_PASS_TIMING=2in Market;dispatch indirect prog 3de6d86ec7e6720eshould drop from~0.42 msout of the top-25 spans (< 0.093 ms) andm dispatchshould drop by~0.45 ms.100% render scale— avoid CPU-bound67% render scale(1024x576) where GPU savings are hidden by CPU frame time). Comparemainvs. this PR (or toggleRX_VK_SIM_TURF_ADAPTIVE=0vs.=1on this build) across>= 3interleaved rounds with>= 12.5 spost-load settle.Market -> Hyrule Field -> Kokiri Forestand confirm grass renders cleanly with0VK_ERROR_DEVICE_LOST. Optionally raise turf density past7/8 * stockin Hyrule Field to verify promotion to a private buffer and clean retirement after 600 quiet frames back in Market.Tested: Windows 11 (build 26200), AMD Ryzen AI 7 350 + AMD Radeon 860M (8 CUs, RDNA 3.5 iGPU, Adrenalin 26.10.1),
1600x1000,handheld_profile=1,sharpness=80,vsync=0,amd_anti-lag_2=1,RX_VK_PRECOMPILE=1,>= 12.5 spost-load settle:Market_Childfountain-first route (67% render scale1024x5763 interleaved rounds,100% render scale1536x8643 interleaved rounds) +RX_VK_PASS_TIMING=2(67% render scale,1024x576):vk: simulated turf: prog 3de6d86ec7e6720elogged: the game's own; span dropped from0.422 msto< 0.093 ms(absent from top 25 spans; totalm dispatch4.515 -> 4.060 ms,-10.1%).HyruleField_Childin-bounds grassy-field orbit (castle-gate,100% render scale,1382x864at16:10, 3 interleaved rounds): all simulated turf bindings logged: the game's own(peak~54,000 / 143,360blades),0VK_ERROR_DEVICE_LOST,0exit/transition frames (min >= 17.67 ms), and GPU time + Median FPS beatmainacross all 3 rounds.Market -> Hyrule Field -> Kokiri Forest,67% render scale,1024x576):0VK_ERROR_DEVICE_LOST,0write-back timeouts, turf rendered cleanly in Hyrule Field.RX_VK_SHOT_FX=1(sharpness=80) visual inspection: scene lighting, geometry, and textures matchmaincleanly with zero artifacts.main @ 0e32bc10withdev.py envllvm-mingw+RX_CPM):tests/test_sim_turf_stock_passthrough.py(new; testsRX_VK_SIM_TURF_ADAPTIVE=1and=0, promotion/retirement, andRX_VK_SSBO_STRETCH/RX_VK_SSBO_WIDEguards): FAIL onmain(753fb5af), PASS on this branch (3641cc34).--strictsuite (test_sim_turf*,test_switch_table,test_vk_braces,test_utf8_paths,test_doc_anchors): 9 passed, 0 failed, 0 skipped.python -I -B tests/run_all.py --changed forge/main: 181 passed, 7 failed, 6 skipped — all 7 failures are pre-existing Windows-onlymainfailures documented in#2304(test_sampler_admission,test_pipeline_state_computes,test_crash_dialog,test_dev_packs,test_saveload_warm_cache,test_dev_ab,test_input_movie).Still to test:
Turf densityhigh enough to exceed7/8 * stock): confirm seamless promotion to private buffer, zero flicker, and retirement back to game buffer after 600 quiet frames in Market (by hand).Measurements
Verdict: Clear, repeatable win across GPU-bound zones and pass timing: eliminates the
0.422 msturf mirror-copy span (m dispatch-10.1%); at GPU-bound Market100% render scale(1536x864) cuts GPU time-0.47 ms(-2.9%), steady VRAM-80 MB, and lifts Median/Mean FPS+1.0%; and at GPU-bound Hyrule Field100% render scale(1382x864at16:10) cuts GPU time-0.50 ms(-2.5%) and lifts Median FPS+0.3%(+0.13 FPS) with non-overlapping 3-round ranges in both zones. Near-CPU-bound Market67% render scale(1024x576) and overlapping secondary metrics show no measurable difference (within run-to-run variance).Setup: Windows 11, AMD Ryzen AI 7 350 + Radeon 860M (Adrenalin 26.10.1),
1600x1000,handheld_profile=1,sharpness=80,vsync=0,amd_anti-lag_2=1,RX_VK_PRECOMPILE=1, symmetric pre-warmed shader/pipeline caches (>= 12.5 ssettle): fountain-firstMarket_Childroute (1536x864at100% render scale,1024x576at67% render scale) and in-boundsHyruleField_Childgrassy-field orbit (1382x864at100% render scale16:10). Measured standalone directly againstmain @ 753fb5af; rebased cleanly ontomain @ 0e32bc10(3641cc34— none of the 8 intervening commits touchvk_draw.cppor simulated turf, and#2232's 4-core Auto threshold does not change behavior on this 8-core CPU, so the numbers hold unchanged). Multi-round values aremedian [min, max]across 3 interleaved rounds.Where it makes a difference (GPU-bound Market & Hyrule Field at
100% render scale, and pass timing):main @ 753fb5af3641cc343de6d86ec7e6720espan (Market67% render scale,1024x576,PASS_TIMING=2)0.422 ms< 0.093 ms(out of top 25)>= -0.329 ms(>= -78%)m dispatch(Market67% render scale,1024x576,PASS_TIMING=2)4.515 ms4.060 ms-0.455 ms(-10.1%)100% render scale(1536x864) GPU time (3 rounds)16.49 [16.48, 16.67] ms16.02 [15.95, 16.35] ms-0.47 ms(-2.9%) — all 3 rounds faster100% render scale(1536x864) steady VRAM (3 rounds)3245 [3213, 3277] MB3165 [3133, 3197] MB-80 MB(~28 MB buffers + VMA block rounding) — all 3 rounds lower100% render scale(1536x864) Median FPS (3 rounds)45.11 [44.92, 45.29]45.56 [45.55, 46.02]+0.45 FPS(+1.0%) — all 3 rounds faster100% render scale(1536x864) Mean FPS (3 rounds)44.79 [44.25, 44.98]45.25 [45.13, 45.61]+0.46 FPS(+1.0%) — all 3 rounds faster100% render scale(1382x864) GPU time (3 rounds)19.88 [19.59, 21.24] ms19.38 [19.31, 19.56] ms-0.50 ms(-2.5%) — all 3 rounds faster100% render scale(1382x864) Median FPS (3 rounds)38.70 [37.59, 38.70]38.83 [38.73, 38.93]+0.13 FPS(+0.3%) — all 3 rounds faster100% render scale(1382x864) Median frame ms (3 rounds)25.84 [25.84, 26.61] ms25.75 [25.69, 25.82] ms-0.09 ms(-0.3%) — all 3 rounds fasterWhere it does NOT make a difference (within run-to-run variance):
main @ 753fb5af3641cc34100% render scale(1536x864) 1% Low FPS (3 rounds)32.89 [31.36, 33.52]33.36 [33.22, 34.04]100% render scale(1536x864)>= 33.3 msframes (3 rounds)7 [3, 10]4 [4, 6]67% render scale(1024x576) Median FPS (3 rounds, CPU-bound)54.38 [53.59, 54.50]54.87 [53.11, 55.01]67% render scale(1024x576) Mean FPS (3 rounds, CPU-bound)53.68 [52.66, 54.00]54.21 [52.06, 54.28]67% render scale(1024x576) 1% Low FPS (3 rounds, CPU-bound)38.95 [36.86, 39.10]38.55 [34.00, 39.41]67% render scale(1024x576) GPU time (3 rounds, CPU-bound)12.82 [12.73, 12.99] ms12.41 [12.39, 13.02] ms67% render scale(1024x576) steady VRAM (3 rounds)3085 [3053, 3149] MB3037 [2973, 3133] MB100% render scale(1382x864) Mean FPS (3 rounds)38.56 [37.02, 38.66]38.64 [38.58, 38.80]100% render scale(1382x864) 1% Low FPS (3 rounds)29.03 [23.29, 29.37]29.56 [28.11, 30.01]100% render scale(1382x864)>= 33.3 msframes (3 rounds)16 [16, 45]15 [12, 30]100% render scale(1382x864)gpu_wait_ms(3 rounds)4.04 [3.66, 5.71] ms4.64 [3.91, 4.64] ms100% render scale(1382x864) steady VRAM (3 rounds)2858 [2858, 2986] MB2810 [2810, 3098] MBRisks
7/8 * stock, the list promotes from the game's buffer to a newly allocated private buffer on the next creator dispatch; after 600 quiet frames, it retires the private buffer (reaped after the GPU timeline passes it) and returns to the game's buffer.tests/test_sim_turf_stock_passthrough.pyverifies the full lifecycle including retirement and destruction.#2174regression: Because the producer writes directly into the game's own buffer on every frame at stock capacity, the game's buffer remains continuously marked written (never introducing a sudden first write-back when entering Hyrule Field).RX_VK_SIM_TURF_ADAPTIVE=0immediately restores stock-sized private buffers for A/B comparison; a revert is also clean. No save/options/cache format changes. Players notice nothing in their files.Checklist
Ready for review
main; the title is a Conventional Commit.mise run testpasses (tests/run_all.py --changed forge/mainon Windows: 181 passed, 7 pre-existing Windows-onlymainfailures named in#2304:test_sampler_admission,test_pipeline_state_computes,test_crash_dialog,test_dev_packs,test_saveload_warm_cache,test_dev_ab,test_input_movie; targeted--strictsuite 9/9 passed).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 (test_sim_turf_floor.py,test_sim_turf_capacity_policy.py,test_sim_turf_pools.py, andtest_switch_table.pyall pass).Assisted-by:/Co-Authored-By:trailers.Ready to merge
main, measured again or a comment says why the numbers still hold.Tested in game: Windows 11, AMD Radeon 860M (Adrenalin 26.10.1): Market (1536x864 and 1024x576), Hyrule Field (1382x864), and 3-zone tour (Market -> Hyrule Field -> Kokiri Forest). Confirmed 3de6d86ec7e6720e uses the game buffer, span dropped from 0.422 ms to <0.093 ms, GPU time -0.47 ms (-2.9%) in Market and -0.50 ms (-2.5%) in Hyrule Field, -80 MB VRAM, 0 device_lost, clean visual parity.
Possibly related, for context:
WIP: perf(vk): cut Market 1536x864 GPU time 2.9% (-80 MB VRAM, +1.0% FPS) across GPUs by keeping stock simulated turf on game buffersto perf(vk): cut Market 1536x864 GPU time 2.9% (-80 MB VRAM, +1.0% FPS) across GPUs by keeping stock simulated turf on game buffers@Jer9 only members of
BigBeanscan start the farm.One of them can approve this request by reacting 👍 to it or to this comment.This request was for2e87213, and the PR has changed since (3641cc3), so a 👍 no longer approves it. Comment@Beanstalkagain to ask for the new commit.2e8721320e3641cc3488@Jer9 only members of
BigBeanscan start the farm. One of them can approve this request by reacting 👍 to it or to this comment.@Beanstalk Please test on Windows NVIDIA and Linux RADV (head
3641cc34): walk Market -> Hyrule Field (normal/stock turf density) at 100% render scale. Confirmvk: simulated turf: prog 3de6d86ec7e6720elogs: the game's owninlongshot_log.txt, and compare GPU time, VRAM, and FPS vsmain.@Jer9 only members of
BigBeanscan start the farm. One of them can approve this request by reacting 👍 to it or to this comment.@ -571,2 +577,3 @@const uint32_t before = g.policy.capacity(), target = g.policy.target();if (sim_turf_resize(g, pool, salign))if (!want_private) {sim_turf_retire(g);i saw the test mocks high turf demand and then 600 quiet frames. did you also try max turf in hyrule field and go back to market in game? im curious if it flickers or hitches when it switches back.
Haven't tried max turf in-game yet — all my live runs so far were at default turf density (peaking around
~54,000 / 143,360blades in Hyrule Field), so I listed dense turf promotion/demotion under Still to test and only exercised the grow -> 600-quiet-frame shrink path intests/test_sim_turf_stock_passthrough.py.On paper it shouldn't flicker or hitch when switching back:
sim_turf_retire(g)only runs on the creator dispatch right before the producer shader writes that frame's grass list, so the creator and every subsequent reader in that frame bind the game's buffer together (and while the private buffer was active,sim_turf_sample_demand()was already mirroring the stock window back into the game's buffer each frame). Meanwhile, the old private buffer stays alive insim_turf_retireduntilvk_timeline_completed()passesvk_retirement_value(), so any earlier frame still in flight on the GPU finishes cleanly.create_device_bufferlikemain), anddestroy_buffer()happens asynchronously on a later reap once the GPU is done with it.If you do try max turf in Hyrule Field and head back to Market, let me know if you spot any flicker or hitching on the switch!
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.