All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] drm/komeda: Fix off-by-1 when with readback conn due to rounding
@ 2021-03-11 12:08 carsten.haitzler
  2021-03-12 10:55 ` Brian Starkey
  0 siblings, 1 reply; 7+ messages in thread
From: carsten.haitzler @ 2021-03-11 12:08 UTC (permalink / raw)
  To: dri-devel; +Cc: liviu.dudau, Carsten Haitzler, steven.price

From: Carsten Haitzler <carsten.haitzler@arm.com>

When setting up a readback connector that writes data back to memory
rather than to an actual output device (HDMI etc.), rounding was set
to round. As the DPU uses a higher internal number of bits when generating
a color value, this round-down back to 8bit ended up with everything
being off-by one. e.g. #fefefe became #ffffff. This sets
rounding to "round-down" so things end up correct by turning on the LW_TRC
round down flag.

Signed-off-by: Carsten Haitzler <carsten.haitzler@arm.com>
---
 drivers/gpu/drm/arm/display/komeda/d71/d71_component.c | 7 ++++++-
 drivers/gpu/drm/arm/display/komeda/d71/d71_regs.h      | 1 +
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/arm/display/komeda/d71/d71_component.c b/drivers/gpu/drm/arm/display/komeda/d71/d71_component.c
index 8a02ade369db..e97acc5519d1 100644
--- a/drivers/gpu/drm/arm/display/komeda/d71/d71_component.c
+++ b/drivers/gpu/drm/arm/display/komeda/d71/d71_component.c
@@ -468,7 +468,12 @@ static void d71_wb_layer_update(struct komeda_component *c,
 	struct komeda_layer_state *st = to_layer_st(state);
 	struct drm_connector_state *conn_st = state->wb_conn->state;
 	struct komeda_fb *kfb = to_kfb(conn_st->writeback_job->fb);
-	u32 ctrl = L_EN | LW_OFM, mask = L_EN | LW_OFM | LW_TBU_EN;
+	/* LW_TRC sets rounding to truncate not round which is needed for
+	 * the output of writeback to match the input in the most common
+	 * use cases like RGB888 -> RGB888, so set this bit by default
+	 */
+	u32 ctrl = LW_TRC | L_EN | LW_OFM;
+	u32 mask = LW_TRC | L_EN | LW_OFM | LW_TBU_EN;
 	u32 __iomem *reg = c->reg;
 
 	d71_layer_update_fb(c, kfb, st->addr);
diff --git a/drivers/gpu/drm/arm/display/komeda/d71/d71_regs.h b/drivers/gpu/drm/arm/display/komeda/d71/d71_regs.h
index e80172a0b320..a8036689d721 100644
--- a/drivers/gpu/drm/arm/display/komeda/d71/d71_regs.h
+++ b/drivers/gpu/drm/arm/display/komeda/d71/d71_regs.h
@@ -321,6 +321,7 @@
 #define LAYER_WR_FORMAT		0x0D8
 
 /* Layer_WR control bits */
+#define LW_TRC			BIT(1)
 #define LW_OFM			BIT(4)
 #define LW_LALPHA(x)		(((x) & 0xFF) << 8)
 #define LW_A_WCACHE(x)		(((x) & 0xF) << 28)
-- 
2.30.0

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

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

* Re: [PATCH] drm/komeda: Fix off-by-1 when with readback conn due to rounding
  2021-03-11 12:08 [PATCH] drm/komeda: Fix off-by-1 when with readback conn due to rounding carsten.haitzler
@ 2021-03-12 10:55 ` Brian Starkey
  2021-03-16  3:17   ` James Qian Wang
  2021-03-29 15:27   ` Carsten Haitzler
  0 siblings, 2 replies; 7+ messages in thread
From: Brian Starkey @ 2021-03-12 10:55 UTC (permalink / raw)
  To: carsten.haitzler, james.qian.wang
  Cc: nd, liviu.dudau, Carsten Haitzler, dri-devel, steven.price

(Adding back James again - did you use get_maintainer.pl?)

On Thu, Mar 11, 2021 at 12:08:46PM +0000, carsten.haitzler@foss.arm.com wrote:
> From: Carsten Haitzler <carsten.haitzler@arm.com>
> 
> When setting up a readback connector that writes data back to memory
> rather than to an actual output device (HDMI etc.), rounding was set
> to round. As the DPU uses a higher internal number of bits when generating
> a color value, this round-down back to 8bit ended up with everything
> being off-by one. e.g. #fefefe became #ffffff. This sets

Perhaps overly pedantic, but now we've tracked down what was actually
happening I think we can be more precise here. Not _everything_ is
off-by-one, it's just rounding in the standard sense - if the most
significant bit-to-be-discarded is set, the value is rounded up to
minimise the absolute error introduced by bit-depth reduction.

> rounding to "round-down" so things end up correct by turning on the LW_TRC
> round down flag.

Can we call it "truncate" rather than round down? I think it makes
"TRC" a bit more understandable.

> 
> Signed-off-by: Carsten Haitzler <carsten.haitzler@arm.com>
> ---
>  drivers/gpu/drm/arm/display/komeda/d71/d71_component.c | 7 ++++++-
>  drivers/gpu/drm/arm/display/komeda/d71/d71_regs.h      | 1 +
>  2 files changed, 7 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/gpu/drm/arm/display/komeda/d71/d71_component.c b/drivers/gpu/drm/arm/display/komeda/d71/d71_component.c
> index 8a02ade369db..e97acc5519d1 100644
> --- a/drivers/gpu/drm/arm/display/komeda/d71/d71_component.c
> +++ b/drivers/gpu/drm/arm/display/komeda/d71/d71_component.c
> @@ -468,7 +468,12 @@ static void d71_wb_layer_update(struct komeda_component *c,
>  	struct komeda_layer_state *st = to_layer_st(state);
>  	struct drm_connector_state *conn_st = state->wb_conn->state;
>  	struct komeda_fb *kfb = to_kfb(conn_st->writeback_job->fb);
> -	u32 ctrl = L_EN | LW_OFM, mask = L_EN | LW_OFM | LW_TBU_EN;
> +	/* LW_TRC sets rounding to truncate not round which is needed for
> +	 * the output of writeback to match the input in the most common
> +	 * use cases like RGB888 -> RGB888, so set this bit by default
> +	 */

Hm, not sure why this file uses "net/" style comments, but as you
said, this is in-keeping with the rest of the file, so meh :-)

> +	u32 ctrl = LW_TRC | L_EN | LW_OFM;
> +	u32 mask = LW_TRC | L_EN | LW_OFM | LW_TBU_EN;

If you were aiming for matching register order, this should be:

    L_EN | LW_TRC | LW_OFM | LW_TBU_EN


I think it'd be nice to have the exact behaviour in the commit
message, but either way this seems OK as a pragmatic fix so:

Reviewed-by: Brian Starkey <brian.starkey@arm.com>

Thanks,
-Brian

>  	u32 __iomem *reg = c->reg;
>  
>  	d71_layer_update_fb(c, kfb, st->addr);
> diff --git a/drivers/gpu/drm/arm/display/komeda/d71/d71_regs.h b/drivers/gpu/drm/arm/display/komeda/d71/d71_regs.h
> index e80172a0b320..a8036689d721 100644
> --- a/drivers/gpu/drm/arm/display/komeda/d71/d71_regs.h
> +++ b/drivers/gpu/drm/arm/display/komeda/d71/d71_regs.h
> @@ -321,6 +321,7 @@
>  #define LAYER_WR_FORMAT		0x0D8
>  
>  /* Layer_WR control bits */
> +#define LW_TRC			BIT(1)
>  #define LW_OFM			BIT(4)
>  #define LW_LALPHA(x)		(((x) & 0xFF) << 8)
>  #define LW_A_WCACHE(x)		(((x) & 0xF) << 28)
> -- 
> 2.30.0
> 
> _______________________________________________
> dri-devel mailing list
> dri-devel@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/dri-devel
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

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

* Re: [PATCH] drm/komeda: Fix off-by-1 when with readback conn due to rounding
  2021-03-12 10:55 ` Brian Starkey
@ 2021-03-16  3:17   ` James Qian Wang
  2021-03-29 15:27   ` Carsten Haitzler
  1 sibling, 0 replies; 7+ messages in thread
From: James Qian Wang @ 2021-03-16  3:17 UTC (permalink / raw)
  To: Brian Starkey
  Cc: Carsten Haitzler, liviu.dudau, dri-devel, steven.price,
	carsten.haitzler, nd

On Fri, Mar 12, 2021 at 10:55:21AM +0000, Brian Starkey wrote:
> (Adding back James again - did you use get_maintainer.pl?)
> 
> On Thu, Mar 11, 2021 at 12:08:46PM +0000, carsten.haitzler@foss.arm.com wrote:
> > From: Carsten Haitzler <carsten.haitzler@arm.com>
> > 
> > When setting up a readback connector that writes data back to memory
> > rather than to an actual output device (HDMI etc.), rounding was set
> > to round. As the DPU uses a higher internal number of bits when generating
> > a color value, this round-down back to 8bit ended up with everything
> > being off-by one. e.g. #fefefe became #ffffff. This sets
> 
> Perhaps overly pedantic, but now we've tracked down what was actually
> happening I think we can be more precise here. Not _everything_ is
> off-by-one, it's just rounding in the standard sense - if the most
> significant bit-to-be-discarded is set, the value is rounded up to
> minimise the absolute error introduced by bit-depth reduction.
> 
> > rounding to "round-down" so things end up correct by turning on the LW_TRC
> > round down flag.
> 
> Can we call it "truncate" rather than round down? I think it makes
> "TRC" a bit more understandable.
> 
> > 
> > Signed-off-by: Carsten Haitzler <carsten.haitzler@arm.com>
> > ---
> >  drivers/gpu/drm/arm/display/komeda/d71/d71_component.c | 7 ++++++-
> >  drivers/gpu/drm/arm/display/komeda/d71/d71_regs.h      | 1 +
> >  2 files changed, 7 insertions(+), 1 deletion(-)
> > 
> > diff --git a/drivers/gpu/drm/arm/display/komeda/d71/d71_component.c b/drivers/gpu/drm/arm/display/komeda/d71/d71_component.c
> > index 8a02ade369db..e97acc5519d1 100644
> > --- a/drivers/gpu/drm/arm/display/komeda/d71/d71_component.c
> > +++ b/drivers/gpu/drm/arm/display/komeda/d71/d71_component.c
> > @@ -468,7 +468,12 @@ static void d71_wb_layer_update(struct komeda_component *c,
> >  	struct komeda_layer_state *st = to_layer_st(state);
> >  	struct drm_connector_state *conn_st = state->wb_conn->state;
> >  	struct komeda_fb *kfb = to_kfb(conn_st->writeback_job->fb);
> > -	u32 ctrl = L_EN | LW_OFM, mask = L_EN | LW_OFM | LW_TBU_EN;
> > +	/* LW_TRC sets rounding to truncate not round which is needed for
> > +	 * the output of writeback to match the input in the most common
> > +	 * use cases like RGB888 -> RGB888, so set this bit by default
> > +	 */
> 
> Hm, not sure why this file uses "net/" style comments, but as you
> said, this is in-keeping with the rest of the file, so meh :-)
> 
> > +	u32 ctrl = LW_TRC | L_EN | LW_OFM;
> > +	u32 mask = LW_TRC | L_EN | LW_OFM | LW_TBU_EN;
> 
> If you were aiming for matching register order, this should be:
> 
>     L_EN | LW_TRC | LW_OFM | LW_TBU_EN
> 
> 
> I think it'd be nice to have the exact behaviour in the commit
> message, but either way this seems OK as a pragmatic fix so:
> 
> Reviewed-by: Brian Starkey <brian.starkey@arm.com>
> 
> Thanks,
> -Brian
> 
> >  	u32 __iomem *reg = c->reg;
> >  
> >  	d71_layer_update_fb(c, kfb, st->addr);
> > diff --git a/drivers/gpu/drm/arm/display/komeda/d71/d71_regs.h b/drivers/gpu/drm/arm/display/komeda/d71/d71_regs.h
> > index e80172a0b320..a8036689d721 100644
> > --- a/drivers/gpu/drm/arm/display/komeda/d71/d71_regs.h
> > +++ b/drivers/gpu/drm/arm/display/komeda/d71/d71_regs.h
> > @@ -321,6 +321,7 @@
> >  #define LAYER_WR_FORMAT		0x0D8
> >  
> >  /* Layer_WR control bits */
> > +#define LW_TRC			BIT(1)
> >  #define LW_OFM			BIT(4)
> >  #define LW_LALPHA(x)		(((x) & 0xFF) << 8)
> >  #define LW_A_WCACHE(x)		(((x) & 0xF) << 28)
> > -- 
> > 2.30.0
> > 

Acked-by: James Qian Wang <james.qian.wang@arm.com>

Thanks
James

> > _______________________________________________
> > dri-devel mailing list
> > dri-devel@lists.freedesktop.org
> > https://lists.freedesktop.org/mailman/listinfo/dri-devel
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

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

* Re: [PATCH] drm/komeda: Fix off-by-1 when with readback conn due to rounding
  2021-03-12 10:55 ` Brian Starkey
  2021-03-16  3:17   ` James Qian Wang
@ 2021-03-29 15:27   ` Carsten Haitzler
  1 sibling, 0 replies; 7+ messages in thread
From: Carsten Haitzler @ 2021-03-29 15:27 UTC (permalink / raw)
  To: dri-devel

On 3/12/21 10:55 AM, Brian Starkey wrote:
> (Adding back James again - did you use get_maintainer.pl?)
> 
> On Thu, Mar 11, 2021 at 12:08:46PM +0000, carsten.haitzler@foss.arm.com wrote:
>> From: Carsten Haitzler <carsten.haitzler@arm.com>
>>
>> When setting up a readback connector that writes data back to memory
>> rather than to an actual output device (HDMI etc.), rounding was set
>> to round. As the DPU uses a higher internal number of bits when generating
>> a color value, this round-down back to 8bit ended up with everything
>> being off-by one. e.g. #fefefe became #ffffff. This sets
> 
> Perhaps overly pedantic, but now we've tracked down what was actually
> happening I think we can be more precise here. Not _everything_ is
> off-by-one, it's just rounding in the standard sense - if the most

Well a very large number of pixels were off-by-1 ... I guess it's an 
exaggeration but a "vast number of pixels were off by 1". I guess I was 
just using common terms like "everything is expensive here" doesn't 
actually mean absolutely everything but a very vast number of things. 
You know what I mean. :) The comment as a whole describing rounding 
policies should provide more details. I just write the log as a "when 
spelunking through history, this log will give me some broader insight 
into what this change is without being war and peace and If I want to 
see more and this commit is interesting to my spelunking efforts, I'll 
git log -U to read that".

> significant bit-to-be-discarded is set, the value is rounded up to
> minimise the absolute error introduced by bit-depth reduction.
> 
>> rounding to "round-down" so things end up correct by turning on the LW_TRC
>> round down flag.
> 
> Can we call it "truncate" rather than round down? I think it makes
> "TRC" a bit more understandable.

That's the official name from the docs though (TRC)... makes it easier 
to match to them... So I think you can argue this both ways. The comment 
where it's used though does make it clear...

>>
>> Signed-off-by: Carsten Haitzler <carsten.haitzler@arm.com>
>> ---
>>   drivers/gpu/drm/arm/display/komeda/d71/d71_component.c | 7 ++++++-
>>   drivers/gpu/drm/arm/display/komeda/d71/d71_regs.h      | 1 +
>>   2 files changed, 7 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/gpu/drm/arm/display/komeda/d71/d71_component.c b/drivers/gpu/drm/arm/display/komeda/d71/d71_component.c
>> index 8a02ade369db..e97acc5519d1 100644
>> --- a/drivers/gpu/drm/arm/display/komeda/d71/d71_component.c
>> +++ b/drivers/gpu/drm/arm/display/komeda/d71/d71_component.c
>> @@ -468,7 +468,12 @@ static void d71_wb_layer_update(struct komeda_component *c,
>>   	struct komeda_layer_state *st = to_layer_st(state);
>>   	struct drm_connector_state *conn_st = state->wb_conn->state;
>>   	struct komeda_fb *kfb = to_kfb(conn_st->writeback_job->fb);
>> -	u32 ctrl = L_EN | LW_OFM, mask = L_EN | LW_OFM | LW_TBU_EN;
>> +	/* LW_TRC sets rounding to truncate not round which is needed for
>> +	 * the output of writeback to match the input in the most common
>> +	 * use cases like RGB888 -> RGB888, so set this bit by default
>> +	 */
> 
> Hm, not sure why this file uses "net/" style comments, but as you
> said, this is in-keeping with the rest of the file, so meh :-)

Yup. Just stick to "follow the style there" unless there is seemingly a 
good reason that what is there is horribly "broken" and needs fixing up.

>> +	u32 ctrl = LW_TRC | L_EN | LW_OFM;
>> +	u32 mask = LW_TRC | L_EN | LW_OFM | LW_TBU_EN;
> 
> If you were aiming for matching register order, this should be:
> 
>      L_EN | LW_TRC | LW_OFM | LW_TBU_EN
> 
> 
> I think it'd be nice to have the exact behaviour in the commit
> message, but either way this seems OK as a pragmatic fix so:

git log -U ? :)

> Reviewed-by: Brian Starkey <brian.starkey@arm.com>
> 
> Thanks,
> -Brian
> 
>>   	u32 __iomem *reg = c->reg;
>>   
>>   	d71_layer_update_fb(c, kfb, st->addr);
>> diff --git a/drivers/gpu/drm/arm/display/komeda/d71/d71_regs.h b/drivers/gpu/drm/arm/display/komeda/d71/d71_regs.h
>> index e80172a0b320..a8036689d721 100644
>> --- a/drivers/gpu/drm/arm/display/komeda/d71/d71_regs.h
>> +++ b/drivers/gpu/drm/arm/display/komeda/d71/d71_regs.h
>> @@ -321,6 +321,7 @@
>>   #define LAYER_WR_FORMAT		0x0D8
>>   
>>   /* Layer_WR control bits */
>> +#define LW_TRC			BIT(1)
>>   #define LW_OFM			BIT(4)
>>   #define LW_LALPHA(x)		(((x) & 0xFF) << 8)
>>   #define LW_A_WCACHE(x)		(((x) & 0xF) << 28)
>> -- 
>> 2.30.0
>>
>> _______________________________________________
>> dri-devel mailing list
>> dri-devel@lists.freedesktop.org
>> https://lists.freedesktop.org/mailman/listinfo/dri-devel
> _______________________________________________
> dri-devel mailing list
> dri-devel@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/dri-devel
> 

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

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

* Re: [PATCH] drm/komeda: Fix off-by-1 when with readback conn due to rounding
  2021-03-09 11:36 ` Brian Starkey
@ 2021-03-11 11:55   ` Carsten Haitzler
  0 siblings, 0 replies; 7+ messages in thread
From: Carsten Haitzler @ 2021-03-11 11:55 UTC (permalink / raw)
  To: Brian Starkey, james.qian.wang
  Cc: nd, liviu.dudau, Carsten Haitzler, dri-devel, steven.price

On 3/9/21 11:36 AM, Brian Starkey wrote:
> Hi Carsten, (+James for komeda)
> 
> Thanks for typing this up.
> 
> On Fri, Mar 05, 2021 at 04:38:53PM +0000, carsten.haitzler@foss.arm.com wrote:
>> From: Carsten Haitzler <carsten.haitzler@arm.com>
>>
>> When setting up a readback conenctor that writes data back to memory
> 
> s/readback conenctor/writeback connector/ (similar in the subject)
> 
>> rather than to an actual output device (HDMI etc.), rounding was ses
> 
> s/ses/set/

I swear I re-read the log text... I must be auto-correcting in my head 
as I read. :)

>> to round-down. As the DPU uses a higher internal number of bits when
> 
> "round-down" isn't really accurate - the rounding mode "rounds" based
> on the most-significant discarded bit - so can round-up too.
> 
> Come to think of it, I can't explain 0xff becoming 0xfe, but still,
> truncation is likely fine.

Actually it was the other way - I mixed up the src/dest, but TRC does 
fix it which is the important bit.

>> generating a color value, this round-down back to 8bit ended up with
>> everything being off-by one. e.g. #ffffff became #fefefe. This sets
>> rounding to "round" so things end up correct by turning on the round
>> flag (LW_TRC).
> 
> LW_TRC is the truncation flag. 0: Round, 1: Truncate
> 
>>
>> Signed-off-by: Carsten Haitzler <carsten.haitzler@arm.com>
>> ---
>>   drivers/gpu/drm/arm/display/komeda/d71/d71_component.c | 6 +++++-
>>   drivers/gpu/drm/arm/display/komeda/d71/d71_regs.h      | 1 +
>>   2 files changed, 6 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/gpu/drm/arm/display/komeda/d71/d71_component.c b/drivers/gpu/drm/arm/display/komeda/d71/d71_component.c
>> index 8a02ade369db..d551e79fa0f1 100644
>> --- a/drivers/gpu/drm/arm/display/komeda/d71/d71_component.c
>> +++ b/drivers/gpu/drm/arm/display/komeda/d71/d71_component.c
>> @@ -468,7 +468,11 @@ static void d71_wb_layer_update(struct komeda_component *c,
>>   	struct komeda_layer_state *st = to_layer_st(state);
>>   	struct drm_connector_state *conn_st = state->wb_conn->state;
>>   	struct komeda_fb *kfb = to_kfb(conn_st->writeback_job->fb);
>> -	u32 ctrl = L_EN | LW_OFM, mask = L_EN | LW_OFM | LW_TBU_EN;
>> +	/* LW_TRC sets rounding to round not truncate which is needed for
>> +         * the output of writeback to match the input in the most common
>> +         * use cases like RGB888 -> RGB888, so set this bit by default */
> 
> /*
>   * Comment style should be like this
>   */
> 
> Same as above though - your description is inverted. By setting the
> LW_TRC bit, you're forcing the hardware to truncate instead of round.

Yeah - inverted. But the source does have mixed comment styles with some
/*
  * xxxx
  */

and some

/* xxxx */

and some

/* xxxx
  */

with the last 2 most common.

>> +	u32 ctrl = L_EN | LW_OFM | LW_TRC;
>> +	u32 mask = L_EN | LW_OFM | LW_TBU_EN | LW_TRC;
> 
> Really nitpicking, but I think it'd be good to keep these in the same
> order as the bits in the register: L_EN | LW_TRC | LW_OFM | LW_TBU_EN

I can do that. I'll send another with the above.

> Cheers,
> -Brian
> 
>>   	u32 __iomem *reg = c->reg;
>>   
>>   	d71_layer_update_fb(c, kfb, st->addr);
>> diff --git a/drivers/gpu/drm/arm/display/komeda/d71/d71_regs.h b/drivers/gpu/drm/arm/display/komeda/d71/d71_regs.h
>> index e80172a0b320..a8036689d721 100644
>> --- a/drivers/gpu/drm/arm/display/komeda/d71/d71_regs.h
>> +++ b/drivers/gpu/drm/arm/display/komeda/d71/d71_regs.h
>> @@ -321,6 +321,7 @@
>>   #define LAYER_WR_FORMAT		0x0D8
>>   
>>   /* Layer_WR control bits */
>> +#define LW_TRC			BIT(1)
>>   #define LW_OFM			BIT(4)
>>   #define LW_LALPHA(x)		(((x) & 0xFF) << 8)
>>   #define LW_A_WCACHE(x)		(((x) & 0xF) << 28)
>> -- 
>> 2.30.0
>>
>> _______________________________________________
>> dri-devel mailing list
>> dri-devel@lists.freedesktop.org
>> https://lists.freedesktop.org/mailman/listinfo/dri-devel

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

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

* Re: [PATCH] drm/komeda: Fix off-by-1 when with readback conn due to rounding
  2021-03-05 16:38 carsten.haitzler
@ 2021-03-09 11:36 ` Brian Starkey
  2021-03-11 11:55   ` Carsten Haitzler
  0 siblings, 1 reply; 7+ messages in thread
From: Brian Starkey @ 2021-03-09 11:36 UTC (permalink / raw)
  To: carsten.haitzler, james.qian.wang
  Cc: nd, liviu.dudau, Carsten Haitzler, dri-devel, steven.price

Hi Carsten, (+James for komeda)

Thanks for typing this up.

On Fri, Mar 05, 2021 at 04:38:53PM +0000, carsten.haitzler@foss.arm.com wrote:
> From: Carsten Haitzler <carsten.haitzler@arm.com>
> 
> When setting up a readback conenctor that writes data back to memory

s/readback conenctor/writeback connector/ (similar in the subject)

> rather than to an actual output device (HDMI etc.), rounding was ses

s/ses/set/

> to round-down. As the DPU uses a higher internal number of bits when

"round-down" isn't really accurate - the rounding mode "rounds" based
on the most-significant discarded bit - so can round-up too.

Come to think of it, I can't explain 0xff becoming 0xfe, but still,
truncation is likely fine.

> generating a color value, this round-down back to 8bit ended up with
> everything being off-by one. e.g. #ffffff became #fefefe. This sets
> rounding to "round" so things end up correct by turning on the round
> flag (LW_TRC).

LW_TRC is the truncation flag. 0: Round, 1: Truncate

> 
> Signed-off-by: Carsten Haitzler <carsten.haitzler@arm.com>
> ---
>  drivers/gpu/drm/arm/display/komeda/d71/d71_component.c | 6 +++++-
>  drivers/gpu/drm/arm/display/komeda/d71/d71_regs.h      | 1 +
>  2 files changed, 6 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/gpu/drm/arm/display/komeda/d71/d71_component.c b/drivers/gpu/drm/arm/display/komeda/d71/d71_component.c
> index 8a02ade369db..d551e79fa0f1 100644
> --- a/drivers/gpu/drm/arm/display/komeda/d71/d71_component.c
> +++ b/drivers/gpu/drm/arm/display/komeda/d71/d71_component.c
> @@ -468,7 +468,11 @@ static void d71_wb_layer_update(struct komeda_component *c,
>  	struct komeda_layer_state *st = to_layer_st(state);
>  	struct drm_connector_state *conn_st = state->wb_conn->state;
>  	struct komeda_fb *kfb = to_kfb(conn_st->writeback_job->fb);
> -	u32 ctrl = L_EN | LW_OFM, mask = L_EN | LW_OFM | LW_TBU_EN;
> +	/* LW_TRC sets rounding to round not truncate which is needed for
> +         * the output of writeback to match the input in the most common
> +         * use cases like RGB888 -> RGB888, so set this bit by default */

/*
 * Comment style should be like this
 */

Same as above though - your description is inverted. By setting the
LW_TRC bit, you're forcing the hardware to truncate instead of round.

> +	u32 ctrl = L_EN | LW_OFM | LW_TRC;
> +	u32 mask = L_EN | LW_OFM | LW_TBU_EN | LW_TRC;

Really nitpicking, but I think it'd be good to keep these in the same
order as the bits in the register: L_EN | LW_TRC | LW_OFM | LW_TBU_EN

Cheers,
-Brian

>  	u32 __iomem *reg = c->reg;
>  
>  	d71_layer_update_fb(c, kfb, st->addr);
> diff --git a/drivers/gpu/drm/arm/display/komeda/d71/d71_regs.h b/drivers/gpu/drm/arm/display/komeda/d71/d71_regs.h
> index e80172a0b320..a8036689d721 100644
> --- a/drivers/gpu/drm/arm/display/komeda/d71/d71_regs.h
> +++ b/drivers/gpu/drm/arm/display/komeda/d71/d71_regs.h
> @@ -321,6 +321,7 @@
>  #define LAYER_WR_FORMAT		0x0D8
>  
>  /* Layer_WR control bits */
> +#define LW_TRC			BIT(1)
>  #define LW_OFM			BIT(4)
>  #define LW_LALPHA(x)		(((x) & 0xFF) << 8)
>  #define LW_A_WCACHE(x)		(((x) & 0xF) << 28)
> -- 
> 2.30.0
> 
> _______________________________________________
> dri-devel mailing list
> dri-devel@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/dri-devel
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

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

* [PATCH] drm/komeda: Fix off-by-1 when with readback conn due to rounding
@ 2021-03-05 16:38 carsten.haitzler
  2021-03-09 11:36 ` Brian Starkey
  0 siblings, 1 reply; 7+ messages in thread
From: carsten.haitzler @ 2021-03-05 16:38 UTC (permalink / raw)
  To: dri-devel; +Cc: liviu.dudau, Carsten Haitzler, steven.price

From: Carsten Haitzler <carsten.haitzler@arm.com>

When setting up a readback conenctor that writes data back to memory
rather than to an actual output device (HDMI etc.), rounding was ses
to round-down. As the DPU uses a higher internal number of bits when
generating a color value, this round-down back to 8bit ended up with
everything being off-by one. e.g. #ffffff became #fefefe. This sets
rounding to "round" so things end up correct by turning on the round
flag (LW_TRC).

Signed-off-by: Carsten Haitzler <carsten.haitzler@arm.com>
---
 drivers/gpu/drm/arm/display/komeda/d71/d71_component.c | 6 +++++-
 drivers/gpu/drm/arm/display/komeda/d71/d71_regs.h      | 1 +
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/arm/display/komeda/d71/d71_component.c b/drivers/gpu/drm/arm/display/komeda/d71/d71_component.c
index 8a02ade369db..d551e79fa0f1 100644
--- a/drivers/gpu/drm/arm/display/komeda/d71/d71_component.c
+++ b/drivers/gpu/drm/arm/display/komeda/d71/d71_component.c
@@ -468,7 +468,11 @@ static void d71_wb_layer_update(struct komeda_component *c,
 	struct komeda_layer_state *st = to_layer_st(state);
 	struct drm_connector_state *conn_st = state->wb_conn->state;
 	struct komeda_fb *kfb = to_kfb(conn_st->writeback_job->fb);
-	u32 ctrl = L_EN | LW_OFM, mask = L_EN | LW_OFM | LW_TBU_EN;
+	/* LW_TRC sets rounding to round not truncate which is needed for
+         * the output of writeback to match the input in the most common
+         * use cases like RGB888 -> RGB888, so set this bit by default */
+	u32 ctrl = L_EN | LW_OFM | LW_TRC;
+	u32 mask = L_EN | LW_OFM | LW_TBU_EN | LW_TRC;
 	u32 __iomem *reg = c->reg;
 
 	d71_layer_update_fb(c, kfb, st->addr);
diff --git a/drivers/gpu/drm/arm/display/komeda/d71/d71_regs.h b/drivers/gpu/drm/arm/display/komeda/d71/d71_regs.h
index e80172a0b320..a8036689d721 100644
--- a/drivers/gpu/drm/arm/display/komeda/d71/d71_regs.h
+++ b/drivers/gpu/drm/arm/display/komeda/d71/d71_regs.h
@@ -321,6 +321,7 @@
 #define LAYER_WR_FORMAT		0x0D8
 
 /* Layer_WR control bits */
+#define LW_TRC			BIT(1)
 #define LW_OFM			BIT(4)
 #define LW_LALPHA(x)		(((x) & 0xFF) << 8)
 #define LW_A_WCACHE(x)		(((x) & 0xF) << 28)
-- 
2.30.0

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

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

end of thread, other threads:[~2021-03-29 15:27 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-11 12:08 [PATCH] drm/komeda: Fix off-by-1 when with readback conn due to rounding carsten.haitzler
2021-03-12 10:55 ` Brian Starkey
2021-03-16  3:17   ` James Qian Wang
2021-03-29 15:27   ` Carsten Haitzler
  -- strict thread matches above, loose matches on Subject: below --
2021-03-05 16:38 carsten.haitzler
2021-03-09 11:36 ` Brian Starkey
2021-03-11 11:55   ` Carsten Haitzler

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.