feat(vk): load shader programs when the game creates them #2760
Closed
github-sync
wants to merge 15 commits from
github/pr/2760 into main
pull from: github/pr/2760
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
1 participant
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!2760
Loading…
Reference in a new issue
No description provided.
Delete branch "github/pr/2760"
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?
On by default where the GPU has mesh shaders; today's behaviour elsewhere.
RX_VK_LOAD=startorcreateoverrides. Known limits are listed under "Not tested" and "Follow-ups".Today every listed program and pipeline is made ready before the title, whatever the session goes on to draw: about 18,000 programs and 25,000 pipelines, 4 seconds and close to 8 GB of host heap on an RTX 3090. This loads a program's stored variants and its listed pipelines when the game creates the program, on background workers, from the caches only. Everything is still compiled in the prepare step; nothing is translated or compiled in play.
What is in it
Compute programs in the shipped pipeline list (two commits): the list can name compute programs, kept ready before the title, with a contributed list of 233 keys (keys and hashes only).
One-variant compute load: a compute program's first dispatch reads the code of the variant it runs, not of every stored variant of its key.
RX_VK_LOAD_ALL_VARIANTS=1is the old way.Program life log and census (
RX_VK_LOG_PROGRAM_LIFE=1) and a create call from the game to the renderer (renderer interface version 19 to 20).Refactor: one place makes a compute pipeline's create info and asks the caches for it.
Load at create (
RX_VK_LOAD=create|start): at start only an index is read (the notes by position; nothing big is loaded). At a create call a job reads the program's variants, makes modules and layouts, and asks the pipeline caches for its listed pipelines. A first draw or dispatch that arrives before its job runs the job itself or waits for it. Jobs publish only finished programs. Only programs a list names are loaded at create (RX_VK_LOAD_UNLISTED=1loads the rest). On a GPU without mesh shaders the mesh-fallback programs and their listed pipelines are still made before the title.Bounded first start: the first start after a prepare builds each listed pipeline into the pipeline cache once and lets it go, then loads at create.
Compute pipelines by module identifier (
VK_EXT_shader_module_identifier): a compute variant seen before gets its pipeline at the create call without its code being read or a module made. Identifiers are learned into a side file as play goes, so existing folders need no new prepare for it.The default and a safety net:
RX_VK_LOAD=createforces). Measured where it works: 10-25 ms in all over a tour, longest 2-7 ms; where it does not: 2.5-4.7 s, longest 0.7-1.3 s.Cost to players: one more prepare after updating (the renderer interface version and a struct size are part of the translator stamp); about 70 s on the test PC with a warm driver cache.
Measured: RTX 3090
Linux, NVIDIA 620.70, 2560x1440. Full tour of five area visits (Kokiri, Kakariko, Market, Field, Kokiri; walking and a pause menu in each; 11 minutes), from the same played-install state unless said. The game's own swap was 0 and memory pressure 0.16-0.39 % in every run. Every create run: 0 translations, 0 compiles, 0 draws or dispatches left out, 0 pipelines missing from a cache.
Area changes (teleport to +30 s, three rounds; fps, then frames over 33 / 50 / 100 ms):
Level with start here (the 41.1 fps start run had the highest memory pressure of the set). One worker and a throttle that parks loads during texture uploads showed no gain and are not in the PR. No slow upload in a change window overlapped a load job. On Windows (RTX 4070 SUPER, the first head of this PR, see the comment below) the Castle Town to field change was a little slower in create mode in both pairs (45-47 against 48 fps); that change has only 33-42 load jobs here, so it is not explained yet.
With no switch set, this head on the RTX 3090 logs "programs are loaded when the game makes them (create): the default where the GPU has mesh shaders"; 0 left out, 0 compiled, first-use loads 14.1 ms in all, no marker written.
First start after a prepare:
One-variant compute load on its own (two pairs, 144 programs, nothing kept ready): first-dispatch total 1,127 to 752 ms and 1,268 to 538 ms; worst 115 to 51 and 86 to 19 ms. Those four runs were on a swapping PC: the direction holds, the sizes are rough.
Measured: RX 580 (RADV, no mesh shaders, 16 GB PC)
Kokiri, Field, Dodongo's Cavern, Jabu-Jabu, Bottom of the Well. This PC is short of memory in both modes (several GB in swap), so times there are partly swap.
startby default, and what the safety net is for. Neither compute identifiers (all 1,051 made that way) nor raising a worker's priority while a draw waits (tried, not in the PR) changed it: 2,557 ms, longest 884 ms. The long jobs are compute keys with 16-64 variants at the save's load; most likely scattered reads of a 7 GB file that PC cannot keep in memory (not proven).VK_EXT_shader_module_identifier47 ms and 0.20 MB read instead of 54.6 MB. On the RTX 3090 identifiers leave the driver's time unchanged (99th percentile about 4.5 ms) and halve the heap.Tried and dropped
VK_KHR_pipeline_binary: 159 compute pipelines at 1.2-1.7 ms median against 0.4-0.6 with the pipeline cache, 2.2 MB a pipeline on NVIDIA.Tests
New:
test_program_life,test_program_load_wait,test_program_cache_one_variant,test_pipeline_state_computes,test_warm_bounded,test_module_ids,test_load_default. Full suite locally on Linux, one commit before the head: 470 passed; 3 fail here for missing local modules or an unrelated host test (CI passed them on the first push). CI passes on Windows and Linux at the previous head.Not tested
Follow-ups (not in this PR)
VK_EXT_shader_module_identifierfor graphics programs (on RADV making the module is most of a load: 159 compute pipelines 47 ms against about 1,000 ms).Touches the pipeline lookup, notes, precompile, draw and dispatch paths in
vk_draw.cpp; #2649 changes the cache file read and save in the same file (different functions).Tested #2760 on Windows 11 (one of the gaps listed), RTX 4070 SUPER 12 GB, NVIDIA 617.42, Ryzen 9 9950X3D, 32 GB, DLAA 2560x1440, default settings, unattended, nothing else running. Build of the PR's head
8b975536; a warm-up start first (the first start after the prepare behaves as start), thenRX_VK_LOAD=startagainstcreate, alternating, in one session. Peak working set from the process, frames fromRX_VK_FRAME_TRACE.In create mode: 0 translations, 0 compiles, 0 pipeline waits and 0 draws left out in every run; the census showed no first use needing work. Loads at create: 6,992-8,804 a run, median 0.60-0.79 ms, 99th percentile 3.8-5.9 ms, worst 31-68 ms, 1.4-1.9 GB read.
So on Windows: 3-5 GB less RAM at the peak, no shader work in play. Frame times are within the run-to-run spread in the walk. The area change was a little worse in create mode in both pairs (45.2-46.9 against 48.1-48.5 fps, more frames over 33 ms), so that may be worth a look: possibly the loads for the new area's programs competing with the area's own loading on two workers. Kokiri was better, but that's one pair. Not checked: flashes (no capture comparison), AMD/Intel.
feat(vk): load shader programs when the game creates them (RX_VK_LOAD=create)to feat(vk): load shader programs when the game creates themA heads-up now that this is in: on main,
tests/test_program_cache_one_variant.pyno longer compiles, so the Python source checks are red for every pull request that merges with main. Main's own runs keep being cancelled by the next merge, which is probably why no completed red run has shown it yet.Checked on plain main
f5c9acc1(Linux, Clang 23.1; the same from86a9cda2on):Cause: two changes that each passed alone met on main. #1630 (
136452cd, the zstd program cache) landed just before this one and added helpers and a global thatprogram_cache_readand its neighbours now use; this pull request's fixture cuts those functions out ofvk_progcache.cppwithout them.I have a fix for the fixture in work (it cuts the real new helpers in as it does the others, zstd off, no product change) and will open it within the hour, after its Windows run. If you would rather do it yourself, say so and I will drop mine.
The other red check on main,
tests/test_readme_menu_rows.py(Skip opening has no README line), is what #2857 fixes.