From: Arun Iyengar Date: Fri, 04 Dec 2026 07:12:31 +0000 Subject: [PATCH 1/2] media: verisilicon: Match the VPU981 line stride MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20261204-av1-ref-stride-v1-1-5d86fb6d6858@gmail.com> References: <20261204-av1-ref-stride-v1-0-5d86fb6d6858@gmail.com> In-Reply-To: <20261204-av1-ref-stride-v1-0-5d86fb6d6858@gmail.com> To: Nicolas Dufresne , Benjamin Gaignard , Philipp Zabel , Mauro Carvalho Chehab , Heiko Stuebner , Hans Verkuil Cc: linux-media@vger.kernel.org, linux-rockchip@lists.infradead.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, stable@vger.kernel.org, Arun Iyengar X-Mailer: b4 0.15.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1796368350; l=6214; i=aiyengar1990@gmail.com; s=20261110; h=from:subject:message-id; bh=IZQdOIh+UZ6Yv4SwCs21fyRZGj42gorLKsN8161FqXQ=; b=jiz0I/KovZL1Lq0L6e1Q2o7U6P6HjzUIvjqKbxA5DjfN3Vq/qHdEPy3RRMSM4ePDuEsGOzq+v lUIu5Mc7vXGBNd0WG+Ixw6Sw5ytPSik9/23BBlD7TdRNsupzuNvFNev X-Developer-Key: i=aiyengar1990@gmail.com; a=ed25519; pk=zXpRgUTrhaFe6jLyPqbBy3ccfkj04w0g2690Wv3mg+0= X-Endpoint-Received: by B4 Relay for aiyengar1990@gmail.com/20261110 with auth_id=1480 List-Id: B4 Relay Submissions The VPU981 writes its 4x4 tile rows with a line stride of ALIGN(ALIGN(width, 8) * depth, 128) / 8 bytes. The driver took the stride from the width rounded up to 16 pixels, without alignment: - 10-bit widths that are not a multiple of 64 got a shorter stride, so the luma overran the chroma and the chroma the motion vectors. av1-1-b10-23-film_grain-50 (352x288) decodes wrong from its second frame. - 10-bit widths that are not a multiple of 16 can get a longer one: NV15_4L4 at 328x288 has bytesperline 420, the decoder uses 416. Align the 4L4 strides to 16 bytes and round the AV1 and 4L4 widths up to 8 pixels. The post-processed formats keep their 16 pixel step, so check the frame size against the reference format, which can now be narrower. Fixes: 003afda97c65 ("media: verisilicon: Enable AV1 decoder on rk3588") Cc: stable@vger.kernel.org # 7.2+ Signed-off-by: Arun Iyengar --- For stable: hantro_av1.c and its size check are not in 7.4 or older; drop that hunk there. --- drivers/media/platform/verisilicon/hantro.h | 2 ++ drivers/media/platform/verisilicon/hantro_av1.c | 8 ++++---- drivers/media/platform/verisilicon/hantro_v4l2.c | 10 ++++++---- drivers/media/platform/verisilicon/rockchip_vpu_hw.c | 8 +++++--- 4 files changed, 17 insertions(+), 11 deletions(-) diff --git a/drivers/media/platform/verisilicon/hantro.h b/drivers/media/platform/verisilicon/hantro.h index 1efa032506e1..8597a8611d8d 100644 --- a/drivers/media/platform/verisilicon/hantro.h +++ b/drivers/media/platform/verisilicon/hantro.h @@ -285,6 +285,7 @@ struct hantro_ctx { * @frmsize: Supported range of frame sizes (only for bitstream formats). * @postprocessed: Indicates if this format needs the post-processor. * @match_depth: Indicates if format bit depth must match video bit depth + * @stride_align: Byte alignment of the line stride written by the decoder */ struct hantro_fmt { char *name; @@ -296,6 +297,7 @@ struct hantro_fmt { struct v4l2_frmsize_stepwise frmsize; bool postprocessed; bool match_depth; + u8 stride_align; }; struct hantro_reg { diff --git a/drivers/media/platform/verisilicon/hantro_av1.c b/drivers/media/platform/verisilicon/hantro_av1.c index 2e79de145f48..d83a182f8a28 100644 --- a/drivers/media/platform/verisilicon/hantro_av1.c +++ b/drivers/media/platform/verisilicon/hantro_av1.c @@ -413,13 +413,13 @@ int hantro_av1_prepare_run(struct hantro_ctx *ctx) /* * The frame size comes from userspace. The decoder writes a frame of * that size, upscaled to upscaled_width, into buffers that are made - * for the CAPTURE format, so the frame has to fit in that format. As + * for the reference format, so the frame has to fit in that format. As * the format is within the limits of the decoder, this also keeps the * frame height in the range the tile column buffers can be sized for. */ - if (ctrls->frame->frame_width_minus_1 >= ctx->dst_fmt.width || - ctrls->frame->frame_height_minus_1 >= ctx->dst_fmt.height || - ctrls->frame->upscaled_width > ctx->dst_fmt.width) + if (ctrls->frame->frame_width_minus_1 >= ctx->ref_fmt.width || + ctrls->frame->frame_height_minus_1 >= ctx->ref_fmt.height || + ctrls->frame->upscaled_width > ctx->ref_fmt.width) return -EINVAL; ctrls->film_grain = diff --git a/drivers/media/platform/verisilicon/hantro_v4l2.c b/drivers/media/platform/verisilicon/hantro_v4l2.c index 8d9545423c65..d6e5834e39ab 100644 --- a/drivers/media/platform/verisilicon/hantro_v4l2.c +++ b/drivers/media/platform/verisilicon/hantro_v4l2.c @@ -141,8 +141,9 @@ hantro_set_reference_frames_format(struct hantro_ctx *ctx) ctx->ref_fmt.height = ctx->src_fmt.height; v4l2_apply_frmsize_constraints(&ctx->ref_fmt.width, &ctx->ref_fmt.height, &fmt->frmsize); - return v4l2_fill_pixfmt_mp(&ctx->ref_fmt, fmt->fourcc, - ctx->ref_fmt.width, ctx->ref_fmt.height); + return v4l2_fill_pixfmt_mp_aligned(&ctx->ref_fmt, fmt->fourcc, + ctx->ref_fmt.width, ctx->ref_fmt.height, + fmt->stride_align ?: 1); } const struct hantro_fmt * @@ -364,8 +365,9 @@ static int hantro_try_fmt(const struct hantro_ctx *ctx, if (!coded) { /* Fill remaining fields */ - v4l2_fill_pixfmt_mp(pix_mp, fmt->fourcc, pix_mp->width, - pix_mp->height); + v4l2_fill_pixfmt_mp_aligned(pix_mp, fmt->fourcc, pix_mp->width, + pix_mp->height, + fmt->stride_align ?: 1); if (ctx->vpu_src_fmt->fourcc == V4L2_PIX_FMT_H264_SLICE && !hantro_needs_postproc(ctx, fmt)) pix_mp->plane_fmt[0].sizeimage += diff --git a/drivers/media/platform/verisilicon/rockchip_vpu_hw.c b/drivers/media/platform/verisilicon/rockchip_vpu_hw.c index 614d54e3a8ef..1248f9086ff1 100644 --- a/drivers/media/platform/verisilicon/rockchip_vpu_hw.c +++ b/drivers/media/platform/verisilicon/rockchip_vpu_hw.c @@ -330,10 +330,11 @@ static const struct hantro_fmt rockchip_vpu981_dec_fmts[] = { .fourcc = V4L2_PIX_FMT_NV12_4L4, .codec_mode = HANTRO_MODE_NONE, .match_depth = true, + .stride_align = 16, .frmsize = { .min_width = ROCKCHIP_VPU981_MIN_SIZE, .max_width = FMT_4K_WIDTH, - .step_width = MB_DIM, + .step_width = 8, .min_height = ROCKCHIP_VPU981_MIN_SIZE, .max_height = FMT_4K_HEIGHT, .step_height = MB_DIM, @@ -343,10 +344,11 @@ static const struct hantro_fmt rockchip_vpu981_dec_fmts[] = { .fourcc = V4L2_PIX_FMT_NV15_4L4, .codec_mode = HANTRO_MODE_NONE, .match_depth = true, + .stride_align = 16, .frmsize = { .min_width = ROCKCHIP_VPU981_MIN_SIZE, .max_width = FMT_4K_WIDTH, - .step_width = MB_DIM, + .step_width = 8, .min_height = ROCKCHIP_VPU981_MIN_SIZE, .max_height = FMT_4K_HEIGHT, .step_height = MB_DIM, @@ -359,7 +361,7 @@ static const struct hantro_fmt rockchip_vpu981_dec_fmts[] = { .frmsize = { .min_width = ROCKCHIP_VPU981_MIN_SIZE, .max_width = FMT_4K_WIDTH, - .step_width = MB_DIM, + .step_width = 8, .min_height = ROCKCHIP_VPU981_MIN_SIZE, .max_height = FMT_4K_HEIGHT, .step_height = MB_DIM, -- 2.55.0