Skip to content

obs-graphics: Port the effect parser compile step - #3843

Merged
rdoupe merged 6 commits into
masterfrom
fix/rust-port-port-the-effect-parser-657
Nov 8, 2026
Merged

rdoupe merged 6 commits into
masterfrom
fix/rust-port-port-the-effect-parser-657

Conversation

@rdoupe

@rdoupe rdoupe commented Nov 7, 2026 •

Copy link
Copy Markdown
Collaborator

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) to obs-graphics. This PR is the Rust port of ep_compile() and its helpers, which fill a gs_effect from the parser once ep_parse() has read the text with no error. It fills each param and annotation (name, section, type, the parser's default value), ViewProj and World, 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's shader module, against todo!() stubs. The core runs over a CompileModel trait, one call where the C makes each step, so the 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, starting from the parser ep_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 the destroyed and leaked lines, which belong to ep_parse() and effect_free(). The edge_* tests add:

    • the location's NULL file and technique name, and its 32-bit pass index;
    • the order of the calls when both shaders of a pass fail;
    • a used name the effect lacks, and a shader lacking a middle param;
    • ViewProj and World matched by name only, with their case (a lower-case world is a plain param);
    • techniques with no pass, and each step on its own.
  • obs-graphics: Port the effect parser compile step (GREEN): the safe core in obs_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 for effect_free().

  • obs-graphics: Swap in the effect parser compile step: the hidden ep_compile() shim in ffi::effect_parser (listed in rust-hidden.d/obs-graphics-effect_parser.txt).

    • It writes struct gs_effect and its params, annotations, techniques, passes and pass shader params in place, on libobs's allocator: each array grown as darray_resize grows it, each name a bstrdup copy, each default value moved as da_move moves it.
    • The shader text is the writer shim's, and the effect param lookup is the Rust gs_effect_get_param_by_name. The shader creates, gs_shader_get_param_by_name() and the three LOG_ERROR lines (with the C's literal formats) go through new private adapters in obs-graphics-adapter.c.h. A shader's error text goes to cf_adderror() and is then freed.
    • The unity group becomes libobs.ported-effect-parser-compile, registered in its own ported-source-sets/effect-parser-compile.json.
    • test_effect_parser_compile keeps checking the C it compiles into itself. The new test_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.
    • The blocks, params, passes and shader call _rust tests no longer compile the compile step's C, so they run on the Rust compile step too.
    • Under cargo test, the new oracle/effect_parser_compile_device.c is 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.

    • The oracle compiles effect-parser-compile.c.h unmodified, on the C writer, param types, effect param lookup, cf_adderror and dstr.
    • Both sides compile the same random parser over the same recording graphics stand-in:
      • params of every type kind, with names that include ViewProj, World and their lower-case forms, flags, default bytes with spare capacity, and annotations;
      • techniques and passes named or NULL, with calls that have no token array or that hold names, NULL, whitespace and punctuation;
      • failed creates, error texts, empty error texts, and shaders lacking a name;
      • file names that include NULL and empty.
    • Compared: 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. The two tests that count allocations re-exec themselves alone, as the counter is process-wide.
    • The port_comparison bench compiles a typical effect on each side.
  • obs-graphics: Keep the compile step's C order (from review): each pass shader param's eparam is stored before gs_shader_get_param_by_name() is called, as in the C. A param's type is read after its name copy and default move. World is compared only when the name isn't ViewProj, 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 ViewProj or World replaces the first as view_proj or world, 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_SHADERS log 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

  • RED commit: f7cd504. soldr cargo test -p obs-graphics --test obs-tests-graphics -- shader::effect_parser_compile fails 8 of 8 (params, techniques, shaders and the five edge_* tests), each panicking at a todo!() in effect_parser/compile.rs. On it, --test-diff origin/master ran 6496 tests: 6488 passed, exactly those 8 failed, 6 skipped. The lint lane passed.
  • GREEN:
    • Tier 1 passes 8/8 and Tier 3 4/4.
    • Linux Tier 2 (native ctest, TMPDIR unset): the effect and shader tests (test_effect_*, test_shader_*) pass 21/21 on the C build, and 28/28 (with the seven _rust variants, test_effect_parser_compile_rust among them) 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, with ep_compile local (t) in each. The hybrid carries the Rust compile step; the C reference doesn't.
    • Mutation: all 20 mutants planted in the core and the shim fail the parity tests, and the 12 in the core also fail Tier 1. One first survived (a case-insensitive World) until the lower-case world cases 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. The port_comparison bench passes its allocation check. The cross lane first caught a -Wformat-nonliteral error in the new graphics stand-in on the macOS target; that fix is in the swap commit.
    • Rebased onto master 9fff84e: the parser _rust tests moved from tests.d/*.cmake into test-graph.json on 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, registers test_effect_parser_compile_rust in 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-only tests.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 with ep_compile local in each, the effect and shader C tests pass 21/21, 28/28 and 28/28 (test_effect_parser_compile_rust built from the graph), the quick checks and ./lint pass, and the compile bench runs on both sides. The port_comparison bench 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).
    • Pre-post, on the head rebased onto master: ./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_replug and test_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. ./unittest also caught a %zu format that the windows-gnu oracle build rejects, fixed in the swap commit.
    • Runs were on 32c1eb5 (Tier 2 and mutation on the same code before the stand-in's format fix, which changes only that test file), docs after. After the review fix (57b48ab): Tier 1 and Tier 3 pass (249/249 in 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.
  • 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) (the characterization landed in libobs: Move the effect parser compile step to file #3807)
  • 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)

@rdoupe
rdoupe force-pushed the fix/rust-port-port-the-effect-parser-657 branch from 8b75c97 to aeda929 Compare November 7, 2026 10:30
@rdoupe
rdoupe marked this pull request as ready for review November 7, 2026 11:00
@rdoupe
rdoupe requested a review from zackees as a code owner November 7, 2026 11:00
@rdoupe
rdoupe added this pull request to the merge queue Nov 7, 2026
@rdoupe

rdoupe commented Nov 7, 2026

Copy link
Copy Markdown
Collaborator Author

Handed off to the coordinator

@obs-rust-project-manager obs-rust-project-manager Bot moved this to In merge queue in obs-rust Multiview Nov 7, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to no response for status checks Nov 7, 2026
@obs-rust-project-manager obs-rust-project-manager Bot moved this from In merge queue to Ready to merge in obs-rust Multiview Nov 7, 2026
@zackees
zackees added this pull request to the merge queue Nov 8, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Nov 8, 2026
@rdoupe
rdoupe added this pull request to the merge queue Nov 8, 2026
@rdoupe

rdoupe commented Nov 8, 2026

Copy link
Copy Markdown
Collaborator Author

Handed off to the coordinator

@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Nov 8, 2026
rdoupe and others added 6 commits November 8, 2026 10:21
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
rdoupe force-pushed the fix/rust-port-port-the-effect-parser-657 branch from aeda929 to 57b48ab Compare November 8, 2026 16:15
@rdoupe
rdoupe added this pull request to the merge queue Nov 8, 2026
@rdoupe

rdoupe commented Nov 8, 2026

Copy link
Copy Markdown
Collaborator Author

Handed off to the coordinator

Merged via the queue into master with commit 731a4eb Nov 8, 2026
40 checks passed
@rdoupe
rdoupe deleted the fix/rust-port-port-the-effect-parser-657 branch November 8, 2026 17:52
@obs-rust-project-manager obs-rust-project-manager Bot moved this from Ready to merge to Done in obs-rust Multiview Nov 8, 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.

rust: Port the effect parser's compile step

1 participant