feat(vk): cap compiler pools at physical cores #2414
Open
polaco1782 wants to merge 3 commits from
polaco1782/fix/physical-core-shader-workers into main
pull from: polaco1782/fix/physical-core-shader-workers
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!2414
Loading…
Reference in a new issue
No description provided.
Delete branch "polaco1782/fix/physical-core-shader-workers"
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?
Concurrent driver pipeline compiles can consume several GiB more memory when every SMT thread gets a worker. This proposes a physical-core upper bound to reduce that concurrent work, accepting longer preparation; the available measurements do not establish an OOM fix or a speedup.
Originally rebuilt from clean upstream
main(3e95ca68), including merged #2323; now refreshed through upstream463eab1fin merge commit7689539d. This remains a compiler-pool policy proposal awaiting the maintainer's direction and additional hardware measurements.Behavior
compile_worker_count(previous_budget)caps the existing pool budget by the detected physical cores. It preserves #2323'susable_cpus()/half_cpus()budgets and every smaller stage ceiling.predict_runandprecompile_run: they previously used up to 64 usable logical CPUs. The half-CPU translation, state-list and library pools usually already equal or fall below the physical count. They can change under restricted affinity or an unusual topology. The shared background pool is capped too.RelationProcessorCorerecords across groups, including hybrid cores, and honors process affinity on single-group systems. Windows 10 multi-group process restrictions and cgroup CPU quotas remain limitations, as on main.vk: CPU topology not readable, using N workersis logged once. A genuine single physical core still gives one worker.RX_VK_COMPILE_LOGICAL=1bypasses the cap for comparison and keeps the existing affinity-aware budgets. This limits application worker counts; it does not pin workers or constrain threads inside the driver.vk_shader.cppnorvk_progcache.cpp/.his modified relative to main. The translator stamp and cache format are unchanged by this PR, so it adds no full-game retranslation on top of main.Historical measurements
These are the original pipeline-only budget experiment, not a benchmark of this revised branch or a complete cold first start. They predate #2323 and the newer quarantine/watchdog changes. Shader translation and gameplay were not timed. The old experiment also changed the cache-reader budget; this revision deliberately leaves cache readers unchanged.
Ryzen 7 5700X (8C/16T), 32 GB; RX 7800 XT; Fedora 44, Linux 7.1.13, RADV/Mesa 26.1.8. Host log:
v2.1.0-rc.3-53-g49f75dc-dirty (source 52a1c006). Identical installed renderer SHA-256:0fec25a6e7ac5a965bb38e6e02585b64f278abfd6ff4bb7ff1cd21c4db97a71b.Four independent cold
--prepare-shaderstrials, each followed by a warm run, in 8/16/16/8 order. Cold trials had empty application pipeline and private Mesa caches, an already translated bank of 46,607 program keys and warmed filesystem inputs. Seed/state lists were omitted. Every trial selected 12,752 variants and built 16,037 graphics plus 1,218 compute pipelines. No game files, caches or translated programs are shared here.A local
LD_PRELOADshim changed the renderer'sget_nprocsresult (itshardware_concurrencyquery) to 8 or 16, preserving 16 for the driver and other modules. SMT stayed enabled; affinity was unchanged. Wall time is monotonic; process CPU time and peak RSS usewait4. Background desktop load and CPU boost were uncontrolled.Cold means: 266.561 vs 255.688 s (+4.25% with eight workers). Mean peak RSS: 6.56 vs 9.65 GiB (32% lower). Mean CPU use: 793.5% vs 1483.0% (100% is one logical CPU). All eight processes succeeded with equal workload counts and no reported compiler fault or device loss. Original input hashes were unchanged. An incomplete full-translation pilot was excluded.
#2323 also measured NVIDIA/Linux prediction at 302 s on six workers vs 271 s on twelve, about 11% longer at the physical-core count. The resource/time tradeoff varies by driver. A physical-core count is not a memory budget: a 16-core PC with 16 GB can still run out of memory.
Current branch validation
463eab1fin7689539deeb6b5e750a53ea519ab336de2a152ac. The only merge conflict was adjacent rows indocs/tested-configurations.md; both were retained. The compiler-pool feature diff remains unchanged: 12 files, +479/-17, with no cache-reader feature changes.scanffixture correction is inherited from upstream rather than added as a separate patch.test_seed_reader.py,test_program_cache_reader.py,test_control.py,test_hookshot_ctl.py, andtest_mem_gate_children.py. This is not a full local test pass. Skips include missing compiler/header/tool dependencies and platform/GPU/game requirements; no native Windows or game test was performed in this cloud run.Validation of the earlier revision
d8f4a173. The failure istest_make_game_cache.py: its blocked subprocess encounters the local PGO-profile compiler probe; reproduced against unmodified upstream, andnx2/make_game.pyis identical on the final base.3e95ca68(the intervening VRAM-compaction fix): all eight focused topology, affinity, queue, driver-stall, cache-stamp, startup and VRAM checks passed. Queue regressions also passed with native affinity restricted to one CPU.hookshot_vk.so. No new gameplay or current-branch performance run was performed.44443d99: Windows Builder package/setup and the native llvm-mingw Vulkan back end compiled and linked. Release publication was skipped.Still needed before merge
The tested-configurations table now has one historical summary row linking here. The separate measurement document and PR self-entry in the worklist have been removed from the proposed diff.
Thanks for the careful measurements, and for keeping an A/B switch. The detector itself reads right to me: on Windows it counts
RelationProcessorCorerecords across groups (so hybrid E-cores count once each and >64-LP machines aren't truncated), applies the affinity mask on single-group systems, and the record walk is bounds-checked; on Linuxsched_getaffinitycovers taskset/cpusets/offline CPUs and the first CPU incore_cpus_listis a global id, so multi-package boxes are fine. A CPU quota (docker --cpus, cgroupcpu.max) isn't seen, but main doesn't see it either, so that's not a regression.What I'd like settled before this goes in:
The failure fallback is a cliff. Any detection failure gives one worker for everything: predict and precompile then build ~17,000 pipelines on a single thread (on your 5700X that's roughly 8x the 266 s), and the in-play job pool drops below its old minimum of 2. On Linux one allowed CPU without a readable topology file is enough (sandboxes that mask
/sys, some container runtimes). Nothing logs that detection failed either: the worker-count lines just say 1. I'd fall back to the old budget (hardware_concurrency(), or half of it) and logvk: CPU topology not readable, using N workersonce.What this actually changes, and what it costs. On SMT CPUs
state_list_prepare,warm_librariesandprepare_runalready rancpus / 2, which is the physical count, and on non-SMT CPUscpus / 2is still below the core count. So in practice the behaviour change ispredict_run+precompile_run(plus the cache reader and the job pool at the edges). It'd help to say that in the description. On those two, both measurements we have say the cap makes first start slower: your RADV run is +4.25%, and #2323's NVIDIA/Linux run (12 usable LPs, 6 cores) measured the prediction at 302 s on 6 threads vs 271 s on 12, about +11%, which is why that draft goes the other way (usable_cpus(), one thread per usable logical CPU). The win here is peak RSS (9.65 -> 6.56 GiB), which matters for the OOM reports in #995/#1593, but a core count is only a proxy for memory: a 16C/32T PC with 16 GB still gets 16 workers, while a 32 GB PC that was fine pays the extra time. Could you get numbers for (a) a 16 GB machine, ideally one that OOMed on main, to show this fixes it there, and (b) Windows with NVIDIA or AMD, cold first start? If memory is the target, something likenx2/build.py'sMemoryGate(start a compile only whenMemAvailableminus the running ones' expected growth leaves room) might be the more direct fix; the core cap could then stay as an upper bound.The
vk_shader.cppedit makes every player translate the whole game again.nx2/build.pyhashes all ofvk_shader.cppintoHOOKSHOT_SHADER_STAMP, so touchingprogram_cache_load_someinvalidates everyone'shookshot_programs.binon update. That reader is a cache load, not a compile; I'd leave it atmin(cpus, 16)here (or wait for #2323, which moves it out of the hashed file).Overlap. #1610 (open, my earlier approval was dismissed) caps
precompile_runwithRX_VK_PRECOMPILE_JOBS/HOOKSHOT_JOBS, and the draft #2323 rewrites the same pool sizes inpredict_run/precompile_run/the cache reader around the affinity mask. These three will conflict and pick different policies, so I'd like @NotRexed to choose the direction before more work goes into any of them. #2263 uses a logical-processor count for an unrelated threshold (the game's short sleeps); no conflict.CI hasn't run. Windows builder, Linux AppImage and the game-free regressions are all waiting on approval (
action_required), so the newtest_compile_threads.pyhasn't been built with llvm-mingw yet. The branch is also 7 commits behind main.Nits:
docs/tested-configurations.md: eight rows for one benchmark is a lot for a table of in-game reports. One summary row linking the measurement doc would do.docs/compile-worker-measurements.mdpoints at local, ignored paths (build-linux/compile-benchmark/,work/...) that readers can't open, and its numbers predate the rebase. The PR body may be a better place for it.docs/worklist.md: the new row describes this PR's own change (and listsCodexas the claimant). The worklist is open work, so it would need removing on merge; I'd just drop it.min(cpus, 64)had the same issue, so not new.Not good to merge yet: points 1 and 3 are concrete, 2 and 4 need numbers and a decision, and CI hasn't run.
@ -0,0 +1,115 @@// Shader/pipeline pools count physical cores, not SMT siblings. Keep each pool's existing smaller limit.With one worker the predict/precompile pools run ~17k pipeline builds on a single thread, and the job pool goes below its old minimum of 2. I'd return 0 for "unknown" here (and from the
return 1paths above), and havecompile_worker_countfall back to the previous budget and log once that topology wasn't readable.One allowed CPU without a readable topology file (a sandbox or container that masks part of
/sys) fails detection for the whole machine. Skipping that CPU, or counting it as its own core, would degrade gracefully.This and
precompile_runare where the behaviour really changes (thecpus / 2pools already equal the physical count on SMT CPUs). #2323 measured this prediction at 302 s on 6 threads vs 271 s on 12 (NVIDIA, Linux), so the cap costs first-start time there as well as on your RADV run.Any edit to
vk_shader.cppchangesHOOKSHOT_SHADER_STAMP(nx2/build.pyhashes the whole file), so every player translates all programs again after updating. This is a cache reader, not a compile pool; I'd leave it as it was in this PR.@ -0,0 +1,115 @@// Shader/pipeline pools count physical cores, not SMT siblings. Keep each pool's existing smaller limit.Addressed in
github.com/NotRexed/Hookshot@44443d9954. Every unknown/failure path now returns 0.compile_worker_count(previous_budget)keeps that exact budget when detection is unavailable (including the background minimum of two) and logsvk: CPU topology not readable, using N workersonce. Windows/Linux/unsupported-platform fixtures check the fallback across budgets 64, 2 and 4 and the once-only warning. A genuine single physical core still caps at one.@ -0,0 +1,115 @@// Shader/pipeline pools count physical cores, not SMT siblings. Keep each pool's existing smaller limit.Addressed in
github.com/NotRexed/Hookshot@44443d9954. Each allowed Linux CPU tries both sysfs names, including when the current file exists but is unreadable. An unreadable record counts separately when other records are readable; it no longer discards the rest of the topology. If no record can be read, detection returns unknown and preserves the previous pool budget. The fixtures cover partial missing and malformed records as well as wholly missing topology.Addressed in
github.com/NotRexed/Hookshot@44443d9954, rebuilt from main after #2323 merged. This PR now changes neithervk_shader.cppnorvk_progcache.cpp/.h; both cache readers retain their existing usable-logical-CPU budgets. The translator stamp and cache format are untouched relative to main, and the program-cache stamp regression passes. There is no additional whole-game retranslation from this change.Agreed. The description now identifies prediction/precompile as the main behavior change on an unrestricted SMT host and explicitly reports both the +4.25% historical RADV cost and the roughly +11% NVIDIA/Linux prediction cost from #2323. The old RADV experiment is labeled historical, includes its cache-reader-policy difference, and is not presented as a benchmark of this revision. Cache readers now remain unchanged. I am keeping this draft pending the maintainer policy decision and the requested Windows/16 GB measurements; the core cap alone is not evidence of an OOM fix.
Rebuilt the proposal as one clean commit from current main
3e95ca68:44443d9954. Replies are on all four inline threads.Concrete fixes: unknown topology preserves each previous budget and warns once; partial Linux topology degrades per CPU; cache readers and translator-stamped sources are unchanged. The merged #2323 affinity-aware budgets remain underneath the physical cap. The benchmark table is one row, the historical measurements are in the description with their limitations, and the worklist self-entry is gone.
Local validation: Linux renderer rebuilt (one worker, 68 s, zero compile failures). The full game-free suite on the initial clean base passed 389 checks, with 21 skips and the existing local-PGO
test_make_game_cache.pyfixture failure reproduced on upstream. After the one intervening upstream VRAM commit, all eight focused checks passed; queue tests also passed restricted to one native CPU. Final topology fixtures passed GCC and Clang.The unchanged workflows are running on this exact head in the fork, since upstream approval is still needed. The Windows build has now passed (both package/setup and native llvm-mingw Vulkan compilation/linking); no release was published:
This remains draft. There is no current-branch Windows cold-first-start or 16 GB/OOM-reporter measurement, and the existing numbers show a time/memory tradeoff rather than a speedup or proven OOM fix. @NotRexed, with #2323 now merged and #1610 still open, please choose whether to pursue this default cap or prefer explicit job limits / memory-aware admission before extending the policy. No MemoryGate rewrite is included.
WIP: feat(vk): cap compiler pools at physical coresto feat(vk): cap compiler pools at physical cores