Repository navigation
obs-graphics: Port the effect technique and pass loop (#2421) - #2422
Merged
Merged
Conversation
…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]>
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
approved these changes
Oct 25, 2026
zackees
left a comment
Member
There was a problem hiding this comment.
Reviewed the core against effect.c.
effect_loopmatchesgs_effect_loop: the already-active and technique-missing warnings,end_passon later iterations,loop_pass++taken beforebegin_pass, andend,looping = falseandloop_pass = 0when the pass runs out.technique_endkeeps the C order: both shaders unloaded,cur_techniqueandcur_effectcleared, then every param emptied, unchanged, withnext_samplerdropped.upload_shader_paramskeeps the order:next_sampleris sent before thechanged_onlyskip, 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_effecton the C side. - Tier 2
test_effect_pass_loopand Tier 3 parity, with a device oracle, are in place. LGTM.
zackees
enabled auto-merge
October 25, 2026 21:43
zackees
added a commit
that referenced
this pull request
Oct 25, 2026
…-Wformat (fixes master after #2422)
rdoupe
pushed a commit
to rdoupe/obs-studio
that referenced
this pull request
Oct 26, 2026
…-Wformat (fixes master after obs-rust#2422) (obs-rust#2429)
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 #2421
Slice 2 of
graphics/effect.c, after #2409 (#2411): the technique and pass loop of an effect, with the parameter upload, moves tolibobs/graphics/effect-passes.c.hand is ported toobs_graphics::effect_passes. Every draw runs it (while (gs_effect_loop(effect, "Draw"))). After this,effect.c.hkeeps onlygs_effect_destroyandgs_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_passandgs_effect_update_params, with the static upload helpers, moved unchanged fromeffect.c.h; the file joinslibobs.ported-graphics, whose PCH gainsgraphics/graphics-internal.h(the C writesgraphics->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 aPassModeltrait (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):CModelimplementsPassModelon the C structs (theffi::effect_lookupsmirrors, plusstruct pass_shaderparamandstruct gs_shader_param_info) and the C graphics functions. The technique lookup is the Rustgs_effect_get_technique; values are emptied and filled in place witheffect_params::DarrayStore(asda_resizeandda_copy).graphics->cur_effectis written through the effect's graphics subsystem by a new hiddenobs_graphics_set_cur_effect()ingraphics.c, sostruct graphics_subsystemdoes not cross. The two warnings ofgs_effect_loopkeep the C's literal formats (one with the technique name) through a newobs_graphics_effect_loop_warning()adapter.Kept, characterized, not endorsed
gs_effect_loopbegins passloop_passand then increments it, also when there is no such pass (then the technique ends andloop_passis reset).gs_effect_update_paramssends it even for an unchanged parameter.cur_valbefore the upload.gs_technique_begin_pass_by_namereturns true on a name match.Intentional differences (C dereferences NULL; libobs never gets there)
strcmp); a NULL pass name matches none.RED → GREEN
71122edcf: behaviour-neutral.093f9e701:test_effect_pass_loop(6 cases) compiles the C with recording stubs for the device functions andgs_get_effect; no graphics context (Linux only,--gc-sections, astest_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 onlibobsandlibobs-c-reference.766077f1c: Tier 1shader::effect_passesmirrors 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!()).6d2882bb3: 9 of 9.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 ofstruct 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'scur_val(num, capacity, bytes),changed,next_samplerand the warnings.Tier 3 caught one bug during development that the render tests did not: the shim first read
gs_shader_get_param_infointo thestruct gs_effect_param_infomirror, 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 pinsstruct 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_namereturninggs_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_renderandtest_scene_rotated_scale_filterpass on the hybrid libobs and onlibobs-c-reference(7/7 each); in the hybrid,gs_effect_loopruns 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 foreffect_passes*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)
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
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.