Skip to content

obs-graphics: Port the effect parameter types - #3165

Merged
rdoupe merged 7 commits into
masterfrom
fix/rust-port-effect-parameter-types-365
Oct 31, 2026
Merged

rdoupe merged 7 commits into
masterfrom
fix/rust-port-effect-parameter-types-365

Conversation

@rdoupe

@rdoupe rdoupe commented Oct 31, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #3162

What and why

Ports the parameter type decisions of the effect parser in libobs/graphics/effect-parser.c.h to rust/obs-graphics (obs_graphics::effect_param_types):

  1. Move (libobs: Move effect parameter types to own file): get_effect_param_type(), the route of ep_parse_param_assignment_val() and the shape of ep_parse_param_assign_intfloat_array() go to libobs/graphics/effect-param-types.c.h as hidden functions on a type name, behaviour-neutral. effect-parser.c keeps every token call, every cf_adderror(), the value parsers, the brace and constructor handling, the loop over the values and the compile.
  2. Characterization: test_effect_param_types_steps on the moved C.
  3. RED: Tier 1 tests on todo!() stubs.
  4. GREEN: the core (param_type() calls the ported shader_param_names::shader_param_type(), the same map; route(); the array shape, its digits as a c_char so a non-ASCII byte counts as the C does on each target) and its hidden shims in libobs.ported-effect-param-types, registered in libobs/build/ported-source-sets/effect-param-types.json. test_effect_param_types_steps_rust runs the characterization against the shims.
  5. Tier 3 against the original C, with a port_comparison bench.
  6. Docs: rust/README.md, naming.md, the crate description and module docs.
  7. Review fix (libobs: Split the effect array shape): the array shape is one function per read, each asked where the C read its byte (obs-source: Port the deinterlace draw decisions #2153): obs_effect_param_rows_bad before the row error, _rows, _has_cols, _cols_bad before the column error, and _cols, the count times the column digit. The first move read the column digit before the row error was added. Only a C string, bools and ints cross now, so the shape struct goes; the core, the shims, the oracle, the characterization, Tier 1, Tier 3, the bench, the export lists and the README row follow.

No intentional difference from the C. A null name, which effect-parser.c never passes (the C hands it to strcmp()), reads as "" in the shims. No upstream issue.

RED → GREEN

  • Move: checked in a scratch harness, master's get_effect_param_type(), ep_parse_param_assign_intfloat_array() and ep_parse_param_assignment_val() against the moved code over logging stand-ins for the token calls, cf_adderror() and the value parsers, on 200,000 type names (40,000 under the sanitizers): gcc and clang, -O0 and -O2, with and without ASan/UBSan. The split code gives 0 differences in all 8 builds, both plain and with a cf_adderror() stand-in that rewrites the dimension bytes of the type name (the first move differs with that stand-in); 21 planted mutants, all caught. Exported symbols unchanged and identical on the C, hybrid and C reference libobs (1767), the seven new functions local.
  • Characterization: test_effect_param_types_steps 10/10 on the C; it catches all 20 mutants of the split C file.
  • RED commit: 8937000. 15/15 Tier 1 tests fail on the stubs (obs-tests-graphics, shader::effect_param_types, e.g. shader::effect_param_types::steps_every_route ... FAILED). The lint lane passes and --test-diff fails only those 15.
  • GREEN (runs were on 76da5d3):
    • Tier 1 and Tier 3: 25/25 (shader::effect_param_types, shader::effect_param_types_parity): every name of up to four bytes over the bytes that matter, every known name with every tail of up to three, every known name with each one-byte suffix, prefix and cut, every byte as a row or column digit, each dimension function on its own, and proptests of any bytes. 25 deliberate breaks of the core and the shims are all caught (the shim breaks by Tier 3).
    • Tier 2: the whole cmocka suite, among them test_effect_param_types_steps, test_effect_param_types_steps_rust and the effect tests, passes against the hybrid libobs and libobs-c-reference (657 of 657 each), 3 skipped on each (a PulseAudio case and two v4l2 vivid cases, with no sound server or vivid module), under Xvfb. In the full run test_pulse_default_follow_pipewire failed once on the C reference and passed 2 of 2 alone. test_source_monitor_only_load is left out: it hangs without a sound server on every build, the plain C one too. Exported symbols identical on the C, hybrid and C reference libobs (1767), the seven shims hidden.
    • Gates: ./lint, --lane lint, --lane cross and ./unittest's Rust lane (5741 and 895 passed, 6 skipped) pass; soldr cargo clippy --workspace --target x86_64-pc-windows-msvc --all-targets --locked -- -D warnings is clean. The local gate's Tier 2 lane (and ./unittest's) needs Docker, which this build machine's user cannot reach, so Tier 2 ran natively (above) and the head is not stamped; the local gate's lint, rust-test and cross lanes pass.
    • port_comparison (effect_param_types/effect/12_params): Rust 250 ns, C 452 ns on an x86_64 Linux build machine; the allocation check passes.
  • Real app (UI, protocol output or logging changes): not applicable, no UI, protocol or logging change.

Test cost: new tests: longest 0.02 s at reduced and 0.14 s at full, peak RSS 9 MB over 20 runs, no threads of their own.

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)
  • 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
  • Intentional differences from C listed in the parity test header and rust/README.md (ports)

Behaviour-neutral extraction before the Rust port. The parameter type
decisions of effect-parser.c move to
libobs/graphics/effect-param-types.c.h, as three functions on a type
name declared in the new libobs/graphics/effect-param-types.h without
EXPORT (hidden, as -fvisibility=hidden keeps them):

- obs_effect_param_type(type): get_effect_param_type() whole, the
  shader parameter type that ep_compile_annotations() and
  ep_compile_param() give a type name;
- obs_effect_param_route(type, is_texture): which default-value parser
  ep_parse_param_assignment_val() calls, in its order (texture flag,
  exact int and float, int and float prefixes, string prefix, exact
  bool, otherwise invalid); the caller switches on it;
- obs_effect_param_array_shape(type, is_float): the value count of
  ep_parse_param_assign_intfloat_array() (the row digit, times the
  column digit after an 'x') and whether each digit is outside 1-4.

effect-parser.c keeps every token call, every cf_adderror() (in the
same order: the row error, then the column error), the value parsers,
the brace and constructor handling, the loop over the values and the
compile. The one reordering: the shape reads the column digit before
the row error is added, where the C added it first; cf_adderror() only
records the error and never touches the type name.

Checked in a scratch harness (not committed): master's
get_effect_param_type(), ep_parse_param_assign_intfloat_array() and
ep_parse_param_assignment_val() against the moved code, over logging
stand-ins for the token calls, cf_adderror() and the value parsers
with scripted results, on 200,000 type names (40,000 under the
sanitizers): the known names, cut by a byte or with one to three bytes
of their letters, digits, 'x', '_' and a non-ASCII byte added, with
and without the texture flag: gcc and clang, -O0 and -O2, with and
without ASan/UBSan, 0 differences in 8 builds. 18 planted mutants (the
texture flag, each route's compare and order, the row and column bounds,
the count's product, the prefix length, the 'x', the texture prefix,
two type names, the caller's errors, count and array flag) are all
caught.

Exported symbols are unchanged and identical on the C, hybrid and
C reference libobs (1767); the three functions are local.

Refs #3162.
Characterization before the Rust port, against the C moved to
libobs/graphics/effect-param-types.c: test_effect_param_types_steps
(every platform, the moved file on its own, ASan and UBSan), 9 cases:

- every exact type name, and any name starting with "texture"
  (characterized, not endorsed: "textures" too) is a texture;
- case matters, and a suffix, a cut or an empty name is unknown;
- every route, the texture flag first whatever the name, and a texture
  name without the flag invalid;
- "strings" gets the string parser and "int1", "float3x3" and
  "integer" array values, with an unknown type (characterized, not
  endorsed);
- the shapes of float2 to float4x4, int1 to int1x4, and only the byte
  after the row digit looked at for an 'x';
- a row digit outside 1-4 adds its error and still counts, 'x' - '0'
  for "floatx" (characterized, not endorsed);
- a column digit outside 1-4 adds its error and still counts, the
  terminator as '\0' - '0' for "float4x" (characterized, not endorsed).

Non-ASCII digit bytes are left out: their count follows the target's
char signedness. The parity test covers them.

Deliberate breaks of the moved C (19: the texture flag, each route's
compare, the row and column bounds, the product, the prefix length,
the 'x', the texture prefix, three type names, the float exact tests
and the column flag): all 19 caught.

Refs #3162.
RED for #3162. obs_graphics::effect_param_types has its API and docs,
with todo!() bodies: param_type() (the shader parameter type of a type
name), route() (the default-value parser a parameter gets) and
array_shape() (the value count of an int or float array type, and its
row and column errors).

tests/shader/effect_param_types.rs:
- steps_*: test_effect_param_types_steps.c 1:1 (9 cases, same names,
  values and expectations);
- edge_*: non-ASCII digit bytes, counted as a C char on the target; a
  name that ends at the row digit or right after an 'x'; the route's
  order; and proptests of every decision against a model (param_type()
  against the ported shader_param_type()).

All 15 fail on the stubs (obs-tests-graphics,
shader::effect_param_types).

Refs #3162.
GREEN for #3162. obs_graphics::effect_param_types implements the
parameter type decisions of effect-parser.c:

- param_type(): the shader parameter type of a type name, through the
  ported shader_param_names::shader_param_type(), the same map;
- route(): the texture flag, exact int and float, the int and float
  prefixes, the string prefix, exact bool, otherwise invalid, in the
  C's order;
- array_shape(): the row digit after the int or float prefix, times the
  column digit after an 'x', each a C char minus '0' (c_char, so
  signed or not as on the target), and whether each is outside 1-4. A
  byte past the end of the name reads as the terminator; the column
  digit is read only after an 'x'.
No intentional difference. The module denies clippy::todo now too.

C ABI (ffi::effect_param_types): three shims; the route crosses as int
and struct obs_effect_param_shape is mirrored and crosses by value. A
null name, which effect-parser.c never passes and the C would hand to
strcmp(), reads as "".

libobs: effect-param-types.c.h leaves libobs.graphics for its own group
libobs.ported-effect-param-types, registered in
libobs/build/ported-source-sets/effect-param-types.json, whose
precompiled header includes the unit's header, <string.h> and
util/dstr.h. The hybrid libobs leaves the group out and links the
shims; the three symbols are listed in rust-exports.map,
rust-hidden.txt and rust-unexports-macos.txt and stay hidden.
ci/test_ported_sources.py lists the object. Exported symbols are
unchanged and identical on the C, hybrid and C reference libobs
(1767), the three functions local.

test_effect_param_types_steps_rust builds the characterization against
the shims in the production staticlib (libobs_rust-static, only with
the hybrid backend), as test_graphics_immediate_steps_rust does, under
ASan and UBSan; the test file is the same, as nothing differs.

Tier 1: 15/15 (obs-tests-graphics, shader::effect_param_types).
test_effect_param_types_steps: 9/9 on the C, hybrid and C reference
builds; test_effect_param_types_steps_rust: 9/9.

Refs #3162.
Tier 3 for #3162. obs-c-oracle builds the original
libobs/graphics/effect-param-types.c.h as oracle_obs_effect_param_*
(oracle/effect_param_types.c, with the C dstr.c's astrcmp_n), with the
GS_SHADER_PARAM_* and route values and the layout of
struct obs_effect_param_shape.

tests/shader/effect_param_types_parity.rs runs every call on the C, the
shim and the core and compares the results exactly: the type, the
route with and without the texture flag, and the shape after both
prefixes for every name longer than the prefix.

- the enums and the shape's size, alignment and field offsets;
- every name of up to four bytes over the bytes that matter (the known
  names' letters, the digits, 'x', '_' and 0xc3, negative as a signed
  C char), and every known name followed by every tail of up to three
  of them; the decisions read a known prefix and at most three bytes
  after it, so these reach every path. Tails of three or more bytes are
  sampled by parity::keep() below the full level;
- every known name with each one-byte suffix and prefix (1-255) and
  each one-byte cut;
- every byte as the row digit, the column digit, or both, after both
  prefixes;
- proptests of any bytes, alone and after a known name.

No intentional difference. Left out, as the C never meets them: the
shape of a name no longer than its prefix (the C reads past the
terminator; the route never gives one) and a null name (the C calls
strcmp(NULL); the shim reads it as "", checked on the Rust side).

port_comparison gets benches/port_comparison/effect_param_types.rs: the
12 parameters of a typical effect through the route, the shape and the
type as effect-parser.c asks them, folded into a checksum both sides
match. Linux x86_64: Rust 189 ns, C 368 ns. It allocates nothing.

Mutation check (done once, not committed); failing tests per mutant,
Tier 1 / Tier 3: the texture flag ignored 2/7; exact int never
matched 3/5; the int prefix shortened 1/3; float arrays as int 4/4;
the string prefix exact 3/3; bool invalid 2/3; the int prefix length 4
6/6; 'X' for 'x' 5/5; the column read at the 'x' 6/5; the product a
sum 6/5; the bounds 1-5 3/6 and 0-4 3/6; the digit unsigned 2/6; the
column error as a row error 5/5; one name's type 2/2; and in the shims
a null name as "int" 0/1, the flags swapped 0/7, the count capped 0/6
and the texture flag inverted 0/7. All 19 are killed, the shim mutants
by Tier 3, the tier that reaches the shims. The proptest regression
files keep seeds the mutants failed on.

Tier 1 and Tier 3: 23/23, longest 0.02 s at reduced and 0.08 s at
full, peak RSS 8 MB over 20 runs, no threads of their own.

Refs #3162.
rust/README.md: the obs-graphics row names
libobs/graphics/effect-param-types.c.h, and a row for the unit says
what moved, what effect-parser.c keeps, the C behaviour kept, the null
name and the tests. docs/rust-port/naming.md lists the file under
rust/obs-graphics, and the crate's description and module docs name
it.

No docs/features.md line: a port with no change in behaviour.

Fixes #3162.
Review fix. obs_effect_param_array_shape() read the row digit, the
byte after it and the column digit at once, before
ep_parse_param_assign_intfloat_array() added either error. The C reads
the row digit for its test, adds the row error, reads it again for the
count, then reads the byte after it, and the column digit for its test
and, after the column error, again for the product. The shape becomes
one function per read, each asked where the C read it (#2153):

- obs_effect_param_rows_bad(type, is_float), before the row error;
- obs_effect_param_rows(type, is_float), the count so far;
- obs_effect_param_has_cols(type, is_float), the 'x';
- obs_effect_param_cols_bad(type, is_float), before the column error;
- obs_effect_param_cols(type, is_float, count), the count times the
  column digit.

Only a C string, bools and ints cross, so struct obs_effect_param_shape
goes. The Rust core (rows_bad(), rows(), has_cols(), cols_bad() and
cols() in place of array_shape() and Shape), its shims, the oracle (the
route renamed by a function-like macro, which leaves the enum tag
alone, with the sizes of bool, int and the route), the
characterization (which asks them in the parser's order, and a new
case for each alone), Tier 1, Tier 3 (each function compared on its
own, the column ones with counts of 0, +-1 and +-1000 too), the bench,
the three export lists and the rust/README.md row follow.

The move harness reruns on this C against master's functions, plain
and with a cf_adderror() stand-in that rewrites the dimension bytes of
the type name: 0 differences in all 8 builds both ways, where the
first move differs with the rewriting stand-in. 21 planted mutants,
all caught. test_effect_param_types_steps (10 cases) catches all 20
mutants of the split C file. Tier 1 and Tier 3: 25/25; 25 mutants of
the core and shims, all caught, the shim ones by Tier 3.

Refs #3162.
@rdoupe
rdoupe force-pushed the fix/rust-port-effect-parameter-types-365 branch from 71ad262 to 76da5d3 Compare October 31, 2026 18:42
@rdoupe
rdoupe marked this pull request as ready for review October 31, 2026 19:12
@rdoupe
rdoupe requested a review from zackees as a code owner October 31, 2026 19:12
@rdoupe
rdoupe added this pull request to the merge queue Oct 31, 2026
@obs-rust-project-manager obs-rust-project-manager Bot moved this to In merge queue in obs-rust Multiview Oct 31, 2026
Merged via the queue into master with commit 7a5b15c Oct 31, 2026
41 checks passed
@rdoupe
rdoupe deleted the fix/rust-port-effect-parameter-types-365 branch October 31, 2026 19:43
zackees added a commit that referenced this pull request Oct 31, 2026
…enerate the linker lists (#3233) [GREEN]

rust-hidden.txt becomes libobs/cmake/rust-hidden.d/<crate>-<ffi module>.txt
(132 fragments) plus rust-hidden-base.txt for Rust runtime patterns, C glue
and the macOS-only compiler-rt helpers. libobs/cmake/rust-hidden.cmake
generates rust-exports.map and rust-unexports-macos.txt into the build tree
at configure time (also runnable with cmake -P); rust/obs-build writes the
same lists. The committed .map and macOS list are gone.
Rebased onto master after #3165 and #3227: their eight new hidden shims
moved into the per-module fragments (obs-graphics-effect_param_types.txt,
obs-core-audio_mix.txt), so the generated sets still equal master's old
lists exactly.

ci_scope: a rust-hidden.d fragment edit is Linux only; the mirrored-lists
rule (#2288) and its test are removed. export_list.rs reads the fragments
and checks each names only its own module's shims.

Refs #3233, #3232
chriscoveries pushed a commit to chriscoveries/obsrust-fork that referenced this pull request Oct 31, 2026
…ists (obs-rust#3233) (obs-rust#3248)

* test(ci): pin per-module hidden-symbol fragments and Linux-only scope (obs-rust#3233) [RED]

Fails: the three shared lists still exist, rust-hidden.d/ and the
generator are missing, and a fragment edit selects macOS and Windows.

Refs obs-rust#3233, obs-rust#3232

* build(libobs): split hidden-symbol lists into per-module fragments, generate the linker lists (obs-rust#3233) [GREEN]

rust-hidden.txt becomes libobs/cmake/rust-hidden.d/<crate>-<ffi module>.txt
(132 fragments) plus rust-hidden-base.txt for Rust runtime patterns, C glue
and the macOS-only compiler-rt helpers. libobs/cmake/rust-hidden.cmake
generates rust-exports.map and rust-unexports-macos.txt into the build tree
at configure time (also runnable with cmake -P); rust/obs-build writes the
same lists. The committed .map and macOS list are gone.
Rebased onto master after obs-rust#3165 and obs-rust#3227: their eight new hidden shims
moved into the per-module fragments (obs-graphics-effect_param_types.txt,
obs-core-audio_mix.txt), so the generated sets still equal master's old
lists exactly.

ci_scope: a rust-hidden.d fragment edit is Linux only; the mirrored-lists
rule (obs-rust#2288) and its test are removed. export_list.rs reads the fragments
and checks each names only its own module's shims.

Refs obs-rust#3233, obs-rust#3232

* style: gersemi format rust-hidden.cmake (obs-rust#3233)
@obs-rust-project-manager obs-rust-project-manager Bot moved this from In merge queue to Done in obs-rust Multiview Oct 31, 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 effect parameter types and default-value shapes

1 participant