Repository navigation
obs-graphics: Port the effect parser compile step - #3843
Merged
Merged
Conversation
This was referenced Nov 7, 2026
rdoupe
force-pushed
the
fix/rust-port-port-the-effect-parser-657
branch
from
November 7, 2026 10:30
8b75c97 to
aeda929
Compare
rdoupe
marked this pull request as ready for review
November 7, 2026 11:00
Collaborator
Author
|
Handed off to the coordinator |
github-merge-queue
Bot
removed this pull request from the merge queue due to no response for status checks
Nov 7, 2026
github-merge-queue
Bot
removed this pull request from the merge queue due to failed status checks
Nov 8, 2026
4 of 5 tasks
Collaborator
Author
|
Handed off to the coordinator |
github-merge-queue
Bot
removed this pull request from the merge queue due to failed status checks
Nov 8, 2026
Tier 1 for the port of the effect parser's compile step (libobs/graphics/effect-parser-compile.c.h) to obs_graphics:: effect_parser::compile, against todo!() stubs. The core runs over a CompileModel: the parser, the effect it fills and the graphics device, one call where the C makes each step (the da_resize of the effect's arrays, each param's, technique's and pass's fill, the writer's text for a call, the shader create, the error text, the effect and shader param lookups, the frees and the log lines), so a shim can write the C structs in place. params, techniques and shaders port test_effect_parser_compile one to one: the same cases and expected dump, from the parser ep_parse() hands the compile step for each of its texts (the params, annotations and defaults, the techniques and passes, and the text and used params the writer builds for each call), over the C test's graphics stand-ins written in Rust. The two texts that never reach the compile step and the destroyed and leaked lines are ep_parse()'s and effect_free()'s. The edge tests add the shader location's NULL file and technique name and its 32-bit pass index, the order of the calls for a pass whose shaders both fail, a used name the effect lacks, a shader lacking a middle param, the ViewProj and World checks by name only, techniques with no pass, and each step on its own. Refs #3792.
The safe core of the effect parser's compile step (libobs/graphics/effect-parser-compile.c.h) in obs_graphics:: effect_parser::compile: ep_compile() and its helpers, one to one, each step a CompileModel call in the C's order and under its condition. ep_compile sizes the effect's params and techniques to the parser's and compiles each. A param links the parser's param to it, takes a copy of its name, its section, its effect, the parser's default value (moved) and its type (obs_effect_param_type, the ported param types), becomes view_proj or world when named exactly ViewProj or World, then its annotations the same way. A technique and each of its passes take their name and section; each pass compiles its vertex and then its pixel shader and logs the one that fails. A shader gets the location the C prints (a NULL file empty, a NULL technique name "(null)", the pass index cut to 32 bits), the writer's text for the call, and the create call; a non-empty error text goes into the parser's list, and a created shader pairs each used param with the effect's and the shader's param, stopping at the first the shader lacks. Nothing the effect holds is freed. Nothing calls the core yet; the C ep_compile() still compiles every effect. Refs #3792. Co-authored-by: Lain <[email protected]>
The hidden C ABI shim ep_compile() in ffi::effect_parser, which ep_parse() calls once the text parsed with no error, over the safe compile step. The hybrid libobs drops the C. The shim fills ep->effect in place as the C does: the effect's params, each param's annotations, the techniques, each technique's passes and each pass's shader params grown as darray_resize grows them (new items zero), each name a bstrdup copy and each default value moved out of the parser as da_move moves it, all on libobs's allocator through the private adapters; each parser param points at its effect param, and view_proj and world point into the effect's params. The shader text is the writer shim's, the effect param lookup the Rust gs_effect_get_param_by_name. The shader creates, the shader param lookup and the compile step's three LOG_ERROR lines (with the C's literal formats) go through new private adapters in obs-graphics-adapter.c.h, and a shader's error text goes to cf_adderror() and is freed. A null parser or effect returns false. The compile step's unity group becomes libobs.ported-effect-parser-compile (its own ported-source-sets/effect-parser-compile.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, with ep_compile local (t) in each. test_effect_parser_compile keeps checking the C it compiles into itself. test_effect_parser_compile_rust runs the same file and expectations with ep_parse() and the function parser compiled in and the compile step from the production staticlib, its shaders and shader params from the test's stand-ins behind the adapters, on the hybrid build only. The blocks, params, passes and shader call _rust tests no longer compile the compile step's C, which the staticlib now defines; the shader call recorders now sit behind the adapters. The new target is registered in test-graph.json like the other parser _rust tests, with its independent expectation in obs-build's private-parser family (now five targets) and its three cases in the private runtime's table. Under cargo test, oracle/effect_parser_compile_device.c is the graphics stand-in the adapters reach. Refs #3792.
Tier 2 layouts and Tier 3 parity for the compile step against the original C. The oracle (oracle/effect_parser_compile.c) compiles effect-parser-compile.c.h unmodified under oracle_* names, on the C writer, param types, effect param lookup, cf_adderror and dstr of the other oracles, so the whole compile step is the original C. Its graphics calls and the shim's adapters reach the same recording stand-in (oracle/effect_parser_compile_device.c), and blog() the stand-in's log handler, which records only the test thread. shader::effect_parser_compile_parity compares the layouts of struct pass_shaderparam, ep_param and effect_parser, then compiles the same parser on each side: lexed by the C from a short text with a file name of the case's (NULL and empty included), so cf_adderror() points at the end token as after ep_parse(), with random params (types of every kind, names from a pool with ViewProj, World and their lower-case forms, uniform and const flags, default bytes with spare capacity, annotations) and techniques (NULL or named, passes with NULL or named calls: no token array, or names, NULL, whitespace and punctuation before the end token), and random failed creates, error texts, empty error texts and shaders lacking a name. The result, every device call and log line, the allocations left, every field of the effect with its darray counts and capacities, the parser's default values and links, and every error must match. The two tests that count allocations re-exec themselves alone in this test executable, as the counter is process-wide. The parser has no functions, so the C and Rust writers write the same text (the writer's own parity is effect_parser_writer_parity). Tier 1's edge_params_and_empty_techniques adds a lower-case world. Mutation: all 20 mutants planted in the core and the shim (a wrong param, annotation or pass section, a case-insensitive World, the first ViewProj kept, a missing shader param ignored, empty error texts added, the technique index in the location, a technique stopping at its first failed pass, the pixel shader skipped after a failed vertex shader, a NULL technique name printed empty, the first param skipped, an annotation typed as its param, the default value left in the parser, the technique's effect unset, the error text leaked, the pixel line logged as the vertex one, the pixel shader built from the vertex call, later effect params dropped, a resize growing one too many, the parser param not linked) fail the parity tests; the 12 in the core also fail Tier 1. The port_comparison bench compiles a typical effect (ViewProj, a color with a default and an annotation, one pass) on each side. No intentional differences reach these tests: the C's _DEBUG_SHADERS lines are in no build here. Refs #3792.
The rust/README.md row for libobs/graphics/effect-parser-compile.c.h (swapped in hybrid libobs, what the core and the shim do, what is characterized and kept, the one intentional difference, and the tests), and the compile step in obs-graphics' crate row, Cargo.toml description, lib.rs and effect_parser module docs. docs/rust-port/naming.md lists the file under obs-graphics since the extraction. Fixes #3792.
Three reads and writes of the compile step happened in a different place than in the C: - ep_compile_pass_shaderparams() sets param->eparam before it calls gs_shader_get_param_by_name(); the port stored both after the call. CompileModel now has set_shader_eparam and set_shader_sparam, called either side of the lookup. - ep_compile_param() and ep_compile_annotations() read the type with obs_effect_param_type() after the name copy and the default move; the port read it first. fill_param no longer takes the type, and set_param_type sets it afterwards. - The World name check ran even when the name was ViewProj, and the annotation loop used the count read before the resize instead of rereading the parser's count each time round, as the C's for loop does. Tier 1's traces follow the new calls, and edge_shader_params_stop_at_the_missing_one checks that each eparam is stored before its shader param is looked up (it fails with the two swapped back). Refs #3792. Local-Gate: v1 tree=13023110071ea8401f8da246a21c4f856988b4f8 secs=2352 lanes=lint:run,dylint:run,rust-test:run,cross:run,tier2-linux:run,macos-native:n/a,windows-native:n/a Ci-Attestation: {"at":1794154520,"gate":"rust/all/fmt","host":"linux-x86_64","key":"55e81d80053d6c2a046e3dc4bacc717e08e96b27fa838504eb471403acfd6d91","lane":"lint","parents":["1fec4da5ceb1ff558a713d6aca81f8bf99f62375"],"secs":50,"stamp":"6e8141a98a3d2fe40b65def9eddecb14","tree":"13023110071ea8401f8da246a21c4f856988b4f8","v":1,"via":"run"} Ci-Attestation: {"at":1794154520,"gate":"rust/x86_64-unknown-linux-gnu/clippy","host":"linux-x86_64","key":"55e81d80053d6c2a046e3dc4bacc717e08e96b27fa838504eb471403acfd6d91","lane":"lint","parents":["1fec4da5ceb1ff558a713d6aca81f8bf99f62375"],"secs":50,"stamp":"3b9c28cfc65a852cb0cc37489c9b4335","tree":"13023110071ea8401f8da246a21c4f856988b4f8","v":1,"via":"run"} Ci-Attestation: {"at":1794154520,"gate":"rust/x86_64-unknown-linux-gnu/test","host":"linux-x86_64","key":"210829562e43e2938afea89821bf933d6f1d3e2ae6791c28aa343e9aa6c935ce","lane":"rust-test","parents":["1fec4da5ceb1ff558a713d6aca81f8bf99f62375"],"secs":252,"stamp":"d65c352aa142cc8a5a36445428fe31be","tree":"13023110071ea8401f8da246a21c4f856988b4f8","v":1,"via":"run"} Ci-Attestation: {"at":1794154520,"gate":"rust/x86_64-pc-windows-msvc/clippy","host":"linux-x86_64","key":"e3f1813cb8d8c7b0e8f02fbf6ee93e302f8934084b081cf40536be219154ce4a","lane":"cross","parents":["1fec4da5ceb1ff558a713d6aca81f8bf99f62375"],"secs":193,"stamp":"b1192bf903a78b60be2ac870becf3d37","tree":"13023110071ea8401f8da246a21c4f856988b4f8","v":1,"via":"run"} Ci-Attestation: {"at":1794154520,"gate":"rust/x86_64-pc-windows-msvc/dylint","host":"linux-x86_64","key":"e3f1813cb8d8c7b0e8f02fbf6ee93e302f8934084b081cf40536be219154ce4a","lane":"cross","parents":["1fec4da5ceb1ff558a713d6aca81f8bf99f62375"],"secs":193,"stamp":"fcf5895ba1bb69ef255e00887255f094","tree":"13023110071ea8401f8da246a21c4f856988b4f8","v":1,"via":"run"} Ci-Attestation: {"at":1794154520,"gate":"rust/aarch64-apple-darwin/clippy","host":"linux-x86_64","key":"e3f1813cb8d8c7b0e8f02fbf6ee93e302f8934084b081cf40536be219154ce4a","lane":"cross","parents":["1fec4da5ceb1ff558a713d6aca81f8bf99f62375"],"secs":193,"stamp":"d60314932b5268b50f411e2cf57f2776","tree":"13023110071ea8401f8da246a21c4f856988b4f8","v":1,"via":"run"} Ci-Attestation: {"at":1794154520,"gate":"rust/aarch64-apple-darwin/dylint","host":"linux-x86_64","key":"e3f1813cb8d8c7b0e8f02fbf6ee93e302f8934084b081cf40536be219154ce4a","lane":"cross","parents":["1fec4da5ceb1ff558a713d6aca81f8bf99f62375"],"secs":193,"stamp":"5c0a89c7f77f396567bae6d7ee16bc20","tree":"13023110071ea8401f8da246a21c4f856988b4f8","v":1,"via":"run"} Ci-Attestation: {"at":1794154521,"gate":"cpp/linux-x64/tier2","host":"linux-x86_64","key":"fd9da00457db86f9d9cf8a110cbd86fe58df167f400a3ccac2592cae768428ca","lane":"tier2-linux","parents":["1fec4da5ceb1ff558a713d6aca81f8bf99f62375"],"secs":2352,"stamp":"a84b28979c4af38a33d0c266a1159395","tree":"13023110071ea8401f8da246a21c4f856988b4f8","v":1,"via":"run"}
rdoupe
force-pushed
the
fix/rust-port-port-the-effect-parser-657
branch
from
November 8, 2026 16:15
aeda929 to
57b48ab
Compare
Collaborator
Author
|
Handed off to the coordinator |
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.
Fixes #3792
What and why
Second step of porting the effect parser's compile step (
libobs/graphics/effect-parser-compile.c.h, moved to its own file in #3807) toobs-graphics. This PR is the Rust port ofep_compile()and its helpers, which fill ags_effectfrom the parser onceep_parse()has read the text with no error. It fills each param and annotation (name, section, type, the parser's default value),ViewProjandWorld, each technique and pass, and each pass's vertex and pixel shader. The shaders are created from the text the shader writer builds, with the effect's and the shader's param for each uniform that text uses. Same shape as the shader writer's port (#3769).obs-graphics: Test the effect parser compile step(RED): Tier 1 in the graphics test binary'sshadermodule, againsttodo!()stubs. The core runs over aCompileModeltrait, one call where the C makes each step, so the shim can write the C structs in place.params,techniquesandshadersporttest_effect_parser_compileone to one: the same cases and expected dump, starting from the parserep_parse()hands the compile step for each text, over the C test's graphics stand-ins written in Rust. Left out: the two texts that never reach the compile step, and thedestroyedandleakedlines, which belong toep_parse()andeffect_free(). Theedge_*tests add:ViewProjandWorldmatched by name only, with their case (a lower-caseworldis a plain param);obs-graphics: Port the effect parser compile step(GREEN): the safe core inobs_graphics::effect_parser::compile, one to one with the C, calling the ported param types directly. The shader location is printed as the C prints it (a NULL file empty, a NULL technique name(null), the pass index cut to 32 bits). It never frees what the effect holds: a failed pass keeps its shader and shader params foreffect_free().obs-graphics: Swap in the effect parser compile step: the hiddenep_compile()shim inffi::effect_parser(listed inrust-hidden.d/obs-graphics-effect_parser.txt).struct gs_effectand its params, annotations, techniques, passes and pass shader params in place, on libobs's allocator: each array grown asdarray_resizegrows it, each name abstrdupcopy, each default value moved asda_movemoves it.gs_effect_get_param_by_name. The shader creates,gs_shader_get_param_by_name()and the threeLOG_ERRORlines (with the C's literal formats) go through new private adapters inobs-graphics-adapter.c.h. A shader's error text goes tocf_adderror()and is then freed.libobs.ported-effect-parser-compile, registered in its ownported-source-sets/effect-parser-compile.json.test_effect_parser_compilekeeps checking the C it compiles into itself. The newtest_effect_parser_compile_rust(hybrid only) runs the same file and expectations against the compile step from the production staticlib, with the test's stand-ins behind the adapters._rusttests no longer compile the compile step's C, so they run on the Rust compile step too.cargo test, the neworacle/effect_parser_compile_device.cis the graphics stand-in the adapters reach.obs-graphics: Compare the effect parser compile step: Tier 2 layouts (pass_shaderparam,ep_param,effect_parser) and Tier 3 parity against the original C.effect-parser-compile.c.hunmodified, on the C writer, param types, effect param lookup,cf_adderrorand dstr.ViewProj,Worldand their lower-case forms, flags, default bytes with spare capacity, and annotations;NULL, whitespace and punctuation;port_comparisonbench compiles a typical effect on each side.obs-graphics: Keep the compile step's C order(from review): each pass shader param'separamis stored beforegs_shader_get_param_by_name()is called, as in the C. A param's type is read after its name copy and default move.Worldis compared only when the name isn'tViewProj, and the annotation loop rereads the parser's count on each pass. Tier 1 checks the store-before-lookup order.Odd but real results stay as the C has them (characterized in #3807, not endorsed): a second
ViewProjorWorldreplaces the first asview_projorworld, while the shader-param lookups find the first. A shader created together with an error text is kept, and the result stays true.One intentional difference: the compile step's own
_DEBUG_SHADERSlog lines (a developer-only define that no build sets) are not written. It is listed in the core's docs and rust/README.md. A null parser or effect returns false, where the C asserts;ep_parse()never passes one.Ported code: Lain Bailey's (upstream obs-studio), credited on the GREEN commit. No upstream issue.
Test cost: new tests: longest 0.04 s (the proptest at the full level, in its own re-exec'd process; 0.013 s at the reduced level), peak RSS 8.2 MB over 25 runs, no threads of their own (two tests each start one child process of the test binary).
RED → GREEN
soldr cargo test -p obs-graphics --test obs-tests-graphics -- shader::effect_parser_compilefails 8 of 8 (params,techniques,shadersand the fiveedge_*tests), each panicking at atodo!()ineffect_parser/compile.rs. On it,--test-diff origin/masterran 6496 tests: 6488 passed, exactly those 8 failed, 6 skipped. The lint lane passed.test_effect_*,test_shader_*) pass 21/21 on the C build, and 28/28 (with the seven_rustvariants,test_effect_parser_compile_rustamong them) on the hybridlibobsand onlibobs-c-reference. None skipped.ep_compilelocal (t) in each. The hybrid carries the Rust compile step; the C reference doesn't.World) until the lower-caseworldcases were added../lint: clean. The local gate's lint and cross lanes: ok.--test-diff origin/master: 6757 tests run, all passed, 6 skipped. MSVC clippy (--workspace --target x86_64-pc-windows-msvc --all-targets): clean. Theport_comparisonbench passes its allocation check. The cross lane first caught a-Wformat-nonliteralerror in the new graphics stand-in on the macOS target; that fix is in the swap commit._rusttests moved fromtests.d/*.cmakeintotest-graph.jsonon master (test: register #1390 batch 39 (Rust-static effect parser and scene crop fixtures) #4029), so this PR now drops the compile step's C from those four graph entries and their obs-build expectations, registerstest_effect_parser_compile_rustin the graph with its own expectation in the private-parser family (now five targets, its three cases in the runtime table), and keeps a comment-onlytests.d/test_effect_parser_compile.cmake. After it: the registration tests pass (native_build::, 243/243), the C, hybrid and C reference builds export the same 1767 symbols withep_compilelocal in each, the effect and shader C tests pass 21/21, 28/28 and 28/28 (test_effect_parser_compile_rustbuilt from the graph), the quick checks and./lintpass, and the compile bench runs on both sides. Theport_comparisonbench as a whole aborts afterwards in the service bench's setup, on master too (bug: port_comparison service bench dereferences its stand-in output, bug: obs-c-oracle: port_comparison service bench dereferences its stand-in output #3886)../lint,./unittest(Rust Tiers 1-3, and Tier 2 750/750 on both the C reference and hybrid builds, with 3 skipped on each:test_pulse_default_follow,test_v4l2_vivid_replugandtest_v4l2_vivid_stall, which need a sound server or devices the container lacks), the lint and cross lanes, and the export comparison all pass again../unittestalso caught a%zuformat that the windows-gnu oracle build rejects, fixed in the swap commit.shader::), the hybrid effect and shader C tests pass 28/28, clippy and the lint lane are clean, and swapping the eparam store back after the lookup fails Tier 1.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)