Skip to content

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

Merged
RyanTheTide merged 1 commit into
aurora-silicon:mainfrom
m0d16l14n1:j815/avd-vp9-shared-seg
Nov 26, 2026
Merged

RyanTheTide merged 1 commit into
aurora-silicon:mainfrom
m0d16l14n1:j815/avd-vp9-shared-seg

Conversation

@m0d16l14n1

@m0d16l14n1 m0d16l14n1 commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

What: AVD VP9 keeps one segmentation map per stream, shared by both banks of the queued transport, instead of one per bank. Before, every stream with segmentation decoded wrong from its first non-key frame. Rebased onto main with #2136: a frame-size change now switches to a second, cleared map, so the frame still in flight in the other bank keeps reading the old one.
Tested: J815 (MacBook Air 15" M5) at 7f024572717a: VP9 test vectors A/B with the same userspace, main's module vs this head: 0 PASS→FAIL, +2 FAIL→PASS, +4 fallback→PASS (177 PASS vs 171). codec-lab decode 21/21. Earlier head: libvpx aq-mode 2/3 and screen content bit-exact; 67-stream set 59/59. Regression at boot: 0 SELinux denials (SELinux off), 0 failed units, 0 new kernel errors.
Risk: two-way door. VP9 decode on every AVD generation.
Not yet: the VP9 suite at this head on a non-M5 Mac (offered by the reviewers on J773g/J700).

Details

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 previous frame left. With the queued transport the two banks alternate. Each bank had its own seg buffer, so a frame read the map of the frame before last.

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

Changed on this head (with #2136, merged): #2136 cleared the bank's seg buffer from the CPU on a frame-size change. With one shared map, that clear could hit a map the other bank's frame is still reading. The stream now has two seg buffers: a size change moves to the other buffer and clears it, and at most one frame is in flight besides the one being set up. The map reset still goes to every frame that uses segmentation until one updates the map.

Evidence

J815, macOS 27.2 stub, this head merged with the other J815 PRs into one test kernel on main 2943fff. The A/B swaps only apple-avd.ko (main's avd-vp9.c built in the same tree) under the same userspace.

PASS FAIL fallback
main 171 39 91
this head 177 63 60

Per vector: 0 PASS→FAIL, 2 FAIL→PASS, 4 fallback→PASS. 26 vectors went from fallback (no frames from main) to FAIL: 24 of them are vp90-2-21 resize vectors and 2 are vp90-2-20. The resize vectors (vp90-2-14, vp90-2-21) fail on both: libva-v4l2request drops its references across an inter-frame resize ("unavailable reference in this decoder context"). That's a userspace item, not this PR.

@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)

@m0d16l14n1

m0d16l14n1 commented Nov 21, 2026 •

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.

@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)

@RyanTheTide

Copy link
Copy Markdown
Contributor

The shared VP9 segmentation map is still needed. Head a22f3eb737f6 replays cleanly onto integration/aurora 5441428d9033, and avd-vp9.o builds for arm64. This supplies the compile row. The J815 decode regression row remains open.

@DjDeveloperr DjDeveloperr left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Formal §1–§6 pre-PR checklist review at verified live head a22f3eb737f6ca92834f45334b00c30e47894150 (not superseded on integration/aurora; live CI 1/1 green: host-tests).

Technical Audit

  • drivers/media/platform/apple/avd/avd-vp9.c (+13/-8): Clean and correct. Moving struct avd_buf seg from struct avd_vp9_bank to struct avd_vp9_ctx, allocating it once in avd_vp9_start() with the existing DIV_ROUND_UP(fmt_width(ctx), 8) * 24 size, pointing both set_header() "seg" slots at vp9_ctx->seg.addr, and freeing it in avd_vp9_free() (including the err_free_ctx OOM path) fixes the queued-transport bank-alternation bug cleanly.
  • Live base & test interaction: Verified against current integration/aurora (70a00e583b03): drivers/media/platform/apple/avd/tests/vp9-test.py (fail_alloc_after = 13) still hits -ENOMEM cleanly on bank 1's first allocation (1 shared + 11 bank 0 + 1 bank 1 = 13) and cleans up properly; avd-vp9-test.c is unaffected. #2136 remains open, so there is no live conflict on integration/aurora (whichever lands second will coordinate on VP9_SEG_RESET/idle clear as noted).

Checklist Summary

  • §1 No model gating: PASS — applies uniformly across all AVD VP9 streams using the queued transport (single-bank unchanged).
  • §2 Production-ready, no hacks: PASS — default kernel cmdline, clean minimal fix.
  • §3 Safety: PASS — allocation/free symmetry and error unwind are sound.
  • §4 Clean-room & attribution: PASS — single commit a22f3eb737f6 carries human author/committer (Nick <[email protected]>) and human Signed-off-by: only (zero AI commit trailers); PR body ends with a plain Assisted-by: line.
  • §5 Evidence: Blocker (owed regression line) — see below.
  • §6 Naming: PASS.

Blocker

  1. §5 Owed regression triad: Functional decode evidence is strong and independently replicated on both J815 (67-stream suite 59/59 PASS, aq-mode 2/3 bit-exact, seek, 3 concurrent decodes) and J813 (aq-mode 2/3 bit-exact including 4/4 deep sleeps). However, the §5 regression run (kernel/build identifier plus 0 SELinux denials [or N/A if Arch], 0 failed units, and 0 new kernel errors) has not yet been posted from either boot and remains open from earlier review/triage.

Verdict

REQUEST_CHANGES — 0 code/§1–§4/§6 blockers; ready to approve as soon as the owed §5 regression triad from the J815 or J813 boot is posted.

@github-actions github-actions Bot added area:media Area from CODEOWNERS (bot) changes-requested A reviewer requested changes (bot) needs-review No approving review from Core or Omarchy Mac yet (bot) needs-template PR body lacks Tested or Risk (bot) merge-conflict Conflicts with the base branch (bot) labels Nov 24, 2026
DjDeveloperr
DjDeveloperr previously approved these changes Nov 24, 2026

@DjDeveloperr DjDeveloperr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Verdict: FINISH, then merge at a22f3eb737f6: the code is ready; it needs a branch update and one more row.

Blockers: none in the code. The branch now conflicts with main; update it. Missing row: avd-vp9.c runs on every AVD generation, and both rows are on M5, so before it merges it also needs the VP9 suite at the updated head on one non-M5 Mac (for example an M4 or the Neo), bit-exact. We'll run it on our J773g or J700.

Checked: thank you, this is well tested. No Apple material, no gates: one segmentation map per stream, shared by the banks. J815: the 67-stream suite passes 59/59, with aq-mode 2/3 bit-exact, seek and 3 concurrent decodes; J813 bit-exact as well.

@DjDeveloperr
DjDeveloperr dismissed their stale review November 24, 2026 21:01

Superseded by the review at a22f3eb

@github-actions github-actions Bot removed changes-requested A reviewer requested changes (bot) needs-review No approving review from Core or Omarchy Mac yet (bot) labels Nov 24, 2026
@github-actions

github-actions Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Merge readiness at 7f024572: not ready yet

Check Detail
CI at head no failing: host-tests, pr-text / pr-text
Review no needs one approving review from Core or Omarchy Mac (not the author)
Requested changes ok none
Hardware row at head ok in the PR body at 7f024572
Conflicts ok none
PR text ok Risk: two-way · . VP9 decode on every AVD generation.

Areas: area:media

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

@RyanTheTide

Copy link
Copy Markdown
Contributor

The approved a22f3eb737f6 now conflicts with main. Please merge current main into the existing branch and push the forward update without rewriting the PR branch.

The VP9 resize fix has landed. Please carry through your agreed update for the shared segmentation map so resizing one bank cannot clear data the other bank is using. The prior J815 and J813 results are recorded. Dj’s review names a bit-exact non-M5 regression on J773g or J700 at the updated head.

…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. A frame size
change (the map is cleared then) moves to a second, cleared buffer instead
of clearing the one the frame still in flight in the other bank reads.

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 <[email protected]>
@m0d16l14n1
m0d16l14n1 force-pushed the j815/avd-vp9-shared-seg branch from a22f3eb to 7f02457 Compare November 25, 2026 03:45
@m0d16l14n1
m0d16l14n1 requested a review from a team as a code owner November 25, 2026 03:45
@m0d16l14n1
m0d16l14n1 requested a review from Acelogic November 25, 2026 03:45
@github-actions github-actions Bot added ci-failing A check failed at the PR head (bot) needs-hw-row No hardware row at the PR head (bot) needs-review No approving review from Core or Omarchy Mac yet (bot) labels Nov 25, 2026
@github-actions github-actions Bot added door:two-way Revertible or not, from Merge risk (bot) and removed merge-conflict Conflicts with the base branch (bot) needs-hw-row No hardware row at the PR head (bot) needs-template PR body lacks Tested or Risk (bot) labels Nov 25, 2026
@m0d16l14n1

Copy link
Copy Markdown
Contributor Author

@DjDeveloperr updated to 7f024572717a: rebased onto main, which now has #2136. With one shared map, #2136's CPU clear on a size change could hit the map the other bank's frame still reads. So the stream keeps two seg buffers: a size change moves to the other one and clears it.

J815 at this head, VP9 test vectors A/B against main's module on the same userspace: 0 PASS→FAIL, 2 FAIL→PASS, 4 fallback→PASS (177 vs 171 PASS). Details in the body; the resize vectors fail on both because of libva-v4l2request. codec-lab decode 21/21.

Thanks for offering the non-M5 run (J773g/J700) at this head.

@RyanTheTide

Copy link
Copy Markdown
Contributor

Verdict: FINISH, then merge at 7f024572717a

Blockers: none in the code. Dj's review found none at the earlier head. The only change since then is the forward update: a size change now moves to the stream's second, cleared seg buffer, so the frame still in flight in the other bank keeps its map. That closes the #2136 interaction.

Still needed: the bit-exact VP9 suite at this head on one non-M5 Mac. I've queued it in our lab on J616s (M4 Pro, T6040 AVD), with the same A/B against main's module. If Dj's J773g/J700 run lands first, that one counts instead. Thanks for the A/B numbers: 0 PASS→FAIL, 177 vs 171 PASS.

@RyanTheTide

Copy link
Copy Markdown
Contributor

7f02457 J616s (M4 Pro, T6040, non-M5 AVD open-queue transport) PASS: batched on main 7f00dc6 (0 merge-tree diffs), default cmdline; 27-clip VP9 bit-exact A/B vs stock fleet89 (main apple-avd) on identical userspace: VA-API 0 PASS->FAIL, +13 FAIL->PASS (20/20 supported clips bit-exact vs 7/20 on stock; all 13 segmented aq-mode 1/2/3 + screen + cyclic streams fixed; 7 unchanged libva resize/Profile-1 fallbacks); GStreamer v4l2slvp9dec 0 PASS->FAIL, +5 FAIL->PASS (10 vs 5); 0 AVD/DART errors, 0 failed units, Enforcing, 0 AVC, 0 new kernel errors; stock fleet89 restored.

@RyanTheTide RyanTheTide left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Verdict: MERGE at 7f024572717a. The non-M5 row is in. On J616s, 20/20 supported VP9 vectors are bit-exact, with +13 FAIL→PASS and 0 PASS→FAIL against main's module. There are no code blockers (Dj's review and mine).

@RyanTheTide
RyanTheTide merged commit f6a3988 into aurora-silicon:main Nov 26, 2026
8 of 10 checks passed
@RyanTheTide

Copy link
Copy Markdown
Contributor

Merged into main. Thank you! It merged on the hardware rows at this head and a non-author review.

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) ci-failing A check failed at the PR head (bot) door:two-way Revertible or not, from Merge risk (bot) needs-review No approving review from Core or Omarchy Mac yet (bot)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants