Repository navigation
libobs: Move the effect parser compile step to file - #3807
Merged
Merged
Conversation
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.
This was referenced Nov 7, 2026
github-merge-queue
Bot
removed this pull request from the merge queue due to failed status checks
Nov 7, 2026
This was referenced Nov 7, 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.
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 newtest_effect_parser_compile(cmocka) parses fixed effect texts withep_parse()and writes out, compared whole, each shader-create call (its text and location) and what it answered, the result, everygs_effect_paramand annotation (name, section, type, default value, effect),view_projandworld, 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 shaderseffect_free()destroys and the allocations still held. It covers every param type, defaults of each kind, annotations, a lower-caseviewproj,ViewProjandWorlddeclared twice, params with no technique, an empty text and a parse error; two techniques with a named, an unnamed and no pass, aNULLcall, a pass with no calls, uniforms named twice; and aNULLvertex 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, astest_effect_parser_shader_calldoes, withgs_vertexshader_create(),gs_pixelshader_create(),gs_shader_get_param_by_name()andgs_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 ineffect-parser.c.h, callsep_compile(), so its declaration goes into a new internalgraphics/effect-parser-compile.h(a private adapter, not a new public API) in place of the forward declaration, andep_compile()loses itsstatic. The graphics precompiled header includes it. The debug printers stay withep_parse(), which prints withdebug_print_string()too; under_DEBUGand_DEBUG_SHADERS, the only builds that have them, the header declaresdebug_param()anddebug_print_string(), which the compile step also calls, and they lose theirstatic. 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()andep_compile()move, as written, fromlibobs/graphics/effect-parser.c.hinto the newlibobs/graphics/effect-parser-compile.c.h. Everything butep_compile()staysstatic. 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.mdlists it underobs-graphics. The tests that compileeffect-parser.c.hinto themselves (the effect parser's blocks, compile, funcs, params, passes, shader call and writer tests, and the_rustvariants 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 thegs_effect_parameach 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 ownparampointer 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'sparampointer 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->paramssized to the parser's params), and the parse-error case writesuncompiled. The test passes withMALLOC_PERTURB_set to 0, 1, 85, 165 and 255.Odd but real results are marked "characterized, not endorsed" in the test:
ViewProjandWorlddeclared twice keep the last of each asview_projandworld, 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
.effectfiles 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-insensitiveViewProj, the firstWorldkept, 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
test_effect_parser_compilepasses 3/3 on the C build, the hybridlibobsandlibobs-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_rustvariants) on the hybridlibobsand onlibobs-c-reference, none skipped. The C, hybrid and C reference builds export the same 1767 symbols;ep_compileis local (t) in each. A build with_DEBUGand_DEBUG_SHADERSstill compiles both groups (their printers' format warnings are upstream's, unchanged)../lint, the local gate's lint and cross lanes and--test-diff origin/masterpass. 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).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)