Skip to content

obs-graphics: Port the effect parser passes - #3609

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

rdoupe merged 4 commits into
masterfrom
fix/rust-port-port-the-effect-parser-590

Conversation

@rdoupe

@rdoupe rdoupe commented Nov 4, 2026 •

Copy link
Copy Markdown
Collaborator

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 into libobs/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 calls ep_parse_technique() on the technique token; the hybrid libobs now runs it in Rust.

  • obs-graphics: Test the effect parser passes (RED): Tier 1 in shader::effect_parser_passes against todo!() stubs. techniques, pass_errors, technique_errors, eof and mixed port test_effect_parser_passes.c one 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_techniques adds 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, compile twice, comments, skips cut short), and pass_returns / pass_command_returns pin the codes ep_parse_pass and ep_parse_pass_command return. A proptest walks token soups. 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 (LEX_ERROR for the ones it already adds).
  • obs-graphics: Port the effect parser passes (GREEN): the safe core in obs_graphics::effect_parser (parse_technique, parse_pass, parse_pass_command and the call's loop, on the shader parser's Tokens trait and its cf-parser.h steps, each called where the C calls it), and the hidden shim ep_parse_technique() in ffi::effect_parser. The core walks ep->cfp.cur_token in place, so ep_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 each struct cf_token whole 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 as util/darray.h grows them, so ep_free() frees them. The passes' group becomes libobs.ported-effect-parser-passes (its own ported-source-sets/effect-parser-passes.json), the shim is hidden by rust-hidden.d/obs-graphics-effect_parser.txt, and a new test_effect_parser_passes_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 stops 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 in shader::effect_parser_passes_parity against oracle/effect_parser_passes.c, the moved file compiled unmodified under oracle_* 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 returning PARSE_SUCCESS instead of PARSE_CONTINUE) is equivalent at the C boundary, since ep_parse_pass treats both codes the same, and Tier 1's pass_command_returns pins the code. A port_comparison bench runs a two-pass technique through both sides.
  • docs: Record the effect parser passes 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 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

  • RED commit: 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, and ep_parse_pass, ep_parse_pass_command in the two return-code tests); the blocks' and shader parser's Tier 1 tests still pass with the shared BlockError change.
  • GREEN: 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_blocks and the effect and shader tests pass 16/16 on the C build and on libobs-c-reference, and 20/20 on the hybrid libobs with test_effect_parser_passes_rust and the other _rust variants, none skipped. The C, hybrid and C reference builds export the same 1767 symbols as master, ep_parse_technique local (t) in each. local_gate.py --test-diff passes 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, 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 6504 and 912 tests, and Tier 2 719/719 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 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.
  • Real app (UI, protocol output or logging changes): N/A, no UI, protocol or logging change.

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

  • 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: the parity header and the README row say so)

rdoupe and others added 4 commits November 3, 2026 22:52
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
rdoupe force-pushed the fix/rust-port-port-the-effect-parser-590 branch from 29d4e2d to 4f3de92 Compare November 4, 2026 05:12
@rdoupe
rdoupe marked this pull request as ready for review November 4, 2026 06:05
@rdoupe
rdoupe requested a review from zackees as a code owner November 4, 2026 06:05
@rdoupe
rdoupe added this pull request to the merge queue Nov 4, 2026
Merged via the queue into master with commit f8bc87e Nov 4, 2026
44 checks passed
@rdoupe
rdoupe deleted the fix/rust-port-port-the-effect-parser-590 branch November 4, 2026 06:23
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 passes and techniques

1 participant