Skip to content

rust: Port graphics/texture-render.c.h to obs-graphics #1860

Closed

Description

@rdoupe

Unit

libobs/graphics/texture-render.c.h, all of it, into rust/obs-graphics. About 150 lines. Unit 5 of #1846. It is the gs_texrender_* state machine: it sizes a render-target texture and an optional zstencil buffer, saves the current render state in begin, and restores it in end.

  • gs_texrender_create
  • gs_texrender_destroy
  • gs_texrender_begin
  • gs_texrender_begin_with_color_space
  • gs_texrender_end
  • gs_texrender_reset
  • gs_texrender_get_texture
  • gs_texrender_get_format

Phase and position

Phase 6 (#444). Graphics math, the effect-parser lifecycle and the effect lookups (#1822) are already in obs-graphics. The file is its own unity include, so the whole file leaves the production build. It does not share a file with an open port.

Dependencies and existing tests

struct gs_texture_render is private to the file, and callers only hold the gs_texrender_t pointer, so there is no struct layout to keep. The file reads no other private layout. It calls only public graphics.h functions: gs_texture_create, gs_zstencil_create, gs_texture_destroy, gs_zstencil_destroy, gs_viewport_push and _pop, gs_projection_push and _pop, gs_matrix_push, _pop and _identity, gs_get_render_target, gs_get_zstencil_target, gs_get_color_space, gs_set_render_target_with_color_space and gs_set_viewport. It also calls bzalloc and bfree. graphics.c.h stays C. The Rust shim calls those functions the way obs-missing-files calls obs_source_get_name: libobs links the real ones, and cargo tests get a stand-in. No new dependency, no FFmpeg, no CI change.

No test covers texrender today. The characterization needs no GPU and no display. It builds a graphics_t by hand, sets its exports to a fake device that records each call, and enters it with gs_enter_context. Then it calls the exported gs_texrender_* through OBS::libobs. The same test runs against the C build, the C reference and hybrid libobs, and it will see the swap. Only the test fixture reads graphics-internal.h. The port does not.

Behavior, as the C is today:

  • A null texrender returns: false from both begins, NULL from get_texture, and nothing from destroy, end and reset. gs_texrender_get_format(NULL) dereferences it.
  • begin returns false, with no graphics call, once rendered (until reset) or for a zero width or height.
  • A new size destroys the texture and zstencil, then creates a GS_RENDER_TARGET texture with one level and no data, then a zstencil unless the format is GS_ZS_NONE. If the zstencil fails, the texture is destroyed again.
  • begin pushes the viewport, the projection and the matrix, sets identity, and saves the render target, zstencil target and color space. Then it sets its own target in the given space (GS_CS_SRGB for gs_texrender_begin) and the viewport 0, 0, cx, cy. end restores the saved state, pops in reverse, and sets rendered.

Characterized, not endorsed:

  • A failed texture create still stores the new size. A second begin at the same size does not retry and returns false. A different size retries.
  • A second begin before end saves the texrender's own target as the previous one, so neither end restores the original target.
  • end without begin restores the zeroed previous state (no target, no zstencil, sRGB). It pops the projection, and it sets rendered, so the next begin fails until reset.
  • The viewport size is the uint32_t size cast to int.

Plan

One PR, as #1846 asks:

  1. Characterization: test/cmocka/test_texture_render.c, 13 cases. No Rust. It passes on the C build, the C reference and hybrid libobs.
  2. RED: Tier 1 in the existing obs-tests-graphics binary, against a todo!() safe core.
  3. GREEN: the safe core drives a Device trait in the C call order. The #[no_mangle] shim implements it with the public gs_* functions, and it allocates the texrender with bmalloc, so bnum_allocs counts it as before. texture-render.c.h moves to libobs.ported-graphics+.h.c. Windows exports go in rust-exports.d/obs-graphics-texture_render.txt. Public headers and the exported symbol set do not change.
  4. Tier 3: the original file is built as oracle_gs_texrender_*. Both sides call one recording gs_* stand-in in the oracle crate. A proptest over operation sequences compares the full call log with arguments, every return value and bnum_allocs after each step. A deliberate break must fail it.
  5. The rust/README.md row and port_comparison pairs.

Tier 2 is the characterization, unchanged. Tier 4 does not apply.

Notes

No intentional differences. The behaviors above are kept. A fix, if one is wanted, should be its own change.

Activity

  1. rdoupe commented on Oct 23, 2026

    @rdoupe
    CollaboratorAuthor

    Claiming: #1860 (unit 5 of #1846). Characterization, port and parity are ready; PR follows.

  2. added
    claimed
    on Oct 23, 2026
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