All of lore.kernel.org
 help / color / mirror / Atom feed
From: Uma Shankar <uma.shankar@intel.com>
To: intel-gfx@lists.freedesktop.org, intel-xe@lists.freedesktop.org
Cc: ville.syrjala@linux.intel.com,
	Uma Shankar <uma.shankar@intel.com>,
	Vidya Srinivas <vidya.srinivas@intel.com>
Subject: [PATCH] drm/i915/cdclk: Fix 2 PPC hscale adjustment for min CDCLK
Date: Fri, 27 Nov 2026 00:40:32 +0530	[thread overview]
Message-ID: <20261126191032.1961148-1-uma.shankar@intel.com> (raw)

The horizontal scaler filter works at 2 PPC, but still needs a full
clock for a fractional shift of just one pixel. It doesn't shift by
two pixels and re-align the taps, so the extra clock doesn't average
out.

Bspec now documents the downscale amount used for the min CDCLK
calculation as:

  hscale_ppc = int(hscale) + min(1, ppc * frac(hscale))
  downscale  = max(hscale_ppc, hscale * vscale)

Compared to the empirical formula we have now, the fractional penalty
is capped at one extra clock, and since the scaler filters vertically
first the penalty does not multiply with the vertical downscale factor.
Update the code to match.

Platforms without 2 PPC (ppc == 1) are unaffected as the formula then
reduces to hscale * vscale.

Bspec: 68858
Fixes: f69946f6d891 ("drm/i915/cdclk: Deal with 2 PPC hscale issues when calculating min CDCLK")
Tested-by: Vidya Srinivas <vidya.srinivas@intel.com>
Signed-off-by: Uma Shankar <uma.shankar@intel.com>
---
 drivers/gpu/drm/i915/display/intel_plane.c | 42 ++++++++++++++--------
 1 file changed, 27 insertions(+), 15 deletions(-)

diff --git a/drivers/gpu/drm/i915/display/intel_plane.c b/drivers/gpu/drm/i915/display/intel_plane.c
index d23de0f34e4b..4a430d6a0ba9 100644
--- a/drivers/gpu/drm/i915/display/intel_plane.c
+++ b/drivers/gpu/drm/i915/display/intel_plane.c
@@ -266,25 +266,28 @@ unsigned int intel_adjusted_rate(const struct drm_rect *src,
 }
 
 static unsigned int hscale_cdclk(const struct drm_rect *src,
-				 const struct drm_rect *dst,
-				 unsigned int ppc)
+				 const struct drm_rect *dst)
 {
 	unsigned int hscale;
 
 	hscale = drm_rect_calc_hscale(src, dst, 0, INT_MAX);
 	hscale = max(hscale, 0x10000);
 
-	/*
-	 * Double the fractional part due to some 2 PPC granularity issue
-	 *
-	 * FIXME: BSpec calls for doubling only the <0.5 fractional part,
-	 * and rounding it down to a unit fraction. In practice that is
-	 * not sufficient, and we need a more aggressive CDCLK bump in
-	 * many cases. The updated formula was derived empirically.
-	 * This may need to be updated once we have better undestading
-	 * of what's happening in the hardware...
-	 */
-	return (hscale & ~0xffff) + ppc * (hscale & 0xffff);
+	return hscale;
+}
+
+/*
+ * Bspec: 68858
+ *
+ * The horizontal filter works at 2 PPC but still needs a full clock
+ * for a fractional shift of just 1 pixel, so the fractional part of
+ * the horizontal downscale factor costs PPC times more, but at most
+ * one full extra clock.
+ */
+static unsigned int hscale_ppc_cdclk(unsigned int hscale,
+				     unsigned int ppc)
+{
+	return (hscale & ~0xffff) + min(ppc * (hscale & 0xffff), 0x10000);
 }
 
 static unsigned int vscale_cdclk(const struct drm_rect *src,
@@ -303,10 +306,19 @@ unsigned int intel_adjusted_rate_cdclk(const struct drm_rect *src,
 				       unsigned int rate,
 				       unsigned int ppc)
 {
-	unsigned int hscale = hscale_cdclk(src, dst, ppc);
+	unsigned int hscale = hscale_cdclk(src, dst);
 	unsigned int vscale = vscale_cdclk(src, dst);
+	u64 scale;
+
+	/*
+	 * The scaler filters vertically first, so the horizontal
+	 * PPC inefficiency doesn't multiply with the vertical
+	 * downscale factor. .32 fixed point.
+	 */
+	scale = max((u64)hscale_ppc_cdclk(hscale, ppc) << 16,
+		    mul_u32_u32(hscale, vscale));
 
-	return DIV64_U64_ROUND_UP((u64)rate * hscale * vscale, 1ull << 32);
+	return DIV64_U64_ROUND_UP(rate * scale, 1ull << 32);
 }
 
 unsigned int intel_plane_pixel_rate(const struct intel_crtc_state *crtc_state,
-- 
2.50.1


             reply	other threads:[~2026-11-26 18:49 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-26 19:10 Uma Shankar [this message]
2026-11-26 19:41 ` [PATCH] drm/i915/cdclk: Fix 2 PPC hscale adjustment for min CDCLK Ville Syrjälä
2026-11-27  3:30   ` Srinivas, Vidya
2026-12-01 11:56     ` Shankar, Uma
2026-11-26 22:01 ` ✓ i915.CI.BAT: success for " Patchwork
2026-11-26 23:07 ` ✓ CI.KUnit: " Patchwork
2026-11-26 23:44 ` ✓ Xe.CI.BAT: " Patchwork
2026-11-27 10:57 ` ✓ Xe.CI.FULL: " Patchwork
2026-11-28  2:40 ` ✓ i915.CI.Full: " Patchwork

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=20261126191032.1961148-1-uma.shankar@intel.com \
    --to=uma.shankar@intel.com \
    --cc=intel-gfx@lists.freedesktop.org \
    --cc=intel-xe@lists.freedesktop.org \
    --cc=vidya.srinivas@intel.com \
    --cc=ville.syrjala@linux.intel.com \
    /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.