Repository navigation
build(obs-qsv11): ratchet the target onto the conversion groups (#2625) - #2965
Conversation
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
left a comment
There was a problem hiding this comment.
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 masterThe 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.
|
Handed off to the coordinator.
|
|
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. |
…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
Slice of the conversion ratchet (#2625):
plugins/obs-qsv11opts into-Wconversion,-Wsign-conversionand-Wfloat-conversion, and the elevendiagnostics that surfaces are stated at the call sites.
RED —
b077ec143plugins/obs-qsv11/CMakeLists.txtnames 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). Replayingthe target's
compile_commands.jsonentries with the global-Wno-*pinsremoved reports 11 implicit conversions:
QSV_Encoder.cpp.hpp:262,263int->uint8_ton the CPU model/family bytes (x2)QSV_Encoder_Internal.cpp.hpp:526int->mfxU32onwidth * height * bitsPerPixel / 8common_utils.cpp.hpp:273int->size_ton the memset plane size (x1 reported)common_utils_linux.cpp.hpp:60unsigned int->intforvaDestroySurfaces()'s countcommon_utils_linux.cpp.hpp:118int->unsigned intforvaCreateSurfaces()'snum_attrscommon_utils_linux.cpp.hpp:173unsigned int->mfxU16forNumFrameActualcommon_utils_linux.cpp.hpp:424int->unsigned intfor__get_cpuid()'s levelobs-qsv11.c.h:570int->mfxU32forMaxDisplayMasteringLuminanceobs-qsv11.c.h:1009int64_t->mfxU64ints_obs_to_mfx()obs-qsv11.c.h:1072~(3 << 5)->uint8_ton the NAL mask ("changes the value of -97")GREEN —
9b41322b6Every site is an explicit cast at the call site, and every cast keeps the value:
0xF + 0xF0= 255, so theuint8_tstore isprovably in range;
surfaceSizemultiplies inmfxU32(the factors aremfxU16/mfxU8, so theold expression was
intarithmetic) and divides by8u;size_t;width * heightis at most2^32-1, so nothing can wrap in 32-bit
intarithmetic that did not before;vaDestroySurfaces()and__get_cpuid()are the API's signed/unsignedsignatures;
num_attrsis widened tounsigned intat its declaration,which is what
vaCreateSurfaces()takes;NumFrameActualis anmfxU16field and
num_surfacesis bounded byMAX_ALLOCABLE_SURFACES;(mfxU32)hdr_nominal_peak_level * 10000uand(mfxU64)ts * 90000ukeep thewhole expression unsigned, so the result is the same modulo nothing;
(uint8_t) ~(3u << 5)is the same0x9Fmask theintexpression produced.No
#pragma, no per-file-Wno-*, no API change.Verification
obs-qsv11.dircompile entry with the pins removed and thethree groups appended: 11 diagnostics before, 0 after (
obs-qsv11.core+ .hpp.cpp,obs-qsv11.linux+.hpp.cpp,obs-qsv11.c+.h.c; the probe andlinux-c groups were already clean).
cmake --build build --target obs-qsv11compilesobs-qsv11.core+.hpp.cpp,obs-qsv11.c+.h.c,obs-qsv11.probe+.h.candobs-qsv11.linux-c+.h.ccleanwith the new flags and
-Werroron the command line.uv run ci/local_gate.py --lane lint --fixok (73 s),gersemi -cok.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_DIRis.../libva-2.23.0-dev/include/va, so the group's#include <va/va_drm.h>fromcommon_utils.his not found. That failure is pre-existing and independent ofthis 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/includeadded: 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.mdline(coordination.md §4).
Refs #2625