Repository navigation
obs-graphics: Port the effect parameter values (#2409) - #2411
Merged
Merged
Conversation
zackees
approved these changes
Oct 25, 2026
zackees
left a comment
Member
There was a problem hiding this comment.
Reviewed. DarrayStore::resize and ensure_capacity reproduce darray_resize and darray_ensure_capacity (util/darray.h) exactly. Same-size returns early, size 0 only sets num, capacity grows as cap ? cap*2 : size and then max(size), it copies the old capacity bytes into a new bmalloc block and bfrees the old one, and growth is zero-filled. The memory stays bmalloc-owned, so C's da_free of cur_val keeps working. The three invalid-param and invalid-data blog paths stay in C through obs_graphics_effect_param_error. The Tier 2 test_effect_param_values and Tier 3 parity with the oracle are in place. LGTM.
zackees
enabled auto-merge
October 25, 2026 19:48
6 of 7 tasks
Member
test_effect_param_values pins the parameter values of libobs/graphics/effect.c before their Rust port (obs-rust#2409). The functions are EXPORT and none of them touches the graphics subsystem, so the test calls them through the real libobs on a hand-built struct gs_effect_param, with no graphics context, on every platform: - each setter's stored size and bytes: bool and int as an int, vec3 as 12 bytes (sizeof(float) * 3), vec2, vec4 and matrix4 as the whole struct, a texture as struct gs_shader_texture with srgb false or true, a color through vec4_from_bgra (0xAARRGGBB to {r, g, b, a} / 255), arbitrary bytes through gs_effect_set_val; - changed: set when the bytes differ or the size changes (also to 0), not when the same bytes are set again; - the getters: NULL for a size of 0, a bmem copy of the stored bytes; - gs_effect_set_default: the default bytes back; without a default it passes the NULL array on, logs "invalid data" and keeps the value; - gs_effect_set_next_sampler: only on a texture parameter; - NULL parameter or data: exactly one LOG_ERROR line with the C's text, nothing changed; the size getters return 0 without an error. Refs obs-rust#2409 Co-Authored-By: Claude Opus 5.5 <[email protected]>
The parameter values of an effect move from graphics/effect.c to graphics/effect-params.c, unchanged: effect_setval_inline and the two getter copies, the gs_effect_set_* setters, gs_effect_get_val, gs_effect_get_val_size, gs_effect_get_default_val, gs_effect_get_default_val_size, gs_effect_set_default and gs_effect_set_next_sampler. None of them touches the graphics subsystem; the technique and pass functions stay in effect.c. The file joins libobs.graphics (sorted before effect-parser) and keeps effect.c's min() with its #undef at the end. Behaviour-neutral: the same code, the same exported symbols. Refs obs-rust#2409 Co-Authored-By: Claude Opus 5.5 <[email protected]>
RED for the port of libobs/graphics/effect-params.c.h, the parameter values of an effect (obs-rust#2409), to a new module, effect_params, of rust/obs-graphics. The safe core is a stub (todo!()): ByteStore (the parameter's DARRAY(uint8_t)), set_val() (effect_setval_inline with a valid parameter and data), copy_out() (the getter copies), bgra_to_vec4() (vec4_from_bgra) and takes_next_sampler(). tests/shader/effect_params.rs ports the rules of test_effect_param_values that live in the core, under the same case names and with the same inputs and expectations: changed on new bytes and on a size change (also to 0), the getter copies, the color, the next sampler. Each setter's size and bytes, gs_effect_set_default without a default and the NULL log lines are the shim's; the cmocka test runs against the shim in the hybrid libobs. New edge cases (edge_*): a copy into a smaller buffer and the color extremes, one channel at a time. Proptests: set_val stores the data and sets changed exactly when the size or bytes differ, never clearing it; copy_out copies min(src, dst) and leaves the rest; every color channel is its byte / 255. cargo test -p obs-graphics --test obs-tests-graphics shader::effect_params fails 10 of 10 with "not yet implemented". Refs obs-rust#2409 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Ports libobs/graphics/effect-params.c.h, the parameter values of an effect (obs-rust#2409), to the effect_params module of rust/obs-graphics: the 17 exported functions gs_effect_set_bool, _float, _int, _matrix4, _vec2, _vec3, _vec4, _color, _texture, _texture_srgb, _val, _default and gs_effect_set_next_sampler, and gs_effect_get_val, _val_size, _default_val and _default_val_size. The hybrid libobs drops the C file and exports the Rust shims in its place. Safe core (src/effect_params.rs): set_val() (store the bytes, resize on a size change, set changed when the size or the bytes differ), copy_out() (at most the stored size), bgra_to_vec4() (vec4_from_bgra) and takes_next_sampler(). No state, no lock, no graphics calls; the module denies clippy's panic, indexing and arithmetic lints. As the C's effect_setval_inline is static inline, set_val() and the shim's setval() are #[inline(always)], so every length is a constant in each setter. Values up to 64 bytes (every typed setter) are compared by ORing the XOR of 8-byte chunks: for a constant length that unrolls into a few loads, as GCC expands the C's memcmp, where LLVM would call bcmp for a 64-byte slice comparison (gs_effect_set_matrix4 took twice the C's time on x86_64 with the slice comparison). Shim (src/ffi/effect_params.rs): struct gs_effect_param is the mirror in ffi::effect_lookups. The value stays the C DARRAY(uint8_t), kept in place by DarrayStore, which grows as darray_resize does (capacity doubling, new bytes zeroed, bmalloc + copy + bfree). The getters return bmem copies, as bzalloc. Allocation and logging go through the C adapters in obs-graphics-adapter.c.h, so the module names no obs-util symbol; the new obs_graphics_effect_param_error() logs the five error lines with the C's literal formats, so a log handler sees the same format string (test_effect_set_default_null matches on it). Kept, characterized, not endorsed: gs_effect_set_vec3 stores 12 bytes; gs_effect_set_bool stores an int; gs_effect_set_default without a default passes the NULL array on and logs "invalid data". Intentional difference: gs_effect_set_texture and _texture_srgb store struct gs_shader_texture with its padding zero. The C builds it on the stack and copies and compares the padding as it finds it, so the same texture set again can count as a change (and be uploaded again); here it never does. C side: effect-params.c.h leaves libobs.graphics for libobs.ported-graphics (its PCH has graphics/effect.h, vec4.h and util/base.h). The functions are EXPORT: the shims are listed in libobs/cmake/rust-exports.d/obs-graphics-effect_params.txt. Tier 1 shader::effect_params passes 10/10. Refs obs-rust#2409 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Oracle (oracle/effect_params.c): the original effect-params.c.h, unmodified, with its 17 exports renamed to oracle_*, plus the layout of struct gs_shader_texture. blog, bzalloc and the darray inlines are the C ones of the test binary; the shim logs and allocates through the adapters of obs-graphics-adapter.c.h, which oracle/image_file.c builds into the same binary. Tier 3 (tests/shader/effect_params_parity.rs): both sides get a parameter built the same way (type, cur_val and default_val with the same bytes and spare capacity, changed, next_sampler) and the same call through their C signatures, and are compared: cur_val's num, capacity and bytes, default_val, changed, next_sampler, the returned size or copy, and the LOG_ERROR lines (count and text, through the process log handler both sides log to): - the layout of struct gs_shader_texture; - every function on 6 chosen parameters, with a valid and a NULL parameter (sizes up and down, the same bytes, NULL data for each pointer setter, no default and an empty default), and the next sampler on every parameter type; - 20 000 random calls on random parameters. Excluded, the intentional difference: the padding of struct gs_shader_texture. For the two texture setters only tex and srgb are compared, the shim's padding must be zero, and the shim's changed must follow its bytes exactly; the C's must be set whenever the fields changed (it can also be set by its stack padding). port_comparison (benches/port_comparison/effect_params.rs): set_float, set_vec4, set_matrix4 and set_texture with the same value (nothing changes) and with a new value each call, changed cleared after each call; the fixtures free their value buffers. shader::effect_params and effect_params_parity pass 13/13 on macOS arm64. Refs obs-rust#2409 Co-Authored-By: Claude Opus 5.5 <[email protected]>
vpacher
added a commit
to vpacher/obs-studio
that referenced
this pull request
Oct 25, 2026
…MSVC (obs-rust#2420) audio_min_ts_parity::insufficient_matches draws the sample rate from all of usize. On MSVC x64 the C's util_mul_div64 is exact 128-bit math (_umul128 / _udiv128), which faults with STATUS_INTEGER_OVERFLOW when the quotient does not fit in 64 bits, so the C oracle crashed the whole obs-tests-core binary on windows-2025 (seen on obs-rust#2411, whose oracle change pulls obs-tests-core into the changed-crates run). The shim saturates there, so only the oracle faults. On MSVC x64 the rate now stays below 1e9, so t * rate / 1e9 fits for any t, as audio_mix_parity does since obs-rust#1909. Other hosts keep the full range (util_mul_div64 wraps there, and both sides wrap the same way). audio_discard_parity keeps its rates below 384 kHz and is not affected. Refs obs-rust#2405 Co-authored-by: Claude Opus 5.5 <[email protected]>
vpacher
force-pushed
the
port/effect-params
branch
from
October 25, 2026 20:37
e600cdc to
ccf9873
Compare
6 of 7 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #2409
Slice 1 of
graphics/effect.c: the parameter values of an effect move tolibobs/graphics/effect-params.c.hand are ported toobs_graphics::effect_params. These are the 17 exported functions every filter and scene item calls on every frame.What changed
libobs/graphics/effect-params.c.h:gs_effect_set_bool,_float,_int,_matrix4,_vec2,_vec3,_vec4,_color,_texture,_texture_srgb,_val,_default,gs_effect_set_next_sampler, andgs_effect_get_val,_val_size,_default_val,_default_val_size, moved unchanged fromeffect.c.h. The technique and pass functions stay ineffect.c.h(slice 2).rust/obs-graphics/src/effect_params.rs(safe core) andsrc/ffi/effect_params.rs(the 17#[no_mangle]shims, listed inlibobs/cmake/rust-exports.d/obs-graphics-effect_params.txt). The file moves intolibobs.ported-graphics.struct gs_effect_paramis the existing mirror inffi::effect_lookups(obs-graphics: Port effect name and index lookups #1843). The value stays the CDARRAY(uint8_t), kept in place byDarrayStore, which grows asdarray_resizedoes (capacity doubling, new bytes zeroed). The getters return bmem copies.obs-graphics-adapter.c.h, as inimage_file, so the module names no obs-util symbol. A new adapter,obs_graphics_effect_param_error(), logs the five error lines with the C's literal formats: a log handler sees the same format string as before (test_effect_set_default_nullmatches on it).set_val()and the shim'ssetval()are#[inline(always)], as the C'seffect_setval_inlineisstatic inline. Values up to 64 bytes are compared by ORing the XOR of 8-byte chunks, which unrolls for the constant length of each setter, as GCC expands the C'smemcmp. With a plain slice comparison, LLVM calledbcmpandgs_effect_set_matrix4took twice the C's time on x86_64.Kept, characterized, not endorsed
gs_effect_set_vec3stores 12 bytes (sizeof(float) * 3), notsizeof(struct vec3).gs_effect_set_boolstores anint.gs_effect_set_defaulton a parameter without a default passes the NULL array on, logs "invalid data" and keeps the value.Intentional difference
gs_effect_set_textureand_texture_srgbstorestruct gs_shader_texturewith its padding bytes zero. The C builds it on the stack and copies and compares its 7 padding bytes as it finds them (x86_64), so setting the same texture again can count as a change, and the parameter is uploaded again. Here it never counts as a change.RED → GREEN
ff2c24d29:test_effect_param_values(8 cases), on the exported functions with a hand-builtstruct gs_effect_param; no graphics context, so it runs on every platform. Passes onlibobsandlibobs-c-reference.8bd4b1715: behaviour-neutral.0bd225a86: Tier 1shader::effect_params, the core's rules from the cmocka cases 1:1 plus edge cases and proptests: 0 of 10 pass (todo!()).0c8e96243: 10 of 10.e600cdcf0: the C oracle (the file unmodified, exports renamed) against the shims: the layout ofstruct gs_shader_texture, every function on 6 chosen parameters with a valid and a NULL parameter, and 20 000 random calls. Compared:cur_val's num, capacity and bytes,default_val,changed,next_sampler, the returned size or copy, and theLOG_ERRORlines (count and text). For the texture setters onlytexandsrgbare compared (see above).Mutation check (done once, not committed): 17 of 19 mutants fail Tier 1 or Tier 3. The two survivors are equivalent: new bytes not zeroed on growth (the only resize is followed by a full copy) and the 64-byte threshold of the chunked compare (exact at any length).
Tier 2 (Linux x86_64, Debian 13, Xvfb)
test_effect_param_values,test_effect_set_default_null,test_color_correction_16f,test_scroll_filter_wide_source,test_sprite_flip_renderandtest_scene_rotated_scale_filterpass on the hybrid libobs and onlibobs-c-reference(6/6 each). In the hybrid,gs_effect_set_floatis the Rust shim (checked in the disassembly) and the C helpers are gone; exported symbols: 1766 on both.shader::effect*32/32 on Linux x86_64;shader::effect_params*13/13 on macOS arm64.Lint lane (
ci/local_gate.py --lane lint) on the same host: clang-format, rustfmt, clippy-D warningsfor the workspace and every feature set, the Dylints and the ratchets pass; its self-test step skipstest_hybrid_packagingthere (nozstdon that host, the same on master).port_comparison (Linux x86_64, one pinned core, criterion median, Rust / C)
_samesets the stored value again (the common case per frame),_newa different one. The texture setters are faster mostly because the C compares its padding;set_floatandset_vec4are 0.3 to 1.1 ns slower than the C,set_matrix4is faster with the same value and 0.7 ns slower with a new one.Checklist
master-W..., ratchets): noneAI note: Claude Code (Claude Opus 5.5) wrote the code, the tests, the commit messages and this text under the submitter's direction, and ran the tests above on the submitter's machines.