Repository navigation
obs-graphics: Port the effect parser passes - #3609
Merged
Merged
Conversation
Tier 1 for the port of the effect parser's passes and techniques (libobs/graphics/effect-parser-passes.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 do, so ep_parse() goes on from the token where a technique stopped, and returns the technique the C would push, or None where the C frees it. A pass's programs are not text: each is the list of the tokens the C copies into it (a Tokens::Mark) and the end token, so the shim can copy the C tokens themselves. techniques, pass_errors, technique_errors, eof and mixed port test_effect_parser_passes.c one to one (same texts, in the same groups) at the technique: the technique kept, its passes and the tokens of each program, the errors it adds and the token it stops at, with the second technique of the C test's two-technique text. edge_techniques adds what the C test leaves out: a '}' inside a call (its tokens kept with no end token), both programs in any order, strings and numbers in a call, three passes named three ways, 'compile' twice, comments in a call, a missing '=' before a '}', skips cut short, and a bad name with nothing after it. pass_returns and pass_command_returns pin the codes ep_parse_pass and ep_parse_pass_command return (PARSE_SUCCESS, PARSE_CONTINUE, PARSE_UNEXPECTED_CONTINUE and PARSE_EOF). A proptest walks random token soups and checks the cursor never steps past the terminator and each program is ';'-ended calls with their end tokens, or a call cut at a '}'. The pass command's "compile keyword not necessary" is a warning, so the shader parser's BlockError gets that error and the level each error is added at; the shader parser shim passes it to cf_adderror() (LEX_ERROR for the errors it already adds), and its Tier 1 cursor writes it. Refs #3598.
The safe core of the effect parser's passes and techniques (libobs/graphics/effect-parser-passes.c.h) in obs_graphics:: effect_parser, and the hidden C ABI shim ep_parse_technique() in ffi::effect_parser that the C ep_parse() calls on the technique token. The hybrid libobs drops the C. The core is ep_parse_pass_command_call(), ep_parse_pass_command(), ep_parse_pass() and ep_parse_technique() 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, cf_go_to_token, cf_go_to_valid_token), each called where the C calls it, with every return path of the C. A technique is returned whole, or None where the C frees it; its passes hold their programs as the marks of the tokens the C copies and the end token. 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 the technique stopped; its errors go to the exported cf_adderror() through the existing private adapter, at the same tokens and levels. A kept technique 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 ep_technique_free() frees it. A pass is ep_pass_init() (all zero, its gs_effect_pass NULL) with its name, NULL when unnamed, and each program entry is the parser's struct cf_token at the mark, copied whole as da_push_back() copies it (its strrefs still point into the lexer's text), or the zeroed end token of cf_token_clear(). The core never changes the token array, so the copies are taken once it returns. The passes' unity group becomes libobs.ported-effect-parser-passes (its own ported-source-sets/effect-parser-passes.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_technique local (t) in each. test_effect_parser_passes compiles ep_parse() and the passes' C into itself, so it keeps checking the C; test_effect_parser_passes_rust runs the same file with ep_parse() compiled in and the techniques, the blocks, 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 no longer compiles the passes' C, which the staticlib now defines. No intentional differences: the C already frees a dropped technique's name on every path. Refs #3598. Co-authored-by: Lain <[email protected]>
Tier 2 layouts and Tier 3 parity for the passes and techniques against
the original C.
The oracle (oracle/effect_parser_passes.c) compiles
effect-parser-passes.c.h unmodified under oracle_* names, on the C
cf-parser.h inlines with the C cf_adderror, cf_pass_pair, 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, give
its token array, 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_passes_parity compares the layouts of struct
ep_pass, ep_technique and cf_token (with enum cf_token_type), then
everything either side leaves in the parser: each technique and pass
(every field, the names, darray counts and capacities), every program
token as the index of the token in its own parser's token array whose
every field it equals, or the zeroed end token, the other collections,
every error (text, file, row, column, level) and where the cursor
stopped. Inputs: 74 fixed texts (the C test's, Tier 1's and techniques
of libobs's own effects), every prefix of each, each from every token,
random token soups from the keyword or from a random token, and
well-formed techniques with random tokens replaced. No intentional
differences.
Mutation check: seven planted mutants (no end token after a call, no
skip after a technique's missing '{', a pass's name dropped, the
compile warning raised as an error, the shim dropping a pass's name,
the shim's end token copied from a real token, and a '}' inside a call
returning PARSE_SUCCESS); six fail four to six of the eight tests. The
seventh is equivalent at the C boundary (ep_parse_pass treats
PARSE_SUCCESS and PARSE_CONTINUE the same), and Tier 1's
pass_command_returns pins the code.
The port_comparison bench runs a two-pass technique through both sides
on the same tokens, freeing what each iteration pushed.
Refs #3598.
A rust/README.md row for libobs/graphics/effect-parser-passes.c.h (obs-graphics::effect_parser: what the shim takes over from the C, how the core walks the C parser's cursor and hands the shim the tokens to copy, what is characterized and kept, no intentional differences, and its tests), and the passes 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 #3598.
rdoupe
force-pushed
the
fix/rust-port-port-the-effect-parser-590
branch
from
November 4, 2026 05:12
29d4e2d to
4f3de92
Compare
rdoupe
marked this pull request as ready for review
November 4, 2026 06:05
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 #3598
What and why
Second step of porting the effect parser's passes and techniques to
obs-graphics(#3598), after the characterization test and the move intolibobs/graphics/effect-parser-passes.c.h(#3599). Same shape as the effect parser's struct and sampler-state blocks (#3561, then #3595).ep_parse()stays C and callsep_parse_technique()on thetechniquetoken; the hybridlibobsnow runs it in Rust.obs-graphics: Test the effect parser passes(RED): Tier 1 inshader::effect_parser_passesagainsttodo!()stubs.techniques,pass_errors,technique_errors,eofandmixedporttest_effect_parser_passes.cone to one (same texts, same groups) at the technique: the technique kept, each pass with every token of its programs (the end token as<end>), the errors it adds (one row up: no guard line) and the token it stops at.edge_techniquesadds what the C test leaves out (a}inside a call, both programs in any order, strings and numbers in a call, passes named three ways,compiletwice, comments, skips cut short), andpass_returns/pass_command_returnspin the codesep_parse_passandep_parse_pass_commandreturn. A proptest walks token soups. The pass command's "compile keyword not necessary" is a warning, so the shader parser'sBlockErrorgets that error and the level each error is added at (LEX_ERRORfor the ones it already adds).obs-graphics: Port the effect parser passes(GREEN): the safe core inobs_graphics::effect_parser(parse_technique,parse_pass,parse_pass_commandand the call's loop, on the shader parser'sTokenstrait and itscf-parser.hsteps, each called where the C calls it), and the hidden shimep_parse_technique()inffi::effect_parser. The core walksep->cfp.cur_tokenin place, soep_parse()goes on from where the technique stopped, and returns a pass's programs as the marks of the tokens the C copies; the shim copies eachstruct cf_tokenwhole from the parser's token array (strrefs into the lexer's text, as the C's are) and writes the end token zeroed, with names and darrays on libobs's allocator asutil/darray.hgrows them, soep_free()frees them. The passes' group becomeslibobs.ported-effect-parser-passes(its ownported-source-sets/effect-parser-passes.json), the shim is hidden byrust-hidden.d/obs-graphics-effect_parser.txt, and a newtest_effect_parser_passes_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_ruststops compiling the passes' C, which the staticlib now defines.obs-graphics: Compare the effect parser passes: Tier 2 layouts (ep_pass,ep_technique,cf_token) and Tier 3 parity inshader::effect_parser_passes_parityagainstoracle/effect_parser_passes.c, the moved file compiled unmodified underoracle_*names. Both sides get the same tokens from the C lexer; everything either side leaves in the parser is compared, each program token as the index of the token in its own parser's array whose every field it equals (or the zeroed end token). Inputs: 74 fixed texts (the C test's, Tier 1's, techniques of libobs's own effects), every prefix of each, each from every token, random token soups, and well-formed techniques with tokens replaced. Mutation check: of seven planted mutants six fail four to six of the eight tests; the seventh (a}inside a call returningPARSE_SUCCESSinstead ofPARSE_CONTINUE) is equivalent at the C boundary, sinceep_parse_passtreats both codes the same, and Tier 1'spass_command_returnspins the code. Aport_comparisonbench runs a two-pass technique through both sides.docs: Record the effect parser passes 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 technique name leak on the two early returns was fixed in the C in #3599, so the C and the port free it on every path. Characterized, not endorsed, and kept: a missing
;before a pass's}ends the call with no end token and drops the technique and what follows it; an entry other than a pass ends the technique with no error; a second command for a program is appended after the first one's end token; end of text after a command's name is reported twice.Ported code: Lain Bailey's (upstream obs-studio), credited on the GREEN commit. No upstream issue.
RED → GREEN
obs-graphics: Test the effect parser passes(5d6324a).soldr cargo test -p obs-graphics --test obs-tests-graphics -- shader::effect_parser_passes::fails 10 of 10 (not yet implemented: ep_parse_technique, andep_parse_pass,ep_parse_pass_commandin the two return-code tests); the blocks' and shader parser's Tier 1 tests still pass with the sharedBlockErrorchange.obs-graphics: Port the effect parser passes(bda71dd). Tier 1 passes 10/10 (57/57 with the blocks' and shader parser's modules), Tier 3 8/8.test_effect_parser_passes,test_effect_parser_blocksand the effect and shader tests pass 16/16 on the C build and onlibobs-c-reference, and 20/20 on the hybridlibobswithtest_effect_parser_passes_rustand the other_rustvariants, none skipped. The C, hybrid and C reference builds export the same 1767 symbols as master,ep_parse_techniquelocal (t) in each.local_gate.py --test-diffpasses 6504/6504 (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 6504 and 912 tests, and Tier 2 719/719 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 4f3de92. The local gate could not stamp this head here (its lint lane stops at the missing Dylint driver), so PR CI runs the full suite.Test cost: new tests: longest 0.06 s (
fixed_texts_cut_short, debug build,OBS_PARITY_CASES=reduced), peak RSS 8 MB over 25 runs of both modules, 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)