Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Misc display sync fixes #15259

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Conversation

llyyr
Copy link
Contributor

@llyyr llyyr commented Nov 4, 2024

First two commits are entirely theoretical, it's more correct but it probably doesn't matter much because this code is only used to detect underruns and to wait for a frame to finish before applying new image_params.

Third commit fixes a real world problem with bad drivers that I encountered while testing various wip fifo-v1/commit-timing implementations. By not always updating base_vsync, we could potentially end up in a permanent underflow state and never recover from it even once the driver has stopped giving us bogus values.

Copy link

github-actions bot commented Nov 4, 2024

Download the artifacts for this pull request:

Windows
macOS

video/out/vo.c Outdated
@@ -489,11 +489,14 @@ static void update_vsync_timing_after_swap(struct vo *vo,
}

in->num_successive_vsyncs++;
if (in->num_successive_vsyncs <= DELAY_VSYNC_SAMPLES)
if (in->num_successive_vsyncs <= DELAY_VSYNC_SAMPLES) {
in->base_vsync += in->vsync_interval;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it is correct to increment base_vsync here. It is updated in update_vsync_timing_after_swap and this function makes sure valid value is used. base_vsync is last valid point, incrementing with with interval will accumulate a lot of drift, making this value unreliable.

Copy link
Contributor Author

@llyyr llyyr Nov 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess it makes more sense to set it to the actual vsync instead of incrementing by nominal vsync interval. Updated the patch

This is still used for caclulating a/v sync and delay remaining even
for initial samples, so we should always update it to the actual vsync
for those initial samples so we have something to work with at least.

And if we receive bogus values, also reset it to 0 along with
prev_vsync.

Not having base_vsync set to _some_ value completely breaks
vsync_skip_detection, and mpv stays stuck in a permanent mistimed state
where every frame is marked as delayed and never recovers from it.
Copy link
Member

@Dudemanguy Dudemanguy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Honestly never tested but I think it makes sense.

@kasper93
Copy link
Contributor

I'm little bit uneasy about those changes, it may break vsync skip detection and thing alongside. This vo sync code has a lot of tiny variables, that need to tick in certain way. But I don't want to trace this whole sync code again, so if you say it is ok, fine.

Third commit fixes a real world problem with bad drivers that I encountered while testing various wip fifo-v1/commit-timing implementations. By not always updating base_vsync

Could you explain this though? Specifically how do we know it doesn't affect good driver and real vsync timings?

@llyyr
Copy link
Contributor Author

llyyr commented Nov 23, 2024

Specifically how do we know it doesn't affect good driver and real vsync timings?

Happens with the current wlroots fifo implementation that's still very wip, and doesn't on mutter's. The problem specifically is that the first few vsync timings can be very jittery on the wlroots MR before it eventually becomes consistent and smooths out.

To be exact, base_vsync only needs to be populated for the in->num_successive_vsyncs == DELAY_VSYNC_SAMPLES iteration, because for the next iteration we don't return early and vsync_skip_detection will be called and the first vsync might have jitter. I don't know why this isn't an issue on non jittery drivers, but theoretically it should be

Increasing window = 4 also helped iirc but I didn't understand wm4's code here so I didn't touch it and I think it makes sense to populate base_vsync anyway for the first iteration of this drift computation. 85498a0

I'm little bit uneasy about those changes

Please test it locally first for a few days

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants