Skip to content

media: apple: avd: decode 10-bit HEVC into P030 (new V4L2 format) - #1995

Draft
IronsideXXVI wants to merge 3 commits into
aurora-silicon:mainfrom
IronsideXXVI:j604-avd-hevc10-p030
Draft

IronsideXXVI wants to merge 3 commits into
aurora-silicon:mainfrom
IronsideXXVI:j604-avd-hevc10-p030

Conversation

@IronsideXXVI

@IronsideXXVI IronsideXXVI commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

What: Let the Apple video decoder (AVD) write 10-bit HEVC packed (three 10-bit samples per 32-bit word, macOS's default), which is DRM_FORMAT_P030. A new V4L2 P030 pixel format is added for it. P030 is listed as a CAPTURE format for 10-bit 4:2:0 HEVC after P010, so clients that do not know P030 keep getting P010. There are no module parameters.

Tested: On the J604 (M4) with this head's 3 commits (9538e29) on our kernel and FFmpeg 9.1: 4K HEVC Main 10 still decodes to P010 with P030 listed, md5 equal to software on 60/60 frames, at 719 fps (4K HEVC 8-bit: 727 fps), 100.6 % and 100.7 % of our current kernel, which does not list P030 (715 / 722). The packed words match software on 60/60 frames, and no new kernel warnings. On this head, each commit builds with W=1 (v4l2-core and apple/avd) with no warnings or errors, and the AVD host tests pass 12/12.

Risk: two-way · Macs with the AVD decoder when a client picks P030. The default stays P010. The v4l2-common change gives the same result for every block size in today's table.

Not yet: A P030 decode md5 through a client that asks for P030 (the packed words above were read through our local test switch, not through the P030 format). Draft until that row is posted.

Full description

What

The Apple video decoder (AVD) can write 10-bit pictures packed: three 10-bit samples in each 32-bit word, macOS's default layout. That layout is DRM_FORMAT_P030. Until now the driver always expanded each sample to 16 bits for P010. A P030 frame is a third smaller than a P010 frame.

P030 is listed as a CAPTURE format for 10-bit 4:2:0 HEVC, after P010. Format negotiation is the gate: clients that don't know P030 skip it and keep getting P010. There are no module parameters.

Commits

  1. media: v4l2-common: allow block widths that are not a power of two: v4l2_format_plane_stride() / v4l2_format_plane_height() use roundup() instead of ALIGN() for the block size. Same result for every block size in the table today (all powers of two).
  2. media: v4l2: Add the P030 pixel format: the fourcc, format info, description and the pixfmt-yuv-planar.rst entry. The format info has a block six pixels wide in both planes, so v4l2_fill_pixfmt_mp() / v4l2_fill_pixfmt() give lines of whole 32-bit words instead of width * 4 / 3 bytes.
  3. media: apple: avd: Decode 10-bit HEVC into P030: P030 listed unconditionally for 10-bit 4:2:0 HEVC, after P010 so the default stays P010. A P030 CAPTURE buffer sets the packed flag in the picture header; lines are whole words padded to 64 bytes. The rest of the header is the same as for P010.

The two test-only commits from the first version (hevc_out_packed, hevc_out_hdr58 / hevc_out_dma) are carried in our own tree, not here. When the 16-bit configuration is understood, its values come as fixed command words with their source.

Testing

On the J604 (M4), 2026-11-24, with this head's 3 commits picked onto our kernel (our test switches are still carried there and were at their defaults, except where noted):

  • P010 with P030 listed, through FFmpeg 9.1 VA-API: md5 equal to software on 60/60 frames, rc 0, 0 stderr lines.
  • Speed, 3 x 1500 frames per clip, spread 0.1-0.3 %: 4K HEVC Main 10 719 fps, 4K HEVC 8-bit 727 fps. Our current kernel, which does not list P030, gave 715 / 722 the day before (that run used FFmpeg 9.0.2, so read this as no slowdown, not as a gain).
  • Packed words: with our hevc_out_packed test switch on, all 60 frames unpacked (bits 9:0, 19:10, 29:20) equal software on every 16th line, 46663680 of 46663680 samples. Packed decode ran at 724 fps.
  • 0 new kernel errors or warnings.

Earlier, on release 1.917 with a local test switch, packed decode ran at 699 fps against 547 fps into P010. On today's kernel P010 itself runs at 715-719 fps, so that gap is gone; what P030 still saves is the frame size.

Build checks on this head:

  • Each commit builds with W=1 (drivers/media/v4l2-core, drivers/media/platform/apple/avd): no warnings, no errors.
  • AVD host tests: 12/12 pass.
  • checkpatch: the P030 entries in v4l2-common.c and v4l2-ioctl.c keep the one-line style of the P010/P012 entries next to them, so checkpatch reports one long line and one "trailing statement".

Not run: a P030 decode through a client that asks for P030 by format. This stays a draft until that row is posted.

@RyanTheTide

Copy link
Copy Markdown
Contributor

Thanks for the P030 work. Packed 10-bit output at 699 fps against 547 is a nice gain.

We try not to put features behind boot options. The new P030 CAPTURE format is offered only when the module parameter hevc_p030 is set (drivers/media/platform/apple/avd/avd-v4l2.c:73-81, default off). The three "test only" parameters, hevc_out_packed, hevc_out_hdr58 and hevc_out_dma (drivers/media/platform/apple/avd/avd-hevc.c:28-49), are writable at run time and change the command stream sent to the decoder.

Applications already choose their capture format through V4L2 format negotiation. Could P030 simply be listed for 10-bit HEVC once you are happy with it, and could the test-only parameters be dropped or moved into a debug-only build option? If some AVD revision can't produce P030, a match-data flag with a comment naming the hardware reason would be the place for that.

We can run 10-bit HEVC decode rows on our A18 Pro, M4 Pro, M2 and M1 Pro.

@IronsideXXVI
IronsideXXVI marked this pull request as draft November 20, 2026 17:30
@IronsideXXVI

Copy link
Copy Markdown
Contributor Author

@RyanTheTide thanks. I agree: format negotiation is the right gate, and the test-only words should not be here.

I'm moving this back to draft, because our own kernel does not offer P030 by default yet. On the J604, P030 decodes bit-exact (md5 60/60 against software). Offering it changes nothing for P010 clients (P010 md5 60/60, 548 vs 548 fps with the offer on). But no userspace client reads P030 today (FFmpeg's V4L2 request path and libva), so we ship it off.

When it comes back, it will be in the form you asked for: P030 listed for 10-bit HEVC through format negotiation, no module parameter, and none of the three test words. If an AVD revision needs it, there will be a match-data flag with the hardware reason. It will also come with fresh J604 numbers on the kernel it was measured on. Your rows on A18 Pro, M4 Pro, M2 and M1 Pro would be welcome then.

@RyanTheTide

Copy link
Copy Markdown
Contributor

The P030 format this PR adds is hidden behind hevc_p030 in avd-v4l2.c, which defaults to off. A default boot never offers it, even though clients that don't know P030 already skip it. Enumerate it unconditionally. hevc_out_packed, hevc_out_hdr58 and hevc_out_dma in avd-hevc.c are marked test only. They let root write unusable pictures or arbitrary header and DMA bits, so they should be removed, and the values hard-coded once they are understood. Until then this should stay a draft.

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

Review of the draft. I agree with Ryan's two points: enumerate P030 unconditionally for 10-bit HEVC, since format negotiation already gates it, and drop the three test-only parameters. Your questions:

  • A new uapi format with no client yet. In our tree that's fine once it's enumerated by default: the format is well defined (the same layout as DRM_FORMAT_P030), the driver produces it bit-exact, and clients that don't know it skip it. An upstream submission would want the client side, or at least a v4l2-compliance run with the format selected, but that doesn't need to hold it here.
  • Commits 1 and 4. Carry them locally. When the 16-bit configuration is understood, the values go in as fixed command words with their source, not as parameters.

One check for the next version: the v4l2_format_info entry gives the chroma plane bpp {8}/bpp_div {3} with hdiv 2. avd_fill_decoded_pixfmt() overrides bytesperline for the AVD, but any other user of v4l2_fill_pixfmt_mp() gets width * 4 / 3 without whole words. Rounding to whole 32-bit words there (or saying in the docs that drivers must) would keep the generic helper honest.

@IronsideXXVI

Copy link
Copy Markdown
Contributor Author

Thanks. The next version enumerates P030 unconditionally for 10-bit HEVC, drops the three test-only parameters, keeps commits 1 and 4 local, and rounds the chroma bytesperline to whole 32-bit words in the format info (or documents that drivers must).

v4l2_format_plane_stride() and v4l2_format_plane_height() round the
width and height up to the format's block size with ALIGN(), which is
only right for powers of two. A format that packs three samples into
each 32-bit word, such as P030, needs a block a multiple of three
pixels wide to give its lines in whole words.

Use roundup() instead. It gives the same result for every block size
in the table today, all of them powers of two, and the right one for
the others.

Signed-off-by: Dylan Ironside <[email protected]>
P030 is a semi-planar 10-bit YUV 4:2:0 format with three components and
two bits of padding in each little endian 32-bit word, the layout of
DRM_FORMAT_P030. The Apple video decoder writes 10-bit pictures in this
layout natively, at a third less memory traffic than P010.

Its format info has a block six pixels wide in both planes, so that
v4l2_fill_pixfmt_mp() and v4l2_fill_pixfmt() give lines of whole 32-bit
words: six pixels are two words of luma and two words of CbCr. Without
it the helpers would give width * 4 / 3 bytes, which is not a whole
number of words for most widths.

Signed-off-by: Dylan Ironside <[email protected]>
The decoder has a packed output mode for 10-bit pictures: three 10-bit
samples in each 32-bit word, macOS's default 'p420' layout. On the J604
it decodes 4K HEVC Main 10 at 699 fps in that mode against 547 fps
when it expands each sample to 16 bits for P010. The layout is
DRM_FORMAT_P030.

List P030 as a CAPTURE format for 10-bit 4:2:0 HEVC, after P010 so the
default stays P010. Format negotiation is the gate: clients that do not
know P030 skip it and keep getting P010. A P030 CAPTURE buffer sets the
packed mode in the picture header, and its lines are whole 32-bit words
padded to 64 bytes. The rest of the picture header is the same as for
P010.

Signed-off-by: Dylan Ironside <[email protected]>
@IronsideXXVI

Copy link
Copy Markdown
Contributor Author

Force-pushed 24c1ed9, rebased onto current integration/aurora:

  • P030 is listed unconditionally for 10-bit 4:2:0 HEVC, after P010. hevc_p030 is gone, and the packed flag comes only from the CAPTURE format being P030.
  • hevc_out_packed, hevc_out_hdr58 and hevc_out_dma are out of the series (old commits 1 and 4). We carry them in our own tree.
  • v4l2_format_info for P030 now has a block six pixels wide in both planes, so v4l2_fill_pixfmt_mp() gives whole 32-bit words for any driver. That needed roundup() instead of ALIGN() for block sizes in the helpers (new first commit; same result for every existing format).

I've updated the description to match. It stays a draft until I post J604 rows on this head: P030 decode md5 against software, and P010 md5 and fps with P030 listed.

@IronsideXXVI IronsideXXVI changed the title media: apple: avd: 10-bit HEVC into P030 on request (new V4L2 format) media: apple: avd: decode 10-bit HEVC into P030 (new V4L2 format) Nov 21, 2026
@RyanTheTide

Copy link
Copy Markdown
Contributor

Thanks, both of our points are resolved in 24c1ed9: P030 is listed unconditionally for 10-bit 4:2:0 HEVC, and the three test-only parameters are out of the series. Rounding the P030 block to six pixels so v4l2_fill_pixfmt_mp() gives whole words is a nice touch. We'll look again when the J604 md5 and fps rows are in and it leaves draft.

@IronsideXXVI

Copy link
Copy Markdown
Contributor Author

Thanks. The J604 P030 md5 and fps rows are next on the machine, on a kernel that carries this branch; I'll post them here when they have run.

@RyanTheTide

Copy link
Copy Markdown
Contributor

integration/aurora 110861f has no P030 format and the AVD still expands 10-bit HEVC to P010 only, so this is still needed. The three commits apply cleanly to 110861f. Both review points are resolved in this head: P030 is listed unconditionally after P010, and the test-only parameters are gone. What is still missing is the J604 rows on this head that the draft is waiting for: a P030 decode md5 against software, and the P010 md5 and fps with P030 listed.

Build check of 110861f plus this change (arm64, LLVM=1, Image, dtbs and every directory it touches, Fedora config plus asahi.config): builds, no warnings in the files it touches.

@RyanTheTide

Copy link
Copy Markdown
Contributor

@IronsideXXVI checking open drafts today. To come out of draft, this still needs:

  • A test run at the current head on a Mac with the hardware it touches, then mark it ready for review.

If it's no longer needed, say so here and we'll close it. Otherwise it stays open as a draft until these are done.

This branch has not been deployed

No deployments
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