WIP: perf(vk): a dispatch after only the game's dispatches waits in the compute stage, or not at all when they share no memory (RX_VK_DISPATCH_BARRIER) #2072
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
4 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
MagicBeanDev/Longshot!2072
Loading…
Reference in a new issue
No description provided.
Delete branch "GummiNaomi/Longshot:perf/narrow-barriers"
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
A compute dispatch that follows only the game's own dispatches no longer waits behind a full barrier. Until now every
dispatch recorded after other work got a full barrier (every stage, every access): about 70-90 a frame in the Market and
Hyrule Field, between the game's compute chains. The console's GPU runs one dispatch after the other, so the order matters
where a dispatch reads what the one before wrote; a full barrier also waits for the graphics stages, and on RADV flushes
and invalidates the colour and depth caches with their metadata every time.
Now such a dispatch waits for the ones before it in the compute stage only, and, by default, not at all when its bindings
and theirs share no memory that one of them writes and neither reaches memory its bindings don't show (global memory,
storage buffer tables, texel buffers). The first command after them that is not one of them (a pass, a copy, the
renderer's own dispatch, an upscaler library's work) gets the full barrier first, so everything after them waits for
them, and for what came before them, as it did.
On an RTX 4070 SUPER the GPU time a frame drops by 0.03-0.04 ms (about 0.4 %); the frame rate doesn't move on this
CPU-bound PC. The reason to take it is mainly AMD (RADV, the Steam Deck), where each full barrier between dispatches costs
more; that is still to be measured (Still to test).
Read first:
gpu/vk/vk_draw.cppdispatch()(the decision, above itfootprint_conflictandRX_VK_DISPATCH_BARRIER'scomment),
gpu/vk/vk_work.h(dispatch_order_owed),gpu/vk/vk_texture.cpp(full_barrier,dispatch_order_pay).Testing
Tested: Windows 11, RTX 4070 SUPER (NVIDIA 617.42), Ryzen 9 9950X3D (SMT off), 32 GB, in the game (output 2560x1440,
presented off-screen at 1920x1080: the control tool's test profile):
and on this PR: the same things drawn (lighting, shadows, grass, fog, fireflies, the people); only Link's pose and the
time of day differ;
main against this PR (2 a side a scene); 0 errors in every log;
those for programs that reach memory their bindings don't show, none for memory in common); in Hyrule Field 27 and 63;
no owed full barrier ever needed, since every stretch of the game's dispatches ended at a full barrier of its own;
9dd41326: the six checks above pass, it builds, and a 60 s run standing in the Market has 0 errors and the same counts (29.8 dispatches a frame with no barrier, 32.1 in the compute stage, 14.8 full barriers recorded, 0 owed); its frame rate is not comparable (the PC's own game started beside it);tests/test_dispatch_barrier.py(new) passes (LLVM clang 22.1, Windows). Of the game-free checks that read a changedfile, three compiled
full_barrier,texture_begin_recordingorvk_work.h's counts with fixtures that lacked the newstate (
test_astc_upload_chunking,test_dump_readback,test_inline_write_order): updated here, they pass, withtest_hos_abandtest_switch_table. The other checks that fail on this PC fail the same way on main (112, among themtests/test_pass_barrier.py, whose macro shapes predate the recorder).Still to test:
slower, since the Deck's frame waits on its GPU (Test Farm: @Beanstalk steamdeck, stand in Castle Town's market 3
minutes with HOS_AB=RX_VK_DISPATCH_BARRIER=0,3,60 and RX_VK_FRAME_TRACE=1, then scripts/perf.py ab on the trace)
linux amd, the same A/B)
screenshot tour on main and on this PR)
Measurements
Verdict: GPU time a frame 0.03-0.06 ms lower (0.4-0.7 %) on an RTX 4070 SUPER, in two scenes and by two methods; the frame rate is within the spread (this PC is CPU-bound there). The compute-stage barrier alone (
=1) shows nothing on NVIDIA; leaving barriers out (=2) is what moves it. The gain this is for is on RADV (the Steam Deck, AMD), still to be measured.Setup: Windows 11, RTX 4070 SUPER (NVIDIA 617.42), Ryzen 9 9950X3D SMT off; headless, output 2560x1440 (the control
tool's test profile, presented off-screen at 1920x1080), uncapped
(
HOS_FPS_MAX=1000),RX_VK_TEX_AHEAD=1 RX_VK_ASTC_BC_ALL=1 RX_VK_IMAGE_BLOCK_MB=32 RX_VK_LOAD=create RX_VK_BC_LAYERS=8;the repository's kokiri-start save, the debug teleport, standing. GPU time: each recording's begin/end timestamps
(
vk: GPU time X ms a frame, pass timing off).Main against this PR, interleaved (main, PR, main, PR), the same exe with only the renderer swapped, standing
150 s; the log's lines every 120 presents from the 16th after the scene's draws are reached:
f1f2dc5bThe switch alternated within one run (0, 2, 0, 1, 3 s each after 100 s, about 20 rounds; GPU time summed by the value
each recording was made with), each value against the two 0s around it, 95 % interval by a bootstrap of rounds:
=0(main's full barriers)=2(the default)=1=0against=0An earlier version leaving out the same barriers measured -0.044 ms (-0.057 to -0.031) in the Market and -0.034 ms
(-0.053 to -0.014) in Hyrule Field, where leaving out every barrier between dispatches would be worth -0.05 and -0.14 ms:
about half of them stay, for programs whose memory the bindings don't show. 48d91d2a is this PR but for the log line's
count (the head changes only that count). Rebased since onto
9dd41326: main's 14 commits in between (input, thewebsite, the camera, the BC encoder's copy, a spin switch, saves, the working-set floor, the FPS counter's footer, the
output-resolution preview, the mesh-draw scan's table, the lift's float bodies, pipeline lists) touch nothing this changes
or measures; the head was built and run again on it (Tested).
Flags and settings
RX_VK_DISPATCH_BARRIERRisks
What could break: a dispatch that reads or writes memory its bindings don't show while being marked as known would race
with a neighbour: a flicker or a wrong value in a compute result (shadows, the people's animation, the culling lists).
The footprint is unknown for every way a program reaches memory past its bindings that the shader translator reports
(global memory, storage buffer tables, texel buffers, networks), and indirect grids always wait.
RX_VK_DISPATCH_BARRIER=1keeps the order between all dispatches (compute stage only);
=0is main's behaviour. Nothing changes in saves, optionsor caches.
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.mainand here, for a change that shows on screen.Assisted-by:/Co-Authored-By:trailers.Ready to merge
main, measured again or a comment says why the numbers still hold.🤖 Generated with Claude Code
Possibly related, for context:
@Beanstalk steamdeck: stand in Castle Town's market 3 minutes at handheld settings with HOS_AB=RX_VK_DISPATCH_BARRIER=0,3,60 and RX_VK_FRAME_TRACE=1, then scripts/perf.py ab on the trace. Side 1 is main's full barriers between dispatches; if this helps the Deck, side 1 is slower. Screenshots from both sides welcome (no flicker expected).
Beanstalk test farm · ⛔ can't be tested as asked
Commit
49fea38· approved by GummiNaomi (untrusted) · dashboardNot run: the farm can't test this as asked, so nothing is built or run:
⚠️ Note: The alternative uses the handheld profile on both targets because scenarios cannot be restricted to individual targets.
⚠️ Note: Two still screenshots can catch persistent visual differences but cannot rule out intermittent flicker.
What it could test instead: As an alternative, Steam Deck and Linux AMD testers would stand in the Market for three minutes per side, using the handheld profile, while GPU time and frame times are measured. Screenshots would be compared with main and the PR's dispatch-statistics line collected when available. A crash, a GPU-time or frame-time regression over 10%, or a screenshot difference over the threshold would fail the plan; it takes about 17 minutes per tester.
A member of
BigBeanscan comment@Beanstalk <new words>to ask for something else, or@Beanstalk test it anywayto run the plan regardless.@Beanstalk linux amd: the same A/B, standing in Castle Town's market 3 minutes with HOS_AB=RX_VK_DISPATCH_BARRIER=0,3,60 and RX_VK_FRAME_TRACE=1, then scripts/perf.py ab on the trace, plus the log's "dispatches after only the game's dispatches" line. Expecting side 1 (main's full barriers) no faster, and no flicker.
Steam Deck result: I ran this PR on a Steam Deck OLED standing in the Market, both with the switch flipped every 3 s inside the same runs and as main against the PR in separate runs. Neither showed a difference the Deck can resolve: the in-run comparison came out at +0.2 % fps with a 95 % interval of -1.6 % to +1.3 %, and main against the PR was within the runs' spread. No errors in any log; the PR's own line shows the barriers being left out as intended (about 27 dispatches a frame with no barrier and 31 waiting only in the compute stage in the Market).
1. In-run, the switch flipped every 3 s (
HOS_AB=RX_VK_DISPATCH_BARRIER=0,3,0), 3 runs of 120 sRX_VK_DISPATCH_BARRIERunset)RX_VK_DISPATCH_BARRIER=0Per run (side 0 = the PR's default, side 1 =
=0): 26.1 / 26.0 fps (-0.40 %), 25.6 / 25.6 (+0.14 %), 25.8 / 26.0 (+0.85 %).dev.py ab's verdict: no difference shown.2. Main against the PR, separate runs, 2 interleaved pairs of 60 s
9dd4132649fea386dev.py ab's verdict: no difference shown, -2.0 % within the runs' spread (A 26.2 to 26.5, B 25.2 to 26.5). The 50 ms frames vary this much between starts on this Deck on the same build (a main-only run earlier in the same session ranged 15 to 122), and the in-run comparison above, which is not exposed to that start-to-start variation, had slightly fewer of them with the PR's default, so I read neither the -2.0 % nor the long frames as a regression.The PR's line (B runs, a frame in the Market):
dispatches after only the game's dispatches (RX_VK_DISPATCH_BARRIER=2): 27.4 with no barrier (no written memory in common), 31.1 waited in the compute stage (31.1 reach memory their bindings do not show, 0.0 share written memory), 7.8 a full barrier recorded. NoFATAL, device-lost,VK_ERRORor validation line in any of the 7 logs; every run exited normally.Hardware: Steam Deck OLED, SteamOS 3.9.5, RADV VANGOGH, Mesa 26.2.0-devel, GPU clock manual 1600 MHz, headless.
Settings: Minimum, Render 50 % (640x400), output 1280x800, uncapped, V-Sync and frame generation off.
Game data: complete (the dump, with the three damaged textures replaced).
Built: main @
9dd41326and this PR @49fea386(its 3 commits, which sit on main9dd41326), x86-64-v3, shaders prepared on the Deck; only the renderer differs.Measured:
dev.py abstanding in the Market (the project's tool, with a local change to compare two prebuilt runtimes, since the Deck does not build).Limits: few runs, one Deck, headless, one standing scene. In the Market on this Deck the frame waits on the replay's CPU work as much as on the GPU (GPU time about 20 ms of a 38 ms frame), so a GPU-side saving may not show in fps here; a GPU-bound scene might. Headless runs can't judge flicker or other visual faults.
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.