Skip to content

libobs: Keep an async rotation in 0-359 - #2136

Merged
zackees merged 2 commits into
obs-rust:masterfrom
rdoupe:fix/async-rotation-normalize
Oct 24, 2026
Merged

zackees merged 2 commits into
obs-rust:masterfrom
rdoupe:fix/async-rotation-normalize

Conversation

@rdoupe

@rdoupe rdoupe commented Oct 24, 2026

Copy link
Copy Markdown
Collaborator

Fixes #2121

What and why

An async source (a camera, capture card or media source) whose rotation is a multiple of 90 other than 0, 90, -90, 180 or 270 is drawn outside its item's box:

  • obs_source_set_async_rotation() stores any long.
  • get_async_width() and get_async_height() swap the axes for any rotation that is not a multiple of 180.
  • rotate_async_video() turns the picture about the item's top-left corner, and only moves it back into the box for 90, 270, -90 and 180.

So -180, -270, 450 and -450 turn the picture out of the box: the item shows nothing. A multiple of 90 near the ends of long turns by whatever angle RAD((float)rotation) leaves. 360, 720 and -360 already drew correctly, since a full turn needs no move. win-dshow's autorotation passes the device's roll through unchanged, and plugins and scripts can pass any value. Upstream has the same code.

The fix:

  • obs_source_set_async_rotation() stores the rotation in 0-359 (Euclidean modulo). rotation % 360 is in (-360, 360), so adding 360 cannot overflow, even for LONG_MIN.
  • rotate_async_video() drops its -90 case, which is now stored as 270.
  • 0, 90, 180 and 270 are stored as before. -90 is now drawn through the 270 case, which has the same move and an equivalent turn.
  • A rotation that is not a multiple of 90 keeps its axis swap, because 360 is a multiple of 180. How such a rotation is drawn (turned about the corner, with no move back and a swapped box) is unchanged and not defined by this fix.
  • The function reference now says that any multiple of 90 is taken as its equivalent in 0-359.

Callers (checked, not changed):

  • win-dshow (DShowInput::OnVideoData) is the only caller in the tree. It passes the device's CameraControl_Roll value when Autorotation is on and the value changed, and it compares the raw value with its own lastRotation, not with the stored one. That still works.
  • No getter exists, the rotation is not saved in the scene collection, and nothing else reads async_rotation. The frontend, obs-websocket and the other plugins do not call the setter. Scene item rotation is a separate path.

docs/features.md gets a line under fixed upstream bugs. Exported symbols: 1766 on the C backend, the hybrid and libobs-c-reference, and the three sets are identical.

RED → GREEN

  • RED commit: 6537a79af (test: Expect async rotations that are multiples of 90 to draw in the box). It adds test_async_rotation_normalize, a real-libobs test in the graphics suite, registered in test/cmocka/build/test-graph.json. The test does this for each case:

    • It creates an async test source with a 32x16 frame in four colours, sets the rotation, and shows the source alone on a 64x64 canvas.
    • It pushes frames at the canvas rate until an output frame, read back through a raw video callback, shows the picture turned by the equivalent rotation exactly in the item's box. Every pixel of each quadrant must be its quadrant's colour and everything outside must be black. It stops after 4 s.
    • It checks obs_source_get_width() and obs_source_get_height().

    On the RED commit it fails 3 of 5 on the C backend, the hybrid and libobs-c-reference:

    • equivalent_rotations_are_drawn_in_the_box: -180, -270, 450 and -450 show nothing in the box on any of 120 output frames. 360, 720 and -360 pass.
    • multiples_of_90_near_the_ends_of_long: with a 64-bit long, the nearest multiples of 90 are LONG_MAX - 7 and LONG_MIN + 8. Both are multiples of 360. The test also checks the next two in from each end. Five of the six show nothing in the box. LONG_MAX - 7 happens to draw unturned.
    • rotation_can_be_changed (-180, then 450, -90 and 0 on one shown source): -180 and 450 fail.
    • rotations_that_worked_are_unchanged (0, 90, 180, 270, and -90 drawn as 270) and other_rotations_keep_their_size pass. The second checks the axis swap of 1, -1, 45, -45, 135, 315, 359, -359, 361, LONG_MAX, LONG_MIN and LONG_MIN + 1.
  • GREEN: 52480b8eb. Results on the C backend, the hybrid and libobs-c-reference:

    • test_async_rotation_normalize 5/5.
    • Tests that push async frames: test_async_delay_audio 6/6, test_async_frame_pacing_steps 12/12, test_deinterlace_2x_field_order 73/73, test_deinterlace_pacing_steps 23/23, test_media_restart_first_frame 4/4, test_media_restart_stale_frame 5/5, test_media_sync_offset_restart 6/6, test_media_gif_last_frame 4/4, test_ffmpeg_restart_close 6/6, test_source_profiler 6/6, test_source_color_space_steps 12/12, test_video_frame 7/7, test_v4l2_controls 32/32, test_v4l2_corrupt_frame 10/10, test_v4l2_fd_cloexec 4/4 and test_v4l2_framerate 11/11. Also test_scene_rotated_scale_filter 6/6. No existing test sets an async rotation.
    • Full ctest: C backend 433/433, hybrid 444/444, libobs-c-reference 444/444, with 0 skipped and 0 not run. Each ran under its own Xvfb with D-Bus and a fresh HOME.
    • test_async_rotation_normalize 10 more times on each of the three: 30/30.
    • ci/local_gate.py --test-diff origin/master, --lane lint and --lane cross pass.

    Which commit each run was on:

    • The RED results are from the RED commit before the two rebases (f1d2004d3, on 1a008c7f4).
    • The focused GREEN runs, the three full ctests, --lane lint and --lane cross ran on the GREEN commit before master moved (652e5efb8, on 1a008c7f4).
    • After rebasing onto 1cddf78da, these ran again: the focused tests (plus test_deinterlace_mode_load 7/7 from libobs: Disable an out-of-range deinterlace mode instead of drawing nothing #2120), the export comparison, --test-diff and --lane lint. One C-backend run of test_deinterlace_2x_field_order failed one case under a load average near 40 (a skipped field, the timing flake in test_deinterlace_2x_field_order is timing-sensitive (yadif 2x 60i into 60): startup underrun and load-induced hold #456; that test never sets a rotation). Of three reruns, two passed 73/73 and one failed a different case the same way.
    • After the last rebase onto 6bae29730 (libobs: Keep source volumes finite and non-negative #2128, source volume, also in obs-source.c.h but in other functions), the final head 52480b8eb passed test_async_rotation_normalize 5/5, test_source_volume_mix 4/4, test_source_audio_ranges 13/13 and test_video_frame 7/7 on all three.
    • On b7946f881 (the same change on 7b39b1e95; the two master commits in that step do not touch these files), these passed on all three: test_async_rotation_normalize (11 runs each), test_deinterlace_mode_load, test_deinterlace_2x_field_order 73/73 and test_video_frame. The export comparison and --test-diff also passed.
  • Real app (UI, protocol output or logging changes): not run. There is no change to the UI, protocol output or logging.

Checklist

  • Base is master (or the description starts with a Stacked: note)
  • I claimed the issue, or no one else has an open PR for it
  • Characterization test (if the unit had none), then RED, then GREEN commits (N/A for docs-only; a focused CI fix may push RED and GREEN together)
  • User-visible change: its line in docs/features.md is added or updated (not applicable: no user-visible change)
  • (Optional) Local gate passed and the pushed head is stamped; otherwise PR CI runs the full suite
  • Warning or flag changes (-W..., ratchets): built with scripting ON (PR CI builds no OBS app: run gh workflow run ci.yml --ref <branch> for the full builds) and cross-checked with clang and MSVC
  • Intentional differences from C listed in the parity test header and rust/README.md (ports)

obs_source_set_async_rotation() stores any long. get_async_width() and
get_async_height() swap the axes for a rotation that is not a multiple of
180, but rotate_async_video() only moves the turned picture back into the
item's box for 90, 270, -90 and 180, so -180, -270, 450 and -450 are drawn
outside the box, and a multiple of 90 near the ends of long turns by
whatever angle its conversion to float leaves.

test_async_rotation_normalize shows an async test source with a 32x16
frame in four colours on channel 0, sets a rotation, and pushes frames
until an output frame shows the picture turned by the equivalent rotation
in 0-359 exactly in the item's box (for at most 4 s), and checks
obs_source_get_width() and obs_source_get_height(). It also pins the five
rotations that work today, and the axis swap of rotations that are not a
multiple of 90.

Refs obs-rust#2121
obs_source_set_async_rotation() stored any long, and rotate_async_video()
only moves the turned picture back into the item's box for 90, 270, -90
and 180. Any other multiple of 90 (-180, -270, 450, -450, or one near the
ends of long) was drawn outside the box, or turned by the angle its
conversion to float left.

The setter now stores the rotation in 0-359 (Euclidean modulo; the
remainder is in (-360, 360), so adding 360 cannot overflow at LONG_MIN),
and rotate_async_video() drops its -90 case, which is 270 now. 0, 90, 180
and 270 are stored as before, and -90 is drawn as 270 was. A rotation that
is not a multiple of 90 keeps its axis swap in get_async_width() and
get_async_height(), since 360 is a multiple of 180; how it is drawn is not
defined here.

The function reference says that any multiple of 90 is taken as its
equivalent, and docs/features.md gets a line under fixed upstream bugs.

Fixes obs-rust#2121
@rdoupe
rdoupe requested a review from zackees as a code owner October 24, 2026 11:39
@zackees
zackees added this pull request to the merge queue Oct 24, 2026
Merged via the queue into obs-rust:master with commit 56a9006 Oct 24, 2026
35 checks passed
rdoupe added a commit to rdoupe/obs-studio that referenced this pull request Oct 24, 2026
test_source_size_route_steps compiles libobs/obs-source-size.c.h (ASan
and UBSan) and calls only obs_source_size_route() and
obs_source_size_entry(). 11 cases:

- route_every_combination: a 128-row table, every combination of the type
  (an input, a filter, a transition, a scene), data, a size callback, a
  filter parent, enabled and async active, at rotation 0;
  route_every_combination_rotated, the same rows at 90, where only the
  async route turns into the swapped one;
- route_other_types_as_inputs: the filter type, scenes, -1, 4, INT_MIN and
  INT_MAX route as an input (only the transition type has a route of its
  own; a filter is a source with a filter parent);
- route_transition: the actual size while enabled and 0 while not, with
  any data, callback, parent or async;
- route_filter_chains: a filter with a size callback asks it only while
  enabled, a filter without one or without data asks its target, the input
  below asks its callback enabled or not, an async input reports its frame
  (0 before the first one), and a callback wins over the async frame;
- swap_rotations: 0, 90, -90, 180, -180, 270, -270, 45 and 360, the rest of
  0-359 (1, 179, 181, 359) and raw values the setter no longer stores (-360,
  540, -1). The setter normalizes since obs-rust#2136; the route takes any long;
- swap_long_extremes: LONG_MIN and LONG_MAX swap (% 180 is -128 and 127 for
  a 32-bit long, -8 and 7 for a 64-bit one), the multiples of 180 next to
  them do not, and on a 64-bit long the ends of int as well;
- swap_only_when_async: the rotation changes no other route;
- entry_points: a filter starts at itself with or without filters; an
  input, a transition, a scene and types outside the enum start at their
  first filter if they have filters, else at themselves.

Characterized, not endorsed:
- a filter that is not in a chain (no filter parent) asks its callback
  even while disabled, and without one reports its async frame or 0
  instead of asking a target; an input with a filter parent routes as a
  filter (8a1486d made the parent, not the type, the test);
- a source with a callback but no data does not ask it and reports its
  async frame or 0 (obs_source_get_width() checks data_valid() first, so
  libobs gets here only through a target or a first filter whose data is
  gone).

The test is in the native test graph in name order, with libm except on
MSVC, and uses fprintf() and fail() for its messages (cmocka 1.x and 2.x).
On the C backend it passes 11 of 11.

Refs obs-rust#2149
rdoupe added a commit to rdoupe/obs-studio that referenced this pull request Oct 24, 2026
* libobs: Move the source size query routing into obs-source-size.c

Behaviour-neutral extraction before the Rust port. The size query routing
of obs-source.c.h moves to libobs/obs-source-size.c.h, declared in the new
libobs/obs-source-size.h without EXPORT (hidden, as -fvisibility=hidden
keeps it), behind two functions:

- obs_source_size_route() takes the fields of a source in
  struct obs_source_size_node (the type, context.data != NULL, the size
  callback of the axis asked for != NULL, filter_parent != NULL, enabled,
  async_active and the long async_rotation) and gives where
  get_base_width() and get_base_height() take the size from: the
  transition's actual size while enabled, the callback (a filter only
  while enabled), the filter target, the async frame (ASYNC, or
  ASYNC_SWAPPED unless rotation % 180 == 0: get_async_width() and
  get_async_height()) or 0.
- obs_source_size_entry() takes the type and filters.num != 0 and gives
  where obs_source_get_width() and obs_source_get_height() start: a filter
  at itself, any other source at its first filter if it has filters
  (get_recurse_width()), else at itself.

One route serves both axes: obs-source.c.h reads the callback of the axis
into the node and applies the route to the width or the height, the
swapped async route giving async_height for the width and async_width for
the height. The rules keep their order and every condition the history
added: filters count (3510e69), 0 before the first async frame (506e30d),
a disabled filter does not answer (f04ef23), transitions (6839ff7), a
filter is a source with a filter parent (8a1486d), no callback without
data (f1aa71b), the rotation swap (b9d6675), and a filter asks itself
(ed8998e). The swap keeps the long and C's %.

obs-source.c.h keeps data_valid(), filter_mutex (obs_source_get_width()
still takes no lock for a filter and holds a source's filter_mutex while it
reads the filters and asks the start), the recursion into the target and
the first filter, the get_width and get_height callbacks, and the field
each route reads (transition_actual_cx/cy, async_width/height). get_base_*,
get_recurse_* and obs_source_get_width/height keep their names and
signatures, so their other callers (the colour space texrender,
obs_source_process_filter_begin_with_color_space() and
obs_source_get_base_width/height()) are unchanged. obs-source.c.h checks at
compile time that the header's filter and transition types match
obs-source.h and that enum obs_source_type is int-sized.

Checked against the unchanged functions of origin/master (outside the
tree, not committed): both versions compiled against a stand-in struct
obs_source that logs every data_valid(), lock, unlock and callback in
order. 22,528 single sources (8 types, data, both callbacks, a filter
parent, enabled, async active, 22 rotations including the ends of long and
of int, with and without one filter) and 2,000,000 random chains (0-4
filters, detached filters, filters with filters, a source that is itself a
filter, random rotations), 24,096,452 calls of obs_source_get_width/height
and get_base_width/height: the same results and the same event logs. The
harness reports a difference for a swap on % 90, for a filter that takes
its lock and for a disabled filter that answers.

The new file joins libobs.core-source with libobs.pch.h, which includes
the new header. The exported symbol sets are unchanged (1766).

Refs obs-rust#2149

* test: Characterize the source size query routing

test_source_size_route_steps compiles libobs/obs-source-size.c.h (ASan
and UBSan) and calls only obs_source_size_route() and
obs_source_size_entry(). 11 cases:

- route_every_combination: a 128-row table, every combination of the type
  (an input, a filter, a transition, a scene), data, a size callback, a
  filter parent, enabled and async active, at rotation 0;
  route_every_combination_rotated, the same rows at 90, where only the
  async route turns into the swapped one;
- route_other_types_as_inputs: the filter type, scenes, -1, 4, INT_MIN and
  INT_MAX route as an input (only the transition type has a route of its
  own; a filter is a source with a filter parent);
- route_transition: the actual size while enabled and 0 while not, with
  any data, callback, parent or async;
- route_filter_chains: a filter with a size callback asks it only while
  enabled, a filter without one or without data asks its target, the input
  below asks its callback enabled or not, an async input reports its frame
  (0 before the first one), and a callback wins over the async frame;
- swap_rotations: 0, 90, -90, 180, -180, 270, -270, 45 and 360, the rest of
  0-359 (1, 179, 181, 359) and raw values the setter no longer stores (-360,
  540, -1). The setter normalizes since obs-rust#2136; the route takes any long;
- swap_long_extremes: LONG_MIN and LONG_MAX swap (% 180 is -128 and 127 for
  a 32-bit long, -8 and 7 for a 64-bit one), the multiples of 180 next to
  them do not, and on a 64-bit long the ends of int as well;
- swap_only_when_async: the rotation changes no other route;
- entry_points: a filter starts at itself with or without filters; an
  input, a transition, a scene and types outside the enum start at their
  first filter if they have filters, else at themselves.

Characterized, not endorsed:
- a filter that is not in a chain (no filter parent) asks its callback
  even while disabled, and without one reports its async frame or 0
  instead of asking a target; an input with a filter parent routes as a
  filter (8a1486d made the parent, not the type, the test);
- a source with a callback but no data does not ask it and reports its
  async frame or 0 (obs_source_get_width() checks data_valid() first, so
  libobs gets here only through a target or a first filter whose data is
  gone).

The test is in the native test graph in name order, with libm except on
MSVC, and uses fprintf() and fail() for its messages (cmocka 1.x and 2.x).
On the C backend it passes 11 of 11.

Refs obs-rust#2149

* obs-source: Add Tier 1 tests for the source size query routing port

Tests for the port of libobs/obs-source-size.c.h to the size_route module
of rust/obs-source, next to color_space and conversion_plan. The safe core
is a stub (todo!()):

- route(), obs_source_size_route() on plain values: a Node (the type as
  the C's int, data, the size callback of the axis, a filter parent,
  enabled, async active and the rotation as c_long) gives a Route:
  Transition, Callback, AskTarget, Async { swap } or Zero;
- entry(), obs_source_size_entry(): the type and whether the source has
  filters give an Entry, Itself (the C's SELF) or FirstFilter;
- swaps(), the C's rotation % 180 != 0 on its long;
- TYPE_FILTER and TYPE_TRANSITION, the enum obs_source_type values.

tests/source/size_route.rs ports test_source_size_route_steps 1:1: its 11
cases under the same names (steps_*), in the same order, with the same
inputs and expectations, the 128-row table copied unchanged.

Edge cases (edge_*): each route has what it needs over every row, five
types and eight rotations, and the async route's swap is swaps() of the
rotation; the swap is periodic in 180 and matches rem_euclid from -1000 to
1000. Proptests (4000 cases each): the route against a model written as
one match, over any type, any flags and any c_long rotation (half of them
in -720..=720); only the transition type has a route of its own; the entry
against its model; the swap over any i32 (what a 32-bit long, as on
Windows, holds: i32's % and i64's % agree) and any i64 that fits c_long.

soldr cargo test -p obs-data --test obs-tests-core source::size_route
fails 18 of 18 with "not yet implemented".

Refs obs-rust#2149

* obs-source: Port the source size query routing

Ports libobs/obs-source-size.c.h, the size query routing of
obs_source_get_width() and obs_source_get_height(), to the size_route
module of rust/obs-source. obs-source.c.h stays C: data_valid(),
filter_mutex (a filter takes no lock; any other source holds its
filter_mutex while it reads its filters and asks the start), the
recursion into the filter target and the first filter, the get_width and
get_height callbacks, and the fields each route reads. The hybrid libobs
drops the C file and links the Rust shims in its place.

Safe core (src/size_route.rs):
- route(): the C's rules in the C's order. A transition is Transition
  while enabled, else Zero; data and a callback give Callback unless the
  source is a disabled filter (a filter is a source with a filter
  parent); a filter otherwise asks its target; an active async source is
  Async { swap }; anything else is Zero.
- swaps(): rotation.wrapping_rem(180) != 0 on c_long, the C's % on its
  long (wrapping_rem wraps only for a divisor of -1, so it is % for every
  rotation, LONG_MIN and LONG_MAX included).
- entry(): Itself for the filter type, else FirstFilter with filters and
  Itself without.
All three are const fns. The module denies clippy's arithmetic, indexing,
as, unwrap, expect, panic, unimplemented and unreachable lints, keeps no
state and takes no lock.

Shim (src/ffi/source_size.rs): obs_source_size_route() takes
struct obs_source_size_node by value (mirrored, #[repr(C)], the rotation
as c_long) and returns the C's enum, Async { swap } as ASYNC or
ASYNC_SWAPPED; obs_source_size_entry() takes the type and the filters
flag. No intentional differences.

C side: the file leaves libobs.core-source for its own group,
libobs.ported-source-size (LIBOBS_PORTED_SOURCES), whose PCH is the
header alone. libobs.pch.h keeps the header for obs-source.c. The
functions are not EXPORT, so the shims are hidden: rust-hidden.txt, the
local: list of rust-exports.map and rust-unexports-macos.txt. libobs-rust
already links the crate's ffi. The exported symbol sets are unchanged and
equal: 1766 on the C backend, the hybrid and libobs-c-reference; both
functions are local in all three, and the hybrid's come from the Rust
archive. ci/test_ported_sources.py checks the group on every host.

test_source_size_route_steps still compiles the C file into itself,
unchanged. The new test_source_size_route_steps_rust builds the same test
source against libobs_rust-static (and libm except on MSVC): the test
calls only the two functions and includes only their header, which needs
no SIMDe, so this variant runs the shims and the node's layout.
test_async_rotation_normalize, test_slideshow_size,
test_filter_color_space, test_scene_item_crop,
test_scene_rotated_scale_filter and the transition and scene size tests
see the swap through the hybrid.

Tier 1 source::size_route passes 18/18.

Refs obs-rust#2149

* obs-source: Check the source size query routing port against the C

Oracle (oracle/source_size.c): the original obs-source-size.c.h,
unmodified, with its two functions renamed to oracle_*, plus the node's
layout (size, alignment, the seven offsets), the enum sizes and every
value the port uses (the six routes, the two starts, the filter and
transition types, sizeof(long) and sizeof(int)). The node is mirrored on
the Rust side.

A second oracle (oracle/source_size_long32.c) builds the same unchanged
file with a 32-bit long, as MSVC builds it: long is remapped to int after
the standard headers and the functions are renamed to oracle32_*. On a
host whose long is 64 bits it shows how the C routes every value a
Windows long holds; on Windows it is the same build as the first.

Tier 3 (tests/source/size_route_parity.rs, 5 tests): both sides take the
same fields through the C ABI and the routes and starts are compared as
integers:
- the layout and the values against the C header, and the 32-bit node's
  size and rotation offset;
- every combination of data, a callback, a filter parent, enabled and
  async active, with 8 types (every enum obs_source_type, -1, 4 and the
  ends of i32) and 46 rotations (the multiples of 45 from -720 to 720, 1,
  -1, 179, 181, 359, the ends of c_long and of i32 and the multiples of
  180 next to them): 11,776 nodes against the C's long, and those whose
  rotation fits 32 bits against the 32-bit build as well;
- the swap of an active async input for every rotation from -100,000 to
  100,000, on both builds (1,111 multiples of 180 not swapped);
- the entry for the 8 types with and without filters, on both builds;
- proptests (20,000 cases each): any node with any c_long rotation
  against the C's long, and any node with any i32 rotation against the
  32-bit build, a fifth of the rotations rounded to a multiple of 180.

Tier 1 and the parity module passed 10 runs in a row with fresh seeds. No
regression file came up.

Mutation check (once, not committed): 26 mutants of the core and the
shim, Tier 1 (18 tests) and Tier 3 (5), failures per mutant. All are
killed but one equivalent mutant.

| Mutant | Tier 1 | Tier 3 |
|---|---|---|
| transition: enabled ignored / rule dropped / after the callback | 5 / 6 / 5 | 3 / 3 / 3 |
| callback without data / without a callback | 7 / 10 | 3 / 4 |
| disabled filter answers / enabled inverted for filters | 7 / 7 | 3 / 3 |
| disabled input does not answer | 6 | 3 |
| filter by type, not by parent | 7 | 3 |
| ask target dropped / async_active ignored | 8 / 9 | 3 / 3 |
| swap on % 90 / % 360 / inverted | 8 / 5 / 12 | 4 / 4 / 4 |
| swap on the low 32 bits of the long | 3 | 2 |
| swap only for 90 and 270 | 6 | 4 |
| swap with rem_euclid (equivalent: only == 0 counts) | 0 | 0 |
| entry: filter type ignored / filters flag inverted | 2 / 2 | 1 / 1 |
| entry: a transition starts at itself | 2 | 1 |
| shim: ASYNC and ASYNC_SWAPPED swapped | 0 | 4 |
| shim: callback read from data / enabled read from async | 0 / 0 | 4 / 3 |
| shim: rotation dropped / ZERO off by one | 0 / 0 | 4 / 4 |
| shim: entry values swapped | 0 | 1 |

Tier 1 does not reach the shim; test_source_size_route_steps_rust does.
The C characterization fails on seven mutants of the C file too (swap on
% 90, a disabled filter answers, the transition ignores enabled,
async_active ignored, the entry ignores the type, a callback without data,
a filter by type).

Refs obs-rust#2149

* docs: Record the source size query routing port

The rust/README.md crate table now lists libobs/obs-source-size.c.h among
the rust/obs-source units, and its port table has a row for it: the two
functions and their rules, each with the commit that added it, what
stays C (data_valid(), filter_mutex and when it is held, the recursion,
the callbacks and the fields each route reads), the node passed by value,
the rotation as c_long with the C's %, the compile-time checks, what is
kept and characterized (a detached filter answers while disabled; a
callback without data is not asked), the _rust variant of the
characterization, the real-libobs tests and what Tier 3 compares,
including the 32-bit long oracle. The crate's description and lib.rs say
what it holds. docs/rust-port/naming.md already maps
libobs/obs-source*.c.h to rust/obs-source.

port_comparison gets its own bench file,
benches/port_comparison/source_size.rs: 1024 routes (every combination
of the five flags for an input, a filter, a transition and a scene at
eight rotations, the ends of long among them) and 1024 starts, each
folded into a checksum both sides must match. On x86_64 Linux (GCC, not
pinned, a loaded machine; median per 1024 calls): route 9.21 us Rust and
10.14 us C (0.91x), entry 1.59 us Rust and 1.53 us C (1.04x), about 9 ns
a route either way. obs_source_get_width() and obs_source_get_height()
ask about one route per source and filter in the chain for every scene
item every frame.

Fixes obs-rust#2149

* fixup: allow the Windows-only no-op i32 conversion in check_route

---------

Co-authored-by: Zach Vorhies <[email protected]>
rdoupe added a commit to rdoupe/obs-studio that referenced this pull request Oct 24, 2026
Behaviour-neutral extraction before the Rust port. The decisions of
rotate_async_video(), obs_source_render_async_video() and
source_render() in obs-source.c.h move to libobs/obs-source-draw-plan.c.h
as eight functions on plain values, declared in the new
libobs/obs-source-draw-plan.h without EXPORT (hidden, as
-fvisibility=hidden keeps them):

- obs_source_draw_plan_rotation_x() and _y(): the translate that moves
  a rotated async frame back into its box (height or width for 270 and
  90, both for 180, nothing for any other angle; the rotation is in
  0-359 since obs-rust#2136);
- obs_source_draw_plan_async_linear_srgb(): the linear sRGB flag of an
  async frame, the graphics flag or an SDR frame into anything but
  GS_CS_SRGB, or an HDR frame tonemapped into SDR;
- obs_source_draw_plan_async_nonlinear_alpha(): the non-linear alpha
  blend, an SDR frame drawn linear whose alpha is not linear;
- obs_source_draw_plan_technique(): the technique for each pair of
  source and current colour spaces, with or without non-linear alpha.
  source_render()'s conversion uses the same table without it, so both
  callers share it;
- obs_source_draw_plan_reads_white_level() and
  obs_source_draw_plan_multiplier(): when the SDR white level is read
  and the multiplier, the level over 80 into scRGB and 80 over the level
  out of it, the same for both callers;
- obs_source_draw_plan_convert(): whether source_render() draws through
  color_space_texrender, when the source and current spaces are in
  different classes (SDR, 709_EXTENDED, scRGB).

The techniques are a new shared enum obs_source_draw_technique in
libobs/obs-source-draw-technique.h, with obs_source_draw_technique_name()
mapping it to the effect's technique name. The deinterlace draw
decisions (obs-rust#2153) move to it from their own technique enum: the four
values keep their numbers (0 to 3) and two are added for the async draw
(DrawNonlinearAlpha 4, DrawNonlinearAlphaMultiply 5), so the deinterlace
shims, their oracle and test_deinterlace_draw_plan_steps change names
only. deinterlace_render() maps the technique with the shared function
instead of its own copy, and obs_source_deinterlace_draw_reads_white_level()
lists the two new values (it never sees them).

obs-source.c.h keeps every gs_* call in its order and under the same
conditions, convert_video_space(), obs_get_video_sdr_white_level(),
gs_get_format_from_space() and the texrenders. gs_get_linear_srgb() is
still read for every async frame, after gs_get_color_space(), and
obs_get_video_sdr_white_level() only for a pair that multiplies, after
the colour spaces and the linear flag (async) or after
gs_get_format_from_space() (source_render()); the decisions are separate
calls so neither is hoisted. The multiplier is the same single float
division, sdr_white_level / 80.0f or 80.0f / sdr_white_level, and the
size converts to float as (float)uint32_t did. The rotation stays a
long, so a value outside 0-359 takes the path it took before. Colour
spaces cross as int, so a value outside the enum takes the paths it
took before; obs-source.c.h already checks that the enum is int-sized.

Checked against the unchanged functions of origin/master (outside the
tree, not committed): both versions compiled against stubs that log
every gs_*, obs_* and texrender call with its arguments (floats as their
bits), and the traces compared byte for byte, under GCC -O0 and -O2 and
clang -O0 and -O2, one trace hash for all four. 1,112,600 async renders
(the eight texture, active and stale gates; 9 source x 9 current spaces,
in the enum and out, x both linear flags x both alpha flags x 22 white
levels, NaNs, infinities, signed zeros and subnormals included, x 19
rotations, LONG_MIN, LONG_MAX and values past 32 bits included, x 6
sizes, past 2^24 and UINT32_MAX included; 300,000 random) and 328,304
source renders (every pair x 22 white levels x no, a matching or a
mismatched texrender x begin failing or not x 0 to 3 passes x 3 base
sizes; 200,000 random). The traces are identical (24,697,614 calls);
each of 12 planted changes (the 792f847 and 0800957 linear rules,
the non-linear alpha rule, the 90 and 270 translates, the multiplier,
the white level read and its hoisting, the gs_get_linear_srgb() read,
the conversion rule, the non-linear alpha technique, the conversion
passing non-linear alpha) is caught.

The new file joins libobs.core-source with libobs.pch.h, which includes
the new header. The exported symbol sets are unchanged (1766).

Refs obs-rust#2187
rdoupe added a commit to rdoupe/obs-studio that referenced this pull request Oct 24, 2026
test_source_draw_plan_steps compiles libobs/obs-source-draw-plan.c.h
(ASan and UBSan) and calls only its eight hidden functions. 17 cases:

- enum_values: the technique numbers the C maps (and the port will
  return), their names, and that the enum and enum gs_color_space are
  int-sized;
- rotation_multiples_of_90: the translate of a 1920 x 1080 frame and of
  a 1080 x 1920 one at 0, 90, 180 and 270, as float bits;
- rotation_other_angles: 1, 45, 89, 91, 135, 179, 181, 269, 271 and 359
  are not moved, nor are 360, 450, -90, -180, -270 and the ends of long;
- rotation_size_to_float: sizes of 0, past 2^24 (rounded to nearest
  even) and UINT32_MAX (2^32);
- async_linear_srgb_space_pairs, async_linear_srgb_outside_enum: the 4 x
  4 pairs with the graphics flag off and on (an SDR frame into anything
  but GS_CS_SRGB, 792f847; an HDR frame into SDR, 0800957); a space
  outside the enum keeps the graphics flag;
- async_nonlinear_alpha_every_input: only an SDR frame drawn linear
  whose alpha is not linear;
- technique_space_pairs, technique_outside_enum: the 4 x 4 pairs with
  and without non-linear alpha; Draw for a space outside the enum;
- reads_white_level_space_pairs, multiplier_space_pairs,
  multiplier_outside_enum: the pairs that read the level, and the
  multiplier as float bits at SDR white levels of 80, 300 and 0
  (300 / 80 = 3.75, 80 / 300 = 0x3e888889, 80 / 0 = +inf);
- multiplier_any_level: -0, infinity, -80, 480, 203, the smallest
  subnormal and NaN, each one IEEE division;
- convert_space_pairs, convert_outside_enum: source_render() converts
  between classes (SDR, 709_EXTENDED, scRGB) only;
- async_plan_every_input, convert_plan_every_input: the decisions in
  their callers' order for every pair, both linear flags, both alpha
  flags and the three white levels.

Characterized, not endorsed:
- obs_get_video_sdr_white_level() is not checked: a level of 0 gives a
  multiplier of 0 into scRGB and +inf out of it, -0 gives -inf, a
  negative level a negative multiplier and a NaN a NaN. OBS sets levels
  from 80 to 480 nits;
- a rotation outside 0-359, which obs_source_set_async_rotation() no
  longer stores since obs-rust#2136, is not moved, even a multiple of 90;
- an SDR frame into a current space outside the enum is drawn linear
  with non-linear alpha, but with Draw (the space is not GS_CS_SRGB, and
  the technique switch has no case for it).

The test is in the native test graph in name order, with libm except on
MSVC, in the core suite (no suite size is pinned in
rust/obs-build/tests/native.rs). On the C backend it passes 17 of 17.

Refs obs-rust#2187
chriscoveries pushed a commit to chriscoveries/obsrust-fork that referenced this pull request Oct 24, 2026
* libobs: Move the source draw decisions into obs-source-draw-plan.c

Behaviour-neutral extraction before the Rust port. The decisions of
rotate_async_video(), obs_source_render_async_video() and
source_render() in obs-source.c.h move to libobs/obs-source-draw-plan.c.h
as eight functions on plain values, declared in the new
libobs/obs-source-draw-plan.h without EXPORT (hidden, as
-fvisibility=hidden keeps them):

- obs_source_draw_plan_rotation_x() and _y(): the translate that moves
  a rotated async frame back into its box (height or width for 270 and
  90, both for 180, nothing for any other angle; the rotation is in
  0-359 since obs-rust#2136);
- obs_source_draw_plan_async_linear_srgb(): the linear sRGB flag of an
  async frame, the graphics flag or an SDR frame into anything but
  GS_CS_SRGB, or an HDR frame tonemapped into SDR;
- obs_source_draw_plan_async_nonlinear_alpha(): the non-linear alpha
  blend, an SDR frame drawn linear whose alpha is not linear;
- obs_source_draw_plan_technique(): the technique for each pair of
  source and current colour spaces, with or without non-linear alpha.
  source_render()'s conversion uses the same table without it, so both
  callers share it;
- obs_source_draw_plan_reads_white_level() and
  obs_source_draw_plan_multiplier(): when the SDR white level is read
  and the multiplier, the level over 80 into scRGB and 80 over the level
  out of it, the same for both callers;
- obs_source_draw_plan_convert(): whether source_render() draws through
  color_space_texrender, when the source and current spaces are in
  different classes (SDR, 709_EXTENDED, scRGB).

The techniques are a new shared enum obs_source_draw_technique in
libobs/obs-source-draw-technique.h, with obs_source_draw_technique_name()
mapping it to the effect's technique name. The deinterlace draw
decisions (obs-rust#2153) move to it from their own technique enum: the four
values keep their numbers (0 to 3) and two are added for the async draw
(DrawNonlinearAlpha 4, DrawNonlinearAlphaMultiply 5), so the deinterlace
shims, their oracle and test_deinterlace_draw_plan_steps change names
only. deinterlace_render() maps the technique with the shared function
instead of its own copy, and obs_source_deinterlace_draw_reads_white_level()
lists the two new values (it never sees them).

obs-source.c.h keeps every gs_* call in its order and under the same
conditions, convert_video_space(), obs_get_video_sdr_white_level(),
gs_get_format_from_space() and the texrenders. gs_get_linear_srgb() is
still read for every async frame, after gs_get_color_space(), and
obs_get_video_sdr_white_level() only for a pair that multiplies, after
the colour spaces and the linear flag (async) or after
gs_get_format_from_space() (source_render()); the decisions are separate
calls so neither is hoisted. The multiplier is the same single float
division, sdr_white_level / 80.0f or 80.0f / sdr_white_level, and the
size converts to float as (float)uint32_t did. The rotation stays a
long, so a value outside 0-359 takes the path it took before. Colour
spaces cross as int, so a value outside the enum takes the paths it
took before; obs-source.c.h already checks that the enum is int-sized.

Checked against the unchanged functions of origin/master (outside the
tree, not committed): both versions compiled against stubs that log
every gs_*, obs_* and texrender call with its arguments (floats as their
bits), and the traces compared byte for byte, under GCC -O0 and -O2 and
clang -O0 and -O2, one trace hash for all four. 1,112,600 async renders
(the eight texture, active and stale gates; 9 source x 9 current spaces,
in the enum and out, x both linear flags x both alpha flags x 22 white
levels, NaNs, infinities, signed zeros and subnormals included, x 19
rotations, LONG_MIN, LONG_MAX and values past 32 bits included, x 6
sizes, past 2^24 and UINT32_MAX included; 300,000 random) and 328,304
source renders (every pair x 22 white levels x no, a matching or a
mismatched texrender x begin failing or not x 0 to 3 passes x 3 base
sizes; 200,000 random). The traces are identical (24,697,614 calls);
each of 12 planted changes (the 792f847 and 0800957 linear rules,
the non-linear alpha rule, the 90 and 270 translates, the multiplier,
the white level read and its hoisting, the gs_get_linear_srgb() read,
the conversion rule, the non-linear alpha technique, the conversion
passing non-linear alpha) is caught.

The new file joins libobs.core-source with libobs.pch.h, which includes
the new header. The exported symbol sets are unchanged (1766).

Refs obs-rust#2187

* test: Characterize the source draw decisions

test_source_draw_plan_steps compiles libobs/obs-source-draw-plan.c.h
(ASan and UBSan) and calls only its eight hidden functions. 17 cases:

- enum_values: the technique numbers the C maps (and the port will
  return), their names, and that the enum and enum gs_color_space are
  int-sized;
- rotation_multiples_of_90: the translate of a 1920 x 1080 frame and of
  a 1080 x 1920 one at 0, 90, 180 and 270, as float bits;
- rotation_other_angles: 1, 45, 89, 91, 135, 179, 181, 269, 271 and 359
  are not moved, nor are 360, 450, -90, -180, -270 and the ends of long;
- rotation_size_to_float: sizes of 0, past 2^24 (rounded to nearest
  even) and UINT32_MAX (2^32);
- async_linear_srgb_space_pairs, async_linear_srgb_outside_enum: the 4 x
  4 pairs with the graphics flag off and on (an SDR frame into anything
  but GS_CS_SRGB, 792f847; an HDR frame into SDR, 0800957); a space
  outside the enum keeps the graphics flag;
- async_nonlinear_alpha_every_input: only an SDR frame drawn linear
  whose alpha is not linear;
- technique_space_pairs, technique_outside_enum: the 4 x 4 pairs with
  and without non-linear alpha; Draw for a space outside the enum;
- reads_white_level_space_pairs, multiplier_space_pairs,
  multiplier_outside_enum: the pairs that read the level, and the
  multiplier as float bits at SDR white levels of 80, 300 and 0
  (300 / 80 = 3.75, 80 / 300 = 0x3e888889, 80 / 0 = +inf);
- multiplier_any_level: -0, infinity, -80, 480, 203, the smallest
  subnormal and NaN, each one IEEE division;
- convert_space_pairs, convert_outside_enum: source_render() converts
  between classes (SDR, 709_EXTENDED, scRGB) only;
- async_plan_every_input, convert_plan_every_input: the decisions in
  their callers' order for every pair, both linear flags, both alpha
  flags and the three white levels.

Characterized, not endorsed:
- obs_get_video_sdr_white_level() is not checked: a level of 0 gives a
  multiplier of 0 into scRGB and +inf out of it, -0 gives -inf, a
  negative level a negative multiplier and a NaN a NaN. OBS sets levels
  from 80 to 480 nits;
- a rotation outside 0-359, which obs_source_set_async_rotation() no
  longer stores since obs-rust#2136, is not moved, even a multiple of 90;
- an SDR frame into a current space outside the enum is drawn linear
  with non-linear alpha, but with Draw (the space is not GS_CS_SRGB, and
  the technique switch has no case for it).

The test is in the native test graph in name order, with libm except on
MSVC, in the core suite (no suite size is pinned in
rust/obs-build/tests/native.rs). On the C backend it passes 17 of 17.

Refs obs-rust#2187

* obs-source: Add Tier 1 tests for the source draw plan port

Tests for the port of libobs/obs-source-draw-plan.c.h to the draw_plan
module of rust/obs-source. The safe core is a stub (todo!()):

- rotation_x() and rotation_y() (the rotation as the C's long, c_long,
  the size as u32, the translate as f32), async_linear_srgb(),
  async_nonlinear_alpha(), technique() (a Technique),
  reads_white_level(), multiplier() (f32) and convert(), on plain values:
  colour spaces as the C's int;
- Technique, enum obs_source_draw_technique with the C's numbers.

The technique enum and the enum gs_color_space values move from
deinterlace_draw to a new shared module, draw_technique, with
Technique::value() (the C's number) and Technique::name() (the name C
maps it to); Technique gains DrawNonlinearAlpha (4) and
DrawNonlinearAlphaMultiply (5). deinterlace_draw re-exports them, so its
users and tests are unchanged, and its shim returns
Technique::value() through the shared ffi type obs_source_draw_technique
(src/ffi/source_draw_technique.rs) instead of its own copy.

tests/source/draw_plan.rs ports test_source_draw_plan_steps 1:1: its 17
cases under the same names (steps_*), in the same order, with the same
inputs and expectations, the floats compared as bits.

Edge cases (edge_*): the rotation translate for every angle from -1000
to 1000, the ends of c_long and, where long is 64 bits, 90, 180 and 270
plus 2^32, against a model that converts the size through f64; every
size from 0 to 1024 and around 2^24, 2^25, 2^31 and u32::MAX; every
decision over every pair of 260 spaces around the enum and the ends of
i32 with every flag, against a model written from the space classes;
the multiplier at 26 special f32 bit patterns (zeros, subnormals, the
normal ends, OBS's levels, infinities, quiet and signalling NaNs of both
signs with payloads) for every pair of 9 spaces, against the one
division written out; the white level is read exactly when the
multiplier at 300 nits is not 1. Proptests (4000 cases each): the
rotation over any c_long and u32 sizes, a third of them at 90, 180 or
270; every decision over any space, flag and white level bit pattern.

soldr cargo test -p obs-data --test obs-tests-core source::draw_plan
fails 23 of 24 with "not yet implemented"; steps_enum_values, which
tests only the enum, passes. source::deinterlace_draw still passes 39
of 39.

Refs obs-rust#2187

* obs-source: Port the source draw decisions

Ports libobs/obs-source-draw-plan.c.h, the source draw decisions of
obs-source.c, to the draw_plan module of rust/obs-source. obs-source.c.h
stays C: every gs_* call in its order and under its conditions,
convert_video_space(), obs_get_video_sdr_white_level(),
gs_get_format_from_space(), the texrenders and the technique names. The
hybrid libobs drops the C file and links the Rust shims in its place.

Safe core (src/draw_plan.rs):
- rotation_x() and rotation_y(): a match over the C's long (c_long,
  never converted, so a value past 32 bits is matched as the C's switch
  matches it on every target): height or width for 270 and 90, both for
  180, 0 otherwise; the size converts to f32 to nearest even, as
  (float)uint32_t does;
- async_linear_srgb(): the graphics flag, or GS_CS_SRGB into anything
  but GS_CS_SRGB (792f847), or 709_EXTENDED or scRGB into SDR
  (0800957); async_nonlinear_alpha(): GS_CS_SRGB, linear, alpha not
  linear;
- technique(), Technique with the C's numbers: DrawMultiply (or
  DrawNonlinearAlphaMultiply) for SDR into scRGB, DrawNonlinearAlpha for
  GS_CS_SRGB with non-linear alpha into SDR or 709_EXTENDED, DrawTonemap
  for 709_EXTENDED into SDR, DrawMultiply for it into scRGB,
  DrawMultiplyTonemap for scRGB into SDR, DrawMultiply for it into
  709_EXTENDED, Draw otherwise (spaces outside the enum included);
- reads_white_level() and multiplier(): into scRGB from SDR or
  709_EXTENDED, sdr_white_level / 80.0; out of scRGB into them,
  80.0 / sdr_white_level; 1.0 otherwise: one f32 division, the same IEEE
  operation as the C's, so the bits match, NaN payloads and infinities
  included;
- convert(): both spaces in the enum, in different classes (SDR,
  709_EXTENDED, scRGB).
The module denies clippy's arithmetic, indexing, as, unwrap, expect,
panic, todo, unimplemented and unreachable lints (one as, the size to
f32, is allowed on its own helper: there is no From<u32> for f32), keeps
no state and takes no lock.

Shim (src/ffi/source_draw_plan.rs): the eight functions keep the C
signatures, plain values in and out; the technique comes back as
Technique::value() through the shared obs_source_draw_technique type.
No intentional differences: there is no pointer to check.

C side: the file leaves libobs.core-source for its own group,
libobs.ported-source-draw-plan (LIBOBS_PORTED_SOURCES), whose PCH is
obs.h (the colour space enum) and obs-source-draw-plan.h (which brings
obs-source-draw-technique.h). libobs.pch.h keeps the header for
obs-source.c. The functions are not EXPORT, so the shims are hidden:
rust-hidden.txt, the local: list of rust-exports.map and
rust-unexports-macos.txt. libobs-rust already links the crate's ffi.
The exported symbol sets are unchanged and equal: 1766 on the C backend,
the hybrid and libobs-c-reference; the eight are local in all three, and
the hybrid's come from the Rust archive (it has no object for the C
file). ci/test_ported_sources.py checks the group on every host.

test_source_draw_plan_steps still compiles the C file into itself,
unchanged. The new test_source_draw_plan_steps_rust builds the same test
source against libobs_rust-static (and libm except on MSVC): the test
calls only the eight functions and the header's static inline
obs_source_draw_technique_name(), and includes their header and obs.h
for the enum values, so it takes libobs's include directories (SIMDe,
obsconfig.h) and links the archive alone. It passes 17 of 17 against
the shims. test_async_rotation_normalize, test_filter_color_space,
test_source_color_space_steps, test_color_correction_16f,
test_pipewire_cursor_hdr and test_texture_render see the swap through
the hybrid.

Tier 1 source::draw_plan passes 24/24; source::deinterlace_draw still
passes 39/39.

Refs obs-rust#2187

* obs-source: Check the source draw plan port against the C

Oracle (oracle/source_draw_plan.c): the original obs-source-draw-plan.c.h,
unmodified, with its eight functions renamed to oracle_*, plus every enum
value the port uses (the four colour spaces and the six techniques), the
enum, int, long, bool and float sizes, and obs_source_draw_technique_name()
for a technique value. No function shares its name with an enum tag, so
the size table names the tags as they are. The bool results are declared
as u8 on the Rust side, the byte the C returns.

Tier 3 (tests/source/draw_plan_parity.rs, 10 tests). Every function takes
and returns plain values, so each run compares the bytes of the two
results: the bools as bytes, the technique as its value, the floats as
their f32 bits.
- the values and sizes against the C headers (long is c_long on every
  target), and the name C maps each technique the port returns to;
- the rotation translate for every angle from -70000 to 70000, a stride
  over the whole c_long range, its ends and, where long is 64 bits, 90,
  180 and 270 plus multiples of 2^32, at 6 sizes (non-square, 0, past
  2^24, u32::MAX); every size from 0 to 4096 and +-2000 around 2^24, 2^25,
  2^31 and u32::MAX at 0, 90, 180, 270 and 45;
- space pairs: both linear flags, both non-linear alpha flags, the white
  level read, the conversion and the multiplier at 300 nits for every pair
  of 649 spaces (-320 to 320 and four near each end of i32): 421,201
  pairs; every pair of -3 to 6 and the ends of i32 at 26 special white
  levels (zeros, subnormals, the normal ends, 80 to 480 nits, infinities,
  quiet and signalling NaNs of both signs with payloads); the non-linear
  alpha rule for every space and flag;
- the decisions of obs_source_render_async_video() (with
  rotate_async_video()) and source_render() in their order, one copy on
  each side: the linear flag, the blend, the technique, the white level
  read, the multiplier only when it is read, and the translate only for a
  rotation other than 0; 9 x 9 spaces x both flags x both alpha flags x
  26 levels x 7 rotations x 2 sizes (235,872 draws);
- proptests (20,000 cases each): the rotation over any c_long and any
  sizes (a third at 90, 180 or 270); every decision over any space and
  any white level bit pattern (never a float range); both callers'
  decisions over all of it at once.

No input reaches an integer division or a 128-bit multiply on either side
(the only division is the f32 multiplier, which cannot trap), so the
MSVC x64 _udiv128 and INT_MIN / -1 faults cannot come up and no input is
skipped there. Tier 1 and the parity module passed 10 runs in a row with
fresh seeds (34/34 each). No regression file came up; the ones the
todo!() stub and the mutants left were deleted. soldr cargo clippy
--target x86_64-pc-windows-msvc -p obs-source -p obs-data -p obs-c-oracle
--all-targets -- -D warnings is clean.

Mutation check (once, not committed): 36 mutants, Tier 1 (24 tests) and
Tier 3 (10), failures per mutant.

| Mutant | Tier 1 | Tier 3 |
|---|---|---|
| rotation: 270 x is width / 180 x is height / 90 y is height / 180 y not moved / -90 as 270 | 5 / 5 / 5 / 5 / 2 | 5 / 5 / 5 / 5 / 2 |
| size truncated to even | 4 | 5 |
| linear: SDR into non-SRGB dropped (pre-792f8473e) / tonemap dropped (pre-080095786) / SRGB into SRGB_16F not linear / HDR is 709_EXTENDED only | 6 / 4 / 4 / 4 | 5 / 5 / 5 / 5 |
| non-linear alpha: linear ignored / SRGB_16F too | 4 / 4 | 3 / 3 |
| technique: flag not masked to SRGB / no NA into 709_EXTENDED / 709_EXTENDED into SDR drawn / scRGB into 709_EXTENDED drawn / NAM is DrawMultiply | 2 / 4 / 5 / 5 / 4 | 3 / 5 / 5 / 5 / 5 |
| into scRGB not from 709_EXTENDED / out of scRGB not into 709_EXTENDED | 8 / 8 | 5 / 5 |
| multiplier: into scRGB inverted / 80.00001 / times 1/80 | 7 / 7 / 3 | 5 / 5 / 4 |
| white level read into scRGB only | 6 | 5 |
| convert: SRGB_16F its own class / outside the enum converts / same class converts | 4 / 3 / 4 | 5 / 5 / 5 |
| Technique::value: NA and NAM swapped / tonemap numbers swapped | 1 / 1 | 6 / 6 |
| shim: rotation width and height swapped / technique ignores the flag / multiplier spaces swapped / graphics flag negated | 0 / 0 / 0 / 0 | 5 / 5 / 5 / 5 |
| equivalent: multiplier in f64 and rounded / size through f64 / shim convert spaces swapped / white level read as "multiplier at 300 is not 1" | 0 / 0 / 0 / 0 | 0 / 0 / 0 / 0 |

32 are killed by Tier 3. The other four are equivalent: one f32 division
done in f64 and rounded is correctly rounded the same; a u32 is exact in
f64, so one rounding to f32 is the same; convert() is symmetric; and every
pair that multiplies gives a multiplier other than 1 at 300 nits. Tier 1
does not reach the shims; test_source_draw_plan_steps_rust and Tier 3 do.

No intentional differences: there is no pointer to check.

Refs obs-rust#2187

* docs: Record the source draw plan port

The rust/README.md crate table now lists libobs/obs-source-draw-plan.c.h
among the rust/obs-source units, and its port table has a row for it: the
eight functions and what they decide, the shared technique enum
(obs-source-draw-technique.h, obs-source::draw_technique), what stays C
(every gs_* call in its order and under its conditions,
convert_video_space(), obs_get_video_sdr_white_level(),
gs_get_format_from_space(), the texrenders and the technique names), why
the decisions are separate calls rather than one plan (neither
gs_get_linear_srgb() nor the white level read is hoisted), the spaces as
int and the rotation as long, the multiplier as one f32 division matching
bit for bit, what is kept and characterized, no intentional differences,
the _rust variant of the characterization, the real-libobs tests and what
Tier 3 compares. The deinterlace draw row names the shared enum. The
crate's description and lib.rs say what it holds, draw_technique
included. docs/rust-port/naming.md already maps libobs/obs-source*.c.h to
rust/obs-source.

port_comparison gets its own bench file,
benches/port_comparison/source_draw_plan.rs, in the sorted modules! list:
1024 async frames (the decisions of obs_source_render_async_video() in
its order and the rotation translate, over every pair of colour spaces,
both linear and alpha flags, white levels of 80 to 480 nits and rotations
of 0, 90, 180 and 270) and 1024 source_render() conversions, folded into
checksums both sides must match. Neither side allocates, and the module
passes the bench's per-module allocation check. On x86_64 Linux (GCC, not
pinned, load average 6 to 8; median, two runs): async_frame 16.3 and 14.6
us Rust, 13.9 and 13.3 us C per 1024 frames (1.1x to 1.2x), about 2 ns
more per async frame drawn; source_render 8.9 and 10.0 us Rust, 7.2 and
7.7 us C (1.2x to 1.3x), about 2 ns more per source drawn.
soldr cargo test -p obs-c-oracle --locked --bench port_comparison passes.

Fixes obs-rust#2187
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: Async rotations other than 0, ±90, 180 and 270 are drawn outside the item

2 participants