Skip to content

media: apple: avd: VP9: one segmentation map per stream, shared by the banks - #2195

Open
m0d16l14n1 wants to merge 1 commit into
aurora-silicon:integration/aurorafrom
m0d16l14n1:j815/avd-vp9-shared-seg
Open

m0d16l14n1 wants to merge 1 commit into
aurora-silicon:integration/aurorafrom
m0d16l14n1:j815/avd-vp9-shared-seg

Conversation

@m0d16l14n1

@m0d16l14n1 m0d16l14n1 commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

The VP9 segmentation map carries over from frame to frame: a frame with temporal map prediction, or one that keeps the map without updating it, reads the map the frame before it left. With the queued transport the two banks alternate, and each had its own seg buffer, so a frame read the map of the frame before last. Every stream with segmentation decoded wrong from its first non-key frame.

Change: one seg buffer per stream, used by both banks.

Tested on J815 (MacBook Air 15" M5), with frame-by-frame MD5 against libavcodec, full decode plus a seek:

  • Before: libvpx aq-mode 2 (complexity) and 3 (cyclic refresh) at 720p and 1080p, and a 360p screen-content clip, went wrong from frame 1–3.
  • After: all bit-exact.
  • The rest of the set: 59 of 59 PASS in a 67-stream H.264/HEVC/VP9/AV1 set, which also runs three decodes at once. The other 8 are 10-bit and interlaced streams the driver doesn't expose.
  • The single-bank transport also decoded these streams correctly, which is what pointed at the bank swap.

checkpatch --strict is clean, and the change builds with W=1 on integration/aurora e95ff7b (this head, a22f3eb7: rebased, with one Signed-off-by and no co-author trailer).

With #2136 (sithglan, open): #2136 clears the bank's seg buffer from the CPU on a frame size change (avd_vp9_run_preamble()). After this PR, that buffer is the stream's shared vp9_ctx->seg, so the clear could hit a map the other bank's frame is still using on the queued transport. Whichever lands second should not memset the shared map while a frame is in flight. Either it waits until the queue is idle, or it sets VP9_SEG_RESET on the first frame after the size change and lets the firmware reset the map. If #2136 lands first, I'll rebase this onto it and make that change here. Which of the two the firmware honours needs a resolution-change vector on hardware.

Part of the J815 bring-up; board results are summarised in #135.

Assisted-by: LLM (Claude:Opus 5.5)

@gig3m

gig3m commented Nov 18, 2026

Copy link
Copy Markdown
Contributor

Same bug and same fix on a J813 (MacBook Air 13" M5). The AVD runs the open-queue transport here (using open-queue transport (7 frames in flight)). Decoding went through VA-API (libva-v4l2-request, ffmpeg -hwaccel vaapi), and the frame MD5s were compared with libavcodec's software decode of the same file.

Test streams, made with libvpx-vp9 from testsrc2, realtime:

Stream Without this PR With this PR
720p, aq-mode 3, 90 frames 82 wrong, from frame 9 0 wrong
1080p, aq-mode 2, 120 frames not run 0 wrong
720p, aq-mode 0 (no segmentation), 90 frames 0 wrong 0 wrong

"Without" is my kernel on #2135's merged head 408e27268fd6. "With" is the same kernel with this commit picked on top, which rebuilt only apple-avd.ko. The aq-mode 3 stream also decoded bit-exact after each of four deep sleeps (with #2193) on that kernel.

🤖 Generated with Claude Code

@RyanTheTide

Copy link
Copy Markdown
Contributor

Blockers: 1.

  1. The commit (a47cddb) has a Co-Authored-By: Claude Opus 5.5 trailer and two copies of the same Signed-off-by. Please re-commit with one Signed-off-by and no co-author trailer. The PR body ends in "Generated with Claude Code"; its last line should be Assisted-by: LLM (<Vendor>:<Model>).
  2. This conflicts in intent with media: apple: avd: decode VP9 frames smaller than the capture format #2136. That PR clears the bank's seg buffer from the CPU on a frame size change (avd-vp9.c:865-866 at its head, in avd_vp9_run_preamble()). After this PR the buffer is vp9_ctx->seg, which both banks share, so that memset would hit the buffer the other bank's frame may still be using on the queued transport. Please coordinate with media: apple: avd: decode VP9 frames smaller than the capture format #2136 so that whichever lands second clears the shared map only once no frame is in flight on it, or relies on VP9_SEG_RESET alone.

The fix itself is correct. vp9_ctx->seg is allocated in avd_vp9_start() (avd-vp9.c:1162) at the same size the per-bank buffer had, the error path frees it through avd_vp9_free() (:1124), and both seg slots in set_header() point at it. The single-bank path is unchanged in effect.

HW row: covered on J815 and J813. Add a regression line from one of those boots: 0 AVC, 0 failed units, 0 new kernel errors.

Assisted-by: LLM (Claude:Opus 5.5)

…e banks

The segmentation map is state that runs from frame to frame: a frame
with temporal map prediction, or one that keeps the map without
updating it, reads the map the frame before it left. With the queued
transport (two banks, alternating) each bank had its own seg buffer, so
a frame read the map of the frame before last. Every stream with
segmentation then decoded wrong from its first non-key frame on.

Keep one seg buffer per stream and point both banks at it.

Tested on J815 (MacBook Air 15" M5), frame-by-frame MD5 against
libavcodec, full decode and a seek into the stream:
- before: libvpx aq-mode 2 (complexity) and 3 (cyclic refresh) at
  720p and 1080p, and a 360p screen-content clip, wrong from frame 1-3;
- after: all of them bit-exact, with the rest of a 67-stream H.264,
  HEVC, VP9 and AV1 set (59 of 59 PASS; the other 8 are 10-bit and
  interlaced streams the driver does not expose). The single-bank
  transport also decoded them right, which pointed at the bank swap.

Signed-off-by: Nick <nekreshen@yandex.ru>
@m0d16l14n1
m0d16l14n1 force-pushed the j815/avd-vp9-shared-seg branch from a47cddb to a22f3eb Compare November 21, 2026 13:18
@m0d16l14n1

Copy link
Copy Markdown
Contributor Author

@RyanTheTide fixed: the commit is re-made with one Signed-off-by and no co-author trailer, rebased onto e95ff7b, and the body ends with Assisted-by: LLM (Claude:Opus 5.5).

On #2136: after this PR, its CPU memset in avd_vp9_run_preamble() would clear the shared vp9_ctx->seg while the other bank's frame may still use it. Whichever of the two lands second shouldn't clear the shared map while a frame is in flight on the queued transport. Either it waits until the queue is idle, or it sets VP9_SEG_RESET on the first frame after the size change. @sithglan, if #2136 lands first, I'll rebase this onto it and do that here. Which of the two the firmware honours needs a resolution-change vector on hardware.

The regression line (0 AVC, 0 failed units, 0 new kernel errors) comes with the next J815 boot.

Assisted-by: LLM (Claude:Opus 5.5)

@RyanTheTide

Copy link
Copy Markdown
Contributor

Re-review of a22f3eb: No blockers.

From the last review:

  1. Trailers: resolved. a22f3eb has one Signed-off-by: Nick and no co-author trailer, and the PR body ends with the Assisted-by line. The code change is byte-identical to a47cddb. Only the message and the base (rebased onto e95ff7b) changed.
  2. The shared seg map against media: apple: avd: decode VP9 frames smaller than the capture format #2136's CPU memset: still open, but not in this PR. media: apple: avd: decode VP9 frames smaller than the capture format #2136 is still open (head b43dd04) and still clears vp9_ctx->b->bufs.seg at prepare time. Both authors have said that whichever lands second moves the clear onto vp9_ctx->seg and drops the CPU memset while a frame is in flight, or leaves the clear to VP9_SEG_RESET. Check that again on whichever rebase comes second.

Nothing else changed since the last review, and the fix stands as reviewed there.

HW row: the regression line from the J815 (or J813) boot on this commit: 0 AVC, 0 failed units, 0 new kernel errors, alongside the existing aq-mode 2/3 MD5 rows.

Assisted-by: LLM (Claude:Opus 5.5)

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.

3 participants