Skip to content

obs-graphics: Port the graphics state stacks (#2517, fixes #2519) - #2528

Merged
zackees merged 7 commits into
masterfrom
port/2517-gs-state-stacks
Oct 26, 2026
Merged

zackees merged 7 commits into
masterfrom
port/2517-gs-state-stacks

Conversation

@vpacher

@vpacher vpacher commented Oct 26, 2026 •

Copy link
Copy Markdown
Member

Fixes #2517
Fixes #2519

The state stacks of the graphics context (the matrix stack, the viewport stack and the blend state stack, from libobs/graphics/graphics.c) are ported to obs_graphics::state_stacks. #2519 (gs_reset_blend_state does not reset a blend op that is not ADD) is fixed in the C before the port. #2518 (#2520) is already in master.

What changed

  • Extraction (behaviour-neutral C). The stack code moves out of graphics.c.h into libobs/graphics/graphics-state-stacks.c.h with the header graphics-state-stacks.h. The functions operate on a struct darray and an index. struct blend_state moves into the new header. graphics.c.h keeps gs_valid, the device calls, the "Tried to pop last matrix on stack" log and the darrays of graphics_subsystem. gs_reset_blend_state now applies the steps of gs_blend_state_reset_steps.
  • Characterization. test_graphics_state_stacks (cmocka, 5 cases): push and pop, each operation on the top against the matrix4 functions, the viewport stack, the blend state stack and the reset steps.
  • bug: libobs/graphics: gs_reset_blend_state leaves a non-default blend op when the blend function is the default #2519 fix (RED, then GREEN). gs_blend_state_reset_steps sets op when the function is not the default, or when the op is not GS_BLEND_OP_ADD. Before, a default function with SUBTRACT, REVERSE_SUBTRACT, MIN or MAX kept that op after the reset.
  • Port. rust/obs-graphics/src/state_stacks.rs (safe core, on Matrix4 and a Stack trait) and src/ffi/state_stacks.rs (shims). DarrayStack is the Stack over a C darray. It grows and erases as util/darray.h does, on libobs's allocator through the C adapters (obs_graphics_bmalloc/obs_graphics_bfree), as the other obs-graphics shims do. It names nothing from obs-util except the darray type, so a test that links libobs_rust-static does not pull obs-util (libuuid, GIO; export clashes on Windows). A push writes in place when there is capacity, and a pop of the last element only lowers num. graphics-state-stacks.c.h moves to the ported group libobs.ported-graphics-state-stacks with its own PCH. Not EXPORT, so the shims are hidden (rust-hidden.txt, rust-exports.map, rust-unexports-macos.txt). ci/test_ported_sources.py, the C oracle (oracle/graphics_state_stacks.c, the original on the C graphics math), Tier 3 and the bench are added, and rust/README.md has a new row.
  • test_graphics_state_stacks_rust. The same five cmocka cases against the shims, with AddressSanitizer and UBSan. It links like test_sprite_geometry_steps_rust.

Intentional differences (C dereferences null or reads past its darray; graphics.c never gets there)

  • Null pointers do nothing: a pop returns false, and the reset has no steps.
  • An index past the stack reads nothing and changes nothing.

Tests

  • Tier 1 (render::state_stacks): the five cmocka cases, one edge case and a proptest (1 000 sequences of pushes, pops and operations against a model on Matrix4).
  • Tier 3 (render::state_stacks_parity): the struct layouts and enum values, and 5 000 random sequences of up to 60 calls on all three stacks. The matrix arguments include NaN and infinities. After each call, the results, the index, every element and the capacity of the three darrays are compared against the oracle: floats bit for bit, any NaN equal to any NaN (docs/rust-port/testing-policy.md, as in linear::matrix4_parity); blend states by field, so no padding is read. The stacks only copy the matrices; the NaN signs come from the matrix4 math (on x86_64, matrix4_rotate_aa_i with an infinite axis gives +NaN in Rust and -NaN in C). The intentional differences and the DarrayStack boundaries are tested on the shim alone.
  • Mutation check: 16 mutants of the core and the shim. 14 are killed (some only after the DarrayStack boundary test and the capacity comparison were added). Two are equivalent: matrix_pop erases cur, which is always the last index, so erase(cur) and pop() are the same (cur + 1 == len is asserted by the Tier 1 proptest); and the max(new_size) in the growth, because a push grows by one, so doubling a non-zero capacity is always enough.

Bench (port_comparison, state_stacks/scene_1000_items, Apple M-series)

One scene of 1 000 items. For each item: push, translate, rotate about z, scale, read the top and pop. The blend state is pushed and popped around the items.

Rust C
Full scene (3 runs) 55.1–56.5 µs 53.5–55.2 µs
Stack layer only (push, get, pop; 2 runs) 6.44 µs 6.34–6.40 µs

The stack layer is at parity. Without the in-place push and the last-element pop, it was +26 %. The full scene is 1–5 % slower than C. The rest of its time is the matrix math, which is already Rust (obs-graphics::matrix4).

Tier 2 (Linux x86_64, Debian 13)

  • All targets build (cmake --build --target all), so every _rust test that links libobs_rust-static links.
  • Lint lane (ci/local_gate.py --lane lint) passes.
  • render::state_stacks and render::state_stacks_parity pass on x86_64 (11/11).
  • 12/12 on the hybrid libobs and on libobs-c-reference: test_graphics_state_stacks, test_graphics_state_stacks_rust (ASan, UBSan), test_graphics_no_context, test_sprite_geometry_steps, test_sprite_geometry_steps_rust, test_effect_parser_lifecycle, test_effect_parser_lifecycle_rust, test_nsgif_decode, test_nsgif_decode_rust, test_texture_render, test_sprite_flip_render and test_scene_rotated_scale_filter. The render tests run under xvfb-run.
  • Exported symbols: 1766 on both. The 16 shims are local.

Checklist

🤖 Generated with Claude Code

vpacher and others added 4 commits October 26, 2026 20:30
…tacks.c

The state stacks of the graphics context move from graphics.c to
graphics-state-stacks.c behind graphics-state-stacks.h for the port
(#2517): the matrix stack (push, pop, the top and its operations:
identity, transpose, set, get, mul, rotate by quaternion and by
axis-angle, translate, scale), the viewport stack (push, pop) and the
blend state stack (push, pop) with the steps of gs_reset_blend_state.
They work on the graphics_subsystem fields by pointer (the darrays and
the matrix index); graphics.c keeps gs_valid, the device calls
(gs_get_viewport, gs_set_viewport, gs_enable_blending,
gs_blend_function_separate, gs_blend_op) and the logging, and calls the
steps. A pop returns the viewport or blend state to restore; the reset
returns which device steps to take. struct blend_state moves to the new
header.

Behaviour-neutral: the same steps in the same order. gs_viewport_push
gets the device's viewport into a zeroed rectangle and pushes a copy, as
da_push_back_new zeroed the new element before gs_get_viewport filled
it; the pops read the element before they remove it, and graphics.c
restores from the copy. The rendering tests (test_texture_render,
test_sprite_flip_render, test_scene_rotated_scale_filter,
test_scene_duplicate_scale_ref, test_group_empty_bounds,
test_darken_transparent, test_color_correction_16f,
test_scroll_filter_wide_source, test_filter_skip_removed,
test_source_draw_plan_steps) pass on the C reference and the hybrid
libobs, rendered under Xvfb (Mesa llvmpipe).

Refs #2517

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…tacks.h (#2517)

test_graphics_state_stacks: five cases for graphics-state-stacks.c
before its port, on plain darrays without a graphics context: push and
pop of the matrix stack to depth 5 (push copies the top, an operation
changes only the top, pop brings back the one below, the last matrix
stays and pop says so); every operation on the top (identity, transpose,
set, get, mul, rotate by quaternion and by axis-angle, translate, scale)
at depths 0 to 2 against the matrix4 function on the same matrix; the
viewport and blend state stacks (pop in reverse order, an empty pop
changes nothing); and the steps of gs_reset_blend_state (the default
state, blending off, each function field off its default, a Subtract
style state, the default function with another op). 5/5 on the C.

The last reset case pins today's behaviour, the op left as it is; #2519
changes it in the next commits.

Refs #2517

Co-Authored-By: Claude Opus 5.5 <[email protected]>
blend_reset_steps now expects the op step for the default blend function
with each other op (subtract, reverse subtract, min, max): the reset is
documented to set the blend state to its default, and the op is part of
it since 33a6d2a. RED: the op is reset only with the function.

Refs #2519

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…#2519)

gs_reset_blend_state is documented to set the blend state to its
default value, and since blend ops were added (33a6d2a, 2021) the op is
part of that state, but the reset set the op back to GS_BLEND_OP_ADD only
when the blend function also differed from the default. With the default
function and another op (a plugin or a script can set one with
gs_blend_op), the op stayed, and a scene rendered after the reset in
scene_video_render drew with it. OBS's own blend modes with another op
also change the function, so they were not affected.

Now the op step is taken whenever the op is not GS_BLEND_OP_ADD, and with
the function step as before. Unchanged in upstream OBS master.

GREEN: blend_reset_steps passes, 5/5.

Fixes #2519

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@vpacher
vpacher requested a review from zackees as a code owner October 26, 2026 19:31
@zackees

zackees commented Oct 26, 2026

Copy link
Copy Markdown
Member

Two real failures in Rust Tier 2 Linux (run 40387545201):

  1. Parity mismatch on NaN sign. In render::state_stacks_parity::sequences (rust/obs-graphics/tests/render/state_stacks_parity.rs:205, minimal input RotAa([inf, 0.0, NaN, 0.0]) at line 300), the matrix bytes differ only in NaN sign: the C gives 00 00 c0 ff (-NaN) in four slots where Rust gives 00 00 c0 7f (+NaN). The Rust rotation arithmetic is ordered or signed differently from C's matrix4_rotate_aa (for example a - b vs -(b - a), or a negation applied to a NaN). Match the C's operation order. Don't normalize the NaN sign in the test: libobs ABI parity includes the bit patterns.
  2. Link error. test/cmocka/test_sprite_geometry_steps_rust fails with libuuid.so.1: error adding symbols: DSO missing from command line. The new Rust symbols in libobs probably pull in uuid, and that target doesn't link it. Add uuid to that target's libraries, or check what in the test's link line changed.

vpacher and others added 2 commits October 26, 2026 21:08
The safe core of libobs/graphics/graphics-state-stacks.c.h as
obs_graphics::state_stacks, with todo!() bodies: matrix_push, matrix_pop,
matrix_apply (MatrixOp: identity, transpose, set, mul, rotate by
quaternion and by axis-angle, translate, scale), matrix_get, state_push
and state_pop for the viewport and blend state stacks, and
blend_reset_steps, over a Stack trait (Vec here, the C darrays in the
shim), with #[repr(C)] GsRect, BlendState and BlendReset.

Tier 1 (render::state_stacks): the five cmocka cases one to one, an edge
case (an index past the stack changes nothing), and a proptest (any
sequence of pushes, pops and operations: the depth and every matrix of
the stack match a model on Matrix4).

RED: 0 of 7 pass.

Refs #2517

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Swaps libobs/graphics/graphics-state-stacks.c.h in hybrid libobs (group
libobs.ported-graphics-state-stacks, with its own PCH) for the shims in
obs_graphics::ffi::state_stacks over the safe core state_stacks: the
matrix stack (push, pop and the operations on the top, on Matrix4), the
viewport and blend state stacks and gs_blend_state_reset_steps.
graphics.c stays C and keeps gs_valid, the device calls, the log and the
darrays of graphics_subsystem.

DarrayStack is the core's Stack over a C darray. A push writes in place
when the capacity is there and a pop of the last element only lowers
num, as the inline da_* macros do; growth and other erases go through
obs-util's darray functions.

Intentional differences, where C dereferences null or reads past its
darray and graphics.c never gets there: null pointers do nothing (a pop
returns false, the reset has no steps); an index past the stack reads
and changes nothing.

Tests:
- No test_graphics_state_stacks_rust: the shims grow the darrays
  through obs-util, whose archive member does not link on its own
  (libuuid, GIO), as for test_context_name_helpers. The C test keeps
  the C; test_graphics_no_context and the render tests run the shims
  through the hybrid libobs.
- Tier 3 render::state_stacks_parity: the layouts and enum values, and
  5 000 random sequences of up to 60 calls on all three stacks (NaN and
  infinities in the matrix arguments), compared bit for bit after every
  call against the oracle (the original C on the C graphics math).
- DarrayStack boundaries: erase in the middle, and no read or write of
  the spare capacity past num.
- Bench port_comparison state_stacks/scene_1000_items.

Closes #2517

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@vpacher
vpacher force-pushed the port/2517-gs-state-stacks branch from 7cc8840 to 1144ac9 Compare October 26, 2026 20:13
@vpacher

vpacher commented Oct 26, 2026

Copy link
Copy Markdown
Member Author

Thanks. Both are fixed in the force-push.

1. NaN sign. The difference does not come from the stack code. The stacks only copy the matrices. It comes from matrix4_rotate_aa_i, which is already in master. On x86_64 the shim and the oracle give the same four lanes as in your log, without any stack (aa = {inf, 0, NaN, 0} on the identity: Rust 7fc00000, C ffc00000, in y.x..y.w). Rust does not specify the sign and payload of a NaN that an arithmetic operation makes (RFC 3514, float semantics), so a bit-exact NaN sign is not something the Rust math can promise. docs/rust-port/testing-policy.md (line 294) says Tier 3 is "exact bit equality (NaN == NaN)", and linear::matrix4_parity compares the same matrix4_rotate_aa_i with "any NaN equals any NaN". My new test compared raw bytes, so it was stricter than the policy and stricter than the matrix4 port. It now uses the policy's rule. All other bits, signed zero included, are still exact.

If we want NaN-sign parity for libobs math, that is a change to the policy and to the matrix4 port, not to this PR. I can open an issue for it if you want one.

2. Link error. You were right about the cause. The shim called obs-util's darray_push_back/darray_erase, so libobs_rust-static's obs-graphics object pulled obs-util (libuuid, GIO) into every _rust test that links it. Adding uuid to one target would only move the problem. On Windows the same pull clashes with libobs's exports, as the note in ffi/image_file.rs says. The shim now grows the darrays itself, the way util/darray.h does, on obs_graphics_bmalloc/obs_graphics_bfree, as the other obs-graphics shims do. It names nothing from obs-util except the darray type. Because of that, test_graphics_state_stacks_rust links again and is back, with ASan and UBSan.

Also: Tier 3 now compares the darrays' capacity (the growth rule) and compares the blend states by field (no padding bytes).

Tier 2 on Linux x86_64, all targets built: 12/12 on both libobs builds, among them test_sprite_geometry_steps_rust, test_effect_parser_lifecycle_rust, test_nsgif_decode_rust and test_graphics_state_stacks_rust; the state-stacks Tier 1 and Tier 3 pass on x86_64; exports 1766 on both; lint lane passes.

@zackees

zackees commented Oct 26, 2026

Copy link
Copy Markdown
Member

Correction to my earlier comment: Tier 3 treats any NaN as equal to any NaN (testing-policy.md:294, as in linear::matrix4_parity), so comparing NaN that way in the parity test is right. Ignore my "match the C's operation order" advice. I pushed the missing features-ledger line for the #2519 blend-op fix.

@zackees zackees left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed:

  • The order is right: #2519 is RED then GREEN in C before the port, then the port gets a RED commit with todo! and then GREEN.
  • The behaviour-neutral extraction has a 5-case characterization test, plus a Rust run of the same cmocka cases under ASan/UBSan.
  • The C oracle, Tier 3 sequences, bench and export lists are all updated.
  • The intentional differences (null pointers and out-of-range indexes do nothing) are documented and tested on the shim only.
  • No existing C test or public header changed; graphics-internal.h is internal.

Queuing; it goes in when CI is green.

@zackees
zackees enabled auto-merge October 26, 2026 20:22
@zackees
zackees added this pull request to the merge queue Oct 26, 2026
Merged via the queue into master with commit 3321450 Oct 26, 2026
36 checks passed
@zackees
zackees deleted the port/2517-gs-state-stacks branch October 26, 2026 20:46
zackees added a commit that referenced this pull request Oct 26, 2026
… libnsgif group

#2528 added this target on master with libobs.nsgif+.h.c, which this PR
moves into the Rust staticlib; the merge queue failed at configure.
@rdoupe

rdoupe commented Oct 26, 2026

Copy link
Copy Markdown
Collaborator

The Rust Tier 2 Windows job now fails on PRs based on master since this merged, at link time of the new test_graphics_state_stacks_rust:

libobs_rust.lib(obs_graphics-...rcgu.o) : error LNK2005: matrix4_mul already defined in obs.lib(obs.dll)
... matrix4_rotate_aa_i, matrix4_rotate_i, matrix4_scale_i, matrix4_translate3v_i, matrix4_transpose ...
test_graphics_state_stacks_rust.exe : fatal error LNK1169: one or more multiply defined symbols found

Seen on #2531 (job 121854751431), which doesn't touch graphics. Master's push run skips that job, so it doesn't show there. The _rust test links both obs.lib and libobs_rust.lib, and on MSVC the matrix symbols come from both.

@vpacher

vpacher commented Oct 26, 2026

Copy link
Copy Markdown
Member Author

Thanks, and sorry for the broken lane. That was my test. #2534 (skip on MSVC) unblocks the Windows lane, and #2533 tracks the real fix.

The cause: test_graphics_state_stacks.c calls six exported functions to compute its expected values: matrix4_mul, matrix4_rotate_i, matrix4_rotate_aa_i, matrix4_scale_i, matrix4_translate3v_i and matrix4_transpose. Those are exactly the six symbols in the LNK2005 list. On MSVC they resolve through obs.lib. The libobs_rust.lib member that provides the hidden gs_matrix_stack_* shims also defines those six, so MSVC finds a second definition. The ELF and Mach-O linkers accept the archive definition next to the shared library's, so Linux and macOS pass, and I tested only on Linux before the merge.

I will take #2533 after the current PRs are through, and test the fix on a Windows machine before the PR.

zackees added a commit that referenced this pull request Oct 26, 2026
… libnsgif group

#2528 added this target on master with libobs.nsgif+.h.c, which this PR
moves into the Rust staticlib.
vpacher pushed a commit that referenced this pull request Oct 26, 2026
… libnsgif group

#2528 added this target on master with libobs.nsgif+.h.c, which this PR
moves into the Rust staticlib.
vpacher added a commit that referenced this pull request Oct 27, 2026
…group

#2528 added test_graphics_state_stacks_rust on master with
libobs.nsgif+.h.c, which this PR moves into the Rust staticlib; #2537 then
gave that file MSVC warning options. Drop the file and its MSVC block. Also
drop the two MSVC set_source_files_properties blocks that no longer name a
file (test_sprite_geometry_steps_rust, test_effect_parser_lifecycle_rust).

Co-Authored-By: Zach Vorhies <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
MCPVOT pushed a commit to MCPVOT/obs-studio that referenced this pull request Oct 30, 2026
…t#2510) (obs-rust#2514)

* test: Characterize the libnsgif state machine and public API through nsgif.h (obs-rust#2510)

Ten cases for gif.c before its port, on GIFs that a small writer in the
test builds (header, screen descriptor, colour tables, graphic control
and loop count extensions, images of one colour from the LZW emitter):
the error and disposal strings; the nine bitmap formats and their byte
orders, and the default black and white table; a whole scan (info, frame
info, the default delay of a frame without a graphic control extension,
local palettes, a second scan, a scan after nsgif_data_complete); scans
in two parts and byte by byte; the screen size quirk with the first
frame setting or growing the size; a GIF without frames, a cut one and
not a GIF; nsgif_data_complete for a frame cut in its image data (also
frame 0, which gets transparency); the frame order of
nsgif_frame_prepare with the redraw area, the delay rules, play once,
loop forever, data not complete and one frame; the disposal across
frames (restore background with and without transparency, restore
previous), a restart, a cached frame and a bad frame number; the bitmap
callbacks and a row span wider than the image. 39/39 on the C.

Kept, characterized, not endorsed:
- When a scan stops at the end of the data inside a frame,
  nsgif_data_scan keeps the position where the frame's parse stopped,
  not the frame's start. The next scan reads image data or an
  extension's terminator as the next block: a bad frame from then on,
  also with all the data. A split inside the image data or on an
  extension's last byte breaks a scan in parts; OBS scans whole files.
- With play once (no loop extension), one more nsgif_frame_prepare after
  the last frame (infinite delay) shows frame 0 again before
  NSGIF_ERR_ANIMATION_END.

Refs obs-rust#2510

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* obs-graphics: RED for the libnsgif state machine and public API (todo!)

The safe core of libobs/graphics/libnsgif/gif.c.h as obs_graphics::gif,
with todo!() bodies: Gif<B: Bitmaps> with new, set_frame_delay_behaviour,
data_scan, data_complete, reset, frame_prepare, frame_decode, info,
frame_info, global_palette and local_palette, and strerror and
str_disposal. Info and FrameInfo have the C layout of nsgif_info_t and
nsgif_frame_info_t, which the API returns pointers to. Bitmaps is the
client's nsgif_bitmap_cb_vt, with default methods for the optional
callbacks. Every call that reads the GIF data takes it. gif_blocks'
disposal constants get UNSPECIFIED and NONE.

Tier 1 (render::gif in obs-tests-graphics): the ten cmocka cases one to
one with the same GIF writer, edge cases (dropping a Gif destroys its
bitmap; a bitmap that cannot be created is out of memory) and a proptest
(random and mutated GIFs, scanned in parts, then random calls: no panic,
the frame count never shrinks).

RED: 0 of 13 pass.

Refs obs-rust#2510

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* obs-graphics: Port the libnsgif state machine and public API (obs-rust#2510)

GREEN for obs_graphics::gif: the safe core (the frame table and the scan
positions of nsgif_data_scan with its frame parse on the gif_blocks
parsers, nsgif_data_complete, the frame order, loop count and delay
rules of nsgif_frame_prepare, nsgif_frame_decode with the disposal
across frames, the saved frame and the bitmap callbacks on the gif_frame
decode, the palettes and the strings; the C's uint32_t arithmetic as
wrapping operations) and a thin hidden #[no_mangle] shim for the
fourteen functions of nsgif.h. nsgif_t is NsgifCtx: the safe Gif plus the
buffer of the last scan; Info and FrameInfo have the C layout, as the API
returns pointers to them; nsgif_bitmap_cb_vt is BitmapCbVt, which
implements the Bitmaps trait over the client's function pointers.

gif.c.h, the last C file of libnsgif, moves from libobs.nsgif to the
ported group libobs.ported-nsgif-gif (its PCH renamed with it), so the
hybrid libobs has no libnsgif C left. The C oracle no longer builds
libnsgif as a library: image-file.c.h in the oracle calls the Rust shims,
as libobs does, and oracle/gif.c is gif.c.h renamed, calling the C
oracles of the other three files, for the parity test. The _rust test
executables (test_effect_parser_lifecycle_rust,
test_sprite_geometry_steps_rust, test_nsgif_decode_rust) take libnsgif
from the staticlib instead of compiling the group.

Tier 1: 13/13. Tier 3 (render::gif_parity): the strings, and 3 000 random
cases of generated GIFs (one to four frames, every disposal, delays,
transparency, rectangles inside and past the screen, interlace, local
tables, loop counts, the screen size quirk), mutated or cut, and random
bytes; scanned whole or in two to four parts, with or without
nsgif_data_complete, in all nine bitmap formats, with or without a row
span wider than the image and the optional callbacks; then random
prepares, decodes, resets and delay rules. After every call the result,
the info, every frame info, both palettes, the prepare outputs, the
decoded bitmap and the callback counts match the whole of libnsgif in C.
3/3 with the shim-only null pointer test. test_nsgif_decode_rust runs the
thirty-nine cmocka cases against the shims without any libnsgif C.

port_comparison (M1 Max, five 1920x1080 frames scanned and decoded through
the API, Rust on Rust, C on C, three runs): 49.3 to 50.6 ms, C 53.0 to
54.4 ms.

Refs obs-rust#2510

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* obs-build: Drop the Windows warning options of the ported libnsgif group

The Windows Rust build of libobs (rust/obs-build) gave the C group
libobs.nsgif /wd4244 /wd4267. obs-rust#2510 moves gif.c.h to the ported group
libobs.ported-nsgif-gif, which is not in that build target (the hybrid
takes libnsgif from Rust), and the build refuses options for sources
outside its target ("compiler options refer to sources outside this
target", native_libobs::windows_tests::core_builds_from_the_canonical_manifest
in Rust Tier 2 windows). The other three ported libnsgif groups have no
entry either.

Refs obs-rust#2510

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fixup: the _rust cmocka tests no longer compile the removed libnsgif group

obs-rust#2528 added test_graphics_state_stacks_rust on master with
libobs.nsgif+.h.c, which this PR moves into the Rust staticlib; obs-rust#2537 then
gave that file MSVC warning options. Drop the file and its MSVC block. Also
drop the two MSVC set_source_files_properties blocks that no longer name a
file (test_sprite_geometry_steps_rust, test_effect_parser_lifecycle_rust).

Co-Authored-By: Zach Vorhies <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>

* obs-graphics: Bound the gif_parity bitmaps; exclude a C read past the data

Two defects in render::gif_parity::api (obs-rust#2510), both from random seeds:

- A mutated logical screen descriptor can ask the bitmap callback for up
  to 65535 x 65535 pixels. cb_create allocated and filled that (17 GB),
  for the C and the Rust decoder. This starved the 16 GB CI runners:
  all three Fast Gate exit-143 runner losses of this PR (runs
  40380261405 attempts 1 and 2, merge queue run 40478704942). With a
  6 GB limit, 3 of 10 runs were OOM-killed. cb_create now returns NULL
  above 4 M pixels (16 MiB), as an out-of-memory host does; both sides
  get the same callback.

- After a scan that stops inside a frame's local colour table,
  nsgif_local_palette in C decodes the table from past the end of the
  data (buf_len); the Rust decodes only the bytes in the data. This is
  an intentional difference (OBS does not call nsgif_local_palette).
  The views now compare, for frames at or after frame_count, only
  whether there is a local palette and its size. The shrunk case is
  kept in proptest-regressions/gif_parity.txt; rust/README.md lists the
  difference.

Verified: the saved case passes; 50 runs (150 000 random cases) pass,
maximum resident size 154 MB; obs-tests-graphics 420/420; clippy clean.

Refs obs-rust#2510

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
Co-authored-by: Zach Vorhies <[email protected]>
MCPVOT pushed a commit to MCPVOT/obs-studio that referenced this pull request Oct 30, 2026
)

* test(obs-core): Make audio_discard_parity's random cases cheap and fewer

random_cases_match took 147.9 s in Fast Gate (58 s on an M-series Mac),
the slowest test of the step (obs-rust#2891).

Two changes:

- Each side built its 8 input deques with one deque_push_back() per
  f32 (up to 3,200 frames per channel) and read them back with one
  deque_pop_front() per f32: about 100,000 calls per case. Source::new
  now reserves the capacity that pushing one f32 at a time from empty
  reaches (4 bytes doubled until it fits) and pushes each channel once;
  end() pops each deque once. Each deque starts in the same state as
  before (start 0, end at the size, the same capacity) and the same
  samples come back. The new one_push_matches_one_push_per_sample
  checks that for 0 to 300 frames and the power-of-two edges up to 3,199.
  With 20,000 cases: 58 s to 11 s.
- 20,000 cases to 1,000. The 19 mutants of obs-rust#2404, rebuilt and run
  again: every one still fails the audio_discard tests. Run against
  random_cases_match alone, 5 runs each, 16 fail within 125 cases in
  every run. The other 3 (no 1 ns adjustment, in sync as `>`, the shim
  clearing timing_set only with the warning) need an exact boundary that
  random inputs do not reach: at 20,000 cases two never failed and one
  failed in 1 of 2 runs. The chosen cases find all three.

random_cases_match: 0.56 s, 17 MB peak RSS over 25 runs (macOS arm64,
debug). The comparison, the input ranges and every other test are
unchanged. The proptest regression file keeps the seeds the mutants
failed on.

Refs obs-rust#2891

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* test(obs-core): Sample the start frames and cut the mix cases of audio_mix_parity

mix_on_every_start_frame took 31.8 s and mix_matches 21.6 s in Fast
Gate (17.6 s and 12.1 s on an M-series Mac), about 3 ms per mix: each
compare_mix() makes two sets of 6 x 8 x 1024 random samples and checks
every sample bit for bit (obs-rust#2891).

- mix_on_every_start_frame becomes mix_on_sampled_start_frames: the
  first and the last 8 start frames and every 61st between them (32 of
  1024; 61 is prime, so the frames fall on varied offsets), each on the
  frame's time and one ns before and after, at 44.1 and 48 kHz, as
  before.
- mix_matches: 4096 cases to 512.

The mix mutants of obs-rust#1909, rebuilt (the window end inclusive, = instead
of +=, the start frame ignored, the window start as <=, the start frame
plus one, frames counted from one ns late, the shim ignoring the channel
count or one channel short, and the equivalent frame 1024 accepted):
all 8 real ones still fail the audio_mix tests, and the equivalent one
survives, as before. mix_matches alone, 5 runs each: 7 of 8 fail within
64 cases in every run; frames counted from one ns late fails
mix_on_sampled_start_frames. The window end inclusive needs audio at
the window's end, which the every-frame test did not check either;
mix_matches and Tier 1 find it.

macOS arm64, debug, 25 runs: mix_on_sampled_start_frames 0.62 s and
13 MB peak RSS, mix_matches 1.88 s and 15 MB. The comparison, the
buffering and frame-count tests and the input ranges are unchanged.

Refs obs-rust#2891

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* test(obs-graphics): Cut state_stacks_parity's random sequences to 500

sequences took 30.9 s in Fast Gate (14.3 s on an M-series Mac): 5,000
random sequences of up to 60 calls, each compared on both sides with the
whole stack state after every call (obs-rust#2891).

5,000 cases to 500. obs-rust#2528 lists 16 mutants without naming the 14 it
killed, so they were rebuilt from the core and the shim: push keeping
cur, the pop floor at 1, pop without the erase, the multiply in the
other order, transpose and identity ignored, translate as scale,
state_pop returning the first entry or not popping, the blend reset
with enable not inverted, the op ignoring the function, the function
without dest_a, and in the shim: the erase of the last element keeping
num, push not counting, and the capacity growing by one. All 15 fail
sequences alone within 125 cases in every one of 5 runs; the equivalent
one obs-rust#2528 names (no max(new_size) in the growth) survives, as before.
1,000 cases would still take about 6 s on the CI runner, so 500 (4x the
need) keeps it under the 5 s that obs-rust#2888 proposes.

macOS arm64, debug, 25 runs: 1.50 s and 15 MB peak RSS. The calls, the
comparison after every call and every other test are unchanged. The
proptest regression files keep the seeds the mutants failed on.

Refs obs-rust#2891

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Local-Gate: v1 tree=8cec7172b177aead0ee3374cc102d09e830003a5 secs=340 lanes=lint:run,rust-test:run,cross:run,tier2-linux:run,macos-native:n/a,windows-native:n/a
Ci-Attestation: {"at":1793263864,"gate":"rust/all/fmt","host":"linux-x86_64","key":"be9de4060c380e3fd3e326cc0ce090e9ac1874b2ad14138f5f0d3a9c1bc97d08","lane":"lint","parents":["c5fdd95feb1daa789bb69e17b52aff8821e3be74"],"secs":75,"stamp":"9eaa0726b440abd9db3f8c736ab1f641","tree":"8cec7172b177aead0ee3374cc102d09e830003a5","v":1,"via":"run"}
Ci-Attestation: {"at":1793263864,"gate":"rust/x86_64-unknown-linux-gnu/clippy","host":"linux-x86_64","key":"be9de4060c380e3fd3e326cc0ce090e9ac1874b2ad14138f5f0d3a9c1bc97d08","lane":"lint","parents":["c5fdd95feb1daa789bb69e17b52aff8821e3be74"],"secs":75,"stamp":"467728ef5aaebb56014fa6076e352270","tree":"8cec7172b177aead0ee3374cc102d09e830003a5","v":1,"via":"run"}
Ci-Attestation: {"at":1793263864,"gate":"rust/x86_64-unknown-linux-gnu/test","host":"linux-x86_64","key":"db8feb23281ca0e220c448d68f1be14a5f1062a0216f9e0340321e38e7dfee04","lane":"rust-test","parents":["c5fdd95feb1daa789bb69e17b52aff8821e3be74"],"secs":169,"stamp":"80eb40a7c4812ab98f972778a57d6bdd","tree":"8cec7172b177aead0ee3374cc102d09e830003a5","v":1,"via":"run"}
Ci-Attestation: {"at":1793263864,"gate":"rust/x86_64-pc-windows-msvc/clippy","host":"linux-x86_64","key":"7cc8841f5fa7a06f3090aade0155e0457b9c4356c17fa44b5418f11c40df3119","lane":"cross","parents":["c5fdd95feb1daa789bb69e17b52aff8821e3be74"],"secs":96,"stamp":"dd713ca81ab3614076faf09ec3a0f5f3","tree":"8cec7172b177aead0ee3374cc102d09e830003a5","v":1,"via":"run"}
Ci-Attestation: {"at":1793263864,"gate":"rust/x86_64-pc-windows-msvc/dylint","host":"linux-x86_64","key":"7cc8841f5fa7a06f3090aade0155e0457b9c4356c17fa44b5418f11c40df3119","lane":"cross","parents":["c5fdd95feb1daa789bb69e17b52aff8821e3be74"],"secs":96,"stamp":"4c9c4ba7cf6c909e381e9266b8bd25d6","tree":"8cec7172b177aead0ee3374cc102d09e830003a5","v":1,"via":"run"}
Ci-Attestation: {"at":1793263864,"gate":"rust/aarch64-apple-darwin/clippy","host":"linux-x86_64","key":"7cc8841f5fa7a06f3090aade0155e0457b9c4356c17fa44b5418f11c40df3119","lane":"cross","parents":["c5fdd95feb1daa789bb69e17b52aff8821e3be74"],"secs":96,"stamp":"558779126ebd09147e4147bd5bea2b6a","tree":"8cec7172b177aead0ee3374cc102d09e830003a5","v":1,"via":"run"}
Ci-Attestation: {"at":1793263864,"gate":"rust/aarch64-apple-darwin/dylint","host":"linux-x86_64","key":"7cc8841f5fa7a06f3090aade0155e0457b9c4356c17fa44b5418f11c40df3119","lane":"cross","parents":["c5fdd95feb1daa789bb69e17b52aff8821e3be74"],"secs":96,"stamp":"228629c266e4919d49763da44bdfe222","tree":"8cec7172b177aead0ee3374cc102d09e830003a5","v":1,"via":"run"}
Ci-Attestation: {"at":1793263864,"gate":"cpp/linux-x64/tier2","host":"linux-x86_64","key":"53488f90bfeb235b9eecee55e15ed8e9bc3e38e2bc5df515126f9b13b5b82908","lane":"tier2-linux","parents":["c5fdd95feb1daa789bb69e17b52aff8821e3be74"],"secs":312,"stamp":"71a9f175dda786dd227f70632db58ab7","tree":"8cec7172b177aead0ee3374cc102d09e830003a5","v":1,"via":"run"}

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

3 participants