Skip to contentSkip to conversation

media: verisilicon: Fix the VPU981 line stride and minimum size

PATCH New Arun Iyengar 1 participant 3 messages Dec 4

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

cover media: verisilicon: Fix the VPU981 line stride and minimum size

Two cases where the format did not describe what the RK3588 AV1 decoder
writes: the 10-bit line stride, and frames narrower than 49 pixels.

Tested on an Orange Pi 5 (RK3588S), 7.3-based tree, under KASAN, against
libdav1d: 10-bit NV15_4L4 CAPTURE is bit-exact at widths 18, 36, 100, 200 and 328, with buffers of the reported sizeimage, and so is 10-bit P010 through the post-processor at widths 200 and 328. No AV1-TEST-VECTORS regression, av1-1-b10-23-film_grain-50 included.

Developed with Claude (Anthropic), which wrote the code and the commit messages. I reviewed every change.

---
Arun Iyengar (2):
media: verisilicon: Match the VPU981 line stride
media: verisilicon: av1: Lower the VPU981 minimum size to 16x16

 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 | 10 ++++++----
 4 files changed, 18 insertions(+), 12 deletions(-)

---
base-commit: 95c189b26efb07257888ccf9d873a5c366aafbc6
change-id: 20261130-av1-ref-stride-9635a02756d5

Best regards,

Signature · 1 line
Arun Iyengar <[email protected]>
#1 lore raw

PATCH 1/2 media: verisilicon: Match the VPU981 line stride

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")

---
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(-)
drivers/media/platform/verisilicon/hantro.h +2 -0
index 1efa032506e1..8597a8611d8d 100644
@@ -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 {
drivers/media/platform/verisilicon/hantro_av1.c +4 -4
index 2e79de145f48..d83a182f8a28 100644
@@ -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 =
drivers/media/platform/verisilicon/hantro_v4l2.c +6 -4
index 8d9545423c65..d6e5834e39ab 100644
@@ -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 +=
drivers/media/platform/verisilicon/rockchip_vpu_hw.c +5 -3
index 614d54e3a8ef..1248f9086ff1 100644
@@ -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,
Signature · 1 line
2.55.0
#2 lore raw

PATCH 2/2 media: verisilicon: av1: Lower the VPU981 minimum size to 16x16

In reply to Arun Iyengar

Frames below the 64x64 format minimum are decoded today, with the line stride of their own width. For frames narrower than 49 pixels the stride of the 64 pixel wide format does not match that.

Fixes 003afda97c65 ("media: verisilicon: Enable AV1 decoder on rk3588")
---
 drivers/media/platform/verisilicon/rockchip_vpu_hw.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/platform/verisilicon/rockchip_vpu_hw.c +1 -1
index 1248f9086ff1..f3e7c881d85b 100644
@@ -19,7 +19,7 @@
 #define RK3066_ACLK_MAX_FREQ (300 * 1000 * 1000)
 #define RK3288_ACLK_MAX_FREQ (400 * 1000 * 1000)
 
-#define ROCKCHIP_VPU981_MIN_SIZE 64
+#define ROCKCHIP_VPU981_MIN_SIZE 16
 
 /*
  * Supported formats.
Signature · 1 line
2.55.0