WIP: fix(build): bake the shaders with the back end's own prepare, opt-in at the build #2474
Draft
hckrman101 wants to merge 1 commit from
hckrman101/fix/offline-bake into main
pull from: hckrman101/fix/offline-bake
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!2474
Loading…
Reference in a new issue
No description provided.
Delete branch "hckrman101/fix/offline-bake"
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 main (after #2323: the program cache split into vk_progcache.cpp). Follows up #1707 and #1954.
Why the #1707 bake was refused
The game only reads a program cache (
hookshot_programs.bin) whose stamp is its own. That stamp covers two things:HOOKSHOT_SHADER_STAMPfromnx2/build.py), andtranslator_stampinvk_shader.cpp): mesh shaders or the fallback, the subgrouplanes and the stages pinned to 32, the cooperative-matrix layout measured on the device, the depth mode, the C++ library's
struct layouts, and the stamped
RX_VK_*/EDEN_*switches.nx2/bake_dsis a hand-made copy of the translator and the record writer. It can't compute the GPU half without the GPU. It hadalso fallen behind main: no
canonical_answer, no compute local memory from the control section, and the old record head(
kind/answers/workgroup/shared; main also writes the questions and five mesh-fallback words). The game refused its banks on thestamp, and with a matching stamp it would have misread the records. Any copy will drift again the next time the translator or the
record format changes.
What changes
The bake now runs the back end's own code, so it writes the same stamp and the same bytes as the game.
hookshot_vkexportsmkwvk_bake(folder, into, workers). It creates the device the game would, then runsprepare_runwithtranslation only: no pipelines, no pipeline cache, no state list. It works in a folder of its own:
game_module_pathtakesthat folder through
game_folder_override. If the game folder already holds a cache with the current stamp, the bake skipsthe work and prints
@@bake current.nx2/bake.py liveloads the build's back end with ctypes and calls it at idle priority (SCHED_IDLE on Linux, IDLE_PRIORITY_CLASSon Windows). On Linux it also ends with the build. The
live_*helpers stage<game>/.hookshot_bake: the shader list ishard-linked, the settings and the back end are copied. Once the build is done they move the cache, its index and the prepare's
record into the game folder, with the record last.
nx2/make_game.pyhandles both builders' paths withstart_bake/finish_bake. Before the lift it makes the shader list andthe back end (
RX_VK_ONLY, objects shared with the full build; the AppImage's prebuilt one is used as is). It then starts thebake beside the lift and the compile, and installs the result before
--prepare-shaders. If the bake fails or finds nothing todo, the prepare translates as before.
The prepare's record gets a new
warmedvalue,kWarmedBaked. When the game's prepare (the build's--prepare-shaders, or afirst start) sees it:
seed_compute'skept_whole), but their pipelines are still built in theprepare's worker pool, as before;
So a bank that was cut short, deleted, or made for another GPU or translator (a different stamp) falls back to translating, as
without a bake.
Off by default:
HOOKSHOT_BAKE=1turns it on, and only when the prepare runs too. The measurements below show it does notshorten build plus first start on this PC.
Measured
RTX 3090, a 12-thread half of a Ryzen 9 7900X (oot-status timing CPUs, checked per CPU), cold build (no object cache, no lift
cache), empty driver cache, same source for both runs:
vk: program cache …: 46666 program keys kept, 6592008 KB, thenvk: the shaders were translated at the build (baked)…, thenvk: prepared 38809 shader programs (0 new, …) in 5.4 s. Withoutthe bake: 242.7 s.
~6,900 CPU-seconds of driver pipeline compiles (compute ~10k, predicted ~56k, listed ~25k). The build cost as much as the bake
saved. Even at idle priority, the bake slowed the mostly single-threaded lift through the SMT siblings of its cores. Building
the back end first added 23 s.
build could save (~150 s at best).
game's precompile with that process's
mkw_vk_pipelines.bin, took 415 s, the same as cold. On this driver the pipeline cachefile only points into the driver's disk cache. The driver picks the disk cache file by the executable's name: a copy of
python named
hookshotshared the game's file, while the game run from another folder and python under its own name did notshare it. A pipeline bake would therefore have to run as an executable named
hookshot.Verified
Same bytes. All 52,464 baked records match records the game's own cold prepare wrote (same .so, same GPU), compared with
the cache's record layout and Shader::Info's container members zeroed. The only differences are uninitialized struct padding
bytes, checked against clang's record layout. The game's own run has 938 more records: the state list's texture variants,
which the prepare still makes after a bake.
Fallback. The game's
--prepare-shaderson a baked folder, run up to its translation line:46666 program keys kept,baked,0 new;18383 program keys kept,28283 new. The rest was translated and the total is the same46,666;
0 program keys kept,46666 new, 9925 compute variants;RX_VK_MARKERS=1): the cache is made again from nothing,46666 new, and the record isnot taken as baked.
Game-free tests:
tests/test_bake_live.pybuilds the record helpers and thebakeddecision fromvk_draw.cpp, andprogram_cache_file_stampfromvk_progcache.cpp, then checks:is not taken for a bake;
mkwvk_bake, andmake_game's switches and fallbacks.tests/run_all.py bake prepare make_game program_cache shader_censuspasses, excepttest_bake_portability.py, whichneeds
zstandard(missing on this PC, unrelated).test_prepared_stamps.pyandtest_prepare_cache_save.pypass with theprepare's code as changed here.
Not tested
screenshots. The programs the game loads are byte-identical to the ones it makes itself, so no difference is expected.
make_game.py, and the bake usesIDLE_PRIORITY_CLASSandctypeswith an ANSI path.On Windows,
nx2/bake.pyencodes the folder path asmbcs(the ANSI code page), which breaks the UTF-8 path rule (tests/test_utf8_paths.py) and fails for user folders with non-ASCII names. Also, by the description's own timing there's no gain (1512 s vs 1521 s), so is it worth merging even opt-in?BAKE.mdat the repo root probably belongs underdocs/.