drm/amd/display: fix flickering caused by S/G mode
PATCH 1/1 drm/amd/display: fix flickering caused by S/G mode
Currently, we allow the framebuffer for a given plane to move between memory domains, however when that happens it causes the screen to flicker, it is even possible for the framebuffer to change memory domains on every plane update (causing a continuous flicker effect). So, to fix this, don't perform an immediate flip in the aforementioned case.
--- .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 41 ++++++++++++++++++- 1 file changed, 39 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +39 -2
@@ -7897,6 +7897,34 @@ static void amdgpu_dm_commit_cursors(struct drm_atomic_state *state)amdgpu_dm_plane_handle_cursor_update (plane, old_plane_state); } +static inline uint32_t get_mem_type (struct amdgpu_device *adev, +struct drm_gem_object *obj, +bool check_domain) +{ +struct amdgpu_bo *abo =gem_to_amdgpu_bo (obj); +uint32_t mem_type; + +if (unlikely (amdgpu_bo_reserve (abo, true))) +return 0 ; + +if (unlikely (dma_resv_reserve_fences (abo->tbo.base.resv,1 ))) + goto err; + +if (check_domain && +amdgpu_display_supported_domains (adev, abo->flags) != + (AMDGPU_GEM_DOMAIN_VRAM |AMDGPU_GEM_DOMAIN_GTT )) + goto err; + + mem_type = abo->tbo.resource->mem_type; +amdgpu_bo_unreserve (abo); + +return mem_type; + +err: +amdgpu_bo_unreserve (abo); +return 0 ; +} + static void amdgpu_dm_commit_planes(struct drm_atomic_state *state, struct dc_state *dc_state, struct drm_device *dev,
@@ -7916,6 +7944,7 @@ static void amdgpu_dm_commit_planes(struct drm_atomic_state *state,to_dm_crtc_state (drm_atomic_get_old_crtc_state (state, pcrtc));int planes_count =0 , vpos, hpos;unsigned long flags; +uint32_t mem_type;u32 target_vblank, last_flip_vblank;bool vrr_active =amdgpu_dm_crtc_vrr_active (acrtc_state);bool cursor_update = false;
@@ -8035,13 +8064,21 @@ static void amdgpu_dm_commit_planes(struct drm_atomic_state *state, } } + mem_type =get_mem_type (dm->adev, old_plane_state->fb->obj[0 ], + true); +/* * Only allow immediate flips for fast updates that don't -* change FB pitch, DCC state, rotation or mirroing. +* change memory domain, FB pitch, DCC state, rotation or +* mirroring. */ bundle->flip_addrs[planes_count].flip_immediate = crtc->state->async_flip && - acrtc_state->update_type ==UPDATE_TYPE_FAST ; + acrtc_state->update_type ==UPDATE_TYPE_FAST && + (!mem_type || (mem_type &&get_mem_type (dm->adev, + fb->obj[0 ], + false) == + mem_type)); timestamp_ns =ktime_get_ns (); bundle->flip_addrs[planes_count].flip_timestamp_in_us =div_u64 (timestamp_ns,1000 );
Signature · 1 line
2.40.0
Christian König
maintainerAm 14.04.23 um 21:33 schrieb Hamza Mahfooz:
Quoted 5 lines
Currently, we allow the framebuffer for a given plane to move between memory domains, however when that happens it causes the screen to flicker, it is even possible for the framebuffer to change memory domains on every plane update (causing a continuous flicker effect). So, to fix this, don't perform an immediate flip in the aforementioned case.
That sounds strongly like you just forget to wait for the move to finish!
What is the order of things done here? E.g. who calls amdgpu_bo_pin() and who waits for fences for finish signaling? Is that maybe just in the wrong order?
Regards,
Christian.
Quoted 79 lines
Fixes 81d0bcf99009 ("drm/amdgpu: make display pinning more flexible (v2)")Signed-off-by Hamza Mahfooz <[email protected]>--- .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 41 ++++++++++++++++++- 1 file changed, 39 insertions(+), 2 deletions(-)drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +39
-2@@ -7897,6 +7897,34 @@ static void amdgpu_dm_commit_cursors(struct drm_atomic_state *state)amdgpu_dm_plane_handle_cursor_update (plane, old_plane_state); } +static inline uint32_t get_mem_type (struct amdgpu_device *adev, +struct drm_gem_object *obj, +bool check_domain) +{ +struct amdgpu_bo *abo =gem_to_amdgpu_bo (obj); +uint32_t mem_type; + +if (unlikely (amdgpu_bo_reserve (abo, true))) +return 0 ; + +if (unlikely (dma_resv_reserve_fences (abo->tbo.base.resv,1 ))) + goto err; + +if (check_domain && +amdgpu_display_supported_domains (adev, abo->flags) != + (AMDGPU_GEM_DOMAIN_VRAM |AMDGPU_GEM_DOMAIN_GTT )) + goto err; + + mem_type = abo->tbo.resource->mem_type; +amdgpu_bo_unreserve (abo); + +return mem_type; + +err: +amdgpu_bo_unreserve (abo); +return 0 ; +} + static void amdgpu_dm_commit_planes(struct drm_atomic_state *state, struct dc_state *dc_state, struct drm_device *dev,@@ -7916,6 +7944,7 @@ static void amdgpu_dm_commit_planes(struct drm_atomic_state *state,to_dm_crtc_state (drm_atomic_get_old_crtc_state (state, pcrtc));int planes_count =0 , vpos, hpos;unsigned long flags; +uint32_t mem_type;u32 target_vblank, last_flip_vblank;bool vrr_active =amdgpu_dm_crtc_vrr_active (acrtc_state);bool cursor_update = false;@@ -8035,13 +8064,21 @@ static void amdgpu_dm_commit_planes(struct drm_atomic_state *state, } } + mem_type =get_mem_type (dm->adev, old_plane_state->fb->obj[0 ], + true); +/* * Only allow immediate flips for fast updates that don't -* change FB pitch, DCC state, rotation or mirroing. +* change memory domain, FB pitch, DCC state, rotation or +* mirroring. */ bundle->flip_addrs[planes_count].flip_immediate = crtc->state->async_flip && - acrtc_state->update_type ==UPDATE_TYPE_FAST ; + acrtc_state->update_type ==UPDATE_TYPE_FAST && + (!mem_type || (mem_type &&get_mem_type (dm->adev, + fb->obj[0 ], + false) == + mem_type)); timestamp_ns =ktime_get_ns (); bundle->flip_addrs[planes_count].flip_timestamp_in_us =div_u64 (timestamp_ns,1000 );
Quoted 10 lines · Christian König
Am 14.04.23 um 21:33 schrieb Hamza Mahfooz:
Quoted 5 lines
Currently, we allow the framebuffer for a given plane to move between memory domains, however when that happens it causes the screen to flicker, it is even possible for the framebuffer to change memory domains on every plane update (causing a continuous flicker effect). So, to fix this, don't perform an immediate flip in the aforementioned case.
That sounds strongly like you just forget to wait for the move to finish!
What is the order of things done here? E.g. who calls
amdgpu_bo_pin()and who waits for fences for finish signaling? Is that maybe just in the wrong order?
The pinning logic is in dm_plane_helper_prepare_fb(). Also, it seems like we wait for the fences in amdgpu_dm_atomic_commit_tail(), using drm_atomic_helper_wait_for_fences(). The ordering should be fine as well, since prepare_fb() is always called before atomic_commit_tail().
Quoted 84 lines
Regards,
Christian.Quoted 79 lines
Fixes 81d0bcf99009 ("drm/amdgpu: make display pinning more flexible (v2)")Signed-off-by Hamza Mahfooz <[email protected]>---
.../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c| 41 ++++++++++++++++++-1 file changed, 39 insertions(+), 2 deletions(-)drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +29
-0@@ -7897,6 +7897,34 @@ static void amdgpu_dm_commit_cursors(struct drm_atomic_state *state) amdgpu_dm_plane_handle_cursor_update(plane, old_plane_state); } +static inline uint32_t get_mem_type (struct amdgpu_device *adev, + struct drm_gem_object *obj, + bool check_domain) +{ + struct amdgpu_bo *abo = gem_to_amdgpu_bo(obj); + uint32_t mem_type; + + if (unlikely(amdgpu_bo_reserve(abo, true))) + return 0; + + if (unlikely(dma_resv_reserve_fences(abo->tbo.base.resv, 1))) + goto err; + + if (check_domain && + amdgpu_display_supported_domains(adev, abo->flags) != + (AMDGPU_GEM_DOMAIN_VRAM | AMDGPU_GEM_DOMAIN_GTT)) + goto err; + + mem_type = abo->tbo.resource->mem_type; + amdgpu_bo_unreserve(abo); + + return mem_type; + +err: + amdgpu_bo_unreserve(abo); + return 0; +} + static void amdgpu_dm_commit_planes(struct drm_atomic_state *state, struct dc_state *dc_state, struct drm_device *dev,@@ -7916,6 +7944,7 @@ static void amdgpu_dm_commit_planes(structdrm_atomic_state *state, to_dm_crtc_state(drm_atomic_get_old_crtc_state(state, pcrtc)); int planes_count = 0, vpos, hpos; unsigned long flags; + uint32_t mem_type; u32 target_vblank, last_flip_vblank; bool vrr_active = amdgpu_dm_crtc_vrr_active(acrtc_state);bool
cursor_update= false;drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +5
-1@@ -8035,13 +8064,21 @@ static void amdgpu_dm_commit_planes(structdrm_atomic_state *state, } } + mem_type = get_mem_type(dm->adev, old_plane_state->fb->obj[0], + true); + /** Only allow immediate flips for fast updates that don't -* change FB pitch, DCC state, rotation or mirroing. +* change memory domain, FB pitch, DCC state, rotation or +* mirroring. */ bundle->flip_addrs[planes_count].flip_immediate =
crtc->state->async_flip&&
-acrtc_state->update_type==UPDATE_TYPE_FAST;
+acrtc_state->update_type==UPDATE_TYPE_FAST&&
+ (!mem_type || (mem_type&& get_mem_type(dm->adev,
+ fb->obj[0],
+ false) ==
+mem_type));
timestamp_ns=ktime_get_ns(); bundle->flip_addrs[planes_count].flip_timestamp_in_us =div_u64(timestamp_ns, 1000);
Signature · 1 line
Hamza
Christian König
maintainerAm 17.04.23 um 16:51 schrieb Hamza Mahfooz:
Quoted 9 lines · Christian König
Quoted 7 lines
Am 14.04.23 um 21:33 schrieb Hamza Mahfooz:
Quoted 5 lines
Currently, we allow the framebuffer for a given plane to move between memory domains, however when that happens it causes the screen to flicker, it is even possible for the framebuffer to change memory domains on every plane update (causing a continuous flicker effect). So, to fix this, don't perform an immediate flip in the aforementioned case.
Quoted 8 lines
Quoted 3 lines
That sounds strongly like you just forget to wait for the move to finish!
What is the order of things done here? E.g. who calls
amdgpu_bo_pin()and who waits for fences for finish signaling? Is that maybe just in the wrong order?The pinning logic is in
dm_plane_helper_prepare_fb(). Also, it seems like we wait for the fences inamdgpu_dm_atomic_commit_tail(), usingdrm_atomic_helper_wait_for_fences(). The ordering should be fine as well, sinceprepare_fb()is always called beforeatomic_commit_tail().
Ok, then why is there any flickering?
BTW reserving a fence slot is completely unnecessary. That looks like you copy&pasted the code from somewhere else without checking what it actually does.
Regards,
Christian.
Quoted 86 lines
Quoted 86 lines
Regards,
Christian.Quoted 80 lines
Fixes 81d0bcf99009 ("drm/amdgpu: make display pinning more flexible (v2)")Signed-off-by Hamza Mahfooz <[email protected]>---
.../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c| 41
++++++++++++++++++-1 file changed, 39 insertions(+), 2 deletions(-)drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +29
-0@@ -7897,6 +7897,34 @@ static void amdgpu_dm_commit_cursors(struct drm_atomic_state *state) amdgpu_dm_plane_handle_cursor_update(plane, old_plane_state); } +static inline uint32_t get_mem_type (struct amdgpu_device *adev, + struct drm_gem_object *obj, + bool check_domain) +{ + struct amdgpu_bo *abo = gem_to_amdgpu_bo(obj); + uint32_t mem_type; + + if (unlikely(amdgpu_bo_reserve(abo, true))) + return 0; + + if (unlikely(dma_resv_reserve_fences(abo->tbo.base.resv, 1))) + goto err; + + if (check_domain && + amdgpu_display_supported_domains(adev, abo->flags) != + (AMDGPU_GEM_DOMAIN_VRAM | AMDGPU_GEM_DOMAIN_GTT)) + goto err; + + mem_type = abo->tbo.resource->mem_type; + amdgpu_bo_unreserve(abo); + + return mem_type; + +err: + amdgpu_bo_unreserve(abo); + return 0; +} + static void amdgpu_dm_commit_planes(struct drm_atomic_state *state, struct dc_state *dc_state, struct drm_device *dev,@@ -7916,6 +7944,7 @@ static void amdgpu_dm_commit_planes(structdrm_atomic_state *state,to_dm_crtc_state (drm_atomic_get_old_crtc_state (state ,pcrtc )); int planes_count = 0, vpos, hpos; unsigned long flags; + uint32_t mem_type; u32 target_vblank, last_flip_vblank; bool vrr_active = amdgpu_dm_crtc_vrr_active(acrtc_state);bool
cursor_update= false;drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +5
-1@@ -8035,13 +8064,21 @@ static void amdgpu_dm_commit_planes(structdrm_atomic_state *state, } } + mem_type = get_mem_type(dm->adev, old_plane_state->fb->obj[0], + true); + /** Only allow immediate flips for fast updates that don't -* change FB pitch, DCC state, rotation or mirroing. +* change memory domain, FB pitch, DCC state, rotation or +* mirroring. */ bundle->flip_addrs[planes_count].flip_immediate =
crtc->state->async_flip&&
-acrtc_state->update_type==UPDATE_TYPE_FAST;
+acrtc_state->update_type==UPDATE_TYPE_FAST&&
+ (!mem_type || (mem_type&& get_mem_type(dm->adev,
+ fb->obj[0],
+ false) ==
+mem_type));
timestamp_ns=ktime_get_ns(); bundle->flip_addrs[planes_count].flip_timestamp_in_us =div_u64(timestamp_ns, 1000);
Quoted 14 lines · Christian König
Am 17.04.23 um 16:51 schrieb Hamza Mahfooz:
Quoted 13 lines · Christian König
Quoted 10 lines
Am 14.04.23 um 21:33 schrieb Hamza Mahfooz:
Quoted 5 lines
Currently, we allow the framebuffer for a given plane to move between memory domains, however when that happens it causes the screen to flicker, it is even possible for the framebuffer to change memory domains on every plane update (causing a continuous flicker effect). So, to fix this, don't perform an immediate flip in the aforementioned case.
That sounds strongly like you just forget to wait for the move to finish!
What is the order of things done here? E.g. who calls
amdgpu_bo_pin()and who waits for fences for finish signaling? Is that maybe just in the wrong order?
Quoted 8 lines
Quoted 4 lines
The pinning logic is in
dm_plane_helper_prepare_fb(). Also, it seems like we wait for the fences inamdgpu_dm_atomic_commit_tail(), usingdrm_atomic_helper_wait_for_fences(). The ordering should be fine as well, sinceprepare_fb()is always called beforeatomic_commit_tail().Ok, then why is there any flickering?
BTW reserving a fence slot is completely unnecessary. That looks like you copy&pasted the code from somewhere else without checking what it actually does.
It seemed like it was necessary to read tbo.resource since the documentation for struct ttm_buffer_object makes mention of a "bo::resv::reserved" lock.
Quoted 91 lines
Regards,
Christian.Quoted 86 lines
Quoted 86 lines
Regards,
Christian.Quoted 80 lines
Fixes 81d0bcf99009 ("drm/amdgpu: make display pinning more flexible (v2)")Signed-off-by Hamza Mahfooz <[email protected]>---
.../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c| 41
++++++++++++++++++-1 file changed, 39 insertions(+), 2 deletions(-)drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +29
-0@@ -7897,6 +7897,34 @@ static void amdgpu_dm_commit_cursors(struct drm_atomic_state *state) amdgpu_dm_plane_handle_cursor_update(plane, old_plane_state); } +static inline uint32_t get_mem_type (struct amdgpu_device *adev, + struct drm_gem_object *obj, + bool check_domain) +{ + struct amdgpu_bo *abo = gem_to_amdgpu_bo(obj); + uint32_t mem_type; + + if (unlikely(amdgpu_bo_reserve(abo, true))) + return 0; + + if (unlikely(dma_resv_reserve_fences(abo->tbo.base.resv, 1))) + goto err; + + if (check_domain && + amdgpu_display_supported_domains(adev, abo->flags) != + (AMDGPU_GEM_DOMAIN_VRAM | AMDGPU_GEM_DOMAIN_GTT)) + goto err; + + mem_type = abo->tbo.resource->mem_type; + amdgpu_bo_unreserve(abo); + + return mem_type; + +err: + amdgpu_bo_unreserve(abo); + return 0; +} + static void amdgpu_dm_commit_planes(struct drm_atomic_state *state, struct dc_state *dc_state, struct drm_device *dev,@@ -7916,6 +7944,7 @@ static void amdgpu_dm_commit_planes(structdrm_atomic_state *state,to_dm_crtc_state (drm_atomic_get_old_crtc_state (state ,pcrtc )); int planes_count = 0, vpos, hpos; unsigned long flags; + uint32_t mem_type; u32 target_vblank, last_flip_vblank; bool vrr_active = amdgpu_dm_crtc_vrr_active(acrtc_state);bool
cursor_update= false;drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +5
-1@@ -8035,13 +8064,21 @@ static void amdgpu_dm_commit_planes(structdrm_atomic_state *state, } } + mem_type = get_mem_type(dm->adev, old_plane_state->fb->obj[0], + true); + /** Only allow immediate flips for fast updates that don't -* change FB pitch, DCC state, rotation or mirroing. +* change memory domain, FB pitch, DCC state, rotation or +* mirroring. */ bundle->flip_addrs[planes_count].flip_immediate =
crtc->state->async_flip&&
-acrtc_state->update_type==UPDATE_TYPE_FAST;
+acrtc_state->update_type==UPDATE_TYPE_FAST&&
+ (!mem_type || (mem_type&& get_mem_type(dm->adev,
+ fb->obj[0],
+ false) ==
+mem_type));
timestamp_ns=ktime_get_ns(); bundle->flip_addrs[planes_count].flip_timestamp_in_us =div_u64(timestamp_ns, 1000);
Signature · 1 line
Hamza
[AMD Official Use Only - General]
Hi,
The change applies to all AMD GPU ASIC.
Please communicate with issue reporter to see if the issue could be reproduced older ASIC, like Mendocino, CZN.
Thanks!
Hersen
-----Original Message-----
From: Mahfooz, Hamza <[email protected]>
Sent: Monday, April 17, 2023 11:26 AM
To: Koenig, Christian <[email protected]>; [email protected]
Cc: [email protected]; Wentland, Harry <[email protected]>; Li, Sun peng (Leo) <[email protected]>; Siqueira, Rodrigo <[email protected]>; Deucher, Alexander <[email protected]>; Pan, Xinhui <[email protected]>; David Airlie <[email protected]>; Daniel Vetter <[email protected]>; Pillai, Aurabindo <[email protected]>; Zhuo, Qingqing (Lillian) <[email protected]>; Hans de Goede <[email protected]>; Wu, Hersen <[email protected]>; Wang, Chao-kai (Stylon) <[email protected]>; Tuikov, Luben <[email protected]>; [email protected]; [email protected]
Subject: Re: [PATCH] drm/amd/display: fix flickering caused by S/G mode
Quoted 24 lines · Christian König
Am 17.04.23 um 16:51 schrieb Hamza Mahfooz:
Quoted 14 lines · Christian König
Quoted 12 lines
Am 14.04.23 um 21:33 schrieb Hamza Mahfooz:
Quoted 7 lines
Currently, we allow the framebuffer for a given plane to move
between memory domains, however when that happens it causes the screen to flicker, it is even possible for the framebuffer to
change memory domains on every plane update (causing a continuous flicker effect). So,
to fix this, don't perform an immediate flip in the aforementioned case.That sounds strongly like you just forget to wait for the move to finish!
Quoted 8 lines
Quoted 3 lines
What is the order of things done here? E.g. who calls
amdgpu_bo_pin()and who waits for fences for finish signaling? Is that maybe just in the wrong order?The pinning logic is in
dm_plane_helper_prepare_fb(). Also, it seems like we wait for the fences inamdgpu_dm_atomic_commit_tail(), usingdrm_atomic_helper_wait_for_fences(). The ordering should be fine as well, sinceprepare_fb()is always called beforeatomic_commit_tail().
Quoted 5 lines
Ok, then why is there any flickering?
BTW reserving a fence slot is completely unnecessary. That looks like you copy&pasted the code from somewhere else without checking what it actually does.
It seemed like it was necessary to read tbo.resource since the documentation for struct ttm_buffer_object makes mention of a "bo::resv::reserved" lock.
Quoted 96 lines
Regards,
Christian.Quoted 91 lines
Quoted 91 lines
Regards,
Christian.Quoted 85 lines
Fixes 81d0bcf99009 ("drm/amdgpu: make display pinning moreflexible
(v2)")Signed-off-by Hamza Mahfooz <[email protected]>---
.../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c| 41
++++++++++++++++++-1 file changed, 39 insertions(+), 2 deletions(-)drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +27
-0@@ -7897,6 +7897,34 @@ static void amdgpu_dm_commit_cursors(struct drm_atomic_state *state) amdgpu_dm_plane_handle_cursor_update(plane,old_plane_state ); } +static inline uint32_t get_mem_type (struct amdgpu_device *adev, + struct drm_gem_object *obj, + bool check_domain) { + struct amdgpu_bo *abo = gem_to_amdgpu_bo(obj); + uint32_t mem_type; + + if (unlikely(amdgpu_bo_reserve(abo, true))) + return 0; + + if (unlikely(dma_resv_reserve_fences(abo->tbo.base.resv, 1))) + goto err; + + if (check_domain && + amdgpu_display_supported_domains(adev, abo->flags) != + (AMDGPU_GEM_DOMAIN_VRAM | AMDGPU_GEM_DOMAIN_GTT)) + goto err; + + mem_type = abo->tbo.resource->mem_type; + amdgpu_bo_unreserve(abo); + + return mem_type; + +err: + amdgpu_bo_unreserve(abo); + return 0; +} +static void amdgpu_dm_commit_planes(struct
drm_atomic_state*state,
structdc_state*dc_state,
structdrm_device*dev, @@ -7916,6 +7944,7 @@ static void amdgpu_dm_commit_planes(structdrm_atomic_state*state,to_dm_crtc_state(drm_atomic_get_old_crtc_state(state, pcrtc)); intplanes_count= 0, vpos, hpos;
unsigned long flags;
+uint32_tmem_type;
u32target_vblank,last_flip_vblank;
boolvrr_active=amdgpu_dm_crtc_vrr_active(acrtc_state); boolcursor_update= false;drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +6
-1@@ -8035,13 +8064,21 @@ static void amdgpu_dm_commit_planes(structdrm_atomic_state *state, } } + mem_type = get_mem_type(dm->adev, +old_plane_state->fb->obj[0 ], + true); + /** Only allow immediate flips for fast updates that don't -* change FB pitch, DCC state, rotation or mirroing. +* change memory domain, FB pitch, DCC state, rotation or +* mirroring. */ bundle->flip_addrs[planes_count].flip_immediate =
crtc->state->async_flip&&
-acrtc_state->update_type==UPDATE_TYPE_FAST; +acrtc_state->update_type==UPDATE_TYPE_FAST&& + (!mem_type || (mem_type&& get_mem_type(dm->adev, + fb->obj[0],
+ false) ==
+mem_type));
timestamp_ns=ktime_get_ns(); bundle->flip_addrs[planes_count].flip_timestamp_in_us =div_u64(timestamp_ns, 1000);
--
Hamza
Christian König
maintainerAm 17.04.23 um 17:25 schrieb Hamza Mahfooz:
Quoted 21 lines · Christian König
Quoted 19 lines
Am 17.04.23 um 16:51 schrieb Hamza Mahfooz:
Quoted 17 lines · Christian König
Quoted 10 lines
Am 14.04.23 um 21:33 schrieb Hamza Mahfooz:
Quoted 5 lines
Currently, we allow the framebuffer for a given plane to move between memory domains, however when that happens it causes the screen to flicker, it is even possible for the framebuffer to change memory domains on every plane update (causing a continuous flicker effect). So, to fix this, don't perform an immediate flip in the aforementioned case.
That sounds strongly like you just forget to wait for the move to finish!
What is the order of things done here? E.g. who calls
amdgpu_bo_pin()and who waits for fences for finish signaling? Is that maybe just in the wrong order?The pinning logic is in
dm_plane_helper_prepare_fb(). Also, it seems like we wait for the fences inamdgpu_dm_atomic_commit_tail(), usingdrm_atomic_helper_wait_for_fences(). The ordering should be fine as well, sinceprepare_fb()is always called beforeatomic_commit_tail().
Quoted 7 lines
Quoted 3 lines
Ok, then why is there any flickering?
BTW reserving a fence slot is completely unnecessary. That looks like you copy&pasted the code from somewhere else without checking what it actually does.
It seemed like it was necessary to read
tbo.resourcesince the documentation forstruct ttm_buffer_objectmakes mention of a "bo::resv::reserved" lock.
What? No, that sounds like you completely misunderstood that. I think we need to improve the documentation.
As long as the object is pinned for scanout you don't even need to reserve it.
Just use something like "abo->tbo.resource ? abo->tbo.resource->mem_type : 0" here.
Regards,
Christian.
Quoted 93 lines
Quoted 93 lines
Regards,
Christian.Quoted 87 lines
Quoted 87 lines
Regards,
Christian.Quoted 81 lines
Fixes 81d0bcf99009 ("drm/amdgpu: make display pinning more flexible (v2)")Signed-off-by Hamza Mahfooz <[email protected]>---
.../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c| 41
++++++++++++++++++-1 file changed, 39 insertions(+), 2 deletions(-)drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +29
-0@@ -7897,6 +7897,34 @@ static void amdgpu_dm_commit_cursors(struct drm_atomic_state *state) amdgpu_dm_plane_handle_cursor_update(plane, old_plane_state); } +static inline uint32_t get_mem_type (struct amdgpu_device *adev, + struct drm_gem_object *obj, + bool check_domain) +{ + struct amdgpu_bo *abo = gem_to_amdgpu_bo(obj); + uint32_t mem_type; + + if (unlikely(amdgpu_bo_reserve(abo, true))) + return 0; + + if (unlikely(dma_resv_reserve_fences(abo->tbo.base.resv, 1))) + goto err; + + if (check_domain && + amdgpu_display_supported_domains(adev, abo->flags) != + (AMDGPU_GEM_DOMAIN_VRAM | AMDGPU_GEM_DOMAIN_GTT)) + goto err; + + mem_type = abo->tbo.resource->mem_type; + amdgpu_bo_unreserve(abo); + + return mem_type; + +err: + amdgpu_bo_unreserve(abo); + return 0; +} + static void amdgpu_dm_commit_planes(struct drm_atomic_state *state, struct dc_state *dc_state, struct drm_device *dev,@@ -7916,6 +7944,7 @@ static void amdgpu_dm_commit_planes(structdrm_atomic_state *state,to_dm_crtc_state (drm_atomic_get_old_crtc_state (state ,pcrtc )); int planes_count = 0, vpos, hpos; unsigned long flags; + uint32_t mem_type; u32 target_vblank, last_flip_vblank; bool vrr_active = amdgpu_dm_crtc_vrr_active(acrtc_state);bool
cursor_update= false;drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +5
-1@@ -8035,13 +8064,21 @@ static void amdgpu_dm_commit_planes(structdrm_atomic_state *state, } } + mem_type = get_mem_type(dm->adev, old_plane_state->fb->obj[0 ], + true); + /** Only allow immediate flips for fast updates that don't -* change FB pitch, DCC state, rotation or mirroing. +* change memory domain, FB pitch, DCC state, rotation or +* mirroring. */ bundle->flip_addrs[planes_count].flip_immediate =
crtc->state->async_flip&&
-acrtc_state->update_type==UPDATE_TYPE_FAST;
+acrtc_state->update_type==UPDATE_TYPE_FAST&&
+ (!mem_type || (mem_type&& get_mem_type(dm->adev,
+ fb->obj[0],
+ false) ==
+mem_type));
timestamp_ns=ktime_get_ns(); bundle->flip_addrs[planes_count].flip_timestamp_in_us =div_u64(timestamp_ns, 1000);
Quoted 6 lines · Hersen
[AMD Official Use Only - General]
Hi,
The change applies to all AMD GPU ASIC.
Please communicate with issue reporter to see if the issue could be reproduced older ASIC, like Mendocino, CZN.
From the community reports, it can be reproduced on as far back as the Ryzen 4800H (which I guess is Renoir).
Quoted 144 lines
Thanks!
Hersen-----Original Message-----
From: Mahfooz, Hamza <[email protected]>
Sent: Monday, April 17, 2023 11:26 AM
To: Koenig, Christian <[email protected]>; [email protected]
Cc: [email protected]; Wentland, Harry <[email protected]>; Li, Sun peng (Leo) <[email protected]>; Siqueira, Rodrigo <[email protected]>; Deucher, Alexander <[email protected]>; Pan, Xinhui <[email protected]>; David Airlie <[email protected]>; Daniel Vetter <[email protected]>; Pillai, Aurabindo <[email protected]>; Zhuo, Qingqing (Lillian) <[email protected]>; Hans de Goede <[email protected]>; Wu, Hersen <[email protected]>; Wang, Chao-kai (Stylon) <[email protected]>; Tuikov, Luben <[email protected]>; [email protected]; [email protected]
Subject: Re: [PATCH] drm/amd/display: fix flickering caused by S/G modeQuoted 24 lines · Christian König
Am 17.04.23 um 16:51 schrieb Hamza Mahfooz:
Quoted 14 lines · Christian König
Quoted 12 lines
Am 14.04.23 um 21:33 schrieb Hamza Mahfooz:
Quoted 7 lines
Currently, we allow the framebuffer for a given plane to move
between memory domains, however when that happens it causes the screen to flicker, it is even possible for the framebuffer to
change memory domains on every plane update (causing a continuous flicker effect). So,
to fix this, don't perform an immediate flip in the aforementioned case.That sounds strongly like you just forget to wait for the move to finish!
Quoted 8 lines
Quoted 3 lines
What is the order of things done here? E.g. who calls
amdgpu_bo_pin()and who waits for fences for finish signaling? Is that maybe just in the wrong order?The pinning logic is in
dm_plane_helper_prepare_fb(). Also, it seems like we wait for the fences inamdgpu_dm_atomic_commit_tail(), usingdrm_atomic_helper_wait_for_fences(). The ordering should be fine as well, sinceprepare_fb()is always called beforeatomic_commit_tail().Quoted 5 lines
Ok, then why is there any flickering?
BTW reserving a fence slot is completely unnecessary. That looks like you copy&pasted the code from somewhere else without checking what it actually does.
It seemed like it was necessary to read
tbo.resourcesince the documentation forstruct ttm_buffer_objectmakes mention of a "bo::resv::reserved" lock.Quoted 96 lines
Regards,
Christian.Quoted 91 lines
Quoted 91 lines
Regards,
Christian.Quoted 85 lines
Fixes 81d0bcf99009 ("drm/amdgpu: make display pinning moreflexible
(v2)")Signed-off-by Hamza Mahfooz <[email protected]>--- .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 41 ++++++++++++++++++- 1 file changed, 39 insertions(+), 2 deletions(-)drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +27
-0@@ -7897,6 +7897,34 @@ static void amdgpu_dm_commit_cursors(struct drm_atomic_state *state) amdgpu_dm_plane_handle_cursor_update(plane,old_plane_state ); } +static inline uint32_t get_mem_type (struct amdgpu_device *adev, + struct drm_gem_object *obj, + bool check_domain) { + struct amdgpu_bo *abo = gem_to_amdgpu_bo(obj); + uint32_t mem_type; + + if (unlikely(amdgpu_bo_reserve(abo, true))) + return 0; + + if (unlikely(dma_resv_reserve_fences(abo->tbo.base.resv, 1))) + goto err; + + if (check_domain && + amdgpu_display_supported_domains(adev, abo->flags) != + (AMDGPU_GEM_DOMAIN_VRAM | AMDGPU_GEM_DOMAIN_GTT)) + goto err; + + mem_type = abo->tbo.resource->mem_type; + amdgpu_bo_unreserve(abo); + + return mem_type; + +err: + amdgpu_bo_unreserve(abo); + return 0; +} + static void amdgpu_dm_commit_planes(struct drm_atomic_state *state, struct dc_state *dc_state, struct drm_device *dev, @@ -7916,6 +7944,7 @@static void amdgpu_dm_commit_planes(struct
drm_atomic_state*state,to_dm_crtc_state(drm_atomic_get_old_crtc_state(state, pcrtc));
intplanes_count= 0, vpos, hpos;
unsigned long flags;
+uint32_tmem_type;
u32target_vblank,last_flip_vblank;
boolvrr_active=amdgpu_dm_crtc_vrr_active(acrtc_state); boolcursor_update= false;drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +11
-2@@ -8035,13 +8064,21 @@ static void amdgpu_dm_commit_planes(structdrm_atomic_state *state, } } + mem_type = get_mem_type(dm->adev, +old_plane_state->fb->obj[0 ], + true); + /* * Only allow immediate flips for fast updates that don't - * change FB pitch, DCC state, rotation or mirroing. + * change memory domain, FB pitch, DCC state, rotation or + * mirroring. */ bundle->flip_addrs[planes_count].flip_immediate = crtc->state->async_flip && - acrtc_state->update_type == UPDATE_TYPE_FAST; + acrtc_state->update_type == UPDATE_TYPE_FAST && + (!mem_type || (mem_type && get_mem_type(dm->adev, + fb->obj[0], + false) == + mem_type)); timestamp_ns = ktime_get_ns();bundle->flip_addrs[planes_count].flip_timestamp_in_us =
div_u64(timestamp_ns, 1000);--
Hamza
Signature · 1 line
Hamza
Quoted 9 lines · Christian König
Am 14.04.23 um 21:33 schrieb Hamza Mahfooz:
Quoted 5 lines
Currently, we allow the framebuffer for a given plane to move between memory domains, however when that happens it causes the screen to flicker, it is even possible for the framebuffer to change memory domains on every plane update (causing a continuous flicker effect). So, to fix this, don't perform an immediate flip in the aforementioned case.
That sounds strongly like you just forget to wait for the move to finish!
It doesn't exhibit when we allow only gtt or only vram, only when switches between pools does it flicker.
Alex
Quoted 88 lines
What is the order of things done here? E.g. who calls
amdgpu_bo_pin()and who waits for fences for finish signaling? Is that maybe just in the wrong order?Regards,
Christian.Quoted 79 lines
Fixes 81d0bcf99009 ("drm/amdgpu: make display pinning more flexible (v2)")Signed-off-by Hamza Mahfooz <[email protected]>--- .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 41 ++++++++++++++++++- 1 file changed, 39 insertions(+), 2 deletions(-)drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +39
-2@@ -7897,6 +7897,34 @@ static void amdgpu_dm_commit_cursors(struct drm_atomic_state *state)amdgpu_dm_plane_handle_cursor_update (plane, old_plane_state); } +static inline uint32_t get_mem_type (struct amdgpu_device *adev, +struct drm_gem_object *obj, +bool check_domain) +{ +struct amdgpu_bo *abo =gem_to_amdgpu_bo (obj); +uint32_t mem_type; + +if (unlikely (amdgpu_bo_reserve (abo, true))) +return 0 ; + +if (unlikely (dma_resv_reserve_fences (abo->tbo.base.resv,1 ))) + goto err; + +if (check_domain && +amdgpu_display_supported_domains (adev, abo->flags) != + (AMDGPU_GEM_DOMAIN_VRAM |AMDGPU_GEM_DOMAIN_GTT )) + goto err; + + mem_type = abo->tbo.resource->mem_type; +amdgpu_bo_unreserve (abo); + +return mem_type; + +err: +amdgpu_bo_unreserve (abo); +return 0 ; +} + static void amdgpu_dm_commit_planes(struct drm_atomic_state *state, struct dc_state *dc_state, struct drm_device *dev,@@ -7916,6 +7944,7 @@ static void amdgpu_dm_commit_planes(struct drm_atomic_state *state,to_dm_crtc_state (drm_atomic_get_old_crtc_state (state, pcrtc));int planes_count =0 , vpos, hpos;unsigned long flags; +uint32_t mem_type;u32 target_vblank, last_flip_vblank;bool vrr_active =amdgpu_dm_crtc_vrr_active (acrtc_state);bool cursor_update = false;@@ -8035,13 +8064,21 @@ static void amdgpu_dm_commit_planes(struct drm_atomic_state *state, } } + mem_type =get_mem_type (dm->adev, old_plane_state->fb->obj[0 ], + true); +/* * Only allow immediate flips for fast updates that don't -* change FB pitch, DCC state, rotation or mirroing. +* change memory domain, FB pitch, DCC state, rotation or +* mirroring. */ bundle->flip_addrs[planes_count].flip_immediate = crtc->state->async_flip && - acrtc_state->update_type ==UPDATE_TYPE_FAST ; + acrtc_state->update_type ==UPDATE_TYPE_FAST && + (!mem_type || (mem_type &&get_mem_type (dm->adev, + fb->obj[0 ], + false) == + mem_type)); timestamp_ns =ktime_get_ns (); bundle->flip_addrs[planes_count].flip_timestamp_in_us =div_u64 (timestamp_ns,1000 );