Skip to content

rust: Port the effect parser's shader writer #3765

Closed

Description

@rdoupe

Unit

libobs/graphics/effect-parser.c.h: the effect parser's shader writer, moved to a new hidden file and then ported to rust/obs-graphics:

  • ep_makeshaderstring(): a pass's vertex or pixel shader call (Name(args)), written out as the HLSL-style text handed to the graphics device, with the uniform params it uses collected into used_params;
  • ep_write_param(), ep_write_sampler(), ep_write_var(), ep_write_struct() and ep_write_func(): one declaration each, skipped when already written;
  • ep_write_func_param_deps(), _sampler_deps(), _struct_deps() and _func_deps(): a function's dependencies, written before it (ep_write_func() and ep_write_func_func_deps() call each other);
  • ep_write_main_params() and ep_write_main(): the main that calls the named function, with the mapped params as its own;
  • ep_reset_written(): every written flag cleared after each shader;
  • ep_getfunc(), ep_getparam() and ep_getannotation() (no caller), the lookups by name only the writer uses, and the dstr_array_t typedef.

The compile step (ep_compile_pass_shader()), which stays in effect-parser.c.h, calls ep_makeshaderstring() and uses dstr_array_t, so those two go into a new internal graphics/effect-parser-writer.h (a private adapter, not a new public API) and ep_makeshaderstring() loses its static. The writer calls ep_getstruct(), ep_getsampler(), ep_getfunc_strref() and ep_getparam_strref() through graphics/effect-parser-funcs.h, and ep_struct_mapped() (effect-parser.h).

Phase and position

Phase 6 style (#444): a behaviour-neutral extraction, then the port. Crate obs-graphics, after the effect parser's parameters (#3621). Tracking: #4.

Dependencies and existing tests

Notes

  • ep_getfunc() and ep_getparam() have generic names: the move checks the graphics groups and the ported effect groups for clashes before ep_makeshaderstring() loses static (only it does; the rest stay static).
  • Expected intentional difference for the port: ep_write_main_params() writes each mapped param straight after the one before, so a function with two mapped params gets main(float4 pos : POSITION float2 uv : TEXCOORD0), which doesn't compile. The characterization pins that as "characterized, not endorsed"; the port puts ", " between them. Every shader that compiles today comes out the same.
  • The empty_params branch, param_str and adjusted_call in ep_write_main()/ep_write_main_params() have no effect on the output; the port may drop them.
  • Threads: effects are parsed on the graphics thread; nothing here keeps state beyond the written flags, which each call clears.

Activity

  1. added
    enhancement
    port
    on Nov 6, 2026
  2. rdoupe commented on Nov 6, 2026

    @rdoupe
    CollaboratorAuthor

    Claiming: #3765.

    1. A new test_effect_parser_writer (cmocka) that compiles the original effect parser C into itself and pins, for each pass's vertex and pixel call, the shader text ep_makeshaderstring() writes, the used_params it collects and every written flag afterwards.
    2. Behaviour-neutral move: the writer, its three name lookups and dstr_array_t into a new libobs/graphics/effect-parser-writer.c.h in its own live unity group, with ep_makeshaderstring() declared in a new private graphics/effect-parser-writer.h. Checked with a move harness (master's and the moved C on the same texts, GCC and Clang, -O0/-O2, ASan/UBSan, planted mutants) and identical export sets on the C, hybrid and C reference builds.
    3. Then the Rust port of the moved file in a second PR on this issue, with the two-mapped-params main fix as its intentional difference.

    Draft PR for 1 and 2 expected today.

  3. added
    ready
    on Nov 6, 2026
  4. rdoupe commented on Nov 6, 2026

    @rdoupe
    CollaboratorAuthor

    Continuing with step 3 of the claim above, now that the extraction has merged (#3766): the Rust port of libobs/graphics/effect-parser-writer.c.h into obs-graphics's effect_parser module, batched in one PR with #3768 (main() with two mapped params and no comma), which is its one intentional difference.

    1. RED: Tier 1 tests against todo!() stubs, porting test_effect_parser_writer's cases 1:1.
    2. GREEN: the safe writer, as the C writes it.
    3. The C shim: ep_makeshaderstring() under its C name (hidden), writing into the caller's struct dstr and used_params and setting and clearing the written flags in place; the funcs file's lookups still called through their C symbols; layout tests for struct ep_func.
    4. Tier 3: an obs-c-oracle wrapper of the writer and a proptest over random parsers and calls, with mutation.
    5. The writer's include moves into a ported unity group.
    6. RED and GREEN for bug: effect parser: main() gets two mapped params with no comma between them #3768.

    Draft PR today, once the RED commit exists.

  5. rdoupe commented on Nov 6, 2026

    @rdoupe
    CollaboratorAuthor

    Intentional difference of the port (PR #3769), as the testing policy asks: main() gets ", " between its mapped params (#3768). The C writes each straight after the one before it, so a function with two or more separately mapped params got float4 main(float4 pos : POSITIONfloat2 uv : TEXCOORD0) and its shader failed to compile. Every shader with at most one mapped param, as every stock effect has, comes out byte for byte the same.

    It is listed in the core's docs (obs_graphics::effect_parser::writer), in shader::effect_parser_writer_parity, which compares exactly those calls with the C's main() rewritten with the commas, and in rust/README.md. test_effect_parser_writer keeps pinning the C writer's output, so it has no _rust variant.

  6. moved this from In progress to In review in obs-rust Multiviewon Nov 6, 2026
  7. rdoupe commented on Nov 7, 2026

    @rdoupe
    CollaboratorAuthor

    Fixed by PR #3769 (merged through the merge queue), after the extraction in #3766: the effect parser's shader writer is now in obs-graphics's effect_parser module, with ep_makeshaderstring() as the hidden C shim over it. The port's one intentional difference, commas between main()'s mapped params, closed #3768.

    What's left: the effect parser's function parser and lookups (the port of the moved funcs file, blocked on a C change landing first) is #3623. The rest of effect-parser.c.h (ep_parse(), the ep_compile* steps and ep_parse_other()) has no issue of its own yet; it sits under the Phase 6 meta issue (#444) and gets one when someone claims it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancementportready

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions