Repository navigation
obs-graphics: Port the effect parser blocks - #3595
Merged
Merged
Conversation
Tier 1 for the port of the effect parser's struct and sampler-state
blocks (libobs/graphics/effect-parser-blocks.c.h) to a new
obs_graphics::effect_parser module, against todo!() stubs.
The core walks the C parser's tokens in place through the shader
parser's Tokens trait (cur_token, its type and text, cf_adderror() and
cf_pass_pair()), so ep_parse() goes on from the token where a block
stopped, and returns the struct or sampler the C would push, or None
where the C frees it. The struct block's C is the shader parser's line
for line; the sampler-state item differs (its value is every token up
to the next ';', joined, and an empty value drops the item).
struct_* and sampler_* port test_effect_parser_blocks.c one to one
(same texts, in the same groups) at the block: the struct or sampler
kept, the errors the block adds, and the token it stops at, with the
second blocks of its two-block and mixed texts. edge_* add what the C
test leaves out: values of any token kind, a string holding a ';',
newlines and tabs inside a value, a '{' or '=' inside a value, several
empty items, a value or state name cut short, a bad name cut short
inside the braces it skips, and the shader parser's struct edges. A
proptest walks random token soups over the blocks' vocabulary and
checks the cursor never steps past the terminator and no kept value is
empty. The shader parser's Tier 1 cursor and dump helpers are shared,
and its cf-parser steps are made visible to the crate.
Refs #3550.
The safe core of the effect parser's struct and sampler-state blocks (libobs/graphics/effect-parser-blocks.c.h) in obs_graphics::effect_parser, and the hidden C ABI shims ep_parse_struct() and ep_parse_sampler_state() in ffi::effect_parser that the C ep_parse() calls on the keyword token of each block. The hybrid libobs drops the C. The core is ep_parse_struct(), ep_parse_sampler_state_item() and ep_parse_sampler_state() over the shader parser's Tokens trait and its one-to-one ports of the util/cf-parser.h inlines (cf_next_name, cf_next_token_should_be, cf_next_valid_token, cf_peek_valid_token), each called where the C calls it. The struct block's C is the shader parser's line for line (struct ep_var and ep_struct in place of shader_var and shader_struct), so parse_struct() is shader_parser::parse_struct(). The sampler-state item keeps its own loop: every token up to the one starting with ';' joined into the value (dstr_ncat), and the item pushed only when the value is not empty. Each block returns the struct or sampler the C would push, or None where the C frees it. The shim's Tokens is ep->cfp.cur_token itself (the shader parser shim's RawTokens), so ep_parse() goes on from the token where a block stopped; its errors and brace skips go to the exported cf_adderror() and cf_pass_pair() through the existing private adapters, at the same tokens. A kept block is written as the C builds it: bmalloc copies and darrays grown as util/darray.h grows them, on libobs's allocator, so ep_free()'s inline destructors free them; a struct variable is ep_var_init() (all zero) with its type, name and mapping, and a struct or sampler is not written. The blocks' unity group becomes libobs.ported-effect-parser-blocks (its own ported-source-sets/effect-parser-blocks.json, out of LIBOBS_SOURCES and the graphics module), and the shims are hidden by rust-hidden.d/obs-graphics-effect_parser.txt. The C, hybrid and C reference builds export the same 1767 symbols as master, the two shims local (t) in each. test_effect_parser_blocks compiles ep_parse() and the blocks' C into itself, so it keeps checking the C; test_effect_parser_blocks_rust runs the same file with ep_parse() compiled in and the blocks, ep_free() and the parameter type decisions from the production staticlib, on the hybrid build only. No intentional differences: the C already frees a dropped item's state name and value on every path. Refs #3550. Co-authored-by: Lain <[email protected]>
Tier 2 layouts and Tier 3 parity for the struct and sampler-state blocks against the original C. The oracle (oracle/effect_parser_blocks.c) compiles effect-parser-blocks.c.h unmodified under oracle_* names, on the C cf-parser.h inlines with the C cf_adderror, cf_pass_pair, dstr_ncat, lexer, preprocessor and strref_cmp, with helpers that lex and preprocess a text into a struct effect_parser with that C, at a chosen token, and free it as ep_free() does. Both sides get the same tokens; the shim reaches libobs's cf_adderror and cf_pass_pair, obs-util's Rust here as in the hybrid libobs. shader::effect_parser_parity compares the layouts of struct ep_var (with enum ep_var_type), ep_struct, ep_sampler and effect_parser, then everything either side leaves in the parser: each struct, variable and sampler (every field, the strings, darray counts and capacities), the other collections, every error (text, file, row, column, level) and where the cursor stopped. A kept value's own allocation size is not compared (the C grows a dstr, the shim copies once; ep_free() frees either). Inputs: 61 fixed texts (the C test's, Tier 1's and libobs's own effects' blocks, with comments), every prefix of each, each from every token as either block, and random token soups from the keyword or from a random token. No intentional differences. Mutation check: five planted mutants (an empty value kept, a space pushed after each value token, end of text inside a value taken as a skipped item, a pushed struct marked written, end of text at the peek keeping the sampler) each fail one to three of the seven tests. The port_comparison bench runs a vertex struct and a four-item sampler state through both sides on the same tokens, freeing what each iteration pushed. Refs #3550.
A rust/README.md row for libobs/graphics/effect-parser-blocks.c.h (obs-graphics::effect_parser: what the shims take over from the C, how the core walks the C parser's cursor and reuses the shader parser's struct block, what is characterized and kept, no intentional differences, and its tests), and the blocks 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 #3550.
rdoupe
force-pushed
the
fix/rust-port-port-the-effect-parser-582
branch
from
November 4, 2026 00:17
39a07d8 to
79497b2
Compare
rdoupe
marked this pull request as ready for review
November 4, 2026 00:30
This was referenced Nov 4, 2026
This was referenced Nov 4, 2026
6 of 7 tasks
6 of 7 tasks
This was referenced Nov 4, 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 #3550
What and why
Second step of #3550: the Rust port of the effect parser's struct and sampler-state blocks (
libobs/graphics/effect-parser-blocks.c.h, moved out ofeffect-parser.c.hwith its characterization in #3561) to a newobs-graphicsmodule,effect_parser. The hybrid libobs drops the C. No upstream issue; upstream code by Lain, credited on the port commit.The struct block's C is the shader parser's line for line (ported in #3541), so the effect core reuses it; only the sampler-state item is new.
obs-graphics: Test the effect parser blocks(RED): Tier 1 inshader::effect_parser, againsttodo!(). The struct and sampler cases oftest_effect_parser_blocks.c, one to one at the block (the struct or sampler kept, the errors the block adds, and the token it stops at), with the second blocks of its two-block and mixed texts, plus edge cases: values of any token kind, a string holding a;, newlines and tabs inside a value, a{or=inside a value, several empty items, a value or state name cut short, a bad name cut short inside the braces it skips, and the shader parser's struct edges; and a proptest that the walk never steps past the terminator and keeps no empty value. It shares the shader parser's Tier 1 cursor and dump helpers.obs-graphics: Port the effect parser blocks(GREEN): the safe core over the shader parser'sTokenstrait and its one-to-one ports of theutil/cf-parser.hinlines, each called where the C calls it.parse_structisshader_parser::parse_struct; the sampler-state item keeps its own loop (every token up to the one starting with;joined into the value, asdstr_ncatdoes, and the item pushed only when the value is not empty). The hidden shimsep_parse_struct()andep_parse_sampler_state()walkep->cfp.cur_tokenitself, soep_parse()(still C) goes on from the token where a block stopped; errors and brace skips go to the exportedcf_adderror()andcf_pass_pair()through the existing private adapters, at the same tokens. A kept block is written as the C builds it (bmalloccopies, darrays grown asutil/darray.hgrows them, on libobs's allocator; nothing markedwritten), soep_free()frees it. The unity group becomeslibobs.ported-effect-parser-blocks(its ownported-source-sets/effect-parser-blocks.json), andrust-hidden.d/obs-graphics-effect_parser.txthides the shims.test_effect_parser_blockscompilesep_parse()and the blocks' C into itself, sinceep_parse()is hidden, so a newtest_effect_parser_blocks_rustruns the same unchanged file withep_parse()compiled in and the blocks,ep_free()and the parameter type decisions taken from the production staticlib (hybrid build only, astest_effect_param_types_steps_rustdoes).obs-graphics: Compare the effect parser blocks(Tier 2 layouts, Tier 3): an oracle that compiles the moved file unmodified underoracle_*names on the C cf-parser inlines and the Ccf_adderror,cf_pass_pair,dstr_ncat, lexer and preprocessor, with helpers that lex a text into astruct effect_parserwith that C, so both sides get the same tokens.shader::effect_parser_paritychecks the layouts ofstruct ep_var(withenum ep_var_type),ep_struct,ep_samplerandeffect_parser, then everything either side leaves in the parser (every field of each struct, variable and sampler, darray counts and capacities, the other collections, every error with its file, row, column and level, and where the cursor stopped) on 61 fixed texts, every prefix of each, each from every token as either block, and random token soups. Plus aport_comparisonbench.docs: Record the effect parser blocks port: the rust/README.md row, the crate row, Cargo.toml description and lib.rs docs.No intentional differences: the sampler-state item leak the round plan carried was fixed in the C by #3561, so the port follows the fixed C. Characterized, not endorsed, and kept as the C does it (pinned by
test_effect_parser_blocksand Tier 1): a missing;in a sampler state joins the next item into the value; an empty value drops the item with no error; a stray token before a struct variable's;drops the variable with no error; a bad block name skips to a;past the braces.RED → GREEN
obs-graphics: Test the effect parser blocks. All 11 Tier 1 tests inshader::effect_parserfail, panicking at the stubs (not yet implemented: ep_parse_struct/ep_parse_sampler_state); the 11shader::shader_parsertests whose helpers it shares still pass.--test-diff origin/masterthere runs 6159 tests and fails on those 11 and nothing else (6 skipped by the test filter), and the lint lane passes every step up to Dylint. Runs were on that commit.docs: Record the effect parser blocks port):shader::effect_parser11/11, Tier 3shader::effect_parser_parity7/7.written, end of text at the peek keeping the sampler) each fail one to three of the seven parity tests. A sixth (the}check after the peek loop never failing) was equivalent: that check cannot fail after the peek.test_effect_parser_blockspasses on the C build, hybrid libobs andlibobs-c-reference, andtest_effect_parser_blocks_rust(the same file on the shims) passes on the hybrid build. The C, hybrid and C reference builds export the same 1767 symbols as master, the two shims local (t) in each; the hybrid compiles none of the group's C.ctest -R 'shader|effect|graphics|texture|image|gif|sampler', under Xvfb): 57/57 on hybrid libobs, 57/57 onlibobs-c-reference, 48/48 on the C build, none skipped.port_comparisonbench passes its allocation check.--test-diff6450 passed, 6 skipped by the test filter;--lane lintand--lane crosspass every step up to Dylint (formatting, theci/tests, every clippy feature set), which this host can't run (no Dylint driver for the pinned nightly);soldr cargo clippy --workspace --target x86_64-pc-windows-msvc --all-targets --locked -- -D warningsis clean. PR CI runs the Dylint step. For the same reason the head is not stamped (the stamp run stops at that lint step), so PR CI runs the full suite../unittest: the Rust tiers pass (6450 and 912), and Tier 2 in Docker passes 717/717 againstlibobs-c-referenceand 717/717 against hybrid libobs,test_effect_parser_blocks_rustamong them (3 skipped on each, the pulse default-follow and two v4l2 vivid tests, which need hardware or a sound server); its export-symbol comparison of C and Rust libobs passes.Test cost: new tests: longest module 0.11 s in the debug build (parity, 7 tests; Tier 1 0.01 s), the same at
reducedandfull; peak RSS 7.5 MB over 25 runs; 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): not applicable