Skip to content

build(obs-qsv11): ratchet the target onto the conversion groups (#2625) - #2965

Merged
zackees merged 2 commits into
masterfrom
infra/2625-conversion-obs-qsv11
Oct 29, 2026
Merged

zackees merged 2 commits into
masterfrom
infra/2625-conversion-obs-qsv11

Conversation

@zackees

@zackees zackees commented Oct 29, 2026

Copy link
Copy Markdown
Member

Slice of the conversion ratchet (#2625): plugins/obs-qsv11 opts into
-Wconversion, -Wsign-conversion and -Wfloat-conversion, and the eleven
diagnostics that surfaces are stated at the call sites.

RED — b077ec143

plugins/obs-qsv11/CMakeLists.txt names the three groups for both C and C++
(the target has obs-qsv11.core+.hpp.cpp, obs-qsv11.linux+.hpp.cpp,
obs-qsv11.c+.h.c, obs-qsv11.probe+.h.c, obs-qsv11.linux-c+.h.c). Replaying
the target's compile_commands.json entries with the global -Wno-* pins
removed reports 11 implicit conversions:

Site Diagnostic
QSV_Encoder.cpp.hpp:262,263 int -> uint8_t on the CPU model/family bytes (x2)
QSV_Encoder_Internal.cpp.hpp:526 int -> mfxU32 on width * height * bitsPerPixel / 8
common_utils.cpp.hpp:273 int -> size_t on the memset plane size (x1 reported)
common_utils_linux.cpp.hpp:60 unsigned int -> int for vaDestroySurfaces()'s count
common_utils_linux.cpp.hpp:118 int -> unsigned int for vaCreateSurfaces()'s num_attrs
common_utils_linux.cpp.hpp:173 unsigned int -> mfxU16 for NumFrameActual
common_utils_linux.cpp.hpp:424 int -> unsigned int for __get_cpuid()'s level
obs-qsv11.c.h:570 int -> mfxU32 for MaxDisplayMasteringLuminance
obs-qsv11.c.h:1009 int64_t -> mfxU64 in ts_obs_to_mfx()
obs-qsv11.c.h:1072 ~(3 << 5) -> uint8_t on the NAL mask ("changes the value of -97")

GREEN — 9b41322b6

Every site is an explicit cast at the call site, and every cast keeps the value:

  • the model/family sum is at most 0xF + 0xF0 = 255, so the uint8_t store is
    provably in range;
  • surfaceSize multiplies in mfxU32 (the factors are mfxU16/mfxU8, so the
    old expression was int arithmetic) and divides by 8u;
  • the two memset plane sizes multiply in size_t; width * height is at most
    2^32-1, so nothing can wrap in 32-bit int arithmetic that did not before;
  • vaDestroySurfaces() and __get_cpuid() are the API's signed/unsigned
    signatures; num_attrs is widened to unsigned int at its declaration,
    which is what vaCreateSurfaces() takes; NumFrameActual is an mfxU16
    field and num_surfaces is bounded by MAX_ALLOCABLE_SURFACES;
  • (mfxU32)hdr_nominal_peak_level * 10000u and (mfxU64)ts * 90000u keep the
    whole expression unsigned, so the result is the same modulo nothing;
  • (uint8_t) ~(3u << 5) is the same 0x9F mask the int expression produced.

No #pragma, no per-file -Wno-*, no API change.

Verification

  • Replay of every obs-qsv11.dir compile entry with the pins removed and the
    three groups appended: 11 diagnostics before, 0 after (obs-qsv11.core+ .hpp.cpp, obs-qsv11.linux+.hpp.cpp, obs-qsv11.c+.h.c; the probe and
    linux-c groups were already clean).
  • cmake --build build --target obs-qsv11 compiles obs-qsv11.core+.hpp.cpp,
    obs-qsv11.c+.h.c, obs-qsv11.probe+.h.c and obs-qsv11.linux-c+.h.c clean
    with the new flags and -Werror on the command line.
  • uv run ci/local_gate.py --lane lint --fix ok (73 s), gersemi -c ok.
  • PYTHONPATH=ci uv run python -m unittest ci/test_conversion_ratchet.py ci/test_ci_scope.py — 61 tests ok.

Not verified here: the Linux-only C++ unity group (obs-qsv11.linux+.hpp.cpp)
cannot be built in this checkout's build tree — its Libva_INCLUDE_DIR is
.../libva-2.23.0-dev/include/va, so the group's #include <va/va_drm.h> from
common_utils.h is not found. That failure is pre-existing and independent of
this change (it fails at the PCH's own include line), so those four sites were
verified by replaying the same command with -isystem .../libva-2.23.0-dev/include
added: 4 diagnostics before, 0 after. The Windows unity groups and the AppleClang
half are not compiled on this host; PR CI's Windows lane and the next nightly
cover them.

This is a build-tooling change, so there is no docs/features.md line
(coordination.md §4).

Refs #2625

RED for the ratchet slice: `plugins/obs-qsv11` now names -Wconversion,
-Wsign-conversion and -Wfloat-conversion for both C and C++. With the global
-Wno-* pins overridden, the target's own unity groups report eleven implicit
conversions; the next commit states them at the call sites.
GREEN for the ratchet slice. Eleven sites in four files, each an explicit
cast at the call site that keeps the value:

- QSV_Encoder.cpp.hpp: the CPU model/family bytes summed from two masked
  fields (max 255) are cast once at the store.
- QSV_Encoder_Internal.cpp.hpp: surfaceSize multiplies in mfxU32 so the
  product stays unsigned.
- common_utils.cpp.hpp: the memset plane sizes multiply in size_t.
- common_utils_linux.cpp.hpp: vaDestroySurfaces() takes an int count,
  num_attrs is unsigned to match vaCreateSurfaces(), NumFrameActual is an
  mfxU16, and __get_cpuid() takes an unsigned level.
- obs-qsv11.c.h: MaxDisplayMasteringLuminance is mfxU32, ts_obs_to_mfx()
  returns mfxU64, and the NAL mask is cast to the uint8_t it is ANDed into.

@zackees zackees left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coordinator review — one cast placement changes a value, and one number in the body is wrong. The other nine sites are parity.

1. obs-qsv11.c.h ts_obs_to_mfx() — the cast moved from the result into the operand, which is not a value-preserving statement.

return (mfxU64)ts * 90000u / voi->fps_num;   // on the branch
return ts * 90000 / voi->fps_num;            // on master

The compiler's implicit conversion was on the return, so master computes in int64_t and widens once. The branch widens ts first, so for a negative ts the multiply and the divide both happen in uint64_t and give a different number: at ts = -1, fps_num = 30, master returns 2^64 - 3000, the branch returns (2^64 - 90000) / 30. Negative timestamps are not hypothetical in this file — ts_mfx_to_obs() right below has an explicit ts < 0 branch, and frame->pts feeds this on the first frames of a stream.

Parity form, if you agree:

return (mfxU64)(ts * 90000 / voi->fps_num);

(ts * 90000 stays inside int64_t for any sane timestamp, so there is no overflow introduced by keeping the arithmetic signed.)

2. The body's justification for family is off by one range. It says "the model/family sum is at most 0xF + 0xF0 = 255", but family is ((cpuInfo[0] >> 8) & 0xF) + ((cpuInfo[0] >> 20) & 0xFF), whose maximum is 0xF + 0xFF = 270. The static_cast<uint8_t> is still parity (master truncates 270 to 14 the same way), so no code change is needed — only the sentence, so the claim does not read as a proof that is false.

Sites I checked and consider sound: the two model/family stores (parity), surfaceSize in mfxU32 (same product, and now defined instead of signed-overflowing), the two memset sizes, vaDestroySurfaces()'s (int) count, num_attrs becoming unsigned int (only used for vaCreateSurfaces()), (mfxU16)num_surfaces, __get_cpuid()'s level, MaxDisplayMasteringLuminance (operand cast is harmless there because the level is pq ? … : 1000 : 0, never negative), and start[0] &= (uint8_t)~(3u << 5); — 0x9F, identical to master's & -97 on a uint8_t.

I am not queueing this one until the ts_obs_to_mfx cast is answered; it is a one-line change and the rest is ready.

@zackees

zackees commented Oct 29, 2026

Copy link
Copy Markdown
Member Author

Handed off to the coordinator.

@zackees

zackees commented Oct 29, 2026

Copy link
Copy Markdown
Member Author

Handed off to the coordinator.

CI is green apart from the sanitizer lane, which is queued behind master's in-progress Sanitizers dispatch; auto-merge is on. The slice's local evidence and the RED/GREEN SHAs are in the description. Rebase/lint fixups and re-queueing after an ejection are the coordinator's.

@zackees
zackees added this pull request to the merge queue Oct 29, 2026
Merged via the queue into master with commit f364c1f Oct 29, 2026
36 checks passed
@zackees
zackees deleted the infra/2625-conversion-obs-qsv11 branch October 29, 2026 23:05
MCPVOT pushed a commit to MCPVOT/obs-studio that referenced this pull request Oct 30, 2026
…bs-rust#2965) (obs-rust#2969)

obs-rust#2965 stated the NAL-mask conversion as `(uint8_t)~(3u << 5)`. The mask
is right (0x9F), but the cast truncates a constant, and MSVC reports that
as C4310, which the ratchet's warnings-as-errors turn makes fatal:

  plugins/obs-qsv11/obs-qsv11.c.h(1072,25): warning C4310: cast truncates
  constant value
  plugins/obs-qsv11/obs-qsv11.c.h(1072,25): error C2220: the following
  warning is treated as an error

Masking in `unsigned` first keeps the expression's intent and leaves the
cast a value that already fits, so no compiler sees a truncation. The
byte written is unchanged.

Refs obs-rust#2625
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.

1 participant