Intel-XE Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] drm/i915/cdclk: Fix 2 PPC hscale adjustment for min CDCLK
@ 2026-11-26 19:10 Uma Shankar
  2026-11-26 19:41 ` Ville Syrjälä
  0 siblings, 1 reply; 2+ messages in thread
From: Uma Shankar @ 2026-11-26 19:10 UTC (permalink / raw)
  To: intel-gfx, intel-xe; +Cc: ville.syrjala, Uma Shankar, Vidya Srinivas

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


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-26 19:42 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-26 19:10 [PATCH] drm/i915/cdclk: Fix 2 PPC hscale adjustment for min CDCLK Uma Shankar
2026-11-26 19:41 ` Ville Syrjälä

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox