Research-2110: Metal float_ms_ssim option and score parity — 2026-09-25¶
Status: Complete
Authority inspected: signed candidates b234f771a and d966c1feba, plus the exact correction delta on agent/fix-metal-ms-ssim-review.
Scope: Metal float_ms_ssim option parsing (enable_db, clip_db, enable_chroma, enable_lcs), geometry-derived max_db ceiling, 3-plane chroma computation and emission (float_ms_ssim_cb, float_ms_ssim_cr), subsampled chroma min-dimension validation (>= 176), fail-closed L/C/S atom handling, and option-dictionary ownership under ADR-1334. Device-free semantic execution and mutation contracts complement Apple-Silicon parity scaffolding. No benchmark, tuning, retraining, or Netflix golden assertion changes.
Problem Statement¶
Pre-RC1 audit gap T-GAP-METAL-MS-SSIM-DB-CHROMA-OPTIONS-2026-09-07 in docs/state.md noted: CPU float_ms_ssim.c, SYCL integer_ms_ssim_sycl.cpp, and HIP integer_ms_ssim_hip.c expose enable_db, clip_db, and enable_chroma; CUDA exposes the two dB controls. The Metal twin core/src/feature/metal/float_ms_ssim_metal.mm only exposed enable_lcs. Any attempt to request dB-domain scoring or chroma planes on Metal failed during option parsing with -EINVAL. Furthermore, collect_fex_metal passed hardcoded false, INFINITY to vmaf_ms_ssim_emit_scores().
Review of the first candidate found two additional correctness defects. The Apple parity test passed the same VmafFeatureDictionary to CPU and Metal even though vmaf_use_feature() consumes it; that was a use-after-free followed by a double-free. The Metal reduction checked only the combined plane score. A non-finite L/C/S atom at a zero-weight scale can therefore disappear through pow(NaN, 0) == 1, publishing an apparently valid result.
ADR-1221 covers CUDA, SYCL, and HIP and explicitly calls Metal a follow-up. ADR-1334 records this extension rather than rewriting that history.
Parity architecture and implementation¶
-
Option Registration:
enable_db,clip_db, andenable_chromaadded asVMAF_OPT_TYPE_BOOLwith defaultfalseinoptions[]. -
Per-Plane Geometry and Buffers:
MS_SSIM_MAX_PLANES 3defined.MsSsimPlaneGeometryMetaltracks per-scale dimensions, grid sizes, and workgroup partial block counts for each plane.- For
enable_chroma = false(or YUV400P),n_planes = 1. Forenable_chroma = true,n_planes = 3. - Separate pyramid buffers (
pyramid_ref[p][scale],pyramid_cmp[p][scale]) and partials buffers (l_partials[p][scale],c_partials[p][scale],s_partials[p][scale]) allocated for each active plane. -
alloc_metal_buffersandrelease_metal_bufferscleanly handle all planes with complete error recovery and deallocation on failure. -
Chroma Dimension Validation:
- The 5-level 11-tap pyramid requires every dimension to be >= 11 * 2^4 = 176.
-
check_chroma_min_dimenforces that subsampled chroma planes are at least 176x176. Plane allocation uses ceil subsampling, so the exact YUV420P luma minimum is 351x351; 352x352 is merely the next even-sized input. If a scored plane is smaller, init returns-EINVALwith an informative error log. YUV400P resolves to one active plane and bypasses the chroma check even when the option was requested. -
dB conversion and
max_dbceiling (ADR-1334 extending ADR-1221): - When
clip_dbis enabled:max_db = ceil(10. * log10(peak * peak / mse))wherepeak = (1 << bpc) - 1andmse = 0.5 / (w * h). - When
!clip_db:max_db = INFINITY. - The framework-free
float_ms_ssim_option_semantics.howns this formula and active-plane/plane-geometry rules; production and a device-free C test compile the same functions. - In
collect_fex_metal, scores are validated withvmaf_ssim_prepare_score_named(name, raw_score, s->enable_db, s->max_db, index, &score). -
Scores emitted using
vmaf_ms_ssim_emit_scores(plane 0) andvmaf_ssim_emit_score_named(planes 1 and 2), passings->enable_db, s->max_db. -
Dispatch Strategy & Features:
provided_featuresinfloat_ms_ssim_metal.mmupdated with"float_ms_ssim","float_ms_ssim_cb","float_ms_ssim_cr".-
g_metal_featuresincore/src/metal/dispatch_strategy.cupdated to register"float_ms_ssim_cb"and"float_ms_ssim_cr". -
NASA Rule 4 Adherence:
- All helper functions decomposed so every function is <= 60 LOC and cyclomatic complexity <= 10.
-
Validated by unit test in
test_metal_ms_ssim_options_contract.py. -
Failure and ownership semantics:
reduce_plane_means()passes each scale's L/C/S triple throughvmaf_feature_validate_finite_scores_named()before the firstpow(). This applies to chroma and toenable_lcs=false.- CPU and Metal parity runners accept an immutable option specification and independently call
make_options(). Each relinquishes the dictionary immediately aftervmaf_use_feature()and cleans up all still-owned state on failure. - The contract rejects both sharing a consumed dictionary and explicitly freeing it after consumption. The double-free mutant runs before the local pointer is cleared, so it exercises the dangling owner rather than becoming a harmless
free(NULL).
Verification & Test Matrix¶
- Device-free semantic and contract suite:
core/test/test_metal_ms_ssim_option_semantics.cexecutes the same helper production uses. Its worked oracles distinguish the correct 105 dB ceiling at 512x384 from a geometry-free or unbounded implementation, distinguish 3-plane chroma from luma-only behavior, and distinguish ceil subsampling at odd dimensions from truncation.core/test/test_metal_ms_ssim_options_contract.pychecks option metadata, helper wiring, dispatch names, ownership, atom-validation ordering, and NASA Rule 4 limits. Its mutations remove the atom guard, reduce its count from all three L/C/S atoms to one, substitute or remove each individual L/C/S name/value mapping, replace the dB ceiling with infinity, force one plane, restore the rawenable_chromagate, remove fresh dictionary construction, and free a consumed dictionary; every mutation is rejected.core/test/test_nonfinite_collector_wiring.py: updated withmetal/float_ms_ssim_metal.mminREQUIRED["vmaf_ssim_prepare_score_named"]and option-awareMETAL_MS_SSIM_OPTIONS_DB_CALL.- Metal Parity Suite:
core/test/test_metal_float_ms_ssim_parity.c: upgraded fixture to 512x384 (chroma 256x192 >= 176). Addedtest_metal_float_ms_ssim_clip_db_ceilingandtest_metal_float_ms_ssim_parity_chroma. Skips honestly off Apple hardware ([skip: no Metal device]).- Repository gates: focused evidence is recorded by the correction commit; Apple hardware remains unavailable, so the device parity test's skip is not represented as a measured pass.