Skip to content

rust: Fill obs-nvenc CudaFunctions from the Rust driver loader - #592

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

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

Conversation

@zackees

@zackees zackees commented Oct 13, 2026

Copy link
Copy Markdown
Member

Fixes #524 (refs #520, #498).

Commits

  1. obs-nvenc: Move the CUDA/NVENC library loaders into their own files - behaviour-neutral extraction: load_cuda_lib, cuda_functions[], init_cuda_internal to cuda-load.c; load_nvenc_lib to nvenc-load.c. Two plugin-private header declarations added; the Tier 3 oracle extraction now reads the new files. No Rust logic.
  2. RED (aa885d847): rust/obs-nvenc/tests/ffi.rs against a stubbed fill_table. 6 of 6 fail: fake-driver fill, [NVENC] Test process failed: cuda_lib string, Could not load function string, truncation, plugin CMake wiring (one more test, C table identity, was added in GREEN).
  3. GREEN: obs_nvenc_cuda_fill (rust/obs-nvenc/src/ffi) fills CudaFunctions from CudaDriver. C passes its own {offsetof, name} rows, so no CUDA struct is mirrored in Rust. cuda-load-rust.c (built only when ENABLE_RUST_LIBOBS is ON; cuda-load.c is dropped) logs the LoadError text and sets the same encoder errors ("Loading CUDA library failed." / "Loading CUDA functions failed."). Also teaches rust/obs-util/tests/export_list.rs that only libobs-rust dependencies export from libobs.

Link decision: plugin link, not libobs-rust re-export

rust/obs-nvenc is a rlib + staticlib linked into obs-nvenc via Corrosion. libobs must link exactly one Rust staticlib and keep the C build's exported symbol set (version script, Windows /EXPORT fragments, macOS unexports); only this plugin calls the shim, so routing it through libobs would add plugin ABI to libobs for nothing. The plugin uses --exclude-libs,ALL so its copy of std does not leak into the dynamic table.

Scope notes

  • load_nvenc_lib is extracted but stays C: there is no Rust NVENC loader wired yet.
  • Missing function: the Rust shim leaves the table untouched; the C code left it partially filled. Neither is read after failure.

Tests

  • Local gate (ci-lint local-gate run): lint, rust-test (Tiers 1-3), cross, tier2-linux (cmocka, ENABLE_RUST_LIBOBS OFF and ON) all passed; HEAD is stamped.
  • The Tier 2 Docker image has no nv-codec-headers, so it does not compile the plugin. I compiled cuda-load.c, cuda-load-rust.c, nvenc-load.c and the helpers with -Wall against FFmpeg's nv-codec-headers, and linked cuda-load-rust.c with the release staticlib in a harness on a machine with a real NVIDIA driver: init_cuda_internal returned true and cu->cuInit was set.
  • The CMake/Corrosion change for the plugin is only exercised by the full ubuntu-build/Windows builds, hence the ci-full label.

Behaviour-neutral extraction (testing-policy: Extracting a function before
porting it). load_cuda_lib, cuda_functions[] and init_cuda_internal move
verbatim to cuda-load.c; load_nvenc_lib (and the nvenc_lib handle it
fills) moves to nvenc-load.c. init_cuda_internal and load_nvenc_lib get
declarations in the plugin-private cuda-helpers.h / nvenc-helpers.h.
The C oracle's extraction now reads the new files. Refs #524.
tests/ffi.rs fails 6/6 against the stubbed fill_table: the fake-driver
fill, the cuda_lib and Could-not-load-function log strings, the truncation
rule, and the plugin CMake wiring (cuda-load.c dropped and cuda-load-rust.c
built under ENABLE_RUST_LIBOBS). Refs #524.
obs_nvenc_cuda_fill (rust/obs-nvenc/src/ffi) loads the CUDA driver with
CudaDriver and writes each resolved symbol at the {offsetof, name} rows C
passes in, so no CUDA struct is mirrored in Rust. With ENABLE_RUST_LIBOBS
ON the plugin builds cuda-load-rust.c instead of cuda-load.c; it logs the
LoadError text (the existing '[NVENC] Test process failed: cuda_lib' and
'Could not load function' strings) and sets the same encoder errors.

The Rust staticlib links into obs-nvenc itself, not libobs-rust: libobs
must keep the C build's export set and one Rust staticlib, and only this
plugin calls the shim. tests/ffi.rs also pins that both C files keep an
identical cuda_functions[] table.

load_nvenc_lib stays C (extracted to nvenc-load.c; no Rust NVENC loader
is wired yet).

Fixes #524

Local-Gate: v1 tree=98e43fe900e75dc944fff4316ef89cf49c5ef297 secs=425 lanes=lint:run,rust-test:run,cross:run,tier2-linux:run
Ci-Attestation: {"at":1791904609,"gate":"rust/all/fmt","host":"linux-x86_64","key":"0db60fe9e741013b8958fa8d15876619ea215192c617d7131fcdf0537a44e3db","lane":"lint","parents":["aa885d847ffde21bb7f59820745e5f987b21dcc7"],"secs":30,"stamp":"5b04bc1425c92e52ce8d93fdf233715b","tree":"98e43fe900e75dc944fff4316ef89cf49c5ef297","v":1,"via":"run"}
Ci-Attestation: {"at":1791904609,"gate":"rust/x86_64-unknown-linux-gnu/clippy","host":"linux-x86_64","key":"0db60fe9e741013b8958fa8d15876619ea215192c617d7131fcdf0537a44e3db","lane":"lint","parents":["aa885d847ffde21bb7f59820745e5f987b21dcc7"],"secs":30,"stamp":"264c6e493abed2a3f7c1d3cccf847126","tree":"98e43fe900e75dc944fff4316ef89cf49c5ef297","v":1,"via":"run"}
Ci-Attestation: {"at":1791904609,"gate":"rust/x86_64-unknown-linux-gnu/test","host":"linux-x86_64","key":"8bfa58f98e21f2679ba89b7d6ee20c3a8e634f5efcd7f6284646361b01f845d0","lane":"rust-test","parents":["aa885d847ffde21bb7f59820745e5f987b21dcc7"],"secs":185,"stamp":"c427731e3a47c924ad4ceacb97f8f3a1","tree":"98e43fe900e75dc944fff4316ef89cf49c5ef297","v":1,"via":"run"}
Ci-Attestation: {"at":1791904609,"gate":"rust/x86_64-pc-windows-msvc/clippy","host":"linux-x86_64","key":"8bbcbb31b66a0b8caa97a5cc2e097dae75e07feeb369943513e7cc0808112b90","lane":"cross","parents":["aa885d847ffde21bb7f59820745e5f987b21dcc7"],"secs":68,"stamp":"b2f97a465f028fb1887f10daabb9aea2","tree":"98e43fe900e75dc944fff4316ef89cf49c5ef297","v":1,"via":"run"}
Ci-Attestation: {"at":1791904609,"gate":"rust/x86_64-pc-windows-msvc/dylint","host":"linux-x86_64","key":"8bbcbb31b66a0b8caa97a5cc2e097dae75e07feeb369943513e7cc0808112b90","lane":"cross","parents":["aa885d847ffde21bb7f59820745e5f987b21dcc7"],"secs":68,"stamp":"20f4a52310a27cd8d0939a78a0201a4f","tree":"98e43fe900e75dc944fff4316ef89cf49c5ef297","v":1,"via":"run"}
Ci-Attestation: {"at":1791904609,"gate":"rust/aarch64-apple-darwin/clippy","host":"linux-x86_64","key":"8bbcbb31b66a0b8caa97a5cc2e097dae75e07feeb369943513e7cc0808112b90","lane":"cross","parents":["aa885d847ffde21bb7f59820745e5f987b21dcc7"],"secs":68,"stamp":"73b63c60c2b62f4daa0826bb119390c2","tree":"98e43fe900e75dc944fff4316ef89cf49c5ef297","v":1,"via":"run"}
Ci-Attestation: {"at":1791904609,"gate":"rust/aarch64-apple-darwin/dylint","host":"linux-x86_64","key":"8bbcbb31b66a0b8caa97a5cc2e097dae75e07feeb369943513e7cc0808112b90","lane":"cross","parents":["aa885d847ffde21bb7f59820745e5f987b21dcc7"],"secs":68,"stamp":"8024e464b1380c354cba06ea976db818","tree":"98e43fe900e75dc944fff4316ef89cf49c5ef297","v":1,"via":"run"}
Ci-Attestation: {"at":1791904609,"gate":"rust/x86_64-apple-darwin/clippy","host":"linux-x86_64","key":"8bbcbb31b66a0b8caa97a5cc2e097dae75e07feeb369943513e7cc0808112b90","lane":"cross","parents":["aa885d847ffde21bb7f59820745e5f987b21dcc7"],"secs":68,"stamp":"ff318b975c80daf69a481cdeeff54932","tree":"98e43fe900e75dc944fff4316ef89cf49c5ef297","v":1,"via":"run"}
Ci-Attestation: {"at":1791904609,"gate":"rust/x86_64-apple-darwin/dylint","host":"linux-x86_64","key":"8bbcbb31b66a0b8caa97a5cc2e097dae75e07feeb369943513e7cc0808112b90","lane":"cross","parents":["aa885d847ffde21bb7f59820745e5f987b21dcc7"],"secs":68,"stamp":"fbe74345a97a1bdd1eb75401e35a138f","tree":"98e43fe900e75dc944fff4316ef89cf49c5ef297","v":1,"via":"run"}
Ci-Attestation: {"at":1791904609,"gate":"cpp/linux-x64/tier2","host":"linux-x86_64","key":"8f41986c24471cfa456ea7fdb572c863f9c49e4724b0f054c0b9f825381f4f35","lane":"tier2-linux","parents":["aa885d847ffde21bb7f59820745e5f987b21dcc7"],"secs":141,"stamp":"2a92a5e6e21c9051f02b58eaca150564","tree":"98e43fe900e75dc944fff4316ef89cf49c5ef297","v":1,"via":"run"}
@zackees zackees added the ci-full Run every CI job on this PR, including the release-gating OBS app builds and Flatpak label Oct 13, 2026
An rlib + staticlib obs-nvenc broke its own test build on windows-msvc
(extern location for obs_nvenc does not exist). obs-nvenc is a plain rlib
again; obs-nvenc-plugin is the staticlib the plugin links, as
libobs-rust is for libobs.

Local-Gate: v1 tree=df5758d5adfb9aff7a99249055ba2bd03daebc19 secs=330 lanes=lint:run,rust-test:run,cross:run,tier2-linux:run
Ci-Attestation: {"at":1791905850,"gate":"rust/all/fmt","host":"linux-x86_64","key":"cfb6ea8342e723c7a194fde602400e16a4118e4f1b40eedc23a7f0840196da9c","lane":"lint","parents":["efae32808123bf994ecc84ac0b2dfd52d51f7525"],"secs":19,"stamp":"ab99c7555dd009f54a9f73cfad0c971c","tree":"df5758d5adfb9aff7a99249055ba2bd03daebc19","v":1,"via":"run"}
Ci-Attestation: {"at":1791905850,"gate":"rust/x86_64-unknown-linux-gnu/clippy","host":"linux-x86_64","key":"cfb6ea8342e723c7a194fde602400e16a4118e4f1b40eedc23a7f0840196da9c","lane":"lint","parents":["efae32808123bf994ecc84ac0b2dfd52d51f7525"],"secs":19,"stamp":"a9f5af4926dfb371173f6c04d31dec0f","tree":"df5758d5adfb9aff7a99249055ba2bd03daebc19","v":1,"via":"run"}
Ci-Attestation: {"at":1791905850,"gate":"rust/x86_64-unknown-linux-gnu/test","host":"linux-x86_64","key":"dd0348552925bda61142f3674e9fb2cc4e67ea08f787d90f01d663f25e058fac","lane":"rust-test","parents":["efae32808123bf994ecc84ac0b2dfd52d51f7525"],"secs":115,"stamp":"1277ec6459637f0b594cf0e4ec8cdd0e","tree":"df5758d5adfb9aff7a99249055ba2bd03daebc19","v":1,"via":"run"}
Ci-Attestation: {"at":1791905850,"gate":"rust/x86_64-pc-windows-msvc/clippy","host":"linux-x86_64","key":"19b4b10744ef1a858ee537da5de07c3ea8f692abbcd0a71d56c0038d7fe79b70","lane":"cross","parents":["efae32808123bf994ecc84ac0b2dfd52d51f7525"],"secs":87,"stamp":"2f16468b96b7a1bcadf3c737bc553ec5","tree":"df5758d5adfb9aff7a99249055ba2bd03daebc19","v":1,"via":"run"}
Ci-Attestation: {"at":1791905850,"gate":"rust/x86_64-pc-windows-msvc/dylint","host":"linux-x86_64","key":"19b4b10744ef1a858ee537da5de07c3ea8f692abbcd0a71d56c0038d7fe79b70","lane":"cross","parents":["efae32808123bf994ecc84ac0b2dfd52d51f7525"],"secs":87,"stamp":"a876f0fc27a7cb44087e93c90e38fc16","tree":"df5758d5adfb9aff7a99249055ba2bd03daebc19","v":1,"via":"run"}
Ci-Attestation: {"at":1791905850,"gate":"rust/aarch64-apple-darwin/clippy","host":"linux-x86_64","key":"19b4b10744ef1a858ee537da5de07c3ea8f692abbcd0a71d56c0038d7fe79b70","lane":"cross","parents":["efae32808123bf994ecc84ac0b2dfd52d51f7525"],"secs":87,"stamp":"a32538cf55a401cb3821c6e9f27922c8","tree":"df5758d5adfb9aff7a99249055ba2bd03daebc19","v":1,"via":"run"}
Ci-Attestation: {"at":1791905850,"gate":"rust/aarch64-apple-darwin/dylint","host":"linux-x86_64","key":"19b4b10744ef1a858ee537da5de07c3ea8f692abbcd0a71d56c0038d7fe79b70","lane":"cross","parents":["efae32808123bf994ecc84ac0b2dfd52d51f7525"],"secs":87,"stamp":"22b5ba314951b4a43a51793ed8b255c8","tree":"df5758d5adfb9aff7a99249055ba2bd03daebc19","v":1,"via":"run"}
Ci-Attestation: {"at":1791905850,"gate":"rust/x86_64-apple-darwin/clippy","host":"linux-x86_64","key":"19b4b10744ef1a858ee537da5de07c3ea8f692abbcd0a71d56c0038d7fe79b70","lane":"cross","parents":["efae32808123bf994ecc84ac0b2dfd52d51f7525"],"secs":87,"stamp":"890beb5cac903a646e63dd42797c7bf9","tree":"df5758d5adfb9aff7a99249055ba2bd03daebc19","v":1,"via":"run"}
Ci-Attestation: {"at":1791905850,"gate":"rust/x86_64-apple-darwin/dylint","host":"linux-x86_64","key":"19b4b10744ef1a858ee537da5de07c3ea8f692abbcd0a71d56c0038d7fe79b70","lane":"cross","parents":["efae32808123bf994ecc84ac0b2dfd52d51f7525"],"secs":87,"stamp":"9a3058bf476b3e24f7d2345c74a59bef","tree":"df5758d5adfb9aff7a99249055ba2bd03daebc19","v":1,"via":"run"}
Ci-Attestation: {"at":1791905850,"gate":"cpp/linux-x64/tier2","host":"linux-x86_64","key":"2eb3f69a053b48071bb1357e4a03b6137b4fdfa285dd45b719baaa10f0606868","lane":"tier2-linux","parents":["efae32808123bf994ecc84ac0b2dfd52d51f7525"],"secs":109,"stamp":"8e80b5b6748a3725a90cd2a19172d4f6","tree":"df5758d5adfb9aff7a99249055ba2bd03daebc19","v":1,"via":"run"}
@zackees
zackees merged commit 0cc9013 into master Oct 13, 2026
23 of 24 checks passed
zackees added a commit to ProtonDev-sys/obs-studio that referenced this pull request Oct 15, 2026
Install nv-codec-headers (libffmpeg-nvenc-dev, FFnvcodec 12) in the
image and configure with ENABLE_NVENC=ON, so both builds compile and
link obs-nvenc. That covers the cuda-load.c / cuda-load-rust.c swap
from obs-rust#592.

Fixes obs-rust#645

Local-Gate: v1 tree=5f5a85eacb13db43b216aa3ef03fb20839601291 secs=396 lanes=lint:run,rust-test:run,cross:run,tier2-linux:run
Ci-Attestation: {"at":1791929419,"gate":"rust/all/fmt","host":"linux-x86_64","key":"331c220c86a55c314a1aed95aab7ba682a259d29a25e8938ac9da9e4218eac61","lane":"lint","parents":["5dd14df70b6afd03a39e3b7d706eeb073bc72719"],"secs":20,"stamp":"00d53eb044d63868a9920dbcc098f41c","tree":"5f5a85eacb13db43b216aa3ef03fb20839601291","v":1,"via":"run"}
Ci-Attestation: {"at":1791929419,"gate":"rust/x86_64-unknown-linux-gnu/clippy","host":"linux-x86_64","key":"331c220c86a55c314a1aed95aab7ba682a259d29a25e8938ac9da9e4218eac61","lane":"lint","parents":["5dd14df70b6afd03a39e3b7d706eeb073bc72719"],"secs":20,"stamp":"3dc63cc0b16598c0ad0f67f27f96a8a6","tree":"5f5a85eacb13db43b216aa3ef03fb20839601291","v":1,"via":"run"}
Ci-Attestation: {"at":1791929419,"gate":"rust/x86_64-unknown-linux-gnu/test","host":"linux-x86_64","key":"4840c0308ea31c36ffa76cd068a46ab3c44d0e27f50d14fcf23350a743ff20fe","lane":"rust-test","parents":["5dd14df70b6afd03a39e3b7d706eeb073bc72719"],"secs":124,"stamp":"912980d7375d73d5bb188d1d6f755e53","tree":"5f5a85eacb13db43b216aa3ef03fb20839601291","v":1,"via":"run"}
Ci-Attestation: {"at":1791929419,"gate":"rust/x86_64-pc-windows-msvc/clippy","host":"linux-x86_64","key":"620c0248d6262a5528478c98fed510193753d9c6c9e9796ec445e56d5e1b9bd3","lane":"cross","parents":["5dd14df70b6afd03a39e3b7d706eeb073bc72719"],"secs":119,"stamp":"f83061a1f616fb134a8e9bd01e725aff","tree":"5f5a85eacb13db43b216aa3ef03fb20839601291","v":1,"via":"run"}
Ci-Attestation: {"at":1791929419,"gate":"rust/x86_64-pc-windows-msvc/dylint","host":"linux-x86_64","key":"620c0248d6262a5528478c98fed510193753d9c6c9e9796ec445e56d5e1b9bd3","lane":"cross","parents":["5dd14df70b6afd03a39e3b7d706eeb073bc72719"],"secs":119,"stamp":"0a5557fce05d69e8280f0a8b798e645b","tree":"5f5a85eacb13db43b216aa3ef03fb20839601291","v":1,"via":"run"}
Ci-Attestation: {"at":1791929419,"gate":"rust/aarch64-apple-darwin/clippy","host":"linux-x86_64","key":"620c0248d6262a5528478c98fed510193753d9c6c9e9796ec445e56d5e1b9bd3","lane":"cross","parents":["5dd14df70b6afd03a39e3b7d706eeb073bc72719"],"secs":119,"stamp":"b584822a28caeb47c9ad95c51affce0a","tree":"5f5a85eacb13db43b216aa3ef03fb20839601291","v":1,"via":"run"}
Ci-Attestation: {"at":1791929419,"gate":"rust/aarch64-apple-darwin/dylint","host":"linux-x86_64","key":"620c0248d6262a5528478c98fed510193753d9c6c9e9796ec445e56d5e1b9bd3","lane":"cross","parents":["5dd14df70b6afd03a39e3b7d706eeb073bc72719"],"secs":119,"stamp":"edb248f5497e4976a5d15de42d34a3f1","tree":"5f5a85eacb13db43b216aa3ef03fb20839601291","v":1,"via":"run"}
Ci-Attestation: {"at":1791929419,"gate":"rust/x86_64-apple-darwin/clippy","host":"linux-x86_64","key":"620c0248d6262a5528478c98fed510193753d9c6c9e9796ec445e56d5e1b9bd3","lane":"cross","parents":["5dd14df70b6afd03a39e3b7d706eeb073bc72719"],"secs":119,"stamp":"50f314020be8736ad0c7647856751423","tree":"5f5a85eacb13db43b216aa3ef03fb20839601291","v":1,"via":"run"}
Ci-Attestation: {"at":1791929419,"gate":"rust/x86_64-apple-darwin/dylint","host":"linux-x86_64","key":"620c0248d6262a5528478c98fed510193753d9c6c9e9796ec445e56d5e1b9bd3","lane":"cross","parents":["5dd14df70b6afd03a39e3b7d706eeb073bc72719"],"secs":119,"stamp":"1b476e164703c614e8b0f853cdfaf621","tree":"5f5a85eacb13db43b216aa3ef03fb20839601291","v":1,"via":"run"}
Ci-Attestation: {"at":1791929419,"gate":"cpp/linux-x64/tier2","host":"linux-x86_64","key":"645acaf6538d7c5e88cd82bf16889acc2533ac8dce314ae80c8b2d7a0eb7e4bb","lane":"tier2-linux","parents":["5dd14df70b6afd03a39e3b7d706eeb073bc72719"],"secs":132,"stamp":"d404e208daddfb51ed47d84d8e995f61","tree":"5f5a85eacb13db43b216aa3ef03fb20839601291","v":1,"via":"run"}
zackees added a commit that referenced this pull request Oct 15, 2026
An rlib + staticlib crate breaks its own test build (#592), as on macOS
CI here; obs-gpu-status stays a plain rlib, like obs-nvenc.

Refs #846
zackees added a commit that referenced this pull request Oct 15, 2026
An rlib + staticlib crate breaks its own test build (#592), as on macOS
CI here; obs-gpu-status stays a plain rlib, like obs-nvenc.

Refs #846
chriscoveries pushed a commit to chriscoveries/obsrust-fork that referenced this pull request Oct 15, 2026
… field (obs-rust#846) (obs-rust#894)

* obs-gpu-status: Add failing tests for the status dialog text and JSON (RED)

Refs obs-rust#846

* obs-gpu-status: Explain the state and expose it through a C ABI (GREEN)

Report::new() adds the dialog's summary and likely causes; to_json() is
the gpuAcceleration object. obs_gpu_status_report()/obs_gpu_status_free()
are the frontend's C ABI; the crate also builds as a staticlib.

Refs obs-rust#846

* test: Tier 4 check that GetStats reports GPU acceleration on llvmpipe (RED)

Starts OBS with LIBGL_ALWAYS_SOFTWARE=1 and asserts GetStats'
gpuAcceleration is not green and the log carries the startup warning.
Fails until the frontend and obs-websocket provide the field.

Refs obs-rust#846

* frontend: Show GPU acceleration status in the status bar (GREEN)

A status-bar light (green/yellow/red, refreshed every 5 s) opens a dialog
with the summary, active adapter, detected GPUs and likely causes from
rust/obs-gpu-status. Startup logs 'GPU acceleration: YELLOW/RED' with
the details, and the get_gpu_status proc feeds obs-websocket's new
additive GetStats.gpuAcceleration field (submodule bump). The crate is
linked into the frontend only with ENABLE_RUST_LIBOBS=ON, like
obs-nvenc-plugin, so libobs' exports do not change.

Refs obs-rust#846

* frontend: clang-format GpuStatus.cpp

Refs obs-rust#846

* obs-gpu-status: Move the frontend staticlib into obs-gpu-status-frontend

An rlib + staticlib crate breaks its own test build (obs-rust#592), as on macOS
CI here; obs-gpu-status stays a plain rlib, like obs-nvenc.

Refs obs-rust#846
@zackees
zackees deleted the port/obs-nvenc-shim 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

ci-full Run every CI job on this PR, including the release-gating OBS app builds and Flatpak

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

rust: Port plugins/obs-nvenc load_cuda_lib/init_cuda to obs-nvenc behind ENABLE_RUST_LIBOBS

1 participant