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

Subpar OpenGL performance in higher resolutions (on a mac) #12728

Open
BAndysc opened this issue Aug 30, 2023 · 7 comments
Open

Subpar OpenGL performance in higher resolutions (on a mac) #12728

BAndysc opened this issue Aug 30, 2023 · 7 comments

Comments

@BAndysc
Copy link
Contributor

BAndysc commented Aug 30, 2023

Describe the bug
(I wasn't sure if I should report it as a bug or just start a discussion, but I've decided to go with an issue).

For some reason, when the OpenGL control render viewport is big enough, the performance lowers down significantly, i.e.:

  • when the effective viewport (not the logical size depending on the dpi, I mean raw pixel size) is 1920x1080, I have stable 120 fps:
image
  • when the viewport size is 2280x1220, it goes down to 60 fps:
image

As you can see on the screenshots, there is no drawing involved, in the render method there is just a gl.Clear call:

    protected override void OnOpenGlRender(GlInterface gl, int fb)
    {
        Dispatcher.UIThread.Post(RequestNextFrameRendering, DispatcherPriority.Render);
        gl.ClearColor(1, 1, 0,1);
        gl.Clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    }

Maybe I am using RequestNextFrameRendering incorrectly? I have tried both different dispatcher priorities AND I tried to directly call RequestNextFrameRendering (without using Dispatcher.Post) - no difference.

I tried to increase MaxGpuResourceSizeBytes, but even setting long.MaxValue doesn't make any difference (With(new SkiaOptions{ MaxGpuResourceSizeBytes = long.MaxValue }))

I have no idea if similar behaviour can be observed on Windows. I will appreciate if anybody with windows and a high resolution monitor could run it.

To Reproduce
Steps to reproduce the behavior:

  1. Clone repo https://github.com/BAndysc/avalonia-rendering-test
  2. Run devtools and enable the FPS measure
  3. Play with the window size and observe how the FPS drops at certain point.

Expected behavior
I believe there is no reason why the fps should drop when there is no advanced drawing involved.

Desktop:

@BAndysc BAndysc added the bug label Aug 30, 2023
@BAndysc BAndysc changed the title Subpar OpenGL performance in higher resolution (on a mac) Subpar OpenGL performance in higher resolutions (on a mac) Aug 30, 2023
@maxkatz6
Copy link
Member

IIRC Avalonia OpenGL renderer on macOS is quite limited in terms of performance. And Avalonia Metal renderer is able to freely render without any additional UI thread synchronization.

You can enable metal with AppBuilder extension .With(new AvaloniaNativePlatformOptions { RenderingMode = Metal }).
But while it should improve FPS, it still experimental and I don't remember it supporting OpenGL interop just yet (which you obviously need for this demo).

@maxkatz6
Copy link
Member

cc @kekekeks to confirm

@BAndysc
Copy link
Contributor Author

BAndysc commented Aug 31, 2023

.With(new AvaloniaNativePlatformOptions { RenderingMode = Metal })

I also tried it, but unfortunately it looks like now OpenGl is not supported when using Metal backend (black screen, no error). May I ask if there is any chance for adding support for it any time soon(ish)? (Ultimately one day I would love to switch to Vulkan via MotelVK and I guess this somehow is related to supporting opengl with metal)

@kekekeks
Copy link
Member

We are planning to add support for importing Metal textures via our generic GPU interop API.

It would then be possible render OpenGL content into a Metal texture using CVPixelBuffer.

Unfortunately no ETA yet, we are a bit busy in other areas

@BAndysc
Copy link
Contributor Author

BAndysc commented Aug 31, 2023

Understandable, thanks anyway!

@bitkidinc
Copy link

bitkidinc commented Dec 31, 2023

IIRC Avalonia OpenGL renderer on macOS is quite limited in terms of performance. And Avalonia Metal renderer is able to freely render without any additional UI thread synchronization.

You can enable metal with AppBuilder extension .With(new AvaloniaNativePlatformOptions { RenderingMode = Metal }). But while it should improve FPS, it still experimental and I don't remember it supporting OpenGL interop just yet (which you obviously need for this demo).

@maxkatz6 Thanks! Using the Metal renderer almost halved CPU usage on my old Macbook with custom controls overriding Render. The only problem is the DPI is off and everything is huge using Metal. Is there any sort of option to correct that?

@maxkatz6
Copy link
Member

maxkatz6 commented Jan 1, 2024

I am afraid there is none. Metal backend is experimental still and might have this sort of issues.
If anybody can send a PR with a fix for them - it would be great.

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