Re: [PATCH 13/13] drm/sun4i: Align VI buffer addresses for subsampled formats

Jernej Škrabec <[email protected]> Tue, 04 Aug 2026 18:25:06 +0200
Newsgroups gmane.linux.kernel,gmane.comp.video.dri.devel,gmane.linux.ports.arm.kernel
Message-ID <[email protected]>
Dne torek, 4. avgust 2026 ob 13:14:38 Srednjeevropski poletni =C4=8Das je C=
hen-Yu Tsai napisal(a):
> On Tue, Aug 4, 2026 at 1:25=E2=80=AFAM Chen-Yu Tsai <[email protected]> wro=
te:
> >
> > On Tue, Aug 4, 2026 at 12:11=E2=80=AFAM Jernej Skrabec <jernej.skrabec@=
gmail.com> wrote:
> > >
> > > This is a partial revert of commit 79ac1c945ab8 ("drm/sun4i: layers:
> > > Use drm_fb_dma_get_gem_addr() to get display memory").
> > >
> > > Chroma must start at the beginning of a subsampling block, for example
> > > chroma start address for NV12 must be aligned to 2 pixels.
> > > drm_fb_dma_get_gem_addr() offsets luma by the exact source coordinates
> > > and chroma by the coordinates divided by the subsampling factor, so f=
or
> > > odd offsets both planes no longer describe the same pixel, which the
> > > Display Engine scaler can't handle.
> > >
> > > Align source coordinates down for all planes instead. Remaining shift
> > > of one pixel is already compensated with scaler phase shift in
> > > sun8i_vi_layer_update_coord().
> >
> > Well I think this applies to the format in general, and probably should
> > be fixed in drm_fb_dma_get_gem_addr() instead?
> >
> > > Fixes: 79ac1c945ab8 ("drm/sun4i: layers: Use drm_fb_dma_get_gem_addr(=
) to get display memory")
> > > Signed-off-by: Jernej Skrabec <[email protected]>
> > > ---
> > >  drivers/gpu/drm/sun4i/sun8i_vi_layer.c | 20 ++++++++++++++++++--
> > >  1 file changed, 18 insertions(+), 2 deletions(-)
> > >
> > > diff --git a/drivers/gpu/drm/sun4i/sun8i_vi_layer.c b/drivers/gpu/drm=
/sun4i/sun8i_vi_layer.c
> > > index 09f668c8af24..ad036cb9d88e 100644
> > > --- a/drivers/gpu/drm/sun4i/sun8i_vi_layer.c
> > > +++ b/drivers/gpu/drm/sun4i/sun8i_vi_layer.c
> > > @@ -197,15 +197,31 @@ static void sun8i_vi_layer_update_buffer(struct=
 sun8i_layer *layer,
> > >         struct drm_plane_state *state =3D plane->state;
> > >         struct drm_framebuffer *fb =3D state->fb;
> > >         const struct drm_format_info *format =3D fb->format;
> > > +       struct drm_gem_dma_object *gem;
> > > +       u32 dx, dy, src_x, src_y;
> > >         dma_addr_t dma_addr;
> > >         u32 ch_base;
> > >         int i;
> > >
> > >         ch_base =3D sun8i_channel_base(layer);
> > >
> > > +       /* Adjust x and y to be divisible by subsampling factor */
> > > +       src_x =3D (state->src.x1 >> 16) & ~(format->hsub - 1);
> > > +       src_y =3D (state->src.y1 >> 16) & ~(format->vsub - 1);
> >
> > AFAICT the only difference compared to drm_fb_dma_get_gem_addr()
> > is the masking here, i.e. round_down().
> >
> > > +
> > >         for (i =3D 0; i < format->num_planes; i++) {
> > > -               /* Get the start of the displayed memory */
> > > -               dma_addr =3D drm_fb_dma_get_gem_addr(fb, state, i);
> > > +               gem =3D drm_fb_dma_get_gem_obj(fb, i);
> > > +               dma_addr =3D gem->dma_addr + fb->offsets[i];
> > > +
> > > +               dx =3D src_x;
> > > +               dy =3D src_y;
> > > +               if (i > 0) {
> > > +                       dx /=3D format->hsub;
> > > +                       dy /=3D format->vsub;
> > > +               }
> > > +
> > > +               dma_addr +=3D dx * format->cpp[i];
> > > +               dma_addr +=3D dy * fb->pitches[i];
> >
> >
> > Where as the helper has (or used to have before the blocksize stuff):
> >
> >     paddr +=3D (format->cpp[plane] * (state->src_x >> 16)) / fb->format=
=2D>hsub;
> >     paddr +=3D (fb->pitches[plane] * (state->src_y >> 16)) / fb->format=
=2D>vsub;
> >
> > Am I missing something?
>=20
> After some headbanging on my end I see that the offset for the Y plane
> needs to be rounded down.
>=20
> But instead of reverting the whole thing and open-coding the helper
> again, could you adjust the address returned by the helper for odd
> offsets?

Yes, that's also an option. I'll do it in v2.

>=20
> And just a heads up, this also needs a clipped version of
> drm_fb_dma_get_gem_addr() as sun8i_ui_layer_update_coord() uses the
> clipped dimensions. I am currently working on this part.

Can you explain a bit more? I don't see why it needs any adjustement.

Best regards,
Jernej

>=20
>=20
> ChenYu
>=20
> > >
> > >                 /* Set the line width */
> > >                 DRM_DEBUG_DRIVER("Layer %d. line width: %d bytes\n",
> > > --
> > > 2.43.0
> > >
>=20