drm/komeda: Fix off-by-1 when with readback conn due to rounding
Subsystems (4)
PATCH 1/1 drm/komeda: Fix off-by-1 when with readback conn due to rounding
From: Carsten Haitzler <[email protected]>
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.
--- 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(-)
drivers/gpu/drm/arm/display/komeda/d71/d71_component.c +6 -1
@@ -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);
drivers/gpu/drm/arm/display/komeda/d71/d71_regs.h +1 -0
@@ -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)
Signature · 6 lines
2.30.0 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
(Adding back James again - did you use get_maintainer.pl?)
Quoted 7 lines · On Thu, Mar 11, 2021 at 12:08:46PM +0000, [email protected] wrote:
From: Carsten Haitzler <[email protected]>
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.
Quoted 2 lines
rounding to "round-down" so things end up correct by turning on the
LW_TRCround down flag.
Can we call it "truncate" rather than round down? I think it makes "TRC" a bit more understandable.
Quoted 12 lines
Signed-off-by Carsten Haitzler <[email protected]>--- 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(-)drivers/gpu/drm/arm/display/komeda/d71/d71_component.c +0
-0
drivers/gpu/drm/arm/display/komeda/d71/d71_component.c static void d71_wb_layer_update(struct komeda_component *c, · line 474
Quoted 8 lines
drivers/gpu/drm/arm/display/komeda/d71/d71_component.c +4
-1@@ -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 :-)
drivers/gpu/drm/arm/display/komeda/d71/d71_component.c static void d71_wb_layer_update(struct komeda_component *c, · line 476
Quoted 2 lines
drivers/gpu/drm/arm/display/komeda/d71/d71_component.c +2
-0+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:
Thanks,
-Brian
Quoted 22 lines
drivers/gpu/drm/arm/display/komeda/d71/d71_component.c +0
-0u32 __iomem *reg = c->reg;d71_layer_update_fb (c, kfb, st->addr);drivers/gpu/drm/arm/display/komeda/d71/d71_regs.h +1
-0@@ -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)Signature · 6 lines
2.30.0 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
James Qian Wang
Acked-byQuoted 73 lines · Brian Starkey
(Adding back James again - did you use get_maintainer.pl?)
Quoted 7 lines · On Thu, Mar 11, 2021 at 12:08:46PM +0000, [email protected] wrote:
From: Carsten Haitzler <[email protected]>
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.
Quoted 2 lines
rounding to "round-down" so things end up correct by turning on the
LW_TRCround down flag.Can we call it "truncate" rather than round down? I think it makes "TRC" a bit more understandable.
Quoted 12 lines
Signed-off-by Carsten Haitzler <[email protected]>--- 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(-)drivers/gpu/drm/arm/display/komeda/d71/d71_component.c +0
-0drivers/gpu/drm/arm/display/komeda/d71/d71_component.c static void d71_wb_layer_update(struct komeda_component *c, · line 474
Quoted 8 lines
drivers/gpu/drm/arm/display/komeda/d71/d71_component.c +4
-1@@ -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 :-)drivers/gpu/drm/arm/display/komeda/d71/d71_component.c static void d71_wb_layer_update(struct komeda_component *c, · line 476
Quoted 2 lines
drivers/gpu/drm/arm/display/komeda/d71/d71_component.c +2
-0+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_ENI 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 <[email protected]>Thanks,
-BrianQuoted 10 lines
drivers/gpu/drm/arm/display/komeda/d71/d71_component.c +0
-0u32 __iomem *reg = c->reg;d71_layer_update_fb (c, kfb, st->addr);drivers/gpu/drm/arm/display/komeda/d71/d71_regs.h +0
-0@@ -321,6 +321,7 @@#define LAYER_WR_FORMAT 0x0D8
Quoted 8 lines
Quoted 8 lines
drivers/gpu/drm/arm/display/komeda/d71/d71_regs.h +1
-0/* 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)Signature · 1 line
2.30.0
Thanks
James
Quoted 4 lines
Quoted 4 lines
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Quoted 11 lines · Brian Starkey
(Adding back James again - did you use get_maintainer.pl?)
Quoted 7 lines · On Thu, Mar 11, 2021 at 12:08:46PM +0000, [email protected] wrote:
From: Carsten Haitzler <[email protected]>
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
Quoted 3 lines
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".
Quoted 8 lines
significant bit-to-be-discarded is set, the value is rounded up to minimise the absolute error introduced by bit-depth reduction.
Quoted 2 lines
rounding to "round-down" so things end up correct by turning on the
LW_TRCround 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...
Quoted 7 lines
Quoted 7 lines
Signed-off-by Carsten Haitzler <[email protected]>--- 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(-)
Quoted 16 lines
drivers/gpu/drm/arm/display/komeda/d71/d71_component.c static void d71_wb_layer_update(struct komeda_component *c, · line 474
Quoted 13 lines
drivers/gpu/drm/arm/display/komeda/d71/d71_component.c +4
-1@@ -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.
Quoted 10 lines
drivers/gpu/drm/arm/display/komeda/d71/d71_component.c static void d71_wb_layer_update(struct komeda_component *c, · line 476
Quoted 2 lines
drivers/gpu/drm/arm/display/komeda/d71/d71_component.c +2
-0+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_ENI 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 ? :)
Quoted 23 lines
Reviewed-by Brian Starkey <[email protected]>Thanks,
-BrianQuoted 18 lines
drivers/gpu/drm/arm/display/komeda/d71/d71_component.c +0
-0u32 __iomem *reg = c->reg;d71_layer_update_fb (c, kfb, st->addr);drivers/gpu/drm/arm/display/komeda/d71/d71_regs.h +1
-0@@ -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)Signature · 1 line
2.30.0
Quoted 9 lines
Quoted 4 lines
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel