WIP: perf(vk): RX_VK_RT_HOME=1 keeps the render thread on its own core on Windows, with a guard for another program holding it (off by default) #2240
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
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
MagicBeanDev/Longshot!2240
Loading…
Reference in a new issue
No description provided.
Delete branch "klimovich008/Longshot:perf/rt-home-v3"
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?
Summary
This brings back a switch that keeps the render thread on one core, after #1309 removed
RX_VK_RT_STRICT_PIN. This timeit comes with a guard for #838's case (another program holding that core) and a farm plan. It is off by default, and
this PR proposes no default: that is the team's call once the farm has run it.
What it does, in player words. On Windows, the renderer keeps one core free of the game's own threads for the render
thread (the "reserved core"). Today the thread prefers that core, but Windows may move it to any fast core. When it moves,
it often lands beside a busy game thread on the same physical core, and both run slower.
RX_VK_RT_HOME=1keeps therender thread on its own core. When something else holds that core off it (#838's case: another program at high
priority on the same core), it lets the thread move again for a while:
It does nothing on Linux, the Steam Deck or macOS, and on a CPU without SMT (two logical processors a core) it changes
nothing that matters.
The switch.
RX_VK_RT_HOME(kindattempt):0): main's placement, exactly;1: home, with the guard;strict: home with no guard. It is a measuring arm and the tests' negative control, never meant to be used.RX_VK_RT_HOME_MS(kindtune, default 4) is the guard's threshold.How the guard decides it is being held. Between two presents 20-250 ms apart, it looks at two things:
RX_VK_RT_HOME_MSor more off the CPU outside its own waits. The time it spent readybut not woken from its job wait counts as lost;
It acts only once it has seen a hold happen, so about one stall frame gets through each time the thread goes back
home (measured below).
Read first:
gpu/vk/rt_pin.h(the Guard), then ingpu/vk/vk_replay.cpp:rt_place,rt_home_frame,job_waitandrt_ready_note. Also changed:gpu/vk/vk_fps.cpp/.h: the render thread's waits by kind;gpu/vk/switches.def: the two rows;docs/dev/reference/threads.md;tests/test_rt_pin.py(new) andtests/test_reserved_core_mask.py.Testing
Tested: Windows 11, Ryzen 7 5700X3D (8 cores, 16 threads), RX 9070 XT, AMD 26.11.2. The PR's renderer DLL went over
main dd5ffe6a's build (DLL b627b1f4, exe 302120c6):
The standard test (Hyrule Field turning),
RX_VK_RT_HOME=1against unset, 3 alternating pairs: see Measurements.1run the guard's lines show the thread at home through the measured window, with 0 holds.1and 0xffff unset.hold.
A stall made on purpose: a test program held both processors of the reserved core at priority 15 for 35 ms in every
250 ms, beside the game, for three rounds of
strict,1and unset in turn. Frames over 40 ms in the window:1under 40, which is why that round counts 0.
1's second frame in each run is the first stall after a return home, caught and held at that very present. Theguard can only see a hold after it has happened, so one stall frame gets through per return home.
strict(no guard) let through 80-81, so the injection worked.Unset against main's own build: the same mask and ideal processor, the same two placement lines, and no new error
lines.
tests/test_rt_pin.py:a2dc5385. One stub was added for main's newspawn_needed(#2170),with the PR's code unchanged.
Other tests:
test_reserved_core_mask,test_reserved_core,test_fps_stats,test_perf_pipe_waitsandtest_threaded_renderingpass with both compilers.
test_switch_tablefails onRX_VK_GRASS_DISTANCE's order inswitches.def, as on main.run_all.pyondd5ffe6a, with both compilers: nothing fails on the branch that doesn't fail on main.Linux syntax (clang 21, gcc 15): ok on
vk_replay.cppandvk_fps.cpp, after the merge.The Windows build after the merge (llvm-mingw, the renderer and the game over main's base): it builds clean. It was
not run in the game: the numbers below are from the PR's code before the merge.
The cost off: one bool test at each job hand-over (1.5 ns measured). With
1, a clock read on each side of ahand-over to the waiting thread, about 55 ns.
Still to test:
RX_VK_RT_HOME=1against unset on this PR's build, uncapped Hyrule Field. Expected: fps up or level, and no more long frames
(
@Beanstalk, request below).(
@Beanstalk).1, about one stall frame perreturn home, not every stall (by hand).
Measurements
Verdict: on this PC, +6.7 % fps with
RX_VK_RT_HOME=1in the standard test, CPU 43.86 -> 41.31 ms and p99 15.9 ->14.4 ms. Every pair gained (+8.4, +6.5, +6.8 %). A second session (the implementer's) gave +6.2 %.
Baseline: this PR's build with
RX_VK_RT_HOMEunset (main's placement), on main dd5ffe6a's build.Setup:
RX_VK_ASYNC=1.HOS_FPS_MAX=240with the options file's cap 0 and vsync 0. At about 98 fps that is in effect the farm'sframe_rate_cap=6,vsync=2.608775b2,RX_VK_RT_HOMEunset608775b2,RX_VK_RT_HOME=1--affinity 0xff), which is a mask of an 8-coreCPU, not a 4-core CPU. It gave 65.04 -> 82.34 fps (+26.6 %), p99 23.1 -> 19.1 ms, one run a side.
dd5ffe6a. The PR is now on maina2dc5385. Main's 7 commits since then don't move the render threador its queue wait. #2170 starts the thread through
spawn_needed, and #2174 changes Hyrule Field's simulated turf onthe way in, so the absolute numbers may move. Not re-measured here.
Risks
case). The guard sees a hold only once it has happened. Unset doesn't have this.
one:
marked as waits, so they count as lost time. Small wakes that add up to 4 ms in a window, with others busy on the
core during such a fence wait, could make a false hold. Follow-up: wrap them in
FpsRtWait(kRtGpu).steady_clock(QPC), the waits onfps_clock(the TSC, scaled once at itsfirst call). A calibration preempted during its loop mis-scales the waits. Follow-up: compare
fps_clock's rate withthe guard's own 1 s calibration, and give up (
rt_home_off) when they disagree by more than 2 %.__rdtsc()makes phantom busy time.core's two processors one after the other while the thread is held off for 4 ms or more. Each needs a wake of 4 ms
or more. In ordinary play the longest was 0.68 ms.
to the game's other three cores is measured only on the mask above.
RX_VK_ASYNC=0's pin (ReplayPin), host/ and the shader-cache stamp files (no re-prepare). HybridCPUs never keep the thread on an efficiency core. A process affinity mask is respected (#1776).
RX_VK_RT_HOME=0adds one start-up line naming the value. Unset gives exactly main's lines.Checklist
Ready for review
main; the title is a Conventional Commit.mise run testpasses (any failure that also fails onmainis named).main, or Measurements says why there is nothing to measure.third_party/untouched; nothing GPL-incompatible.When it applies
gpu/vk/switches.def.tests/that reads changed source is updated, not weakened.Assisted-by:/Co-Authored-By:trailers.Ready to merge
main, measured again or a comment says why the numbers still hold.🤖 Generated with Claude Code
a2dc5385) into perf/rt-home-v3 ce23f32f74Tested in game: Windows 11, Ryzen 7 5700X3D (8C/16T), RX 9070 XT, AMD 26.11.2, the PR's renderer over main dd5ffe6a's build: Hyrule Field turning, uncapped (HOS_FPS_MAX=240), 3 alternating pairs of RX_VK_RT_HOME=1 against unset: 91.64 -> 97.79 fps, the thread at home through every window with 0 holds, live mask 0xc000 against 0xffff, clock 1.000. A stall made on purpose (both reserved processors at priority 15, 35 ms in every 250 ms), 3 rounds: frames over 40 ms strict 80/81/81, =1 2/2/2, unset -/0/1 (about one stall frame per return home gets through). Unset against main's own build: the same mask, the same placement lines, no new error lines. The merge with main
a2dc5385was built, not run. Not run: Intel, other AMD CPUs, 4- and 6-core CPUs, SMT off, #838's real stall.@Beanstalk the PR's own build only, its switch against itself: baseline ref = pr, [matrix.pr_only] RX_VK_RT_HOME = ["0", "1"], and pass.compare RX_VK_RT_HOME = "1" against "0" on the pr side (unset is the same as 0: main's placement). It is off by default and does anything only on Windows CPUs with SMT, so every target is Windows.
Targets, each with 1-2 reports. Windows with a CPU that has two logical processors a core, by model:
The 4-core ones matter most (on this PC a 4-core mask gained far more, report-only), but don't let the plan wait on them alone.
Settings: frame_rate_cap = 6 (Uncapped), vsync = 2 (Off), frame_generation = 0; headless is fine.
Scenario: Hyrule Field (HyruleField_Child), measured 30 s, 3 game starts a cell (2 at least). Compare rules, pr side, RX_VK_RT_HOME=1 vs 0: fps_mean min_delta_pct = 3 (fails on a loss of more than 3 %) and frametime_p99_ms max_delta_pct = 10; crash = false. Hitch counts (run_hitch_count, run_frametime_max_ms) report-only.
Log on the =1 cells: "vk: RX_VK_RT_HOME=1: the render thread is kept to logical processors" expected (the thread really went home: on a PC where the placement does not apply it says "free to move, as unset" instead, and that cell compares nothing).
Beanstalk test farm · 🔄 testing (0 of 4 reports so far)
Commit
5867310· approved by klimovich008 (reviewed) · dashboard⚠️ Note: Two starts per setting keep the plan within the farm’s time limit, but leave no spare usable start for the frame-time comparison.
⚠️ Note: The placement log is unjudged when absent, including in the 0 cell; the farm cannot suppress the performance comparison when placement is refused, so such results may compare identical placement.
⚠️ Note: The farm cannot inject the competing high-priority workload needed to test guard recovery under a deliberate core hold.
Started at 10:54 UTC.
Estimate: done in about 1 h 15 min, from the queue and the testers online now; some jobs can't start yet.
windows+cpu-3300x_i3-10100_i3-12100_i3-13100_i7-6700_i7-6700k_i7-7700_i7-7700k(CPU "3300x" or "i3 10100" or "i3 12100" or "i3 13100" or "i7 6700" or "i7 6700k" or "i7 7700" or "i7 7700k")windows+cpu-3600_5600_5600x_7600_7600x_i5-10400_i5-11400_i7-8700k(CPU "3600" or "5600" or "5600x" or "7600" or "7600x" or "i5 10400" or "i5 11400" or "i7 8700k")windows+cpu-3700x_5700x_5800x_5800x3d_7700x_7800x3d_i7-10700k_i9-9900k(CPU "3700x" or "5700x" or "5800x" or "5800x3d" or "7700x" or "7800x3d" or "i7 10700k" or "i9 9900k")windows+cpu-i5-12400_i5-12600k_i5-13600k_i5-14600k_i7-12700k_i7-13700k(CPU "i5 12400" or "i5 12600k" or "i5 13600k" or "i5 14600k" or "i7 12700k" or "i7 13700k")hyrule-field· frame time p99 (ms)RX_VK_RT_HOME=0(reference)RX_VK_RT_HOME=1windows+cpu-3300x_i3-10100_i3-12100_i3-13100_i7-6700_i7-6700k_i7-7700_i7-7700k(CPU "3300x" or "i3 10100" or "i3 12100" or "i3 13100" or "i7 6700" or "i7 6700k" or "i7 7700" or "i7 7700k")windows+cpu-3600_5600_5600x_7600_7600x_i5-10400_i5-11400_i7-8700k(CPU "3600" or "5600" or "5600x" or "7600" or "7600x" or "i5 10400" or "i5 11400" or "i7 8700k")windows+cpu-3700x_5700x_5800x_5800x3d_7700x_7800x3d_i7-10700k_i9-9900k(CPU "3700x" or "5700x" or "5800x" or "5800x3d" or "7700x" or "7800x3d" or "i7 10700k" or "i9 9900k")windows+cpu-i5-12400_i5-12600k_i5-13600k_i5-14600k_i7-12700k_i7-13700k(CPU "i5 12400" or "i5 12600k" or "i5 13600k" or "i5 14600k" or "i7 12700k" or "i7 13700k")What was tested
What will be tested · AI plan (
gpt-6.1-terra)On selected Windows SMT CPUs, this compares the PR’s render-thread placement switch with its off setting in Hyrule Field. Two starts per setting measure 30 seconds of uncapped gameplay, taking about 45 minutes per tester. A crash, an FPS loss over 3%, or a p99 frame-time increase over 10% fails the comparison; hitches are reported without a limit. Some requested CPU targets may wait for matching Windows testers. No tester online now matches windows+cpu-3300x_i3-10100_i3-12100_i3-13100_i7-6700_i7-6700k_i7-7700_i7-7700k, windows+cpu-3600_5600_5600x_7600_7600x_i5-10400_i5-11400_i7-8700k, windows+cpu-i5-12400_i5-12600k_i5-13600k_i5-14600k_i7-12700k_i7-13700k: those targets wait for one.
RX_VK_RT_HOME) and off; main is not built or run.0or1(PR only).castle-gate(settings vsync=2, frame_rate_cap=6, frame_generation=0), then teleport to Hyrule Field, measure field for 30 s (after 5 s warm-up); 2 runs on each side for each of 2 cells (2 game starts a run).View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.