perf(vk): a draw that has to wait for its pipeline gets one at once, not the full build #1946
Open
j64esatxzdrhfg wants to merge 1 commit from
j64esatxzdrhfg/perf/pipeline-stutter into main
pull from: j64esatxzdrhfg/perf/pipeline-stutter
merge into: MagicBeanDev:main
MagicBeanDev:main
MagicBeanDev:github/pr/2893
MagicBeanDev:github/pr/2890
MagicBeanDev:github/pr/2887
MagicBeanDev:github/pr/2878
MagicBeanDev:github/pr/2875
MagicBeanDev:github/pr/2874
MagicBeanDev:github/pr/2873
MagicBeanDev:github/pr/2871
MagicBeanDev:github/pr/2756
MagicBeanDev:github/pr/2897
MagicBeanDev:github/pr/2896
MagicBeanDev:github/pr/2718
MagicBeanDev:github/pr/2842
MagicBeanDev:github/pr/2691
MagicBeanDev:github/pr/2895
MagicBeanDev:github/pr/2743
MagicBeanDev:github/pr/2765
MagicBeanDev:github/pr/2708
MagicBeanDev:github/pr/2732
MagicBeanDev:github/pr/2755
MagicBeanDev:github/pr/2817
MagicBeanDev:github/pr/2876
MagicBeanDev:release-please--branches--main
MagicBeanDev:release-please--branches--main--release-notes
MagicBeanDev:github/pr/2778
MagicBeanDev:github/pr/2888
MagicBeanDev:github/pr/2866
MagicBeanDev:github/pr/2877
MagicBeanDev:github/pr/2800
MagicBeanDev:github/pr/2829
MagicBeanDev:github/pr/2850
MagicBeanDev:github/pr/2889
MagicBeanDev:github/pr/2882
MagicBeanDev:github/pr/2860
MagicBeanDev:github/pr/2849
MagicBeanDev:github/pr/2886
MagicBeanDev:github/pr/2794
MagicBeanDev:github/pr/2840
MagicBeanDev:github/pr/2830
MagicBeanDev:github/pr/2834
MagicBeanDev:github/pr/2719
MagicBeanDev:github/pr/2742
MagicBeanDev:github/pr/2741
MagicBeanDev:github/pr/2820
MagicBeanDev:github/pr/2771
MagicBeanDev:github/pr/2859
MagicBeanDev:github/pr/2858
MagicBeanDev:github/pr/2823
MagicBeanDev:github/pr/2757
MagicBeanDev:github/pr/2769
MagicBeanDev:github/pr/2844
MagicBeanDev:github/pr/2843
MagicBeanDev:github/pr/2673
MagicBeanDev:github/pr/2855
MagicBeanDev:github/pr/2739
MagicBeanDev:github/pr/2807
MagicBeanDev:github/pr/2851
MagicBeanDev:github/pr/2789
MagicBeanDev:github/pr/2814
MagicBeanDev:github/pr/2818
MagicBeanDev:github/pr/2774
MagicBeanDev:github/pr/2772
MagicBeanDev:github/pr/2750
MagicBeanDev:github/pr/2786
MagicBeanDev:github/pr/2785
MagicBeanDev:github/pr/2782
MagicBeanDev:github/pr/2779
MagicBeanDev:github/pr/2775
MagicBeanDev:github/pr/2706
MagicBeanDev:github/pr/2766
MagicBeanDev:github/pr/2747
MagicBeanDev:github/pr/2759
MagicBeanDev:github/pr/2745
MagicBeanDev:github/pr/2740
MagicBeanDev:github/pr/2733
MagicBeanDev:github/pr/2725
MagicBeanDev:github/pr/2727
MagicBeanDev:github/pr/2728
MagicBeanDev:github/pr/2729
MagicBeanDev:github/pr/2721
MagicBeanDev:github/pr/2722
MagicBeanDev:github/pr/2715
MagicBeanDev:github/pr/2714
MagicBeanDev:github/pr/2707
MagicBeanDev:github/pr/2703
MagicBeanDev:github/pr/2705
MagicBeanDev:github/pr/2697
MagicBeanDev:github/pr/2679
MagicBeanDev:github/pr/2676
MagicBeanDev:github/pr/2669
MagicBeanDev:docs/what-hookshot-connects-to
MagicBeanDev:fix/hdr-encode-test
MagicBeanDev:fix/main-tests
MagicBeanDev:fix/play-cache-files
MagicBeanDev:perf/game-barrier-order
MagicBeanDev:feat/heap-lazy
MagicBeanDev:feat/texture-detail
MagicBeanDev:perf/astc-opaque-bc1
MagicBeanDev:fix/fs-dir-lock
MagicBeanDev:fix/framegen-native-kept
MagicBeanDev:fix/update-no-downgrade
MagicBeanDev:port/k10-gcn-f16-mirrors
MagicBeanDev:fix/framegen-mult-cap
MagicBeanDev:chore/release-as-2.1.1
MagicBeanDev:perf/pcache-load-switch
MagicBeanDev:fix/prepare-progress-log
MagicBeanDev:fix/update-closes-stale-game
MagicBeanDev:fix/hdr-scaled-sampled
MagicBeanDev:perf/first-start-preset
MagicBeanDev:perf/zero-upload
MagicBeanDev:fix/vcore-escape-2s
MagicBeanDev:test/fake-gh-atomic
MagicBeanDev:perf/batch-idle-flush
MagicBeanDev:test/finish-stub-a
MagicBeanDev:chore/record-2.1.0
MagicBeanDev:fix/main-red-tests
MagicBeanDev:fix/test-display-startup-driver-cache
MagicBeanDev:feat/mesh-shader-mode
MagicBeanDev:fix/menu-probes-at-startup
MagicBeanDev:fix/fps-counter-classic
MagicBeanDev:fix/test-log-batch-flake
MagicBeanDev:fix/narrow-screen-hud
MagicBeanDev:ci/prereleases
MagicBeanDev:release/v2.0.15
MagicBeanDev:hotfix/v2.0.15
MagicBeanDev:fix/present-ahead-replay
MagicBeanDev:release/v2.0.13
MagicBeanDev:fix/bracket-paths-2013
MagicBeanDev:fix/hdr-overlays-2013
MagicBeanDev:fix/fps-counter-scale-2013
MagicBeanDev:fix/stick-seen-at-rest
MagicBeanDev:hotfix/menu-fits-screen
MagicBeanDev:fix/f1-always-opens-menu
MagicBeanDev:fix/ini-keep-lines
MagicBeanDev:claude/cranky-pike-7cf247
MagicBeanDev:perf/texture-answer-flat
MagicBeanDev:fix/stamp-test-modules
MagicBeanDev:fix/appimage-fonts
MagicBeanDev:fix/display-awake
MagicBeanDev:release/v2.0.12
MagicBeanDev:fix/discord-windows
MagicBeanDev:rc/v2.0.12-tests
MagicBeanDev:fix/dlss-keep-feature
MagicBeanDev:rc/v2.0.12
MagicBeanDev:button-icons
No reviewers
Labels
Clear labels
accessibility
Barrier affecting people with disabilities
autorelease: pending
autorelease: tagged
bug
Something isn't working
dependencies
Pull requests that update a dependency file
documentation
Improvements or additions to documentation
duplicate
This issue or pull request already exists
enhancement
New feature or request
github_actions
Pull requests that update GitHub Actions code
good first issue
Good for newcomers
help wanted
Extra attention is needed
invalid
This doesn't seem right
question
Further information is requested
testing wanted
wontfix
This will not be worked on
No labels
accessibility
autorelease: pending
autorelease: tagged
bug
dependencies
documentation
duplicate
enhancement
github_actions
good first issue
help wanted
invalid
question
testing wanted
wontfix
Milestone
Clear milestone
No items
No milestone
Assignees
Clear assignees
No assignees
2 participants
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".
No due date set.
Dependencies
No dependencies set
Reference
MagicBeanDev/Hookshot!1946
Loading…
Reference in a new issue
No description provided.
Delete branch "j64esatxzdrhfg/perf/pipeline-stutter"
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?
Effects seen for the first time stutter. A draw into a target made that frame can't be left out, so it waits for the worker's full optimized pipeline build: about 65 ms each on an RTX 5080, with 236 new pipelines in a 6-minute session.
What changed
vk_draw.cppquick_pipeline: such a draw first asks for the pipeline without compiling (FAIL_ON_PIPELINE_COMPILE_REQUIRED), so a cached one comes back optimized at once. Otherwise it builds one withDISABLE_OPTIMIZATION, into none of our caches. That pipeline stands in like a fast-linked one until the queued full build replaces it; a stand-in that loses the race is destroyed. The frame log counts it as a short wait.RX_VK_QUICK_WAIT=0restores the old wait.targets_persistent: a target cleared whole this frame (Texture::cleared_frame, set byclear_color_targetwith every channel and byclear_depth_stencil's depth, over the whole target) kept no earlier picture, the same as one made this frame. OoT clears its scene's colour and depth every frame, so on a cold pipeline cache the field's draws were left out over the cleared depth: a white wash on the first field load (thanks @hckrman101). Such a draw now gets its quick pipeline.RX_VK_PIPE_SKIP=0still forces waiting.vk_shader.cpp: translation jobs go ahead of queued pipeline builds (urgent), keeping main's new failure callback (#1874).vk_jobs.cpp: 6 workers with 16+ hardware threads (2–4 below, unchanged);RX_VK_WORKERS=<n>.test_quick_pipeline.pycompilesquick_pipelinebeside a stand-in driver, andtargets_persistentwith the cleared cases. It covers cached, cold, unbuildable and a racing full build, plus nopipelineCreationCacheControlandRX_VK_QUICK_WAIT=0.test_gpl_library_cachefollows the cache line.Testing: RTX 5080 + Ryzen 7 9800X3D. An earlier form on v2.0.13 played smooth through new areas and effects; the version before the cleared-target rule ran in a build of main (
8c92fe3) with this series, with Asynchronous and warm caches. The cleared-target rule and the new default are not yet run in game; game-free tests pass.Not tested: a cold pipeline cache with Wait where needed (no numbers for stand-ins in a heavy scene yet), fewer cores, AMD/Intel, Linux.
Screenshot
🤖 Generated with Claude Code
Nice. Quick pipelines for the draws that have to wait is a clear win. A few things from our side, since we've been chasing first-load problems on Linux and an RTX 3090:
quick_pipelinefor each wait, and leave out the rest once the budget is spent. Lichii uses a bounded wait for the same reason (itsnative_async_draws=Bounded, 8 ms default). We're working on this on top of your branch and will post numbers (brightness, draws left out, worst frame, 1% low) for Bounded vs Asynchronous vs Wait where needed on the cold field load.We can test it on Linux (NVIDIA) here if useful.
Data point for this PR on AMD: on an RX 7800 XT / 5800X3D, a 112-minute v2.0.12 session logged 19 "a draw waited 59-306 ms for a pipeline" lines, and 53 of 79 slow submits were dominated by
draw. I hand-portedquick_pipeline(without the menu part) onto v2.0.12: boots and runs a scripted 150 s route at 59.7 fps mean with no regression, but that route never produced a first-seen effect, so I have not yet seen the stand-in path used. Details in #995. I will report back once I have a real-play log.@hckrman101 Thanks for the careful look, and for the Linux / RTX 3090 numbers.
targets_persistent. A target cleared whole this frame (every colour channel, or the depth, over the whole target) now counts like one made this frame (Texture::cleared_frame, set inclear_color_target/clear_depth_stencil). So under Wait where needed, the field's draws on a cold cache get their quick pipeline instead of being left out over the cleared depth.test_quick_pipeline.pynow also compilestargets_persistentand checks the cases.Given the white wash on cold loads, I've made Wait where needed the default again and kept Asynchronous as the opt-in. With the cleared-target rule above, Wait where needed should avoid both the first-time stutter (quick pipelines) and the wash. Bounded could take over as the default once it's in.
PipeEntry::pipelinefails, i.e. when the full build (or another thread's stand-in) is already in the entry, so no command buffer can hold it. A stand-in that won is never destroyed; the full build only replaces it in the entry, as with fast-linked pipelines, so draws recorded with it stay valid.a waiting draw's pipeline built without the driver's optimizer in … ms (n so far, … on average)). If your cold-load runs log those lines, they would answer it better than mine; otherwise I can measure a cold run with Wait where needed.RX_VK_WORKERScovers tuning either way.Rebased onto current main.
@lucasmazzoni45-del Thanks for the AMD numbers and for hand-porting it. A real-play log with the
built without the driver's optimizerlines would be great to see.Linux run with NVIDIA's driver: no regression, but nothing for the change to act on on this route. RTX 4090, NVIDIA 615.78.08, i9-13900K, Arch Linux. I merged 27d9136b onto main
bdfe09c(the conflicts invk_menu.cpp,vk_menu.handreadme.mdare main's new Mesh shaders row and V-Sync text next to your row; I kept both sides). Headless, defaults, the menu row at its default (Asynchronous).Both builds started from a fresh folder: the pipeline caches and the driver's shader cache deleted, then
--prepare-shaders. Then a scripted first visit: Kokiri Forest from a save, then the debug teleports to Hyrule Field, Kakariko, the Market, the Lost Woods and Death Mountain Trail, about 22 s each with a camera turn. The counts are fromRX_VK_FRAME_TRACE. Load average 1-5.bdfe09c(two runs)After the prepare, no draw on this route waited for a pipeline even on main, so the quick build never ran. The other differences are within what two runs of main gave each other. The left-out draws fall in Death Mountain Trail (7-8) and the Lost Woods (1), in one run of main and in the PR's run. Both builds ran without a fault.
So on Linux with NVIDIA I have nothing to show for or against it. It would need a route with cold pipelines (no prepare, or areas the prepare doesn't cover) to show the wait it removes. Not tested: AMD, Intel, Windows, a folder without the prepare.
This run was the earlier head 27d9136b; the head has since moved to 98d6e23d, which I have not run.
@mooki000 Thanks for the careful Linux/NVIDIA run and the table. That fits: after
--prepare-shadersno draw on the route had to wait, so there was nothing for the quick build to do. Your run was of 27d9136; the head since has the cleared-target rule (a draw into a target cleared this frame no longer counts as left to the last frame's picture) and Wait where needed as the default, which is where a cold route (no prepare, or areas it doesn't cover) would show the difference. Rebased onto current main.The core idea is good, and
quick_pipelineis careful. The no-compile probe goes topcache; the unoptimized stand-in stays out ofpcacheand out ofpcache_built_since_save, and the driver keys its own cache on the flags. A stand-in that loses the compare-and-swap was never recorded, so destroying it is safe. Nothing insidebuild_graphicsruns a queued job, so the thread-localquick_buildcan't leak into another entry's full build. I compiled and rantest_quick_pipeline,test_gpl_library_cacheand the 13 menu checks at this head: all pass. Note that the PR's own test workflows haven't run yet: they are waiting for a maintainer's approval (action_required).blocking (merge conflict, and not only in text): the PR conflicts with main in
gpu/vk/vk_draw.cpp,vk_menu.cpp,vk_menu.h,readme.mdanddocs/development.md. Thevk_draw.cpppart is a change of meaning. #1573 has landed: on main a draw always waits for its translation (except withRX_VK_PIPE_SKIP=2), and a pending pipeline is left out only when no stage writes global memory, storage buffers or images. Here (gpu/vk/vk_draw.cpp:6265),may_skip = !always_wait && (opts.async_pipelines != 0 || targets_persistent(at))predates that. If it is carried over as it is, Asynchronous would drop memory-writing draws again, which is exactly the bug #1573 fixed. When you rebase, keep main's memory-write check over both modes (Asynchronous may only widen thetargets_persistenthalf), and send the wait in main'sif (!pe->ready...)block throughquick_pipeline. The row's hint and the readme ("Never waits") then need to say that a draw still waits for its shader translation and for a pipeline that writes memory.should fix (the default changes for every player, untested in game): with the cleared-target rule (
:3850, set at:4404and:4459), a draw into OoT's scene colour and depth targets, which are cleared every frame, no longer counts as persistent. On a cold pipeline that draw now builds a stand-in on the replay thread, where main left it out. That fixes the white wash, but it trades it for serial unoptimized compiles in the frame: hckrman101 measured 456-625 draws left out per frame on a cold field load, and if even a few dozen distinct pipelines are behind them, that is a long frame. Unoptimized build times also vary much more across vendors (AMD's proprietary compiler, Intel) than on a 5080. The description says the new default and the cleared-target rule haven't been run in game, and mooki000's run had nothing cold for the change to act on. Before this becomes the default, please post one cold-cache run with Wait where needed (no--prepare-shaders, or an area the prepare doesn't cover): how many stand-ins were built, their average and worst ms from the new log line, and the worst frame time compared with main.should fix (scope, and stale against main): the worker-count change (
gpu/vk/vk_jobs.cpp:80,RX_VK_WORKERS) is a separate tuning decision from the quick pipeline, and CONTRIBUTING.md asks for one topic per PR. It also now goes against main. #2323 addedusable_cpus()(the process's affinity mask), because sizing pools fromhardware_concurrency()ran 24 threads on 12 usable CPUs and made translation 40% slower (gpu/vk/vk_internal.h, thehalf_cpuscomment). #2440 already proposes the same change on its own, so the simplest fix is to drop it here and settle it there, based onusable_cpus(), ideally with a number from an 8-core/16-thread CPU under load, as hckrman101 asked. Making translation jobs urgent (vk_shader.cpp) belongs with this change and is fine to keep.There hasn't been a push since my review: the head is still
aeb130ed, committed before it. So the points there all still apply, and I'll only list them:may_skip(vk_draw.cpp:6265) would let Asynchronous drop memory-writing draws again, which #1573 fixed. Keep main's memory-write check over both modes.RX_VK_WORKERS/ worker-count change (vk_jobs.cpp:80) and settle it in #2440, sized fromusable_cpus()(#2323).quick_pipelineisn't on main in any form, so this isn't superseded. It just needs the rebase and that one cold-cache run.This now conflicts with main in
docs/development.md,gpu/vk/vk_draw.cpp,gpu/vk/vk_menu.cpp,gpu/vk/vk_menu.h,readme.md,tests/test_gpl_library_cache.py. Could you merge main into the branch (or rebase) when you get a chance? I'll take another look once it's up to date.I rebased this onto current main and applied the review points on a branch in my fork: fix/pr1946-quick-pipeline.
may_skipkeeps main's #1573 memory-write check in both modes; Asynchronous only widens thetargets_persistenthalf. The wait in the!pe->readyblock goes throughquick_pipeline.RX_VK_WORKERS/ worker-count change is dropped (left to #2440). Urgent translation jobs invk_shader.cppare kept.tests/test_draw_side_effects.pyneeded stubs foroptsandquick_pipeline; added, plus 20 Asynchronous cases.tests/run_all.pyon Windows (llvm-mingw, .NET 8): 426 passed, 4 failed, 66 skipped. The 4 failures (test_fpx_sticky,test_input_background,test_spawn_emit,nx2/test_nup_paths) fail the same way on main here.Not done: the cold-cache in-game run asked for in the review (stand-in count, avg/worst ms, worst frame vs main) is still missing. Nothing was run in game. Feel free to cherry-pick from the branch.
🤖 Generated with Claude Code
Update to my branch fix/pr1946-quick-pipeline: the quick stand-in is now default-on for AMD only (vendor 0x1002), so NVIDIA and Intel keep main's behaviour.
RX_VK_QUICK_WAIT(set, non-empty) still decides either way. It is never used for task/mesh programs (the unoptimized mesh build resets the GPU on RADV, issue 1000); those wait for the full build as before. Readme, docs, the menu hint andtests/test_quick_pipeline.py(vendor/env/mesh cases in separate processes) follow. The cleared-target rule and the urgent translation jobs are unchanged and still apply to every GPU. Measured only on AMD by the earlier logs; NVIDIA/Intel are untested.🤖 Generated with Claude Code
Windows with an NVIDIA card, areas with no recorded pipelines: with Asynchronous, about a fifth as many draws were left out as on main, with no waits. With Wait where needed, few draws were left out, but it waited 58 s over the route.
RTX 4070 Ti SUPER, NVIDIA 621.14, Ryzen 7 9800X3D, Windows 11. I tested 98d6e23 against its base
d7a7306, one run each. The current headaeb130edis the same code rebased, with one menu hint reworded.Setup: a scripted 9-minute drive as child with 5 teleports (Hyrule Field, Kakariko, Market, Lost Woods, Gerudo Valley).
RX_VK_NO_STATE_LIST=1andRX_VK_NO_PREDICT=1were set, so neither the shipped list nor prediction prepared those areas. Before each measured run the game booted once to the title with the driver cache kept, so start-up was warm and the areas were not. The counts are summed from the frame log's stat lines.d7a7306