Skip to content

libobs: Move the effect parser writer to file - #3766

Merged
rdoupe merged 3 commits into
masterfrom
fix/rust-port-extract-the-effect-par-641
Nov 6, 2026
Merged

rdoupe merged 3 commits into
masterfrom
fix/rust-port-extract-the-effect-par-641

Conversation

@rdoupe

@rdoupe rdoupe commented Nov 6, 2026 •

Copy link
Copy Markdown
Collaborator

Refs #3765

What and why

First step of porting the effect parser's shader writer to obs-graphics: a declaration, a characterization test and a behaviour-neutral extraction, C only. The Rust port of the moved file follows in its own PR on the same issue. Same shape as the function parser (#3627) and the parameters (#3615).

  • libobs: Declare the effect parser shader writer: the compile step, which stays in effect-parser.c.h, calls ep_makeshaderstring() and declares a dstr_array_t, so the typedef and the function's declaration go into a new internal graphics/effect-parser-writer.h (a private adapter, not a new public API; effect-parser.h stays as it is), and ep_makeshaderstring() loses its static. The graphics precompiled header includes it. The name appears nowhere else in the tree.
  • test: Characterize the effect parser writer: a new test_effect_parser_writer (cmocka) parses 15 fixed effect texts with ep_parse(), calls ep_makeshaderstring() on each pass's vertex and pixel call, and pins, written out and compared whole, the shader text, the names pushed into used_params, every written flag afterwards, the parse errors and the allocations still held once everything is freed. It covers const, uniform, plain and array params (one of a single element), params the call names, a param and a function declared twice; samplers with and without states, a sampler named twice, structs whose first member is mapped or not; a chain and a diamond of function calls, a function calling itself, the in, inout, out and uniform keywords; main() with two mapped params, mapped and unmapped params mixed, no params and no return mapping; NULL, a pass with no call, an unknown function, a param in the function's place, spaces inside the call, two passes calling one function; and every flag set before each call. It compiles the original effect parser C into itself and links libobs for the rest, as test_effect_parser_funcs does; each text is parsed behind a first line of {}, whose error keeps ep_parse() from calling ep_compile() (which needs a device). No display and no graphics context, so it runs on every platform.
  • libobs: Move the effect parser writer to file: ep_getfunc(), ep_getparam(), ep_getannotation() (no caller), the seven ep_write_* declaration and dependency writers, ep_write_func_func_deps() and ep_write_func() (which call each other) with the forward declaration, ep_write_main_params(), ep_write_main(), ep_reset_written() and ep_makeshaderstring() move, as written, from libobs/graphics/effect-parser.c.h into the new libobs/graphics/effect-parser-writer.c.h. Everything but ep_makeshaderstring() stays static, so the generic lookup names can't clash. The file has its own live unity group, libobs.effect-parser-writer (graphics module), with a precompiled header of its declarations, effect-parser-funcs.h and string.h, so the port can later move its include into a ported group. docs/rust-port/naming.md lists it under obs-graphics. The tests that compile effect-parser.c.h into themselves (test_effect_parser_blocks, _funcs, _params, _passes, _shader_call, _writer and the _rust variants of blocks, params and passes) compile the moved file beside it.

Odd but real results are marked "characterized, not endorsed" in the test: main() writes two mapped params with nothing between them (float4 main(float4 pos : POSITIONfloat2 uv : TEXCOORD0)), so such a shader doesn't compile; and it drops a param whose struct's first member is unmapped, though the call still passes it. The port fixes the first as its intentional difference (#3765). Also pinned: a const param is declared without its value, a sampler named twice in one function adds a blank line each time, and a uniform the call names that is already marked written isn't pushed into used_params.

Moved code: Lain Bailey's (upstream obs-studio), credited on the move commit. No upstream issue.

Move harness (scratch, not committed): the whole effect parser C, built once from master's files (with ep_makeshaderstring() made reachable, as the first commit does) and once from the moved ones, each with a driver that parses a text behind the same {} guard, writes every pass's vertex and pixel call, and logs the shader text, used_params, every written flag, the error count and the live allocations after ep_free(), then does it all again with every flag set before each call. 200,000 effect texts generated (the stock .effect files and the test's texts, with 1/64 to 29/64 of their tokens dropped, replaced or joined by others, a quarter cut short, and token soups); the harness's filter kept 193,048. Two kinds were left out: 32 whose pass call is cut short by a missing ; or the end of the text, which the writer can't take (the call has no end token) and ep_parse() never writes, since each adds a parse error; and texts that fail in the lexer before the writer runs. Identical logs (8,896,977 lines, 267,704 calls, 253,638 main()s) in 8 builds of each side: GCC and Clang, -O0 and -O2, with and without ASan and UBSan without recovery. All twenty planted mutants of the moved code are caught: seventeen change the harness logs and fail the characterization test; the other three (an array of one element written without [1], and ep_getparam() or ep_getfunc() returning the last of two same-named declarations instead of the first) fail the test only.

RED → GREEN

  • RED commit: N/A. The extraction has no RED: the characterization test passes on master's code and after the move, unchanged, and no bug is fixed in this PR (the main() comma is fixed in the port).
  • GREEN: test_effect_parser_writer passes 6/6 on the C build, the hybrid libobs and libobs-c-reference, before and after the move. It and the other effect and shader tests (test_effect_*, test_shader_*) pass 20/20 on the C build and 25/25 (with the five _rust variants) on the hybrid libobs and on libobs-c-reference, none skipped. The C, hybrid and C reference builds export the same 1767 symbols as master; ep_makeshaderstring is local (t) in each. ./lint, the local gate's lint and cross lanes, --test-diff origin/master and the Windows clippy on all targets pass, and ./unittest passed (6700 and 912 Rust tests; Tier 2 742/742 against libobs-c-reference and 742/742 against the hybrid libobs, with the PulseAudio and v4l2 vivid device tests skipped, 3 on each, as the container has no such devices). The head is stamped by the local gate (lint, Rust tests, cross and Tier 2 Linux). Runs were on 8c7f2ae; the move harness ran on the same three commits before their rebase onto the output stop fix (libobs: End the stop of an output that never got a packet #3764), which changed none of the C it compiles.
  • Real app (UI, protocol output or logging changes): N/A, no UI, protocol or logging change.

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) (declaration, characterization, then the behaviour-neutral move; no RED, as nothing changes)
  • 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) (not applicable: no Rust in this PR)

rdoupe and others added 3 commits November 6, 2026 12:17
Behaviour-neutral step before the effect parser's shader writer moves
to its own file. The compile step, which stays in effect-parser.c,
calls ep_makeshaderstring() and declares a dstr_array_t, so the
typedef and the function's declaration move into a new internal
graphics/effect-parser-writer.h (a private adapter, not a new public
API), and ep_makeshaderstring() loses its static. The graphics
precompiled header includes it. The writer's tests call it through
the header too.

ep_makeshaderstring appears nowhere else in the tree. It stays local
(t) in the C, hybrid and C reference builds, which export the same
1767 symbols as master.

Refs #3765.
The effect parser's shader writer has no C test of its own beyond one
case (a call to an unknown function, test_effect_parser_shader_call):
the effect tests load whole effects through a device.
test_effect_parser_writer parses fixed effect texts with ep_parse(),
then calls ep_makeshaderstring() on each pass's vertex and pixel call
and pins, written out and compared whole, the shader text, the names
pushed into used_params and every written flag afterwards, then the
parse errors and the allocations still held once everything is freed.

15 texts in six groups: const, uniform, plain and array params (one
of a single element), params the call names (written before the
function, once each), and a param and a function declared twice (the
first of each is the one written);
samplers with and without states, a sampler named twice, structs whose
first member is mapped or not; a chain and a diamond of function
calls, a function calling itself, and the in, inout, out and uniform
keywords; main() with two mapped params, mapped and unmapped params
mixed, no params, and no return mapping; NULL, a pass with no call, an
unknown function, a param in the function's place, spaces inside the
call, and two passes calling one function; and every flag set before
each call. Odd but real results are marked "characterized, not
endorsed": main() writes two mapped params with nothing between them
(float4 pos : POSITIONfloat2 uv : TEXCOORD0), so such a shader doesn't
compile, and it drops a param whose struct's first member is unmapped
while the call still passes it.

ep_parse() and ep_makeshaderstring() are hidden in libobs, so the test
compiles the original effect parser C into itself and links libobs for
the rest, as test_effect_parser_funcs does, and calls the writer
through graphics/effect-parser-writer.h. Every text is parsed behind a
first line of "{}", whose error keeps ep_parse() from calling
ep_compile(), which needs a device. No display and no graphics
context: it runs on every platform. It passes, none skipped, against
the C, hybrid and C reference libobs.

Refs #3765.
Behaviour-neutral extraction before the Rust port. The effect parser's
shader writer and the lookups only it uses move, as written, from
effect-parser.c into the new libobs/graphics/effect-parser-writer.c.h:

- ep_getfunc(), ep_getparam() and ep_getannotation() (which has no
  caller);
- ep_write_param(), ep_write_func_param_deps(), ep_write_sampler(),
  ep_write_func_sampler_deps(), ep_write_var(), ep_write_struct() and
  ep_write_func_struct_deps();
- the forward declaration of ep_write_func(), then
  ep_write_func_func_deps() and ep_write_func(), which call each
  other;
- ep_write_main_params(), ep_write_main(), ep_reset_written() and
  ep_makeshaderstring().

The compile step, which stays, calls ep_makeshaderstring() through
graphics/effect-parser-writer.h, as it has since the function lost its
static. Every other moved function stays static, so the generic
lookup names can't clash. The writer calls ep_getstruct(),
ep_getsampler(), ep_getfunc_strref() and ep_getparam_strref() through
graphics/effect-parser-funcs.h. Nothing else changes: the compile step
calls the writer on the same tokens, in the same places.

The new file has its own live group, libobs.effect-parser-writer (in
the graphics module), with a precompiled header of its declarations
and string.h, so the C oracle can compile it alone and the port can
move its include into a ported group. No Rust: the hybrid libobs
compiles the C too. The C, hybrid and C reference builds export the
same 1767 symbols as master, ep_makeshaderstring local (t) in each.
The tests that compile the effect parser C into themselves compile the
new file beside it. docs/rust-port/naming.md lists it under
obs-graphics.

Refs #3765.

Co-authored-by: Lain <[email protected]>
Local-Gate: v1 tree=dfd4c6d2e95d3cd8a413d28f0315573c2081986f secs=2214 lanes=lint:run,rust-test:run,cross:run,tier2-linux:run,macos-native:n/a,windows-native:n/a
Ci-Attestation: {"at":1793990631,"gate":"rust/all/fmt","host":"linux-x86_64","key":"de29e587560a24933b9da5cbec95bf9841dfc6890922e71243c1e8afca67cf0c","lane":"lint","parents":["bc11e8ebc82788190a4981e0c41af49e7954d8b1"],"secs":48,"stamp":"8fb121e807e4931b05e71ed6c17cd720","tree":"dfd4c6d2e95d3cd8a413d28f0315573c2081986f","v":1,"via":"run"}
Ci-Attestation: {"at":1793990631,"gate":"rust/x86_64-unknown-linux-gnu/clippy","host":"linux-x86_64","key":"de29e587560a24933b9da5cbec95bf9841dfc6890922e71243c1e8afca67cf0c","lane":"lint","parents":["bc11e8ebc82788190a4981e0c41af49e7954d8b1"],"secs":48,"stamp":"45411f0a7c589a9157283af6c2110368","tree":"dfd4c6d2e95d3cd8a413d28f0315573c2081986f","v":1,"via":"run"}
Ci-Attestation: {"at":1793990631,"gate":"rust/x86_64-unknown-linux-gnu/test","host":"linux-x86_64","key":"13fef02bc0c134a1b026aa6586d2303ddea3b0fa846ffd6859f97f5ec9e8fd73","lane":"rust-test","parents":["bc11e8ebc82788190a4981e0c41af49e7954d8b1"],"secs":110,"stamp":"70f953daec17bb858e744104faed2551","tree":"dfd4c6d2e95d3cd8a413d28f0315573c2081986f","v":1,"via":"run"}
Ci-Attestation: {"at":1793990631,"gate":"rust/x86_64-pc-windows-msvc/clippy","host":"linux-x86_64","key":"5ae605cfb05d94c257cab2ae0a73717714c4fbd29b631a5439c7126c4d9df985","lane":"cross","parents":["bc11e8ebc82788190a4981e0c41af49e7954d8b1"],"secs":71,"stamp":"51af21d7aaaf33762a15bcb45be5e5f7","tree":"dfd4c6d2e95d3cd8a413d28f0315573c2081986f","v":1,"via":"run"}
Ci-Attestation: {"at":1793990631,"gate":"rust/x86_64-pc-windows-msvc/dylint","host":"linux-x86_64","key":"5ae605cfb05d94c257cab2ae0a73717714c4fbd29b631a5439c7126c4d9df985","lane":"cross","parents":["bc11e8ebc82788190a4981e0c41af49e7954d8b1"],"secs":71,"stamp":"6d70ae569169610a266f5d9732a48f2e","tree":"dfd4c6d2e95d3cd8a413d28f0315573c2081986f","v":1,"via":"run"}
Ci-Attestation: {"at":1793990631,"gate":"rust/aarch64-apple-darwin/clippy","host":"linux-x86_64","key":"5ae605cfb05d94c257cab2ae0a73717714c4fbd29b631a5439c7126c4d9df985","lane":"cross","parents":["bc11e8ebc82788190a4981e0c41af49e7954d8b1"],"secs":71,"stamp":"7154e0ce46cf74ff79bf98588b6fac4e","tree":"dfd4c6d2e95d3cd8a413d28f0315573c2081986f","v":1,"via":"run"}
Ci-Attestation: {"at":1793990631,"gate":"rust/aarch64-apple-darwin/dylint","host":"linux-x86_64","key":"5ae605cfb05d94c257cab2ae0a73717714c4fbd29b631a5439c7126c4d9df985","lane":"cross","parents":["bc11e8ebc82788190a4981e0c41af49e7954d8b1"],"secs":71,"stamp":"7c544b0385a8cbfb6a2b0352246cc543","tree":"dfd4c6d2e95d3cd8a413d28f0315573c2081986f","v":1,"via":"run"}
Ci-Attestation: {"at":1793990631,"gate":"cpp/linux-x64/tier2","host":"linux-x86_64","key":"a13e489d62b1bc3d743c43e9d0de8e732fe27f22334ff1730d10a2bca0b6d1dd","lane":"tier2-linux","parents":["bc11e8ebc82788190a4981e0c41af49e7954d8b1"],"secs":2213,"stamp":"92939986462ccdb565e0aab93d6d6fe3","tree":"dfd4c6d2e95d3cd8a413d28f0315573c2081986f","v":1,"via":"run"}
@rdoupe
rdoupe force-pushed the fix/rust-port-extract-the-effect-par-641 branch from 793cbb4 to 8c7f2ae Compare November 6, 2026 18:44
@obs-rust-project-manager obs-rust-project-manager Bot moved this to In progress in obs-rust Multiview Nov 6, 2026
@rdoupe
rdoupe marked this pull request as ready for review November 6, 2026 19:01
@rdoupe
rdoupe requested a review from zackees as a code owner November 6, 2026 19:01
@rdoupe
rdoupe added this pull request to the merge queue Nov 6, 2026
@rdoupe

rdoupe commented Nov 6, 2026

Copy link
Copy Markdown
Collaborator Author

Handed off to the coordinator

Merged via the queue into master with commit 99b50a6 Nov 6, 2026
40 checks passed
@rdoupe
rdoupe deleted the fix/rust-port-extract-the-effect-par-641 branch November 6, 2026 19:11
@obs-rust-project-manager obs-rust-project-manager Bot moved this from In progress 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.

1 participant