Skip to content

obs-graphics: Port the effect parser params - #3621

Merged
rdoupe merged 6 commits into
masterfrom
fix/rust-port-port-the-effect-parser-596
Nov 6, 2026
Merged

rdoupe merged 6 commits into
masterfrom
fix/rust-port-port-the-effect-parser-596

Conversation

@rdoupe

@rdoupe rdoupe commented Nov 4, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #3610
Fixes #3611
Refs #3610
Refs #3611

What and why

Second step of porting the effect parser's parameter declarations, annotations and value assignments to obs-graphics (#3610, #3611), after the characterization test and the move into libobs/graphics/effect-parser-params.c.h (#3615). Same shape as the struct and sampler-state blocks (#3595) and the passes and techniques (#3609). ep_parse_other() stays C and calls ep_parse_param() on the token after a declaration's type and name ([[count]] [< type name [= value]; ... >] [= value];); the hybrid libobs now runs it in Rust. One RED → GREEN pair per issue:

  • obs-graphics: Test the effect parser param values (RED, rust: Port the effect parser's parameter value assignments #3610): Tier 1 in shader::effect_parser_params against todo!() stubs. array_returns, assignment_returns and assign_returns run ep_parse_param_array, ep_parse_param_assignment_val and ep_parse_param_assign from their [ or = token and pin the code or result, the count and default bytes (as test_effect_parser_params writes them), the errors and the token each stops at, for every value form, malformed and cut-short values, and counts that are 0, negative, not a number or past INT_MAX. ParamTokens (beside the shader parser's Tokens) gives the value parsers what the C reads: the number token's text as the C string strtol and os_strtod read (it runs on into the lexer's text), libobs's os_strtod, cf_literal_to_str, and the "Invalid type '$1'" error with the type. BlockError gets "Invalid row count" and "Invalid column count".
  • obs-graphics: Port the effect parser param values (GREEN, rust: Port the effect parser's parameter value assignments #3610): the safe core of the value parsers, one to one over the shader parser's cf-parser.h steps, on effect_param_types' type, row, column, int and count rules and shader_param_values' float read (os_strtod's 63-byte copy, then the (float) cast). Core only: the C declaration still calls the C helpers until the next pair.
  • obs-graphics: Test the effect parser param decls (RED, rust: Port the effect parser's annotations and parameter declaration #3611): scalars, vectors, arrays, eof, annotations, annotation_eof and mixed port test_effect_parser_params.c one to one (same texts, same groups, its comments kept) at the declaration: the cursor steps over the specifiers, type and name as ep_parse_other() does, and each expectation is the declaration's own part of the C one (the param kept, the errors it adds, one row up: no guard line, and the token it stops at). edge_params adds what the C test leaves out (every specifier, values past INT_MAX and FLT_MAX, a float longer than os_strtod's buffer, a NUL escape, the string/texture prefixes, int1 and bool2, matrix constructors, two counts, annotations on an array, an annotation's texture type and its vector and matrix values), and annotation_var_returns / annotations_returns pin the inner codes. A proptest walks token soups after a name.
  • obs-graphics: Port the effect parser param decls (GREEN, rust: Port the effect parser's annotations and parameter declaration #3611): the rest of the core (parse_param_annotation_var, parse_annotations, parse_param) and the hidden shim ep_parse_param() in ffi::effect_parser. The core walks ep->cfp.cur_token in place, so ep_parse() goes on from where the declaration stopped. A kept param is written as the C builds it: ep_param_init() with the caller's type and name (kept, as the C keeps them), the flags, count and annotations (bmalloc copies of their type and name), and default_val a string or texture path in one da_copy_array or each int/float in its own 4-byte da_push_back_array, on libobs's allocator, so ep_free() frees it; its gs_effect_param pointer is NULL (the C leaves it unset until ep_compile_param()). A dropped one frees the type and name, as ep_param_free() does. os_strtod and cf_literal_to_str go through the private adapters (obs_graphics_cf_literal_to_str is new, beside obs_graphics_os_strtod). The params' group becomes libobs.ported-effect-parser-params (its own ported-source-sets/effect-parser-params.json), the shim is hidden by rust-hidden.d/obs-graphics-effect_parser.txt, and a new test_effect_parser_params_rust runs the unchanged C test against the shim from the production staticlib (hybrid only, with its own Windows import library for the lookup bridge). test_effect_parser_blocks_rust and test_effect_parser_passes_rust stop compiling the params' C, which the staticlib now defines.
  • obs-graphics: Compare the effect parser params: the Tier 2 layout of ep_param and Tier 3 parity in shader::effect_parser_params_parity against oracle/effect_parser_params.c, the moved file compiled unmodified under oracle_* names on the C cf-parser, lexer, preprocessor, cf_literal_to_str, os_strtod, type decisions and number reads. Both sides get the same tokens from the C lexer; everything either side leaves in the parser is compared (every param and annotation field but the gs_effect_param pointer, every default byte, darray counts and capacities, the other collections, every error, the cursor). Inputs: the 143 declarations of the C test and Tier 1 with each set of flags, every prefix of each, each from every token and as ten types, and random token soups. Mutation check: ten planted mutants (in the core and in the shim), each failing one to four of the eight tests. A port_comparison bench runs a two-annotation float4 declaration through both sides.
  • docs: Record the effect parser params port: the rust/README.md row and the crate row, Cargo.toml description and lib.rs docs. docs/rust-port/naming.md lists the file since the move.

No intentional differences: the C frees a dropped declaration's type and name on every path. The int and count reads keep their own intentional difference (#3464, saturation past INT_MAX), which lives in effect_param_types; the parity test leaves those values out and checks the port's side against that contract. Characterized, not endorsed, and kept: an int reads the leading digits of a number token; - 1 reads as -1, and the end of the text after a - adds no error; a bad bool or a type with no value parser doesn't skip to the ;; a bad row or column digit adds its error and still counts; a count that is not a number token, or no ; after a value or annotation list, drops the declaration with no error; a : mapping or a failed value ends an annotation list where it is and drops the declaration (a failed value is reported twice); an annotation's texture flag comes from the empty type its entry starts with, so a texture annotation's value is an invalid type.

The two value helpers ep_parse_param_array() and ep_parse_param_assign() stay declared in the private effect-parser-params.h for the C and C reference builds; their only caller is now the Rust ep_parse_param(), so they get no shim of their own.

Ported code: Lain Bailey's (upstream obs-studio), credited on the GREEN commits. No upstream issue.

RED → GREEN

  • RED commits: obs-graphics: Test the effect parser param values (646c3cc): soldr cargo test -p obs-graphics --test obs-tests-graphics -- shader::effect_parser_params:: fails 3 of 3 (not yet implemented in parse_param_array, parse_param_assignment_val, parse_param_assign). obs-graphics: Test the effect parser param decls (2ef345c): fails 11 of 14, the 3 value tests passing.
  • GREEN: obs-graphics: Port the effect parser param values (8ed7139) passes the 3 value tests; obs-graphics: Port the effect parser param decls (78bf33e) passes Tier 1 14/14 (215/215 in the shader category), and Tier 3 passes 8/8 with all ten mutants caught. The effect and shader cmocka tests pass 19/19 on the C build and on libobs-c-reference and 24/24 on the hybrid libobs with test_effect_parser_params_rust (ASan and UBSan) and the other _rust variants, none skipped. The C, hybrid and C reference builds export the same 1767 symbols as master, ep_parse_param local (t) in each, and the hybrid holds none of the C helpers. local_gate.py --test-diff passes 6526/6526 (6 skipped, as on master); the lint and cross lanes pass every step up to Dylint, which has no driver for nightly-2026-08-15 on this host, and cargo clippy --workspace --target x86_64-pc-windows-msvc --all-targets -D warnings is clean. The port_comparison bench passes its allocation check. ./unittest passes (Rust 6526 and 912 tests, Tier 2 722/722 against both libobs-c-reference and the hybrid libobs, 3 skipped on each: the PulseAudio default-device and vivid V4L2 tests that need hardware the image lacks). Runs were on ad2aa1990; after the rebase onto current master (which added the effect parser's function parser as its own C file, now compiled into the _rust tests beside ep_parse()), the export comparison, the effect and shader cmocka tests (19/19 C and C reference, 24/24 hybrid), the shader Rust tests (215/215), the quick CI checks and the bench were rerun on 5ccee6d, and the local gate's lint, rust-test and tier2-linux lanes passed there. The stamp could not be made here (its cross lane hit a stale build cache on this host), so PR CI runs the full suite.
  • Real app (UI, protocol output or logging changes): N/A, no UI, protocol or logging change.

Test cost: new tests: longest under 0.1 s (the whole parity module runs in 0.10 s, debug build, OBS_PARITY_CASES=reduced), peak RSS 7.2 MB over 25 runs of each module, no own threads.

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)
  • 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) (none in this file: the parity header and the README row say so, and point to rust: Port the effect parser's number values #3464's in effect_param_types)

@rdoupe
rdoupe force-pushed the fix/rust-port-port-the-effect-parser-596 branch from b663ae6 to ae424e6 Compare November 4, 2026 16:12
@rdoupe
rdoupe marked this pull request as ready for review November 4, 2026 16:33
@rdoupe
rdoupe requested a review from zackees as a code owner November 4, 2026 16:33
@obs-rust-project-manager obs-rust-project-manager Bot moved this from Needs fix to In review in obs-rust Multiview Nov 5, 2026
@obs-rust-project-manager obs-rust-project-manager Bot moved this from In review to Needs fix in obs-rust Multiview Nov 6, 2026
rdoupe and others added 6 commits November 6, 2026 09:47
Tier 1 for the port of the effect parser's parameter value assignments
(libobs/graphics/effect-parser-params.c.h) to obs_graphics::
effect_parser, against todo!() stubs.

The core walks the C parser's tokens in place through the shader
parser's Tokens trait, as the blocks and passes do, and fills a Param
(struct ep_param as the C fills it: type, name, flags, array count,
the default value's bytes and the annotations). ParamTokens adds what
the value parsers read beyond Tokens: the number token's text as the C
string strtol and os_strtod read (it runs on into the lexer's text),
libobs's os_strtod, cf_literal_to_str of the token, and the "Invalid
type '$1' used for assignment" error with the type. BlockError gets
the "Invalid row count" and "Invalid column count" errors.

array_returns, assignment_returns and assign_returns run
ep_parse_param_array, ep_parse_param_assignment_val and
ep_parse_param_assign from their '[' or '=' token, and pin the code or
result, the count and the default bytes as test_effect_parser_params
writes them, the errors and the token each stops at: each value form
(int, float, bool, string, texture path, '-' with and without a space,
the { } and type( ) forms of vectors and matrices), each malformed one
and each cut short, and counts that are 0, negative, not a number,
past INT_MAX or unterminated.

Refs #3610.
The safe core of the effect parser's parameter value assignments
(libobs/graphics/effect-parser-params.c.h) in obs_graphics::
effect_parser: ep_parse_param_array(), the texture path, string,
int and float, bool and vector or matrix value parsers,
ep_parse_param_assignment_val() and ep_parse_param_assign(), one to
one over the shader parser's ports of the util/cf-parser.h inlines
(cf_next_token, cf_next_valid_token, cf_next_token_should_be,
cf_go_to_token, cf_token_is_type), each called where the C calls it,
with every return path and error of the C.

The type decisions, the row and column counts, the int value and the
array count are effect_param_types' rules, the float shader_param_
values' read (os_strtod's 63-byte copy, then the (float) cast), each
on the number token's text as the C string the C hands them, read a
byte at a time through ParamTokens. An int or float is pushed as its
native bytes, a string or texture path is its cf_literal_to_str up to
the first NUL, with the NUL.

The declaration that calls them stays C until its own port; the C
ep_parse_param() still calls the C helpers.

Refs #3610.

Co-authored-by: Lain <[email protected]>
Tier 1 for the port of the effect parser's annotations and parameter
declaration (libobs/graphics/effect-parser-params.c.h) to
obs_graphics::effect_parser, against todo!() stubs.

scalars, vectors, arrays, eof, annotations, annotation_eof and mixed
port test_effect_parser_params.c one to one (same texts, in the same
groups, with its comments) at the declaration: the cursor steps over
the specifiers, the type and the name as ep_parse_other() does, then
ep_parse_param runs from the token after the name. Each expectation is
the declaration's own part of the C one: the param it keeps, written
as the C test writes it with its annotations, the errors it adds (one
row up: no guard line) and the token it stops at, where ep_parse()
goes on. A text that ends after the name never reaches it. mixed runs
every declaration of its text and steps over the function.

edge_params adds what the C test leaves out: every specifier in any
order, ints and counts past INT_MAX (#3464's saturation), a float past
FLT_MAX and one longer than os_strtod's 63 bytes, strings with a NUL
escape and single quotes, the string and texture prefixes, int1 and
bool2, the matrix constructor form, two counts, annotations on an
array, an annotation's texture type (no texture flag: it is set from
the empty type the entry starts with) and its vector and matrix
values. annotation_var_returns and annotations_returns pin the codes
of ep_parse_param_annotation_var and the results of
ep_parse_annotations. A proptest walks token soups after a name and
checks the cursor never steps past the terminator and a kept param
stops at its ';' with whole values and named annotations.

Refs #3611.
The safe core of the effect parser's annotations and parameter
declaration (libobs/graphics/effect-parser-params.c.h) in obs_graphics::
effect_parser, and the hidden C ABI shim ep_parse_param() in
ffi::effect_parser that the C ep_parse_other() calls on the token after
a declaration's name. The hybrid libobs drops the C.

The core is ep_parse_param_annotation_var(), ep_parse_annotations()
(with ep_parse_param_annotations()) and ep_parse_param(), one to one
over the shader parser's cf-parser.h steps, each called where the C
calls it, with every return path and error of the C, on #3610's value
parsers. A declaration is returned whole, or None where the C frees
it. Each annotation entry starts as ep_param_init() of two empty
strings, so its texture flag stays false whatever its type, as in the
C.

The shim's Tokens is ep->cfp.cur_token itself (RawTokens), so
ep_parse() goes on from the token where the declaration stopped. Its
ParamTokens reads the number token's text in place, byte by byte, as
strtol and os_strtod read it, and calls libobs's os_strtod and
cf_literal_to_str through the private adapters (a new
obs_graphics_cf_literal_to_str beside obs_graphics_os_strtod); the
invalid type error goes to cf_adderror() with the type. A kept param
is ep_param_init() with the caller's type and name (kept, as the C
keeps them), the flags, the count, the annotations (bmalloc copies of
their type and name) and default_val built as the C builds it: a
string or texture path in one da_copy_array, each int or float with
its own 4-byte da_push_back_array, on libobs's allocator, so ep_free()
frees it. Its gs_effect_param pointer is NULL; the C leaves it unset
until ep_compile_param() writes it. A dropped param frees the caller's
type and name, as ep_param_free() does.

The params' unity group becomes libobs.ported-effect-parser-params (its
own ported-source-sets/effect-parser-params.json, out of LIBOBS_SOURCES
and the graphics module), and the shim is hidden by
rust-hidden.d/obs-graphics-effect_parser.txt. The C, hybrid and C
reference builds export the same 1767 symbols as master,
ep_parse_param local (t) in each, and the hybrid holds none of the C
helpers. test_effect_parser_params compiles ep_parse() and the params'
C into itself, so it keeps checking the C; test_effect_parser_params_
rust runs the same file with ep_parse() compiled in and the parameter
declarations, the blocks, the techniques, ep_free() and the parameter
type decisions from the production staticlib, on the hybrid build
only, with its own Windows import library for the lookup bridge.
test_effect_parser_blocks_rust and test_effect_parser_passes_rust no
longer compile the params' C, which the staticlib now defines.

No intentional differences: the C frees a dropped declaration's type
and name on every path. The int and count reads keep their own
intentional difference (#3464), in effect_param_types.

Refs #3610.
Refs #3611.

Co-authored-by: Lain <[email protected]>
Tier 2 layout and Tier 3 parity for the parameter declarations,
annotations and value assignments against the original C.

The oracle (oracle/effect_parser_params.c) compiles
effect-parser-params.c.h unmodified under oracle_* names, on the C
cf-parser.h inlines with the C cf_adderror, cf_pass_pair,
cf_literal_to_str, lexer, preprocessor, strref_cmp, astrcmp_n,
os_strtod, parameter type decisions and number reads, with helpers
that lex and preprocess a text into a struct effect_parser with that C
at a chosen token, copy a type or name as ep_parse_other() hands it
over, and free the parser as ep_free() does. Both sides get the same
tokens; the shim reaches libobs's cf_adderror, cf_literal_to_str and
os_strtod, obs-util's Rust here as in the hybrid libobs.

shader::effect_parser_params_parity compares the layout of struct
ep_param, then everything either side leaves in the parser: each param
and annotation (every field but the gs_effect_param pointer, which the
C leaves unset, so the shim's NULL is checked on its own; the strings,
every default byte, darray counts and capacities), the other
collections, every error (text, file, row, column, level) and where the
cursor stopped. Inputs: the 143 declarations of the C test and Tier 1
from the token after their name with each set of flags, every prefix of
each, each from every token and as each of ten types, and random token
soups after a type or from a random token. Left out, as #3464's
intentional difference of the number reads applies there: an int or a
count past INT_MAX; int_values_past_int_max checks the port's side
against that contract. No intentional differences.

Mutation check: ten planted mutants (the '-' stepped with
cf_next_valid_token, an int pushed big-endian, a string without its
NUL, no "variable name" error at a ';', one value too many, an
annotation's texture flag from its own type, cf_next_token after a
value, the shim's numbers in one push, an annotation named by its
type, two flags swapped in the shim); each fails one to four of the
eight tests.

The port_comparison bench runs a float4 declaration with two
annotations and a { } value through both sides on the same tokens,
freeing what each iteration pushed.

Refs #3610.
Refs #3611.
A rust/README.md row for libobs/graphics/effect-parser-params.c.h
(obs-graphics::effect_parser: what the shim takes over from the C,
how the core walks the C parser's cursor and reads the number token's
text in place, how a kept param is written, what is characterized and
kept, no intentional differences, and its tests), and the parameter
declarations in the obs-graphics crate row, its Cargo.toml description
and its lib.rs module docs. docs/rust-port/naming.md already lists the
file since the move.

Fixes #3610.
Fixes #3611.
@rdoupe
rdoupe force-pushed the fix/rust-port-port-the-effect-parser-596 branch from ae424e6 to 5ccee6d Compare November 6, 2026 15:41
@rdoupe
rdoupe added this pull request to the merge queue Nov 6, 2026
Merged via the queue into master with commit ab2a28b Nov 6, 2026
43 of 45 checks passed
@rdoupe
rdoupe deleted the fix/rust-port-port-the-effect-parser-596 branch November 6, 2026 16:10
@obs-rust-project-manager obs-rust-project-manager Bot moved this from Needs fix to Done in obs-rust Multiview Nov 6, 2026
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 parser's annotations and parameter declaration rust: Port the effect parser's parameter value assignments

1 participant