Skip to content

obs-graphics: Port graphics/image-file.c.h - #1911

Merged
zackees merged 8 commits into
masterfrom
port/image-file
Oct 23, 2026
Merged

zackees merged 8 commits into
masterfrom
port/image-file

Conversation

@zackees

@zackees zackees commented Oct 23, 2026 •

Copy link
Copy Markdown
Member

Fixes #1907
Refs #1846 (unit 6)

Ports libobs/graphics/image-file.c.h (gs_image_file_ex_*) to obs-graphics.

Commits

  1. Characterization test: Characterize gs_image_file_ex before its port: test/cmocka/test_image_file.c (10 cases) with GIF/PNG fixtures in test/cmocka/data/ (written by image-file.py, uv + Pillow). Fake device on a hand-built graphics_t, as test_texture_render. Ran locally in Tier 2 against the C build: passes.
  2. RED obs-graphics: Port the image-file cases against stubs: Tier 1 mirror in obs-tests-graphics (tests/render/image_file.rs) against todo!() bodies. Result: test result: FAILED. 0 passed; 14 failed (each panics at not yet implemented).
  3. GREEN obs-graphics: Port graphics/image-file.c.h: safe core over a Host trait (libnsgif, file read, bmalloc, gs_create_texture_file_data3, gs_texture_*, log) + #[no_mangle] shim; ImageFileEx<GsHost> is struct gs_image_file_ex. File moves to libobs.ported-graphics+.h.c; export fragment obs-graphics-image_file.txt.
    test_effect_parser_lifecycle_rust links the Rust staticlib directly; its obs-graphics object now references libnsgif, which libobs.so does not export, so that executable also compiles libobs.nsgif+.h.c (cmake only; the C test is unchanged).
  4. Tier 3 obs-graphics: Compare image-file with the original C: original built as oracle_gs_image_file_ex_*; oracle crate builds libnsgif; recording stand-in extended with gs_create_texture_file_data3, gs_texture_set_image, pixel hashes and log capture. Proptest (512 cases + every file × alpha-mode walk) compares call/log stream, return values, every public field and bnum_allocs per step. Layout test for struct gs_image_file_ex.
    Mutation check: changing the zero-delay frame time to 100 ms + 1 ns made image_file_matches_original_c fail (first diff at the frame-1 tick).
  5. README row + port_comparison bench.

Results (local)

  • soldr cargo test -p obs-graphics --test obs-tests-graphics: 262 passed.
  • ./lint: clean. native_test_graph_replaces: passes (test is in tests.d only, like test_texture_render; no count change).
  • rust/tools/linux-validate/run.sh: build OK, libobs exported symbols C vs Rust IDENTICAL (1766), test_image_file passes; the run stopped on test_async_delay_audio (timing failure under local load, unrelated), so the ON pass was not completed locally — PR CI decides.

Intentional differences

None. Characterized, not endorsed (kept): failed/oversized .gif does not fall back to FFmpeg and leaks its nsgif object; init leaves mem_usage/alpha_mode/space 0; only frame 0 gets the init alpha mode; infinite-loop GIFs never count cur_loop; a tick back to the same frame returns false; 0 delay = 100 ms.

Performance (port_comparison, local, noisy)

  • image_file/tick_update: Rust 50.1 ns, C 47.2 ns
  • image_file/load_free: Rust 11.3 µs, C 10.1 µs (file read + nsgif dominated)

Follow-up commits (CI fixes)

  • Zero the image like the C memset: the exports zero the whole struct (padding included) before init, after a failed init and after free, as the C memset does. Tier 2 null_file compares the bytes.
  • Keep image-file free of the Rust heap and panics: logging builds lines in a stack buffer, with no Vec, format! or expect.
  • C adapters for allocator/log/file: test_effect_parser_lifecycle_rust links the Rust staticlib next to libobs. On Windows, link.exe resolved bmalloc/bfree for the obs-graphics object that ep_free pulls from the staticlib itself, which dragged in obs-util and caused LNK2005/LNK2019. obs-graphics (image-file and the existing texture-render) now names no obs-util symbol. It calls the private adapters in libobs/graphics/obs-graphics-adapter.c.h instead: graphics unity group, compiled by that test, copied verbatim into the oracle. I checked this on a local x86_64-pc-windows-msvc release staticlib: the symbol closure from ep_free stays inside obs-graphics.

test_image_file loads GIF and PNG fixtures (data/image-file.py writes
them) through the exported gs_image_file_ex_* on a hand-built graphics_t
with a fake device, as test_texture_render does: fields after load, failing
paths and their log lines, bnum_allocs, the texture created, tick timing
across frames and loop counts, frame updates and alpha modes. No GPU.

Refs #1907
Tier 1 mirror of test_image_file.c through a safe core whose bodies are
todo!(): ImageFileEx (struct gs_image_file_ex over a Host trait's handles)
and the timing, premultiply and format helpers. All 14 cases fail.

Refs #1907
gs_image_file_ex_* now live in obs-graphics. The safe core drives
libnsgif, the file read, the allocator, gs_create_texture_file_data3 and
the gs_texture_* calls through a Host trait in the C order; the shim
implements it with the real functions, which stay C. struct
gs_image_file_ex keeps its layout; the internal block and every buffer
are bmalloc blocks, so bnum_allocs counts them as before. image-file.c.h
moves to the ported graphics group, so hybrid libobs no longer compiles
it and the C reference still does.

test_effect_parser_lifecycle_rust links the production Rust staticlib
directly; its obs-graphics object now calls libnsgif, which libobs does
not export, so that executable compiles the vendored libnsgif group too.

Refs #1907
The original image-file.c.h is built as oracle_gs_image_file_ex_*, and
the oracle crate builds the vendored libnsgif both sides call. The
recording gs_* stand-in also stands in for gs_create_texture_file_data3
and gs_texture_set_image, hashes the pixels it is given and logs libobs
log lines. A proptest over tick/update/texture-init sequences on every
fixture and alpha mode compares that log, every return value, every
public field and bnum_allocs after each step. Layout test for struct
gs_image_file_ex.

Refs #1907
Adds the rust/README.md row and two port_comparison pairs on the
animated fixture: a tick plus texture update, and load, texture init
and free.

Fixes #1907
…y name

Tier 2 ON: null_file_test memcmps the image against zero after init and
free, padding included; the shim now zeroes the whole struct where the
C memsets it. Windows: test_effect_parser_lifecycle_rust links the
staticlib next to obs.lib; calling bmalloc/bfree/os_fopen/os_ftelli64
through obs-util's Rust paths pulled obs-util objects that clash with
obs.lib (LNK2005), so the shim declares them extern like the other
libobs functions it calls.

Refs #1907
test_effect_parser_lifecycle_rust links the staticlib next to obs.lib.
The obs-graphics objects it pulls for ep_free now also hold image-file,
whose Vec/format!/expect reached the Rust allocator, std and from there
obs-util objects that clash with obs.lib on Windows (LNK2005). Log lines
are built in a stack buffer and the impossible branches return instead of
panicking. Checked on the x86_64-pc-windows-msvc staticlib: the members
the test pulls reach neither core, std nor obs-util.

Refs #1907
… C adapters

test_effect_parser_lifecycle_rust links the Rust staticlib next to libobs.
On Windows, once ep_free pulls an obs-graphics object, link.exe resolves
that object's bmalloc/bfree from the same staticlib, which drags in
obs-util and clashes with libobs's exports (LNK2005, LNK2019). Adding
image-file moved gs_texrender_* and gs_image_file_ex_* into the CGU that
ep_free pulls.

obs-graphics now names no obs-util symbol: it calls private C adapters in
libobs/graphics/obs-graphics-adapter.c.h (the graphics unity group; the
test compiles its own copy, and the oracle copies it verbatim), so the
closure from ep_free stays inside obs-graphics.
@zackees
zackees marked this pull request as ready for review October 23, 2026 09:35
@zackees
zackees added this pull request to the merge queue Oct 23, 2026
Merged via the queue into master with commit d002b26 Oct 23, 2026
33 checks passed
@zackees
zackees deleted the port/image-file 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.

rust: Port graphics/image-file.c.h to obs-graphics

1 participant