Skip to content

Fix QTGMC InputType 2/3 at >8 bits: run havsfunc's MVTools Mask on an 8-bit stand-in (task #89) - #259

Merged
StuartCameronCode merged 1 commit into
mainfrom
stuart/89-qtgmc-inputtype-2-3-fails-on-every-8-bit
Nov 24, 2026
Merged

StuartCameronCode merged 1 commit into
mainfrom
stuart/89-qtgmc-inputtype-2-3-fails-on-every-8-bit

Conversation

@StuartCameronCode

Copy link
Copy Markdown
Owner

Problem

havsfunc's QTGMC runs core.mv.Mask(srchClip, bVec1, kind=1, ml=ProgSADMask) when InputType is 2 or 3 and ProgSADMask > 0. ProgSADMask is 10 at Placebo, Very Slow, Slower, Slow and Medium. MVTools' Mask refuses any clip above 8 bits ("Mask: input clip must be GRAY8, YUV420P8, …"). So every 10/12/16-bit job with Input Type 2/3 at those presets failed, on every platform. Every High Precision job (QTGMC at 16 bits) with those settings failed too, even from an 8-bit source. The format sweep missed it because InputType isn't one of its axes.

Fix (template-side, no deps release)

  • plugin_formats.mvtools_mask_any_depth: runs Mask on an 8-bit stand-in clip (a BlankClip of the clip's size and subsampling). For kind 1 it scales ml by 2^(bits−8), then scales the mask back to the clip's depth (x peak * 255 /). This works because:
    • kinds 0–4 never read the clip's pixels;
    • MVTools takes the SAD shift from the clip but scales the scene-change thresholds by the vectors' depth.
  • plugin_formats.havsfunc_mask_any_depth(haf, fn): rebinds havsfunc's module-level core to a proxy that replaces only mv.Mask, for the duration of the QTGMC call. The original is restored in a finally, and patch 7's akarin proxy keeps working.
  • Template: a {{#QTGMC_MASK_ANY_DEPTH}} block wraps _deinterlace_qtgmc. It is emitted only when QTGMCParameters::prog_sad_mask_blocks() is Some, the same condition as test: verify frame counts and geometry against the pipeline, not the model #79's padding. Every other job's script is byte-for-byte unchanged.
  • Probe: adds havsfunc.QTGMC[InputType=2] (records the refusal, listed in HANDLED) and pass.QTGMC[InputType=2] (the pass as the template runs it). The table only gains those two calls; no existing cell changed.
  • Fixes the Input Type descriptions, which didn't match havsfunc: 1 = progressive repair, 2/3 = progressive input with combing from a bad deinterlace.
  • Adds a report (docs/reports/task-89-qtgmc-mask-high-bit-depth), an ENGINEERING_NOTES entry, a reports index row and a CLAUDE.md rule.

Results (macOS arm64, deps 1.18.0-rc3)

  • 10-bit vs 8-bit output differs by 0.16 levels at Slow/Medium and 0.07 at Placebo. That is below the difference with the Mask switched off (0.28 / 0.12).
  • 8-bit output is identical to before.
  • The mask is exact where SADs scale exactly (pel 1). With pel 2, MVTools' half-pel interpolation rounds differently at each depth; this correction is noted in the report.

Tests

  • Rust: new test_269 (block emitted exactly for Placebo..Medium × InputType 2/3, nowhere else); test_263 adjusted.
  • plugin_format_contracts_test: the stand-in mask equals the 8-bit mask at 10 and 16 bits, sample for sample. QTGMC through the helper runs at 10 and 16 bits while the bare call still refuses. The 8-bit output equals the plain call's. havsfunc's core is restored, including after an error.
  • integration_qtgmc_parameters_test: checks the wrapper is in the generated script for those jobs and absent for the others.
  • Format sweep: 2 new variants (InputType 2 at Slower, InputType 3 at Medium). The smoke rows and all 138 nightly rows pass locally.
  • Heavy 8-bit vs 10-bit parity: deinterlace_qtgmc_input_type_2 (0.68) and _3_high_precision (0.26), against a tolerance of 3.0. Both fail without the fix.
  • Local run: cargo test and the Flutter push gate pass. Measured on macOS arm64 only; x86 is covered by this PR's CI (contracts test and the sweep smoke rows).

🤖 Generated with Claude Code

…y depth (task #89)

havsfunc's QTGMC runs mv.Mask(kind=1, ml=ProgSADMask) on InputType 2/3 at
Placebo..Medium, and MVTools' Mask refuses every clip above 8 bits, so all
those 10/12/16-bit jobs (and every High Precision one) failed.

plugin_formats.havsfunc_mask_any_depth rebinds havsfunc's core for the QTGMC
call to a proxy whose mv.Mask is mvtools_mask_any_depth: an 8-bit BlankClip
stand-in of the clip's size, ml x 2^(bits-8) for kind 1, the mask put on the
clip's scale. Exact because kinds 0-4 never read the clip's pixels, and
MVTools takes the SAD shift from the clip but the scene-change thresholds
from the vectors. The template rebinds _deinterlace_qtgmc in a
{{#QTGMC_MASK_ANY_DEPTH}} block only for prog_sad_mask_blocks() jobs; every
other script is unchanged.

10-bit vs 8-bit output 0.16 levels (Slow/Medium), 0.07 (Placebo), below the
Mask-off control; 8-bit output unchanged. Tests: test_269 (test_263
adjusted), the contracts test's task #89 group, probe calls
havsfunc.QTGMC[InputType=2] (HANDLED) and pass.QTGMC[InputType=2] with the
table updated, two format-sweep variants, heavy 8-vs-10 parity cases. Also
fixes the Input Type description in the Deinterlace panel. Report:
docs/reports/task-89-qtgmc-mask-high-bit-depth.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@StuartCameronCode
StuartCameronCode force-pushed the stuart/89-qtgmc-inputtype-2-3-fails-on-every-8-bit branch from 4c0b98a to a6f88ba Compare November 22, 2026 09:12
@StuartCameronCode
StuartCameronCode merged commit 4bcff96 into main Nov 24, 2026
7 of 8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant