Skip to content

libobs: Move the effect parser functions to file - #3627

Merged
rdoupe merged 2 commits into
masterfrom
fix/rust-port-extract-the-effect-par-600
Nov 4, 2026
Merged

rdoupe merged 2 commits into
masterfrom
fix/rust-port-extract-the-effect-par-600

Conversation

@rdoupe

@rdoupe rdoupe commented Nov 4, 2026

Copy link
Copy Markdown
Collaborator

Refs #3623

What and why

First step of porting the effect parser's function parser to obs-graphics: a characterization test and a behaviour-neutral extraction, C only. The Rust port of the moved file follows in its own PR on the same issue. Same shape as the effect parser's parameters (#3615).

  • test: Characterize the effect parser functions: a new test_effect_parser_funcs (cmocka) calls ep_init(), ep_parse() and ep_free() on 73 fixed effect texts and pins, written out and compared whole, the functions kept (return type, name, mapping, each param var's keyword, type, name and mapping, the contents, and the struct, func, sampler and param dependency lists in the order they were pushed), the structs, samplers and params by name, every error and warning with its row, column and level, and the allocations still held after ep_free(). It covers well-formed and malformed signatures (each param keyword, a repeated or second keyword, () and empty params, a stray or trailing ,, a missing type, name or mapping, a mapping after ), a missing {), bodies (nested braces, newlines and tabs, comments, a } in a string, text after the body), dependencies (on a declared struct, sampler, param and earlier function, a struct return type, a function calling itself, a name declared later, and the order the four lookups are tried in), the declaration keywords (repeated, and used on a function), and text cut short at each step of a signature. ep_parse() and ep_free() are hidden in libobs, so the test compiles the original effect parser C into itself and links libobs for the rest; each text is parsed behind a first line of {}, whose error keeps ep_parse() from calling ep_compile() (which needs a device). No display and no graphics context, so it runs on every platform.
  • libobs: Move the effect parser functions to file: ep_getstruct(), ep_getsampler(), the four _strref lookups, ep_check_for_keyword(), ep_parse_func_param(), ep_parse_func_params(), the four ep_process_*_dep() helpers, ep_parse_func_contents() and ep_parse_function() move, as written, from libobs/graphics/effect-parser.c.h into the new libobs/graphics/effect-parser-funcs.c.h. ep_get_var_specifiers(), ep_parse_other() and the effect writer, which stay, call ep_check_for_keyword(), ep_parse_function(), ep_getstruct(), ep_getsampler(), ep_getfunc_strref() and ep_getparam_strref(), so those six lose their static (and inline) and are declared in a new internal graphics/effect-parser-funcs.h (a private adapter, not a new public API; effect-parser.h stays as it is); the other helpers stay static. ep_getfunc(), ep_getparam() and ep_getannotation() stay with the writer that calls them. The six names appear nowhere else in the tree. The file has its own live unity group, libobs.effect-parser-funcs (graphics module), with a precompiled header of its declarations and string.h, so the port can later move its include into a ported group. docs/rust-port/naming.md lists it under obs-graphics. The tests that compile effect-parser.c.h into themselves (test_effect_parser_blocks, _params, _passes, _funcs and the _rust variants of blocks and passes) compile the moved file beside it.

Odd but real results are marked "characterized, not endorsed" in the test. Among them: an error on the closing ) of a parameter list (a second keyword such as in out, a trailing ,, a token after a param's name) skips past that ) to the next one, so the function and the rest of the text are dropped; a missing mapping name on the { skips past it the same way; without its {, the function is dropped and its body is read as a declaration. The four body lookups are tried struct, function, sampler, param, and a name is pushed once for each time it appears. No leak showed, so the port has no intentional difference so far.

Moved code: Lain Bailey's (upstream obs-studio), credited on the move commit. No upstream issue.

Move harness (scratch, not committed): the whole effect parser C, built once from master's files and once from the moved ones, each with a driver that writes out every struct, sampler, param (with default bytes and annotations), function (signature, contents and all four dependency lists), technique (with each pass's program tokens), error and the live allocations after ep_free(), run on the same 189,023 effect texts (the ones the harness's filter kept out of 200,000 generated: seed effects heavy in functions, with 1/64 to 29/64 of their tokens dropped, replaced or joined by others, a quarter cut short, and token soups): identical logs (1,709,975 lines, 77,179 functions kept, 797,687 errors) in 8 builds of each side (GCC and Clang, -O0 and -O2, with and without ASan and UBSan without recovery). Of eighteen planted mutants of the moved code, seventeen change the logs; the eighteenth (a sampler looked up before a function of the same name, which the generated texts almost never declare) fails the characterization test.

RED → GREEN

  • RED commit: N/A. The extraction has no RED: the characterization test passes on master's code and after the move, unchanged, and no bug turned up to fix in this unit.
  • GREEN: test_effect_parser_funcs passes 6/6 on the C build, the hybrid libobs and libobs-c-reference, none skipped. It and the effect and shader tests (test_effect_int_bool_defaults, test_effect_lookups, test_effect_number_defaults, test_effect_param_numbers_steps, test_effect_param_types_steps, test_effect_param_values, test_effect_parser_blocks, test_effect_parser_lifecycle, test_effect_parser_params, test_effect_parser_passes, test_effect_pass_loop, test_effect_set_default_null, test_shader_number_defaults, test_shader_param_names, test_shader_param_values_steps, test_shader_parser_blocks, test_shader_sampler_convert) pass 18/18 on the C build and 22/22 (with the four _rust variants) on the hybrid libobs and on libobs-c-reference, none skipped. The C, hybrid and C reference builds export the same 1767 symbols as master; ep_getstruct, ep_getsampler, ep_getfunc_strref, ep_getparam_strref, ep_check_for_keyword and ep_parse_function are local (t) in each. The workspace tests, formatting, clippy and the Windows clippy on all targets pass, and ./unittest passed (6534 and 912 Rust tests; Tier 2 722/722 against libobs-c-reference and 722/722 against the hybrid libobs, with the PulseAudio and v4l2 vivid device tests skipped, 3 on each, as the container has no such devices). The local gate could not stamp this head here (its Dylint step has no driver for the pinned nightly on this machine), so PR CI runs the full suite. Runs were on 6a31c1c; the move harness ran on the same two commits before their rebase onto the source audio settings port, which changed none of the C it compiles.
  • Real app (UI, protocol output or logging changes): N/A, no UI, protocol or logging change.

Checklist

  • Base is master (or the description starts with a Stacked: note)
  • 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 (N/A for docs-only; a focused CI fix may push RED and GREEN together) (characterization, then the behaviour-neutral move; no RED, as nothing changes)
  • User-visible change: its line in docs/features.md is added or updated (not applicable: no user-visible change)
  • (Optional) Local gate passed and the pushed head is stamped; otherwise PR CI runs the full suite
  • Warning or flag changes (-W..., ratchets): built with scripting ON (PR CI builds no OBS app: run gh workflow run ci.yml --ref <branch> for the full builds) and cross-checked with clang and MSVC (not applicable: no warning or flag change)
  • Intentional differences from C listed in the parity test header and rust/README.md (ports) (not applicable: no Rust in this PR)

The effect parser's function parser and the lookups it uses have no C
test of their own: the effect tests load whole effects through a
device. test_effect_parser_funcs calls ep_init(), ep_parse() and
ep_free() on fixed effect texts and pins, written out and compared
whole, the functions kept (return type, name, mapping, each param
var's keyword, type, name and mapping, the contents, and the struct,
func, sampler and param dependency lists in the order they were
pushed), the structs, samplers and params by name, every error and
warning with its row, column and level, and the allocations still held
after ep_free().

73 texts: well-formed and malformed signatures (each param keyword, a
repeated or second keyword, () and empty params, a stray or trailing
',', a missing type, name or mapping, a mapping after ')', a missing
'{'), bodies (nested braces, newlines and tabs, comments, a '}' in a
string, text after the body), dependencies (on a declared struct,
sampler, param and earlier function, a struct return type, a function
calling itself, a name declared later, and the order the four lookups
are tried in), the declaration keywords (repeated, and used on a
function), and text cut short at each step of a signature. Odd but
real results are marked "characterized, not endorsed": among them, an
error on the closing ')' skips past it, so the function and the rest
of the text are dropped, and without its '{' a function's body is read
as a declaration.

ep_parse() and ep_free() are hidden in libobs, so the test compiles the
original effect parser C into itself and links libobs for the rest, as
test_effect_parser_params does. Every text is parsed behind a first
line of "{}", whose error keeps ep_parse() from calling ep_compile(),
which needs a device. No display and no graphics context: it runs on
every platform. It passes, none skipped, against the C, hybrid and C
reference libobs.

Refs #3623.
Behaviour-neutral extraction before the Rust port. The effect parser's
function parser and the lookups it uses move, as written, from
effect-parser.c into the new libobs/graphics/effect-parser-funcs.c.h:

- ep_getstruct() and ep_getsampler();
- ep_getfunc_strref(), ep_getstruct_strref(), ep_getsampler_strref()
  and ep_getparam_strref();
- ep_check_for_keyword();
- ep_parse_func_param() and ep_parse_func_params();
- ep_process_struct_dep(), _func_dep(), _sampler_dep() and
  _param_dep();
- ep_parse_func_contents() and ep_parse_function().

ep_get_var_specifiers() calls ep_check_for_keyword(), ep_parse_other()
calls ep_parse_function(), and the effect writer calls ep_getstruct(),
ep_getsampler(), ep_getfunc_strref() and ep_getparam_strref(), all
still in effect-parser.c, so those six lose their static (and inline)
and are declared in a new internal graphics/effect-parser-funcs.h, a
private adapter and not a new public API. The other helpers stay
static in the new file. ep_getfunc(), ep_getparam() and
ep_getannotation() stay with the writer that calls them. Nothing else
changes: the callers call them on the same tokens, in the same places.

The new file has its own live group, libobs.effect-parser-funcs (in
the graphics module), with a precompiled header of its declarations
and string.h, so the C oracle can compile it alone and the port can
move its include into a ported group. No Rust: the hybrid libobs
compiles the C too. The C, hybrid and C reference builds export the
same 1767 symbols as master, the six functions local (t) in each. The
tests that compile the effect parser C into themselves compile the new
file beside it.

Refs #3623.

Co-authored-by: Lain <[email protected]>
@rdoupe
rdoupe requested a review from zackees as a code owner November 4, 2026 13:39
@obs-rust-project-manager obs-rust-project-manager Bot moved this to Ready to merge in obs-rust Multiview Nov 4, 2026
@rdoupe
rdoupe added this pull request to the merge queue Nov 4, 2026
Merged via the queue into master with commit c654feb Nov 4, 2026
43 checks passed
@rdoupe
rdoupe deleted the fix/rust-port-extract-the-effect-par-600 branch November 4, 2026 17:09
@obs-rust-project-manager obs-rust-project-manager Bot moved this from Ready to merge to Done in obs-rust Multiview Nov 4, 2026
zackees added a commit that referenced this pull request Nov 4, 2026
Fix the Tier 2 merge-queue link failure for #3626 after #3627 extracted six private parser helpers. Compile their source into the standalone parser test, as sibling targets do; preserve symbol visibility and every existing C assertion.
chriscoveries pushed a commit to chriscoveries/obsrust-fork that referenced this pull request Nov 4, 2026
* test: Check a pass that calls an unknown function

A pass whose shader call names a function the effect doesn't define
makes ep_makeshaderstring() return before it frees the call string and
resets the written flags. The pass's pixel shader then leaves out the
params the failed call named, and the call string leaks.

The new test compiles the effect parser C into itself with the two
shader-create calls renamed to recorders, so ep_compile() runs with no
graphics device. It checks the pixel shader against a pass whose vertex
call is NULL, and that nothing is left allocated after ep_free() and
effect_free(). Both checks fail on master.

Refs obs-rust#3625.

* libobs: Free and reset after unknown shader calls

When a pass's shader call names a function the effect doesn't define,
ep_makeshaderstring() now frees the call string and resets the written
flags before it returns, as it does after a call that succeeds. Only the
shader with the bad call fails: the pass's other shader declares the
params that call named again, and the call string no longer leaks.

Fixes obs-rust#3625.

Local-Gate: v1 tree=6ad2c637b4895e52e61ea1c2285eb74feadf04d1 secs=2198 lanes=lint:run,rust-test:run,cross:run,tier2-linux:run,macos-native:n/a,windows-native:n/a
Ci-Attestation: {"at":1793810969,"gate":"rust/all/fmt","host":"linux-x86_64","key":"c8e5b8c8ecb627702f6b239e667ab66355cf22d730a76cf2ff71a279148344e8","lane":"lint","parents":["817e4d9afbf5067cad0552c107e654c5f04a4fa0"],"secs":69,"stamp":"330594638529efaafc9f1c81947b69bb","tree":"6ad2c637b4895e52e61ea1c2285eb74feadf04d1","v":1,"via":"run"}
Ci-Attestation: {"at":1793810969,"gate":"rust/x86_64-unknown-linux-gnu/clippy","host":"linux-x86_64","key":"c8e5b8c8ecb627702f6b239e667ab66355cf22d730a76cf2ff71a279148344e8","lane":"lint","parents":["817e4d9afbf5067cad0552c107e654c5f04a4fa0"],"secs":69,"stamp":"fc150300d15eab2c09a7a0e0e297db05","tree":"6ad2c637b4895e52e61ea1c2285eb74feadf04d1","v":1,"via":"run"}
Ci-Attestation: {"at":1793810969,"gate":"rust/x86_64-unknown-linux-gnu/test","host":"linux-x86_64","key":"ad3ccb3438a02ac0968638fa6bfcd194addd0e6352d97235f1762c42a04e1eb7","lane":"rust-test","parents":["817e4d9afbf5067cad0552c107e654c5f04a4fa0"],"secs":142,"stamp":"6dd7ee2fa63da31fd7442f7648a647d5","tree":"6ad2c637b4895e52e61ea1c2285eb74feadf04d1","v":1,"via":"run"}
Ci-Attestation: {"at":1793810969,"gate":"rust/x86_64-pc-windows-msvc/clippy","host":"linux-x86_64","key":"89034ad58ee31e6f4f7f96472ce0887950ee541c232aa87b42e0438dd874b4b6","lane":"cross","parents":["817e4d9afbf5067cad0552c107e654c5f04a4fa0"],"secs":84,"stamp":"79ed599d0bf6dd30a4cf9fe931077638","tree":"6ad2c637b4895e52e61ea1c2285eb74feadf04d1","v":1,"via":"run"}
Ci-Attestation: {"at":1793810969,"gate":"rust/x86_64-pc-windows-msvc/dylint","host":"linux-x86_64","key":"89034ad58ee31e6f4f7f96472ce0887950ee541c232aa87b42e0438dd874b4b6","lane":"cross","parents":["817e4d9afbf5067cad0552c107e654c5f04a4fa0"],"secs":84,"stamp":"437df2674667fc47a9ff02d4de5df647","tree":"6ad2c637b4895e52e61ea1c2285eb74feadf04d1","v":1,"via":"run"}
Ci-Attestation: {"at":1793810969,"gate":"rust/aarch64-apple-darwin/clippy","host":"linux-x86_64","key":"89034ad58ee31e6f4f7f96472ce0887950ee541c232aa87b42e0438dd874b4b6","lane":"cross","parents":["817e4d9afbf5067cad0552c107e654c5f04a4fa0"],"secs":84,"stamp":"790b5f7a391670abd05ef0dc52e65b57","tree":"6ad2c637b4895e52e61ea1c2285eb74feadf04d1","v":1,"via":"run"}
Ci-Attestation: {"at":1793810969,"gate":"rust/aarch64-apple-darwin/dylint","host":"linux-x86_64","key":"89034ad58ee31e6f4f7f96472ce0887950ee541c232aa87b42e0438dd874b4b6","lane":"cross","parents":["817e4d9afbf5067cad0552c107e654c5f04a4fa0"],"secs":84,"stamp":"8e47c826caa16acf6326bffa25dbc489","tree":"6ad2c637b4895e52e61ea1c2285eb74feadf04d1","v":1,"via":"run"}
Ci-Attestation: {"at":1793810969,"gate":"cpp/linux-x64/tier2","host":"linux-x86_64","key":"b9f7eb92939f575cf174379ee1017a99ce1b9f7454e4513da247fd7dd0648bb5","lane":"tier2-linux","parents":["817e4d9afbf5067cad0552c107e654c5f04a4fa0"],"secs":2198,"stamp":"ee204655a5f902de5bbba781e67aa299","tree":"6ad2c637b4895e52e61ea1c2285eb74feadf04d1","v":1,"via":"run"}

* test: Link extracted effect parser functions into shader-call test

Fix the Tier 2 merge-queue link failure for obs-rust#3626 after obs-rust#3627 extracted six private parser helpers. Compile their source into the standalone parser test, as sibling targets do; preserve symbol visibility and every existing C assertion.

---------

Co-authored-by: Zach Vorhies <[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

Development

Successfully merging this pull request may close these issues.

1 participant