All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dave Stevenson <dave.stevenson@raspberrypi.com>
To: Maxime Ripard <mripard@kernel.org>,
	Raspberry Pi Kernel Maintenance <kernel-list@raspberrypi.com>,
	Maarten Lankhorst <maarten.lankhorst@linux.intel.com>,
	Thomas Zimmermann <tzimmermann@suse.de>,
	David Airlie <airlied@gmail.com>, Daniel Vetter <daniel@ffwll.ch>,
	dri-devel@lists.freedesktop.org
Cc: Dom Cobley <popcornmix@gmail.com>,
	Dave Stevenson <dave.stevenson@raspberrypi.com>
Subject: [PATCH v2 02/31] drm/vc4: plane: Handle fractional coordinates using the phase field
Date: Fri, 21 Jun 2024 16:20:26 +0100	[thread overview]
Message-ID: <20240621152055.4180873-3-dave.stevenson@raspberrypi.com> (raw)
In-Reply-To: <20240621152055.4180873-1-dave.stevenson@raspberrypi.com>

From: Dom Cobley <popcornmix@gmail.com>

Apply fractional source co-ordinates into the scaling filters.

Signed-off-by: Dom Cobley <popcornmix@gmail.com>
Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
---
 drivers/gpu/drm/vc4/vc4_plane.c | 87 ++++++++++++++++++++++++++++-----
 1 file changed, 76 insertions(+), 11 deletions(-)

diff --git a/drivers/gpu/drm/vc4/vc4_plane.c b/drivers/gpu/drm/vc4/vc4_plane.c
index e0df210bedcb..b8c68d4688c8 100644
--- a/drivers/gpu/drm/vc4/vc4_plane.c
+++ b/drivers/gpu/drm/vc4/vc4_plane.c
@@ -532,14 +532,61 @@ static void vc4_write_tpz(struct vc4_plane_state *vc4_state, u32 src, u32 dst)
 			VC4_SET_FIELD(recip, SCALER_TPZ1_RECIP));
 }
 
-static void vc4_write_ppf(struct vc4_plane_state *vc4_state, u32 src, u32 dst)
+/* phase magnitude bits */
+#define PHASE_BITS 6
+
+static void vc4_write_ppf(struct vc4_plane_state *vc4_state, u32 src, u32 dst,
+			  u32 xy, int channel)
 {
-	u32 scale = (1 << 16) * src / dst;
+	u32 scale = src / dst;
+	s32 offset, offset2;
+	s32 phase;
+
+	/*
+	 * Start the phase at 1/2 pixel from the 1st pixel at src_x.
+	 * 1/4 pixel for YUV.
+	 */
+	if (channel) {
+		/*
+		 * The phase is relative to scale_src->x, so shift it for
+		 * display list's x value
+		 */
+		offset = (xy & 0x1ffff) >> (16 - PHASE_BITS) >> 1;
+		offset += -(1 << PHASE_BITS >> 2);
+	} else {
+		/*
+		 * The phase is relative to scale_src->x, so shift it for
+		 * display list's x value
+		 */
+		offset = (xy & 0xffff) >> (16 - PHASE_BITS);
+		offset += -(1 << PHASE_BITS >> 1);
+
+		/*
+		 * This is a kludge to make sure the scaling factors are
+		 * consistent with YUV's luma scaling. We lose 1-bit precision
+		 * because of this.
+		 */
+		scale &= ~1;
+	}
+
+	/*
+	 * There may be a also small error introduced by precision of scale.
+	 * Add half of that as a compromise
+	 */
+	offset2 = src - dst * scale;
+	offset2 >>= 16 - PHASE_BITS;
+	phase = offset + (offset2 >> 1);
+
+	/* Ensure +ve values don't touch the sign bit, then truncate negative values */
+	if (phase >= 1 << PHASE_BITS)
+		phase = (1 << PHASE_BITS) - 1;
+
+	phase &= SCALER_PPF_IPHASE_MASK;
 
 	vc4_dlist_write(vc4_state,
 			SCALER_PPF_AGC |
 			VC4_SET_FIELD(scale, SCALER_PPF_SCALE) |
-			VC4_SET_FIELD(0, SCALER_PPF_IPHASE));
+			VC4_SET_FIELD(phase, SCALER_PPF_IPHASE));
 }
 
 static u32 vc4_lbm_size(struct drm_plane_state *state)
@@ -597,27 +644,27 @@ static void vc4_write_scaling_parameters(struct drm_plane_state *state,
 
 	/* Ch0 H-PPF Word 0: Scaling Parameters */
 	if (vc4_state->x_scaling[channel] == VC4_SCALING_PPF) {
-		vc4_write_ppf(vc4_state,
-			      vc4_state->src_w[channel], vc4_state->crtc_w);
+		vc4_write_ppf(vc4_state, vc4_state->src_w[channel],
+			      vc4_state->crtc_w, vc4_state->src_x, channel);
 	}
 
 	/* Ch0 V-PPF Words 0-1: Scaling Parameters, Context */
 	if (vc4_state->y_scaling[channel] == VC4_SCALING_PPF) {
-		vc4_write_ppf(vc4_state,
-			      vc4_state->src_h[channel], vc4_state->crtc_h);
+		vc4_write_ppf(vc4_state, vc4_state->src_h[channel],
+			      vc4_state->crtc_h, vc4_state->src_y, channel);
 		vc4_dlist_write(vc4_state, 0xc0c0c0c0);
 	}
 
 	/* Ch0 H-TPZ Words 0-1: Scaling Parameters, Recip */
 	if (vc4_state->x_scaling[channel] == VC4_SCALING_TPZ) {
-		vc4_write_tpz(vc4_state,
-			      vc4_state->src_w[channel], vc4_state->crtc_w);
+		vc4_write_tpz(vc4_state, vc4_state->src_w[channel],
+			      vc4_state->crtc_w);
 	}
 
 	/* Ch0 V-TPZ Words 0-2: Scaling Parameters, Recip, Context */
 	if (vc4_state->y_scaling[channel] == VC4_SCALING_TPZ) {
-		vc4_write_tpz(vc4_state,
-			      vc4_state->src_h[channel], vc4_state->crtc_h);
+		vc4_write_tpz(vc4_state, vc4_state->src_h[channel],
+			      vc4_state->crtc_h);
 		vc4_dlist_write(vc4_state, 0xc0c0c0c0);
 	}
 }
@@ -1052,6 +1099,24 @@ static int vc4_plane_mode_set(struct drm_plane *plane,
 		return -EINVAL;
 	}
 
+	/* fetch an extra pixel if we don't actually line up with the left edge. */
+	if ((vc4_state->src_x & 0xffff) && vc4_state->src_x < (state->fb->width << 16))
+		width++;
+
+	/* same for the right side */
+	if (((vc4_state->src_x + vc4_state->src_w[0]) & 0xffff) &&
+	    vc4_state->src_x + vc4_state->src_w[0] < (state->fb->width << 16))
+		width++;
+
+	/* now for the top */
+	if ((vc4_state->src_y & 0xffff) && vc4_state->src_y < (state->fb->height << 16))
+		height++;
+
+	/* and the bottom */
+	if (((vc4_state->src_y + vc4_state->src_h[0]) & 0xffff) &&
+	    vc4_state->src_y + vc4_state->src_h[0] < (state->fb->height << 16))
+		height++;
+
 	/* Don't waste cycles mixing with plane alpha if the set alpha
 	 * is opaque or there is no per-pixel alpha information.
 	 * In any case we use the alpha property value as the fixed alpha.
-- 
2.34.1


  parent reply	other threads:[~2024-06-21 15:21 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-21 15:20 [PATCH v2 00/31] Preparatory patches for BCM2712 (Pi5) support Dave Stevenson
2024-06-21 15:20 ` [PATCH v2 01/31] drm/vc4: plane: Keep fractional source coords inside state Dave Stevenson
2024-06-21 15:20 ` Dave Stevenson [this message]
2024-06-21 15:20 ` [PATCH v2 03/31] drm/vc4: crtc: Force trigger of dlist update on margins change Dave Stevenson
2024-06-21 15:20 ` [PATCH v2 04/31] drm/vc4: hdmi: Avoid log spam for audio start failure Dave Stevenson
2024-06-21 15:20 ` [PATCH v2 05/31] drm/vc4: plane: Add support for YUV444 formats Dave Stevenson
2024-06-21 15:20 ` [PATCH v2 06/31] drm/vc4: hvs: Set AXI panic modes for the HVS Dave Stevenson
2024-06-21 15:20 ` [PATCH v2 07/31] drm/vc4: hdmi: Increase audio MAI fifo dreq threshold Dave Stevenson
2024-06-21 15:20 ` [PATCH v2 08/31] drm/vc4: hdmi: Warn if writing to an unknown HDMI register Dave Stevenson
2024-06-21 15:20 ` [PATCH v2 09/31] drm/vc4: hvs: More logging for dlist generation Dave Stevenson
2024-06-21 15:20 ` [PATCH v2 10/31] drm/vc4: hvs: Print error if we fail an allocation Dave Stevenson
2024-06-21 15:20 ` [PATCH v2 11/31] drm/vc4: plane: Add more debugging for LBM allocation Dave Stevenson
2024-06-21 15:20 ` [PATCH v2 12/31] drm/vc4: plane: Use return variable in atomic_check Dave Stevenson
2024-06-21 15:20 ` [PATCH v2 13/31] drm/vc4: crtc: Move assigned_channel to a variable Dave Stevenson
2024-06-21 15:20 ` [PATCH v2 14/31] drm/vc4: hvs: Don't write gamma luts on 2711 Dave Stevenson
2024-06-21 15:20 ` [PATCH v2 15/31] drm/vc4: plane: YUV planes require vertical scaling to always be enabled Dave Stevenson
2024-06-21 15:20 ` [PATCH v2 16/31] drm/vc4: hdmi: Avoid hang with debug registers when suspended Dave Stevenson
2024-06-21 15:20 ` [PATCH v2 17/31] drm/vc4: hvs: Fix dlist debug not resetting the next entry pointer Dave Stevenson
2024-06-21 15:20 ` [PATCH v2 18/31] drm/vc4: hvs: Remove incorrect limit from hvs_dlist debugfs function Dave Stevenson
2024-06-21 15:20 ` [PATCH v2 19/31] drm/vc4: hvs: Remove ABORT_ON_EMPTY flag Dave Stevenson
2024-06-21 15:20 ` [PATCH v2 20/31] drm/vc4: Introduce generation number enum Dave Stevenson
2024-10-07 11:59   ` [v2,20/31] " Marek Szyprowski
2024-10-07 18:13     ` Dave Stevenson
2024-06-21 15:20 ` [PATCH v2 21/31] drm/vc4: Make v3d paths unavailable on any generation newer than vc4 Dave Stevenson
2024-06-21 15:20 ` [PATCH v2 22/31] drm/vc4: hvs: Use switch statement to simplify vc4_hvs_get_fifo_from_output Dave Stevenson
2024-06-21 15:20 ` [PATCH v2 23/31] drm/vc4: hvs: Create hw_init function Dave Stevenson
2024-06-21 15:20 ` [PATCH v2 24/31] drm/vc4: hvs: Create cob_init function Dave Stevenson
2024-06-21 15:20 ` [PATCH v2 25/31] drm/vc4: hvs: Rename hvs_regs list Dave Stevenson
2024-06-21 15:20 ` [PATCH v2 26/31] drm/vc4: plane: Change ptr0_offset to an array Dave Stevenson
2024-06-21 15:20 ` [PATCH v2 27/31] drm/vc4: hvs: Rework LBM alignment Dave Stevenson
2024-06-21 15:20 ` [PATCH v2 28/31] drm/vc4: hvs: Change prototype of __vc4_hvs_alloc to pass registers Dave Stevenson
2024-06-21 15:20 ` [PATCH v2 29/31] drm/vc4: plane: Move the buffer offset out of the vc4_plane_state Dave Stevenson
2024-06-21 15:20 ` [PATCH v2 30/31] drm/vc4: hvs: Enable SCALER_CONTROL early in HVS init Dave Stevenson
2024-06-21 15:20 ` [PATCH v2 31/31] drm/vc4: hvs: Correct logic on stopping an HVS channel Dave Stevenson
2024-06-26 13:33 ` [PATCH v2 00/31] Preparatory patches for BCM2712 (Pi5) support Maxime Ripard

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=20240621152055.4180873-3-dave.stevenson@raspberrypi.com \
    --to=dave.stevenson@raspberrypi.com \
    --cc=airlied@gmail.com \
    --cc=daniel@ffwll.ch \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=kernel-list@raspberrypi.com \
    --cc=maarten.lankhorst@linux.intel.com \
    --cc=mripard@kernel.org \
    --cc=popcornmix@gmail.com \
    --cc=tzimmermann@suse.de \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.