Skip to content

libobs: Extract the raster and blend setters - #4818

Merged
rdoupe merged 2 commits into
masterfrom
fix/rust-port-extract-the-raster-and-809
Nov 13, 2026
Merged

rdoupe merged 2 commits into
masterfrom
fix/rust-port-extract-the-raster-and-809

Conversation

@rdoupe

@rdoupe rdoupe commented Nov 13, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #4812

What and why

The behaviour-neutral prerequisite for porting seven graphics state entry points to obs-graphics (testing-policy.md, "Extracting a function before porting it"): the cull mode getter and setter, the colour write mask, and the four blend setters that the blend push, pop and reset port (#4296) left in C. Each new file can then be swapped to Rust as a whole.

  1. Characterization (test: Characterize the raster and blend setters): a new GPU-free cmocka test, test/cmocka/test_raster_state_entrypoints.c, calls the real public exports through a recording backend, the way test_present_entrypoints does. It is defined in test/cmocka/build/test-graph.json (default core suite: it needs no graphics module), so CMake and the Cargo-native validator both build and run it. It pins:
    • outside a graphics context (never entered, and after leaving one): no dispatch, the blend state untouched, gs_get_cull_mode returns GS_NEITHER even when the backend would answer otherwise, and each call writes its own gs_valid debug line;
    • inside one: each call reaches its own device export exactly once, with the current device (two devices) and its arguments unchanged: every cull mode and an undeclared one, all 16 colour masks with each channel in its own position, every blend factor and operation and undeclared ones; gs_get_cull_mode returns the export's answer each time, nothing cached;
    • the blend setters store the new state before the device is told; gs_blend_function sets the colour and alpha factors alike; gs_blend_op forwards the stored operation;
    • what the setters store is what gs_blend_state_push saves and gs_blend_state_pop restores, a single gs_blend_function pair included.
  2. Move (libobs: Extract the raster and blend setters): gs_enable_blending, gs_blend_function, gs_blend_function_separate and gs_blend_op move verbatim from libobs/graphics/graphics.c.h (lines 1333-1342 and 1374-1412) into libobs/graphics/state-blend-setters.c.h, and gs_set_cull_mode, gs_get_cull_mode and gs_enable_color (lines 1313-1331 and 1364-1372) into libobs/graphics/raster-state-entrypoints.c.h, each in its original order. Both include libobs-graphics.pch.h like present-entrypoints.c.h did, and sort after graphics.c.h in libobs.graphics+.h.c, where thread_graphics and the static gs_valid are defined. No Rust, and no signature, header or behaviour change. The Rust blend pop and reset keep calling the blend setters through their C symbols.

The four stencil calls between them (gs_enable_stencil_test, gs_enable_stencil_write, gs_stencil_function, gs_stencil_op) stay in graphics.c.h: their extraction is #4418's.

RED → GREEN

  • RED commit: N/A. Behaviour-neutral extraction: the characterization passes before and after the move.
  • GREEN (runs were on fa3192c):
    • test_raster_state_entrypoints passes (3/3) on the plain C build, hybrid libobs and libobs-c-reference, on the characterization commit and after the move.
    • Unchanged C tests, full cmocka suite under a private Xvfb with no sound server: plain C 881/884, hybrid 942/944, C reference 941/944, 3 skipped on each (test_pulse_default_follow and the two vivid camera tests, which need hardware or a sound server). Two fail on all three builds, the plain C one included, because they need a running sound server: test_v4l2_vcam_audio and test_v4l2_vmic_libpulse. The third on plain C (test_enum_modules) and on the C reference (test_find_modules) passed alone on all three builds (load).
    • Exported symbol sets: identical on plain C, hybrid and C reference (1768 each), and identical to master before the move; all seven are still exported (T).
    • Move harness: master's seven functions and the moved text, each compiled in its own unit over a logging stand-in for the graphics subsystem and linked side by side. Built with gcc and clang at -O0, at -O2 and under ASan/UBSan; each build runs 20,000 random calls (about a quarter outside a context, three devices, declared and out-of-range enum values, every colour mask), logging each dispatch with the blend state the export saw. The dispatch logs, debug lines, return values and the blend state left behind are identical on every build. All 8 planted mutants are caught on every build: gs_get_cull_mode returning GS_BACK without a context, gs_blend_function's alpha source taken from the destination, gs_blend_op telling the device before storing, gs_enable_blending not storing, green and blue swapped in gs_enable_color, the wrong name in gs_blend_function_separate's debug line, the cull mode's back and front swapped, and gs_blend_function_separate's alpha destination taken from the alpha source. Planted in the real files, the same 8 also fail test_raster_state_entrypoints.
    • Local gates: --lane lint, --lane dylint, --lane cross, --test-diff (8444 passed, 6 skipped) and the Windows MSVC all-targets clippy all pass. The full local gate (lint, dylint, rust-test, cross, Tier 2 in the Linux container) passed and stamped the pushed head.
  • Real app (UI, protocol output or logging changes): not applicable, no change.

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 (not applicable: no user-visible change)
  • (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) (not applicable: no port, no differences)

Pin seven public graphics state exports (gs_set_cull_mode,
gs_get_cull_mode, gs_enable_color, gs_enable_blending,
gs_blend_function, gs_blend_function_separate and gs_blend_op)
through a recording backend, before they move out of graphics.c.h.
No graphics module or GPU is needed.

Outside a graphics context (never entered, and after leaving one)
each call dispatches nothing, leaves the blend state alone and writes
its own gs_valid debug line, and gs_get_cull_mode returns GS_NEITHER.
Inside one, each call reaches its own device export once with the
current device and its arguments unchanged, undeclared enum values
included; gs_get_cull_mode returns the export's answer. The blend
setters store the new state before the device is told,
gs_blend_function sets the colour and alpha factors alike, and
gs_blend_op forwards the stored operation. What they store is what
gs_blend_state_push saves and gs_blend_state_pop restores.

The test is defined in test-graph.json, so the Cargo-native validator
runs it too, in the default core suite like the frame and present
characterization.

Refs #4812.
Move gs_enable_blending, gs_blend_function,
gs_blend_function_separate and gs_blend_op verbatim from graphics.c.h
into state-blend-setters.c.h, and gs_set_cull_mode, gs_get_cull_mode
and gs_enable_color into raster-state-entrypoints.c.h, each in its
original order, so each file can be ported as a whole. Both files sort
after graphics.c.h in the graphics unity group, where thread_graphics
and the static gs_valid are defined, as present-entrypoints.c.h did.

The stencil calls between them stay in graphics.c.h. The Rust blend
pop and reset keep calling the blend setters through their C symbols.

No signature, header or behaviour change. The exported symbol sets
stay identical on the plain C build, hybrid libobs and
libobs-c-reference, with all seven still exported.

Refs #4812.

Local-Gate: v1 tree=96ab1b92f4bffce5b57a323950af5f743440b550 secs=3047 lanes=lint:run,dylint:run,rust-test:run,cross:run,tier2-linux:run,macos-native:n/a,windows-native:n/a,client-checks:run,client-swift:n/a,client-lint:run,client-test:run,client-test-x86_64-unknown-linux-gnu:run,client-test-aarch64-unknown-linux-gnu:n/a,client-test-x86_64-pc-windows-msvc:n/a,client-test-aarch64-pc-windows-msvc:n/a,client-test-x86_64-apple-darwin:n/a,client-test-aarch64-apple-darwin:n/a
Ci-Attestation: {"at":1794548695,"gate":"rust/all/fmt","host":"linux-x86_64","key":"828448f7722d8172cc7e04cd8708dba28c8bbae14bf38bd62d427a3979e8803a","lane":"lint","parents":["d31a92ad2fce2bf934a04579e0e03d7bd2589e35"],"secs":59,"stamp":"21d6793b647bfdb4929ff8714dc3eaa7","tree":"96ab1b92f4bffce5b57a323950af5f743440b550","v":1,"via":"run"}
Ci-Attestation: {"at":1794548695,"gate":"rust/x86_64-unknown-linux-gnu/clippy","host":"linux-x86_64","key":"828448f7722d8172cc7e04cd8708dba28c8bbae14bf38bd62d427a3979e8803a","lane":"lint","parents":["d31a92ad2fce2bf934a04579e0e03d7bd2589e35"],"secs":59,"stamp":"f223b5eb3b2f999f3aa4a2696c1d7d96","tree":"96ab1b92f4bffce5b57a323950af5f743440b550","v":1,"via":"run"}
Ci-Attestation: {"at":1794548695,"gate":"rust/x86_64-unknown-linux-gnu/dylint","host":"linux-x86_64","key":"dee6f7c12117f5eb874c202cc4145078d199000c52db8b882890c43d0fc90028","lane":"dylint","parents":["d31a92ad2fce2bf934a04579e0e03d7bd2589e35"],"secs":0,"stamp":"a2f7ecd98e49ae4fe4243418cfaa25b6","tree":"96ab1b92f4bffce5b57a323950af5f743440b550","v":1,"via":"run"}
Ci-Attestation: {"at":1794548695,"gate":"rust/x86_64-unknown-linux-gnu/test","host":"linux-x86_64","key":"b44411cbb7a4a3c46972508af4576200cc93d69d4b3f877c52227fddd055b6f3","lane":"rust-test","parents":["d31a92ad2fce2bf934a04579e0e03d7bd2589e35"],"secs":376,"stamp":"e4773e9633b99602193d8b7f74d8f29d","tree":"96ab1b92f4bffce5b57a323950af5f743440b550","v":1,"via":"run"}
Ci-Attestation: {"at":1794548695,"gate":"rust/x86_64-pc-windows-msvc/clippy","host":"linux-x86_64","key":"0a0b9f726a80f3a4389fe7229c2bc0e7cacbc8a4b32896037d234bf40eccf24c","lane":"cross","parents":["d31a92ad2fce2bf934a04579e0e03d7bd2589e35"],"secs":245,"stamp":"4e7e9bcab5d544cf8719dc04dfb8d05d","tree":"96ab1b92f4bffce5b57a323950af5f743440b550","v":1,"via":"run"}
Ci-Attestation: {"at":1794548695,"gate":"rust/x86_64-pc-windows-msvc/dylint","host":"linux-x86_64","key":"0a0b9f726a80f3a4389fe7229c2bc0e7cacbc8a4b32896037d234bf40eccf24c","lane":"cross","parents":["d31a92ad2fce2bf934a04579e0e03d7bd2589e35"],"secs":245,"stamp":"cd510be107df0c0e73e359085f5eb1ec","tree":"96ab1b92f4bffce5b57a323950af5f743440b550","v":1,"via":"run"}
Ci-Attestation: {"at":1794548695,"gate":"rust/aarch64-apple-darwin/clippy","host":"linux-x86_64","key":"0a0b9f726a80f3a4389fe7229c2bc0e7cacbc8a4b32896037d234bf40eccf24c","lane":"cross","parents":["d31a92ad2fce2bf934a04579e0e03d7bd2589e35"],"secs":245,"stamp":"152991ae6db48a056b70a4910fe37ee9","tree":"96ab1b92f4bffce5b57a323950af5f743440b550","v":1,"via":"run"}
Ci-Attestation: {"at":1794548695,"gate":"rust/aarch64-apple-darwin/dylint","host":"linux-x86_64","key":"0a0b9f726a80f3a4389fe7229c2bc0e7cacbc8a4b32896037d234bf40eccf24c","lane":"cross","parents":["d31a92ad2fce2bf934a04579e0e03d7bd2589e35"],"secs":245,"stamp":"07f2db33d32b4940ed8a87209d7ba48f","tree":"96ab1b92f4bffce5b57a323950af5f743440b550","v":1,"via":"run"}
Ci-Attestation: {"at":1794548695,"gate":"cpp/linux-x64/tier2","host":"linux-x86_64","key":"b05adf22c53d0b0aacb294d165547768ae0e3fd145a039a29d70ebc19351d07f","lane":"tier2-linux","parents":["d31a92ad2fce2bf934a04579e0e03d7bd2589e35"],"secs":3046,"stamp":"c17caf60ab4bd637b280263d177e7992","tree":"96ab1b92f4bffce5b57a323950af5f743440b550","v":1,"via":"run"}
Ci-Attestation: {"at":1794548695,"gate":"python/all/self-test","host":"linux-x86_64","key":"c53c5ddb531ae0caf0a6b412b17764eeee64357e2d988f7cf3e42aa9669d6f89","lane":"client-checks","parents":["d31a92ad2fce2bf934a04579e0e03d7bd2589e35"],"secs":63,"stamp":"6a64b24936ae576834b98d8c60960354","tree":"96ab1b92f4bffce5b57a323950af5f743440b550","v":1,"via":"run"}
Ci-Attestation: {"at":1794548695,"gate":"general/all/client-lint","host":"linux-x86_64","key":"f6164116c8f83c8d9056e4f45e86f5b4086814a4da814742a6ba850d21b247fa","lane":"client-lint","parents":["d31a92ad2fce2bf934a04579e0e03d7bd2589e35"],"secs":88,"stamp":"2566726a1a9ff535c5b0d0da398244b4","tree":"96ab1b92f4bffce5b57a323950af5f743440b550","v":1,"via":"run"}
Ci-Attestation: {"at":1794548695,"gate":"rust/x86_64-unknown-linux-gnu/client-clippy","host":"linux-x86_64","key":"f6164116c8f83c8d9056e4f45e86f5b4086814a4da814742a6ba850d21b247fa","lane":"client-lint","parents":["d31a92ad2fce2bf934a04579e0e03d7bd2589e35"],"secs":88,"stamp":"71882819bd8d91b9c03b112f85974596","tree":"96ab1b92f4bffce5b57a323950af5f743440b550","v":1,"via":"run"}
Ci-Attestation: {"at":1794548695,"gate":"rust/x86_64-unknown-linux-gnu/client-dylint","host":"linux-x86_64","key":"f6164116c8f83c8d9056e4f45e86f5b4086814a4da814742a6ba850d21b247fa","lane":"client-lint","parents":["d31a92ad2fce2bf934a04579e0e03d7bd2589e35"],"secs":88,"stamp":"40ce76391262f5df18d4bf5156390b32","tree":"96ab1b92f4bffce5b57a323950af5f743440b550","v":1,"via":"run"}
Ci-Attestation: {"at":1794548695,"gate":"rust/aarch64-unknown-linux-gnu/client-clippy","host":"linux-x86_64","key":"f6164116c8f83c8d9056e4f45e86f5b4086814a4da814742a6ba850d21b247fa","lane":"client-lint","parents":["d31a92ad2fce2bf934a04579e0e03d7bd2589e35"],"secs":88,"stamp":"8e2d067d9ec79b850399a92cbfaf0138","tree":"96ab1b92f4bffce5b57a323950af5f743440b550","v":1,"via":"run"}
Ci-Attestation: {"at":1794548695,"gate":"rust/aarch64-unknown-linux-gnu/client-dylint","host":"linux-x86_64","key":"f6164116c8f83c8d9056e4f45e86f5b4086814a4da814742a6ba850d21b247fa","lane":"client-lint","parents":["d31a92ad2fce2bf934a04579e0e03d7bd2589e35"],"secs":88,"stamp":"d12d1e1eae177a9e1714f879ce0c4587","tree":"96ab1b92f4bffce5b57a323950af5f743440b550","v":1,"via":"run"}
Ci-Attestation: {"at":1794548695,"gate":"rust/x86_64-pc-windows-msvc/client-clippy","host":"linux-x86_64","key":"f6164116c8f83c8d9056e4f45e86f5b4086814a4da814742a6ba850d21b247fa","lane":"client-lint","parents":["d31a92ad2fce2bf934a04579e0e03d7bd2589e35"],"secs":88,"stamp":"6890cd127cee1fbd9921adf88fd56ff2","tree":"96ab1b92f4bffce5b57a323950af5f743440b550","v":1,"via":"run"}
Ci-Attestation: {"at":1794548695,"gate":"rust/x86_64-pc-windows-msvc/client-dylint","host":"linux-x86_64","key":"f6164116c8f83c8d9056e4f45e86f5b4086814a4da814742a6ba850d21b247fa","lane":"client-lint","parents":["d31a92ad2fce2bf934a04579e0e03d7bd2589e35"],"secs":88,"stamp":"14132bfa86ab09c7cfd190ce1a850248","tree":"96ab1b92f4bffce5b57a323950af5f743440b550","v":1,"via":"run"}
Ci-Attestation: {"at":1794548695,"gate":"rust/aarch64-pc-windows-msvc/client-clippy","host":"linux-x86_64","key":"f6164116c8f83c8d9056e4f45e86f5b4086814a4da814742a6ba850d21b247fa","lane":"client-lint","parents":["d31a92ad2fce2bf934a04579e0e03d7bd2589e35"],"secs":88,"stamp":"4f6c763a58db354d528826279b14ce0e","tree":"96ab1b92f4bffce5b57a323950af5f743440b550","v":1,"via":"run"}
Ci-Attestation: {"at":1794548695,"gate":"rust/aarch64-pc-windows-msvc/client-dylint","host":"linux-x86_64","key":"f6164116c8f83c8d9056e4f45e86f5b4086814a4da814742a6ba850d21b247fa","lane":"client-lint","parents":["d31a92ad2fce2bf934a04579e0e03d7bd2589e35"],"secs":88,"stamp":"ba90ecdd54a0950c4a208607341bc672","tree":"96ab1b92f4bffce5b57a323950af5f743440b550","v":1,"via":"run"}
Ci-Attestation: {"at":1794548695,"gate":"rust/x86_64-apple-darwin/client-clippy","host":"linux-x86_64","key":"f6164116c8f83c8d9056e4f45e86f5b4086814a4da814742a6ba850d21b247fa","lane":"client-lint","parents":["d31a92ad2fce2bf934a04579e0e03d7bd2589e35"],"secs":88,"stamp":"237ca1a882aeb2e8792ee71ed6db3e3d","tree":"96ab1b92f4bffce5b57a323950af5f743440b550","v":1,"via":"run"}
Ci-Attestation: {"at":1794548695,"gate":"rust/x86_64-apple-darwin/client-dylint","host":"linux-x86_64","key":"f6164116c8f83c8d9056e4f45e86f5b4086814a4da814742a6ba850d21b247fa","lane":"client-lint","parents":["d31a92ad2fce2bf934a04579e0e03d7bd2589e35"],"secs":88,"stamp":"110ae0a8ef3ee068eea1beb05480b03e","tree":"96ab1b92f4bffce5b57a323950af5f743440b550","v":1,"via":"run"}
Ci-Attestation: {"at":1794548695,"gate":"rust/aarch64-apple-darwin/client-clippy","host":"linux-x86_64","key":"f6164116c8f83c8d9056e4f45e86f5b4086814a4da814742a6ba850d21b247fa","lane":"client-lint","parents":["d31a92ad2fce2bf934a04579e0e03d7bd2589e35"],"secs":88,"stamp":"aeafc46b88f09768a422eb90c2027bb1","tree":"96ab1b92f4bffce5b57a323950af5f743440b550","v":1,"via":"run"}
Ci-Attestation: {"at":1794548695,"gate":"rust/aarch64-apple-darwin/client-dylint","host":"linux-x86_64","key":"f6164116c8f83c8d9056e4f45e86f5b4086814a4da814742a6ba850d21b247fa","lane":"client-lint","parents":["d31a92ad2fce2bf934a04579e0e03d7bd2589e35"],"secs":88,"stamp":"802fa01056e42a79ce24f234e5b5090d","tree":"96ab1b92f4bffce5b57a323950af5f743440b550","v":1,"via":"run"}
Ci-Attestation: {"at":1794548695,"gate":"rust/x86_64-unknown-linux-gnu/client-test","host":"linux-x86_64","key":"54a501d14919185ef5b7ce47c5ffcc7b27697fdcfeb279a44785c31803e2cf03","lane":"client-test-x86_64-unknown-linux-gnu","parents":["d31a92ad2fce2bf934a04579e0e03d7bd2589e35"],"secs":326,"stamp":"ec813fd0706c12c862c195a0aa1e0d39","tree":"96ab1b92f4bffce5b57a323950af5f743440b550","v":1,"via":"run"}
@rdoupe
rdoupe requested a review from zackees as a code owner November 13, 2026 05:45
@rdoupe
rdoupe added this pull request to the merge queue Nov 13, 2026
@rdoupe

rdoupe commented Nov 13, 2026

Copy link
Copy Markdown
Collaborator Author

Handed off to the coordinator

Merged via the queue into master with commit 9800296 Nov 13, 2026
41 checks passed
@rdoupe
rdoupe deleted the fix/rust-port-extract-the-raster-and-809 branch November 13, 2026 07:04
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: Extract the raster and blend state calls before porting to obs-graphics

1 participant