Skip to content

obs-core: Port the graphics task drain to Rust - #4742

Merged
zackees merged 6 commits into
masterfrom
fix/rust-port-port-the-graphics-task-800
Nov 13, 2026
Merged

zackees merged 6 commits into
masterfrom
fix/rust-port-port-the-graphics-task-800

Conversation

@rdoupe

@rdoupe rdoupe commented Nov 12, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #4408

What and why

Ports execute_graphics_tasks() (libobs/obs-video-graphics-tasks.c.h), the graphics thread's per-frame drain of the OBS_TASK_GRAPHICS queue, to obs-core::video_graphics_tasks. It is the Rust half of zackees' extraction (#4410, from #4403), and the last piece of that obs-video.c.h split after the stop check (#4671) and the render size (#4541).

This carries zackees' draft from port/4408-graphics-tasks (the Queue trait and the Tier 1 cases), rebased onto current master and reshaped like the stop check port, with his Co-Authored-By on the RED and GREEN commits.

  • The live obs-video-graphics-tasks.c.h is now a private bridge: execute_graphics_tasks() keeps its name and its call site in obs_graphics_thread_loop(), and calls the hidden obs_video_graphics_tasks_execute() (declared in the new private obs-video-graphics-tasks.h, not EXPORT, listed in rust-hidden.d) with the core and four accessors: lock and unlock of task_mutex, tasks.size != 0, and a pop of one struct obs_task_info. The deque and its mutex stay C-owned; the Rust reads no private layout.
  • The Rust keeps the C's order exactly: take the mutex; while the queue is not empty, pop the oldest task, release the mutex, run the task through its own function pointer, take the mutex again; then release it. A task queued meanwhile, by the running task or by another thread, runs in the same pass, and the loop stays unbounded, as in the C. No Rust borrow is held across a task.
  • The original C is the C reference, verbatim, in its own ported group (obs-video-graphics-tasks-reference.c.h, libobs.ported-video-graphics-tasks+).
  • One intentional difference, a bug fix with its own RED and GREEN commits after the port: a NULL task, which obs_queue_task() queues without a check and the C calls and crashes on, is skipped, and the tasks after it still run, as the audio task drain (obs-core::audio_callback) already does. The port itself keeps the C's behaviour (a NULL task aborts the graphics thread); the fix follows it. It is listed in the parity test header and the rust/README.md row, and has its line in docs/features.md (Fixed upstream bugs, Stability). Tier 3 can't compare it, since the C crashes; null_task_is_skipped covers it on the oracle's real core.

Upstream: no upstream issue. The C characterization and extraction are zackees' (#4410).

RED → GREEN

  • RED commit: 9a061b8. obs_core::video_graphics_tasks::{graphics_fifo, graphics_callback_enqueue, graphics_empty_then_second_drain, graphics_chain_drains_in_one_pass} (Tier 1, mirroring test_video_graphics_tasks.c, with the C's call order logged) fail 4/4 on the todo!() drain ("not yet implemented: execute_graphics_tasks"); --lane lint passes, and --test-diff fails on those four tests only.
  • GREEN: d136e1c (port), 111792d (Tier 3), a17300d (docs).
  • NULL task: RED 6dd2e89, obs_core::video_graphics_tasks_parity::null_task_is_skipped aborts on "a queued graphics task" (the panic crosses the C ABI); --test-diff fails on that test only (8407 passed, 1 failed). GREEN 23faf1f skips it.
  • Runs were on 23faf1f (rebased onto bebe504 and stamped by the local gate: lint, dylint, rust-test, cross and Tier 2 Linux all passed), except the wide Tier 2 run, which was on an earlier head (65895aed33) whose libobs and Rust drain are the same as 23faf1f's:
    • Tier 1: obs_core::video_graphics_tasks 4/4.
    • Tier 2: the unchanged test_video_graphics_tasks passes on the C build, against hybrid libobs and against libobs-c-reference. The video, graphics, task, shutdown and reset tests (ctest -R 'video|graphics|task|shutdown|reset', under Xvfb) pass 66/66 on the C build, 75/75 against hybrid libobs and 75/75 against libobs-c-reference, 0 skipped. Rerun on 23faf1f: ctest -R 'video|graphics|task' 62/62 against hybrid libobs and 62/62 against libobs-c-reference, 0 skipped.
    • Tier 3: obs_core::video_graphics_tasks_parity 4/4 (3 parity cases, plus null_task_is_skipped): the characterization's queues, every tree of up to six tasks, and a proptest over random trees of up to 62, where tasks queue more tasks through a real producer push. Planted mutants caught: the mutex held across a task, one task per pass, and the queue taken whole before any task runs.
    • Gates: ci/local_gate.py --test-diff (8408 passed, 6 skipped, plus the Windows-GNU oracle build), --lane lint, --lane dylint, --lane cross, and cargo clippy --workspace --target x86_64-pc-windows-msvc --all-targets -D warnings all pass. After the rebase, ./unittest ran the Rust tests (8437 passed, 6 skipped) and Tier 2 in Docker, whose C-reference pass came first and stopped it at 917/918: test_screencast_portal_teardown timed out under load (SIGALRM). It passed alone 3/3 on the C reference and once each on the hybrid and C builds, and the local gate's own Tier 2 Linux run (both builds) then passed in full.
    • Export sets: identical on the C, hybrid and c-ref builds (1768 symbols); obs_video_graphics_tasks_execute is local (t) in all three, and hybrid libobs doesn't compile the reference group.
  • Test cost: new tests: longest 0.02 s, peak RSS 6.1 MB over 20 runs (OBS_PARITY_CASES=reduced), no threads of their own.
  • Real app (UI, protocol output or logging changes): not applicable: no UI, protocol or log change. The one change a user could notice is the NULL-task crash fix, covered by null_task_is_skipped.

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 (N/A for docs-only; a focused CI fix may push RED and GREEN together)
  • User-visible change: its line in docs/features.md is added or updated (the NULL-task crash fix, under Fixed upstream bugs, Stability)
  • (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 (PR CI builds no OBS app: run gh workflow run ci.yml --ref <branch> for the full builds) and cross-checked with clang and MSVC (not applicable: no warning or flag change)
  • Intentional differences from C listed in the parity test header and rust/README.md (ports)

@rdoupe rdoupe changed the title test: Mirror the graphics task drain over a stub obs-core: Port the graphics task drain to Rust Nov 12, 2026
rdoupe and others added 6 commits November 12, 2026 17:31
Tier 1 tests for obs-core's video_graphics_tasks, ported 1:1 from
test_video_graphics_tasks.c over a model queue: queued tasks run
oldest first, each once; a task queued while another runs runs in
the same pass; and task_mutex is held for every size check and pop
and released around every task. The model logs each call, so the
tests also pin the C's order of lock, size check, pop, unlock, run
and lock again. The drain is a todo!() stub, so all four fail.

Refs #4408.

Co-Authored-By: Zach Vorhies <[email protected]>
execute_graphics_tasks() in obs-video-graphics-tasks.c.h is now a
bridge to the hidden obs_video_graphics_tasks_execute(), Rust in
hybrid libobs (obs-core::video_graphics_tasks). The bridge passes the
core and its accessors for task_mutex, tasks.size and a pop of one
struct obs_task_info, so the deque and its mutex stay C-owned. The
Rust keeps the C's order: take the mutex; while the queue is not
empty, pop the oldest task, release the mutex, run the task through
its own function pointer and take the mutex again; release it. The
call site in obs_graphics_thread_loop() is unchanged.

The original C is the C reference, in its own ported group
(obs-video-graphics-tasks-reference.c.h), and the unchanged
test_video_graphics_tasks runs against it and against the Rust.

Refs #4408.

Co-Authored-By: Zach Vorhies <[email protected]>
Tier 3 for obs-core's video_graphics_tasks. The oracle compiles the
original C (obs-video-graphics-tasks-reference.c.h) and the
production bridge's accessors over a real private core with a real
task_mutex and deque. The parity test runs both over the same trees
of tasks: some queued before the drain, the rest queued by their
parent while it runs, the way another producer does. It compares the
tasks run, in order, whether task_mutex was held for each, that
every producer got the mutex, the queue left empty and the mutex
released: for the characterization's queues, every tree of up to six
tasks, and random trees of up to 62.

Planted mutants caught: the mutex held across a task, one task per
pass, and the queue taken whole before any task runs.

Refs #4408.
The rust/README.md row for obs-video-graphics-tasks.c.h, its place in
naming.md's obs-core row, and obs-core's Cargo.toml description and
module docs.

Refs #4408.
obs_queue_task() queues a NULL task without a check, and the graphics
task drain calls it, so the graphics thread crashes (the C) or aborts
(the Rust, which panics on it across the C ABI). The new
null_task_is_skipped case queues a NULL task between two real ones
on the oracle's real core and runs the Rust drain over it: it should
run the two real tasks, in order, unlocked, and leave the queue empty
and the mutex released. It aborts on "a queued graphics task" now.

The oracle's push takes an optional task for it.

Refs #4408.
The graphics task drain now skips a popped task whose function is
NULL instead of calling it, as the audio task drain already does:
obs_queue_task() queues one without a check, and calling it crashed
the graphics thread. The tasks queued after it still run, and the
mutex is released around each as before. This is the port's one
intentional difference from the C, listed in the parity test header
and the rust/README.md row, with its line in docs/features.md.

Fixes #4408.

Local-Gate: v1 tree=046cad34c620d2fab1186d87d7b372e3a19ee904 secs=2440 lanes=lint:run,dylint:run,rust-test:run,cross:run,tier2-linux:run,macos-native:n/a,windows-native:n/a
Ci-Attestation: {"at":1794527848,"gate":"rust/all/fmt","host":"linux-x86_64","key":"b55f4ad6d00b5afefa9a92bf79da3f7ec4fbeecd05782853af6e74d25509bcec","lane":"lint","parents":["6dd2e890550fa34832412ae51400ba7ae69e12cd"],"secs":61,"stamp":"fa63df07ac740661fb5b2053e7d2a7ad","tree":"046cad34c620d2fab1186d87d7b372e3a19ee904","v":1,"via":"run"}
Ci-Attestation: {"at":1794527848,"gate":"rust/x86_64-unknown-linux-gnu/clippy","host":"linux-x86_64","key":"b55f4ad6d00b5afefa9a92bf79da3f7ec4fbeecd05782853af6e74d25509bcec","lane":"lint","parents":["6dd2e890550fa34832412ae51400ba7ae69e12cd"],"secs":61,"stamp":"8905d7aa7d33f3ea8ce0208a56e55572","tree":"046cad34c620d2fab1186d87d7b372e3a19ee904","v":1,"via":"run"}
Ci-Attestation: {"at":1794527848,"gate":"rust/x86_64-unknown-linux-gnu/dylint","host":"linux-x86_64","key":"46e3b4cebcc7c6e904004b16bbdc7cc7e5d3f9bffcc030f5df71014fc2c6389c","lane":"dylint","parents":["6dd2e890550fa34832412ae51400ba7ae69e12cd"],"secs":0,"stamp":"22235d4296f349162d99da6d28cfe433","tree":"046cad34c620d2fab1186d87d7b372e3a19ee904","v":1,"via":"run"}
Ci-Attestation: {"at":1794527848,"gate":"rust/x86_64-unknown-linux-gnu/test","host":"linux-x86_64","key":"506c02b53123e54694c3f6c805fbdadfb1685d239fadeac11fb499522b4b4a12","lane":"rust-test","parents":["6dd2e890550fa34832412ae51400ba7ae69e12cd"],"secs":225,"stamp":"203bbd62ac24e99bf2f5d97cffde705a","tree":"046cad34c620d2fab1186d87d7b372e3a19ee904","v":1,"via":"run"}
Ci-Attestation: {"at":1794527848,"gate":"rust/x86_64-pc-windows-msvc/clippy","host":"linux-x86_64","key":"7b57f59c3f725abfde890d3230e6505735111b127bdf01e3341dabe51b653291","lane":"cross","parents":["6dd2e890550fa34832412ae51400ba7ae69e12cd"],"secs":107,"stamp":"b4b5b6b4031706cc68a15d04c69131cd","tree":"046cad34c620d2fab1186d87d7b372e3a19ee904","v":1,"via":"run"}
Ci-Attestation: {"at":1794527848,"gate":"rust/x86_64-pc-windows-msvc/dylint","host":"linux-x86_64","key":"7b57f59c3f725abfde890d3230e6505735111b127bdf01e3341dabe51b653291","lane":"cross","parents":["6dd2e890550fa34832412ae51400ba7ae69e12cd"],"secs":107,"stamp":"17d7e196bc3a2ca412495570f842603e","tree":"046cad34c620d2fab1186d87d7b372e3a19ee904","v":1,"via":"run"}
Ci-Attestation: {"at":1794527848,"gate":"rust/aarch64-apple-darwin/clippy","host":"linux-x86_64","key":"7b57f59c3f725abfde890d3230e6505735111b127bdf01e3341dabe51b653291","lane":"cross","parents":["6dd2e890550fa34832412ae51400ba7ae69e12cd"],"secs":107,"stamp":"322eab0aa0638d563258d3a07b7b1a75","tree":"046cad34c620d2fab1186d87d7b372e3a19ee904","v":1,"via":"run"}
Ci-Attestation: {"at":1794527848,"gate":"rust/aarch64-apple-darwin/dylint","host":"linux-x86_64","key":"7b57f59c3f725abfde890d3230e6505735111b127bdf01e3341dabe51b653291","lane":"cross","parents":["6dd2e890550fa34832412ae51400ba7ae69e12cd"],"secs":107,"stamp":"45b787735e77a164f581a5a2010e0211","tree":"046cad34c620d2fab1186d87d7b372e3a19ee904","v":1,"via":"run"}
Ci-Attestation: {"at":1794527848,"gate":"cpp/linux-x64/tier2","host":"linux-x86_64","key":"9edf3a97d4984cd25fc77e348d4a56249c29ebf4e4a5c0b00a8b0420a88dbd28","lane":"tier2-linux","parents":["6dd2e890550fa34832412ae51400ba7ae69e12cd"],"secs":2440,"stamp":"918ffb009b27d150367e9fe1951b9818","tree":"046cad34c620d2fab1186d87d7b372e3a19ee904","v":1,"via":"run"}
@rdoupe
rdoupe force-pushed the fix/rust-port-port-the-graphics-task-800 branch from 74b4edd to 23faf1f Compare November 12, 2026 23:58
@rdoupe
rdoupe marked this pull request as ready for review November 13, 2026 00:27
@rdoupe
rdoupe requested a review from zackees as a code owner November 13, 2026 00:27
@zackees
zackees added this pull request to the merge queue Nov 13, 2026
Merged via the queue into master with commit 00e363c Nov 13, 2026
42 checks passed
@zackees
zackees deleted the fix/rust-port-port-the-graphics-task-800 branch November 13, 2026 00:55
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.

rust: Port obs-video-graphics-tasks.c to obs-core after extraction

2 participants