From f65e84d956d146ec07f96eb01f82846176845b98 Mon Sep 17 00:00:00 2001 From: DjDeveloperr Date: Thu, 26 Nov 2026 04:03:23 -0500 Subject: [PATCH] media: apple: scaler: fill alpha for XRGB32 like ARGB32 A Y'CbCr source converted to XRGB32 had the alpha fill (0x8c bit 31) off, while the same source converted to ARGB32 has it on. The engine writes four bytes per pixel for both formats. Without source alpha and with the fill off, nothing supplies the fourth component, and every Y'CbCr to R'G'B' job macOS runs in our capture has the fill on. XRGB32 was the one such job the driver programmed differently, and P010 to XRGB32 at 1280x720 times out on the M4 and the A18 Pro. Turn the fill on for any R'G'B' destination whose source has no alpha. An XRGB32 destination is now programmed write for write like ARGB32, and its fourth byte is 0xff like ARGB32's alpha. Every traced job keeps its register values: Y'CbCr destinations and sources with alpha leave the fill off as before. Add a KUnit case: for NV12, NV12M, P010, ARGB32 and XRGB32 sources, the XRGB32 job equals the ARGB32 job write for write, and the fill is on exactly when the source has no alpha. Refs: #3216 Signed-off-by: DjDeveloperr --- .../platform/apple/scaler/apple-scaler-hw.c | 9 ++- .../platform/apple/scaler/apple-scaler-test.c | 61 +++++++++++++++++++ 2 files changed, 68 insertions(+), 2 deletions(-) diff --git a/drivers/media/platform/apple/scaler/apple-scaler-hw.c b/drivers/media/platform/apple/scaler/apple-scaler-hw.c index bc766c47e1948..9903f1475b4be 100644 --- a/drivers/media/platform/apple/scaler/apple-scaler-hw.c +++ b/drivers/media/platform/apple/scaler/apple-scaler-hw.c @@ -451,8 +451,13 @@ int asc_job_build(const struct asc_job *job, struct asc_reg *w, unsigned int max asc_emit_image(&e, &asc_rdma, &job->src); asc_emit_image(&e, &asc_wdma, &job->dst); asc_emit_memory(&e, job); - /* Alpha fill: constant opaque alpha when the source has none. */ - asc_emit(&e, 0x8c, (d->alpha && !s->alpha ? BIT(31) : 0) | 0xffff); + /* + * Alpha fill: constant opaque alpha for R'G'B' written from a source + * without alpha. macOS sets it for every such job in our capture, and + * the engine writes the fourth byte of XRGB32 as it does that of ARGB32, + * so an XRGB32 destination is programmed exactly like ARGB32. + */ + asc_emit(&e, 0x8c, (!d->yuv && !s->alpha ? BIT(31) : 0) | 0xffff); asc_emit_chroma(&e, job); asc_emit_unscaled(&e, job); if (job->csc) diff --git a/drivers/media/platform/apple/scaler/apple-scaler-test.c b/drivers/media/platform/apple/scaler/apple-scaler-test.c index 763d8a4010982..e91270ce57958 100644 --- a/drivers/media/platform/apple/scaler/apple-scaler-test.c +++ b/drivers/media/platform/apple/scaler/apple-scaler-test.c @@ -638,6 +638,66 @@ static void asc_test_job_rejects(struct kunit *test) KUNIT_EXPECT_EQ(test, asc_job_build(&job, w, ASC_JOB_MAX_WRITES), -EINVAL); } +/* + * An XRGB32 destination is programmed write for write like ARGB32: the + * engine writes both four bytes per pixel, and a source without alpha has + * the fill on, as macOS drives every Y'CbCr to R'G'B' job. + */ +static void asc_test_job_xrgb(struct kunit *test) +{ + static const u32 sources[] = { + V4L2_PIX_FMT_NV12, V4L2_PIX_FMT_NV12M, V4L2_PIX_FMT_P010, + V4L2_PIX_FMT_ARGB32, V4L2_PIX_FMT_XRGB32, + }; + struct asc_reg *a, *x; + struct asc_csc csc; + + a = kunit_kcalloc(test, ASC_JOB_MAX_WRITES, sizeof(*a), GFP_KERNEL); + x = kunit_kcalloc(test, ASC_JOB_MAX_WRITES, sizeof(*x), GFP_KERNEL); + KUNIT_ASSERT_NOT_NULL(test, a); + KUNIT_ASSERT_NOT_NULL(test, x); + KUNIT_ASSERT_EQ(test, asc_csc_compute(V4L2_YCBCR_ENC_709, V4L2_QUANTIZATION_LIM_RANGE, + true, &csc), 0); + + for (unsigned int i = 0; i < ARRAY_SIZE(sources); i++) { + struct asc_job job = { + .src = { + .fmt = asc_find_format(sources[i]), + .width = 1280, .height = 720, + .dva = { 0x100000000ULL, 0x100400000ULL }, + .stride = { 2560, 2560 }, + }, + .dst = { + .width = 1280, .height = 720, + .dva = { 0x200000000ULL }, .stride = { 5120 }, + }, + .transform_id = 0x94, + .msr20 = true, + }; + int na, nx; + u32 fill = 0; + + KUNIT_ASSERT_NOT_NULL(test, job.src.fmt); + job.csc = job.src.fmt->yuv ? &csc : NULL; + job.dst.fmt = asc_find_format(V4L2_PIX_FMT_ARGB32); + na = asc_job_build(&job, a, ASC_JOB_MAX_WRITES); + job.dst.fmt = asc_find_format(V4L2_PIX_FMT_XRGB32); + nx = asc_job_build(&job, x, ASC_JOB_MAX_WRITES); + KUNIT_ASSERT_GT(test, na, 0); + KUNIT_ASSERT_EQ(test, nx, na); + for (int j = 0; j < na; j++) { + KUNIT_EXPECT_EQ_MSG(test, x[j].off, a[j].off, "source %p4cc, write %d", + &sources[i], j); + KUNIT_EXPECT_EQ_MSG(test, x[j].val, a[j].val, "source %p4cc, register %#x", + &sources[i], a[j].off); + if (x[j].off == 0x8c) + fill = x[j].val; + } + KUNIT_EXPECT_EQ_MSG(test, fill, job.src.fmt->alpha ? 0x0000ffffU : 0x8000ffffU, + "source %p4cc", &sources[i]); + } +} + static struct kunit_case asc_test_cases[] = { KUNIT_CASE_PARAM(asc_test_csc, asc_csc_gen_params), KUNIT_CASE(asc_test_csc_rejects), @@ -648,6 +708,7 @@ static struct kunit_case asc_test_cases[] = { KUNIT_CASE(asc_test_job_rejects), KUNIT_CASE(asc_test_lossless_geom), KUNIT_CASE(asc_test_job_lossless), + KUNIT_CASE(asc_test_job_xrgb), {} };