Repository navigation
media: apple: avd: match the macOS H.264/HEVC slice and scaling commands - #1116
Merged
Merged
Conversation
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
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
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
This was referenced Nov 14, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
V4L2_H264_PPS_FLAG_SCALING_MATRIX_PRESENTis 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.direct_spatial_mv_pred_flagexists 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.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_INSTbuild). 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
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.cqm=jvt(non-flat lists, still loaded), Main without 8x8,direct=temporalB-frames, a high-detail clip with weighted P; HEVC 1080p/4K, all-P x265, Main10 B-pyramid.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 newavd_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