Repository navigation
media: apple: avd: decode 10-bit HEVC into P030 (new V4L2 format) - #1995
IronsideXXVI wants to merge 3 commits into
Conversation
|
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 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. |
|
@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. |
|
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
left a comment
There was a problem hiding this comment.
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.
|
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 |
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]>
33f929a to
24c1ed9
Compare
|
Force-pushed 24c1ed9, rebased onto current integration/aurora:
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. |
|
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 |
|
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. |
24c1ed9 to
9538e29
Compare
|
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. |
|
@IronsideXXVI checking open drafts today. To come out of draft, this still needs:
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. |
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
media: v4l2-common: allow block widths that are not a power of two:v4l2_format_plane_stride()/v4l2_format_plane_height()useroundup()instead ofALIGN()for the block size. Same result for every block size in the table today (all powers of two).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, sov4l2_fill_pixfmt_mp()/v4l2_fill_pixfmt()give lines of whole 32-bit words instead ofwidth * 4 / 3bytes.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):
hevc_out_packedtest 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.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:
Not run: a P030 decode through a client that asks for P030 by format. This stays a draft until that row is posted.