perf(prepare): the segment heap, so the driver's compiles run side by side on Windows #2895
Open
github-sync
wants to merge 2 commits from
github/pr/2895 into main
pull from: github/pr/2895
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/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!2895
Loading…
Reference in a new issue
No description provided.
Delete branch "github/pr/2895"
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?
A first start (or the Builder's shader preparation) on AMD's Windows driver spends hours compiling, and adding CPU threads did not make it faster: the driver's compiler threads queue on one lock in Windows' default process heap. This switches the game to Windows' segment heap and, when it is in use, gives the preparation's first part a worker on every CPU.
Why
On a Ryzen 5 5600 (6 cores, 12 threads) with an RX 6700 XT, a cold
--prepare-shadersrun of main spent 1,466 s in its first part (prepare_run: every program translated, and AMD's compile of 9,691 compute variants), most of it in the driver. More workers did not help:amdvlk64.dll -> RtlAllocateHeap / RtlFreeHeap -> RtlEnterCriticalSection -> NtWaitForAlertByThreadId: the NT heap's lock.VkAllocationCallbacksdid not help: the driver does not use them for its compiler's memory.What changed
nx2/win_manifest.py: the game's manifest asks for<heapType>SegmentHeap</heapType>(Windows 10 2004 and newer; older Windows ignores it).gpu/vk/prepare_workers.h(new),vk_progcache.cppprepare_cpus():prepare_run's pool before the game ishalf_cpus()as before, unless the process heap really is the segment heap (read from the heap's header, so a Windows that ignored the manifest, or Linux, keeps the old count). Then every usable CPU gets a worker, one more for each 768 MB of free physical memory past 4 GB (each worker past half the CPUs took 0.4-0.5 GB more at the peak). The log says which:vk: preparation: 12 workers for the shader programs (12 CPUs usable; the segment heap: ...).RX_VK_PREPARE_BACKGROUND), Linux, and every other pool.Measured
Windows 11 (26200), Ryzen 5 5600, 16 GB, RX 6700 XT, AMD 26.10.1. Cold runs: empty Hookshot caches, and a new folder path each run, which gives the AMD driver an empty cache too (a new path got a new file in
%LOCALAPPDATA%\AMD\VkCacheeach time).--prepare-shaders, no window.Same build (this branch,
v2.1.0-rc.3-299-gdae19300): its own exe against a copy of the same exe whose manifest has theheapTypeline taken out:vk: prepared ... in)Earlier, on main
51da0464with the manifest patched into a copy of the exe: first part 1,466 s (NT heap, 6 workers) against 904 s (segment heap, 12 workers); predicted pipelines in the first 300 s of a fresh process 1,495 (NT heap) against 2,358 (segment heap, after its first part in the same process).In play (main's renderer and exe, the same exe with and without the manifest line; the field bench save: Hyrule Field by day, 2560x1440 output with AMD FSR 4, standing, 150 s each, four alternated pairs): fps median, NT heap / segment heap: 50.8 / 50.1, 51.2 / 50.7, 49.5 / 51.3, 47.3 / 49.2 (pair differences -1.4%, -1.0%, +3.6%, +4.0%: run-to-run noise, no direction). GPU time 13.0-13.6 ms and replay draw time 9.7-10.9 ms move with the fps in both; peak private memory 21.1-21.4 GB in both. (Three earlier runs, both kinds among them, were all at 45 fps while the PC was busy, and are left out.)
Not measured: NVIDIA and Intel on Windows (they get the heap, and on the segment heap the same worker count change), a full end-to-end preparation (hours on this PC either way), Windows 10.
Overlap
prepare_run/predict_run/precompile_run. On the NT heap, more workers ran slower here, so those counts are worth measuring again on the segment heap.See #2696, #2505.
Tests
tests/test_prepare_workers.py(new): compilesprepare_workers.h: the NT heap's count, one worker per 768 MB past the reserve, the usable CPUs and 32 as limits, the heap signatures; and checksprepare_runand the manifest use them.tests/test_utf8_paths.py: the manifest also hasheapType SegmentHeap; its probe exe still starts from a folder named in Japanese and emoji with the new manifest (UTF-8 code page as before).tests/test_prepare_cpus.py:prepare_runis sized byprepare_cpus, which starts fromhalf_cpusandusable_cpus.tests/run_all.pyon Windows (llvm-mingw clang, the Vulkan headers from the builder's CPM cache): 469 passed, 11 failed, 41 skipped; the same 11 fail on maindae19300alone on this PC (builder, portable-archive and readme checks, andtest_program_cache_one_variant.py, which does not compile #1630'sdisk_zstdhere).🤖 Generated with Claude Code