perf(vk): add RX_VK_MESH_FAST mesh program, bank, and UBO descriptor fast paths #2946
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
3 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
MagicBeanDev/Longshot!2946
Loading…
Reference in a new issue
No description provided.
Delete branch "siantm/Longshot:perf/vk-mesh-prog-bank-ubo"
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
On Switch 2 / NVN2, Task (
6), Mesh (7), and UBO-heavy world draws repeated shader selection, driver-bank fills, program flag scans, null-sampler verification loops, and barrier stat locking on every draw. This PR removes those bottlenecks behindRX_VK_MESH_FAST(default1, wired toHOS_AB), reducingdraw_ms(-0.185 ms,-2.37%) andwait_gpu_ms(-0.186 ms,-7.88%) to improve Market frame time by -0.182 ms (+1.34% FPS, 95% CI+0.87%to+1.84%).What this changes:
gpu/vk/vk_shader.cpp): Extendsanswer_stage_maskto stages1, 6, 7and routesProgramKind::Meshthrough the TLSprog_fast+pickslookup viaprogram_pickinstead of taking globalshader_muand re-checkingcodes_of/mesh_key/still_validon every mesh draw.BankCachenarrowing (gpu/vk/vk_draw.cpp): Keysuniform_range()BankCacheons.tex_gen[bank_stage]forc2(index == 2) ands.ssbo_gen[bank_stage]forc0withinkPointerTable(n <= 0x880) instead of invalidating on every UBO bind (s.bind_gen), keepingc.sizecurrent onFC_BANK_SAMEhits.Programflags & widenedubo_delta_safe(gpu/vk/vk_shader.h,vk_shader.cpp,vk_progcache.cpp,vk_draw.cpp): Precomputesstage_maskandcached_flags(kProgUboDeltaSafe,kProgUboDeltaSafeGlobal,kProgWritesSsbo) once at translation/load, allowinginfo.native_global_boundsshaders onto theubo_deltafast path when all SSBOs are inc0and all textures inc2.gpu/vk/draw_key.h,vk_draw.cpp,vk_replay.cpp): Unrolls/hoists branches with single-resizeinwords_appendandwords_same_store, tracksDescWriter::has_null_samplersobind_descriptorsskips the null-sampler scan when false, and skips unconditionalst_barrier_flags_mulocking inNOP_BARRIERunlesscall_count_on()is enabled.Key files to read first: vk_shader.h, vk_shader.cpp, vk_draw.cpp, draw_key.h, and vk_replay.cpp.
Testing
Tested: Windows 11, NVIDIA GeForce RTX 4060 (driver
621.40,591.74/ Vulkan 1.4):HOS_AB=RX_VK_MESH_FAST=0,3,0sessions inmarket(1280x720, 50% internal res, V-Sync off, uncappedHOS_FPS_MAX=1000,89paired periods) viadev.py ab: 0 crashes, 0 visual/Vulkan errors, and consistent speedup in all 3 runs (AB1..AB3).python -X utf8 -I tests/test_vk_mesh_fast.py: passed.python -X utf8 -I tests/test_draw_side_effects.py: passed.python -X utf8 -I tests/test_hos_ab.py: passed.python -X utf8 -I tests/test_bank_gen.py: passed.python -X utf8 -I tests/test_pick_tex_gen.py: passed.mise run testsuite on this branch (test_vk_mesh_fast.py,test_draw_side_effects.py,test_hos_ab.py,test_bank_gen.py,test_pick_tex_gen.pyran here directly). Pre-existing baseline failures onmain @ 4908cc6da(test_switch_table.py,test_tex_desc_memo.py,test_recording_admission.py, and pre-existingspirv_pack::Storefixture errors invk_progcachetests) are unrelated to this PR.Still to test:
@Beanstalk: Linux (RADV) smoke and shader/mesh draw parity run onmain, plus GPU/scene sweep (Hyrule Field, Fire Temple, Kokiri Forest) to confirm no visual or performance regression outside RTX 4060 Market.@Beanstalk: CI full test suite (mise run test) on Linux and Windows.Measurements
Verdict: faster: +1.34% FPS (
+1.36%mean frame time reduction when enabled; -0.182 ms per frame, 95% CI+0.87%to+1.84%,89paired periods across 3 in-runHOS_ABsessions;1% Low +1.98%,0.1% Low +0.24%).Setup: Windows 11, NVIDIA GeForce RTX 4060 (driver
621.40); Market, child (crowded) (window1280x720); quality preset Custom, resolution 50% (768x432), output res1280x720, frame generation Off, vsync Off; uncapped (HOS_FPS_MAX=1000); the frame trace (RX_VK_FRAME_TRACE=1), 90 s each after a warm-up until no frame waited for a pipeline, 3 runs,RX_VK_MESH_FASTflipped every 3 s within each run (HOS_AB=RX_VK_MESH_FAST=0,3,0).Baseline: both columns are one build,
v3.2.0-186-gd693b9dd0(notmain):RX_VK_MESH_FAST=0(side 1) againstRX_VK_MESH_FASTunset /1(side 0) on it.d693b9dd0d693b9dd0perf.py ab)draw_ms(programs/desc/cmds)1.301/2.930/2.377)1.245/2.860/2.325)wait_gpu_msRisks
info.native_global_boundsshader readsc3+UBO values to index dynamic SSBO/texture addresses outsidec0/c2, or if a Task/Meshc0table reads> 0x880entries withoutn > 0x880, descriptor updates could go stale; guarded by explicitProgramFastFlagschecks (c0only, no written SSBOs, no image descriptors, textures inc2,n <= 0x880).RX_VK_MESH_FAST=0disables every optimization in this PR at runtime, or reverting the commit removes it completely.longshot_options.ini, and shader/pipeline caches are unaffected.Checklist
Ready for review
main; the title is a Conventional Commit.mise run testpasses (any failure that also fails onmainis named).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.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 RTX 4060 Market 3x90s HOS_AB=RX_VK_MESH_FAST=0,3,0 (89 periods): +1.34% FPS (74.7 vs 73.7), -0.182 ms (95% CI +0.87% to +1.84%), +1.98% 1% Low FPS, -2.37% draw_ms
Possibly related, for context:
#2946: Deck measurement
Measurements on a Steam Deck LCD (RADV VANGOGH, Mesa 26.2.0-devel, Vulkan 1.4, AC power, GPU clock pinned at 1600 MHz), 2026-12-01.
Build: base
87045899plus a dev-pack ofmain(4908cc6d) with #2932, #2946 and #2952 merged (merge heade72783d7), renderer and host both from that tree. Settings per arm: 1280x800 output, the game's own upscaler, quality preset Custom/0, shadows 1, V-Sync off, no fps cap, no overlays. Route: slot 05 save, Hyrule Field anchor, 1,200 presents of warm-up, then three passes of walking, panning, full-stick turns and a walk-and-circle. Play window is 30-97 % of each frame trace. Arms are separate launches, interleaved in time, identical except for the switch set.HOS_ABis not usable on this platform yet: the A/B thread does not start (ab: the A/B's thread did not start). Root cause: glibc refuses a thread stack smaller than the executable's static TLS block plus a guard page and a rest stack, and this host binary's block is 61,936 bytes, so the 64 KiBCreateThreadrequest inhost/hos_ab.cis refused with EINVAL. A fix (aCreateThreadstack under the executable's static TLS block) is in review as #2971, so these numbers come from separate launches rather than the in-run A/B.50 % render, stack of the three switches, 5 runs on against 4 off:
Median ranges are separated (worst on-run 27.07 ms, best off-run 27.10 ms); fps ranges overlap. Run-to-run spread on this machine is 3-12 %, larger than the effect, so the medians are the firmer statement. p is an exact permutation test over run labels (all 126 splits of nine runs; 0.008 is the floor of that test).
Phase medians, two paired samples (ms, on against off):
desc_ms2.81/2.78 against 3.18 (-11.6 %/-12.6 %),programs_ms1.45/1.44 against 1.62 (-10.5 %/-11.1 %),draw_ms10.13/9.94 against 10.76 (-5.9 %/-7.6 %),cmds_ms4.37/4.24 against 4.45 (-1.8 %/-4.7 %),game_msunchanged in one sample and -6.0 % in the other (noise).100 % render (the Deck's default), 3 runs a side: fps 31.34 against 30.67 (+2.21 %, p 0.15), median frame 31.12 against 31.34 ms (-0.22 ms, p 0.25). The host phases move the same way (
desc_ms-7.5 to -10.4 %,programs_ms-8.9 to -12.1 %,draw_ms-2.9 to -6.8 %, render -1.8 to -2.7 %), butgpu_wait_msrises by 0.91 to 1.01 ms (+36 to +42 %) in all three pairs, so at native resolution the host saving is largely spent waiting for the GPU. That is expected for a GPU-bound frame and is not a fault of the change.Limits: one scene, one save, one machine; Deck LCD only; the switches were moved together, so this table does not separate the three PRs from each other. Raw traces are on my Deck and archived locally, available on request.
For this PR specifically: #2946's share of the gain is visible by subtraction. A build of #2932 + #2952 + #2958 (without #2946, the largest set that merges without editing anyone's code) gives
desc_ms-5.1 to -8.5 % anddraw_ms-2.6 to -5.2 % at 50 %, againstdesc_ms-11.6 to -12.6 % here. The mesh bank and UBO descriptor fast paths therefore carry a good half of the descriptor win, which is the largest single phase saving we measured on this hardware.One conflict note for the queue: #2946 does not merge cleanly on top of #2954 (
vk_internal.h,vk_progcache.cpp,vk_shader.cpp) or #2958 (vk_draw.cpp). Those two merge with each other and with #2952's test file alone; #2946 and #2952 merge cleanly. If both families are wanted, one of them needs a rebase.One caveat to add to the table above, from a second pass over the same traces: the size of the effect depends on where the trace is windowed. Trimming to 30-97 % gives +2.6 % fps and -2.9 % median frame; 20-90 % gives +3.7 % and -2.8 %; 40-99 % gives +1.4 % and -2.0 %. The direction is the same in all three, and I did not choose a window after the fact, but treat 2-3 % as a range rather than a point.
Two further limits worth naming: the arms ran in blocks (switch set A, then B) rather than strictly alternating, so thermal or cache drift cannot be separated from the switch set with these runs; and with nine runs the smallest attainable permutation p is 0.008, which is exactly the median's value, so that figure is the floor of the test rather than a precise probability.
Thank you @omgitsgela for the thorough Steam Deck LCD (RADV) measurements (+2.57% FPS, -2.89% median frame,
desc_ms-11.6%..-12.6%,programs_ms-10.5%..-11.1%) and the detailed breakdown across windowing choices and the GPU-bound 100% render case. We are ready to rebase cleanly onto whichever merge order maintainers choose with #2954 and #2958.View command line instructions
Manual merge helper
Use this merge commit message when completing the merge manually.
Checkout
From your project repository, check out a new branch and test the changes.