Repository navigation
Description
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_creategs_texrender_destroygs_texrender_begings_texrender_begin_with_color_spacegs_texrender_endgs_texrender_resetgs_texrender_get_texturegs_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 fromdestroy,endandreset.gs_texrender_get_format(NULL)dereferences it. beginreturns false, with no graphics call, once rendered (untilreset) or for a zero width or height.- A new size destroys the texture and zstencil, then creates a
GS_RENDER_TARGETtexture with one level and no data, then a zstencil unless the format isGS_ZS_NONE. If the zstencil fails, the texture is destroyed again. beginpushes 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_SRGBforgs_texrender_begin) and the viewport0, 0, cx, cy.endrestores the saved state, pops in reverse, and sets rendered.
Characterized, not endorsed:
- A failed texture create still stores the new size. A second
beginat the same size does not retry and returns false. A different size retries. - A second
beginbeforeendsaves the texrender's own target as the previous one, so neitherendrestores the original target. endwithoutbeginrestores the zeroed previous state (no target, no zstencil, sRGB). It pops the projection, and it sets rendered, so the nextbeginfails untilreset.- The viewport size is the
uint32_tsize cast toint.
Plan
One PR, as #1846 asks:
- Characterization:
test/cmocka/test_texture_render.c, 13 cases. No Rust. It passes on the C build, the C reference and hybrid libobs. - RED: Tier 1 in the existing
obs-tests-graphicsbinary, against atodo!()safe core. - GREEN: the safe core drives a
Devicetrait in the C call order. The#[no_mangle]shim implements it with the publicgs_*functions, and it allocates the texrender withbmalloc, sobnum_allocscounts it as before.texture-render.c.hmoves tolibobs.ported-graphics+.h.c. Windows exports go inrust-exports.d/obs-graphics-texture_render.txt. Public headers and the exported symbol set do not change. - Tier 3: the original file is built as
oracle_gs_texrender_*. Both sides call one recordinggs_*stand-in in the oracle crate. A proptest over operation sequences compares the full call log with arguments, every return value andbnum_allocsafter each step. A deliberate break must fail it. - The rust/README.md row and
port_comparisonpairs.
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.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
rdoupe commentedon Oct 23, 2026
Claiming: #1860 (unit 5 of #1846). Characterization, port and parity are ready; PR follows.
obs-graphics: Port graphics/texture-render.c.h to Rust (obs-rust#1861)