WIP: perf(vk): derive Auto threaded rendering's threshold from the game's cores #1407

Draft
riqmarmes wants to merge 1 commit from riqmarmes/Longshot:perf/threaded-auto-8-cpus into main
First-time contributor

Type: perf · Risk: medium · Tested on: Windows 11 22631, RTX 3080 Ti, i7-9700K (8 logical) · Needs: a PC with 8-11 logical processors, with 1 % lows

Why

#588 turned Threaded rendering on by default (Auto) from 12 logical processors. This header's own words for that rule are "the game's own threads, the replay, the recorder and the parallel replay's workers beside one another": six game cores plus the replay thread and the recorder thread is 8 — the count at which the mode fits exactly. 12 was the same rule with a four-thread margin, and it leaves 8-processor CPUs, which run the mode well, on the serial replay.

GrimVisage's Market measurement in #688 (a 6-core/12-thread Ryzen 5 5600X, above the current cutoff) shows why average fps alone does not settle the cutoff: +17 % fps on the gate scene, but +8 % fps with -7 % 1 % low on the laps. The 8-11 band is the one that needs 1 % lows, which this PR does not have yet (WIP).

What changed

The patch replaces Auto's hard-coded 12-processor threshold with the count the mode actually needs: the game's six cores, the replay thread and the recorder thread. Only PCs with 8 to 11 logical processors change behaviour; at 12 or more Auto chooses exactly as before.

  • gpu/vk/threaded_rendering.h: new kGameCores = 6 (the game's own virtual cores, vc_cores); kAutoCpus is kGameCores + 2 (the replay and the recorder threads) instead of the hard-coded 12, and the comment records the derivation and the measurement.
  • tests/test_threaded_rendering.py: the fixture checks the derivation and the boundary — kAutoCpus == kGameCores + 2 == 8, !auto_picks(7), auto_picks(8), and the choose(AUTO, …) cases moved from 8/11/12 to 4/7/8.
  • No other file changes: PCs at 12 or more logical processors choose exactly as before (auto_picks is cpus >= kAutoCpus).

Measurements

Verdict: the median frame time improves (replay submit 8.78/9.15 -> 6.51/6.65 ms, +6 % fps at matched draws) but the 1 % low is worse with the render thread on (64.2 -> 53.7 fps, p99 15.6 -> 18.6 ms) at 8 logical processors. 12+ is unchanged by construction. Not ready: the trade needs the team's call, and the 1 % low needs more pairs and a 10-11 processor machine.

Hardware: i7-9700K (8 cores/8 logical), 32 GB, RTX 3080 Ti 12 GB (driver 621.24), Windows 11 22631, output 3440x1440 at the game's resolution with DLSS, V-Sync off, cap 165.
Scene: Hyrule Field (child), save slot 04, teleported to the field arrival point, standing still (1,219-1,234 draws a frame, 162 passes), 45 s a run after 20 s of warm-up.
Method: one game folder (development build of main 544229a2), warm shader and program caches, only longshot_vk.dll swapped between the arms (base pack, then this branch's renderer pack); two interleaved pairs; pinned options file, RX_VK_FRAME_TRACE=1; fps medians of the log's per-120-present samples, draws from the same lines.

Before: main @ 544229a2 After: this PR @ c4f2d5b
fps (pair 1 / pair 2) 74.4 / 72.8 78.7 / 77.6
draws a frame 1,219 / 1,234 1,221 / 1,229
replay submit, ms 8.78 / 9.15 6.51 / 6.65

Transition check, four teleports each (Kakariko <-> Hyrule Field): base 8 frames over 150 ms totalling 2,354 ms and one 360 ms GPU wait; this branch 7 frames totalling 1,996 ms and no GPU wait over 100 ms.

1 % low (one pair, same scene, RX_VK_FRAME_TRACE frame times over the last 40 % of each run, 2,338 and 2,374 frames): Off median 12.8 ms, p99 15.6 ms, 1 % low 64.2 fps; On median 12.6 ms, p99 18.6 ms, 1 % low 53.7 fps. The median is the same and the 1 % low is 16 % worse with the render thread on, which is the direction #688 saw on its laps (-7 %). This is the reason this PR stays WIP and should be read before the threshold moves to 8: at 8 logical processors the mode has no spare thread, and the tail is where that shows.

How to reproduce: build a base and a pack of this branch (scripts/dev_packs.py base / pack, the workflow in docs/development.md), then run the same save and spot on each (python -I scripts/longshot_ctl.py launch <runtime> --user <run>/user --save <save> --slot 04 --ready present --env HOS_OPTIONS_FILE=<pinned ini> --env RX_VK_FRAME_TRACE=1, teleport 1 --arrive 120, 20 s of warm-up, 45 s standing still) and compare the log's N presents, F fps; a frame: D draws lines and longshot_frames.csv.

Flags and settings

None: the patch reads no new switch. The runs used RX_VK_FRAME_TRACE=1 (diagnostics only), a pinned options file, and the base and renderer packs of one base.

Testing

Tested: python -I -B tests/test_threaded_rendering.py --cxx <clang++> passes (the derivation and boundary above); python -I -B tests/run_all.py gives the same 154 failure lines as main on this PC (pre-existing Windows-side checks, 420 skipped for lack of gcc/g++); in the game, four scripted runs on the scene above and four teleports, this build only.
Not tested: any build of this branch other than the renderer pack over the base; 1 % lows and p99 frame times for the pair; any CPU other than 8 logical processors; HDR, frame generation and non-DLSS upscalers.
Must be tested: @Beanstalk 8-11 logical processors, 10-11 first, Windows or Linux with any Tier 1 GPU: the Market lap scene from #688 with Threaded rendering Auto against Off, expecting fps to hold or rise and the 1 % low not to fall below the Off run by more than the run-to-run spread; by hand on such a PC also says what to look at (the row, the caches and the culling artifacts in Hyrule Field and the Market).

Risks

Compatibility: nothing changes for saves, longshot_options.ini, the shader and pipeline caches, the vk ABI (MKWVK_API_VERSION untouched) or the builder's tools; on 8-11 logical processors the visible change is the render thread on by default, and the log line naming the new threshold.

What could break, and where: on an 8-11 logical processor PC the render thread can make a scene slower instead of faster (the 1 % low is the number to watch), and the frame-lag caveat threaded_rendering.h records can show as culling artifacts in Hyrule Field or the Market (a GPU-written table read a frame old). It shows in the heavy outdoor scenes; this PC's Hyrule Field is the measured case.

How to turn it off: Insert menu -> Gameplay -> Threaded rendering -> Off, which is saved in longshot_options.ini (threaded_rendering=2) and applies from the next start.

How to revert: git revert this one commit, or set kAutoCpus back to 12 — the constant is the whole change.

12 or more logical processors: no code path changes at all.

Checklist

Everyone

  • One topic.
  • The title is a Conventional Commit (type(scope): description) of the status line's type.
  • Why gives the reason plainly and links the issues that fit (the tracker searched).
  • Tested on my own PC where it runs (in the game, for a change the game runs), as Testing's Tested says; what
    can't be run by hand is in Testing's Not testable by hand, with why.
  • Measurements has a verdict, or one line saying why there is nothing to measure.
  • Nothing gets worse that I know of: any cost (speed, latency, memory, a setup that worked before) is measured and
    in Risks. Not ticked yet: Measurements show the 1 percent low worse with the render thread on, 64.2 to 53.7 fps, and the default still ships on.
  • Testing names what was tested, what wasn't, and what must still be tested, where and how.
  • Rebased on current main.
  • python -I -B tests/run_all.py passes (any failure that also fails on main is named).
  • No game files, dumps, build output or generated files.
  • third_party/ untouched (a new folder with a PROVENANCE.md instead).
  • The license is OK: GPL-3.0-or-later, nothing incompatible and nothing decompiled.

When it applies

  • AI assistance recorded with Assisted-by: / Co-Authored-By: trailers.
  • Numbers from the same PC, scene and settings, at least 2 interleaved runs each, the median reported.
  • A check under tests/ that reads changed source updated in this PR, not weakened.

Assisted-by: DeepSeek Harness (agent), for the measurement runs and the patch text.

**Type:** perf · **Risk:** medium · **Tested on:** Windows 11 22631, RTX 3080 Ti, i7-9700K (8 logical) · **Needs:** a PC with 8-11 logical processors, with 1 % lows ## Why #588 turned Threaded rendering on by default (Auto) from 12 logical processors. This header's own words for that rule are "the game's own threads, the replay, the recorder and the parallel replay's workers beside one another": six game cores plus the replay thread and the recorder thread is 8 — the count at which the mode fits exactly. 12 was the same rule with a four-thread margin, and it leaves 8-processor CPUs, which run the mode well, on the serial replay. GrimVisage's Market measurement in #688 (a 6-core/12-thread Ryzen 5 5600X, above the current cutoff) shows why average fps alone does not settle the cutoff: +17 % fps on the gate scene, but +8 % fps with -7 % 1 % low on the laps. The 8-11 band is the one that needs 1 % lows, which this PR does not have yet (WIP). ## What changed The patch replaces Auto's hard-coded 12-processor threshold with the count the mode actually needs: the game's six cores, the replay thread and the recorder thread. Only PCs with 8 to 11 logical processors change behaviour; at 12 or more Auto chooses exactly as before. - `gpu/vk/threaded_rendering.h`: new `kGameCores = 6` (the game's own virtual cores, `vc_cores`); `kAutoCpus` is `kGameCores + 2` (the replay and the recorder threads) instead of the hard-coded 12, and the comment records the derivation and the measurement. - `tests/test_threaded_rendering.py`: the fixture checks the derivation and the boundary — `kAutoCpus == kGameCores + 2 == 8`, `!auto_picks(7)`, `auto_picks(8)`, and the `choose(AUTO, …)` cases moved from 8/11/12 to 4/7/8. - No other file changes: PCs at 12 or more logical processors choose exactly as before (`auto_picks` is `cpus >= kAutoCpus`). ## Measurements **Verdict:** the median frame time improves (replay submit 8.78/9.15 -> 6.51/6.65 ms, +6 % fps at matched draws) but the **1 % low is worse with the render thread on** (64.2 -> 53.7 fps, p99 15.6 -> 18.6 ms) at 8 logical processors. 12+ is unchanged by construction. Not ready: the trade needs the team's call, and the 1 % low needs more pairs and a 10-11 processor machine. **Hardware:** i7-9700K (8 cores/8 logical), 32 GB, RTX 3080 Ti 12 GB (driver 621.24), Windows 11 22631, output 3440x1440 at the game's resolution with DLSS, V-Sync off, cap 165. **Scene:** Hyrule Field (child), save slot 04, teleported to the field arrival point, standing still (1,219-1,234 draws a frame, 162 passes), 45 s a run after 20 s of warm-up. **Method:** one game folder (development build of main 544229a2), warm shader and program caches, only `longshot_vk.dll` swapped between the arms (base pack, then this branch's renderer pack); two interleaved pairs; pinned options file, `RX_VK_FRAME_TRACE=1`; fps medians of the log's per-120-present samples, draws from the same lines. | | Before: main @ 544229a2 | After: this PR @ c4f2d5b | |---|---|---| | fps (pair 1 / pair 2) | 74.4 / 72.8 | 78.7 / 77.6 | | draws a frame | 1,219 / 1,234 | 1,221 / 1,229 | | replay submit, ms | 8.78 / 9.15 | 6.51 / 6.65 | Transition check, four teleports each (Kakariko <-> Hyrule Field): base 8 frames over 150 ms totalling 2,354 ms and one 360 ms GPU wait; this branch 7 frames totalling 1,996 ms and no GPU wait over 100 ms. **1 % low (one pair, same scene, `RX_VK_FRAME_TRACE` frame times over the last 40 % of each run, 2,338 and 2,374 frames):** Off median 12.8 ms, p99 15.6 ms, **1 % low 64.2 fps**; On median 12.6 ms, p99 18.6 ms, **1 % low 53.7 fps**. The median is the same and the 1 % low is 16 % worse with the render thread on, which is the direction #688 saw on its laps (-7 %). This is the reason this PR stays WIP and should be read before the threshold moves to 8: at 8 logical processors the mode has no spare thread, and the tail is where that shows. **How to reproduce:** build a base and a pack of this branch (`scripts/dev_packs.py base / pack`, the workflow in docs/development.md), then run the same save and spot on each (`python -I scripts/longshot_ctl.py launch <runtime> --user <run>/user --save <save> --slot 04 --ready present --env HOS_OPTIONS_FILE=<pinned ini> --env RX_VK_FRAME_TRACE=1`, `teleport 1 --arrive 120`, 20 s of warm-up, 45 s standing still) and compare the log's `N presents, F fps; a frame: D draws` lines and `longshot_frames.csv`. ### Flags and settings None: the patch reads no new switch. The runs used `RX_VK_FRAME_TRACE=1` (diagnostics only), a pinned options file, and the base and renderer packs of one base. ## Testing **Tested:** `python -I -B tests/test_threaded_rendering.py --cxx <clang++>` passes (the derivation and boundary above); `python -I -B tests/run_all.py` gives the same 154 failure lines as main on this PC (pre-existing Windows-side checks, 420 skipped for lack of gcc/g++); in the game, four scripted runs on the scene above and four teleports, this build only. **Not tested:** any build of this branch other than the renderer pack over the base; 1 % lows and p99 frame times for the pair; any CPU other than 8 logical processors; HDR, frame generation and non-DLSS upscalers. **Must be tested:** `@Beanstalk` 8-11 logical processors, 10-11 first, Windows or Linux with any Tier 1 GPU: the Market lap scene from #688 with Threaded rendering Auto against Off, expecting fps to hold or rise and the 1 % low not to fall below the Off run by more than the run-to-run spread; by hand on such a PC also says what to look at (the row, the caches and the culling artifacts in Hyrule Field and the Market). ## Risks Compatibility: nothing changes for saves, `longshot_options.ini`, the shader and pipeline caches, the vk ABI (`MKWVK_API_VERSION` untouched) or the builder's tools; on 8-11 logical processors the visible change is the render thread on by default, and the log line naming the new threshold. What could break, and where: on an 8-11 logical processor PC the render thread can make a scene slower instead of faster (the 1 % low is the number to watch), and the frame-lag caveat `threaded_rendering.h` records can show as culling artifacts in Hyrule Field or the Market (a GPU-written table read a frame old). It shows in the heavy outdoor scenes; this PC's Hyrule Field is the measured case. How to turn it off: Insert menu -> Gameplay -> Threaded rendering -> Off, which is saved in `longshot_options.ini` (`threaded_rendering=2`) and applies from the next start. How to revert: `git revert` this one commit, or set `kAutoCpus` back to 12 — the constant is the whole change. 12 or more logical processors: no code path changes at all. ## Checklist ### Everyone - [x] One topic. - [x] The title is a Conventional Commit (`type(scope): description`) of the status line's type. - [x] Why gives the reason plainly and links the issues that fit (the tracker searched). - [x] Tested on my own PC where it runs (in the game, for a change the game runs), as Testing's Tested says; what can't be run by hand is in Testing's Not testable by hand, with why. - [x] Measurements has a verdict, or one line saying why there is nothing to measure. - [ ] Nothing gets worse that I know of: any cost (speed, latency, memory, a setup that worked before) is measured and in Risks. Not ticked yet: Measurements show the 1 percent low worse with the render thread on, 64.2 to 53.7 fps, and the default still ships on. - [x] Testing names what was tested, what wasn't, and what must still be tested, where and how. - [x] Rebased on current `main`. - [x] `python -I -B tests/run_all.py` passes (any failure that also fails on `main` is named). - [x] No game files, dumps, build output or generated files. - [x] `third_party/` untouched (a new folder with a `PROVENANCE.md` instead). - [x] The license is OK: GPL-3.0-or-later, nothing incompatible and nothing decompiled. ### When it applies - [x] AI assistance recorded with `Assisted-by:` / `Co-Authored-By:` trailers. - [x] Numbers from the same PC, scene and settings, at least 2 interleaved runs each, the median reported. - [x] A check under `tests/` that reads changed source updated in this PR, not weakened. Assisted-by: DeepSeek Harness (agent), for the measurement runs and the patch text.
perf(vk): auto threaded rendering from 8 logical processors
Some checks are pending
CI / Conventional Commit title (pull_request) Blocked by required conditions
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Blocked by required conditions
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Blocked by required conditions
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Blocked by required conditions
CI / Workflow lint (actionlint) (pull_request) Blocked by required conditions
Guide screenshots / Guide images and local UI source review (pull_request) Blocked by required conditions
Third-party parts / As their notes say (pull_request) Blocked by required conditions
Third-party parts / The same as upstream (pull_request) Blocked by required conditions
Website / Website on Cloudflare (pull_request_target) Has been skipped
PR description / Description follows the template (pull_request_target) Successful in 8s
c4f2d5b61c
Auto (the Threaded rendering row) picked the render thread and the
recorder thread from 12 logical processors; below that it stayed off.
On an i7-9700K (8 logical processors, Windows 11, RTX 3080 Ti) forcing
the render thread on with RX_VK_ASYNC=1 beat Auto off by 5-8 %, and the
rule change shows the same on the same scene (Hyrule Field child, save
slot 04, standing still at the teleport, 45 s a run, one game folder,
only longshot_vk.dll swapped between the arms):

  draws  fps   replay submit
  1219   74.4  8.78 ms   Auto off (main)
  1221   78.7  6.51 ms   Auto on (this change)
  1234   72.8  9.15 ms   Auto off (main)
  1229   77.6  6.65 ms   Auto on (this change)

The frame-lag caveat threaded_rendering.h already records (a GPU-written
table read a frame old behind the game) applies to these CPUs as it does
to the 12-thread ones, so whether Auto takes them by default is the
maintainer's call, not this measurement's.

tests/test_threaded_rendering.py follows the new threshold.
Author
First-time contributor

Tested in game: Hyrule Field (child) and Kakariko Village on an i7-9700K / RTX 3080 Ti / Windows 11: four scripted runs at a fixed view (1,219-1,234 draws) and four area teleports, this build only

Tested in game: Hyrule Field (child) and Kakariko Village on an i7-9700K / RTX 3080 Ti / Windows 11: four scripted runs at a fixed view (1,219-1,234 draws) and four area teleports, this build only
Author
First-time contributor

1 % lows measured at 8 logical processors (one pair, same Hyrule Field scene, frame trace over the last 40 % of each run): Threaded rendering Off median 12.8 ms / p99 15.6 ms / 1 % low 64.2 fps; On median 12.6 ms / p99 18.6 ms / 1 % low 53.7 fps. The median improves and the tail is 16 % worse, the same direction as #688's laps. That is why this stays WIP: the threshold at 8 needs the team's call on the tail, and a 10-11 processor machine to show whether the spare threads change it.

1 % lows measured at 8 logical processors (one pair, same Hyrule Field scene, frame trace over the last 40 % of each run): Threaded rendering Off median 12.8 ms / p99 15.6 ms / 1 % low 64.2 fps; On median 12.6 ms / p99 18.6 ms / 1 % low 53.7 fps. The median improves and the tail is 16 % worse, the same direction as #688's laps. That is why this stays WIP: the threshold at 8 needs the team's call on the tail, and a 10-11 processor machine to show whether the spare threads change it.
Owner

Brought up to the ready-for-review standard (#1454): the checklist's Everyone list has two new boxes, added here from what this PR's description and comments show (please check they match what you know).

  • Tested on my own PC: ticked: Testing's Tested: four in-game runs on Windows 11 with an i7-9700K and RTX 3080 Ti, this build only.
  • Nothing gets worse that I know of: not ticked: Measurements show the 1 percent low worse with the render thread on, 64.2 to 53.7 fps, and the default still ships on. Measure that cost and state it in Risks, then tick it.
Brought up to the [ready-for-review standard](https://git.magicbean.dev/MagicBeanDev/Longshot/src/branch/main/CONTRIBUTING.md#ready-for-review-out-of-wip) (#1454): the checklist's Everyone list has two new boxes, added here from what this PR's description and comments show (please check they match what you know). - *Tested on my own PC*: ticked: Testing's Tested: four in-game runs on Windows 11 with an i7-9700K and RTX 3080 Ti, this build only. - *Nothing gets worse that I know of*: not ticked: Measurements show the 1 percent low worse with the render thread on, 64.2 to 53.7 fps, and the default still ships on. Measure that cost and state it in Risks, then tick it.
Some checks are pending
CI / Conventional Commit title (pull_request) Blocked by required conditions
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Blocked by required conditions
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Blocked by required conditions
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Blocked by required conditions
CI / Workflow lint (actionlint) (pull_request) Blocked by required conditions
Guide screenshots / Guide images and local UI source review (pull_request) Blocked by required conditions
Third-party parts / As their notes say (pull_request) Blocked by required conditions
Third-party parts / The same as upstream (pull_request) Blocked by required conditions
Website / Website on Cloudflare (pull_request_target) Has been skipped
PR description / Description follows the template (pull_request_target) Successful in 8s
This pull request is marked as a work in progress.
Some workflows are waiting to be reviewed.
This branch is out-of-date with the base branch
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u 'perf/threaded-auto-8-cpus:riqmarmes-perf/threaded-auto-8-cpus'
git switch 'riqmarmes-perf/threaded-auto-8-cpus'
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
2 participants
Notifications
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/Longshot!1407
No description provided.