Repository navigation
media: apple: scaler: scale on the MMIO engines - #4165
Conversation
The MMIO engines (MSR hardware-version 10 to 22) forced the CAPTURE size to the OUTPUT size and ran every job with the polyphase filters off. A CAPTURE format of another size came back at the source size, and GStreamer's V4L2 converter then took a top-left crop of the source as a resized picture. Program the scaler. Each axis gets its step and inverse step in Q22, an initial phase and a generated polyphase filter in both of its banks. The filters use the kernels and ratio bins of the MSR23 table (a Kaiser windowed sinc low-pass when downscaling, an interpolating 4-tap kernel when upscaling), generated by tools/media/apple-scaler/mmio_filters.py. The bank layout (32 phase slots per tap, signed phases, one or two coefficients per word) follows the public m1n1 scaler register map; the flags, steps and chroma resampling follow our own macOS register trace. The initial phase centres output on source, as swscale and GStreamer do: (step - 1) / 2, limited to the signed Q1.22 field. The chroma phase is twice that between two 4:2:0 pictures. The pseudo-linear mode stays off. Each of these was measured against swscale on the M4 Pro. CAPTURE now keeps its own size within 4x of the OUTPUT size per axis (the lossless layout stays at 1:1), and a scaled job grows to about 1400 register writes. Jobs at 1:1 program the same values as before. Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
|
Merge readiness at
Areas: Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels. |
|
Neo (J700, T8140,
One thing to look at, not a blocker for the YUV paths: scaled RGB->NV12 ( |
There was a problem hiding this comment.
Verdict: FINISH at e0100ff
Failure: The new lossless 1:1 path can negotiate a format that contradicts the advertised frame size steps. For example, an MMIO RGB OUTPUT width of 641 is valid, but asking for APPLE_L8V0 CAPTURE now copies 641 directly through asc_fill() at apple-scaler-drv.c:477–479. That format advertises an even-width step and the hardware job computes chroma width with integer division by two. The old format path aligned CAPTURE to its format's subsampling. Keep the lossless 1:1 constraint and reject an incompatible pair before accepting it.
Checked: The new resize path constrains each axis to the scale envelope, selects a generated filter from the step, and keeps unit-ratio programming on the existing path. I compared the new lossless branch with the base alignment path and traced the advertised size step and DMA plane-width calculation.
DjDeveloperr
left a comment
There was a problem hiding this comment.
Request changes at e0100ffe: one behaviour break, small fix. The rest of the scaling path looks right.
CAPTURE set before OUTPUT gives the wrong size. asc_s_fmt_out() (apple-scaler-drv.c:653-655) refills CAPTURE from its already clamped size. v4l2-ctl sets CAPTURE first, against the open-time 1920x1080 source. So 320x240 -> 320x240 is clamped to 480x270 by the CAPTURE call, and OUTPUT 320x240 then keeps 480x270. On main the same calls give 320x240. This hits every same-size job below 480x270 or above 7680x4320 set in that order. An application that sets only OUTPUT also gets 1920x1080 now instead of its source size. The colorimetry already has this fix (dst_ycbcr_req); do the same for the size:
/* struct apple_scaler_ctx: the CAPTURE size asked for, 0 until then */
u32 dst_w_req, dst_h_req;
/* asc_s_fmt_cap(), next to dst_quant_req, before asc_fill() */
ctx->dst_w_req = f->fmt.pix_mp.width;
ctx->dst_h_req = f->fmt.pix_mp.height;
/* asc_s_fmt_out(), before asc_fill(ctx->asc, &ctx->dst, ...) */
if (!ctx->asc->variant->fw_fronted) {
ctx->dst.width = ctx->dst_w_req ?: ctx->src.width;
ctx->dst.height = ctx->dst_h_req ?: ctx->src.height;
}Odd sizes into the lossless layout (also in the earlier review): asc_fill() lines 477-479 skip the ALIGN. Put the lossless case inside the last else (if (ref && lossless) {w = ref->width; ...} else if (ref) {clamp}), so the ALIGN and clamp below still run. Then 641x481 RGB -> L8V0 fails in asc_job_build() as on main.
I built both changes on the merge with main: W=1 and checkpatch clean, KUnit passes.
Small: the mmio_filters.py header names asc_emit_filter(), the function is asc_emit_axis().
Checked on the merge of this head with main dc4d6f06:
- W=1 arm64 objects clean, checkpatch --strict clean (one MAINTAINERS note for the new file), KUnit (UML) 29/29,
mmio_filters.py --checkmatches the table,apple-scaler-recovery-tests.pypasses. - Ratio and phase: no null filter set inside the 4x range, the phase cannot overflow, the write list and bank offsets fit the aperture and
ASC_JOB_MAX_WRITES. At 1:1 every register gets the same value as before. - CAPTURE size cannot change under queued buffers, so the engine does not get a picture larger than the buffer. MSR23 (M5) formats are unchanged. T602x, T603x and T8122 do not bind this driver, so nothing changes there.
Rows: after the push, one row at the new head (J700 again, or our J773g/T8132, MSR20) that includes a 256x128 same-size job with CAPTURE set first. J616s is the second generation. An M1 or M2 row (MSR 10, 12 or 13) is wanted but does not block, since 1:1 is unchanged there. The RGB -> NV12 chroma level you noted can be a follow-up.
Reapply the requested CAPTURE size when OUTPUT changes so the old source bounds do not constrain the new pair. Use the new source size until the application sets CAPTURE explicitly. Reject a lossless format pair when its 1:1 geometry violates CAPTURE subsampling. Commit formats and rectangles only after both queues have been validated. Signed-off-by: DjDeveloperr <hey@djdev.me>
|
Pushed Both arm64 scaler objects built with The remaining hardware rows are a CAPTURE-first 256×128 job and the scaling matrix on J700 or J773g, plus the same checks on J616s. The fix also needs a fresh independent review. |
There was a problem hiding this comment.
Verdict: FINISH at 87c6f8b.
Failure: With an idle MMIO scaler configured for 320×240 ARGB32 OUTPUT and L8V0 CAPTURE, ask to change OUTPUT to ARGB32 641×480. The exact asc_try_fmt_out() returned 0 and advertised 641×480, while asc_s_fmt_out() returned -EINVAL for the same request on the same configured queues. The first path normalizes OUTPUT alone, while the second reaches the new lossless alignment rejection for CAPTURE. Keep the OUTPUT format probe and application consistent so userspace can negotiate the pair. V4L2 format ioctl contract
Checked: The earlier odd-width failure is now rejected by S_FMT without changing either configured format or rectangle. CAPTURE-first 320×240 also retains that size when OUTPUT changes from 1920×1080 to 320×240.
DjDeveloperr
left a comment
There was a problem hiding this comment.
The CAPTURE sizing and lossless alignment findings are addressed at 87c6f8b7affd. I pushed the fix, so a separate maintainer still needs to approve. The J700 or J773g run and the J616s run are still due.
|
J773g (Apple M4 Mac mini, T8132) JPEG + scaler module row receipt:
|
An OUTPUT TRY_FMT can accept an odd RGB width while CAPTURE uses a lossless format. S_FMT rejects the same request because the lossless CAPTURE format must use the OUTPUT dimensions and requires alignment. Use the same format pair preparation for both OUTPUT ioctls. Commit the formats and rectangles only after S_FMT validates the pair. Signed-off-by: DjDeveloperr <hey@djdev.me>
|
Pushed The J773g hardware receipt covers |
There was a problem hiding this comment.
Verdict: MERGE at 5c61925
Checked: Both OUTPUT ioctls now validate the same pair using the original CAPTURE request. With L8V0 CAPTURE and idle queues, both exact callbacks return -EINVAL for 641x480 ARGB32 and preserve the configured formats and rectangles. At 640x480 they agree and S_FMT updates the configuration. CAPTURE-first sizing and odd RGB widths with an RGB CAPTURE format still work. A busy queue still allows TRY_FMT and rejects S_FMT without mutating the configuration. The callback checks passed under GCC and Clang. Hosted checks are pending.
|
J773g (Apple M4 Mac mini, T8132) scaler module row at exact head
The J700 row (#4160 |
|
MacBook Neo (J700, T8140) row, 12-03 16:40Z, zero reboot, module swap on stock
Not covered: other T8140 Macs, larger frames, long runs, and the display/camera users of these blocks. |
|
J616s (16" MacBook Pro M4 Pro, T6040, MSR21 scaler,
Afterwards the Mac went back to its production default (fleet94, Enforcing, 0 failed units). |
satchlj
left a comment
There was a problem hiding this comment.
Reviewed at head 5c61925c7e10.
- Format negotiation (
asc_fill,asc_try_fmt_pair) cleanly validates both sides before mutating context state, clamps scaled dimensions to[1/4, 4x]while keeping lossless layouts locked at 1:1 with subsampling alignment checked, and preservesdst_width_req/dst_height_reqacross OUTPUT updates. - Polyphase filter selection (
asc_filter_for,asc_filter_coef), centred DDA initial phases (including 2x chroma phase for 4:2:0->4:2:0 and Q1.22 clamping), dual-bank writes withinASC_JOB_MAX_WRITES(device-ownedasc->writes, no stack bloat), and 4:4:4 chroma resampling on scaled jobs are sound and well covered by KUnit (asc_test_filters,asc_test_job_scaled,asc_test_job_one_axis) andmmio_filters.py. - All checks green and exact-head hardware rows present.
The MMIO scaler engines (M1 to M4 generations, A18 Pro) now scale. Until now they only converted: a CAPTURE format of another size came back at the source size, and GStreamer's V4L2 converter passed a top-left crop of the source off as a resized picture.
Closes #4102
Refs #3614
Problem: on MSR hardware-version 10-22 the driver forced CAPTURE to the OUTPUT size and ran every job with the polyphase filters off. NV12 1920x1080 -> 1280x720 returned 1920x1080 on the M4 Pro and the A18 Pro.
Change: program the scaler. Each axis gets its steps, a centred initial phase and a generated filter in both banks. The filters use the same Kaiser windowed-sinc kernels and ratio bins as the MSR23 table, generated by
tools/media/apple-scaler/mmio_filters.py. CAPTURE keeps its own size within 4x either way per axis. The lossless layout stays at 1:1. Jobs at 1:1 program the same values as before.Tested: 7.3.0-aurora-fleet94 with this module (W=1 clean, checkpatch --strict clean, KUnit arm64 29/29 including 3 new cases) on the M4 Pro (J616s, MSR21). Every scaled job ran at the requested size with no kernel messages. PSNR-Y against swscale lanczos (frame 0 detail / frame 1 bars):
Against the old top-left crop the same rows score about 10 dB. All 9 same-size conversions (including NV12 -> BX24 640x480) are byte-identical to the stock driver. GStreamer 1.28.9
v4l2convertresizing to 1280x720, 960x540 and 1080p gives byte-identical pixels to those jobs.Risk: two-way door. It changes the driver only (no DT or UAPI). Applications that asked for another CAPTURE size and relied on getting the source size back now get the size they asked for.
Tested at
5c61925c7e10: J773g (T8132) and J700 (T8140) both passed same-size conversion, CAPTURE-first downscale to 256×128, and lossless OUTPUT TRY_FMT/S_FMT parity. Both runs kept the same boot, restored stock modules and reported zero new matching kernel errors. J773g receipt · J700 receipt.Still to run: current-head J616s coverage and an M1/M2/M3 row (hardware-version 10–17, same register layout per the public m1n1 map). #2804 changes the same
asc_fill()area.How the register values were chosen
CSC rows (scale-only reference)
The engine's own 1:1 colour conversion differs from swscale's (stock BGRA -> NV12 at 1:1 scores 28 dB, NV12 -> BGRA 32 dB). So these rows are also compared with swscale applied to the engine's 1:1 output:
Chroma of RGB -> 4:2:0 is limited by the existing 1:1 downsampler, not by scaling.