[PATCH v2 1/3] media: qcom: iris: venc: keep the crop rectangle in visible resolution space

From: Loic Poulain

Date: Tue Nov 17 2026 - 05:47:13 EST


The encoder keeps two source resolutions. inst->fmt_src holds the padded
buffer geometry handed to userspace, with width aligned to 128 and height
to 32. enc_raw_width and enc_raw_height hold the visible resolution sent
to the firmware as HFI_PROP_RAW_RESOLUTION.

inst->crop must use the visible resolution, because
iris_hfi_gen2_set_crop_offsets() computes

bottom_offset = inst->enc_raw_height - inst->crop.height;

iris_venc_s_fmt_input() seeded inst->crop from the padded fmt_src instead,
so any height that is not a multiple of 32 underflows. Both offsets share
one payload word, so the right offset is corrupted too.

Seed inst->crop from the requested visible size, and report CROP_BOUNDS
and CROP_DEFAULT from enc_raw_*, so the bounds match the real source frame.

G_FMT is left as is. For contiguous NV12 pix_mp.height is the only way to
report the vertical luma padding, and the hardware is programmed with
scanline_y = ALIGN(h, 32).

v4l2-ctl -d /dev/video1 \
--set-fmt-video-out=width=1280,height=720,pixelformat=NV12 \
--get-selection-output=target=crop

Before:

Selection Video Output: crop, Left 0, Top 0, Width 1280, Height 736

After:

Selection Video Output: crop, Left 0, Top 0, Width 1280, Height 720

Fixes: d9967fa37ca9 ("media: qcom: iris: Improve format alignment for encoder")
Signed-off-by: Loic Poulain <loic.poulain@xxxxxxxxxxxxxxxx>
---
drivers/media/platform/qcom/iris/iris_venc.c | 4 ++--
drivers/media/platform/qcom/iris/iris_vidc.c | 4 ++--
2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/media/platform/qcom/iris/iris_venc.c b/drivers/media/platform/qcom/iris/iris_venc.c
index 2f2c56bf9122c73e10e86815b1aa5fad99b0fb42..c55d2d905c0064c6d292158ac741571a1471dc82 100644
--- a/drivers/media/platform/qcom/iris/iris_venc.c
+++ b/drivers/media/platform/qcom/iris/iris_venc.c
@@ -312,8 +312,8 @@ static int iris_venc_s_fmt_input(struct iris_inst *inst, struct v4l2_format *f)
f->fmt.pix_mp.height != inst->crop.height) {
inst->crop.top = 0;
inst->crop.left = 0;
- inst->crop.width = fmt->fmt.pix_mp.width;
- inst->crop.height = fmt->fmt.pix_mp.height;
+ inst->crop.width = f->fmt.pix_mp.width;
+ inst->crop.height = f->fmt.pix_mp.height;

iris_venc_s_fmt_output(inst, output_fmt);
}
diff --git a/drivers/media/platform/qcom/iris/iris_vidc.c b/drivers/media/platform/qcom/iris/iris_vidc.c
index 05aab6e3005d5c3788f5dfe5857f2d6b782e7a83..e3eaec1b7c2e30c065d8419ac3278756f70a8a97 100644
--- a/drivers/media/platform/qcom/iris/iris_vidc.c
+++ b/drivers/media/platform/qcom/iris/iris_vidc.c
@@ -522,8 +522,8 @@ static int iris_g_selection(struct file *filp, void *fh, struct v4l2_selection *
switch (s->target) {
case V4L2_SEL_TGT_CROP_BOUNDS:
case V4L2_SEL_TGT_CROP_DEFAULT:
- s->r.width = inst->fmt_src->fmt.pix_mp.width;
- s->r.height = inst->fmt_src->fmt.pix_mp.height;
+ s->r.width = inst->enc_raw_width;
+ s->r.height = inst->enc_raw_height;
break;
case V4L2_SEL_TGT_CROP:
s->r.width = inst->crop.width;

--
2.34.1