Skip to content

rust: obs-nvenc CUDA/NVENC driver loader (phase 1 of #520) - #529

Merged
zackees merged 4 commits into
masterfrom
port/obs-nvenc-loader
Oct 13, 2026
Merged

zackees merged 4 commits into
masterfrom
port/obs-nvenc-loader

Conversation

@zackees

@zackees zackees commented Oct 13, 2026

Copy link
Copy Markdown
Member

Refs #520 (phase 1 only; phase 2 is #525, the C shim swap is #524).

What

New crate rust/obs-nvenc (rlib, not yet linked into libobs-rust):

  • candidates(): OBS_{CUDA,NVENC,NVML}_LIBRARY override, then the C soname (libcuda.so.1), the unversioned symlink, distro/multiarch/NixOS paths, then WSL. Windows: bare DLL names loaded only from System32 (LOAD_LIBRARY_SEARCH_SYSTEM32), with the ARM64 nvEncodeAPI.dll order from nvenc-helpers.c. macOS: empty.
  • CudaDriver::load/load_from: first success wins; typed LoadError (NotFound with every dlerror, GlibcMismatch parsed from version 'GLIBC_x.y' not found, MissingSymbol, DriverTooOld). Display keeps the [NVENC] Test process failed: cuda_lib prefix.
  • Required symbol table equal to cuda_functions[] (same _v2 names, GL entries off on Windows); cuDriverGetVersion optional.
  • unsafe only in src/platform/{unix,windows}.rs (libloading), one cfg_select! in platform/mod.rs, no Dylint allowlist. libloading = "=0.8.9" as a workspace dependency.

Commits

  • RED b30c2c55e: tests/loader.rs against todo!() stubs: 17 failed, 1 passed (cuda_version_parts), 1 ignored.
  • GREEN 3d1ad78ab: 18 passed, 1 ignored.
  • Tier 3 6911ceaad (stamped).

Tests

  • Tier 1 (tests/loader.rs, 18 tests): every LoadError variant, Linux/Windows (x64 + ARM64)/macOS lists on every OS, env override, first-fails-second-succeeds, success-beats-glibc-mismatch, optional symbol, symbol table.
  • Opt-in real_gpu_loads (#[ignore]): on a NixOS host it loaded /run/opengl-driver/lib/libcuda.so.1 (DistroPath) and reported driver 13.2. The C plugin's single libcuda.so.1 lookup would rely on the loader search path there.
  • Tier 2: none (no C symbol replaced).
  • Tier 3 (tests/loader_parity.rs, 3 tests): the Rust search starts with the exact name C's load_cuda_lib/load_nvenc_lib open, and required_cuda_symbols equals cuda_functions[].
    • Design decision: cuda-helpers.c/nvenc-helpers.c cannot be compiled whole in the oracle (they need nv-codec-headers, glad, D3D11). obs-c-oracle/build.rs copies the original lines of those three items verbatim (with #line, panics if the markers move) and oracle/obs_nvenc_loader.c compiles them with a recording os_dlopen and a stub offsetof. plugins/obs-nvenc is added to the oracle input hash.
    • Mutation check: swapping libcuda.so.1/libcuda.so, renaming libnvidia-encode.so.1, and cuCtxCreate_v2 to cuCtxCreate in the Rust core made all 3 parity tests fail. With the changes reverted, they pass.
    • No proptest, because the input is a fixed list with no random input space. The intended difference from C is the extra fallbacks after the first name.
  • Tier 4: N/A.

Gate

./lint ok, ./unittest ok (rust-test incl. windows-gnu cross build, tier2-linux), local-gate stamped on 6911cea.

No C headers, C tests, plugin C files or workflow files are changed.

Still open on #520: the decision comment on phase 2, which needs the #427 CI-minutes data.

Adds the rust/obs-nvenc crate skeleton (candidate lists, typed LoadError,
DynLoader seam, libloading-backed SystemLoader in src/platform/) with the
safe core stubbed. tests/loader.rs: 17 of 18 tests fail on todo!().

Refs #520
…nctions table (#520)

Candidate lists per host (env override, soname, unversioned, distro and
NixOS paths, WSL; System32-only DLL names on Windows; none on macOS),
first-success walk with GLIBC_x.y dlerror parsing, the cuda_functions[]
symbol table with the same _v2 names, and cuDriverGetVersion. All 18
Tier 1 tests pass; the ignored real_gpu_loads smoke test loads
/run/opengl-driver/lib/libcuda.so.1 (driver 13.2) on a NixOS host.

Refs #520
…520)

obs-c-oracle copies the original load_cuda_lib(), cuda_functions[] and
load_nvenc_lib() lines verbatim (build.rs, with #line markers; the whole
files need nv-codec-headers) and compiles them in oracle/obs_nvenc_loader.c
with a recording os_dlopen. tests/loader_parity.rs asserts the Rust search
starts with the exact name C opens and the required symbol table equals
cuda_functions[]. plugins/obs-nvenc is added to the oracle input hash.

Mutation check: swapping libcuda.so.1/libcuda.so, renaming
libnvidia-encode.so.1, and dropping _v2 from cuCtxCreate_v2 in the Rust
core fails all 3 parity tests; restored, all pass.

Refs #520

Local-Gate: v1 tree=90fb0d918bf242fda6c272f0ee9474a10ab0994c secs=383 lanes=lint:run,rust-test:run,tier2-linux:run
Ci-Attestation: {"at":1791884124,"gate":"rust/all/fmt","host":"linux-x86_64","key":"4b595d4bbc8d0053b8c6d79981e88a05922e6fb837c89c86fb0c51ff44980b35","lane":"lint","parents":["3d1ad78ab12b745a0365d929adc2f2a39ef502eb"],"secs":75,"stamp":"e8ada8ff64e0d0ac90c01fba944124df","tree":"90fb0d918bf242fda6c272f0ee9474a10ab0994c","v":1,"via":"run"}
Ci-Attestation: {"at":1791884124,"gate":"rust/x86_64-unknown-linux-gnu/clippy","host":"linux-x86_64","key":"4b595d4bbc8d0053b8c6d79981e88a05922e6fb837c89c86fb0c51ff44980b35","lane":"lint","parents":["3d1ad78ab12b745a0365d929adc2f2a39ef502eb"],"secs":75,"stamp":"7ded1fd86ed52d37e898b17e9d7da2ff","tree":"90fb0d918bf242fda6c272f0ee9474a10ab0994c","v":1,"via":"run"}
Ci-Attestation: {"at":1791884124,"gate":"rust/x86_64-unknown-linux-gnu/test","host":"linux-x86_64","key":"524bbd5e1ff902058fa4fc8401353c3b6e525d7de595cb86cae9e44b4e1003b2","lane":"rust-test","parents":["3d1ad78ab12b745a0365d929adc2f2a39ef502eb"],"secs":244,"stamp":"2d88f4d341c584035621aba83af50117","tree":"90fb0d918bf242fda6c272f0ee9474a10ab0994c","v":1,"via":"run"}
Ci-Attestation: {"at":1791884124,"gate":"cpp/linux-x64/tier2","host":"linux-x86_64","key":"853c9ee0cf8c5dc5a8615d5249672bae6d9cca8ee383c655cb0b6b9b371d88dc","lane":"tier2-linux","parents":["3d1ad78ab12b745a0365d929adc2f2a39ef502eb"],"secs":64,"stamp":"48fafb2cd8b882e7cbe55d985be254f1","tree":"90fb0d918bf242fda6c272f0ee9474a10ab0994c","v":1,"via":"run"}
Keep extract_c next to the #516 strict flags, and declare the nvenc
oracle's exported functions for -Wmissing-prototypes.

Local-Gate: v1 tree=214f4ee974d1d87f94467b841d6483610ef5c98d secs=506 lanes=lint:run,rust-test:run,cross:run,tier2-linux:run
Ci-Attestation: {"at":1791903015,"gate":"rust/all/fmt","host":"linux-x86_64","key":"093b0888e99ed353c649d6231c7b8971b38f0498abe897ef86cb93292cb51e09","lane":"lint","parents":["6911ceaadd9b67b7d38878599d29348e840f8daa","56ae6bcb8f54443ccc06eaec470cd89b7a8e525a"],"secs":137,"stamp":"24a9802a0ee7205a89b030a32cfb703a","tree":"214f4ee974d1d87f94467b841d6483610ef5c98d","v":1,"via":"run"}
Ci-Attestation: {"at":1791903015,"gate":"rust/x86_64-unknown-linux-gnu/clippy","host":"linux-x86_64","key":"093b0888e99ed353c649d6231c7b8971b38f0498abe897ef86cb93292cb51e09","lane":"lint","parents":["6911ceaadd9b67b7d38878599d29348e840f8daa","56ae6bcb8f54443ccc06eaec470cd89b7a8e525a"],"secs":137,"stamp":"d18b79eed5103ad9b6c7ef0caf14d07c","tree":"214f4ee974d1d87f94467b841d6483610ef5c98d","v":1,"via":"run"}
Ci-Attestation: {"at":1791903015,"gate":"rust/x86_64-unknown-linux-gnu/test","host":"linux-x86_64","key":"b13a3e4e8d44fe75aca42552a99cc2eaa911ca71a18b8d7fd9d20874814a178f","lane":"rust-test","parents":["6911ceaadd9b67b7d38878599d29348e840f8daa","56ae6bcb8f54443ccc06eaec470cd89b7a8e525a"],"secs":122,"stamp":"6f8ba9153dc09b2aef5b7e50bdad8ed2","tree":"214f4ee974d1d87f94467b841d6483610ef5c98d","v":1,"via":"run"}
Ci-Attestation: {"at":1791903015,"gate":"rust/x86_64-pc-windows-msvc/clippy","host":"linux-x86_64","key":"fb9a549b6c4ef65f9f0f4b3cf8a0d30709759bdedded7c00c95d24576e528e04","lane":"cross","parents":["6911ceaadd9b67b7d38878599d29348e840f8daa","56ae6bcb8f54443ccc06eaec470cd89b7a8e525a"],"secs":130,"stamp":"97ea6da0224fe8ef77e08efe6fbc2505","tree":"214f4ee974d1d87f94467b841d6483610ef5c98d","v":1,"via":"run"}
Ci-Attestation: {"at":1791903015,"gate":"rust/x86_64-pc-windows-msvc/dylint","host":"linux-x86_64","key":"fb9a549b6c4ef65f9f0f4b3cf8a0d30709759bdedded7c00c95d24576e528e04","lane":"cross","parents":["6911ceaadd9b67b7d38878599d29348e840f8daa","56ae6bcb8f54443ccc06eaec470cd89b7a8e525a"],"secs":130,"stamp":"413af48c100cac15ebd4f0742e91974c","tree":"214f4ee974d1d87f94467b841d6483610ef5c98d","v":1,"via":"run"}
Ci-Attestation: {"at":1791903015,"gate":"rust/aarch64-apple-darwin/clippy","host":"linux-x86_64","key":"fb9a549b6c4ef65f9f0f4b3cf8a0d30709759bdedded7c00c95d24576e528e04","lane":"cross","parents":["6911ceaadd9b67b7d38878599d29348e840f8daa","56ae6bcb8f54443ccc06eaec470cd89b7a8e525a"],"secs":130,"stamp":"b7654c81b4f0a5e86b81522bc4559a52","tree":"214f4ee974d1d87f94467b841d6483610ef5c98d","v":1,"via":"run"}
Ci-Attestation: {"at":1791903015,"gate":"rust/aarch64-apple-darwin/dylint","host":"linux-x86_64","key":"fb9a549b6c4ef65f9f0f4b3cf8a0d30709759bdedded7c00c95d24576e528e04","lane":"cross","parents":["6911ceaadd9b67b7d38878599d29348e840f8daa","56ae6bcb8f54443ccc06eaec470cd89b7a8e525a"],"secs":130,"stamp":"c67261876c92d68f25be28acbaa61c78","tree":"214f4ee974d1d87f94467b841d6483610ef5c98d","v":1,"via":"run"}
Ci-Attestation: {"at":1791903015,"gate":"rust/x86_64-apple-darwin/clippy","host":"linux-x86_64","key":"fb9a549b6c4ef65f9f0f4b3cf8a0d30709759bdedded7c00c95d24576e528e04","lane":"cross","parents":["6911ceaadd9b67b7d38878599d29348e840f8daa","56ae6bcb8f54443ccc06eaec470cd89b7a8e525a"],"secs":130,"stamp":"4af16c91d7443888ada96f552fd0aa0a","tree":"214f4ee974d1d87f94467b841d6483610ef5c98d","v":1,"via":"run"}
Ci-Attestation: {"at":1791903015,"gate":"rust/x86_64-apple-darwin/dylint","host":"linux-x86_64","key":"fb9a549b6c4ef65f9f0f4b3cf8a0d30709759bdedded7c00c95d24576e528e04","lane":"cross","parents":["6911ceaadd9b67b7d38878599d29348e840f8daa","56ae6bcb8f54443ccc06eaec470cd89b7a8e525a"],"secs":130,"stamp":"97a8a45b954567a11634f446fe988e6c","tree":"214f4ee974d1d87f94467b841d6483610ef5c98d","v":1,"via":"run"}
Ci-Attestation: {"at":1791903015,"gate":"cpp/linux-x64/tier2","host":"linux-x86_64","key":"0a00f5f9df6fa38cb1320f1c0291da542d71aec3ae8d3268b5c9949f67506d89","lane":"tier2-linux","parents":["6911ceaadd9b67b7d38878599d29348e840f8daa","56ae6bcb8f54443ccc06eaec470cd89b7a8e525a"],"secs":117,"stamp":"9bc9a8428c7d53445bd659e5f7b4d2eb","tree":"214f4ee974d1d87f94467b841d6483610ef5c98d","v":1,"via":"run"}
@zackees
zackees merged commit fd1b5bc into master Oct 13, 2026
21 checks passed
@zackees
zackees deleted the port/obs-nvenc-loader branch October 26, 2026 15:46
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.

1 participant