Skip to content

media: apple: avd: keep the full PP count of frames with 256 tiles or more - #3226

Merged
RyanTheTide merged 1 commit into
mainfrom
fix/avd-av1-full-pp-count
Nov 28, 2026
Merged

RyanTheTide merged 1 commit into
mainfrom
fix/avd-av1-full-pp-count

Conversation

@DjDeveloperr

@DjDeveloperr DjDeveloperr commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

What: An AV1 frame takes one PP kick per tile, but the driver kept the count in a u8. Frames of 256 to 512 tiles, which the stateless API allows, were kicked 256 times too few or not at all past the first kick. Such a frame ends early or waits for the watchdog, whose reset fails the frames of every stream on the decoder. The count is now a u32 on both submission paths.

Tested: the module builds W=1-clean (clang, arm64). The new host test avd-pp-count-tests.py runs the production set_tiles(), PP kick hook and legacy submit hook for 1, 255, 256, 272 and 512 tiles, and fails at the previous revision (registered as the negative control). run-host-tests.py --only avd: 14/14, and tests/av1-test.py passes. J700 (Neo) at bc4f27ccba11, in the combined candidate 7.3.0-neo-combined1126, which carries it unchanged: AV1 decode 3/3 streams, 180/180 frames, CRCs equal base. 0 DART faults.

Risk: two-way · all Macs with AVD AV1 or VP9 decode. Frames below 256 tiles program exactly as before.

Not yet: AV1 decode CRCs against base on the M5 Pro.

Details
  • struct avd_av1_ctx::submit_num and the VP9 bank's submit_num are now u32. max_t() in the PP kick hooks takes u32. The legacy continuation loops run from 1 to the count, so a widened count can't underflow count - 1.
  • Queued firmware:
    • A 256-tile frame now asks for 255 continuations, which is AVDQ_MAX_PP_EXTRA.
    • A frame with more tiles than that is refused by the existing -E2BIG check in avd_qfw_submit() before its descriptor is written. Before, it was sent with a wrapped count.
  • The legacy path kicks every tile.
  • VP9 has the same counter, but at the decoder's 4096-pixel width limit it has at most 64 tiles. The change there only matches the type.
  • tests/vp9-test.py doesn't build on main either (it refers to seg and seg_clear members avd-vp9.c no longer has); not touched here.
Evidence
  • python3 tools/asahi/avd-pp-count-tests.py: 1, 255, 256, 272 and 512 tiles (16x16, 16x17, 32x16, 64x8) get one segment, one PP kick and one legacy EXEC per tile.
  • python3 tools/asahi/avd-pp-count-tests.py --ref 255761f1d55f8dcf3e2c24d17095439237ad6f72: 256 tiles get 1 kick, 272 get 16, 512 get 1.
  • make M=drivers/media/platform/apple/avd LLVM=1 W=1 modules against a configured 7.3 tree: no warnings in the changed files.

… more

An AV1 frame takes one PP kick per tile, and set_tiles() stored their
number, tile_cols * tile_rows, in a u8. The stateless API allows up to
V4L2_AV1_MAX_TILE_COUNT (512) tiles, so a frame of 256 or 512 tiles
recorded 0 kicks and one of 257 to 511 tiles 256 too few. Both
submission paths then kicked too few PP continuations for the segments
set_tiles() had built: the legacy submit loop wrote that many EXECs,
and the queued firmware's metadata asked for that many continuations.
Such a frame either ends early or waits for the watchdog, whose reset
fails the frames of every stream on the decoder.

Keep the count in a u32 and run the legacy continuation loop from 1
without the unsigned "count - 1". A 256-tile frame now gets all 256
kicks, on the legacy path and as 255 continuations for the queued
firmware. A frame with more tiles than the queued firmware takes is
now refused at submission by its existing AVDQ_MAX_PP_EXTRA check,
instead of being sent with a wrapped count. VP9 keeps the same counter
and gets the same change; its tiles stay far below 256 at the
decoder's 4096-pixel width limit.

Add a host test that runs the production set_tiles(), the PP kick hook
and the legacy submit hook for 1, 255, 256, 272 and 512 tiles, with the
previous revision registered as the negative control: it kicks 256 and
512 tiles once and 272 tiles 16 times.

Signed-off-by: DjDeveloperr <[email protected]>
@DjDeveloperr
DjDeveloperr requested review from a team as code owners November 26, 2026 09:53
@DjDeveloperr

Copy link
Copy Markdown
Contributor Author

Verdict at bc4f27ccba11: ready

Blockers: none

Checked:

  • No narrowing is left on the path.
    • set_tiles() stores tile_cols * tile_rows, both unsigned int in struct avd_av1_run, in the new u32 submit_num. VP9 counts its tiles into a u32 too.
    • pp_kicks() returns unsigned int from max_t(u32, …, 1), so it is never 0. The prepare step stores pp_kicks() - 1 in f->cmd[1], a u32, which avd_qfw_submit() reads back as u32 extra and writes as a full word to D_PP_EXTRA.
    • The segment table is size_t job->num against tile_cols * tile_rows + 1 entries, and avd_open_build_program() sums its words with check_add_overflow().
    • HEVC's counter is already an int.
  • The cap check comes before any write. if (extra > AVDQ_MAX_PP_EXTRA) return -E2BIG; runs before avd_qfw_pick_vp(), configure_stream(), every descriptor writel() and the doorbell. Up to then it has only read the mailbox status. avd_slot_submit_result() turns -E2BIG into a finished frame with that status, unlike -EBUSY, which is retried, so a refused frame fails on its own instead of hanging. 256 tiles gives extra == 255 and passes; 257 to 512 are refused.
  • The legacy loops are bounded. for (u32 i = 1; i < submit_num; i++) writes submit_num - 1 continuation EXECs after the start kick. That is none for 0 or 1, matching max(submit_num, 1) kicks in total, with no unsigned submit_num - 1 to underflow. AV1 and VP9 have the same shape.
  • Merged-code rules: no runtime switch, no new constant, no SoC or board gate.
Evidence
  • Build at bc4f27ccba11 with the asahi profile (LLVM) and W=1: drivers/media/platform/apple/avd/, 14 objects rebuilt, 0 warnings.
  • tools/asahi/avd-pp-count-tests.py: ok. 1, 255, 256, 272 and 512 tiles (16x16, 16x17, 32x16, 64x8) each get one segment, one PP kick and one legacy EXEC per tile.
  • With --ref 255761f1d55f, it fails: 512 tiles get 1 kick and 1 EXEC, and kicks == n and the cap predicate fail.
  • run-host-tests.py --only avd: 14/14, including both avd-pp-count-tests runs. tests/av1-test.py: PASS.
  • KUnit drivers/media/platform/apple/avd/tests/.kunitconfig at this head (arm64 QEMU, run locally because CI was still queued): 178/178. I had to turn CONFIG_WERROR off: this host's clang 23 flags -Wuninitialized-const-pointer in avd-pm-test.c, which this PR does not touch and CI's clang 18 does not warn about.
  • The AV1 decode CRC rows on the Neo and the M5 Pro are still listed under "Not yet".

@github-actions github-actions Bot added area:gpu Area from CODEOWNERS (bot) area:media Area from CODEOWNERS (bot) blast:all Macs affected, from Merge risk (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) labels Nov 26, 2026
@github-actions

github-actions Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Merge readiness at bc4f27cc: not ready yet

Check Detail
CI at head no failing: 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 bc4f27cc
Conflicts ok none
PR text ok Risk: two-way · all Macs with AVD AV1 or VP9 decode. Frames below 256 tiles program exactly as before.

Areas: area:gpu, area:media

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

@DjDeveloperr

Copy link
Copy Markdown
Contributor Author

J714s (MacBook Pro 14" M5 Pro, T6050) row at bc4f27ccba11: no regression. The 256-tile path isn't exercised by the available stream.

@aurora-silicon-review aurora-silicon-review Bot 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.

Verdict: MERGE at bc4f27cc (once cancelled CI checks are rerun green)

Blockers: none (code, host tests, and two-generation hardware rows are ready; rerun the 18 cancelled CI checks before merge).

Checked:

  • drivers/media/platform/apple/avd/avd-av1.c and avd-vp9.c: verified submit_num is widened from u8 to u32 for both AV1 and VP9, pp_kicks() uses max_t(u32, ..., 1), and legacy submit loops use for (u32 i = 1; i < ...->submit_num; i++) (avoiding both 8-bit wrap at 256..512 tiles and unsigned underflow if 0).
  • tools/asahi/avd-pp-count-tests.py and run-host-tests.py: verified production set_tiles(), avd_av1_pp_kicks(), and avd_av1_submit() across 1, 255, 256, 272, and 512 tiles with negative control against the previous revision.
  • Verified exact-head (bc4f27ccba11) hardware rows on J700 (Neo, 3/3 AV1 streams, 180/180 frames, CRCs match base, 0 DART faults) and J714s (M5 Pro, no regression).
Evidence
  • Diff reviewed at bc4f27cc (all 4 files, 257 lines).
  • CI at review time: 3 passed, 0 failed, 18 cancelled.

@RyanTheTide

Copy link
Copy Markdown
Contributor

Merge-train status at bc4f27cc (App approval noted; rows: 18 cancelled; J700 + J714s exact-head PASS). @DjDeveloperr code-owner ping (6-point rule, point 6): merge earliest 17:15 AEDT once full CI is green (I re-ran cancelled jobs) and the second-family row point holds. Revert: git revert -m 1 <merge>.

@RyanTheTide

Copy link
Copy Markdown
Contributor

Merging under the 6-point rule (Ryan 09:29, permanent), at bc4f27cc. (1) The review App approved at this head. (2) Full CI is green. (3/4) Rows: J700+J714s. (5) There's no blocking review. (6) Dj was pinged here 551 min ago with no objection. Revert: git revert -m 1 <merge>.

@RyanTheTide
RyanTheTide merged commit eebbde8 into main Nov 28, 2026
25 of 107 checks passed
@RyanTheTide
RyanTheTide deleted the fix/avd-av1-full-pp-count branch November 28, 2026 14:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:gpu Area from CODEOWNERS (bot) area:media Area from CODEOWNERS (bot) blast:all Macs affected, from Merge risk (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.

2 participants