Skip to content

rust: Port graphics/effect-lookups.c to obs-graphics #1822

Closed

Description

@nathan-v

Unit

libobs/graphics/effect.c.h, the name and index lookups, into rust/obs-graphics. They move to libobs/graphics/effect-lookups.c.h. About 110 lines. They walk arrays on a gs_effect the caller already built. They do not call the graphics device.

  • gs_effect_get_technique
  • gs_effect_get_current_technique
  • gs_effect_get_num_params
  • gs_effect_get_param_by_idx
  • gs_effect_get_param_by_name
  • gs_param_get_num_annotations
  • gs_param_get_annotation_by_idx
  • gs_param_get_annotation_by_name
  • gs_technique_get_pass_by_idx
  • gs_technique_get_pass_by_name
  • gs_effect_get_viewproj_matrix
  • gs_effect_get_world_matrix
  • gs_effect_get_param_info

These stay in effect.c.h: gs_effect_destroy, gs_effect_loop, technique begin and end, begin_pass and end_pass, parameter upload, and the setters. They call the device (gs_get_effect, cur_effect, shader load).

Phase and position

Phase 6 (#444). Graphics math is already in obs-graphics (Phase 5). Shader parameter names are ported (#839). The effect-parser lifecycle is already its own C file. This slice is next: a pure walk of the effect arrays, and it does not share a file with an open port. The rest of effect.c.h waits until the device side has a seam.

Dependencies and existing tests

The functions take the public typedefs in graphics.h (gs_effect_t, gs_technique_t, gs_epass_t, gs_eparam_t, gs_effect_param_info). The structs are complete in graphics/effect.h. A test can fill them with effect_init, effect_param_init and effect_technique_init and never start a GPU.

No cmocka test covers these lookups. The characterization lands first, with the move, and links OBS::libobs. The symbols are EXPORT, so the test calls them through libobs and will see the later swap. It does not compile the .c.h into itself.

Name walks are a first-match strcmp. A missing name returns NULL. A null effect returns NULL, or 0 from gs_effect_get_num_params. A null param returns 0 annotations and NULL annotation pointers, and gs_effect_get_param_info returns without writing info. A null technique returns NULL passes.

Index checks, as the C is today:

  • gs_effect_get_param_by_idx returns NULL when the index is greater than or equal to params.num.
  • gs_param_get_annotation_by_idx and gs_technique_get_pass_by_idx return NULL only when the index is greater than the count. An index equal to the count returns one past the array. The test compares that pointer and does not dereference it.

gs_effect_get_current_technique returns the stored pointer even when that technique is not in the techniques array. View-proj and world are the stored pointers.

Plan

  1. Characterization PR, opening with the claim. Move the functions verbatim into libobs/graphics/effect-lookups.c.h, include it from libobs/build/libobs.graphics+.h.c, and add test/cmocka/test_effect_lookups.c. No Rust, no public header change, no behavior change. Refs this issue.
  2. Port PR after that merges. RED, then GREEN, in obs-graphics. Tier 1 ports the cmocka cases. Tier 2 runs the same test with Rust off and on. Tier 3 compares the lookups to the moved C. Tier 4 does not apply. The Rust tests join the existing obs-tests-graphics binary.

Notes

The one-past return on an annotation index or a pass index equal to the count is characterized, not endorsed. This plan does not change it. A fix, if one is wanted, should land before the port so the port copies the fixed C.

Activity

  1. nathan-v commented on Oct 22, 2026

    @nathan-v
    ContributorAuthor

    Claiming: graphics/effect-lookups.c

    1. Characterization PR, opening now. Move the lookups verbatim from effect.c.h into graphics/effect-lookups.c.h (same graphics unity group, no behavior change) and add a cmocka test that links libobs. The test pins first-match names, null inputs, and the index checks as they are: a param index uses >= and returns null at the count, while an annotation index and a pass index use >, so an index equal to the count returns one past the array. That one-past return is characterized, not endorsed. No Rust.
    2. Port PR after the characterization merges. RED, then GREEN, in obs-graphics, with a layout check and a differential against the moved C. The cmocka test stays unchanged.

    First PR today.

  2. added
    claimed
    on Oct 22, 2026
  3. nathan-v commented on Oct 22, 2026

    @nathan-v
    ContributorAuthor

    Characterization PR: #1823 (draft). test_effect_lookups passed 5/5 before the move and 5/5 after, on macOS arm64, Rust off. The Rust port is still the second step.

  4. nathan-v commented on Oct 22, 2026

    @nathan-v
    ContributorAuthor

    The Rust port is up as a draft: #1843

    RED is 056a97b. The five lookup tests panic in todo!(). GREEN is next on the same branch.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    claimed

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions