Skip to content

rust: Port the effect technique and pass loop in graphics/effect.c to obs-graphics (effect.c slice 2) #2421

Closed

Description

@vpacher

Unit

The technique and pass loop of libobs/graphics/effect.c.h, with the parameter upload, into rust/obs-graphics as obs_graphics::effect_passes. Slice 2 of effect.c, after #2409 (the parameter values, #2411, merged).

  • The exported functions: gs_effect_loop, gs_technique_begin, gs_technique_end, gs_technique_begin_pass, gs_technique_begin_pass_by_name, gs_technique_end_pass, gs_effect_update_params.
  • The static helpers: upload_shader_params (the next sampler, then the value or the default, only the changed ones on an update), upload_parameters (vertex then pixel shader, then changed cleared), reset_params, clear_tex_params (texture parameters set to NULL at the end of a pass).

Every draw in OBS runs this loop (while (gs_effect_loop(effect, "Draw"))), once per pass.

These stay C: gs_effect_destroy and gs_effect_actually_destroy (the effect's lifecycle through the header-inline effect_free, not on the hot path).

Phase and position

obs-graphics, next to effect_lookups, effect_parser_lifecycle and effect_params.

Seam

  • Structs: struct gs_effect, gs_effect_technique, gs_effect_pass and gs_effect_param are mirrored in ffi::effect_lookups. New: struct pass_shaderparam (eparam, sparam) for the vertshader_params / pixelshader_params arrays.
  • Device: a Device trait, as in texture_render, for gs_load_vertexshader, gs_load_pixelshader, gs_shader_set_val, gs_shader_set_next_sampler, gs_shader_get_param_info, gs_shader_set_texture and gs_get_effect. The shim implements it with the C functions.
  • graphics->cur_effect: gs_technique_begin / _end write it through the effect's graphics subsystem (tech->effect->graphics), not the thread's. struct graphics_subsystem does not cross: a hidden C setter in obs-graphics-adapter.c.h does the write.
  • Logging: the two LOG_WARNING lines of gs_effect_loop ("An effect is already active", "Technique '%s' not found.") go through the adapter with the C's literal formats and the name as the argument, as effect_params does for its errors.
  • Values: cur_val / default_val stay the C darrays; gs_technique_end empties cur_val (da_resize(.., 0)) through effect_params::DarrayStore.

Characterized behaviour to keep

  • gs_effect_loop begins the technique on the first call, ends the previous pass on each later call, and begins pass loop_pass++; when there is no next pass it ends the technique and resets looping and loop_pass.
  • A missing technique or an active effect (gs_get_effect()) logs a warning and returns false without changing state.
  • gs_technique_begin_pass_by_name returns true when the name matches, whatever gs_technique_begin_pass returns.
  • gs_technique_end loads NULL shaders, clears cur_technique and cur_effect, empties every parameter's cur_val, clears changed and drops next_sampler.
  • The upload sets the next sampler before it checks changed; with no value it copies the default into cur_val (da_copy) and uploads that; with neither it skips the parameter.

All of these are pinned by test_effect_pass_loop, done locally on top of #2411 and passing on libobs and libobs-c-reference.

Existing tests

  • Every render test runs the loop through the real libobs (test_color_correction_16f, test_scroll_filter_wide_source, test_sprite_flip_render, test_scene_rotated_scale_filter, test_effect_set_default_null, ...). They are the Tier 2.
  • No test pins the call sequence. New: test_effect_pass_loop compiles the moved C into itself with recording stubs for the device functions and gs_get_effect (no graphics context; every platform), on hand-built effects: one and two passes, a missing technique, an active effect, changed_only updates, defaults, next samplers, texture clearing, begin_pass_by_name, the end-of-technique reset.

Plan

One PR, in this order:

  1. Extraction commit, behaviour-neutral: the loop and upload move to libobs/graphics/effect-passes.c.h (same group for now); effect.c.h keeps the destroy functions.
  2. Characterization commit: test_effect_pass_loop against the C (libobs, libobs-c-reference).
  3. RED: the safe core in obs-graphics (effect_passes) on a Device trait, with todo!(); Tier 1 tests on a recording device (the cmocka cases 1:1, plus properties), failing.
  4. GREEN: the core, the 7 exported shims, the hidden cur_effect setter, the file in libobs.ported-graphics, Tier 3 (the C oracle and the shim against the same recording stubs: the same call sequence and the same effect state), port_comparison for a one- and a two-pass loop with 4 parameters.
  5. Tier 2: the render tests with Rust off and on. Exported symbols unchanged.

After this slice, effect.c.h keeps only gs_effect_destroy and gs_effect_actually_destroy.

Activity

  1. vpacher commented on Oct 25, 2026

    @vpacher
    MemberAuthor

    Claiming: #2421

    Plan as in the description: one PR (extraction, characterization, RED, GREEN with Tier 3 and port_comparison, Tier 2). The work is done locally on top of #2411; the PR follows after the checks on the rebased head.

  2. added
    ready
    on Oct 25, 2026
  3. vpacher commented on Oct 25, 2026

    @vpacher
    MemberAuthor

    Progress: #2422 is open with the whole plan (extraction, characterization, RED, GREEN, Tier 3). Tier 2 7/7 on the hybrid and the C reference, Tier 1/3 45/45 on Linux (three runs), mutation check 16/17 (the survivor is equivalent).

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

Metadata

Metadata

Assignees

Labels

ready

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions