feat(vk): measure the PCIe link at start and log it #3161
No reviewers
Labels
No labels
area/accessibility
area/audio
area/input
area/install
area/menu
area/mods
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
3 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
MagicBeanDev/Longshot!3161
Loading…
Reference in a new issue
No description provided.
Delete branch "neotoxic/Longshot:perf/pcie-probe"
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
When a player reports stutter or low fps, nothing in the log says what their GPU sits behind: a full x16 slot, a laptop's x8, a x4 slot, or an eGPU over Thunderbolt. Every submission sends the pages the CPU wrote to VRAM (the mirrors) and brings the GPU's writes back, and that traffic costs a lot more on a narrow link.
This adds one line to the log at start, on a discrete GPU only. It gives the link speed measured each way and the link the OS says was negotiated, from the GPU up to its root port. The measurement is a 32 MB copy each way, best of 6 rounds, timed with GPU timestamps. The OS's link comes from sysfs on Linux and from the PCI bus driver's properties on Windows. Nothing else changes: the line only tells what the link is.
RX_VK_PCIE_PROBE=0leaves the probe out, in case a driver mishandles it. The line then readsvk: pcie link: not probed (RX_VK_PCIE_PROBE=0).A mode for slow links was built and measured on top of this probe, and it is not part of this PR. That mode made mirror syncs copy only the 256-byte blocks that changed since a page's last sync. It was correct: RX_VK_MEM_CHECK read every diffed page back on Windows and Linux, and 0 pages differed. It also sent 59 % fewer upload bytes. But it gained nothing on an x16 desktop and lost 3 % fps on a PCIe 3.0 x8 laptop, where the hashing cost more than the link saved. The probe stays because the log line is useful for diagnosing reports.
The idea of a measured link probe comes from HeyListen (Sacrappy) and ProjectReLink. No code was taken from either; the code is Longshot's own.
Read first:
gpu/vk/vk_pcie_link.cpppcie_link_probe(the probe and the line), thengpu/vk/pcie_link.h(the parsing rules, tested without a GPU).Testing
Tested:
dev.py ab --env RX_VK_PCIE_PROBE=0 --runs 1in Hyrule Field onc9a29ba7. With the switch unset, the log has the line above: 26.8 / 26.4 GB/s, measured in 19 ms. WithRX_VK_PCIE_PROBE=0, the log says "not probed". Both runs played normally and the logs have no FATAL line.181ae977(the same probe, which also set a policy flag removed since). The line read 6.7 GB/s host to device and 6.6 device to host, measured in 74 ms, and the OS's link was 8 GT/s x8 over 2 hops. The Linux code built and ran.c9a29ba7: built on Linux, the line read 6.7 / 6.6 GB/s in 75 ms, anddev.py ab --runs 3in Hyrule Field againstmain@ee9e1ed7gave the same fps (Measurements).c9a29ba7:tests/test_pcie_link.py(the parsing rules compiled and run on made-up values, plus the source: the probe after the device is made, the kill switch read before anything is measured, no slow-link switch left),tests/test_switch_table.py,tests/test_device_policy.py,tests/test_recorder_sync.py(source part: the probe's own command buffer is listed as direct).run_all.py --changed origin/maingives 116 passed, 3 failed, 14 skipped. The 3 that fail, test_tex_desc_memo, test_recorder_sync (runtime part) and test_prepare_stall, fail the same way onmainee9e1ed7on this PC.Still to test:
vk: pcie link:line, expecting measured GB/s close to the link's and the OS's link read, with no crash or driver error at start (@Beanstalk run any scene on an AMD runner and post the vk: pcie link line)Measurements
Verdict: nothing measurable: the probe runs once at start (19 ms on x16, 75 ms on PCIe 3.0 x8) and nothing in a frame changes.
Setup: an RTX 3060 Laptop on CachyOS with its display wired to the dGPU, PCIe 3.0 x8. Hyrule Field,
dev.py ab --runs 3, interleaved A1 B1 A2 B2 A3 B3, 60 s a run, no fps cap, atc9a29ba7.ee9e1ed7c9a29ba7On this PC (RTX 5080, x16, Windows 11), the same build with the probe against
RX_VK_PCIE_PROBE=0, one run each, gave 172.2 against 173.6 fps. The probe took 19 ms at start.Risks
RX_VK_PCIE_PROBE=0turns it off, and a revert is enough otherwise.Checklist
Ready for review
main; the title is a Conventional Commit.mise run testpasses (any failure that also fails onmainis named).python -I -B tests/run_all.py --stricton Windows, onc9a29ba7: 688 passed, 160 failed, 51 skipped; onmain@ee9e1ed7: 687, 160, 51, the same 160 failing checks and none new (Windows ones: missing Linux tools, paths, file locking). Linux CI runs the lot.main, or Measurements says why there is nothing to measure (three runs a side on the laptop, atc9a29ba7).third_party/untouched; nothing GPL-incompatible.When it applies
gpu/vk/switches.def.tests/that reads changed source is updated, not weakened.c9a29ba7.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
Tested in game: yes, on Windows 11 (RTX 5080, PCIe x16) and CachyOS (RTX 3060 Laptop, PCIe 3.0 x8): the vk: pcie link line read in both logs, and RX_VK_PCIE_PROBE=0 skips the probe.
WIP: feat(vk): measure the PCIe link at start and log itto feat(vk): measure the PCIe link at start and log itb77c2f4b) into perf/pcie-probe 60f62f7deae345b3cab) into perf/pcie-probeBrought up to current
main(e345b3ca) by a merge, nothing rewritten. Its tests ran in #3162, which carries this branch.@review
Recommendation: Request changes. The probe can submit an invalid command buffer after a recording failure, turning an optional diagnostic into a startup failure. Its default also needs the outstanding hardware runs before it is ready to merge.
Adds a discrete-GPU startup log with measured transfer rates and the OS-reported PCIe links. It helps diagnose slow-link reports, at the cost of a measured 19–75 ms startup probe and temporary allocations.
Blocking (1): must change before merging.
gpu/vk/vk_pcie_link.cpp:129: The probe ignores failures from beginning and ending its command buffer and proceeds to record and submit it. (more on the line) Do: Check both results, skip recording or submission on failure, report that the probe was not measured, and release the resources that are safe to destroy.Should fix (2): not blocking, but worth doing before merging.
gpu/vk/pcie_link.h:77: The first hop with readable data is treated as the GPU's own link even when the GPU's link was not readable. (more on the line) Do: Track the GPU entry independently of the count of readable hops, leaving its own link unknown when its attributes cannot be read. Add a case with an unreadable GPU and a readable parent.tests/test_pcie_link.py:107: The standalone test defaults to g++ and ignores CXX. (more on the line) Do: Use the configured CXX or the repository's compiler discovery for the default while retaining the explicit --cxx override.Testing before merging (2) (runs on the systems it can change; it doesn't hold the recommendation)
gpu/vk/vk_main.cpp:1109: The default-on probe has not been exercised on the affected AMD drivers. (more on the line) Do: Run the game on AMD discrete GPUs on Windows and Linux and record the probe line and whether startup succeeds without driver errors.gpu/vk/vk_main.cpp:1109: The probe has not been exercised on Intel Arc or on a hybrid laptop displaying through its iGPU. (more on the line) Do: Run on Windows Intel Arc and on a hybrid laptop with the game on the dGPU; record the line and confirm normal startup or an explained not-measured result.@fixcan do L1, L2 and L3.Checks: Still running: 11 checks.
More: does it help, other systems, switches, what was read
Does it help: Yes: the reported Windows and Linux NVIDIA runs produced plausible link readings. The laptop comparison showed no clear frame-rate change across three runs per side; the feature has not yet been verified on AMD, Intel Arc or a hybrid laptop.
Other systems: The probe submits Vulkan copies on the replay queue before gameplay, so discrete GPUs and their drivers on Windows and Linux are affected. Integrated GPUs, including the Steam Deck's GPU, skip it. AMD, Intel Arc and a display-on-iGPU hybrid setup remain untested; the reported NVIDIA runs do not establish their behavior.
Switches: RX_VK_PCIE_PROBE is added as a kill switch, on by default for discrete GPUs; 0 skips both measurement and OS lookup. The row is present in switches.def. The default works on the two reported NVIDIA systems but needs the outstanding hardware coverage.
Reviewed:
92b13c0f7dagainste345b3cab4: Read AGENTS.md, CONTRIBUTING.md, the pull request template, the relevant standards, the full new probe, parsing header and test, the changed lines in vk_main.cpp and test_recorder_sync.py, and the surrounding device creation and build source selection. Skimmed the remainder of the large existing vk_main.cpp and test_recorder_sync.py, the commit history, and the reported runs. docs/review-checklist.md and the adjacent Tooling checkout were absent. No generated files or translations changed.; nothing run (a code review).Checked and fine:
Testing: Read-only review; no code or tests were run. The author reports in-game NVIDIA runs on Windows and Linux. CI was still running on this head.
Overlaps and merge order: #3162 is reported to carry this branch; its relationship and merge order could not be checked from the supplied information.
Automated code review by BeanBot (gpt-6.1-terra), asked for by HumanBean. Nothing was run; a maintainer decides.
@ -0,0 +74,4 @@const auto keep = [&](Hop& h, double gts, unsigned width) {const double g = link_gbps(gts, width);if (g > 0 && (!(h.gbps() > 0) || g < h.gbps())) {h.gts = gts, h.width = width;L2 (should fix): The first hop with readable data is treated as the GPU's own link even when the GPU's link was not readable.
When: On Linux, if the GPU's sysfs link attributes are unavailable but its parent bridge exposes them, the GPU entry is skipped and the bridge becomes own_now and own_most. The log then labels the bridge's speed and width as the GPU's own.
Do: Track the GPU entry independently of the count of readable hops, leaving its own link unknown when its attributes cannot be read. Add a case with an unreadable GPU and a readable parent.
@ -1105,1 +1106,4 @@gpu_clock_device_created(has_extension(exts, VK_EXT_PHYSICAL_DEVICE_DRM_EXTENSION_NAME));// (longshot: the PCIe link measured and read once, and logged: pcie_link.h; the PCI address from VK_EXT_pci_bus_info,// which needs no enabling to be asked either)pcie_link_probe(has_extension(exts, VK_EXT_PCI_BUS_INFO_EXTENSION_NAME));L4 (should fix): The default-on probe has not been exercised on the affected AMD drivers.
When: AMD discrete GPUs run the new allocation, transfer and timestamp path at startup on both Windows and Linux, but the supplied runs cover NVIDIA only.
Do: Run the game on AMD discrete GPUs on Windows and Linux and record the probe line and whether startup succeeds without driver errors.
L5 (should fix): The probe has not been exercised on Intel Arc or on a hybrid laptop displaying through its iGPU.
When: Both setups can select a discrete GPU and execute this new path, but neither the measured rates nor the selected device's OS link has been checked there.
Do: Run on Windows Intel Arc and on a hybrid laptop with the game on the dGPU; record the line and confirm normal startup or an explained not-measured result.
@ -0,0 +126,4 @@else {VkCommandBufferBeginInfo cbb{VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO};cbb.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;vkBeginCommandBuffer(cmd, &cbb);L1 (blocking): The probe ignores failures from beginning and ending its command buffer and proceeds to record and submit it.
When: If vkBeginCommandBuffer fails, for example under memory pressure, the following vkCmd calls target a command buffer that is not recording. If vkEndCommandBuffer fails, the code submits a buffer that is not executable; either path violates Vulkan requirements during game startup.
Do: Check both results, skip recording or submission on failure, report that the probe was not measured, and release the resources that are safe to destroy.
@ -0,0 +104,4 @@def main():parser = argparse.ArgumentParser(description=__doc__)parser.add_argument("--cxx", default="g++")L3 (should fix): The standalone test defaults to g++ and ignores CXX.
When: A Windows or Linux developer with CXX set to an installed clang++ but no g++ on PATH gets a compiler-not-found failure when running the documented test command, even though the configured compiler can run the test.
Do: Use the configured CXX or the repository's compiler discovery for the default while retaining the explicit --cxx override.
@fix
Recommendation: Approve. The code is ready: only testing is left. The probe reports useful link information and has worked on two NVIDIA systems, but the requested AMD, Intel Arc and hybrid-laptop runs remain outstanding. CI has also not yet run on this head. Recommend approval; not approved on the forge.
What
@fixchangedI changed this pull request: the new head is
b616795bfb. I mergedmain(921e6cbea8) into it, as it has merge commits. I edited its description to match the change.Changed
Nothing was built or run: the checks run again on the new head.
The change adds a startup log line measuring discrete-GPU transfer bandwidth and reporting the OS PCIe link. It adds a short startup cost and temporary buffers, with no intended per-frame work.
Testing before merging (2) (runs on the systems it can change; it doesn't hold the recommendation)
gpu/vk/vk_main.cpp:1109: The default-on probe has not been exercised on the affected AMD drivers. When: AMD discrete GPUs run the new allocation, transfer and timestamp path at startup on both Windows and Linux, but the supplied runs cover NVIDIA only. Do: Run the game on AMD discrete GPUs on Windows and Linux and record the probe line and whether startup succeeds without driver errors.gpu/vk/vk_main.cpp:1109: The probe has not been exercised on Intel Arc or on a hybrid laptop displaying through its iGPU. When: Both setups can select a discrete GPU and execute this new path, but neither the measured rates nor the selected device's OS link has been checked there. Do: Run on Windows Intel Arc and on a hybrid laptop with the game on the dGPU; record the line and confirm normal startup or an explained not-measured result.Checks: they run again on this head; a failure shows on the pull request.
Also noticed (1; not asked for, not blocking)
More: does it help, other systems, switches, what was read
Does it help: Yes for the diagnostic feature on the reported NVIDIA systems: the Windows RTX 5080 reported 26.8/26.4 GB/s in 19 ms, and the Linux RTX 3060 laptop reported 6.7/6.6 GB/s in 75 ms. The laptop's three interleaved runs per side showed no clear frame-rate change; the hardware coverage is incomplete.
Other systems: The probe runs on discrete GPUs on Windows and Linux. AMD drivers on both systems, Windows Intel Arc, and a hybrid laptop displaying through its integrated GPU still need the recorded startup checks.
Switches: RX_VK_PCIE_PROBE is added, default 1; setting it to 0 skips the probe. The default works on the reported NVIDIA systems, but its coverage on the other affected drivers remains unverified.
Reviewed:
b616795bfbagainst921e6cbea8: Read the fix diff, PCIe probe, parsing rules and PCIe test; inspected the repository rules and pull request template. The broader base diff includes merged changes beyond the listed PCIe files; those files and their surrounding code were not all read in full.; nothing run (a code review).Checked and fine:
Testing: No commands from the project were run. The author reports successful NVIDIA game runs on Windows and Linux; CI has not run on this head.
Overlaps and merge order: The author says #3162 carries this branch; its merge order was not established.
Automated code review by BeanBot (gpt-6.1-terra), asked for by BeanBot, after its fix. Nothing was run; a maintainer decides.