Skip to content

media: apple: avd: VP9 temporal MVs and reference scale after a size change - #3017

Merged
DjDeveloperr merged 2 commits into
aurora-silicon:mainfrom
sithglan:thomas/avd-vp9-spec-fixes
Nov 24, 2026
Merged

DjDeveloperr merged 2 commits into
aurora-silicon:mainfrom
sithglan:thomas/avd-vp9-spec-fixes

Conversation

@sithglan

@sithglan sithglan commented Nov 23, 2026 •

Copy link
Copy Markdown

What: Two VP9 fixes in the Apple AVD decoder for streams that change size: no temporal motion vectors from a reference frame of another size, and the reference scale's two 16-bit halves in the right order. Split out of #2136.
Tested: J813 M5 Air at 6fd057431b55: all libvpx VP9 vectors in both FFmpeg builds match the base, and the codec clips are bit-exact; 0 failed units, 0 DART faults, 0 new kernel errors (issuecomment-7115442359).
Risk: two-way door · every Mac whose AVD decodes VP9 (shared avd-vp9.c); checked on the J813 only.
Not yet: a row on a Mac with the queued-firmware AVD transport.

Details

Two VP9 fixes in the AVD driver for frames that change size, split out of #2136. Both are independent of #2136's change that accepts frames smaller than the capture format.

  1. Temporal MVs only from a frame of the same size. VP9 uses the previous frame's motion vectors only if that frame has the same size (UsePrevFrameMvs, libvpx's use_prev_frame_mvs). avd_vp9_uses_prev_mv() doesn't compare sizes, so after a size change the decoder reads an MV buffer laid out for the other size.
    • Frames of different sizes already pass validate_dec_params() when they share the 64x16 aligned capture format, for example 1920x1080 and 1900x1080.
    • With media: apple: avd: decode VP9 frames smaller than the capture format #2136's fits rule alone, every non-error-resilient stream that changes size on an inter frame crashed the firmware at the first frame of the new size ("open firmware error 0x8", a timeout and a decoder reset). With this commit, no frame fails in the firmware.
  2. Reference scale halves. set_refs() packs the horizontal reference scale into the upper 16 bits. The decoder reads the vertical one there.
    • This only matters for references whose aspect ratio differs from the frame's.
    • A size change within the aligned capture format predicts from such a reference already.
    • With media: apple: avd: decode VP9 frames smaller than the capture format #2136, libvpx's vp90-2-05-resize (352x288 to 282x173) and vp90-2-18-resize decode bit-exact (10/10 and 100/100 frames, up from 3 and 94).
Evidence

Testing

At this head (6fd057431b55, on integration/aurora 70a00e583b03):

  • tests/vp9-test.py passes. Each commit adds its own case, which fails on the commit before it.
  • The AVD host tests in run-host-tests.py pass (12/12).
  • The AVD KUnit suites pass in arm64 QEMU (avd-pm.kunitconfig): 81/81, apple-avd-vp9 included.
  • checkpatch --strict is clean on both commits.

Hardware: J813 (MacBook Air M5, legacy transport) row on this exact head against its base: #3017 (comment). The libvpx VP9 suite (273/31/10) and the codec clips are identical to the base in both FFmpeg builds, with the same AVD kernel lines and 0 DART faults, 0 failed units and 0 AVC denials. None of those vectors reaches the changed code without #2136.

… size

VP9 predicts motion vectors from the previous frame only if that frame
has the same size (UsePrevFrameMvs in compute_image_size(), libvpx's
use_prev_frame_mvs). avd_vp9_uses_prev_mv() does not compare sizes, so
after a size change the decoder reads the previous frame's MV buffer,
which is laid out for the other size. Frames of different sizes already
pass validate_dec_params() when they share the 64x16 aligned capture
format, e.g. 1920x1080 and 1900x1080.

Accepting frames smaller than the capture format, as
aurora-silicon#2136 does, makes this common: with that change
alone, every VP9 stream that changes size on an inter frame without
error resilience fails at the first frame of the new size with "open
firmware error 0x8", a timeout and a decoder reset. With this patch no
frame fails in the firmware.

Record the size of each frame and require the previous one to match.
The host test decodes a 1900x1080 frame after a 1920x1088 one and checks
that the prior bank's MV buffer is not used.

Signed-off-by: Thomas Glanzmann <thomas@glanzmann.de>
set_refs() packs the horizontal reference scale into the upper 16 bits
and the vertical one into the lower 16 bits. The decoder reads them the
other way round. A reference scaled the same in both directions (2:1,
4:3) decodes either way, so only references whose aspect ratio differs
from the frame's were wrong.

A frame whose size changes within its 64x16 aligned capture format
(1920x1080 to 1900x1080) already predicts from such a reference. Once
frames smaller than the capture format are accepted
(aurora-silicon#2136), libvpx's vp90-2-05-resize.ivf (352x288 to
282x173) and vp90-2-18-resize.ivf (310x230 to 248x138) do too, and
decode bit-exact against libvpx's MD5s: 10 of 10 and 100 of 100 frames,
up from 3 and 94.

Pack the vertical scale with AVD_HDR_HEIGHT() and the horizontal one with
AVD_HDR_WIDTH(), as the reference size above it is. The host test checks
the word for a 1440x1088 reference of a 1920x1088 frame.

Signed-off-by: Thomas Glanzmann <thomas@glanzmann.de>
@sithglan

Copy link
Copy Markdown
Author

J813 row on this exact head.

Setup

  • MacBook Air M5 (J813, T8142). The AVD runs on the legacy transport (open-compat).
  • Two one-shot trial boots through the enrolled aura (1.0.0b12-g693083b4), on the default kernel command line, both with the same config:
    • base: integration/aurora 70a00e583b03, 7.3.0-aurora-j813-intbase+;
    • this PR: 6fd057431b55, 7.3.0-aurora-j813-avdspec+.
  • On each boot:
    • the libvpx VP9 test vectors (314), compared frame by frame with libvpx's MD5s;
    • six codec clips (H.264, HEVC, HEVC Main10, VP9, AV1, H.264 4K60), compared with FFmpeg's software decode.
  • Both sets run through two FFmpeg builds with the V4L2 request hwaccel. One renegotiates the capture format on a size change. The other, FFmpeg PR 20847 v2, decodes a frame that fits into the current buffers.
base this PR
libvpx VP9, renegotiating FFmpeg 273 match / 31 fail / 10 unsupported 273 / 31 / 10
libvpx VP9, in-place FFmpeg 273 / 31 / 10 273 / 31 / 10
codec clips, both FFmpeg builds bit-exact bit-exact
  • The per-vector results are identical between the two kernels, in both FFmpeg builds.
  • Kernel: the same AVD lines on both boots:
    • 3 × "open firmware error 0x8", with their resets and timeouts (vp90-2-05-resize and vp90-2-18-resize, renegotiating build);
    • "unexpected bitstream resolution" for the size-changing vectors in the in-place build.
  • Counts: 0 DART faults, 0 failed units, 0 AVC denials (SELinux not enabled). The only new kernel error lines against the default boot are those AVD lines, the same 17 on both boots.

What this shows and what it doesn't. It shows no regression on the J813. It doesn't show the fixes working: none of these vectors reaches the changed code without #2136. In the in-place build a smaller frame is still refused, and the renegotiating build gives the same results on both kernels. 05-resize and 18-resize still fail with firmware error 0x8 in the renegotiating build on both kernels, so that has a different cause, which I'll look into separately. The effect of the two commits shows with #2136's fits rule: 05-resize 10/10 and 18-resize 100/100 frames bit-exact, and no firmware errors on the inter-frame resizes (the 11-17 series runs in #2136).

Assisted-by: LLM (Claude:Opus 5.5)

@sithglan
sithglan marked this pull request as ready for review November 23, 2026 22:11

@DjDeveloperr DjDeveloperr left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Formal adversarial §1–§6 pre-PR review at live head 6fd057431b55e034a3b01e7f97d97e09ba55cb2a (checked against live integration/aurora 5746ef8a5afd).

Checklist Audit (§1–§6)

  • §1 No model gating: Pass. Pure VP9 specification and hardware-packing fixes in drivers/media/platform/apple/avd/avd-vp9.c; zero model, SoC, board, or firmware-version gating.
  • §2 Production-ready / Code correctness: Pass.
    • Commit 1 (e04db3b4f021): Records width/height (frame_*_minus_1 + 1) in struct avd_vp9_frame_info via update_ctx_cur_info(), propagated to vp9_ctx->last in both QFW (avd_vp9_run()) and legacy (avd_vp9_done()) paths, and enforces avd_vp9_same_size(frame, last) in avd_vp9_uses_prev_mv() at both call sites (make_flags1() VP9_HAS_REF and set_header() temporal-MV color DMA address). No integer overflow or lifetime issues. (Minor pre-existing non-blocking note: VP9 UsePrevFrameMvs also excludes last->flags & V4L2_VP9_FRAME_FLAG_INTRA_ONLY, which was already absent prior to this PR.)
    • Commit 2 (6fd057431b55): Fixes the swapped 16-bit halves in set_refs() from AVD_HDR_HEIGHT(xscale) | AVD_HDR_WIDTH(yscale) to AVD_HDR_HEIGHT(yscale) | AVD_HDR_WIDTH(xscale), matching AVD_HDR_HEIGHT (GENMASK(31, 16)) / AVD_HDR_WIDTH (GENMASK(15, 0)) in avd-inst.h and hdr_70_ref_height_width immediately above.
    • drivers/media/platform/apple/avd/tests/vp9-test.py adds deterministic host tests exercising both commits under ASan/UBSan in QFW two-bank mode (prior-bank MV suppression on 1920x1088 -> 1900x1080, and 0x40003000 vs 0x30004000 for 1440x1088 -> 1920x1088), failing prior to each commit.
  • §3 Safety: Pass. Prevents reading a mismatched-size temporal MV buffer and fixes wrong reference scale packing.
  • §4 Clean-room & Attribution: Pass. Both commits (e04db3b4f021, 6fd057431b55) carry human author/committer (Thomas Glanzmann <thomas@glanzmann.de>) and human Signed-off-by: only; zero AI commit trailers; Assisted-by: disclosed in PR body.
  • §5 Evidence: Pass. Exact-head A/B hardware row on J813 (6fd057431b55 vs integration/aurora 70a00e583b03, default kernel command line, enrolled Aura 1.0.0b12-g693083b4) ran all 314 libvpx VP9 vectors across both FFmpeg builds + 6 codec clips (bit-exact), matching base with 0 DART faults, 0 failed units, 0 AVC denials (SELinux disabled on J813), and 0 new kernel error lines vs base, backed by 12/12 AVD host tests, 81/81 arm64 QEMU KUnit tests, and positive resize decode proof with #2136 (05-resize 10/10, 18-resize 100/100 bit-exact). (Note for MERGETRAIN6: a queued-firmware / SELinux-enforcing Mac smoke run is good coverage alongside the J813 legacy-transport row.)
  • §6 Naming & CI: Pass. Clean naming; CI host-tests is SUCCESS; merges cleanly onto live integration/aurora.

Verdict: APPROVE — 0 blockers; ready for MERGETRAIN6.

Assisted-by: LLM (Gemini 4 Neon)

@github-actions github-actions Bot added area:media Area from CODEOWNERS (bot) needs-hw-row No hardware row at the PR head (bot) needs-template PR body lacks Tested or Risk (bot) blast:all Macs affected, from Merge risk (bot) door:two-way Revertible or not, from Merge risk (bot) ready-to-merge Meets the merge policy: merge it (bot) and removed needs-hw-row No hardware row at the PR head (bot) needs-template PR body lacks Tested or Risk (bot) labels Nov 24, 2026
@github-actions

github-actions Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Merge readiness at 6fd05743: ready to merge

Check Detail
CI at head ok 1 check passed
Review ok approved by DjDeveloperr
Requested changes ok none
Hardware row at head ok in the PR body at 6fd05743
Conflicts ok none
PR text ok Risk: two-way · every Mac whose AVD decodes VP9 (shared avd-vp9.c); checked on the J813 only.

Areas: area:media
Merge: gh pr merge 3017 --merge (Owners and Core through the bypass: add --admin).

Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels.

@github-actions github-actions Bot added ready-to-merge Meets the merge policy: merge it (bot) and removed ready-to-merge Meets the merge policy: merge it (bot) labels Nov 24, 2026
@DjDeveloperr
DjDeveloperr merged commit 6247ec9 into aurora-silicon:main Nov 24, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:media Area from CODEOWNERS (bot) blast:all Macs affected, from Merge risk (bot) door:two-way Revertible or not, from Merge risk (bot) ready-to-merge Meets the merge policy: merge it (bot)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants