Skip to content

Commit 634092b

Browse files
kleinermairlied
authored andcommitted
drm/amd/display: Use vrr friendly pageflip throttling in DC.
In VRR mode, keep track of the vblank count of the last completed pageflip in amdgpu_crtc->last_flip_vblank, as recorded in the pageflip completion handler after each completed flip. Use that count to prevent mmio programming a new pageflip within the same vblank in which the last pageflip completed, iow. to throttle pageflips to at most one flip per video frame, while at the same time allowing to request a flip not only before start of vblank, but also anywhere within vblank. The old logic did the same, and made sense for regular fixed refresh rate flipping, but in vrr mode it prevents requesting a flip anywhere inside the possibly huge vblank, thereby reducing framerate in vrr mode instead of improving it, by delaying a slightly delayed flip requests up to a maximum vblank duration + 1 scanout duration. This would limit VRR usefulness to only help applications with a very high GPU demand, which can submit the flip request before start of vblank, but then have to wait long for fences to complete. With this method a flip can be both requested and - after fences have completed - executed, ie. it doesn't matter if the request (amdgpu_dm_do_flip()) gets delayed until deep into the extended vblank due to cpu execution delays. This also allows clients which want to regulate framerate within the vrr range a much more fine-grained control of flip timing, a feature that might be useful for video playback, and is very useful for neuroscience/vision research applications. In regular non-VRR mode, retain the old flip submission behavior. This to keep flip scheduling for fullscreen X11/GLX OpenGL clients intact, if they use the GLX_OML_sync_control extensions glXSwapBufferMscOML(, ..., target_msc,...) function with a specific target_msc target vblank count. glXSwapBuffersMscOML() or DRI3/Present PresentPixmap() will not flip at the proper target_msc for a non-zero target_msc if VRR mode is active with this patch. They'd often flip one frame too early. However, this limitation should not matter much in VRR mode, as scheduling based on vblank counts is pretty futile/unusable under variable refresh duration anyway, so no real extra harm is done. According to some testing already done with this patch by Nicholas on top of my tests, IGT tests didn't report any problems. If fixes stuttering and flickering when flipping at rates below the minimum vrr refresh rate. Fixes: bb47de7 ("drm/amdgpu: Set FreeSync state using drm VRR properties") Signed-off-by: Mario Kleiner <mario.kleiner.de@gmail.com> Cc: <stable@vger.kernel.org> Cc: Harry Wentland <harry.wentland@amd.com> Cc: Alex Deucher <alexander.deucher@amd.com> Cc: Michel Dänzer <michel@daenzer.net> Tested-by: Bruno Filipe <bmilreu@gmail.com> Reviewed-by: Nicholas Kazlauskas <nicholas.kazlauskas@amd.com> Signed-off-by: Nicholas Kazlauskas <nicholas.kazlauskas@amd.com> Signed-off-by: Alex Deucher <alexander.deucher@amd.com> Signed-off-by: Dave Airlie <airlied@redhat.com>
1 parent 2c3cd66 commit 634092b

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4645,6 +4645,8 @@ static void amdgpu_dm_commit_planes(struct drm_atomic_state *state,
46454645
struct amdgpu_bo *abo;
46464646
uint64_t tiling_flags, dcc_address;
46474647
uint32_t target, target_vblank;
4648+
uint64_t last_flip_vblank;
4649+
bool vrr_active = acrtc_state->freesync_config.state == VRR_STATE_ACTIVE_VARIABLE;
46484650

46494651
struct {
46504652
struct dc_surface_update surface_updates[MAX_SURFACES];
@@ -4804,7 +4806,31 @@ static void amdgpu_dm_commit_planes(struct drm_atomic_state *state,
48044806
* hopefully eliminating dc_*_update structs in their entirety.
48054807
*/
48064808
if (flip_count) {
4807-
target = (uint32_t)drm_crtc_vblank_count(pcrtc) + *wait_for_vblank;
4809+
if (!vrr_active) {
4810+
/* Use old throttling in non-vrr fixed refresh rate mode
4811+
* to keep flip scheduling based on target vblank counts
4812+
* working in a backwards compatible way, e.g., for
4813+
* clients using the GLX_OML_sync_control extension or
4814+
* DRI3/Present extension with defined target_msc.
4815+
*/
4816+
last_flip_vblank = drm_crtc_vblank_count(pcrtc);
4817+
}
4818+
else {
4819+
/* For variable refresh rate mode only:
4820+
* Get vblank of last completed flip to avoid > 1 vrr
4821+
* flips per video frame by use of throttling, but allow
4822+
* flip programming anywhere in the possibly large
4823+
* variable vrr vblank interval for fine-grained flip
4824+
* timing control and more opportunity to avoid stutter
4825+
* on late submission of flips.
4826+
*/
4827+
spin_lock_irqsave(&pcrtc->dev->event_lock, flags);
4828+
last_flip_vblank = acrtc_attach->last_flip_vblank;
4829+
spin_unlock_irqrestore(&pcrtc->dev->event_lock, flags);
4830+
}
4831+
4832+
target = (uint32_t)last_flip_vblank + *wait_for_vblank;
4833+
48084834
/* Prepare wait for target vblank early - before the fence-waits */
48094835
target_vblank = target - (uint32_t)drm_crtc_vblank_count(pcrtc) +
48104836
amdgpu_get_vblank_counter_kms(pcrtc->dev, acrtc_attach->crtc_id);

0 commit comments

Comments
 (0)