Repository navigation
obs-graphics: Port the effect parser params - #3621
Merged
Merged
Conversation
rdoupe
force-pushed
the
fix/rust-port-port-the-effect-parser-596
branch
from
November 4, 2026 16:12
b663ae6 to
ae424e6
Compare
rdoupe
marked this pull request as ready for review
November 4, 2026 16:33
4 of 7 tasks
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
force-pushed
the
fix/rust-port-port-the-effect-parser-596
branch
from
November 6, 2026 15:41
ae424e6 to
5ccee6d
Compare
This was referenced Nov 6, 2026
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 #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 intolibobs/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 callsep_parse_param()on the token after a declaration's type and name ([[count]] [< type name [= value]; ... >] [= value];); the hybridlibobsnow 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 inshader::effect_parser_paramsagainsttodo!()stubs.array_returns,assignment_returnsandassign_returnsrunep_parse_param_array,ep_parse_param_assignment_valandep_parse_param_assignfrom their[or=token and pin the code or result, the count and default bytes (astest_effect_parser_paramswrites 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 pastINT_MAX.ParamTokens(beside the shader parser'sTokens) gives the value parsers what the C reads: the number token's text as the C stringstrtolandos_strtodread (it runs on into the lexer's text), libobs'sos_strtod,cf_literal_to_str, and the "Invalid type '$1'" error with the type.BlockErrorgets "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'scf-parser.hsteps, oneffect_param_types' type, row, column,intand count rules andshader_param_values'floatread (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_eofandmixedporttest_effect_parser_params.cone to one (same texts, same groups, its comments kept) at the declaration: the cursor steps over the specifiers, type and name asep_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_paramsadds what the C test leaves out (every specifier, values pastINT_MAXandFLT_MAX, a float longer thanos_strtod's buffer, a NUL escape, thestring/textureprefixes,int1andbool2, matrix constructors, two counts, annotations on an array, an annotation's texture type and its vector and matrix values), andannotation_var_returns/annotations_returnspin 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 shimep_parse_param()inffi::effect_parser. The core walksep->cfp.cur_tokenin place, soep_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 (bmalloccopies of their type and name), anddefault_vala string or texture path in oneda_copy_arrayor eachint/floatin its own 4-byteda_push_back_array, on libobs's allocator, soep_free()frees it; itsgs_effect_parampointer isNULL(the C leaves it unset untilep_compile_param()). A dropped one frees the type and name, asep_param_free()does.os_strtodandcf_literal_to_strgo through the private adapters (obs_graphics_cf_literal_to_stris new, besideobs_graphics_os_strtod). The params' group becomeslibobs.ported-effect-parser-params(its ownported-source-sets/effect-parser-params.json), the shim is hidden byrust-hidden.d/obs-graphics-effect_parser.txt, and a newtest_effect_parser_params_rustruns 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_rustandtest_effect_parser_passes_ruststop compiling the params' C, which the staticlib now defines.obs-graphics: Compare the effect parser params: the Tier 2 layout ofep_paramand Tier 3 parity inshader::effect_parser_params_parityagainstoracle/effect_parser_params.c, the moved file compiled unmodified underoracle_*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 thegs_effect_parampointer, 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. Aport_comparisonbench runs a two-annotationfloat4declaration through both sides.docs: Record the effect parser params port: therust/README.mdrow and the crate row,Cargo.tomldescription andlib.rsdocs.docs/rust-port/naming.mdlists the file since the move.No intentional differences: the C frees a dropped declaration's type and name on every path. The
intand count reads keep their own intentional difference (#3464, saturation pastINT_MAX), which lives ineffect_param_types; the parity test leaves those values out and checks the port's side against that contract. Characterized, not endorsed, and kept: anintreads the leading digits of a number token;- 1reads as-1, and the end of the text after a-adds no error; a badboolor 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()andep_parse_param_assign()stay declared in the privateeffect-parser-params.hfor the C and C reference builds; their only caller is now the Rustep_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
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 implementedinparse_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.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 onlibobs-c-referenceand 24/24 on the hybridlibobswithtest_effect_parser_params_rust(ASan and UBSan) and the other_rustvariants, none skipped. The C, hybrid and C reference builds export the same 1767 symbols as master,ep_parse_paramlocal (t) in each, and the hybrid holds none of the C helpers.local_gate.py --test-diffpasses 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, andcargo clippy --workspace --target x86_64-pc-windows-msvc --all-targets -D warningsis clean. Theport_comparisonbench passes its allocation check../unittestpasses (Rust 6526 and 912 tests, Tier 2 722/722 against bothlibobs-c-referenceand the hybridlibobs, 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_rusttests besideep_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.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
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)effect_param_types)