Repository navigation
libobs: Port the scene blend mode table to obs-scene-blend - #1543
Merged
Merged
Conversation
The blend mode table in libobs/obs-scene-blend.c.h (obs-rust#1521) gets its own crate, obs-scene-blend, as obs-scene-bounds did. The safe core names the blend factors, operations and modes with the values of graphics.h and obs.h, and has the table and the row lookup as todo!() stubs. The Tier 1 tests mirror test_scene_blend 1:1 (same six names and cases), plus new edge cases: the row lookup against the table, the factor and operation values, values no row uses, and which modes split color from alpha. They are a module of obs-tests-core, so no new test binary. Eight of eleven fail with "not yet implemented"; the three enum value checks pass. Refs obs-rust#1520
obs_blend_mode_params, the table render_item_texture() reads to set each scene item's blend factors and operation, moves to the obs-scene-blend crate. The file is one table, so the shim is the table: a #[no_mangle] static with the same rows, built at compile time from the safe core. libobs-with-rust drops the C file and links that static. The table could stay static only while it shared a translation unit with obs-scene.c. Now that its file is its own ported group, libobs.ported-scene-blend, the C table has external linkage in both builds, with its row type, struct obs_blend_mode_param, and an extern declaration in the new private header obs-scene-blend.h (in the core PCH and the group's own). obs-scene.c is unchanged and still indexes the table unchecked, so a mode past OBS_BLEND_DARKEN reads past its end, as before. The symbol is not EXPORT: it is hidden in the C build by -fvisibility=hidden and in the Rust one through rust-hidden.txt, rust-exports.map and rust-unexports-macos.txt. The export_list check now also finds #[no_mangle] statics. Tier 3 (oracle/scene_blend.c) compares the whole table with the C one, row by row and byte for byte, plus the row count, the row struct layout and the enum values. test_scene_blend compiles the C file into itself and is unchanged. Refs obs-rust#1520
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 #1520 (PR 2 of 2; PR 1, #1521, moved the table into its own file and added its characterization test)
What and why
This PR ports
libobs/obs-scene-blend.c.hto a new crate,rust/obs-scene-blend. The file holds a single table,obs_blend_mode_params.render_item_texture()inobs-scene.creads it to look up the blend factors it passes togs_blend_function_separate()and the operation it passes togs_blend_op()for each scene item blend mode.libobs-with-rustdrops the C file and links the Rust table instead.obs-scene-blend, one crate per file likeobs-scene-bounds(meta: Phase 6 libobs core migration through opaque C seams #444). It is listed in naming.md, in bothrust/README.mdtables and in the testing-policyobs-tests-corerow. It adds no new dependency.src/blend.rs):BlendType,BlendOpandBlendMode, with the values fromgraphics.handobs.h.BlendParams, the row type.blend_mode_params()returns the whole table andblend_params(mode)returns one row. Both areconst fnover aconsttable.cfg, nounsafe.src/ffi/scene_blend.rs): the C file contains only a table, so the shim is also a table.obs_blend_mode_paramsis a#[no_mangle]static of#[repr(C)] obs_blend_mode_paramrows (five Cints), built from the safe core at compile time. It contains no code that runs.staticand sharedlibobs.core-sourcewithobs-scene.c, its only user. A ported group is a separate translation unit, so the table now has external linkage in both builds.struct obs_blend_mode_param, the same five fields that were in the anonymous struct) and anexterndeclaration move to a new private header,libobs/obs-scene-blend.h. It is insource-sets.jsonbut not installed, likeobs-scene-bounds.h. Bothlibobs.pch.h(soobs-scene.csees it) and the group's own PCH include it.obs-scene.c.his unchanged and still indexes the table directly.obs-scene-blend.c.hleaveslibobs.core-sourcefor its own group,libobs.ported-scene-blend, which is listed inLIBOBS_PORTED_SOURCES.libobs-ported-scene-blend.pch.hincludesobs.h(for theOBS_BLEND_*values the C test uses) andobs-scene-blend.h, and nothing from the core. That lets the C test and the oracle compile the file on its own.sources.cmake,os-*.cmake, obs-build andported_sources.pyneed no change; they all readsource-sets.json.EXPORT. In the C build-fvisibility=hiddenhides the table. In the Rust buildrust-hidden.txt,rust-exports.mapandrust-unexports-macos.txthide it, and there is norust-exports.dfragment.nmshowsr obs_blend_mode_params(local, read-only) in bothlibobs.sobuilds.export_listcheck: before this PR it only collected#[no_mangle]functions. A#[no_mangle] staticwould have gone unnoticed, or the scan would have picked the nextfnin the file. It now also collects statics. To check this, I removedobs_blend_mode_paramsfromrust-hidden.txt: the check then fails with "shims missing from rust-exports.d and rust-hidden.txt: ["obs_blend_mode_params"]".oracle/scene_blend.c): renames the table tooracle_obs_blend_mode_paramswith a#defineand includes the original file. It adds accessors for the row count (from the table's ownsizeof), the row struct's size, alignment and field offsets, and every value ofenum obs_blending_type,enum gs_blend_typeandenum gs_blend_op_type.obs_sceneitem_set_blending_mode()stores any value it is given, so a mode pastOBS_BLEND_DARKENreads past the end of the table. That is undefined behaviour in C, and the Rust static behaves the same way. Scene loading and obs-websocket only produce the seven valid modes. I added no clamp; it would be a separate behaviour fix (test_scene_blendmarks this case "characterized, not endorsed"). This is documented in the shim, the parity test header and therust/README.mdrow.test_scene_blend(6 cases) compiles the C file into itself and is unchanged. It passes in every lane but cannot see the swap. Tier 3 is the proof of the swap, and so istest_darken_transparent, which draws Darken through the real libobs and therefore throughlibobs-with-rustin mode ON.RED → GREEN
d19567b92libobs: Add Tier 1 tests for the scene blend mode table port. The table and the row lookup aretodo!().soldr cargo test -p obs-data --test obs-tests-core scene_blendfails 8 of 11 with "not yet implemented"; the three enum value checks pass.tests/scene_blend/main.rs) mirrorstest_scene_blend1:1: the same six test names (withouttest_) and the same cases.BlendMode::ALLin row order, the factor and operation values, values no row uses (GS_BLEND_OP_SUBTRACT,GS_BLEND_ZERO,GS_BLEND_SRCALPHASAT), and the check that only Screen and Multiply use different factors for color and alpha.obs-tests-core. No new test binary:ci/test_binary_cap.pypasses (8 of 8).5902c53felibobs: Port the scene blend mode table to obs-scene-blend.scene_blendpasses 16/16 (11 Tier 1, 5 Tier 3), and the wholeobs-tests-corebinary passes 216/216.tests/scene_blend/parity.rs). The domain is finite, so everything is compared and nothing is sampled:sizeof;obs_blend_mode_paramagainst the C struct (the Tier 2 layout test);blend_params(mode)for every mode against the C row.MintoMax, then restored it.parity_every_row_matches_candparity_blend_params_matches_c.libobs-with-rustrebuilt:test_darken_transparent(darken_keeps_background_where_transparent) failed in mode ON and passed in mode OFF.test_scene_blendpassed in both modes, because it compiles the C table itself and never sees the Rust one.ENABLE_RUST_LIBOBS=OFFandON,ENABLE_WAYLAND=ON). Each tree runs the full cmocka suite againstlibobs(OFF) and againstlibobs-with-rust(ON):ENABLE_RUST_LIBOBS=OFF)ENABLE_RUST_LIBOBS=ON)No test was skipped or not run in any of the four runs. The export lists are also identical across the two lanes, and none of them contains
obs_blend_mode_params.test_scene_blendandtest_darken_transparentpass in all four runs.libobs.ported-scene-blend+.h.cis linked intolibobsand not intolibobs-with-rust. Inlibobs-with-rustthe table comes from the Rust static.Environment: headless (private Xvfb, private D-Bus, fresh HOME).
ci/local_gate.py:--lane lint(clang-format, gersemi, rustfmt, clippy-D warnings, Dylints, ifdef ratchet, test-binary cap): passed.--lane cross(clippy and Dylints forx86_64-pc-windows-msvcandaarch64-apple-darwin, plus a link of every test binary, the oracle included): passed.--lane cross-release: passed.--lane rust-test(soldr cargo test --workspace --locked, plus a--no-runlink forx86_64-pc-windows-gnu): passed. The obs-util harness passes 668/668, including the extendedexport_listcheck.ci/test_build_groups.py,ci/test_naming.py,ci/test_ported_sources.py,ci/test_rust_scope.py,ci/test_binary_cap.py,ci/test_cmocka_includes.py: OK.Real app: not applicable (no behaviour change).
Checklist
master(or the description starts with a Stacked: note)test_scene_blendlanded in libobs: Move the scene blend mode table into obs-scene-blend.c #1521)docs/features.mdis added or updated (not applicable: no user-visible change)-W..., ratchets): not applicable