Skip to content

rust: Port the effect parser's compile step #3792

Closed

Description

@rdoupe

Unit

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

  • ep_compile(): once ep_parse() finds no errors, fills the gs_effect from the parser: sizes effect->params and effect->techniques, then compiles each param and technique;
  • ep_compile_param(), ep_compile_param_annotations() and ep_compile_annotations(): each gs_effect_param (and annotation) gets a copy of its name, its section, its effect, its type (obs_effect_param_type()) and the parser's default value (moved, da_move); ViewProj and World are kept as effect->view_proj / effect->world;
  • ep_compile_technique() and ep_compile_pass(): each technique's and pass's name and section, with a "missing vertex/pixel shader" error logged for a pass whose shader fails;
  • ep_compile_pass_shader(): builds the shader text with ep_makeshaderstring() (the ported writer), creates the vertex or pixel shader, adds the device's compile errors to the parser's error list, then ep_compile_pass_shaderparams() pairs each used param with the effect's and the shader's param of that name.

The debug printers (debug_get_default_value(), debug_param(), debug_param_annotation(), debug_print_string(), only built with _DEBUG and _DEBUG_SHADERS) stay with ep_parse(), which prints with debug_print_string() too. ep_parse() calls ep_compile(), so its declaration goes into a new internal graphics/effect-parser-compile.h (a private adapter, not a new public API) and ep_compile() loses its static; under the same #if, debug_param() and debug_print_string() are declared there and lose theirs.

Phase and position

Phase 6 style (#444): a behaviour-neutral extraction, then the port. Crate obs-graphics, after the effect parser's shader writer (#3765, ported in #3769). Tracking: #4.

Dependencies and existing tests

Notes

  • A failed pass keeps whatever shader and params it got (effect_free() frees them later); the port must leave the same state and free nothing itself.
  • ViewProj and World are found with a case-sensitive strcmp.
  • Expected intentional difference for the port: the compile step's own debug lines are gone in _DEBUG_SHADERS builds (a developer-only define that no CI build sets). Nothing else changes.
  • Threads: effects are compiled on the graphics thread, inside gs_effect_create().

Activity

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

    @rdoupe
    CollaboratorAuthor

    Claiming: #3792.

    1. A new test_effect_parser_compile (cmocka): the original effect parser C compiled into the test, the shader-create calls and gs_shader_get_param_by_name() renamed to stand-ins with a table of fake shaders and params, pinning what ep_parse() puts in the gs_effect for fixed texts (params, annotations, defaults, view_proj / world, techniques, passes, shader params), the shader-create calls, the result, the errors and the logged lines. No graphics device, so it runs everywhere.
    2. graphics/effect-parser-compile.h declares ep_compile() (no longer static; hidden, not EXPORT), plus debug_param() and debug_print_string() under _DEBUG_SHADERS; the debug printers stay in effect-parser.c.h with ep_parse().
    3. Behaviour-neutral move of the ep_compile* functions into graphics/effect-parser-compile.c.h, in its own live unity group, checked with a move harness (master's and the moved C over the same inputs, GCC and Clang, -O0/-O2, ASan/UBSan, planted mutants) and identical export sets on the C, hybrid and C reference builds.
    4. Then the Rust port of the moved file in obs-graphics's effect_parser module (Tier 1, the hidden ep_compile() shim, Tier 3 against the C with mutation, the include into a ported group), in its own PR.

    Draft PR for 1 to 3 expected today.

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

    @rdoupe
    CollaboratorAuthor

    Continuing with step 4, the Rust port of the moved compile step (steps 1 to 3 landed in #3807):

    1. RED: Tier 1 tests in the shader test module against todo!() stubs, porting test_effect_parser_compile's cases one to one, with the shader backend (create, param lookups, errors, log) behind a trait.
    2. GREEN: the safe core in obs_graphics::effect_parser::compile, calling the ported param types and writer directly.
    3. The hidden ep_compile() shim, writing gs_effect, its params, techniques, passes and pass shader params in place as the C does, through gs_vertexshader_create(), gs_pixelshader_create(), gs_shader_get_param_by_name(), gs_effect_get_param_by_name(), cf_adderror() and blog(); layout tests against the C.
    4. Tier 3: an oracle of effect-parser-compile.c.h over a recording stub backend, and a proptest comparing the effect, the backend calls, the errors and the result, with a mutation check.
    5. The include moves into a ported unity group; Tier 2 on the C, hybrid and C reference builds, identical export sets.
    6. Docs. Intentional difference to record: the compile step's own debug lines are gone in _DEBUG_SHADERS builds.

    Draft PR expected today, once the RED commit exists.

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

    @rdoupe
    CollaboratorAuthor

    Progress: the Rust port of the compile step is in #3843. It includes Tier 1, the hidden ep_compile() shim swapped into the hybrid libobs, test_effect_parser_compile_rust running the unchanged C test against it, and Tier 3 parity with mutation. Local gate and PR CI were green, and it went to the merge queue, but the latest queue run failed its checks. Next: find out whether that failure is the PR's or a flake, fix it if it's ours, and re-queue.

  8. rdoupe commented on Nov 8, 2026

    @rdoupe
    CollaboratorAuthor

    Closed by the Rust port of the effect parser's compile step (PR #3843, merged through the merge queue). The compile step was first moved to its own file with a characterization test (PR #3807). The port covers ep_compile() and its helpers in obs_graphics::effect_parser::compile, the hidden ep_compile() shim in the hybrid libobs, the unchanged C test test_effect_parser_compile_rust against it, and Tier 3 parity with mutation.

    Left: nothing for this unit. The compile step's own debug lines are gone in _DEBUG_SHADERS builds (the expected, developer-only difference). The rest of the effect parser has no follow-up issue from this unit.

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