Skip to content

obs-gpu-status: Pick the Windows render GPU by LUID - #1198

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

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

Conversation

@vpacher

@vpacher vpacher commented Oct 17, 2026 •

Copy link
Copy Markdown
Member

Stacked: on #1195 (macOS); #1194 (Linux) is merged. Review only the last two commits: f773709 (RED) and 6a7f585 (GREEN). Once #1195 merges, this PR shrinks to them.

Fixes #1020 (with #1194 for Linux and #1195 for macOS)

What and why

libobs-d3d11 renders on EnumAdapters1(adapterIdx) (gs_device::InitAdapter), and adapterIdx is obs_video_info.adapter, which the frontend already reads in GpuStatus.cpp. The key for that adapter is its DXGI LUID, which PDH's "GPU Engine" counters (#1022) also use in their instance names (luid_0x..._0x..._phys_0).

This PR:

  1. Adds AdapterDesc::luid (AdapterLuid as one number, HighPart in the upper 32 bits), filled in platform/windows.rs from DXGI_ADAPTER_DESC1, and RenderAdapter::Luid(u64).
  2. Adds dxgi::render_adapter_from_dxgi(index, adapters) (pure). Only GPUs count, with the rule devices_from_dxgi already uses (feat: Windows GPU detection through DXGI adapter enumeration #942): not a software adapter, not Microsoft's, a known GPU vendor. An index on anything else (WARP, a VM's display adapter, virtio) or past the list is Unknown. Without an index, one GPU is the answer and two or more are Ambiguous.
  3. Changes platform::render_adapter() to take a RenderHint: the EGL render node on Linux, the adapter index on Windows; macOS needs neither. This replaces the Option<&str> argument from obs-gpu-status: Resolve the render node's PCI device (Linux) #1194, so each platform gets the identifier libobs actually has. The frontend does not call it yet; the first consumer is obs-gpu-status: NVIDIA utilization through NVML (dlopen), matched by PCI bus ID #1021/obs-gpu-status: Windows GPU utilization through PDH GPU Engine counters #1022.
  4. Adds a smoke test, host_render_adapter_does_not_panic, that runs the real host path on every platform (sysfs, Metal/IOKit, DXGI).
  5. The probe example reads a number as the adapter index and anything else as a render node, and prints registry IDs and LUIDs in hex.

Mapping a LUID to a PCI address (for NVML on Windows, #1021) is not part of this PR: D3DKMTQueryAdapterInfo(KMTQAITYPE_ADAPTERADDRESS) can do it when #1021 needs it.

RED → GREEN

  • RED commit: f773709 adds 6 cases to tests/gpu_status/dxgi.rs with a stub that returns Unknown. 4 fail: an index among two identical RTX 3060s with different LUIDs, one GPU without an index, two GPUs without an index, and a known GPU next to a virtio adapter. The 2 Unknown cases (WARP or out-of-range index, a VM with Microsoft adapters only) pass with the stub. The 5 existing DXGI tests still pass.
  • GREEN commit: 6a7f585. 72/72 crate tests pass on macOS and Linux. clippy -D warnings is clean on macOS, Linux and for x86_64-pc-windows-msvc (soldr cargo clippy --target x86_64-pc-windows-msvc). ./lint passes on Linux (Debian 13, with --with pyyaml, see ci: the local gate's lint lane fails without a system PyYAML (test_ccache_launcher_installed.py) #1196).
  • Real host: no Windows machine with a GPU here. The DXGI path runs on CI's Windows runner through the smoke test (Microsoft adapters only, so the result there is Unknown). On Linux, the probe with the new RenderHint still resolves /dev/dri/renderD128 to Pci("0000:2b:00.0") (RTX 3060); on macOS it returns RegistryId(0x100000b5b) (M1 Max).

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

vpacher commented Oct 17, 2026

Copy link
Copy Markdown
Member Author

Rebased onto the updated #1195 (now on master, #1194 merged). This PR's commits: f773709 (RED) and 6a7f585 (GREEN, 72/72); the stack note in the description is updated.

vpacher and others added 2 commits October 17, 2026 03:51
libobs-d3d11 renders on EnumAdapters1(obs_video_info.adapter). The key
for that adapter is its DXGI LUID, which PDH's "GPU Engine" counters
(obs-rust#1022) also use in their instance names.

AdapterDesc gets a `luid` field (still 0 from DXGI here) and
RenderAdapter a Luid variant. dxgi::render_adapter_from_dxgi() is a
stub that returns Unknown, so the cases that need a pick fail: an index
among two identical RTX 3060s, one or two GPUs without an index, and a
known GPU next to a virtio display adapter (as in devices_from_dxgi,
an unknown vendor is not a GPU).

Refs obs-rust#1020

Co-Authored-By: Claude Opus 5.5 <[email protected]>
dxgi::render_adapter_from_dxgi() takes the EnumAdapters1 index that
libobs-d3d11 renders on (obs_video_info.adapter) and returns that
adapter's LUID. Only GPUs count, with the same rule as devices_from_dxgi
(not software, not Microsoft's, a known GPU vendor). An index on
anything else (WARP, a VM's display adapter) or past the list is
Unknown. Without an index, one GPU is the answer and two or more are
Ambiguous.

platform/windows.rs fills AdapterDesc::luid from AdapterLuid (HighPart
in the upper 32 bits).

platform::render_adapter() now takes a RenderHint: the EGL render node
on Linux, the adapter index on Windows; macOS needs neither. A smoke
test runs the host path on every platform (on CI's Windows runner:
Microsoft adapters only). The probe example reads a number as the index
and anything else as a node, and prints registry IDs and LUIDs in hex.

Refs obs-rust#1020

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@zackees
zackees force-pushed the feat/gpu-render-adapter-windows branch from 6a7f585 to 0d6da23 Compare October 17, 2026 10:51
@zackees

zackees commented Oct 17, 2026

Copy link
Copy Markdown
Member

Rebased onto master now that #1195 merged as a squash: dropped its two commits, leaving only this PR's RED and GREEN Windows commits. Will queue once CI is green.

@zackees
zackees added this pull request to the merge queue Oct 17, 2026
Merged via the queue into obs-rust:master with commit 18a9f9d Oct 17, 2026
26 checks passed
@vpacher
vpacher deleted the feat/gpu-render-adapter-windows branch October 17, 2026 12:02
vpacher added a commit to vpacher/obs-studio that referenced this pull request Oct 17, 2026
platform::usage_sources() asks the PDH GPU Engine counters (obs-rust#1022,
LUID (obs-rust#1198) through pdh_utilization, the busiest engine as Task
Manager shows it, for every vendor. NVML cannot map the LUID to a PCI
address yet, so PDH also reads NVIDIA GPUs on Windows. One sample
blocks for 100 ms on the obs-gpu-usage thread, never the UI thread.
The JSON source name is "pdh". 125/125 crate tests pass on macOS;
clippy -D warnings is clean for macOS and x86_64-pc-windows-msvc.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
vpacher added a commit to vpacher/obs-studio that referenced this pull request Oct 17, 2026
platform::usage_sources() asks the PDH GPU Engine counters (obs-rust#1022,
LUID (obs-rust#1198) through pdh_utilization, the busiest engine as Task
Manager shows it, for every vendor. NVML cannot map the LUID to a PCI
address yet, so PDH also reads NVIDIA GPUs on Windows. One sample
blocks for 100 ms on the obs-gpu-usage thread, never the UI thread.
The JSON source name is "pdh". 125/125 crate tests pass on macOS;
clippy -D warnings is clean for macOS and x86_64-pc-windows-msvc.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
chriscoveries pushed a commit to chriscoveries/obsrust-fork that referenced this pull request Oct 17, 2026
…t#1264)

* obs-gpu-status: Windows GPU: x% from PDH (RED, Refs obs-rust#1025)

Source::Pdh names the Windows PDH GPU Engine counters (obs-rust#1022) in the
JSON; the stub name is empty, so source_names fails. A Windows-only
test requires usage_sources() to ask NVML, then PDH; it fails on
Windows, where PDH is not wired in yet.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* obs-gpu-status: Windows GPU: x% from PDH (GREEN, Refs obs-rust#1025)

platform::usage_sources() asks the PDH GPU Engine counters (obs-rust#1022,
LUID (obs-rust#1198) through pdh_utilization, the busiest engine as Task
Manager shows it, for every vendor. NVML cannot map the LUID to a PCI
address yet, so PDH also reads NVIDIA GPUs on Windows. One sample
blocks for 100 ms on the obs-gpu-usage thread, never the UI thread.
The JSON source name is "pdh". 125/125 crate tests pass on macOS;
clippy -D warnings is clean for macOS and x86_64-pc-windows-msvc.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* docs: GPU: x% ledger line covers macOS and Windows (Refs obs-rust#1025)

The features ledger line for the GPU: x% label names all three
platforms and their sources: NVML and gpu_busy_percent on Linux, IOKit
on macOS (obs-rust#1262, merged before the ledger existed) and PDH on Windows.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
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.

obs-gpu-status: Identify the render adapter's PCI bus ID on every platform

2 participants