Skip to content

rust: Port the effect parameter values in graphics/effect.c to obs-graphics (effect.c slice 1) #2409

Closed

Description

@vpacher

Unit

The parameter values of libobs/graphics/effect.c.h (433 lines), into rust/obs-graphics as obs_graphics::effect_params. Slice 1 of effect.c; it follows the effect lookups (#1822, #1843) and the effect-parser lifecycle (#1644) in the same crate.

The 17 public functions that set and read a parameter's value, all EXPORT:

  • the setters: gs_effect_set_bool, _float, _int, _matrix4, _vec2, _vec3, _vec4, _color, _texture, _texture_srgb, _val, _default, and gs_effect_set_next_sampler;
  • the getters: gs_effect_get_val, gs_effect_get_val_size, gs_effect_get_default_val, gs_effect_get_default_val_size;
  • the shared core, effect_setval_inline (resize cur_val when the size changes, copy and set changed only when the bytes differ) and the two getter copies (at most the stored size).

Every filter and scene item sets its effect parameters on every frame, so the setters are on the hot path.

These stay C in this slice: everything that touches the graphics device or the pass state: gs_effect_loop, gs_technique_begin / _end, gs_technique_begin_pass / _by_name / _end_pass, gs_effect_update_params and the upload (upload_shader_params, clear_tex_params, reset_params), and gs_effect_destroy. They are slice 2.

Phase and position

Phase 5/6 graphics (obs-graphics), next to effect_lookups and effect_parser_lifecycle.

Seam

  • Structs: struct gs_effect_param is already mirrored #[repr(C)] in obs-graphics::ffi::effect_lookups, with layout tests (obs-graphics: Port effect name and index lookups #1843). This slice reuses it: cur_val and default_val (DARRAY(uint8_t)), changed, next_sampler, type. No new layout crosses; no public header changes.
  • Memory: cur_val is resized in place through obs_util::ffi::darray (bmem, as effect_free frees it with da_free); gs_effect_get_val and gs_effect_get_default_val return bzalloc memory, which the caller frees with bfree, so the shim allocates through obs-util's bmem.
  • Logging: the four LOG_ERROR lines ("effect_setval_inline: invalid param" / "invalid data", "gs_effect_get_val: invalid param", "gs_effect_get_default_val: invalid param", "gs_effect_set_next_sampler: invalid param") go through the existing log helper the graphics shims use (image_file), with the same text.
  • vec4_from_bgra (gs_effect_set_color) is a header inline in graphics/vec4.h, not in the Rust vec4 port yet; the slice ports it as a helper with its own parity case.
  • No device: none of these functions calls into the graphics subsystem, so no Device trait is needed in this slice.

Characterized behaviour to keep (from reading; to pin with tests)

  • gs_effect_set_default on a parameter without a default passes the NULL default_val.array on, so it logs "invalid data" and keeps the current value (partly covered by test_effect_set_default_null, libobs/graphics: gs_effect_set_default dereferences a NULL param #2210).
  • gs_effect_set_vec3 stores 12 bytes (sizeof(float) * 3), not sizeof(struct vec3) (16 with the SSE lane); gs_effect_set_vec4 and _matrix4 store the whole struct.
  • gs_effect_set_bool stores an int (4 bytes).
  • Setting the same bytes again does not set changed; a different size always does (even with a common prefix).
  • gs_effect_set_next_sampler only takes effect on a GS_SHADER_PARAM_TEXTURE parameter and is silent otherwise.
  • The getters return NULL for a size of 0 and copy at most the stored size.

Existing tests

  • test_effect_set_default_null (libobs/graphics: gs_effect_set_default dereferences a NULL param #2210) runs the real setters with graphics up (Xvfb on Linux): a NULL parameter, the default put back, a parameter without a default.
  • Many render tests set effect parameters through the real libobs (test_color_correction_16f, test_scroll_filter_wide_source, test_sprite_flip_render, test_scene_rotated_scale_filter, ...). They are the Tier 2 for this slice.
  • No test pins the value rules above. New cases go into a new test_effect_param_values on a hand-built struct gs_effect_param (no graphics context needed): each setter's size and bytes, changed on same / different bytes and on a size change, the getters (NULL at 0, copy limits, freed with bfree), set_default with and without a default, next_sampler on texture and non-texture parameters, NULL parameter and NULL data (one log line each).

Plan

One PR, in this order:

  1. Characterization commit: test_effect_param_values against the C (libobs and libobs-c-reference).
  2. Extraction commit, behaviour-neutral: the parameter value functions move to libobs/graphics/effect-params.c.h (same unity group for now). The unchanged tests pass.
  3. RED: the safe core in obs-graphics (effect_params) with todo!(), Tier 1 tests (the cmocka cases 1:1, plus properties), failing.
  4. GREEN: the core and the #[no_mangle] shims for the 17 exported functions, the file moved to a libobs.ported-effect-params group, Tier 3 proptest against the C oracle (the extracted file), port_comparison numbers for gs_effect_set_float, _vec4, _matrix4 and _texture (same value and changed value).
  5. Tier 2: test_effect_set_default_null and the render tests above with Rust off and on. Exported symbols unchanged.

Next slice

Slice 2: the technique and pass loop with the parameter upload. It calls the graphics device (gs_load_vertexshader, gs_shader_set_val, gs_shader_set_next_sampler, gs_shader_get_param_info, gs_shader_set_texture), so it needs a Device trait as in texture_render, and a hidden C accessor for graphics->cur_effect (the graphics_subsystem layout does not cross). Filed when this one closes.

Activity

  1. vpacher commented on Oct 25, 2026

    @vpacher
    MemberAuthor

    Claiming: #2409

    Plan as in the description: one PR (characterization, extraction, RED, GREEN with Tier 3 and port_comparison, Tier 2). Progress notes here as the steps land.

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

    @vpacher
    MemberAuthor

    Progress: #2411 is open with the whole plan (characterization, extraction, RED, GREEN, Tier 3). Tier 2 6/6 on the hybrid and the C reference (the four render tests plus test_effect_param_values and test_effect_set_default_null), Tier 1/3 32/32 on Linux, mutation check 17/19 (the two survivors are equivalent). Slice 2 (the technique and pass loop with the upload) gets its own issue when this one closes.

  4. moved this from In progress to Done in obs-rust Multiviewon Oct 25, 2026
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