[PATCH 1/4] media: tegra-vde: size the bitstream buffer from the frame size

From: Jerome Berclaz via B4 Relay

Date: Thu Nov 26 2026 - 19:55:58 EST


From: Jerome Berclaz <jerome.berclaz@xxxxxxxxx>

tegra_try_coded_fmt() makes every bitstream (OUTPUT) buffer at least 2 MiB.
When the decoder sits behind the SMMU, the buffers use vb2_dma_sg_memops,
i.e. cached pages, and videobuf2 cleans the whole plane for every queued
buffer (once in dma_buf_end_cpu_access() when user space has written the
slice data, once more in __buf_prepare()). With 2 MiB per buffer that is
about 4 MiB of cache maintenance per decoded frame, although a 720p frame
is typically well below 200 KiB.

Use three quarters of a raw 4:2:0 frame as the default minimum instead
(704 KiB at 1280x720, 1.5 MiB at 1920x1080), still aligned to
SXE_BUFFER and never below 256 KiB. User space can still ask for more.

Measured on a Microsoft Surface RT (Tegra 30) with GStreamer
v4l2slh264dec on a 720p Constrained Baseline file: the v7/l2c210 clean
and invalidate functions in the decoding thread were about 21% of all CPU
samples before the change.

Signed-off-by: Jerome Berclaz <jerome.berclaz@xxxxxxxxx>
---
drivers/media/platform/nvidia/tegra-vde/v4l2.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/drivers/media/platform/nvidia/tegra-vde/v4l2.c b/drivers/media/platform/nvidia/tegra-vde/v4l2.c
index f2ca1c7ed9ba..9fe31b5c0275 100644
--- a/drivers/media/platform/nvidia/tegra-vde/v4l2.c
+++ b/drivers/media/platform/nvidia/tegra-vde/v4l2.c
@@ -635,6 +635,7 @@ static int tegra_try_coded_fmt(struct file *file, void *priv,
const struct tegra_vde_soc *soc = ctx->vde->soc;
int size = pix_mp->plane_fmt[0].sizeimage;
const struct tegra_coded_fmt_desc *desc;
+ unsigned int min_size;

desc = tegra_find_coded_fmt_desc(ctx, pix_mp->pixelformat);
if (!desc) {
@@ -646,7 +647,11 @@ static int tegra_try_coded_fmt(struct file *file, void *priv,
&pix_mp->height,
&desc->frmsize);

- pix_mp->plane_fmt[0].sizeimage = max(ALIGN(size, SXE_BUFFER), SZ_2M);
+ min_size = ALIGN(pix_mp->width * pix_mp->height * 3 / 4, SXE_BUFFER);
+ min_size = max_t(unsigned int, min_size, SZ_256K);
+
+ pix_mp->plane_fmt[0].sizeimage =
+ max_t(unsigned int, ALIGN(size, SXE_BUFFER), min_size);
pix_mp->field = V4L2_FIELD_NONE;
pix_mp->num_planes = 1;


--
2.53.0