Repository navigation
media: apple: scaler: scale on the MMIO engines - #4165
RyanTheTide wants to merge 1 commit into
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.
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.
Still to run: the same rows on the MacBook Neo (A18 Pro, MSR22). The engine was busy there, held by the camera service, so it is not tested yet. Also an M1/M2/M3 row (hardware-version 10-17; same register layout per the public m1n1 map). #2804 changes the same
asc_fill()area; whichever lands second needs a small rebase.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.