Skip to content

obs-graphics: Port the effect technique and pass loop (#2421) - #2422

Merged
zackees merged 7 commits into
obs-rust:masterfrom
vpacher:port/effect-passes
Oct 25, 2026
Merged

zackees merged 7 commits into
obs-rust:masterfrom
vpacher:port/effect-passes

Conversation

@vpacher

@vpacher vpacher commented Oct 25, 2026

Copy link
Copy Markdown
Member

Fixes #2421

Slice 2 of graphics/effect.c, after #2409 (#2411): the technique and pass loop of an effect, with the parameter upload, moves to libobs/graphics/effect-passes.c.h and is ported to obs_graphics::effect_passes. Every draw runs it (while (gs_effect_loop(effect, "Draw"))). After this, effect.c.h keeps only gs_effect_destroy and gs_effect_actually_destroy.

What changed

  • libobs/graphics/effect-passes.c.h: gs_effect_loop, gs_technique_begin, _end, _begin_pass, _begin_pass_by_name, _end_pass and gs_effect_update_params, with the static upload helpers, moved unchanged from effect.c.h; the file joins libobs.ported-graphics, whose PCH gains graphics/graphics-internal.h (the C writes graphics->cur_effect).
  • rust/obs-graphics/src/effect_passes.rs (safe core): the order of the device calls and state changes is the behaviour, so the whole loop is in the core, written once against a PassModel trait (the effect's loop state, the lookups, a parameter's state, the device).
  • rust/obs-graphics/src/ffi/effect_passes.rs (the 7 #[no_mangle] shims, libobs/cmake/rust-exports.d/obs-graphics-effect_passes.txt): CModel implements PassModel on the C structs (the ffi::effect_lookups mirrors, plus struct pass_shaderparam and struct gs_shader_param_info) and the C graphics functions. The technique lookup is the Rust gs_effect_get_technique; values are emptied and filled in place with effect_params::DarrayStore (as da_resize and da_copy).
  • graphics->cur_effect is written through the effect's graphics subsystem by a new hidden obs_graphics_set_cur_effect() in graphics.c, so struct graphics_subsystem does not cross. The two warnings of gs_effect_loop keep the C's literal formats (one with the technique name) through a new obs_graphics_effect_loop_warning() adapter.

Kept, characterized, not endorsed

  • gs_effect_loop begins pass loop_pass and then increments it, also when there is no such pass (then the technique ends and loop_pass is reset).
  • A next sampler is sent before the changed check, so gs_effect_update_params sends it even for an unchanged parameter.
  • A parameter without a value gets its default copied into cur_val before the upload.
  • gs_technique_begin_pass_by_name returns true on a name match.

Intentional differences (C dereferences NULL; libobs never gets there)

  • A NULL technique name finds no technique (the C passes it to strcmp); a NULL pass name matches none.

RED → GREEN

  1. Extraction 71122edcf: behaviour-neutral.
  2. Characterization 093f9e701: test_effect_pass_loop (6 cases) compiles the C with recording stubs for the device functions and gs_get_effect; no graphics context (Linux only, --gc-sections, as test_audio_buffering_subsample). It pins the call sequence and the state of one- and two-pass loops, a missing technique and an active effect, the value / default / nothing upload, changed_only, next samplers, the texture clear at the end of a pass and the reset at the end of the technique. Passes on libobs and libobs-c-reference.
  3. RED 766077f1c: Tier 1 shader::effect_passes mirrors the 6 cases 1:1 (same fixture, same expected call sequences) on a plain model with a recording device, plus edge cases and a proptest: 0 of 9 pass (todo!()).
  4. GREEN 6d2882bb3: 9 of 9.
  5. Tier 3 c3be80d2c: the C oracle (the file unmodified, exports renamed) and the shim call the same recording graphics stand-in (oracle/effect_passes_device.c), so they are compared call by call: the layout of struct gs_shader_param_info, the cmocka scenarios and 5000 random sequences of up to 24 calls on random effects; after every call the device calls, the return value, the loop state, graphics->cur_effect, every parameter's cur_val (num, capacity, bytes), changed, next_sampler and the warnings.

Tier 3 caught one bug during development that the render tests did not: the shim first read gs_shader_get_param_info into the struct gs_effect_param_info mirror, whose fields are in the other order, so texture parameters were not set to NULL at the end of a pass (a texture left bound does not change the rendered pixels). The layout test now pins struct gs_shader_param_info.

Mutation check (done once, not committed): 16 of 17 mutants fail Tier 1 or Tier 3. The survivor is equivalent: gs_technique_begin_pass_by_name returning gs_technique_begin_pass's result (it is always true for an index below the pass count).

Tier 2 (Linux x86_64, Debian 13, Xvfb)

test_effect_pass_loop, test_effect_param_values, test_effect_set_default_null, test_color_correction_16f, test_scroll_filter_wide_source, test_sprite_flip_render and test_scene_rotated_scale_filter pass on the hybrid libobs and on libobs-c-reference (7/7 each); in the hybrid, gs_effect_loop runs the Rust code (checked in the disassembly). Exported symbols: 1766 on both. shader::effect* 45/45 on Linux x86_64, three runs in a row; 13/13 for effect_passes* on macOS arm64.

Lint lane (ci/local_gate.py --lane lint) on the same host: clang-format, rustfmt, clippy -D warnings for the workspace and every feature set, the Dylints and the ratchets pass; its self-test step skips test_hybrid_packaging there (no zstd on that host, the same on master).

port_comparison (Linux x86_64, one pinned core, criterion median, Rust / C)

effect_passes/draw_one_pass      71.1 ns /  64.6 ns
effect_passes/draw_two_passes   107.0 ns /  93.7 ns

One draw with 4 float parameters, the graphics stand-in doing nothing. effect_passes/draw_one_pass 71.1 ns / 64.6 ns
effect_passes/draw_two_passes 107.0 ns / 93.7 nsNOTE

Checklist

  • Base is master
  • 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
  • User-visible change: none
  • (Optional) Local gate passed and the pushed head is stamped; otherwise PR CI runs the full suite
  • Warning or flag changes (-W..., ratchets): none
  • Intentional differences from C listed in the parity test header and rust/README.md (ports)

AI 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.

vpacher and others added 5 commits October 25, 2026 22:21
…passes.c

The technique and pass loop of an effect moves from graphics/effect.c to
graphics/effect-passes.c, unchanged: gs_effect_loop, gs_technique_begin,
gs_technique_end, gs_technique_begin_pass, gs_technique_begin_pass_by_name,
gs_technique_end_pass and gs_effect_update_params, with the static upload
helpers (upload_shader_params, upload_parameters, reset_params,
clear_tex_params). effect.c keeps gs_effect_destroy and
gs_effect_actually_destroy. The file joins libobs.graphics, sorted after
effect-parser. Behaviour-neutral: the same code, the same exported
symbols.

Refs obs-rust#2421

Co-Authored-By: Claude Opus 5.5 <[email protected]>
test_effect_pass_loop compiles graphics/effect-passes.c into itself with
recording stubs for the device functions it calls (gs_load_vertexshader,
gs_load_pixelshader, gs_shader_set_val, gs_shader_set_next_sampler,
gs_shader_get_param_info, gs_shader_set_texture) and for gs_get_effect,
which reads the cur_effect the loop writes through the effect's graphics
subsystem. No graphics context; Linux only (--gc-sections), as
test_audio_buffering_subsample. The effects are built by hand;
gs_effect_get_technique is the real lookup in libobs.

It pins the call sequence and the effect state of one- and two-pass
loops (shaders, then the full upload; at the end of a pass textures set
to NULL; at the end of the technique NULL shaders, cur_technique and
cur_effect cleared, every value emptied, next samplers dropped), a
missing technique and an active effect (no change, no call), the upload
of the value, of the default copied in when there is no value, of
nothing when there is neither, changed cleared after an upload,
gs_effect_update_params sending only changed values but every next
sampler (set before the changed check), and the bounds and NULL cases
of the technique and pass functions.

Refs obs-rust#2421

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

RED for the port of libobs/graphics/effect-passes.c.h, the technique and
pass loop of an effect with the parameter upload, to a new module,
effect_passes, of rust/obs-graphics. The order of the device calls and
state changes is the behaviour, so the whole loop is in the core,
written once against PassModel: the effect's loop state, the lookups, a
parameter's state and the device (gs_get_effect, the shader loads, the
next sampler, the value upload, the texture check and clear, the two
loop warnings). The functions are stubs (todo!()): effect_loop,
technique_begin, technique_end, technique_begin_pass,
technique_begin_pass_by_name, technique_end_pass and
effect_update_params.

tests/shader/effect_passes.rs mirrors test_effect_pass_loop 1:1, under
the same names, with the same fixture (technique "Draw", shaders 10+i
and 20+i, shader params 1, 2, 3 and the texture 100) and the same
expected call sequences and state, on a plain model with a recording
device.

New edge cases (edge_*): a technique with no passes (loop_pass is
incremented and reset, the technique begins and ends), and the texture
clear following the device's parameter type. Proptest: any call
sequence, misuse included, does not panic, and a failed gs_effect_loop
that logged no warning has reset the loop.

cargo test -p obs-graphics --test obs-tests-graphics
shader::effect_passes fails 9 of 9 with "not yet implemented".

Refs obs-rust#2421

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Ports libobs/graphics/effect-passes.c.h, the technique and pass loop of
an effect with the parameter upload, to the effect_passes module of
rust/obs-graphics: the 7 exported functions gs_effect_loop,
gs_technique_begin, gs_technique_end, gs_technique_begin_pass,
gs_technique_begin_pass_by_name, gs_technique_end_pass and
gs_effect_update_params. The hybrid libobs drops the C file and exports
the Rust shims in its place.

Safe core (src/effect_passes.rs): the order of the device calls and
state changes is the behaviour, so the whole loop is in the core,
written once against PassModel (the effect's loop state, lookups,
parameter state and the device). No state of its own, no lock; the
module denies clippy's panic, indexing and arithmetic lints.

Shim (src/ffi/effect_passes.rs): CModel implements PassModel on the C
structs (the mirrors of ffi::effect_lookups, plus struct
pass_shaderparam) and the C graphics functions (gs_get_effect,
gs_load_vertexshader, gs_load_pixelshader, gs_shader_set_val,
gs_shader_set_next_sampler, gs_shader_get_param_info,
gs_shader_set_texture). The technique lookup is the Rust
gs_effect_get_technique; values are emptied and filled in place with
effect_params::DarrayStore (as da_resize and da_copy).
graphics->cur_effect is written through the effect's graphics subsystem
by the new hidden obs_graphics_set_cur_effect() in graphics.c, so struct
graphics_subsystem does not cross. The two warnings of gs_effect_loop
go to blog with the C's literal formats through the new
obs_graphics_effect_loop_warning() adapter.

Kept, characterized, not endorsed: loop_pass is incremented also when
there is no such pass; a next sampler is sent before the changed check,
so gs_effect_update_params sends it for an unchanged parameter; a
parameter without a value gets its default copied in before the upload;
gs_technique_begin_pass_by_name returns true on a name match.

Intentional differences, where the C dereferences NULL and libobs never
gets there: a NULL technique name finds no technique (the C passes it
to strcmp) and a NULL pass name matches none.

C side: effect-passes.c.h leaves libobs.graphics for
libobs.ported-graphics, whose PCH gains graphics/graphics-internal.h
(the C writes graphics->cur_effect). The functions are EXPORT: the shims
are listed in libobs/cmake/rust-exports.d/obs-graphics-effect_passes.txt.

Tier 1 shader::effect_passes passes 9/9.

Refs obs-rust#2421

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

Oracle (oracle/effect_passes.c): the original effect-passes.c.h,
unmodified, with its 7 exports renamed to oracle_*. Graphics stand-in
(oracle/effect_passes_device.c): recording stubs of the graphics
functions the loop calls (gs_load_vertexshader, gs_load_pixelshader,
gs_shader_set_val, gs_shader_set_next_sampler, gs_shader_get_param_info,
gs_shader_set_texture, gs_get_effect) and of the hidden
obs_graphics_set_cur_effect, which the C oracle and the Rust shim both
call, so the two are compared call by call; plus the layout of struct
gs_shader_param_info.

Tier 3 (tests/shader/effect_passes_parity.rs): each side gets its own
copy of the same hand-built effect and runs the same calls; after every
call the test compares the device calls, the return value, the loop
state (looping, loop_pass, the current technique and pass),
graphics->cur_effect, every parameter's cur_val (num, capacity, bytes),
changed and next_sampler, and the LOG_WARNING lines:
- the layout of struct gs_shader_param_info (the type first, unlike
  struct gs_effect_param_info);
- the scenarios of test_effect_pass_loop;
- 5000 random sequences of up to 24 calls on random effects (0 to 3
  passes, 1 to 2 techniques, values, defaults, changed flags and next
  samplers at random, another effect active or not).
Excluded, the intentional differences, tested on the shim alone: NULL
technique and pass names.

port_comparison (benches/port_comparison/effect_passes.rs): one draw
(while (gs_effect_loop(effect, "Draw"))) over one and two passes with 4
float parameters, the stand-in recording nothing.

shader::effect_passes and effect_passes_parity pass 13/13 on macOS
arm64.

Refs obs-rust#2421

Co-Authored-By: Claude Opus 5.5 <[email protected]>
vpacher and others added 2 commits October 25, 2026 22:31
obs_graphics_set_cur_effect() moves from graphics.c to the private
obs-graphics adapters (obs-graphics-adapter.c.h). The executables that
link the Rust staticlib next to libobs (test_effect_parser_lifecycle_rust,
test_sprite_geometry_steps_rust) compile their own copy of the adapters
but not graphics.c, so the effect_passes shim's reference to the setter
was undefined there and the Tier 2 Linux build failed to link. libobs.pch.h
already brings graphics-internal.h, so the adapter can write the field.
The oracle's graphics stand-in drops its own definition: oracle/image_file.c
builds the adapters into the test binary.

Refs obs-rust#2421

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The previous commit removed the obs_graphics_set_cur_effect declaration
but left an empty last line, which clang-format rejects (Fast Gate).

Refs obs-rust#2421

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

@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 core against effect.c.

  • effect_loop matches gs_effect_loop: the already-active and technique-missing warnings, end_pass on later iterations, loop_pass++ taken before begin_pass, and end, looping = false and loop_pass = 0 when the pass runs out.
  • technique_end keeps the C order: both shaders unloaded, cur_technique and cur_effect cleared, then every param emptied, unchanged, with next_sampler dropped.
  • upload_shader_params keeps the order: next_sampler is sent before the changed_only skip, then the default copied into an empty value or skipped, then the value sent. Changed flags are reset for both stages after both uploads.
  • The model trait keeps device calls and graphics->cur_effect on the C side.
  • Tier 2 test_effect_pass_loop and Tier 3 parity, with a device oracle, are in place. LGTM.

@zackees
zackees enabled auto-merge October 25, 2026 21:43
@zackees
zackees added this pull request to the merge queue Oct 25, 2026
Merged via the queue into obs-rust:master with commit 49e5e5a Oct 25, 2026
38 checks passed
zackees added a commit that referenced this pull request Oct 25, 2026
@obs-rust-project-manager obs-rust-project-manager Bot moved this from In review to Done in obs-rust Multiview Oct 26, 2026
rdoupe pushed a commit to rdoupe/obs-studio that referenced this pull request Oct 26, 2026
@vpacher
vpacher deleted the port/effect-passes branch October 26, 2026 06:11
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 the effect technique and pass loop in graphics/effect.c to obs-graphics (effect.c slice 2)

2 participants