Skip to content

libobs: GS_FLIP_U mirrors a sprite instead of drawing it upside down (#2124) - #2135

Merged
zackees merged 5 commits into
masterfrom
fix/sprite-flip-u
Oct 24, 2026
Merged

zackees merged 5 commits into
masterfrom
fix/sprite-flip-u

Conversation

@zackees

@zackees zackees commented Oct 24, 2026 •

Copy link
Copy Markdown
Member

Fixes #2124

What

gs_draw_quadf() drew every flipped 2D texture from the one static buffer flipped on v (flip ? flipped_sprite_buffer : sprite_buffer, since upstream 7b8b51b), so GS_FLIP_U drew a texture upside down instead of mirroring it. That hit PipeWire capture of Flipped/Flipped180 streams, and a full-size gs_draw_sprite_subregion().

  • graphics_init_sprite_vbs() now builds four static 1x1 sprites (plain, u, v, uv) in graphics_subsystem.sprite_buffers[4] (graphics-internal.h, not a public header).
  • gs_sprite_quad_flipped_buffer() (bool) is renamed gs_sprite_quad_buffer() (uint32_t, the index of the buffer to draw).
    • A flip with GS_FLIP_U set picks flip & (GS_FLIP_U|GS_FLIP_V): u or uv.
    • Every other flip picks what upstream picked: plain for 0, and the v buffer for GS_FLIP_V or for a flip made only of unknown bits.
    • The same change is in the C (graphics-sprite.c.h) and in the Rust port (obs-graphics::sprite, the one the hybrid build links).
  • The export lists (rust-exports.map, rust-hidden.txt, rust-unexports-macos.txt) are renamed in place. The function is still hidden and not EXPORT. Its only consumer is graphics.c.h.
  • The plain and v buffers are built from the same gs_sprite_uv_norm(0) / gs_sprite_uv_norm(GS_FLIP_V) as before and are chosen for exactly the same flips. Only the GS_FLIP_U and GS_FLIP_U|GS_FLIP_V (with or without unknown bits) draws change.

Changed pinned rows (signed off on #2124 under the Decided: conditions)

test/cmocka/test_sprite_geometry_steps.c (an existing C test; edit approved on #2124):

  • quad_flipped_buffer becomes quad_buffer. Rows that stay as upstream had them: 0 → none, and every flip without GS_FLIP_U → the v buffer (FLIP_V, 1<<2, FLIP_V|1<<31, 0xfffffffc). Changed rows, the GS_FLIP_U ones: FLIP_U → u (was v), FLIP_U|FLIP_V → uv (was v), FLIP_U|1<<2 → u (was v), FLIP_U|FLIP_V|0xfffffff0 → uv (was v), UINT32_MAX → uv (was v).
  • static_sprite_buffers: new build rows for the FLIP_U and FLIP_U|FLIP_V buffers. The plain and v rows are untouched.

rust/obs-graphics/tests/render/sprite.rs: the same rows in steps_quad_buffer and in the edge_quad_rules proptest, plus the u and uv rows in steps_static_sprite_buffers.

Tier 3: the oracle keeps upstream's code

rust/obs-c-oracle/oracle/graphics_sprite.c now carries upstream's selection as oracle_gs_sprite_quad_flipped_buffer() (return flip != 0;, any bit picks the v buffer). The Rust binding uses that function. The tree's fixed gs_sprite_quad_buffer() is still compiled into the oracle under its oracle_ rename, so the symbol cannot clash with the Rust shim, but nothing binds it.

sprite_parity.rs check_quad_buffer runs every flip of the low 16 bits with four high halves, plus a proptest:

Evidence

RED, rerun on the RED commit exactly as pushed (8391102bf, full Tier 2 rust/tools/linux-validate/run.sh):

[ RUN      ] sprite_plain             [       OK ]
[ RUN      ] sprite_flip_u            [  FAILED  ]  gs_draw_sprite flip 1: pixel (0, 0) is RGBA 40 220 0 255, want texel (3, 0) = 220 40 0 255
[ RUN      ] sprite_flip_v            [       OK ]
[ RUN      ] sprite_flip_uv           [  FAILED  ]  gs_draw_sprite flip 3: pixel (0, 0) is RGBA 40 220 0 255, want texel (3, 3) = 220 220 0 255
[ RUN      ] subregion_whole_plain    [       OK ]
[ RUN      ] subregion_whole_flip_u   [  FAILED  ]  gs_draw_sprite_subregion (whole) flip 1: pixel (0, 0) is RGBA 40 220 0 255, want texel (3, 0) = 220 40 0 255
[ RUN      ] subregion_whole_flip_v   [       OK ]
[ RUN      ] subregion_whole_flip_uv  [  FAILED  ]  gs_draw_sprite_subregion (whole) flip 3: pixel (0, 0) is RGBA 40 220 0 255, want texel (3, 3) = 220 220 0 255
[ RUN      ] subregion_part_*         [       OK ] (all four)
[  PASSED  ] 8 test(s).
[  FAILED  ] tests: 4 test(s): sprite_flip_u, sprite_flip_uv, subregion_whole_flip_u, subregion_whole_flip_uv
(16 of 16 pixels wrong in each failing case)
99% tests passed, 3 tests failed out of 442: test_sprite_flip_render, test_sprite_geometry_steps_rust, test_sprite_geometry_steps

Rust RED: steps_quad_buffer ... FAILED, edge_quad_rules ... FAILED.

GREEN:

  • Tier 2 on 137efc261: 100% tests passed, 0 tests failed out of 442, in both modes.
  • After the later commits (2227b6c60, b294408f4): ctest -R sprite in the same Tier 2 build tree passed 3 of 3 (test_sprite_flip_render, test_sprite_geometry_steps, test_sprite_geometry_steps_rust).
  • soldr cargo test -p obs-graphics: 306 passed, 0 failed.
  • ./lint: rc 0.

Empty draws right after obs_reset_video()

The first RED run had sprite_plain read back an all-zero target. I put a diagnostic build in the Tier 2 container (Mesa llvmpipe, Xvfb) and ran the binary on its own:

  • The first draw after obs_reset_video() read back all zeros every time (about 10 ms, no GL error logged).
  • In most runs the second draw read back correctly. In 2 of 12 runs, four warm-up draws in a row were all empty, and in 1 of those the first cases also failed. So a single warm-up draw was not enough.
  • After a 3 s wait the first draw read back correctly in 25 of 25 runs.

So it is a startup window: it closes with time, not after some number of draws. Not root-caused. The graphics thread starts rendering frames on the same device at that time, and my guess is something in how the device or EGL context settles on llvmpipe, but I could not confirm it. The test now polls before running any case: it draws until three plain draws in a row read back, for up to 3 s, and fails setup if they never do. With that, 40 of 40 standalone runs passed. The case assertions are unchanged.

@zackees

zackees commented Oct 24, 2026

Copy link
Copy Markdown
Member Author

Holding this PR against the Decided: conditions on #2124. Two changes are in progress:

  • Condition 3: the C oracle has to keep upstream's buffer selection, with the differential test recording U and U|V as an intended divergence. This PR currently changes the oracle too, through the shared graphics-sprite.c.h.
  • Condition 1: the unknown-bits behavior change is out of scope and will be reverted.

I'll also rerun the RED as committed. Auto-merge stays off until these are done.

@zackees
zackees disabled auto-merge October 24, 2026 11:42
@zackees

zackees commented Oct 24, 2026

Copy link
Copy Markdown
Member Author

Coordinator, FYI for the rework: the Linux Tier 2 (tests ON) failure is the new test. In run 40090743951, test_sprite_flip_render fails at test/cmocka/test_sprite_flip_render.c:158: error: Failure!; the other 442 passed. I'm leaving auto-merge off while you hold it.

@zackees

zackees commented Oct 24, 2026

Copy link
Copy Markdown
Member Author

Rework done; checked against the Decided: conditions on #2124:

  1. Only the GS_FLIP_U and U|V rows changed, each listed in the body. Plain, V, rectangle-texture and subregion rows are untouched. Unknown-bit-only flips keep upstream's v buffer.
  2. RED stands on its own: Tier 2 on 8391102 exactly as pushed fails sprite_flip_u, sprite_flip_uv and subregion_whole_flip_u/_uv, and passes plain, V and the partial cases.
  3. The oracle keeps upstream's flip != 0 choice (oracle_gs_sprite_quad_flipped_buffer). sprite_parity.rs compares all non-U flips exactly and records the U cases as the intended divergence.

The empty first draw after obs_reset_video isn't root-caused: it's a startup window that closes with time. The test now waits for three good plain draws, up to 3 s, before running the cases. Re-enabling auto-merge; PR CI runs the full suite on this head.

@zackees
zackees enabled auto-merge October 24, 2026 12:46
zackees added a commit that referenced this pull request Oct 24, 2026
Adds test_sprite_flip_render: a real-libobs render of a 4x4 texture with
gs_draw_sprite() and gs_draw_sprite_subregion() (whole and partial) for
each flip, read back pixel by pixel. Renames gs_sprite_quad_flipped_buffer()
to gs_sprite_quad_buffer(), returning which static buffer to draw (the flip
bits of its coordinates), still with the upstream choice, and updates the
pinned characterization rows in test_sprite_geometry_steps and the Rust
step tests to each axis following its own bit (maintainer sign-off).
graphics_init_sprite_vbs() builds four static 1x1 sprites (plain, flipped
on u, on v, on both) and gs_draw_quadf() draws the one
gs_sprite_quad_buffer() names, flip & (GS_FLIP_U | GS_FLIP_V), in the C and
the Rust port alike. GS_FLIP_U now mirrors a 2D texture instead of drawing
it upside down; the plain and GS_FLIP_V buffers are built and drawn as
before.
…tream's choice (#2124)

gs_sprite_quad_buffer() changes only the GS_FLIP_U and GS_FLIP_U |
GS_FLIP_V choices: a flip of only unknown bits picks the v-flipped buffer
again, as upstream. The C oracle keeps upstream's selection as
oracle_gs_sprite_quad_flipped_buffer() (any bit: flipped on v), and the
differential test compares every flip against it except those with
GS_FLIP_U set, the intended divergence, checked on the shim alone.
…m-up draw (#2124)

Right after obs_reset_video() draws can read back an empty target for a
few draws (seen with four warm-up draws in 1 of 12 runs under llvmpipe and
Xvfb). Probe until three plain draws in a row read back, for up to 3 s;
40 of 40 runs then pass.
@zackees

zackees commented Oct 24, 2026

Copy link
Copy Markdown
Member Author

Coordinator: rebased onto master. The only conflict was docs/features.md, where #2140's line for #2137 sits next to this PR's line for #2124. I kept both. Auto-merge is still on.

@zackees
zackees added this pull request to the merge queue Oct 24, 2026
Merged via the queue into master with commit 4360dd4 Oct 24, 2026
37 checks passed
@zackees
zackees deleted the fix/sprite-flip-u branch October 26, 2026 15:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

libobs: GS_FLIP_U draws a texture upside down instead of mirrored (PipeWire flipped capture)

1 participant