Repository navigation
obs-source: Port the async upload parameters - #2342
Merged
Merged
Conversation
Behaviour-neutral extraction before the Rust port. The decisions and shader parameter values of set_async_texture_size(), update_async_texrender(), update_async_textures(), check_to_swap_bgrx_bgra() and obs_source_update_async_video() in obs-source.c.h move to libobs/obs-source-async-upload.c.h, as fourteen functions on plain values declared in the new libobs/obs-source-async-upload.h without EXPORT (hidden, as -fvisibility=hidden keeps them): - obs_source_async_upload_texture_changed(): the five-field compare (width, height, format, full range, transfer) that rebuilds the textures, on two struct obs_source_async_upload_format values; - obs_source_async_upload_tries_gpu(): whether the rebuild tries init_gpu_conversion() (any convert type but NONE); - obs_source_async_upload_size_uniforms(): width, height, width_d2, height_d2, width_x2_i and height_x2_i, the same float operations in the same order ((float)cx * 0.5f, 0.5f / (float)cx); - obs_source_async_upload_hlg_peak(): the BT.2408 clamp at 1000; - obs_source_async_upload_maximum_nits() and _over_sdr_white(): the HLG peak or 10000, then one float division by the white level; - obs_source_async_upload_hdr_lw() and _sets_range(); - obs_source_async_upload_linear_alpha(), _uses_texrender() and _plain(): update_async_textures()'s flag and route; - obs_source_async_upload_bgr_swap(): the format the texture is recreated with, or GS_UNKNOWN to keep it; - obs_source_async_upload_reanchor_reads_unbuffered() and _reanchor(): the timing re-anchor rule (!async_decoupled || !async_unbuffered). Split where a read or call would otherwise move: every gs_* call stays in obs-source.c.h in its order and under its condition, and the uniforms are computed piecewise so no level is read earlier than before. obs->video.hdr_nominal_peak_level is still read directly after height_x2_i is set, obs_get_video_sdr_white_level() just before maximum_over_sdr_white_nits, obs_get_video_hdr_nominal_peak_level() just before hdr_lmax, all after gs_texrender_begin() succeeds. log10f() and the HLG exponent stay C. get_convert_type() is called only off the texrender route, as before; init_gpu_conversion() only for a convert type that tries it. async_unbuffered, set without a lock, is read only for a decoupled source, as the short-circuit did. The new file joins libobs.core-source with libobs.pch.h, which includes the new header; source-sets.json lists it. docs/rust-port/naming.md already maps libobs/obs-source*.c.h to rust/obs-source. Checked in a scratch harness (not committed) that compiles origin/master's set_async_texture_size(), update_async_texrender(), update_async_textures(), update_async_texture(), check_to_swap_bgrx_bgra(), obs_source_update_async_video() and their helpers verbatim next to this branch's and the moved file, on a stand-in source and frame whose every field read and write is logged with its value (a script rewrites each access into a logging accessor), with every gs_* call and its arguments (the float uniforms as bits), the levels, log10f(), get_convert_type(), init_gpu_conversion(), the conversion plan, the frame get and release and the asserts logged in order. The stubs answer from one seeded stream in call order (texrender begin, texture creation, colour formats, levels as any bit pattern or 80, 300, 480, 1000, 1001, 10000), and async_decoupled and async_unbuffered return the field or a new value per read. 150,000,000 random states: 50,000,000 each with GCC and Clang at -O2, 20,000,000 each at -O0, 5,000,000 each under ASan and UBSan (GCC -O0, Clang -O2), sizes at 0, 1, 2^24 + 1, 2^31, UINT32_MAX and random, each texture field changed alone or not, formats and transfers outside their enums. Over 4,500,000,000 events are equal, with the final state and the return value, after the one normalization the move needs: the field reads inside the compare (the branch reads all ten, master a prefix) and frame->format inside the BGR swap (the branch reads it for any texture format) are dropped; the compare must read each of the ten fields exactly once and make no call or write. Twenty-four of twenty-five deliberately broken moves fail it (the white level read before gs_texrender_begin(), the peak read hoisted above the size uniforms or through the getter, hdr_lmax read before hdr_lw, async_unbuffered read for any source, init_gpu_conversion() before the convert type test, get_convert_type() before the texrender test, and each decision changed); the one that passes is equivalent (width_d2 through double: halving commutes with rounding). Refs obs-rust#2336
test_async_upload_steps compiles libobs/obs-source-async-upload.c.h into itself (ASan and UBSan) and calls only its hidden functions, through its header. 16 cases pin: - the enum values the port relies on (GS_UNKNOWN, GS_BGRX, GS_BGRA, the _UNORM pair, VIDEO_FORMAT_BGRA and BGRX, the transfers, OBS_SOURCE_FRAME_LINEAR_ALPHA, OBS_SOURCE_CONVERT_NONE) and the two structs' sizes, alignments and offsets; - the five-field compare: equal values keep the textures, each field changed alone rebuilds them in both directions, and all at once; characterized, not endorsed: a 0 x 0 first frame of the zero values keeps the (absent) textures; the ends of every field; - the GPU conversion and plain routes for every convert type and values outside the enum; - the size uniforms as float bits for 0, 1, 2, 3, 1919, 1920, 16777217 and UINT32_MAX on each axis (characterized, not endorsed: a size of 0 gives an infinite half texel; sizes past 2^24 round); - the HLG clamp at 1000 for 100, 999, 1000, the next float, 1001, 10000, infinities, zeros, a subnormal, a negative and NaNs (characterized, not endorsed: a NaN stays a NaN); - the maximum nits for HLG, DEFAULT, SRGB, PQ and values outside the enum; the chain obs-source.c runs (the HLG peak, the maximum nits, the ratio) for SRGB, PQ, HLG and 4 at peaks of 100, 1000, 1001 and 10000 and white levels of 80, 300 and 480; - the ratio at its edges (characterized, not endorsed: a white level of 0 gives +inf; obs-rust#2209 keeps the level above 0); - hdr_lw for every uint16_t, the colour range, the linear alpha flag for every flag byte, the texrender route; - every BGR swap pair of texture and frame formats around both enums; - the four re-anchor cases and when async_unbuffered is read. The test is in the test graph, sorted. test_async_conversion_plan, test_pipewire_cursor_hdr, test_media_format_change and test_filter_color_space cover the callers through the real libobs. Refs obs-rust#2336
Adds the async_upload module to rust/obs-source with its API and every function as todo!(): FRAME_LINEAR_ALPHA, CONVERT_NONE, the Format and SizeUniforms values, the conversion plan's video_format, video_trc and gs_color_format values, texture_changed(), tries_gpu(), size_uniforms(), hlg_peak(), maximum_nits(), over_sdr_white(), hdr_lw(), sets_range(), linear_alpha(), uses_texrender(), plain(), bgr_swap() and reanchor_reads_unbuffered() with reanchor(). tests/source/async_upload.rs ports test_async_upload_steps 1:1 (steps_*: the same 16 cases, inputs and expectations, the floats as bits) and adds edge cases (edge_*): - the compare with each field changed alone from bases at the ends of every field, and by proptest (20,000 cases) against a model of the five fields; - the size uniforms against models in f64 (exact for one-operation results) for every size around each power of two and by proptest over every u32; each axis reads only its own size; - the HLG clamp for every special f32 bit pattern (zeros, subnormals, the ends of the normals, infinities, quiet and signalling NaNs of both signs) and every float within 256 of 1000; the ratio for every pair of special patterns against the f64 division; the maximum nits for every transfer; all of it by proptest over any bits; - the routes for convert types from -1000 to 1000 and the ends of i32; every BGR swap pair from -64 to 64 and the ends; the flags and the re-anchor by proptest. RED: soldr cargo test -p obs-data --test obs-tests-core source::async_upload: 1 passed (the values), 27 failed, each on a todo!() (obs_source_async_upload_texture_changed, _size_uniforms, _hlg_peak, _over_sdr_white and _bgr_swap among the first reached). Refs obs-rust#2336
Ports libobs/obs-source-async-upload.c.h, the async video upload
decisions of set_async_texture_size(), update_async_texrender(),
update_async_textures(), check_to_swap_bgrx_bgra() and
obs_source_update_async_video(), to the async_upload module of
rust/obs-source. obs-source.c.h stays C around it: every gs_* call in
its order and under its condition, get_convert_type(),
init_gpu_conversion(), log10f() and the HLG exponent, the direct read
of obs->video.hdr_nominal_peak_level, obs_get_video_sdr_white_level()
and obs_get_video_hdr_nominal_peak_level() (each read where it was,
after gs_texrender_begin() succeeds), the source's and frame's fields,
the frame get and release. The hybrid libobs drops the C file and
links the Rust shims in its place.
Safe core (src/async_upload.rs):
- texture_changed(Format, Format) and tries_gpu();
- size_uniforms() -> SizeUniforms { width, height, width_d2, height_d2,
width_x2_i, height_x2_i }, with (float)u32 as `as f32` (nearest,
ties to even), then one f32 multiply or divide each, as the C;
- hlg_peak() (the C's >, so a NaN is kept with its payload),
maximum_nits(), over_sdr_white() (one f32 division), hdr_lw()
(f32::from(u16), exact) and sets_range();
- linear_alpha(), uses_texrender(), plain();
- bgr_swap() -> Option<i32>;
- reanchor_reads_unbuffered() and reanchor().
Every float is the same single IEEE operation as the C's, in the same
order: no f64 intermediate, and Rust never contracts into a fused
multiply-add. Nothing divides an integer, so no MSVC trap is possible.
The module denies clippy's arithmetic, indexing, as, unwrap, expect,
panic, todo, unimplemented and unreachable lints (the two float
functions and the size conversion allow only what they need), keeps
no state and takes no lock.
Shims (src/ffi/source_async_upload.rs): the fourteen functions keep
the C signatures; struct obs_source_async_upload_format and
struct obs_source_async_upload_size cross by value as #[repr(C)]
mirrors, the enums as int, the transfer as uint8_t. bgr_swap()'s None
goes back as GS_UNKNOWN. No intentional differences: there is no
pointer.
C side: the file leaves libobs.core-source for its own group,
libobs.ported-source-async-upload (LIBOBS_PORTED_SOURCES), whose PCH is
obs.h, obs-source-async-upload.h and obs-source-conversion-plan.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. ci/test_ported_sources.py checks the group on
every host.
test_async_upload_steps still compiles the C file into itself,
unchanged, and test_async_upload_steps_rust runs the same test source
against libobs_rust-static alone: the obs-source member links on its
own, as for test_source_draw_plan_steps_rust.
Tier 1 obs_source::async_upload passes 28/28.
Refs obs-rust#2336
Adds the C oracle of the unchanged libobs/obs-source-async-upload.c.h (rust/obs-c-oracle, oracle/source_async_upload.c, its fourteen functions renamed to oracle_*, with a table of the structs' layouts, the enum values and the type sizes) and tests/source/async_upload_parity.rs, which gives every input to the oracle and the shims and compares the bytes the C returns: each bool as the byte (0 or 1, and equal), the format as its int, every float as its bits, NaN payloads and signs included. - the two structs' sizes, alignments and offsets, the enum values and type sizes against the C header; - the compare with each field changed alone and all at once, from 480 bases at the ends of every field; - the size uniforms for every size from 0 to 70,000, within 64 of every power of two, every 65,521st u32 and the ends; - the HLG clamp for every 4,099th f32 bit pattern, every pattern within 4,096 of 1000 and 28 special patterns (zeros, subnormals, the ends of the normals, the levels, infinities, quiet and signalling NaNs of both signs); the maximum nits for every transfer at each; the ratio for every pair of them; - hdr_lw for every uint16_t; the linear alpha flag for every flag byte with every texrender, re-anchor and range input; the routes for every convert type from -100,000 to 100,000 and the ends of int; every BGR swap pair from -300 to 300 and the ends; - the uniforms of update_async_texrender() in its order (the size uniforms, the HLG peak, the maximum nits, the ratio, hdr_lw, the range), one chain on each side, exhaustive over every transfer, both ranges and every pair of special levels (401,408 chains); - proptests (20,000 cases each): the compare, the size uniforms, the levels (any bit pattern, or drawn from finite, subnormal, NaN and user-set levels), the whole uniform chain, and every decision. Float parity: every uniform is one f32 operation on each side, the same IEEE operation in the same order, so the bits match on x86_64 (SSE) and aarch64; no f64 intermediate, and the Rust side cannot contract into a fused multiply-add. MSVC x64: nothing divides an integer or reaches util_mul_div64()/_udiv128(), so no input needs a guard. No intentional differences. Mutation check (not committed): 27 mutants, each run against Tier 1 (28 tests) and Tier 3 (13). | Area | Mutants | Tier 1 kills | Tier 3 kills | Survivors | |---|---|---|---|---| | compare (trc or width skipped, tries_gpu inverted) | 3 | 3 | 3 | 0 | | size uniforms (height_d2 from width, width_x2_i from height, the conversion truncated to 24 bits, the half texel as 0.5 / (2x) * 2) | 4 | 3 | 3 | 1, equivalent: scaling by 2 commutes with rounding | | levels (the clamp through f32::min, at 1001, the maximum for PQ, the ratio through the reciprocal or through f64 nudged by 1e-12, hdr_lw off at 65535, the range for full range) | 7 | 6 | 7 | 0 | | routes and swap (linear alpha from bit 1, a texrender without one, plain for negative types, BGRA both ways, BGRX_UNORM swapping) | 5 | 5 | 5 | 0 | | re-anchor (and for or, unbuffered read for any source) | 2 | 2 | 2 | 0 | | shims (none as -1, the compare against itself, size axes swapped, halves swapped in the mirror, the format dropped, the re-anchor arguments swapped) | 6 | 0 | 5 | 1, equivalent: the rule is symmetric | Tier 1 28/28 and Tier 3 13/13 pass. Refs obs-rust#2336
- rust/README.md: the obs-source crate row lists libobs/obs-source-async-upload.c.h, and a new row for it in the ported file table: the fourteen functions, why the uniforms are split (each level read stays after gs_texrender_begin(), where it was; the unlocked async_unbuffered is read only for a decoupled source), what stays C, the float rule, the characterized and not endorsed cases and the tests; - rust/obs-source: the crate description and the lib.rs docs name the new file and the async_upload module; - rust/obs-c-oracle: a port_comparison bench file, port_comparison/source_async_upload.rs, in the sorted modules![...] list: 1024 frames through the decisions of one shown frame (the BGR swap, the re-anchor, the compare, the GPU route, the linear alpha flag and the upload route) and through the uniforms of one conversion draw, checked equal by a checksum first. Measured (x86_64 Linux, GCC, release, not pinned to a core, load average about 4; median per 1024 frames, two runs): frame Rust 23.2 and 22.6 us, C 14.8 and 15.0 us; texrender Rust 21.0 and 21.3 us, C 12.1 and 12.5 us, about 8 to 9 ns more per frame, beside the frame's texture upload and draw. Its fixtures are plain vectors and allocate nothing through bmem, so the bench's free check holds. docs/rust-port/naming.md already maps libobs/obs-source*.c.h to rust/obs-source, so it needs no new row. The port changes no behaviour a user can see, so docs/features.md has no line for it. Fixes obs-rust#2336
rdoupe
force-pushed
the
port/async-upload
branch
from
October 25, 2026 05:08
ca10cb4 to
07fce7e
Compare
rdoupe
marked this pull request as ready for review
October 25, 2026 05:09
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #2336
What and why
Ports the async video upload decisions of
libobs/obs-source.c.htorust/obs-source, as a new moduleasync_uploadnext toconversion_planandframe_copy. Every async source (media, cameras, capture cards, PipeWire) runs these once for each frame it shows:set_async_texture_size(): the five-field compare (width, height, format, full range, transfer) that rebuilds the textures, and whether the rebuild tries a GPU conversion or makes one plain texture;update_async_texrender(): the shader parameters of the conversion draw:width,height,width_d2,height_d2,width_x2_i,height_x2_i, the HLG peak clamp at 1000 (BT.2408),maximum_over_sdr_white_nits(the HLG peak or 10000, over the SDR white level),hdr_lw, and whether the colour range is set (limited range only);update_async_textures(): the linear alpha flag, and the route: the texrender, one plain upload, or neither;check_to_swap_bgrx_bgra(): the format a BGRX or BGRA texture is recreated with;obs_source_update_async_video(): the timing re-anchor rule (!async_decoupled || !async_unbuffered).The plan's API was split further. The plan sketched
uniforms(in) -> Uniformsand a three-wayupload_route(). A single uniforms call would need every level before the firstset_eparam(), which moves the white level and HDR peak reads ahead ofgs_*calls. A three-way route would callget_convert_type()on the texrender route too. So there are fourteen functions, and each read and call stays where it was:obs->video.hdr_nominal_peak_levelis still read directly, afterheight_x2_iis set.obs_get_video_sdr_white_level()is read just beforemaximum_over_sdr_white_nits, andobs_get_video_hdr_nominal_peak_level()just beforehdr_lmax. All three are read only aftergs_texrender_begin()succeeds. These are the two different reads the plan names, and both stay.log10f()and the HLG exponent stay C (hlg_exponentfrom the clamped peak).get_convert_type()is called only off the texrender route, andinit_gpu_conversion()only for a convert type that tries it.async_unbufferedis set without a lock, so it is read only for a decoupled source, as the short-circuit did (obs_source_async_upload_reanchor_reads_unbuffered()).The functions:
obs_source_async_upload_texture_changed()and_tries_gpu();_size_uniforms(),_hlg_peak(),_maximum_nits(),_over_sdr_white(),_hdr_lw()and_sets_range();_linear_alpha(),_uses_texrender()and_plain();_bgr_swap();_reanchor_reads_unbuffered()and_reanchor().Two structs (
obs_source_async_upload_format,obs_source_async_upload_size) cross by value.Every
gs_*call stays inobs-source.c.h, in its order and under its condition: the context, the texture and texrender destroys and creates,gs_texrender_begin(), eachgs_effect_get_param_by_name()andgs_effect_set_*(),gs_draw(), the sRGB and blending state. The frame get and release stay there too.Floats are bit-equal to the C. Each uniform is one
f32operation, the same IEEE operation in the same order:(float)cx * 0.5f,0.5f / (float)cxandmaximum_nits / sdr_white_level. The size converts as(float)uint32_tdoes (nearest, ties to even). There is nof64intermediate, and Rust never contracts into a fused multiply-add. The HLG clamp keeps the C's>, so a NaN is kept with its payload and sign. This is checked on x86_64 and in the Windows MSVC clippy and cross lanes.MSVC x64: there is no division by a sample rate and no integer division at all. Nothing reaches
util_mul_div64()/_udiv128()orINT_MIN / -1, so no input can trap and nothing is guarded.Six commits:
Move (behaviour-neutral,
a1e6a7cd2): the decisions go tolibobs/obs-source-async-upload.c.h, declared in the newobs-source-async-upload.hwithoutEXPORT, so they are hidden.The move was checked against the original code. A scratch harness (not committed) compiles origin/master's functions and their helpers verbatim, next to this branch's and the moved file:
set_async_texture_size(),update_async_texrender(),update_async_textures(),update_async_texture(),check_to_swap_bgrx_bgra()andobs_source_update_async_video();obs->videointo a logging accessor that records the value;gs_*call and its arguments (the float uniforms as bits), the levels,log10f(),get_convert_type(),init_gpu_conversion(), the conversion plan, the frame get and release, and the asserts;async_decoupledandasync_unbufferedreturn the field, or a new value on each read.150,000,000 random states: 50,000,000 each with GCC and Clang at
-O2, 20,000,000 each at-O0, and 5,000,000 each under ASan and UBSan (GCC-O0, Clang-O2). All 4,532,576,563 events match, as do the final state and the return value, after one normalization:frame->formatinside the BGR swap (the branch reads it for any texture format);25 deliberately broken moves were tried; 24 fail the harness:
gs_texrender_begin();hdr_lmaxread beforehdr_lw;async_unbufferedread for any source;init_gpu_conversion()called before the convert type test;get_convert_type()called before the texrender test;The one that passes is equivalent:
width_d2computed throughdouble(halving commutes with rounding).Characterization (
508c339a2):test_async_upload_steps, 16 cases. It compiles the moved file (ASan and UBSan) and calls only its functions. It pins:UINT32_MAX;hdr_lwfor everyuint16_t, every flag byte, every BGR swap pair and the four re-anchor cases.It is in the test graph, sorted.
RED (
9cf54642c): Tier 1 againsttodo!(). It ports the 16 C cases 1:1 and adds 12 edge tests:f64models, around every power of two and by proptest over everyu32;f32pattern and by proptest over any bits;GREEN (
aebd69fc1): the safe core and fourteen#[no_mangle]shims, in a newlibobs.ported-source-async-uploadgroup whose PCH isobs.h, the new header andobs-source-conversion-plan.h.source-sets.json, the unity lists, the three export lists andci/test_ported_sources.py, each in sorted place.test_async_upload_steps_rust, which linkslibobs_rust-staticalone, astest_source_draw_plan_steps_rustdoes.Tier 3 (
11fda6401): a C oracle of the unchanged file, the parity tests and a mutation check.Docs (
07fce7e1b): the README rows, the crate's description,lib.rsand aport_comparisonbench file.docs/rust-port/naming.mdalready mapslibobs/obs-source*.c.htorust/obs-source. The port changes nothing a user can see, sodocs/features.mdhas no line.The core denies clippy's arithmetic, indexing,
as, unwrap, expect, panic, todo, unimplemented and unreachable lints. The two float functions and the size conversion allow only what they need. It keeps no state and takes no lock.Bench (x86_64 Linux, GCC, release, not pinned to a core, load average about 4; median per 1024 frames, two runs):
frame(one shown frame's decisions)texrender(one conversion draw's uniforms)That is about 8 to 9 ns more per frame, beside the frame's texture upload and conversion draw.
RED → GREEN
9cf54642c(obs-source: Test the async_upload port; it wasca10cb451before the rebase ontobd029c837).soldr cargo test -p obs-data --test obs-tests-core source::async_upload: 1 passed (the values), 27 failed, each on atodo!().local_gate --lane lintwas clean and--test-diff origin/masterfailed only on those 27 cases.aebd69fc1): Tier 1 28/28.test_async_upload_stepspasses 16/16 on the C backend, on hybridlibobsand onlibobs-c-reference, andtest_async_upload_steps_rustpasses 16/16. Exported symbols are identical on all three (1766); the fourteen functions are local, and the hybrid's come from the Rust archive (the group's object is built only forlibobs-c-reference).11fda6401) 13/13. Each bool is compared as a byte and each float as bits.u32.f32pattern and every pattern within 4,096 of 1000.hdr_lwfor everyuint16_t, every flag byte, the routes from -100,000 to 100,000, and every BGR swap pair from -300 to 300.update_async_texrender()in its order, over every transfer × both ranges × every pair of special levels (401,408 chains).0.5 / (2x) * 2, and the re-anchor arguments swapped (the rule is symmetric).07fce7e1b:local_gate --lane lint,--test-diff origin/master(4015 passed, 6 skipped) and--lane crossall pass;soldr cargo clippy --workspace --target x86_64-pc-windows-msvc --all-targets --locked -- -D warningsis clean;soldr cargo test -p obs-c-oracle --locked --bench port_comparisonpasses.libobs,libobs-c-reference): 100% passed on each: 503/503 (C backend), 529/529 (hybrid), 529/529 (libobs-c-reference), on9eb1917a2(the tree before the bench-only clippy fixup squashed into the docs commit), no reruns needed.Checklist
master(or the description starts with a Stacked: note)docs/features.mdis added or updated (not applicable: no user-visible change)-W..., ratchets): built with scripting ON (PR CI builds no OBS app: rungh workflow run ci.yml --ref <branch>for the full builds) and cross-checked with clang and MSVC (not applicable)