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

X11 v-sync not working on Raspberry Pi with Avalonia (Screen Tearing Between Views) #18127

Open
myrup opened this issue Feb 5, 2025 · 6 comments

Comments

@myrup
Copy link

myrup commented Feb 5, 2025

Describe the bug

I'm experiencing heavy screen tearing in my Avalonia application running on a Raspberry Pi. The issue occurs when switching between views, where both views appear partially at the same time, causing a visible tear. Display can even get stuck in a rendered state between two views (usually teared around the horizontal centerline).

Interestingly, glxgears runs perfectly synchronized, but Avalonia does not, suggesting that Avalonia is not properly handling v-sync on my setup.

I prefer to run without without DRM because screenshotting tools is needed. I have been unable to find documentation on which flags I could experiment with to fix this.

To Reproduce

App without DRM:

public static AppBuilder BuildAvaloniaApp()
            => AppBuilder.Configure<App>()
                .UsePlatformDetect()
                .LogToTrace();

Expected behavior

No tearing

Avalonia version

11.2.2

OS

Linux

Additional context

No response

@myrup myrup added the bug label Feb 5, 2025
@myrup
Copy link
Author

myrup commented Feb 6, 2025

I have been unable to find updated information about the configuration of Avalonia X11 rendering engine options. If anyone can provide information on how to configure things like enabling/disabling GL, or v-sync related options it would be of great help for me towards debugging this.

@thevortexcloud
Copy link
Contributor

As far as I am aware, the only options you get are these:

public class X11PlatformOptions

Which you use by passing to the setup methods to start Avalonia (most likely in your main method), like this:

static void Main(string[] args)
{
HarfbuzzWorkaround.Apply();
AppBuilder.Configure<App>()
.UseSkia()
.With(new X11PlatformOptions()
{
UseGLibMainLoop = true,
ExterinalGLibMainLoopExceptionLogger = e => Console.WriteLine(e.ToString())
})
.UseX11()
.SetupWithoutStarting();

@maxkatz6
Copy link
Member

maxkatz6 commented Feb 7, 2025

@kekekeks does X11 backend has v-sync timer? I don't see any special IRenderTimer implementations.

@myrup
Copy link
Author

myrup commented Feb 7, 2025

As far as I am aware, the only options you get are these:

Avalonia/src/Avalonia.X11/X11Platform.cs

Line 263 in dd2c92c

public class X11PlatformOptions
Which you use by passing to the setup methods to start Avalonia (most likely in your main method), like this:

Avalonia/samples/XEmbedSample/Program.cs

Lines 13 to 24 in dd2c92c

static void Main(string[] args)
{
HarfbuzzWorkaround.Apply();
AppBuilder.Configure()
.UseSkia()
.With(new X11PlatformOptions()
{
UseGLibMainLoop = true,
ExterinalGLibMainLoopExceptionLogger = e => Console.WriteLine(e.ToString())
})
.UseX11()
.SetupWithoutStarting();

Exactly the stuff I was looking for thanks 🙏! Further investigation pending, but I can confirm that (counterintuitively) forcing software rendering removes the worst tearing.

@kekekeks
Copy link
Member

kekekeks commented Feb 8, 2025

does X11 backend has v-sync timer? I don't see any special IRenderTimer implementations.

V-Sync and tearing prevention is expected to be provided by OpenGL implementation, not by timing your frames.
We might be missing some flag during GLX/EGL initialization

@kekekeks
Copy link
Member

kekekeks commented Feb 8, 2025

Try adding something like

using(context.EnsureCurrent())
     glXSwapIntervalEXT(context.Display, _info.Handle, 1);

here https://github.com/AvaloniaUI/Avalonia/blob/master/src/Avalonia.X11/Glx/GlxGlPlatformSurface.cs#L22

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

No branches or pull requests

4 participants