All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Ville Syrjälä" <ville.syrjala@linux.intel.com>
To: "Laxminarayan Bharadiya,
	Pankaj" <pankaj.laxminarayan.bharadiya@intel.com>
Cc: "tzimmermann@suse.de" <tzimmermann@suse.de>,
	"airlied@linux.ie" <airlied@linux.ie>,
	"De Marchi, Lucas" <lucas.demarchi@intel.com>,
	"intel-gfx@lists.freedesktop.org"
	<intel-gfx@lists.freedesktop.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"dri-devel@lists.freedesktop.org"
	<dri-devel@lists.freedesktop.org>,
	"Shankar, Uma" <uma.shankar@intel.com>,
	"Vivi, Rodrigo" <rodrigo.vivi@intel.com>,
	"Souza, Jose" <jose.souza@intel.com>,
	"Nautiyal, Ankit K" <ankit.k.nautiyal@intel.com>,
	"mihail.atanassov@arm.com" <mihail.atanassov@arm.com>
Subject: Re: [RFC][PATCH 5/5] drm/i915/display: Add Nearest-neighbor based integer scaling support
Date: Thu, 12 Mar 2020 15:54:38 +0200	[thread overview]
Message-ID: <20200312135438.GF13686@intel.com> (raw)
In-Reply-To: <E92BA18FDE0A5B43B7B3DA7FCA031286057B2C55@BGSMSX107.gar.corp.intel.com>

On Thu, Mar 12, 2020 at 09:13:24AM +0000, Laxminarayan Bharadiya, Pankaj wrote:
> 
> 
> > -----Original Message-----
> > From: Ville Syrjälä <ville.syrjala@linux.intel.com>
> > Sent: 10 March 2020 21:47
> > To: Laxminarayan Bharadiya, Pankaj
> > <pankaj.laxminarayan.bharadiya@intel.com>
> > Cc: jani.nikula@linux.intel.com; daniel@ffwll.ch; intel-
> > gfx@lists.freedesktop.org; dri-devel@lists.freedesktop.org; airlied@linux.ie;
> > maarten.lankhorst@linux.intel.com; tzimmermann@suse.de;
> > mripard@kernel.org; mihail.atanassov@arm.com; Joonas Lahtinen
> > <joonas.lahtinen@linux.intel.com>; Vivi, Rodrigo <rodrigo.vivi@intel.com>;
> > Chris Wilson <chris@chris-wilson.co.uk>; Souza, Jose
> > <jose.souza@intel.com>; De Marchi, Lucas <lucas.demarchi@intel.com>;
> > Roper, Matthew D <matthew.d.roper@intel.com>; Deak, Imre
> > <imre.deak@intel.com>; Shankar, Uma <uma.shankar@intel.com>; linux-
> > kernel@vger.kernel.org; Nautiyal, Ankit K <ankit.k.nautiyal@intel.com>
> > Subject: Re: [RFC][PATCH 5/5] drm/i915/display: Add Nearest-neighbor
> > based integer scaling support
> > 
> > On Tue, Feb 25, 2020 at 12:35:45PM +0530, Pankaj Bharadiya wrote:
> > > Integer scaling (IS) is a nearest-neighbor upscaling technique that
> > > simply scales up the existing pixels by an integer (i.e., whole
> > > number) multiplier.Nearest-neighbor (NN) interpolation works by
> > > filling in the missing color values in the upscaled image with that of
> > > the coordinate-mapped nearest source pixel value.
> > >
> > > Both IS and NN preserve the clarity of the original image. Integer
> > > scaling is particularly useful for pixel art games that rely on sharp,
> > > blocky images to deliver their distinctive look.
> > >
> > > Program the scaler filter coefficients to enable the NN filter if
> > > scaling filter property is set to DRM_SCALING_FILTER_NEAREST_NEIGHBOR
> > > and enable integer scaling.
> > >
> > > Bspec: 49247
> > >
> > > Signed-off-by: Pankaj Bharadiya
> > > <pankaj.laxminarayan.bharadiya@intel.com>
> > > Signed-off-by: Ankit Nautiyal <ankit.k.nautiyal@intel.com>
> > > ---
> > >  drivers/gpu/drm/i915/display/intel_display.c | 83
> > > +++++++++++++++++++-  drivers/gpu/drm/i915/display/intel_display.h |
> > > 2 +  drivers/gpu/drm/i915/display/intel_sprite.c  | 20 +++--
> > >  3 files changed, 97 insertions(+), 8 deletions(-)
> > >
> > > diff --git a/drivers/gpu/drm/i915/display/intel_display.c
> > > b/drivers/gpu/drm/i915/display/intel_display.c
> > > index b5903ef3c5a0..6d5f59203258 100644
> > > --- a/drivers/gpu/drm/i915/display/intel_display.c
> > > +++ b/drivers/gpu/drm/i915/display/intel_display.c
> > > @@ -6237,6 +6237,73 @@ void skl_scaler_disable(const struct
> > intel_crtc_state *old_crtc_state)
> > >  		skl_detach_scaler(crtc, i);
> > >  }
> > >
> > > +/**
> > > + *  Theory behind setting nearest-neighbor integer scaling:
> > > + *
> > > + *  17 phase of 7 taps requires 119 coefficients in 60 dwords per set.
> > > + *  The letter represents the filter tap (D is the center tap) and
> > > +the number
> > > + *  represents the coefficient set for a phase (0-16).
> > > + *
> > > + *         +------------+------------------------+------------------------+
> > > + *         |Index value | Data value coeffient 1 | Data value coeffient 2 |
> > > + *         +------------+------------------------+------------------------+
> > > + *         |   00h      |          B0            |          A0            |
> > > + *         +------------+------------------------+------------------------+
> > > + *         |   01h      |          D0            |          C0            |
> > > + *         +------------+------------------------+------------------------+
> > > + *         |   02h      |          F0            |          E0            |
> > > + *         +------------+------------------------+------------------------+
> > > + *         |   03h      |          A1            |          G0            |
> > > + *         +------------+------------------------+------------------------+
> > > + *         |   04h      |          C1            |          B1            |
> > > + *         +------------+------------------------+------------------------+
> > > + *         |   ...      |          ...           |          ...           |
> > > + *         +------------+------------------------+------------------------+
> > > + *         |   38h      |          B16           |          A16           |
> > > + *         +------------+------------------------+------------------------+
> > > + *         |   39h      |          D16           |          C16           |
> > > + *         +------------+------------------------+------------------------+
> > > + *         |   3Ah      |          F16           |          C16           |
> > > + *         +------------+------------------------+------------------------+
> > > + *         |   3Bh      |        Reserved        |          G16           |
> > > + *         +------------+------------------------+------------------------+
> > > + *
> > > + *  To enable nearest-neighbor scaling:  program scaler coefficents
> > > +with
> > > + *  the center tap (Dxx) values set to 1 and all other values set to
> > > +0 as per
> > > + *  SCALER_COEFFICIENT_FORMAT
> > > + *
> > > + */
> > > +void skl_setup_nearest_neighbor_filter(struct drm_i915_private
> > *dev_priv,
> > > +				  enum pipe pipe, int scaler_id)
> > 
> > skl_scaler_...
> > 
> > > +{
> > > +
> > > +	int coeff = 0;
> > > +	int phase = 0;
> > > +	int tap;
> > > +	int val = 0;
> > 
> > Needlessly wide scope for most of these.
> > 
> > > +
> > > +	/*enable the index auto increment.*/
> > > +	intel_de_write_fw(dev_priv, SKL_PS_COEF_INDEX_SET0(pipe,
> > scaler_id),
> > > +			  _PS_COEE_INDEX_AUTO_INC);
> > > +
> > > +	for (phase = 0; phase < 17; phase++) {
> > > +		for (tap = 0; tap < 7; tap++) {
> > > +			coeff++;
> > 
> > Can be part of the % check.
> 
> OK.
> 
> > 
> > > +			if (tap == 3)
> > > +				val = (phase % 2) ? (0x800) : (0x800 << 16);
> > 
> > Parens overload.
> 
> OK. Will remove.
> > 
> > > +
> > > +			if (coeff % 2 == 0) {
> > > +				intel_de_write_fw(dev_priv,
> > SKL_PS_COEF_DATA_SET0(pipe, scaler_id), val);
> > > +				val = 0;
> > 
> > Can drop this val=0 if you move the variable into tight scope and initialize
> > there.
> 
> Moving val=0 initialization to the tight scope will not work here as we need
> to retain "val" and write only when 2 coefficients are ready (since 2 
> coefficients are packed in 1 dword).
> 
> e.g. for (12th , 11th)  coefficients, coefficient reg value should be ( (0 << 16) | 0x800).
> If we initialize val = 0 in tight loop, 0 will be written to  coefficient register.

Hmm, right. I guess I'd try to rearrange this to iterate the
registers directly instead of the phases and taps. Something
like this perhaps:

static int cnl_coef_tap(int i)
{
	return i % 7;
}

static u16 cnl_coef(int t)
{
	return t == 3 ? 0x0800 : 0x3000;
}

static void cnl_program_nearest_filter_coefs(void)
{
	int i;

	for (i = 0; i < 17 * 7; i += 2) {
		uint32_t tmp;
		int t;

		t = cnl_coef_tap(i);
		tmp = cnl_nearest_filter_coef(t);

		t = cnl_coef_tap(i + 1);
		tmp |= cnl_nearest_filter_coef(t) << 16;

		intel_de_write_fw(tmp);
	}
}

More readable I think. The downside being all those modulo operations
but hopefully that's all in the noise when it comes to performance.

-- 
Ville Syrjälä
Intel
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

WARNING: multiple messages have this Message-ID (diff)
From: "Ville Syrjälä" <ville.syrjala@linux.intel.com>
To: "Laxminarayan Bharadiya,
	Pankaj" <pankaj.laxminarayan.bharadiya@intel.com>
Cc: "mripard@kernel.org" <mripard@kernel.org>,
	"tzimmermann@suse.de" <tzimmermann@suse.de>,
	"airlied@linux.ie" <airlied@linux.ie>,
	"De Marchi, Lucas" <lucas.demarchi@intel.com>,
	"intel-gfx@lists.freedesktop.org"
	<intel-gfx@lists.freedesktop.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"dri-devel@lists.freedesktop.org"
	<dri-devel@lists.freedesktop.org>,
	"Nautiyal, Ankit K" <ankit.k.nautiyal@intel.com>,
	"mihail.atanassov@arm.com" <mihail.atanassov@arm.com>
Subject: Re: [Intel-gfx] [RFC][PATCH 5/5] drm/i915/display: Add Nearest-neighbor based integer scaling support
Date: Thu, 12 Mar 2020 15:54:38 +0200	[thread overview]
Message-ID: <20200312135438.GF13686@intel.com> (raw)
In-Reply-To: <E92BA18FDE0A5B43B7B3DA7FCA031286057B2C55@BGSMSX107.gar.corp.intel.com>

On Thu, Mar 12, 2020 at 09:13:24AM +0000, Laxminarayan Bharadiya, Pankaj wrote:
> 
> 
> > -----Original Message-----
> > From: Ville Syrjälä <ville.syrjala@linux.intel.com>
> > Sent: 10 March 2020 21:47
> > To: Laxminarayan Bharadiya, Pankaj
> > <pankaj.laxminarayan.bharadiya@intel.com>
> > Cc: jani.nikula@linux.intel.com; daniel@ffwll.ch; intel-
> > gfx@lists.freedesktop.org; dri-devel@lists.freedesktop.org; airlied@linux.ie;
> > maarten.lankhorst@linux.intel.com; tzimmermann@suse.de;
> > mripard@kernel.org; mihail.atanassov@arm.com; Joonas Lahtinen
> > <joonas.lahtinen@linux.intel.com>; Vivi, Rodrigo <rodrigo.vivi@intel.com>;
> > Chris Wilson <chris@chris-wilson.co.uk>; Souza, Jose
> > <jose.souza@intel.com>; De Marchi, Lucas <lucas.demarchi@intel.com>;
> > Roper, Matthew D <matthew.d.roper@intel.com>; Deak, Imre
> > <imre.deak@intel.com>; Shankar, Uma <uma.shankar@intel.com>; linux-
> > kernel@vger.kernel.org; Nautiyal, Ankit K <ankit.k.nautiyal@intel.com>
> > Subject: Re: [RFC][PATCH 5/5] drm/i915/display: Add Nearest-neighbor
> > based integer scaling support
> > 
> > On Tue, Feb 25, 2020 at 12:35:45PM +0530, Pankaj Bharadiya wrote:
> > > Integer scaling (IS) is a nearest-neighbor upscaling technique that
> > > simply scales up the existing pixels by an integer (i.e., whole
> > > number) multiplier.Nearest-neighbor (NN) interpolation works by
> > > filling in the missing color values in the upscaled image with that of
> > > the coordinate-mapped nearest source pixel value.
> > >
> > > Both IS and NN preserve the clarity of the original image. Integer
> > > scaling is particularly useful for pixel art games that rely on sharp,
> > > blocky images to deliver their distinctive look.
> > >
> > > Program the scaler filter coefficients to enable the NN filter if
> > > scaling filter property is set to DRM_SCALING_FILTER_NEAREST_NEIGHBOR
> > > and enable integer scaling.
> > >
> > > Bspec: 49247
> > >
> > > Signed-off-by: Pankaj Bharadiya
> > > <pankaj.laxminarayan.bharadiya@intel.com>
> > > Signed-off-by: Ankit Nautiyal <ankit.k.nautiyal@intel.com>
> > > ---
> > >  drivers/gpu/drm/i915/display/intel_display.c | 83
> > > +++++++++++++++++++-  drivers/gpu/drm/i915/display/intel_display.h |
> > > 2 +  drivers/gpu/drm/i915/display/intel_sprite.c  | 20 +++--
> > >  3 files changed, 97 insertions(+), 8 deletions(-)
> > >
> > > diff --git a/drivers/gpu/drm/i915/display/intel_display.c
> > > b/drivers/gpu/drm/i915/display/intel_display.c
> > > index b5903ef3c5a0..6d5f59203258 100644
> > > --- a/drivers/gpu/drm/i915/display/intel_display.c
> > > +++ b/drivers/gpu/drm/i915/display/intel_display.c
> > > @@ -6237,6 +6237,73 @@ void skl_scaler_disable(const struct
> > intel_crtc_state *old_crtc_state)
> > >  		skl_detach_scaler(crtc, i);
> > >  }
> > >
> > > +/**
> > > + *  Theory behind setting nearest-neighbor integer scaling:
> > > + *
> > > + *  17 phase of 7 taps requires 119 coefficients in 60 dwords per set.
> > > + *  The letter represents the filter tap (D is the center tap) and
> > > +the number
> > > + *  represents the coefficient set for a phase (0-16).
> > > + *
> > > + *         +------------+------------------------+------------------------+
> > > + *         |Index value | Data value coeffient 1 | Data value coeffient 2 |
> > > + *         +------------+------------------------+------------------------+
> > > + *         |   00h      |          B0            |          A0            |
> > > + *         +------------+------------------------+------------------------+
> > > + *         |   01h      |          D0            |          C0            |
> > > + *         +------------+------------------------+------------------------+
> > > + *         |   02h      |          F0            |          E0            |
> > > + *         +------------+------------------------+------------------------+
> > > + *         |   03h      |          A1            |          G0            |
> > > + *         +------------+------------------------+------------------------+
> > > + *         |   04h      |          C1            |          B1            |
> > > + *         +------------+------------------------+------------------------+
> > > + *         |   ...      |          ...           |          ...           |
> > > + *         +------------+------------------------+------------------------+
> > > + *         |   38h      |          B16           |          A16           |
> > > + *         +------------+------------------------+------------------------+
> > > + *         |   39h      |          D16           |          C16           |
> > > + *         +------------+------------------------+------------------------+
> > > + *         |   3Ah      |          F16           |          C16           |
> > > + *         +------------+------------------------+------------------------+
> > > + *         |   3Bh      |        Reserved        |          G16           |
> > > + *         +------------+------------------------+------------------------+
> > > + *
> > > + *  To enable nearest-neighbor scaling:  program scaler coefficents
> > > +with
> > > + *  the center tap (Dxx) values set to 1 and all other values set to
> > > +0 as per
> > > + *  SCALER_COEFFICIENT_FORMAT
> > > + *
> > > + */
> > > +void skl_setup_nearest_neighbor_filter(struct drm_i915_private
> > *dev_priv,
> > > +				  enum pipe pipe, int scaler_id)
> > 
> > skl_scaler_...
> > 
> > > +{
> > > +
> > > +	int coeff = 0;
> > > +	int phase = 0;
> > > +	int tap;
> > > +	int val = 0;
> > 
> > Needlessly wide scope for most of these.
> > 
> > > +
> > > +	/*enable the index auto increment.*/
> > > +	intel_de_write_fw(dev_priv, SKL_PS_COEF_INDEX_SET0(pipe,
> > scaler_id),
> > > +			  _PS_COEE_INDEX_AUTO_INC);
> > > +
> > > +	for (phase = 0; phase < 17; phase++) {
> > > +		for (tap = 0; tap < 7; tap++) {
> > > +			coeff++;
> > 
> > Can be part of the % check.
> 
> OK.
> 
> > 
> > > +			if (tap == 3)
> > > +				val = (phase % 2) ? (0x800) : (0x800 << 16);
> > 
> > Parens overload.
> 
> OK. Will remove.
> > 
> > > +
> > > +			if (coeff % 2 == 0) {
> > > +				intel_de_write_fw(dev_priv,
> > SKL_PS_COEF_DATA_SET0(pipe, scaler_id), val);
> > > +				val = 0;
> > 
> > Can drop this val=0 if you move the variable into tight scope and initialize
> > there.
> 
> Moving val=0 initialization to the tight scope will not work here as we need
> to retain "val" and write only when 2 coefficients are ready (since 2 
> coefficients are packed in 1 dword).
> 
> e.g. for (12th , 11th)  coefficients, coefficient reg value should be ( (0 << 16) | 0x800).
> If we initialize val = 0 in tight loop, 0 will be written to  coefficient register.

Hmm, right. I guess I'd try to rearrange this to iterate the
registers directly instead of the phases and taps. Something
like this perhaps:

static int cnl_coef_tap(int i)
{
	return i % 7;
}

static u16 cnl_coef(int t)
{
	return t == 3 ? 0x0800 : 0x3000;
}

static void cnl_program_nearest_filter_coefs(void)
{
	int i;

	for (i = 0; i < 17 * 7; i += 2) {
		uint32_t tmp;
		int t;

		t = cnl_coef_tap(i);
		tmp = cnl_nearest_filter_coef(t);

		t = cnl_coef_tap(i + 1);
		tmp |= cnl_nearest_filter_coef(t) << 16;

		intel_de_write_fw(tmp);
	}
}

More readable I think. The downside being all those modulo operations
but hopefully that's all in the noise when it comes to performance.

-- 
Ville Syrjälä
Intel
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

WARNING: multiple messages have this Message-ID (diff)
From: "Ville Syrjälä" <ville.syrjala@linux.intel.com>
To: "Laxminarayan Bharadiya,
	Pankaj"  <pankaj.laxminarayan.bharadiya@intel.com>
Cc: "jani.nikula@linux.intel.com" <jani.nikula@linux.intel.com>,
	"daniel@ffwll.ch" <daniel@ffwll.ch>,
	"intel-gfx@lists.freedesktop.org"
	<intel-gfx@lists.freedesktop.org>,
	"dri-devel@lists.freedesktop.org"
	<dri-devel@lists.freedesktop.org>,
	"airlied@linux.ie" <airlied@linux.ie>,
	"maarten.lankhorst@linux.intel.com" 
	<maarten.lankhorst@linux.intel.com>,
	"tzimmermann@suse.de" <tzimmermann@suse.de>,
	"mripard@kernel.org" <mripard@kernel.org>,
	"mihail.atanassov@arm.com" <mihail.atanassov@arm.com>,
	Joonas Lahtinen <joonas.lahtinen@linux.intel.com>,
	"Vivi, Rodrigo" <rodrigo.vivi@intel.com>,
	Chris Wilson <chris@chris-wilson.co.uk>,
	"Souza, Jose" <jose.souza@intel.com>,
	"De Marchi, Lucas" <lucas.demarchi@intel.com>,
	"Roper, Matthew D" <matthew.d.roper@intel.com>,
	"Deak, Imre" <imre.deak@intel.com>,
	"Shankar, Uma" <uma.shankar@intel.com>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"Nautiyal, Ankit K" <ankit.k.nautiyal@intel.com>
Subject: Re: [RFC][PATCH 5/5] drm/i915/display: Add Nearest-neighbor based integer scaling support
Date: Thu, 12 Mar 2020 15:54:38 +0200	[thread overview]
Message-ID: <20200312135438.GF13686@intel.com> (raw)
In-Reply-To: <E92BA18FDE0A5B43B7B3DA7FCA031286057B2C55@BGSMSX107.gar.corp.intel.com>

On Thu, Mar 12, 2020 at 09:13:24AM +0000, Laxminarayan Bharadiya, Pankaj wrote:
> 
> 
> > -----Original Message-----
> > From: Ville Syrjälä <ville.syrjala@linux.intel.com>
> > Sent: 10 March 2020 21:47
> > To: Laxminarayan Bharadiya, Pankaj
> > <pankaj.laxminarayan.bharadiya@intel.com>
> > Cc: jani.nikula@linux.intel.com; daniel@ffwll.ch; intel-
> > gfx@lists.freedesktop.org; dri-devel@lists.freedesktop.org; airlied@linux.ie;
> > maarten.lankhorst@linux.intel.com; tzimmermann@suse.de;
> > mripard@kernel.org; mihail.atanassov@arm.com; Joonas Lahtinen
> > <joonas.lahtinen@linux.intel.com>; Vivi, Rodrigo <rodrigo.vivi@intel.com>;
> > Chris Wilson <chris@chris-wilson.co.uk>; Souza, Jose
> > <jose.souza@intel.com>; De Marchi, Lucas <lucas.demarchi@intel.com>;
> > Roper, Matthew D <matthew.d.roper@intel.com>; Deak, Imre
> > <imre.deak@intel.com>; Shankar, Uma <uma.shankar@intel.com>; linux-
> > kernel@vger.kernel.org; Nautiyal, Ankit K <ankit.k.nautiyal@intel.com>
> > Subject: Re: [RFC][PATCH 5/5] drm/i915/display: Add Nearest-neighbor
> > based integer scaling support
> > 
> > On Tue, Feb 25, 2020 at 12:35:45PM +0530, Pankaj Bharadiya wrote:
> > > Integer scaling (IS) is a nearest-neighbor upscaling technique that
> > > simply scales up the existing pixels by an integer (i.e., whole
> > > number) multiplier.Nearest-neighbor (NN) interpolation works by
> > > filling in the missing color values in the upscaled image with that of
> > > the coordinate-mapped nearest source pixel value.
> > >
> > > Both IS and NN preserve the clarity of the original image. Integer
> > > scaling is particularly useful for pixel art games that rely on sharp,
> > > blocky images to deliver their distinctive look.
> > >
> > > Program the scaler filter coefficients to enable the NN filter if
> > > scaling filter property is set to DRM_SCALING_FILTER_NEAREST_NEIGHBOR
> > > and enable integer scaling.
> > >
> > > Bspec: 49247
> > >
> > > Signed-off-by: Pankaj Bharadiya
> > > <pankaj.laxminarayan.bharadiya@intel.com>
> > > Signed-off-by: Ankit Nautiyal <ankit.k.nautiyal@intel.com>
> > > ---
> > >  drivers/gpu/drm/i915/display/intel_display.c | 83
> > > +++++++++++++++++++-  drivers/gpu/drm/i915/display/intel_display.h |
> > > 2 +  drivers/gpu/drm/i915/display/intel_sprite.c  | 20 +++--
> > >  3 files changed, 97 insertions(+), 8 deletions(-)
> > >
> > > diff --git a/drivers/gpu/drm/i915/display/intel_display.c
> > > b/drivers/gpu/drm/i915/display/intel_display.c
> > > index b5903ef3c5a0..6d5f59203258 100644
> > > --- a/drivers/gpu/drm/i915/display/intel_display.c
> > > +++ b/drivers/gpu/drm/i915/display/intel_display.c
> > > @@ -6237,6 +6237,73 @@ void skl_scaler_disable(const struct
> > intel_crtc_state *old_crtc_state)
> > >  		skl_detach_scaler(crtc, i);
> > >  }
> > >
> > > +/**
> > > + *  Theory behind setting nearest-neighbor integer scaling:
> > > + *
> > > + *  17 phase of 7 taps requires 119 coefficients in 60 dwords per set.
> > > + *  The letter represents the filter tap (D is the center tap) and
> > > +the number
> > > + *  represents the coefficient set for a phase (0-16).
> > > + *
> > > + *         +------------+------------------------+------------------------+
> > > + *         |Index value | Data value coeffient 1 | Data value coeffient 2 |
> > > + *         +------------+------------------------+------------------------+
> > > + *         |   00h      |          B0            |          A0            |
> > > + *         +------------+------------------------+------------------------+
> > > + *         |   01h      |          D0            |          C0            |
> > > + *         +------------+------------------------+------------------------+
> > > + *         |   02h      |          F0            |          E0            |
> > > + *         +------------+------------------------+------------------------+
> > > + *         |   03h      |          A1            |          G0            |
> > > + *         +------------+------------------------+------------------------+
> > > + *         |   04h      |          C1            |          B1            |
> > > + *         +------------+------------------------+------------------------+
> > > + *         |   ...      |          ...           |          ...           |
> > > + *         +------------+------------------------+------------------------+
> > > + *         |   38h      |          B16           |          A16           |
> > > + *         +------------+------------------------+------------------------+
> > > + *         |   39h      |          D16           |          C16           |
> > > + *         +------------+------------------------+------------------------+
> > > + *         |   3Ah      |          F16           |          C16           |
> > > + *         +------------+------------------------+------------------------+
> > > + *         |   3Bh      |        Reserved        |          G16           |
> > > + *         +------------+------------------------+------------------------+
> > > + *
> > > + *  To enable nearest-neighbor scaling:  program scaler coefficents
> > > +with
> > > + *  the center tap (Dxx) values set to 1 and all other values set to
> > > +0 as per
> > > + *  SCALER_COEFFICIENT_FORMAT
> > > + *
> > > + */
> > > +void skl_setup_nearest_neighbor_filter(struct drm_i915_private
> > *dev_priv,
> > > +				  enum pipe pipe, int scaler_id)
> > 
> > skl_scaler_...
> > 
> > > +{
> > > +
> > > +	int coeff = 0;
> > > +	int phase = 0;
> > > +	int tap;
> > > +	int val = 0;
> > 
> > Needlessly wide scope for most of these.
> > 
> > > +
> > > +	/*enable the index auto increment.*/
> > > +	intel_de_write_fw(dev_priv, SKL_PS_COEF_INDEX_SET0(pipe,
> > scaler_id),
> > > +			  _PS_COEE_INDEX_AUTO_INC);
> > > +
> > > +	for (phase = 0; phase < 17; phase++) {
> > > +		for (tap = 0; tap < 7; tap++) {
> > > +			coeff++;
> > 
> > Can be part of the % check.
> 
> OK.
> 
> > 
> > > +			if (tap == 3)
> > > +				val = (phase % 2) ? (0x800) : (0x800 << 16);
> > 
> > Parens overload.
> 
> OK. Will remove.
> > 
> > > +
> > > +			if (coeff % 2 == 0) {
> > > +				intel_de_write_fw(dev_priv,
> > SKL_PS_COEF_DATA_SET0(pipe, scaler_id), val);
> > > +				val = 0;
> > 
> > Can drop this val=0 if you move the variable into tight scope and initialize
> > there.
> 
> Moving val=0 initialization to the tight scope will not work here as we need
> to retain "val" and write only when 2 coefficients are ready (since 2 
> coefficients are packed in 1 dword).
> 
> e.g. for (12th , 11th)  coefficients, coefficient reg value should be ( (0 << 16) | 0x800).
> If we initialize val = 0 in tight loop, 0 will be written to  coefficient register.

Hmm, right. I guess I'd try to rearrange this to iterate the
registers directly instead of the phases and taps. Something
like this perhaps:

static int cnl_coef_tap(int i)
{
	return i % 7;
}

static u16 cnl_coef(int t)
{
	return t == 3 ? 0x0800 : 0x3000;
}

static void cnl_program_nearest_filter_coefs(void)
{
	int i;

	for (i = 0; i < 17 * 7; i += 2) {
		uint32_t tmp;
		int t;

		t = cnl_coef_tap(i);
		tmp = cnl_nearest_filter_coef(t);

		t = cnl_coef_tap(i + 1);
		tmp |= cnl_nearest_filter_coef(t) << 16;

		intel_de_write_fw(tmp);
	}
}

More readable I think. The downside being all those modulo operations
but hopefully that's all in the noise when it comes to performance.

-- 
Ville Syrjälä
Intel

  reply	other threads:[~2020-03-12 13:54 UTC|newest]

Thread overview: 83+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-25  7:05 [RFC][PATCH 0/5] Introduce drm scaling filter property Pankaj Bharadiya
2020-02-25  7:05 ` Pankaj Bharadiya
2020-02-25  7:05 ` [Intel-gfx] " Pankaj Bharadiya
2020-02-25  7:05 ` [RFC][PATCH 1/5] drm: Introduce " Pankaj Bharadiya
2020-02-25  7:05   ` Pankaj Bharadiya
2020-02-25  7:05   ` [Intel-gfx] " Pankaj Bharadiya
2020-02-25  9:56   ` Jani Nikula
2020-02-25  9:56     ` Jani Nikula
2020-02-25  9:56     ` [Intel-gfx] " Jani Nikula
2020-02-25 10:09     ` Laxminarayan Bharadiya, Pankaj
2020-02-25 10:09       ` Laxminarayan Bharadiya, Pankaj
2020-02-25 10:09       ` [Intel-gfx] " Laxminarayan Bharadiya, Pankaj
2020-02-25 11:07       ` Jani Nikula
2020-02-25 11:07         ` Jani Nikula
2020-02-25 11:07         ` [Intel-gfx] " Jani Nikula
2020-03-10 16:01   ` Ville Syrjälä
2020-03-10 16:01     ` Ville Syrjälä
2020-03-10 16:01     ` [Intel-gfx] " Ville Syrjälä
2020-03-16  8:31     ` Daniel Vetter
2020-03-16  8:31       ` Daniel Vetter
2020-03-16  8:31       ` [Intel-gfx] " Daniel Vetter
2020-03-16 15:14       ` Ville Syrjälä
2020-03-16 15:14         ` Ville Syrjälä
2020-03-16 15:14         ` [Intel-gfx] " Ville Syrjälä
2020-02-25  7:05 ` [RFC][PATCH 2/5] drm/drm-kms.rst: Add Scaling filter property documentation Pankaj Bharadiya
2020-02-25  7:05   ` Pankaj Bharadiya
2020-02-25  7:05   ` [Intel-gfx] " Pankaj Bharadiya
2020-02-25  7:05 ` [RFC][PATCH 3/5] drm/i915: Enable scaling filter for plane and pipe Pankaj Bharadiya
2020-02-25  7:05   ` Pankaj Bharadiya
2020-02-25  7:05   ` [Intel-gfx] " Pankaj Bharadiya
2020-03-10 16:05   ` Ville Syrjälä
2020-03-10 16:05     ` Ville Syrjälä
2020-03-10 16:05     ` [Intel-gfx] " Ville Syrjälä
2020-03-12  8:58     ` Laxminarayan Bharadiya, Pankaj
2020-03-12  8:58       ` Laxminarayan Bharadiya, Pankaj
2020-03-12  8:58       ` [Intel-gfx] " Laxminarayan Bharadiya, Pankaj
2020-03-12 12:27       ` Ville Syrjälä
2020-03-12 12:27         ` Ville Syrjälä
2020-03-12 12:27         ` [Intel-gfx] " Ville Syrjälä
2020-02-25  7:05 ` [RFC][PATCH 4/5] drm/i915: Introduce scaling filter related registers and bit fields Pankaj Bharadiya
2020-02-25  7:05   ` Pankaj Bharadiya
2020-02-25  7:05   ` [Intel-gfx] " Pankaj Bharadiya
2020-03-10 16:08   ` Ville Syrjälä
2020-03-10 16:08     ` Ville Syrjälä
2020-03-10 16:08     ` [Intel-gfx] " Ville Syrjälä
2020-02-25  7:05 ` [RFC][PATCH 5/5] drm/i915/display: Add Nearest-neighbor based integer scaling support Pankaj Bharadiya
2020-02-25  7:05   ` Pankaj Bharadiya
2020-02-25  7:05   ` [Intel-gfx] " Pankaj Bharadiya
2020-02-25  7:29   ` Daniel Stone
2020-02-25  7:29     ` Daniel Stone
2020-02-25  7:29     ` Daniel Stone
2020-02-28  5:50     ` Laxminarayan Bharadiya, Pankaj
2020-02-28  5:50       ` Laxminarayan Bharadiya, Pankaj
2020-02-28  5:50       ` Laxminarayan Bharadiya, Pankaj
2020-03-10 16:17   ` Ville Syrjälä
2020-03-10 16:17     ` Ville Syrjälä
2020-03-10 16:17     ` [Intel-gfx] " Ville Syrjälä
2020-03-12  9:13     ` Laxminarayan Bharadiya, Pankaj
2020-03-12  9:13       ` Laxminarayan Bharadiya, Pankaj
2020-03-12  9:13       ` [Intel-gfx] " Laxminarayan Bharadiya, Pankaj
2020-03-12 13:54       ` Ville Syrjälä [this message]
2020-03-12 13:54         ` Ville Syrjälä
2020-03-12 13:54         ` [Intel-gfx] " Ville Syrjälä
2020-03-13  8:45         ` Laxminarayan Bharadiya, Pankaj
2020-03-13  8:45           ` Laxminarayan Bharadiya, Pankaj
2020-03-13  8:45           ` [Intel-gfx] " Laxminarayan Bharadiya, Pankaj
2020-03-13 19:53           ` Ville Syrjälä
2020-03-13 19:53             ` Ville Syrjälä
2020-03-13 19:53             ` [Intel-gfx] " Ville Syrjälä
2020-02-25  7:24 ` [Intel-gfx] ✗ Fi.CI.CHECKPATCH: warning for Introduce drm scaling filter property Patchwork
2020-02-25  7:50 ` [Intel-gfx] ✗ Fi.CI.BAT: failure " Patchwork
2020-03-12 14:04 ` [RFC][PATCH 0/5] " Ville Syrjälä
2020-03-12 14:04   ` Ville Syrjälä
2020-03-12 14:04   ` [Intel-gfx] " Ville Syrjälä
2020-03-12 15:37   ` Laxminarayan Bharadiya, Pankaj
2020-03-12 15:37     ` Laxminarayan Bharadiya, Pankaj
2020-03-12 15:37     ` [Intel-gfx] " Laxminarayan Bharadiya, Pankaj
2020-03-12 16:01     ` Ville Syrjälä
2020-03-12 16:01       ` Ville Syrjälä
2020-03-12 16:01       ` [Intel-gfx] " Ville Syrjälä
2020-03-13 10:35       ` Pekka Paalanen
2020-03-13 10:35         ` Pekka Paalanen
2020-03-13 10:35         ` [Intel-gfx] " Pekka Paalanen

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=20200312135438.GF13686@intel.com \
    --to=ville.syrjala@linux.intel.com \
    --cc=airlied@linux.ie \
    --cc=ankit.k.nautiyal@intel.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=intel-gfx@lists.freedesktop.org \
    --cc=jose.souza@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lucas.demarchi@intel.com \
    --cc=mihail.atanassov@arm.com \
    --cc=pankaj.laxminarayan.bharadiya@intel.com \
    --cc=rodrigo.vivi@intel.com \
    --cc=tzimmermann@suse.de \
    --cc=uma.shankar@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.