Skip to content

libobs: Move the effect parser compile step to file - #3807

Merged
rdoupe merged 5 commits into
masterfrom
fix/rust-port-extract-the-effect-par-650
Nov 7, 2026
Merged

rdoupe merged 5 commits into
masterfrom
fix/rust-port-extract-the-effect-par-650

Conversation

@rdoupe

@rdoupe rdoupe commented Nov 7, 2026 •

Copy link
Copy Markdown
Collaborator

Refs #3792

What and why

First step of porting the effect parser's compile step to obs-graphics: a characterization test, a declaration 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 shader writer (#3766) and the function parser (#3627).

  • test: Characterize the effect parser compile step: a new test_effect_parser_compile (cmocka) parses fixed effect texts with ep_parse() and writes out, compared whole, each shader-create call (its text and location) and what it answered, the result, every gs_effect_param and annotation (name, section, type, default value, effect), view_proj and world, every technique and pass (name, section, shaders, and the effect and shader param of each name the writer used), the error list, every logged line, the shaders effect_free() destroys and the allocations still held. It covers every param type, defaults of each kind, annotations, a lower-case viewproj, ViewProj and World declared twice, params with no technique, an empty text and a parse error; two techniques with a named, an unnamed and no pass, a NULL call, a pass with no calls, uniforms named twice; and a NULL vertex or pixel shader, an error text with and without a shader, an empty error text, a shader lacking its first or a middle param, and every shader failing. It compiles the original effect parser C into itself and links libobs for the rest, as test_effect_parser_shader_call does, with gs_vertexshader_create(), gs_pixelshader_create(), gs_shader_get_param_by_name() and gs_shader_destroy() renamed to stand-ins that hand back fake shaders and shader params. No display and no graphics context, so it runs on every platform.
  • libobs: Declare the effect parser compile step: ep_parse(), which stays in effect-parser.c.h, calls ep_compile(), so its declaration goes into a new internal graphics/effect-parser-compile.h (a private adapter, not a new public API) in place of the forward declaration, and ep_compile() loses its static. The graphics precompiled header includes it. The debug printers stay with ep_parse(), which prints with debug_print_string() too; under _DEBUG and _DEBUG_SHADERS, the only builds that have them, the header declares debug_param() and debug_print_string(), which the compile step also calls, and they lose their static. None of the three names appears anywhere else in the tree.
  • libobs: Move the effect parser compile step to file: ep_compile_annotations(), ep_compile_param_annotations(), ep_compile_param(), ep_compile_pass_shaderparams(), ep_compile_pass_shader(), ep_compile_pass(), ep_compile_technique() and ep_compile() move, as written, from libobs/graphics/effect-parser.c.h into the new libobs/graphics/effect-parser-compile.c.h. Everything but ep_compile() stays static. The file has its own live unity group, libobs.effect-parser-compile (graphics module), with a precompiled header of what it uses, 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 (the effect parser's blocks, compile, funcs, params, passes, shader call and writer tests, and the _rust variants of blocks, params, passes and shader call) compile the moved file beside it.
  • test: Pin what the compile step leaves in parser: each case also writes out the parser's params after the compile, how many default bytes are left in each param and annotation (none, as the compile step moves them) and the gs_effect_param each param points at, and a new text has a single annotation. Without this, two planted changes to the moved code got through the test (below). An annotation's own param pointer isn't written out: ep_param_init() never sets it, and the compile step sets it only for params.
  • test: Skip the param link when nothing compiled: ep_param_init() never sets a param's param pointer either, only the compile step does, so after a parse error (no compile) the test read it uninitialized. It is now read only when the compile step ran (effect->params sized to the parser's params), and the parse-error case writes uncompiled. The test passes with MALLOC_PERTURB_ set to 0, 1, 85, 165 and 255.

Odd but real results are marked "characterized, not endorsed" in the test: ViewProj and World declared twice keep the last of each as view_proj and world, while the shader-param lookups use the first; and a shader created together with an error text is kept and the result stays true, with the error in the parser's list.

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

Move harness (scratch, not committed): the effect parser C built once from master's files and once from the moved ones, each with the same driver and the test's graphics stand-ins, logging everything the test writes out. 2,000 effect texts generated (the stock .effect files with their includes inlined, random effects with params, annotations, samplers, functions and techniques, and both with 1/256 to 1/8 of their tokens dropped, replaced or joined by others, a tenth cut short); each runs with no shader failing and with two random sets of failing creates, error texts, empty error texts and missing shader params. The harness's filter kept 1,444: it leaves out texts that fail in the preprocessor or the parser before the compile step runs, each run in its own process with a time and memory limit. Identical logs (4,332 runs, 2,015 compiled without error, 11,628 shader-create calls, 1,965 shader errors, 31 missing shader params) in 8 builds of each side: GCC and Clang, -O0 and -O2, with and without ASan and UBSan without recovery, which reported nothing. All 14 planted mutants of the moved code (a wrong section, copying instead of moving annotation defaults, a case-insensitive ViewProj, the first World kept, a missing first shader param ignored, empty error texts added, the wrong location, a technique stopping at its first failed pass, the wrong log level, the last param or single annotations skipped, the technique's effect not set, the error text leaked, a wrong pass section) change the harness logs and fail the characterization test.

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.
  • GREEN: test_effect_parser_compile passes 3/3 on the C build, the hybrid libobs and libobs-c-reference. It and the other effect and shader tests (test_effect_*, test_shader_*) pass 21/21 on the C build and 27/27 (with the six _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; ep_compile is local (t) in each. A build with _DEBUG and _DEBUG_SHADERS still compiles both groups (their printers' format warnings are upstream's, unchanged). ./lint, the local gate's lint and cross lanes and --test-diff origin/master pass. Runs were on 836db4e (the move harness on the same commits before their rebase onto the signal emission speed-up (perf: bring signal emission within C comparison target #3657), 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) (characterization, declaration, 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 4 commits November 6, 2026 22:50
No C test pins what the effect parser's compile step (ep_compile() and
the ep_compile_* steps under it) puts in a gs_effect: the effect tests
load whole effects through a device. test_effect_parser_compile parses
fixed effect texts with ep_parse() and writes out, compared whole, each
shader-create call (its text and location) and what it answered, the
result, every gs_effect_param and annotation (name, section, type,
default value, effect), view_proj and world, every technique and pass
(name, section, shaders, and the effect and shader param of each name
the writer used), the error list, every logged line, the shaders
effect_free() destroys and the allocations still held.

16 texts in three groups: every param type, defaults of each kind,
annotations, a lower-case viewproj, ViewProj and World declared twice
(the last of each is kept), params with no technique, an empty text and
a parse error (nothing compiled); two techniques with a named, an
unnamed and no pass, a NULL call, a pass with no calls, and uniforms
named twice; and a NULL vertex or pixel shader, an error text with and
without a shader, an empty error text, a shader lacking its first or a
middle param, and every shader failing. A shader created with an error
text is kept and the result stays 1 ("characterized, not endorsed").

ep_parse() and ep_compile() 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_shader_call does, with the shader-create calls,
gs_shader_get_param_by_name() and gs_shader_destroy() renamed to
stand-ins that hand back fake shaders and shader params. No display and
no graphics context: it runs on every platform.

Refs #3792.
Behaviour-neutral step before the effect parser's compile step moves
to its own file. ep_parse(), which stays in effect-parser.c, calls
ep_compile(), so its declaration moves into a new internal
graphics/effect-parser-compile.h (a private adapter, not a new public
API) in place of the forward declaration, and ep_compile() loses its
static. The graphics precompiled header includes it.

The debug printers stay in effect-parser.c with ep_parse(), which
prints with debug_print_string() too. The compile step prints with it
and with debug_param(), so under _DEBUG and _DEBUG_SHADERS, the only
builds that have them, the header declares those two and they lose
their static.

None of the three names appears anywhere else in the tree. ep_compile
stays local (t) in libobs, which exports the same 1767 symbols as
master.

Refs #3792.
ep_compile_annotations(), ep_compile_param_annotations(),
ep_compile_param(), ep_compile_pass_shaderparams(),
ep_compile_pass_shader(), ep_compile_pass(), ep_compile_technique()
and ep_compile() move, as written, from graphics/effect-parser.c into
the new graphics/effect-parser-compile.c, so the compile step can be
ported on its own. Everything but ep_compile() stays static.

The file has its own live unity group, libobs.effect-parser-compile
(graphics module), with a precompiled header of its declarations, the
shader writer's, the param types', effect.h, util/base.h, assert.h,
limits.h and string.h, so the port can later move its include into a
ported group. The debug printers stay in effect-parser.c with
ep_parse(); a _DEBUG _DEBUG_SHADERS build still compiles both groups.
naming.md lists the file under obs-graphics. The tests that compile
effect-parser.c into themselves (the effect parser's blocks, compile,
funcs, params, passes, shader call and writer tests, and the _rust
variants of blocks, params, passes and shader call) compile the moved
file beside it.

ep_compile stays local (t) in the C, hybrid and C reference builds,
which export the same 1767 symbols.

Refs #3792.

Co-authored-by: Lain <[email protected]>
test_effect_parser_compile wrote out only the effect the compile step
fills. Two changes to the moved code got through it: copying the
parser's default values instead of moving them out, and compiling a
param's annotations only when it has more than one. Each case now also
writes out the parser's params after the compile: how many default
bytes are left in each param and annotation (none, as they are moved)
and the gs_effect_param each param points at. A new text has a single
annotation with and without a value.

An annotation's own param pointer is not written out: ep_param_init()
never sets it, and the compile step sets it only for params.

Refs #3792.

Local-Gate: v1 tree=00b1cc5773b01ec832c964949f89e60e3e428c77 secs=2467 lanes=lint:run,rust-test:run,cross:run,tier2-linux:run,macos-native:n/a,windows-native:n/a
Ci-Attestation: {"at":1794026681,"gate":"rust/all/fmt","host":"linux-x86_64","key":"614a042e9b76c3e1b03350417d09cfd6b7d96744a3c2b4e3776b825175c94b01","lane":"lint","parents":["7b912329dc280eec335118d6fef7f7d510c9bec0"],"secs":73,"stamp":"c3f9ebaf38155247f27895af95223b2d","tree":"00b1cc5773b01ec832c964949f89e60e3e428c77","v":1,"via":"run"}
Ci-Attestation: {"at":1794026681,"gate":"rust/x86_64-unknown-linux-gnu/clippy","host":"linux-x86_64","key":"614a042e9b76c3e1b03350417d09cfd6b7d96744a3c2b4e3776b825175c94b01","lane":"lint","parents":["7b912329dc280eec335118d6fef7f7d510c9bec0"],"secs":73,"stamp":"ec86f7ccfc89ce57a19538df77c0239a","tree":"00b1cc5773b01ec832c964949f89e60e3e428c77","v":1,"via":"run"}
Ci-Attestation: {"at":1794026681,"gate":"rust/x86_64-unknown-linux-gnu/test","host":"linux-x86_64","key":"1ce63a98624dbdbb83d1c18f64b3509e935856aeaa29d79c60e8fa99b0df4966","lane":"rust-test","parents":["7b912329dc280eec335118d6fef7f7d510c9bec0"],"secs":256,"stamp":"820ff29bd9ddc51b89af9b1479b49c9a","tree":"00b1cc5773b01ec832c964949f89e60e3e428c77","v":1,"via":"run"}
Ci-Attestation: {"at":1794026681,"gate":"rust/x86_64-pc-windows-msvc/clippy","host":"linux-x86_64","key":"384f66429fa04a8f4e1fb6eb3b8f2d7a9822696ecc9da2b4d4f98e639df544f8","lane":"cross","parents":["7b912329dc280eec335118d6fef7f7d510c9bec0"],"secs":48,"stamp":"e899e655d98a454863e4230413b80bf4","tree":"00b1cc5773b01ec832c964949f89e60e3e428c77","v":1,"via":"run"}
Ci-Attestation: {"at":1794026681,"gate":"rust/x86_64-pc-windows-msvc/dylint","host":"linux-x86_64","key":"384f66429fa04a8f4e1fb6eb3b8f2d7a9822696ecc9da2b4d4f98e639df544f8","lane":"cross","parents":["7b912329dc280eec335118d6fef7f7d510c9bec0"],"secs":48,"stamp":"77ac59dc636771f7932fb4d4137023c4","tree":"00b1cc5773b01ec832c964949f89e60e3e428c77","v":1,"via":"run"}
Ci-Attestation: {"at":1794026681,"gate":"rust/aarch64-apple-darwin/clippy","host":"linux-x86_64","key":"384f66429fa04a8f4e1fb6eb3b8f2d7a9822696ecc9da2b4d4f98e639df544f8","lane":"cross","parents":["7b912329dc280eec335118d6fef7f7d510c9bec0"],"secs":48,"stamp":"e72de836cac63afcddaae8c1cda5f7ad","tree":"00b1cc5773b01ec832c964949f89e60e3e428c77","v":1,"via":"run"}
Ci-Attestation: {"at":1794026681,"gate":"rust/aarch64-apple-darwin/dylint","host":"linux-x86_64","key":"384f66429fa04a8f4e1fb6eb3b8f2d7a9822696ecc9da2b4d4f98e639df544f8","lane":"cross","parents":["7b912329dc280eec335118d6fef7f7d510c9bec0"],"secs":48,"stamp":"86602e5a2018d985cc74f0dd9861d027","tree":"00b1cc5773b01ec832c964949f89e60e3e428c77","v":1,"via":"run"}
Ci-Attestation: {"at":1794026681,"gate":"cpp/linux-x64/tier2","host":"linux-x86_64","key":"087a0785b43db7c0334983f64985b95726e5ef97968d63bc0b7735926bb8d327","lane":"tier2-linux","parents":["7b912329dc280eec335118d6fef7f7d510c9bec0"],"secs":2467,"stamp":"ed72b7b2f6ece0b2bee09974ff827b45","tree":"00b1cc5773b01ec832c964949f89e60e3e428c77","v":1,"via":"run"}
dump_parser() wrote out each parser param's gs_effect_param pointer,
which ep_param_init() never sets: only the compile step does. After a
parse error ep_compile() doesn't run, so the parse-error case read an
uninitialized pointer, and its expected "(foreign)" depended on what
was there. The pointer is now read only when the compile step ran,
which sizes effect->params to the parser's params; otherwise the case
writes "uncompiled".

Refs #3792.
@rdoupe
rdoupe added this pull request to the merge queue Nov 7, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Nov 7, 2026
@rdoupe
rdoupe added this pull request to the merge queue Nov 7, 2026
Merged via the queue into master with commit 53d5593 Nov 7, 2026
45 checks passed
@rdoupe
rdoupe deleted the fix/rust-port-extract-the-effect-par-650 branch November 7, 2026 07:07
@obs-rust-project-manager obs-rust-project-manager Bot moved this from In review to Done in obs-rust Multiview Nov 7, 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