Repository navigation
libobs: Move the effect parser writer to file - #3766
Merged
Merged
Conversation
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
force-pushed
the
fix/rust-port-extract-the-effect-par-641
branch
from
November 6, 2026 18:44
793cbb4 to
8c7f2ae
Compare
rdoupe
marked this pull request as ready for review
November 6, 2026 19:01
Collaborator
Author
|
Handed off to the coordinator |
This was referenced Nov 6, 2026
6 of 7 tasks
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 #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 ineffect-parser.c.h, callsep_makeshaderstring()and declares adstr_array_t, so the typedef and the function's declaration go into a new internalgraphics/effect-parser-writer.h(a private adapter, not a new public API;effect-parser.hstays as it is), andep_makeshaderstring()loses itsstatic. The graphics precompiled header includes it. The name appears nowhere else in the tree.test: Characterize the effect parser writer: a newtest_effect_parser_writer(cmocka) parses 15 fixed effect texts withep_parse(), callsep_makeshaderstring()on each pass's vertex and pixel call, and pins, written out and compared whole, the shader text, the names pushed intoused_params, everywrittenflag afterwards, the parse errors and the allocations still held once everything is freed. It coversconst,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, thein,inout,outanduniformkeywords;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, astest_effect_parser_funcsdoes; each text is parsed behind a first line of{}, whose error keepsep_parse()from callingep_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 sevenep_write_*declaration and dependency writers,ep_write_func_func_deps()andep_write_func()(which call each other) with the forward declaration,ep_write_main_params(),ep_write_main(),ep_reset_written()andep_makeshaderstring()move, as written, fromlibobs/graphics/effect-parser.c.hinto the newlibobs/graphics/effect-parser-writer.c.h. Everything butep_makeshaderstring()staysstatic, 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.handstring.h, 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 (test_effect_parser_blocks,_funcs,_params,_passes,_shader_call,_writerand the_rustvariants 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: aconstparam 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 intoused_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, everywrittenflag, the error count and the live allocations afterep_free(), then does it all again with every flag set before each call. 200,000 effect texts generated (the stock.effectfiles 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) andep_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,638main()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], andep_getparam()orep_getfunc()returning the last of two same-named declarations instead of the first) fail the test only.RED → GREEN
main()comma is fixed in the port).test_effect_parser_writerpasses 6/6 on the C build, the hybridlibobsandlibobs-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_rustvariants) on the hybridlibobsand onlibobs-c-reference, none skipped. The C, hybrid and C reference builds export the same 1767 symbols as master;ep_makeshaderstringis local (t) in each../lint, the local gate's lint and cross lanes,--test-diff origin/masterand the Windows clippy on all targets pass, and./unittestpassed (6700 and 912 Rust tests; Tier 2 742/742 againstlibobs-c-referenceand 742/742 against the hybridlibobs, 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.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)