Skip to content

obs-gpu-status: Resolve the render node's PCI device (Linux) - #1194

Merged
zackees merged 2 commits into
obs-rust:masterfrom
vpacher:feat/gpu-render-adapter-pci
Oct 17, 2026
Merged

zackees merged 2 commits into
obs-rust:masterfrom
vpacher:feat/gpu-render-adapter-pci

Conversation

@vpacher

@vpacher vpacher commented Oct 17, 2026 •

Copy link
Copy Markdown
Member

Refs #1020 (Linux part; Windows DXGI LUID and macOS Metal registryID stay open)

What and why

Every GPU utilization source (#1021 NVML, #1023 fdinfo, #1024 amdgpu) must measure the GPU that OBS renders on. On a machine with two identical cards, the vendor and device IDs do not tell them apart; the PCI address does.

On Linux, EGL names the render node of the display's device. gl_egl_enum_adapters() already reports it as adapter 0 (/dev/dri/renderD128, or /Software without one). This PR adds the resolution from that node to its PCI device:

  1. render_adapter(root, render_node) in rust/obs-gpu-status reads the node's sysfs device link (/sys/class/drm/renderD128/device → ../../../0000:2b:00.0) and returns RenderAdapter::Pci("0000:2b:00.0").
  2. Without a render node (GLX, or EGL without EGL_EXT_device_drm_render_node), one PCI card is the answer. Two or more give RenderAdapter::Ambiguous; the function never guesses.
  3. /Software, names that are not renderD<n> (also .. paths), non-PCI devices (Arm platform GPUs) and a missing sysfs give RenderAdapter::Unknown.
  4. platform::render_adapter() runs it against / on Linux. On Windows and macOS it returns Unknown until their parts of obs-gpu-status: Identify the render adapter's PCI bus ID on every platform #1020 land.
  5. The probe example prints the result for a node given as its argument.

The frontend does not call it yet. The first consumer, #1021, passes adapter 0's name from gs_enum_adapters(); no libobs-opengl change is needed for that.

RED → GREEN

  • RED commit: 10447b9 adds tests/gpu_status/render_adapter.rs (7 cases) with a stub that returns Unknown. The fixture builds sysfs as the kernel does: class/drm/<node> links into the PCI device, and the node's device link points back up. 3 of 7 fail (two identical 10de:2504 cards on 0000:2b:00.0 and 0000:2c:00.0, one card without a node, two cards without a node); the 4 Unknown cases pass with the stub.
  • GREEN commit: 726d4fd. 57/57 crate tests pass (59/59 after rebasing onto frontend: GPU status runs nvidia-smi (~40 ms) on the startup path #1172); clippy -D warnings clean on macOS, Linux and for x86_64-pc-windows-msvc; rustfmt clean.
  • Real host: Debian 13 LXC container, RTX 3060 (10de:2504), /sys/class/drm/renderD128/device → ../../../0000:2b:00.0. probe /dev/dri/renderD128 prints Pci("0000:2b:00.0"); probe without a node prints the same (one card); probe /Software prints Unknown.
  • ./lint passes on Linux (fmt, clippy -D warnings, dylint, ci/test_*.py).

Checklist

  • Base is master (or the description starts with a Stacked: note)
  • I claimed the issue, or no one else has an open PR for it
  • Characterization test (if the unit had none), then RED, then GREEN commits
  • (Optional) Local gate passed and the pushed head is stamped; otherwise PR CI runs the full suite
  • Warning or flag changes (-W..., ratchets): built with scripting ON (a flag change under cmake/ or build-aux/ runs the full builds) and cross-checked with clang and MSVC (not applicable: no flag changes)
  • Intentional differences from C listed in the parity test header and rust/README.md (ports) (not applicable: not a port)

🤖 Generated with Claude Code

vpacher and others added 2 commits October 17, 2026 09:38
Every GPU utilization source (obs-rust#1021 NVML, obs-rust#1023 fdinfo, obs-rust#1024 amdgpu)
must measure the GPU OBS renders on, not any GPU. On Linux, EGL names
the render node of the display's device (adapter 0 in
gl_egl_enum_adapters, "/Software" without one); sysfs maps the node to
its PCI device.

render_adapter() is a stub that returns Unknown, so the fixture cases
fail: two identical cards (10de:2504) on different PCI addresses, one
card without a render node, and no node with two cards (Ambiguous, never
a guess).

Refs obs-rust#1020

Co-Authored-By: Claude Opus 5.5 <[email protected]>
render_adapter() maps the render node that EGL reports for the display
(/dev/dri/renderD128) to its PCI address through the node's sysfs
`device` link (../../../0000:2b:00.0). Without a render node, one PCI
card is the answer and two or more are Ambiguous. "/Software", other
names and non-PCI devices are Unknown.

platform::render_adapter() runs it against "/" on Linux. Windows (DXGI
LUID) and macOS (Metal registryID) return Unknown until their parts of
obs-rust#1020 land. The probe example prints the result for a given node.

Refs obs-rust#1020

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@vpacher
vpacher force-pushed the feat/gpu-render-adapter-pci branch from a5aba93 to 726d4fd Compare October 17, 2026 07:39
@vpacher

vpacher commented Oct 17, 2026

Copy link
Copy Markdown
Member Author

Force-pushed (10447b9, 726d4fd): the Windows clippy failure was mine. The sysfs fixture helpers (gpu, symlink, two_identical_cards) were used only by the cfg(unix) tests, so -D warnings failed on Windows (dead code). They are now cfg(unix) as well, and the non-unix symlink stub is gone. Checked with soldr cargo clippy -p obs-gpu-status --all-targets --target x86_64-pc-windows-msvc -- -D warnings. RED still fails 3/7 here, GREEN passes. Only the RED commit's test file changed; the branch is also rebased onto master.

Separate from this PR: the "CI Pre / Cache Janitor" job fails on fork PRs with HTTP Error 403: Forbidden when it deletes caches (the fork PR token is read-only), e.g. run 39012965303.

@zackees
zackees added this pull request to the merge queue Oct 17, 2026
Merged via the queue into obs-rust:master with commit f49e7aa Oct 17, 2026
25 of 26 checks passed
@vpacher
vpacher deleted the feat/gpu-render-adapter-pci branch October 17, 2026 08:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants