Skip to content

obs-graphics: Port graphics/texture-render.c.h to Rust - #1861

Merged
zackees merged 5 commits into
obs-rust:masterfrom
rdoupe:port/texture-render
Oct 23, 2026
Merged

zackees merged 5 commits into
obs-rust:masterfrom
rdoupe:port/texture-render

Conversation

@rdoupe

@rdoupe rdoupe commented Oct 23, 2026

Copy link
Copy Markdown
Collaborator

Fixes #1860

What and why

Unit 5 of #1846. The eight gs_texrender_* functions from libobs/graphics/texture-render.c.h now live in obs-graphics. The file moves from libobs.graphics+.h.c to libobs.ported-graphics+.h.c. Hybrid libobs no longer compiles it, and the C reference still does. Public headers and the exported symbols do not change.

The file reads no private layout. Its struct is private to the file, and callers only hold the pointer. It calls only public graphics.h functions. The safe core drives a Device trait in the C call order. The shim implements the trait with those gs_* functions, which stay C in graphics.c.h. That is the pattern obs-missing-files uses for obs_source_get_name: libobs links the real functions, and cargo tests get a stand-in. Here the stand-in is in the oracle crate (oracle/texture_render_device.c), because every test binary that links obs-graphics also links the oracle. The texrender is a bmalloc block, so bnum_allocs counts it as before.

No intentional differences. Characterized, not endorsed, and kept:

  • A failed texture create still stores the new size. A second begin at that size does not retry and returns false.
  • A second begin before end saves the texrender's own target, so neither end restores the original target.
  • End without begin restores the zeroed previous state (no target, no zstencil, sRGB), and the next begin fails until reset.
  • The viewport size is the uint32_t size cast to int.

gs_texrender_get_format(NULL) is not checked, as in the C.

Tests:

  • Tier 2: test/cmocka/test_texture_render.c, 13 cases. No GPU or display: the fixture builds a graphics_t with a recording fake device in its exports and enters it with gs_enter_context. It calls the exported gs_texrender_*, so it runs the C or the Rust, whichever libobs is loaded.
  • Tier 1: the same 13 cases, plus one edge case, in obs-tests-graphics (render::texture_render). They run through the safe core with a fake that does what graphics.c does, and the expected strings are the C test's strings.
  • Tier 3: render::texture_render_parity compares the shim with the original file, which is built as oracle_gs_texrender_*. Both sides call the same recording gs_* stand-in, which logs every call with its arguments, null destroys and matrix calls included. Seven fixed sequences cover the cmocka cases' situations, and 512 proptest sequences of up to 48 operations cover the rest. The test compares the whole log, every return value, the returned device handles and bnum_allocs after each step. It runs in its own child process, because the stand-in and the allocation counter are process-wide.
  • Mutation check: three breaks, each reverted. Swapping matrix_pop and projection_pop in end failed it. Storing the size only after a successful create failed it. Dropping the saved color space failed it. With the fixed sequences disabled, the proptest alone also caught the size change.

port_comparison (soldr cargo bench -p obs-c-oracle --bench port_comparison -- texture_render), medians. The stand-in does not record during the benches:

bench run Rust C
begin_end_reset 1 253.9 ns 111.5 ns
begin_end_reset 2 90.5 ns 145.1 ns
begin_end_reset 3 151.7 ns 128.5 ns
create_resize_destroy 1 142.8 ns 187.0 ns
create_resize_destroy 2 148.3 ns 320.8 ns
create_resize_destroy 3 415.5 ns 278.7 ns

These came from a shared build host with a load average of 25 to 31, pinned to one CPU, and they do not settle which side is faster: the order changes from run to run and the confidence intervals overlap. They should be rerun on a quiet machine before anyone reads them as a regression or a gain.

RED → GREEN

  • RED commit: c47b8350e37a77763444f5ea4b8d5b2a079b886e. The 13 render::texture_render tests panic in todo!() (not yet implemented), 0 passed, 13 failed.
  • GREEN: e833989708d9119998e77697d1aea0f94c7e9a3e. obs-tests-graphics passes 245/245 at GREEN, including the 13 texrender cases, and 246/246 at the head with the parity test (c2ccca498). The obs-media-io harness passes 237/237, and every workspace test binary builds and links on the host, for Windows MSVC and for macOS arm64 (the local gate cross lane). test_texture_render passes 13/13 against the C build (OBS_LIBOBS_BACKEND=C), against libobs-c-reference and against hybrid libobs. Each run loaded the intended libobs.so. All three libobs.so export the same 1766 symbols. Hybrid libobs compiles libobs.graphics+.h.c and not libobs.ported-graphics+.h.c. The C reference compiles both.
  • Real app (UI, protocol output or logging changes): not applicable. No UI, protocol or logging change.

Full ctest on the hybrid tree (private Xvfb, dbus-run-session): against hybrid libobs 382/382. Against libobs-c-reference, 381/382: test_deinterlace_2x_field_order failed while the host was at a load average of about 30, then passed 2/2 alone against each library. A run before the last rebase had the same pattern: test_pulse_monitor_device failed against the C reference while another pulse test ran on the host, then passed alone. Neither test touches texrender. The only skips are open_crashes_without_obs_core (by design while obs core is up) and test_hex_float_values_ignore_comma_locale (no comma-decimal locale installed on the host), the same on both. Local gate lint and cross lanes pass.

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). Characterization eec7df67a, RED c47b8350e, GREEN e83398970.
  • 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. None. The oracle wrapper turns off -Wsign-conversion around the unchanged original, which passes its uint32_t size to gs_set_viewport's int parameters.
  • Intentional differences from C listed in the parity test header and rust/README.md (ports). None.

Records every device call gs_texrender_* makes through graphics.c on a
fake device in a hand-built graphics_t, so the test needs no GPU and runs
against the C build, the C reference and hybrid libobs.

Refs obs-rust#1860
Tier 1 mirror of test_texture_render.c through a safe core whose bodies
are todo!().

Refs obs-rust#1860
gs_texrender_* now live in obs-graphics. The safe core drives a Device
trait in the C call order; the shim implements it with the public gs_*
functions, which stay C in graphics.c.h. The texrender is a bmalloc block,
so bnum_allocs counts it as before. texture-render.c.h moves to the
ported graphics group, so hybrid libobs no longer compiles it and the C
reference still does.

Cargo tests have no graphics context: the oracle crate supplies a
recording stand-in for the gs_* functions the shim calls.

Refs obs-rust#1860
The original texture-render.c.h is built as oracle_gs_texrender_*. Both
sides run the same operation sequences on the recording gs_* stand-in,
and the test compares the full call log with arguments, every return
value and bnum_allocs after each step.

Refs obs-rust#1860
Adds the rust/README.md row and two port_comparison pairs: a begin, end
and reset frame on a sized texrender, and create, size and destroy. The
oracle's gs_* stand-in stops recording for them, so they time the state
machine and its graphics calls.

Fixes obs-rust#1860
@rdoupe
rdoupe requested a review from zackees as a code owner October 23, 2026 02:36
@zackees
zackees enabled auto-merge October 23, 2026 02:55
@zackees
zackees added this pull request to the merge queue Oct 23, 2026
Merged via the queue into obs-rust:master with commit 019272e Oct 23, 2026
32 checks passed
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 graphics/texture-render.c.h to obs-graphics

2 participants