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

macOS rendering update + initial metal support #11914

Merged
merged 3 commits into from
Jun 30, 2023
Merged

Conversation

kekekeks
Copy link
Member

@kekekeks kekekeks commented Jun 27, 2023

  • software framebuffer render target now has to be explicitly created
  • software rendering is now supported again for macOS (should allow running apps on mac VMs, fixes macOS application doesn't work in VM environment (or without a GPU) #10770)
  • use a surface queue instead of rendering to a single IOSurface since it causes glitches under some circumstances
  • added experimental metal support (proof of concept, not production ready)

@robloo
Copy link
Contributor

robloo commented Jun 27, 2023

If I understand correctly, with this Avalonia can render directly to metal without any abstraction in-between, correct? If so, this is a fantastic surprise addition for 11.0!

@kekekeks
Copy link
Member Author

It's directly to metal, however it's still experimental and has window resize issues.

@robloo
Copy link
Contributor

robloo commented Jun 27, 2023

Well, it's great first step! Awesome work!

@avaloniaui-team
Copy link
Contributor

You can test this PR using the following package version. 11.0.999-cibuild0037039-beta. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

@BAndysc
Copy link
Contributor

BAndysc commented Jun 27, 2023

That's a cool addition, great job! Does it make GpuInterop support any easier/possible? Or it doesn't matter? https://github.com/AvaloniaUI/Avalonia/tree/master/samples/GpuInterop sample didn't support Mac, I wonder if now it could work? I would love to embed Vulkan in my app, via MoltenVK on mac.

Comment on lines +46 to +51
_contextCtor = typeof(GRContext).GetConstructor(
BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null,
new[] { typeof(IntPtr), typeof(bool) }, null) ?? throw new MissingMemberException("GRContext.ctor(IntPtr,bool)");


_renderTargetCtor = typeof(GRBackendRenderTarget).GetConstructor(
BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null,
new[] { typeof(IntPtr), typeof(bool) }, null) ?? throw new MissingMemberException("GRContext.ctor(IntPtr,bool)");

_contextOptionsToNative = typeof(GRContextOptions).GetMethod("ToNative",
BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)
?? throw new MissingMemberException("GRContextOptions.ToNative()");
Copy link
Member

Choose a reason for hiding this comment

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

To avoid trimming issues, please add these attributes on SkiaMetalApi ctor.

[DynamicDependency(DynamicallyAccessedMemberTypes.NonPublicConstructors, typeof(GRContext))]
[DynamicDependency(DynamicallyAccessedMemberTypes.NonPublicConstructors, typeof(GRBackendRenderTarget))]
[DynamicDependency(DynamicallyAccessedMemberTypes.NonPublicMethods, typeof(GRContextOptions))]

Copy link
Member

Choose a reason for hiding this comment

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

Have not tested it, but should work without any rd.xml iles.

Copy link
Member

Choose a reason for hiding this comment

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

It's also possible to write a specific member signature in the DynamicDependency attribute, but only if you know exactly one needed.

Copy link
Member

Choose a reason for hiding this comment

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

That's just to ensure that "We use reflection only on member that are guaranteed to be referenced by OpenGL gpu code" is actually not a problem, as I have doubts. Something like GRContextOptions.ToNative could be trimmed out otherwise.

@kekekeks
Copy link
Member Author

@BAndysc
It's technically possible to consume metal content while using our current OpenGL backend, Metal<->OpenGL interop is rather simple.

kekekeks added 3 commits June 30, 2023 15:42
# Conflicts:
#	src/Avalonia.Native/AvaloniaNativePlatform.cs
#	src/Avalonia.Native/AvaloniaNativePlatformExtensions.cs
#	src/Avalonia.Native/PopupImpl.cs
#	src/Avalonia.Native/WindowImpl.cs
#	src/Avalonia.Native/WindowImplBase.cs
@kekekeks kekekeks changed the title Initial metal support macOS rendering update + initial metal support Jun 30, 2023
@avaloniaui-team
Copy link
Contributor

You can test this PR using the following package version. 11.0.999-cibuild0037183-beta. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

@danwalmsley danwalmsley added this pull request to the merge queue Jun 30, 2023
Merged via the queue into master with commit 137b0c6 Jun 30, 2023
@danwalmsley danwalmsley deleted the feature/metal branch June 30, 2023 12:08
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.

macOS application doesn't work in VM environment (or without a GPU)
6 participants