Repository navigation
libobs: Move the effect parser functions to file - #3627
Merged
Merged
Conversation
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]>
4 of 7 tasks
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]>
This was referenced Nov 6, 2026
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.
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 newtest_effect_parser_funcs(cmocka) callsep_init(),ep_parse()andep_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 afterep_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()andep_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 keepsep_parse()from callingep_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_strreflookups,ep_check_for_keyword(),ep_parse_func_param(),ep_parse_func_params(), the fourep_process_*_dep()helpers,ep_parse_func_contents()andep_parse_function()move, as written, fromlibobs/graphics/effect-parser.c.hinto the newlibobs/graphics/effect-parser-funcs.c.h.ep_get_var_specifiers(),ep_parse_other()and the effect writer, which stay, callep_check_for_keyword(),ep_parse_function(),ep_getstruct(),ep_getsampler(),ep_getfunc_strref()andep_getparam_strref(), so those six lose theirstatic(andinline) and are declared in a new internalgraphics/effect-parser-funcs.h(a private adapter, not a new public API;effect-parser.hstays as it is); the other helpers staystatic.ep_getfunc(),ep_getparam()andep_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 andstring.h, so the port can later move its include into a ported group.docs/rust-port/naming.mdlists it underobs-graphics. The tests that compileeffect-parser.c.hinto themselves (test_effect_parser_blocks,_params,_passes,_funcsand the_rustvariants 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 asin 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
test_effect_parser_funcspasses 6/6 on the C build, the hybridlibobsandlibobs-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_rustvariants) on the hybridlibobsand onlibobs-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_keywordandep_parse_functionare local (t) in each. The workspace tests, formatting, clippy and the Windows clippy on all targets pass, and./unittestpassed (6534 and 912 Rust tests; Tier 2 722/722 againstlibobs-c-referenceand 722/722 against the hybridlibobs, 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.Checklist
master(or the description starts with a Stacked: note)docs/features.mdis added or updated (not applicable: no user-visible change)-W..., ratchets): built with scripting ON (PR CI builds no OBS app: rungh workflow run ci.yml --ref <branch>for the full builds) and cross-checked with clang and MSVC (not applicable: no warning or flag change)