Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: "Jernej Škrabec" <jernej.skrabec@gmail.com>
To: wens@kernel.org
Cc: maarten.lankhorst@linux.intel.com, mripard@kernel.org,
	tzimmermann@suse.de, airlied@gmail.com, simona@ffwll.ch,
	samuel@sholland.org, dri-devel@lists.freedesktop.org,
	linux-arm-kernel@lists.infradead.org,
	linux-sunxi@lists.linux.dev, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 13/13] drm/sun4i: Align VI buffer addresses for subsampled formats
Date: Tue, 04 Aug 2026 19:58:45 +0200	[thread overview]
Message-ID: <58Gvon3UR1Sy7a6nLT6bDw@gmail.com> (raw)
In-Reply-To: <CAGb2v67mTzB+R7XDasSNhpmdzu5ikdoO0QwiHR432pdt_v7A_Q@mail.gmail.com>

Dne torek, 4. avgust 2026 ob 19:04:10 Srednjeevropski poletni čas je Chen-Yu Tsai napisal(a):
> On Wed, Aug 5, 2026 at 12:25 AM Jernej Škrabec <jernej.skrabec@gmail.com> wrote:
> >
> > Dne torek, 4. avgust 2026 ob 13:14:38 Srednjeevropski poletni čas je Chen-Yu Tsai napisal(a):
> > > On Tue, Aug 4, 2026 at 1:25 AM Chen-Yu Tsai <wens@kernel.org> wrote:
> > > >
> > > > On Tue, Aug 4, 2026 at 12:11 AM 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 for
> > > > > 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 <jernej.skrabec@gmail.com>
> > > > > ---
> > > > >  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 = plane->state;
> > > > >         struct drm_framebuffer *fb = state->fb;
> > > > >         const struct drm_format_info *format = 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 = sun8i_channel_base(layer);
> > > > >
> > > > > +       /* Adjust x and y to be divisible by subsampling factor */
> > > > > +       src_x = (state->src.x1 >> 16) & ~(format->hsub - 1);
> > > > > +       src_y = (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 = 0; i < format->num_planes; i++) {
> > > > > -               /* Get the start of the displayed memory */
> > > > > -               dma_addr = drm_fb_dma_get_gem_addr(fb, state, i);
> > > > > +               gem = drm_fb_dma_get_gem_obj(fb, i);
> > > > > +               dma_addr = gem->dma_addr + fb->offsets[i];
> > > > > +
> > > > > +               dx = src_x;
> > > > > +               dy = src_y;
> > > > > +               if (i > 0) {
> > > > > +                       dx /= format->hsub;
> > > > > +                       dy /= format->vsub;
> > > > > +               }
> > > > > +
> > > > > +               dma_addr += dx * format->cpp[i];
> > > > > +               dma_addr += dy * fb->pitches[i];
> > > >
> > > >
> > > > Where as the helper has (or used to have before the blocksize stuff):
> > > >
> > > >     paddr += (format->cpp[plane] * (state->src_x >> 16)) / fb->format->hsub;
> > > >     paddr += (fb->pitches[plane] * (state->src_y >> 16)) / fb->format->vsub;
> > > >
> > > > Am I missing something?
> > >
> > > After some headbanging on my end I see that the offset for the Y plane
> > > needs to be rounded down.
> > >
> > > 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.
> >
> > >
> > > 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.
> 
> My understanding is that drm_atomic_helper_check_plane_state() calculates
> the "clipped" rectangles for the plane using values from userspace in
> state->src_[xywh] and state->crtc_[xywh] and puts them in state->src
> and state->dst, respectively. If the overlay is moved partially outside
> the screen, the overlay is "clipped".
> 
> 
> Say we have a screen of 1920x1080, with an overlay buffer that is 1280x720.
> Say state->src_x and state->src_y are (-50, 0), given by userspace.
> drm_atomic_helper_check_plane_state() will calculate the clipped & scaled
> rectangles and put them in state->src. This latter rectangle is what is
> used sun8i_ui_layer_update_coord().
> 
> So we would have:
> 
>     (src_x, src_y) = (-50, 0), (src_w, src_h) = (1280, 720)
> 
> The clipped numbers are
> 
>     (src.x1, src.y1) = (0, 0), (src.x2, src.y2) = (1230, 720)
> 
> src, not src_[xywh], is what sun8i layers uses to program the coordinates,
> and prior to the drm_fb_dma_get_gem_addr() conversion, also to calculate
> the buffer start address. drm_fb_dma_get_gem_addr() however uses src_[xy]
> to calculate the address.
> 
> 
> Essentially, when overlaying a clipped plane, the start address needs to
> be adjusted if the source (top left) offset is outside the screen.
> clipping == automatic cropping to fit the screen.
> 
> I don't know if userspace applications routinely do this, but I think this
> needs to be restored to the prior behavior.

Uh, it would be nice if this is fixed. But I think it's not too common
for app to use negative coordinates.

Best regards,
Jernej




      reply	other threads:[~2026-08-04 17:59 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <cover.1785772659.git.jernej.skrabec@gmail.com>
2026-08-03 16:10 ` [PATCH 01/13] drm/sun4i: Fix V3s YUV scanline size Jernej Skrabec
2026-08-03 16:13   ` Chen-Yu Tsai
2026-08-06  6:34   ` (subset) " Chen-Yu Tsai
2026-08-03 16:10 ` [PATCH 02/13] drm/sun4i: vi scaler: Fix coefficient selection Jernej Skrabec
2026-08-04  2:13   ` Chen-Yu Tsai
2026-08-03 16:10 ` [PATCH 03/13] drm/sun4i: vi scaler: Restore opaque alpha in video modes Jernej Skrabec
2026-08-03 16:35   ` Chen-Yu Tsai
2026-08-03 16:10 ` [PATCH 04/13] drm/sun4i: tcon-top: Keep mixer routes distinct Jernej Skrabec
2026-08-03 16:44   ` Chen-Yu Tsai
2026-08-03 16:10 ` [PATCH 05/13] drm/sun4i: tcon: Set output mux for DSI and LVDS Jernej Skrabec
2026-08-03 16:45   ` Chen-Yu Tsai
2026-08-03 16:10 ` [PATCH 06/13] drm/sun4i: tcon: Drop TCON TOP device reference Jernej Skrabec
2026-08-03 16:49   ` Chen-Yu Tsai
2026-08-03 16:10 ` [PATCH 07/13] drm/sun4i: hdmi: Don't leak sync polarity bits into packet control Jernej Skrabec
2026-08-03 17:26   ` Chen-Yu Tsai
2026-08-03 16:10 ` [PATCH 08/13] drm/sun4i: crtc: Propagate layer initialization error Jernej Skrabec
2026-08-03 17:02   ` Chen-Yu Tsai
2026-08-03 16:10 ` [PATCH 09/13] drm/sun4i: tcon: Drop remote endpoint reference Jernej Skrabec
2026-08-03 17:04   ` Chen-Yu Tsai
2026-08-03 16:10 ` [PATCH 10/13] drm/sun4i: dw-hdmi: Drop TCON TOP port reference Jernej Skrabec
2026-08-03 17:05   ` Chen-Yu Tsai
2026-08-03 16:10 ` [PATCH 11/13] drm/sun4i: Drop node references while building component list Jernej Skrabec
2026-08-03 17:10   ` Chen-Yu Tsai
2026-08-03 16:10 ` [PATCH 12/13] drm/sun4i: hdmi-phy: Fix H6 8-bit MPLL config at 594 MHz Jernej Skrabec
2026-08-03 17:10   ` Chen-Yu Tsai
2026-08-03 16:10 ` [PATCH 13/13] drm/sun4i: Align VI buffer addresses for subsampled formats Jernej Skrabec
2026-08-03 17:25   ` Chen-Yu Tsai
2026-08-04 11:14     ` Chen-Yu Tsai
2026-08-04 16:25       ` Jernej Škrabec
2026-08-04 17:04         ` Chen-Yu Tsai
2026-08-04 17:58           ` Jernej Škrabec [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=58Gvon3UR1Sy7a6nLT6bDw@gmail.com \
    --to=jernej.skrabec@gmail.com \
    --cc=airlied@gmail.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-sunxi@lists.linux.dev \
    --cc=maarten.lankhorst@linux.intel.com \
    --cc=mripard@kernel.org \
    --cc=samuel@sholland.org \
    --cc=simona@ffwll.ch \
    --cc=tzimmermann@suse.de \
    --cc=wens@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox