Skip to content

media: apple: avd: match the macOS H.264/HEVC slice and scaling commands - #1116

Merged
RyanTheTide merged 4 commits into
integration/aurorafrom
avx/avd-macos-command-parity
Nov 7, 2026
Merged

RyanTheTide merged 4 commits into
integration/aurorafrom
avx/avd-macos-command-parity

Conversation

@RyanTheTide

@RyanTheTide RyanTheTide commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

Three fixes that make the AVD slice and picture commands match what macOS programs for the same streams. All three are bit-exact by construction and were checked bit-exact on hardware on the Neo, M2 and M4 Pro. They are correctness/parity changes at zero cost: the same-boot A/B on the M4 Pro (J616s), where H.264 decode is slowest relative to macOS (74%), shows no throughput change, so the remaining H.264 gap lies elsewhere.

What changes

  1. H.264: skip flat scaling lists. FFmpeg's request backend and the VA-API driver always attach a scaling matrix, so V4L2_H264_PPS_FLAG_SCALING_MATRIX_PRESENT is set for every picture even when the stream carries no lists. The driver then loaded 24 4x4 and 32 8x8 list words per picture. When every list the picture uses is 16, that is Flat_4x4_16/Flat_8x8_16 (H.264 7.4.2.1.1), which the decoder applies with no list loaded. macOS leaves the list section empty for these streams. A KUnit case covers the check.
  2. H.264: temporal-direct bit only for B slices. direct_spatial_mv_pred_flag exists only in B slice headers, so the cleared V4L2 flag made the driver set the temporal-direct bit of the slice reference command on every I and P slice. macOS sets it only for B slices that use temporal direct. B-slice words were already identical.
  3. HEVC: mvd_l1_zero bit only for B slices. Same pattern: the bit was set for every P slice from the absent flag. macOS clears it for P slices.

How the differences were found

Our own traces on our hardware, no Apple code or bytes involved: the frame-parameter images macOS 27.0 builds for each picture (J616s, VideoToolbox decoding the public testsrc2 sample) next to the words this driver emits for the same clip (DEBUG_INST build). Every picture-header field already matched (dimensions, SPS/PPS words, chroma QP offsets, feature word); the three items above were the only differences in the first pictures of each type (I/P/B) for H.264 and HEVC.

Validation

  • Same-boot A/B on fleet22 (7.3.0-aurora-fleet22, integration e5a1f1d + these commits as a signed module; order stock -> test -> stock; avd-bench queue 16, 1 stream, 3 passes; every displayed frame MD5-checked against software decode before and after timing): bit-exact on every clip.
    • Neo (J700): H.264 1080p/4K testsrc2, x264 cqm=jvt (non-flat lists, still loaded), Main without 8x8, direct=temporal B-frames, a high-detail clip with weighted P; HEVC 1080p/4K, all-P x265, Main10 B-pyramid.
    • M2 (J413): H.264 1080p, temporal direct, high-detail clip.
  • fps on the Neo and M2 is unchanged within run-to-run noise (Neo: H.264 1080p 740.3/736.9/740.4 stock vs 741.4/739.7/741.8 test; M2: 1678.6/1705.2/1722.6 vs 1721.7/1697.8/1721.9). Expected: the Neo decoder is pixel-rate bound and the M2 is clock-capped (linux#1064), so neither is limited by per-picture command work.
  • J616s (M4 Pro) A/B, fleet22, same boot, stock -> test -> stock, 3 passes each, all bit-exact:
clip stock test stock again
H.264 1080p 1897.8 / 1869.7 / 1870.0 1897.1 / 1867.1 / 1896.4 1896.9 / 1868.1 / 1896.6
H.264 4K 480.4 / 478.8 / 479.8 477.9 / 479.1 / 479.9 480.8 / 479.1 / 479.7
HEVC 1080p 2598.6 / 2606.5 / 2608.7 2594.7 / 2562.4 / 2600.7 2594.6 / 2579.5 / 2598.4
HEVC 4K 697.4 / 689.7 / 698.9 695.5 / 689.6 / 698.7 695.2 / 689.5 / 689.8
H.264 high-detail, weighted P 1482.1 / 1502.7 / 1451.7 1483.8 / 1504.1 / 1458.5 1481.2 / 1483.6 / 1494.7
HEVC all-P 2315.9 / 2315.2 / 2305.7 2348.3 / 2318.3 / 2306.4 2311.7 / 2310.8 / 2301.8

Equal within run-to-run noise on every row.

  • checkpatch.pl --strict: clean on all three commits. KUnit (arm64 QEMU) apple-avd-h264: 23/23, including the new avd_scaling_flat_test.

Benchmark method

Same boot, stock module -> test module -> stock module (signed module swap, no reboot), avd-bench queue 16, 1 stream, 3 passes each, every displayed frame MD5-checked against software decode; testsrc2 samples (12 Mb/s, GOP 30) plus x264/x265 clips of a high-detail source. Raw per-pass fps above.

🤖 Generated with Claude Code

FFmpeg and the VA-API driver always attach a scaling matrix to H.264
requests, so V4L2_H264_PPS_FLAG_SCALING_MATRIX_PRESENT is set for
every picture even when the stream carries no lists. The driver then
loads 24 4x4 and 32 8x8 list words into the decoder for every picture.

When every list the picture uses is 16, the matrix is Flat_4x4_16 /
Flat_8x8_16 (H.264 7.4.2.1.1), which is what the decoder applies with
no list loaded. Leave the list section empty in that case, as macOS
does for the same streams. Streams with real lists are unchanged.

Add a KUnit case for the flat check.

Signed-off-by: Ryan Murray <[email protected]>
Assisted-by: LLM
direct_spatial_mv_pred_flag exists only in B slice headers, so the
V4L2 flag is clear for every I and P slice and the driver set the
temporal-direct bit in the slice reference command for all of them.
macOS leaves the bit clear for I and P slices and sets it only for B
slices that use temporal direct prediction. Do the same.

Signed-off-by: Ryan Murray <[email protected]>
Assisted-by: LLM
mvd_l1_zero_flag exists only in B slice headers. The driver derived
the slice reference command bit from the cleared V4L2 flag and so set
it for every P slice. macOS leaves the bit clear for P slices and
only reflects the flag for B slices. Do the same.

Signed-off-by: Ryan Murray <[email protected]>
Assisted-by: LLM
@RyanTheTide
RyanTheTide marked this pull request as ready for review November 7, 2026 17:13
The H.264 program host test extracts avd-h264.c into a host build. It
needs a no-op EXPORT_SYMBOL_IF_KUNIT now that the flat scaling check is
exported for KUnit.

The conformance check compares every generated program against the
757fc07 baseline. The baseline set the temporal-direct bit of the
slice reference header word for I and P slices too; clear that bit in
the baseline I/P programs before comparing, so the test still checks
every other word for equality.

Signed-off-by: Ryan Murray <[email protected]>
Assisted-by: LLM
@RyanTheTide
RyanTheTide merged commit bc4d399 into integration/aurora Nov 7, 2026
1 check passed
@RyanTheTide
RyanTheTide deleted the avx/avd-macos-command-parity branch November 7, 2026 17:41
RyanTheTide added a commit that referenced this pull request Nov 7, 2026
Brings aurora-wip up to the 11-08 morning integration tip: DT
descriptions for every Mac family (#1094, #1097, #1111, #1131, #1132,
#1148, #1149, #1155, #1156, #1157, #1172), the J616s scaler (#1168), the
panel primaries from boot data (#1105), AVD macOS command parity
(#1116), AVD dma-coherent (#1169), the M2 PMU RTC alarm (#1151), G17
admission without spinning (#1146) and the AOP map wait (#1147).

Signed-off-by: Ryan Murray <[email protected]>
Assisted-by: LLM
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.

1 participant