Skip to content

libobs: Move the effect parser params to own file - #3615

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

rdoupe merged 4 commits into
masterfrom
fix/rust-port-extract-the-effect-par-592

Conversation

@rdoupe

@rdoupe rdoupe commented Nov 4, 2026

Copy link
Copy Markdown
Collaborator

Refs #3610
Refs #3611

What and why

First step of porting the effect parser's parameters to obs-graphics: a characterization test and a behaviour-neutral extraction, C only, for two batched units, the parameter value assignments (#3610) and the annotations and parameter declaration (#3611). The Rust port of the moved file follows in its own PR on both issues. Same shape as the effect parser's passes and techniques (#3599).

  • test: Characterize the effect parser param values (rust: Port the effect parser's parameter value assignments #3610): a new test_effect_parser_params (cmocka) calls ep_init(), ep_parse() and ep_free() on 78 fixed effect texts and pins, written out and compared whole, the params kept (flags, array count and every byte of the default value), the functions after them, every error and warning with its row, column and level, and the allocations still held after ep_free(). It covers each value form (int, float, bool, string, texture path, negative values with and without a space, the { } and type( ) forms of the vectors and of the 3x3, 4x4 and 2x2 matrices), malformed values (not a number, a bool other than true or false, an invalid type, a bad row or column count, too few or too many values, a missing , or end, a vector without {, a missing ;), array counts (valid, 0, negative, not a number, unterminated) and text cut short at each step. 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 param values to own file (rust: Port the effect parser's parameter value assignments #3610): ep_parse_param_array(), ep_parse_param_assign_texture(), _string(), _intfloat(), _bool(), ep_parse_param_assign_intfloat_array(), ep_parse_param_assignment_val() and ep_parse_param_assign() move, as written, from libobs/graphics/effect-parser.c.h into the new libobs/graphics/effect-parser-params.c.h. The annotations and ep_parse_param() still call ep_parse_param_array() and ep_parse_param_assign(), so those two lose their static and are declared in a new internal graphics/effect-parser-params.h (a private adapter, not a new public API; effect-parser.h stays as it is), which replaces the forward declaration; the value helpers stay static. The file has its own live unity group, libobs.effect-parser-params (graphics module), with a precompiled header of its declarations, the parameter type decisions and util/platform.h, so the port can later move its include into a ported group. docs/rust-port/naming.md lists it under obs-graphics. test_effect_parser_blocks, test_effect_parser_passes and their _rust variants, which compile effect-parser.c.h into themselves, compile the moved file beside it.
  • test: Characterize the effect parser annotations (rust: Port the effect parser's annotations and parameter declaration #3611): the same test gains 30 texts and writes out each param's annotations: well-formed lists with each value form, empty lists, stray ;, repeated names, a list after an array count and before a value, entries with no name, a : mapping, an entry that ends at >, a failed value, no ; after a value, a bad type or name, a nested list, an invalid type, no ; after the list, a list after the value, two lists, and text cut short at each step of an entry.
  • libobs: Move the effect param declaration to file (rust: Port the effect parser's annotations and parameter declaration #3611): ep_parse_param_annotation_var(), ep_parse_annotations() and ep_parse_param_annotations() (which keep their int return type), the commented-out ep_parse_param_property() stub and ep_parse_param() move, as written, into the same file, in effect-parser.c's order (annotations first, then the values, then the declaration). ep_parse_other() calls ep_parse_param(), so it loses its static and is declared in effect-parser-params.h; the two value helpers stay declared so the value parser can be ported before the declaration that calls it, and the annotation helpers stay static. Without its static the signature fits on one line, the only change clang-format makes to the moved code. effect-parser.c now reaches the file only through ep_parse_param().

Odd but real results are marked "characterized, not endorsed" in the test. Among them: a bool other than true or false, or an invalid type, does not skip to the ;, so the next statement starts at the bad token and reports it again; no ; after a value drops the param with no error; a : mapping or a failed value in an annotation ends the list where it is, so the param is dropped and the parser goes on from inside the list; a nested annotation list ends the outer one at its >. No leak and no undefined behaviour showed: built with ASan and UBSan (gcc and clang) the test has no report, so the port has no intentional difference so far.

Moved code: Lain Bailey's (upstream obs-studio), credited on the move commits. 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 param (flags, array count, default bytes, annotations recursively), function, struct, technique, error and the live allocations after ep_free(), run on the same 199,997 generated effect texts (seed declarations with 1/64 to 29/64 of their tokens dropped, replaced or joined by others, a quarter cut short, and token soups; three generated texts that reach the function parser, a later unit, are left out): identical logs (1,153,060 lines, 40,337 params kept, 28,946 with a default value, 3,010 with annotations, 712,726 errors) in 8 builds of each side (GCC and Clang, -O0 and -O2, with and without ASan and UBSan without recovery), for the tree after each move. Sixteen planted mutants of the moved code all differ.

RED → GREEN

  • RED commit: N/A. The extraction has no RED: the characterization test passes on master's code and after each move, unchanged, and no bug turned up to fix.
  • GREEN: test_effect_parser_params passes 7/7 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_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 17/17 on the C build and 21/21 (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_parse_param, ep_parse_param_array and ep_parse_param_assign are local (t) in each. The workspace tests, formatting, clippy and the Windows clippy on all targets pass, and ./unittest passed (6504 and 912 Rust tests; Tier 2 720/720 against libobs-c-reference and 720/720 against the hybrid libobs). 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 046aa14; the move harness ran on the same commits before their rebase onto the passes port, which changed none of the C it compiles but one precompiled header include, the same on both sides.
  • 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, for each unit; 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)

rdoupe and others added 4 commits November 4, 2026 01:24
The effect parser's parameter value assignments have no C test of
their own: the effect tests load whole effects through a device.
test_effect_parser_params calls ep_init(), ep_parse() and ep_free()
on fixed effect texts and pins, written out and compared whole, the
params kept (flags, array count and every byte of the default value),
the functions after them, every error and warning with its row,
column and level, and the allocations still held after ep_free().

78 texts: each value form (int, float, bool, string, texture path,
negative values with and without a space, the { } and type( ) forms of
the vectors and the 3x3, 4x4 and 2x2 matrices), malformed values (not
a number, a bool other than true or false, an invalid type, a bad row
or column count, too few or too many values, a missing ',' or end, a
vector without '{', a missing ';'), array counts (valid, 0, negative,
not a number, unterminated) and text cut short at each step. Odd but
real results are marked "characterized, not endorsed": among them, a
bad bool or an invalid type does not skip to the ';', so the next
statement starts at the bad token and reports it again.

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_passes 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, and built with ASan and UBSan
it has no report.

Refs #3610.
Behaviour-neutral extraction before the Rust port. The effect
parser's parameter value assignments move, as written, into the new
libobs/graphics/effect-parser-params.c.h:

- ep_parse_param_array();
- ep_parse_param_assign_texture(), _string(), _intfloat() and
  _bool(), and ep_parse_param_assign_intfloat_array();
- ep_parse_param_assignment_val();
- ep_parse_param_assign().

The annotations and ep_parse_param(), still in effect-parser.c, call
ep_parse_param_array() and ep_parse_param_assign(), so those two lose
their static (and inline) and are declared in a new internal
graphics/effect-parser-params.h, a private adapter and not a new
public API; its declaration replaces effect-parser.c's forward one.
The value helpers stay static in the new file. 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-params (in
the graphics module), with a precompiled header of its declarations,
the parameter type decisions and util/platform.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
two moved functions local (t) in each. The tests that compile the
effect parser C into themselves compile the new file beside it.

Refs #3610.

Co-authored-by: Lain <[email protected]>
The effect parser's annotations and parameter declaration have no C
test of their own either. test_effect_parser_params gains two groups
of texts and now also writes out each param's annotations (type,
name and default bytes, in the order they were pushed):

- 22 annotation lists: well-formed ones with each value form, empty
  lists, stray ';', repeated names, a list after an array count and
  before a value, entries with no name, a ':' mapping, an entry that
  ends at '>', a failed value, no ';' after a value, a bad type or
  name, a nested list, an invalid type, no ';' after the list, a list
  after the value and two lists;
- 8 texts cut short at each step of an entry.

Odd but real results are marked "characterized, not endorsed": among
them, a ':' mapping or a failed value ends the list where it is, so
the param is dropped and the parser goes on from inside the list, and
a nested list ends the outer one at its '>', so the outer list's last
entry is read as a param of its own. It passes, none skipped, against
the C, hybrid and C reference libobs, and built with ASan and UBSan
it has no report.

Refs #3611.
Behaviour-neutral extraction before the Rust port. The effect
parser's annotations and parameter declaration move, as written, into
libobs/graphics/effect-parser-params.c.h, ahead of the value
assignments as in effect-parser.c:

- ep_parse_param_annotation_var();
- ep_parse_annotations() and ep_parse_param_annotations(), which keep
  their int return type;
- the commented-out ep_parse_param_property() stub and
  ep_parse_param().

ep_parse_other() calls ep_parse_param(), so it loses its static and
is declared in graphics/effect-parser-params.h beside the two value
helpers, which stay declared so the value parser can be ported before
the declaration that calls it. The annotation helpers stay static.
Nothing else changes: ep_parse_other() calls it on the same token,
with the same type and name. Without its static the signature fits on
one line, which is the only change clang-format makes to the moved
code.

effect-parser.c now reaches the file only through ep_parse_param().
The C, hybrid and C reference builds export the same 1767 symbols as
master, ep_parse_param, ep_parse_param_array and ep_parse_param_assign
local (t) in each.

Refs #3611.

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