Skip to content

rust: Port graphics/shader-parser.c to obs-graphics #1785

Open

Description

@vpacher

Unit

Port shader_parse and its sp_parse_* helpers in libobs/graphics/shader-parser.c.h to the existing obs-graphics crate. Not in scope: shader_sampler_convert (#1716) and the name lookups get_shader_param_type, get_sample_filter, get_address_mode (#839).

Phase and position

Phase 6 (#444): "the effect/shader parser" is a claimable unit there. The effect parser lifecycle is done (#1644, #1650). The shader parser is the smaller of the two parsers and has no claim.

Dependencies and existing tests

  • shader_parse (EXPORT) runs cf_parser_parse, which calls the cf preprocessor. cf-parser and cf-tokenizer are ported; the cf preprocessor is rust: Port util/cf-lexer.c (cf preprocessor) to obs-util #1499 (claimed). The Rust swap waits for rust: Port util/cf-lexer.c (cf preprocessor) to obs-util #1499. The C characterization does not.
  • The result is the public struct shader_parser in shader-parser.h: DARRAYs of shader_var, shader_struct, shader_sampler and shader_func, plus the cf_parser and its tokens. The header's static inline init, free and lookup functions use these fields directly.
  • Direct users of the fields: libobs-opengl (gl-shaderparser.c.h walks the tokens between shader_func.start and .end to write GLSL), libobs-d3d11 (d3d11-shaderprocessor.cpp.hpp) and libobs-metal (OBSShader.swift). The port must fill the same C layouts, with memory from bmalloc so that shader_parser_free can release it, and with start/end pointing into cfp's token array.
  • Existing tests: test_shader_param_names and test_shader_sampler_convert cover the parts that are already split off. No test covers shader_parse.

Plan and notes

  1. C-only characterization PR: a cmocka test against the real exported shader_parse, run against the C reference and the hybrid. It covers uniform and const parameters, arrays and assignments (int, float, float array), structs, samplers, functions with parameters, mappings and return types, the lookup functions, the start/end tokens of each function body, and the error text and position for malformed input. A corpus check parses shader text taken from the shipped .effect files and compares a digest of each result.
  2. Rust RED, then GREEN, in obs-graphics after rust: Port util/cf-lexer.c (cf preprocessor) to obs-util #1499 merges, with layout assertions for the public structs and differential parity against the C oracle on the characterization inputs. A fuzz target follows docs/rust-port/fuzzing.md.
  3. Swap: move the file to the ported list (LIBOBS_PORTED_SOURCES).

No intended behavior changes and no protocol surface. Any difference from the C code goes to its own issue first.

Activity

  1. vpacher commented on Oct 22, 2026

    @vpacher
    MemberAuthor

    Claiming: graphics/shader-parser.c (shader_parse and the sp_parse_* helpers), characterization first.

    1. C-only characterization PR (next): a cmocka test against the real exported shader_parse, against the C reference and the hybrid. Parameters, structs, samplers, functions, lookups, the function body tokens (start/end) that the OpenGL backend walks, error text and position, plus a corpus digest over shader text taken from the shipped .effect files.
    2. Rust RED/GREEN in obs-graphics after rust: Port util/cf-lexer.c (cf preprocessor) to obs-util #1499 (cf preprocessor) merges: layout assertions for the public structs, differential parity against the C oracle, fuzz target.
    3. Swap to the ported list.

    Decisions:

    • The Rust code fills the existing C structs (bmalloc memory, start/end into cfp's tokens) and does not change shader-parser.h. Reason: libobs-opengl, libobs-d3d11 and libobs-metal read the fields directly.
    • The PRs do not depend on rust: Port util/cf-lexer.c (cf preprocessor) to obs-util #1499 until step 2. The characterization PR uses the cf code that is on master.
  2. added
    claimed
    and removed
    claimed
    on Oct 22, 2026
  3. zackees commented on Oct 24, 2026

    @zackees
    Member

    @vpacher, are you still on this? The claim from 2026-10-22 has lapsed, and I found no PR here (or a characterization PR for shader_parse). If you've stopped, I'll take it from the characterization step in your plan. If there's a branch, link it and I'll build on it. I'll take it over tomorrow (2026-10-25) if there's no reply.

  4. vpacher commented on Oct 24, 2026

    @vpacher
    MemberAuthor

    Claiming: graphics/shader-parser.c (shader_parse and the sp_parse_* helpers).

    @zackees yes, I am still on this. The characterization step waits on non-public work that is coordinated with a maintainer, and the Rust step waits on #1499. There is no public branch yet. I will mark the claim blocked in the next comment.

  5. added
    claimed
    on Oct 24, 2026
  6. vpacher commented on Oct 24, 2026

    @vpacher
    MemberAuthor

    Blocked: waiting on #1499 and on non-public work that is coordinated with a maintainer.

  7. added
    claim-blocked
    on Oct 24, 2026
  8. moved this from In progress to Blocked in obs-rust Multiviewon Oct 25, 2026
  9. added
    ready
    and removed
    claimed
    on Oct 25, 2026
  10. removed
    claim-blocked
    on Oct 25, 2026
  11. moved this from Blocked to In progress in obs-rust Multiviewon Oct 25, 2026
  12. vpacher commented on Oct 25, 2026

    @vpacher
    MemberAuthor

    Blocked: waiting on #1499 and on non-public work that is coordinated with a maintainer.

  13. added
    claim-blocked
    on Oct 25, 2026
  14. moved this from In progress to Blocked in obs-rust Multiviewon Oct 25, 2026
  15. removed
    claim-blocked
    on Nov 1, 2026
  16. nathan-v commented on Nov 7, 2026

    @nathan-v
    Contributor

    Claiming: #1785, the characterization of shader_parse.

    1. C-only characterization PR today: a cmocka test against the exported shader_parse. It pins functions (params, mappings, and the token range the GL backend walks from start), the header lookups, and error text and position. Sampler-state and struct blocks stay with test_shader_parser_blocks. Number defaults stay with test_shader_number_defaults. No change to shader-parser.h.
    2. The Rust port waits on rust: Port util/cf-lexer.c (cf preprocessor) to obs-util #1499. I'll pick that up after the preprocessor lands.

    The characterization PR should be up today.

  17. github-actions commented on Nov 7, 2026

    @github-actions

    Claim bot: @nathan-v, this can't be claimed yet: it is blocked by 1 open issue(s) (see "Blocked by" on the issue); claim it once they close.

  18. vpacher commented on Nov 8, 2026

    @vpacher
    MemberAuthor

    This is blocked by #1499, which is mine and waits on non-public work that is coordinated with a maintainer. I'll claim #1785 once #1499 is closed. @nathan-v, please hold the characterization PR until then, so it builds on the port in #1499.

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

    ready

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions