Skip to content

obs-gpu-status: Pick the macOS render GPU by registry ID - #1195

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

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

Conversation

@vpacher

@vpacher vpacher commented Oct 17, 2026 •

Copy link
Copy Markdown
Member

Refs #1020 (macOS part; Linux was #1194, the Windows DXGI LUID part is #1198)

What and why

On macOS the key for the GPU that OBS renders on is its IORegistry entry ID. MTLDevice.registryID of the default Metal device equals the entry ID of the GPU's IOAccelerator service, and that service holds the PerformanceStatistics that #1026 reads. Checked on two machines:

Machine MTLCreateSystemDefaultDevice().registryID ioreg -c IOAccelerator
M1 Max 0x100000b5b AGXAcceleratorG13X, id 0x100000b5b
M1 (Mac mini) 0x100000648 AGXAcceleratorG13G_B0, id 0x100000648

Both renderers use Metal's default GPU: libobs-metal creates its device with MTLCreateSystemDefaultDevice() (device_create ignores the adapter number), and the Cocoa OpenGL context does not allow offline renderers. So no frontend plumbing is needed on macOS; the render node argument is unused there.

This PR:

  1. Adds RenderAdapter::RegistryId(u64).
  2. Adds render_adapter_from_registry(render, gpus) (pure): a Metal ID is the answer if IOKit lists it or lists nothing; a Metal ID that IOKit does not list is Unknown (the sources disagree, so nothing is picked). Without a Metal device, one GPU is the answer and two or more are Ambiguous.
  3. Adds platform/macos.rs: MTLCreateSystemDefaultDevice + -registryID (through objc_msgSend, cast to the method's exact type) and IOServiceGetMatchingServices("IOAccelerator") + IORegistryEntryGetRegistryEntryID. Metal, IOKit and libobjc are opened with libloading (macOS-only dependency, already in the workspace for obs-nvenc), so no framework is added to the link.
  4. platform::render_adapter() uses it on macOS. Other non-Linux, non-Windows hosts return Unknown.

Not tested on real hardware: a Mac with two GPUs (Intel MacBook Pro with integrated + discrete). The fixture covers that case.

RED → GREEN

  • RED commit: 55d5c10 adds 6 cases to tests/gpu_status/render_adapter.rs with a stub that returns Unknown. 4 fail (Apple Silicon and the discrete GPU of a two-GPU MacBook Pro in one case, a Metal ID without an IOKit list, one GPU without a Metal device, two GPUs without one); the 2 Unknown cases pass with the stub.
  • GREEN commit: 9ce881c. 65/65 crate tests pass on macOS; clippy -D warnings, rustfmt and dylint clean on macOS. ./lint passes on Linux (Debian 13) with --with pyyaml (see note below).
  • Real hosts: probe prints RegistryId(4294970203) (= 0x100000b5b) on the M1 Max and RegistryId(4294968904) (= 0x100000648) on the M1, the IDs in the table above.

Note: on master, ./lint fails on hosts without a system PyYAML: ci/test_ccache_launcher_installed.py declares pyyaml as an inline script dependency, but the gate runs it with python -m unittest. Not part of this PR.

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 requested a review from zackees as a code owner October 17, 2026 07:23
@vpacher
vpacher force-pushed the feat/gpu-render-adapter-macos branch from 0a7b98f to 7bdd8c0 Compare October 17, 2026 07:39
@vpacher

vpacher commented Oct 17, 2026

Copy link
Copy Markdown
Member Author

Force-pushed after rebasing onto the updated #1194 (its RED test file now gates the Linux fixture helpers on cfg(unix), which fixed the Windows clippy dead-code failure there). The two commits of this PR are unchanged in content: bb9c6df (RED), 7bdd8c0 (GREEN). Sorry for the stale approval.

@zackees

zackees commented Oct 17, 2026

Copy link
Copy Markdown
Member

#1194 merged (08:17). This PR still carries #1194's two commits and GitHub can't rebase it automatically (RebaseConflictError). Please rebase onto master and drop #1194's commits (git rebase --onto origin/master <last #1194 commit> ), then I'll queue it. #1198 next once this lands.

vpacher and others added 2 commits October 17, 2026 10:41
On macOS the key for the render GPU is its IORegistry entry ID:
MTLDevice.registryID of the default Metal device equals the entry ID of
its IOAccelerator, which also holds the PerformanceStatistics that
obs-rust#1026 reads (checked on an M1 Max: both 0x100000b5b).

render_adapter_from_registry() and RenderAdapter::RegistryId are a stub
that returns Unknown, so the cases that need a pick fail: Apple Silicon,
the discrete GPU of a two-GPU MacBook Pro, a Metal ID without an IOKit
list, and one or two GPUs without a Metal device.

Refs obs-rust#1020

Co-Authored-By: Claude Opus 5.5 <[email protected]>
render_adapter_from_registry() takes the registry ID of Metal's default
GPU and the registry IDs of the IOAccelerator services. A Metal ID is
the answer if IOKit lists it or lists nothing; one IOKit says is not
there is Unknown. Without a Metal device, one GPU is the answer and two
or more are Ambiguous.

platform/macos.rs reads both sources: MTLCreateSystemDefaultDevice and
-registryID through objc_msgSend, and IOServiceGetMatchingServices for
"IOAccelerator" with IORegistryEntryGetRegistryEntryID. Metal, IOKit and
libobjc are opened with libloading (macOS-only dependency, already in
the workspace for obs-nvenc), so no framework is added to the link.

Both renderers use Metal's default GPU: libobs-metal creates its device
with MTLCreateSystemDefaultDevice, and the Cocoa OpenGL context does not
allow offline renderers.

Refs obs-rust#1020

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@vpacher
vpacher force-pushed the feat/gpu-render-adapter-macos branch from 7bdd8c0 to 9ce881c Compare October 17, 2026 08:42
@vpacher

vpacher commented Oct 17, 2026

Copy link
Copy Markdown
Member Author

Rebased onto master (f861687) with #1194's commits dropped (git rebase --onto origin/master 726d4fd67; #1194's squash f49e7aa has the same tree for rust/obs-gpu-status). Now only this PR's two commits: 55d5c10 (RED, 4/65 fail) and 9ce881c (GREEN, 65/65). clippy -D warnings clean on macOS and for x86_64-pc-windows-msvc. Description updated (no longer stacked). #1198 is rebased onto it.

@zackees
zackees added this pull request to the merge queue Oct 17, 2026
Merged via the queue into obs-rust:master with commit 9c67adb Oct 17, 2026
25 of 26 checks passed
@vpacher
vpacher deleted the feat/gpu-render-adapter-macos branch October 17, 2026 12:02
vpacher added a commit to vpacher/obs-studio that referenced this pull request Oct 17, 2026
obs-rust#1262)

* obs-gpu-status: macOS Device Utilization % parser (RED, Refs obs-rust#1026)

Tier 1 tests for iokit::device_utilization on a PerformanceStatistics
dictionary captured from an M1 Max (macOS 26.7.1) while the GPU was
busy. The stub returns Unavailable: the captured dictionary and the 0
and 100 bounds fail; a missing key and values outside 0 to 100 pass.

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

* obs-gpu-status: macOS Device Utilization % parser (GREEN, Refs obs-rust#1026)

iokit::device_utilization takes the PerformanceStatistics number entries
and returns Device Utilization % as the whole-GPU percent. Renderer and
Tiler Utilization % are parts of the GPU and do not stand in for it. A
missing key or a value outside 0 to 100 is Unavailable. 129/129 crate
tests pass.

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

* obs-gpu-status: macOS GPU: x% from IOKit (Fixes obs-rust#1026)

platform::usage_sources() gets an IOKit source on macOS. It reads the
PerformanceStatistics dictionary of the IOAccelerator service with the
render adapter's registry ID (obs-rust#1195) through IORegistryEntryIDMatching
and IORegistryEntryCreateCFProperty, and gives its number entries to
iokit::device_utilization. IOKit and CoreFoundation open at run time
through libloading, as the rest of the macOS code does. The JSON source
name is "iokit".

The probe prints the label's sample. On an M1 Max (macOS 26.7.1) the
render adapter is 0x100000b5b (AGXAcceleratorG13X); the sample is 13 %
idle and 99 % under a Metal compute load, the same as ioreg, in about
0.6 ms. clippy -D warnings is clean for macOS and Windows.

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

* docs: GPU status label screenshot on macOS (Refs obs-rust#1026)

The status bar of this branch's app on an M1 Max under a Metal compute
load: GPU: 99% with a green dot (ioreg: Device Utilization % 98).

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.

2 participants