Repository navigation
obs-graphics: Port the effect parameter types - #3165
Merged
Merged
Conversation
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
force-pushed
the
fix/rust-port-effect-parameter-types-365
branch
from
October 31, 2026 18:42
71ad262 to
76da5d3
Compare
rdoupe
marked this pull request as ready for review
October 31, 2026 19:12
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)
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 #3162
What and why
Ports the parameter type decisions of the effect parser in
libobs/graphics/effect-parser.c.htorust/obs-graphics(obs_graphics::effect_param_types):libobs: Move effect parameter types to own file):get_effect_param_type(), the route ofep_parse_param_assignment_val()and the shape ofep_parse_param_assign_intfloat_array()go tolibobs/graphics/effect-param-types.c.has hidden functions on a type name, behaviour-neutral.effect-parser.ckeeps every token call, everycf_adderror(), the value parsers, the brace and constructor handling, the loop over the values and the compile.test_effect_param_types_stepson the moved C.todo!()stubs.param_type()calls the portedshader_param_names::shader_param_type(), the same map;route(); the array shape, its digits as ac_charso a non-ASCII byte counts as the C does on each target) and its hidden shims inlibobs.ported-effect-param-types, registered inlibobs/build/ported-source-sets/effect-param-types.json.test_effect_param_types_steps_rustruns the characterization against the shims.port_comparisonbench.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_badbefore the row error,_rows,_has_cols,_cols_badbefore 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 andints 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.cnever passes (the C hands it tostrcmp()), reads as""in the shims. No upstream issue.RED → GREEN
get_effect_param_type(),ep_parse_param_assign_intfloat_array()andep_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 acf_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.test_effect_param_types_steps10/10 on the C; it catches all 20 mutants of the split C file.obs-tests-graphics,shader::effect_param_types, e.g.shader::effect_param_types::steps_every_route ... FAILED). The lint lane passes and--test-difffails only those 15.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).test_effect_param_types_steps,test_effect_param_types_steps_rustand the effect tests, passes against the hybrid libobs andlibobs-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 runtest_pulse_default_follow_pipewirefailed once on the C reference and passed 2 of 2 alone.test_source_monitor_only_loadis 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../lint,--lane lint,--lane crossand./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 warningsis 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.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
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