perf(vk): Threaded rendering's Auto chooses by physical cores, in three tiers #1664
No reviewers
Labels
No labels
area/accessibility
area/audio
area/input
area/install
area/menu
area/renderer
area/saves
area/tooling
area/upscaling
beanstalk: approved
beanstalk: failed
beanstalk: needs approval
beanstalk: running
beanstalk: tested
ci: approved
good first issue
gpu/amd
gpu/igpu
gpu/intel
gpu/nvidia
help wanted
kind
bug
kind
chore
kind
docs
kind
feature
kind
performance
kind
question
needs measurements
platform/linux
platform/macos
platform/steam-deck
platform/windows
preview
priority
critical
priority
high
priority
low
regression
risk
high
risk
low
risk
medium
status
blocked
status
confirmed
status
duplicate
status
invalid
status
needs-info
status
wontfix
ci: approved
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
MagicBeanDev/Longshot!1664
Loading…
Reference in a new issue
No description provided.
Delete branch "GummiNaomi/Longshot:perf/threaded-auto-cores"
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?
Type: perf · Risk: medium · Tested on: Windows 11, RTX 4070 SUPER, Ryzen 9 9950X3D (SMT off, held to 4, 6 and 8 cores) · Needs: a build of this head; CPUs with SMT (4c/8t, 6c/12t, 8c/16t); Linux; a Steam Deck
TL;DR
Threaded rendering's Auto turned the render thread and the recorder thread on together from 12 logical processors, and left everything below on the slow serial path. Measured by core count on one CPU, the render thread alone already helps on 4 cores, both threads help from 6 cores, and both threads on 4 cores make it worse. This PR makes Auto choose by physical cores in three steps: under 4 off, 4 or 5 the render thread only, 6 or more both. On my PC held to 4, 6 and 8 cores that is +2.3, +4.8 and +6.1 fps over today's Auto, with fewer long frames.
Breakdown
RX_VK_ASYNCandRX_VK_RECORDERstill choose over Auto; the unsafe gate (no buffer pool mirrors: integrated GPUs, the Steam Deck) still turns Auto off; 12+ logical processors with 6+ cores choose as before.Why
On a PC with a few cores the game's frame waits for the replay of its GPU work, which today runs on the game's own Presentation thread unless Threaded rendering moves it. #588 made Auto turn both helper threads on from 12 logical processors and leave everything below serial. Measured core count by core count, the right answer is not one threshold: the render thread alone helps from 4 cores; adding the recorder thread helps from 6 but hurts on 4, where it competes with the game's own threads. And 12 logical processors means very different CPUs with SMT on or off.
Upstream's open #1407 (riqmarmes) also moves Auto's threshold, to 8 logical processors with one tier. This PR differs in what it counts (physical cores, not logical processors) and in having a render-thread-only tier for 4 and 5 cores. Where they choose differently: 4 cores with 8 threads (#1407 both threads, this PR the render thread only: both threads measured worst on 4 cores here), 4 cores with 4 threads (#1407 off, this the render thread), 6 or 7 cores without SMT (#1407 off, this both). #1407 found the 1 % low worse with both threads on an 8-core, 8-thread i7-9700K in Hyrule Field; my 8-core runs (the market, SMT off) had fewer long frames with both. Different CPU and scene: worth looking at together. Whichever merges second will conflict on the
kAutoCpuslines.See #1407, #588, #688.
What changed
Auto asks how many physical cores the game may use and picks a tier. The menu's help for Auto says the rule; the log at the start says what this PC got.
gpu/vk/threaded_rendering.h:kAutoCpus(12 logical) is gone;kAutoRenderCores = 4,kAutoRecorderCores = 6; aChoicehas two halves (render_thread,recorder_thread);auto_picks(cores),auto_picked(),cores_of()(the cores among the affinity mask's processors),describe()(the start's log line); the measured table in the header's comment.gpu/vk/vk_progcache.cppusable_cores()besideusable_cpus(): the process's affinity mask andGetLogicalProcessorInformation's per-core masks (on Linux the renderer's copy of the posix shim groups processors by sysfsphysical_package_idandcore_id); a core counts once when any of its processors is usable; with nothing counted, the logical count as before; never more than the logical count.gpu/vk/vk_internal.hdeclares it.gpu/vk/vk_menu.cppthreaded_choice()(resolved once fromusable_cores(), the mirrors gate asked in both Auto tiers,describe()logged),menu_render_thread()andmenu_recorder_thread()in place ofmenu_threaded_rendering();gpu/vk/vk_replay.cppreads the render thread's half, the recorder hook the recorder's;vk_menu.h,vk_recorder.hcomments.gpu/vk/device_policy.hDeviceFacts::cores_usable, the logged flagsthreaded_auto_renderandthreaded_auto_recorderin place ofthreaded_auto_cpus;gpu/vk/vk_main.cppfillscores_usable.docs/development.md's Threaded rendering andRX_VK_ASYNCrows, theRX_VK_ASYNCandRX_VK_RECORDERrows' default text ingpu/vk/switches.def.tests/test_threaded_rendering.pyrewritten: the rule compiled for 0 to 256 cores,cores_ofon Windows- and Linux-numbered siblings, a hybrid 6P+8E CPU, SMT off and 64 processors;usable_corescut fromvk_progcache.cppover stand-in Win32 calls (SMT siblings once, failing calls, no core entry, the cap); the readers compiled in 21 environments; source checks of the wiring and the texts; 20 broken copies, each caught.tests/test_device_policy.py: a cores column for its 19 PCs and the flags by cores.Measurements
Verdict: faster where it changes the default: +2.3 fps on 4 cores (the render thread), +4.8 on 6 and +6.1 on 8 (both threads), frames of 16.7 ms or more down by about 35 % to 75 %; both threads on 4 cores would have been 3.6 fps slower than serial, which the 4-5 tier avoids.
Hardware: Windows 11, RTX 4070 SUPER (NVIDIA 617.42), Ryzen 9 9950X3D with SMT off, 32 GB; the game held to 4, 6 or 8 cores by affinity
Scene: Castle Town's market (child), standing after a debug teleport from the
kokiri-startsave; output 2560x1440, uncapped (HOS_FPS_MAX=1000), no window (HOS_HEADLESS=1),HOS_CACHE_CORES=0Method:
RX_VK_FRAME_TRACE=1; from 300 frames after the teleport to the run's end (about 50 s), fps from the summed frame times, the median frame and the share of frames of 16.7 ms or more; two runs each way, in rounds; the three ways forced withRX_VK_ASYNC=1andRX_VK_RECORDER=threadHow to reproduce: the same spot,
RX_VK_ASYNC=0,RX_VK_ASYNC=1, andRX_VK_ASYNC=1 RX_VK_RECORDER=thread; the runs also hadRX_VK_ASTC_BC_ALL=1 RX_VK_IMAGE_BLOCK_MB=32 RX_VK_LOAD=create RX_VK_BC_LAYERS=8 RX_VK_LATE_FIX=0 HOS_THREAD_TIMES=5Baseline: build @
54a42715(main 93 commits before this PR's base) with the 18 Nov changes, the three ways forced by switches in one build (main's Auto is the serial column at 4, 6 and 8 cores: it is off under 12 logical processors). This PR's rule chooses the bold cell in each row. A later build with this rule, left to choose by itself, gave 68.3 fps on 4 cores, 73.9 on 6, 73.6 on 8 and 75.4 on 16 (logs not kept).54a42715RX_VK_ASYNC=1): build @54a42715+ RX_VK_RECORDER=thread): build @54a42715Flags and settings
No switch added; the menu row's Auto changes what it picks.
threaded_rendering=in the options file)RX_VK_ASYNC,RX_VK_RECORDERTesting
Tested: the core-count runs above and the rule's own choices on 4, 6, 8 and 16 cores (in the game, at 93 commits behind this base). On this head:
tests/test_threaded_rendering.py --cxx clang++andtests/test_device_policy.py --cxx clang++pass; of the 257 checks that read the changed files, the 47 that fail on this PC failed the same way on main (run before the rebase onto main's last 11 commits; after it, the two tests above,tests/test_readme_menu_rows.pyandtests/test_doc_anchors.pypass again). The branch's ownusable_cpusandusable_coreson the real Windows calls of this PC (SMT off), the process held by affinity: 0x3 2 cores, off; 0xF 4, the render thread only; 0x3F 6, both; 0xFF 8, both; 0xFFFF and none 16, both.Not testable by hand: CPUs with SMT on, Intel hybrid CPUs, and Linux's sysfs core grouping are not on my PC; the counting is checked with stand-in Win32 calls and sibling masks for each of those layouts, and Linux uses the posix shim's existing
GetLogicalProcessorInformation.Not tested: a build of this exact head;
threaded_choice()itself is not compiled by a test (its pieces are: the rule, the count, the gate's source); Wine/Proton'sGetLogicalProcessorInformation.Must be tested:
vk: Threaded rendering: Auto: the render thread only (4 cores of 8 logical processors; ...)line, and the market's fps against Threaded rendering Off, expecting Auto no slower (Test Farm: @Beanstalk windows, a 4-core 8-thread CPU, Castle Town's market standing 60 s with Threaded rendering Auto and Off)Risks
What could break: PCs of 4 or 5 cores and 6 to 11 logical processors without SMT with a discrete card now run the render thread (and from 6 cores the recorder thread) by default; Threaded rendering's known costs apply to them as to 12+ processors today (GPU-written tables read a frame later where the header says so). A miscount (a system whose core information is missing or odd) falls back to the logical count.
Turning it off: Threaded rendering Off in the menu, or
RX_VK_ASYNC=0.Compatibility: nothing changes for saves, options or caches; the options file's value is the same Auto.
Issues
See #1407, #688
Checklist
Everyone
type(scope): description) of the status line's type.main.python -I -B tests/run_all.pypasses (any failure that also fails onmainis named). (The changed files' checks on this PC; failures are main's own here.)third_party/untouched (a new folder with aPROVENANCE.mdinstead).When it applies
Assisted-by:/Co-Authored-By:trailers.tests/that reads changed source updated in this PR, not weakened.🤖 Generated with Claude Code
mooki referenced this pull request2026-11-19 00:27:16 +00:00