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

[BUG] GRGlInterface.Create() returns null on Windows on Arm #3155

Closed
1 task done
peternoyes opened this issue Feb 4, 2025 · 2 comments · Fixed by #3189
Closed
1 task done

[BUG] GRGlInterface.Create() returns null on Windows on Arm #3155

peternoyes opened this issue Feb 4, 2025 · 2 comments · Fixed by #3189
Labels

Comments

@peternoyes
Copy link

peternoyes commented Feb 4, 2025

Description

I am developing on Arm64 on Windows 11, using the latest version of SkiaSharp. The app is a .NET Framework 4.8 application. We use OpenGL for GPU rendering.

Calling:
GRGlInterface.Create()

returns null

The same code on x64 works correctly.

I have the OpenCL™, OpenGL®, and Vulkan® Compatibility Pack installed. https://apps.microsoft.com/detail/9nqpsl29bfff?hl=en-us&gl=US, so would I expect this to work.

Code

using (var glInterface = GRGlInterface.Create())
_grContext = GRContext.CreateGl(glInterface);

This is how we get the OpenGL context. On Arm64 glInterface ends up being null which results in a null context as well.

Expected Behavior

We expect that OpenGL would work on Arm64 just as it does on x64 with that compatibility pack installed

Actual Behavior

Null is returned

Version of SkiaSharp

3.116.0 (Current)

Last Known Good Version of SkiaSharp

No known good versions

IDE / Editor

Visual Studio (Windows)

Platform / Operating System

Windows

Platform / Operating System Version

Windows 11 2H24
Arm64
.NET Framework 4.8
OpenCL™, OpenGL®, and Vulkan® Compatibility Pack

Devices

Lenovo Yoga Slim 7x

Relevant Screenshots

No response

Relevant Log Output

Code of Conduct

  • I agree to follow this project's Code of Conduct
@mattleibow
Copy link
Contributor

mattleibow commented Mar 7, 2025

EDIT

The SKGLControl (Windows Forms) just works. So it must be the WPF + GL + DX issues. I did see this issue: opentk/GLWpfControl#136

I am running Windows in Parallels on my M1, so it may just be that.

ORIGINAL

My PR fixes the direct issue with the creation of the GL context for drawing. However, this does not mean the GL views suddenly start working.

I am currently using this on WPF:

var ctrl = new GLWpfControl();
Content = ctrl;
ctrl.Start(new()
{
    MajorVersion = 2,
    MinorVersion = 1,
    RenderContinuously = false
});

But I get an error:

Fatal error. 0xC0000005
   at OpenTK.Graphics.Wgl.Wgl.DXOpenDeviceNV(IntPtr)
   at OpenTK.Wpf.DxGlContext..ctor(OpenTK.Wpf.GLWpfControlSettings)
   at OpenTK.Wpf.GLWpfControlRenderer..ctor(OpenTK.Wpf.GLWpfControlSettings)
   at OpenTK.Wpf.GLWpfControl.Start(OpenTK.Wpf.GLWpfControlSettings)
   at MauiApp1.MainWindow..ctor()
   at System.RuntimeType.CreateInstanceDefaultCtor(Boolean, Boolean)
   at System.RuntimeType.CreateInstanceImpl(System.Reflection.BindingFlags, System.Reflection.Binder, System.Object[], System.Globalization.CultureInfo)
   at MS.Internal.Xaml.Runtime.ClrObjectRuntime.CreateInstance(System.Xaml.XamlType, System.Object[])
   at System.Xaml.XamlObjectWriter.Logic_CreateAndAssignToParentStart(MS.Internal.Xaml.Context.ObjectWriterContext)
   at System.Xaml.XamlObjectWriter.WriteStartMember(System.Xaml.XamlMember)
   at System.Windows.Markup.WpfXamlLoader.TransformNodes(System.Xaml.XamlReader, System.Xaml.XamlObjectWriter, Boolean, Boolean, Boolean, System.Xaml.IXamlLineInfo, System.Xaml.IXamlLineInfoConsumer, MS.Internal.Xaml.Context.XamlContextStack`1<System.Windows.Markup.WpfXamlFrame>, System.Windows.Markup.IStyleConnector)
   at System.Windows.Markup.WpfXamlLoader.Load(System.Xaml.XamlReader, System.Xaml.IXamlObjectWriterFactory, Boolean, System.Object, System.Xaml.XamlObjectWriterSettings, System.Uri)
   at System.Windows.Markup.WpfXamlLoader.LoadBaml(System.Xaml.XamlReader, Boolean, System.Object, System.Xaml.Permissions.XamlAccessLevel, System.Uri)
   at System.Windows.Markup.XamlReader.LoadBaml(System.IO.Stream, System.Windows.Markup.ParserContext, System.Object, Boolean)
   at System.Windows.Application.LoadBamlStreamWithSyncInfo(System.IO.Stream, System.Windows.Markup.ParserContext)
   at System.Windows.Application.DoStartup()
   at System.Windows.Application.<.ctor>b__1_0(System.Object)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate, System.Object, Int32)
   at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(System.Object, System.Delegate, System.Object, Int32, System.Delegate)
   at System.Windows.Threading.DispatcherOperation.InvokeImpl()
   at MS.Internal.CulturePreservingExecutionContext.CallbackWrapper(System.Object)
   at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)
   at MS.Internal.CulturePreservingExecutionContext.Run(MS.Internal.CulturePreservingExecutionContext, System.Threading.ContextCallback, System.Object)
   at System.Windows.Threading.DispatcherOperation.Invoke()
   at System.Windows.Threading.Dispatcher.ProcessQueue()
   at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr, Int32, IntPtr, IntPtr, Boolean ByRef)
   at MS.Win32.HwndWrapper.WndProc(IntPtr, Int32, IntPtr, IntPtr, Boolean ByRef)
   at MS.Win32.HwndSubclass.DispatcherCallbackOperation(System.Object)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate, System.Object, Int32)
   at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(System.Object, System.Delegate, System.Object, Int32, System.Delegate)
   at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(System.Windows.Threading.DispatcherPriority, System.TimeSpan, System.Delegate, System.Object, Int32)
   at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr, Int32, IntPtr, IntPtr)
   at MS.Win32.UnsafeNativeMethods.DispatchMessage(System.Windows.Interop.MSG ByRef)
   at MS.Win32.UnsafeNativeMethods.DispatchMessage(System.Windows.Interop.MSG ByRef)
   at System.Windows.Threading.Dispatcher.PushFrameImpl(System.Windows.Threading.DispatcherFrame)
   at System.Windows.Application.RunDispatcher(System.Object)
   at System.Windows.Application.RunInternal(System.Windows.Window)
   at TheTestApp.App.Main()

@mattleibow
Copy link
Contributor

mattleibow commented Mar 7, 2025

You do need to build your own glfw as the OpenTK packages do not have it for ARM. This comes from https://github.com/glfw/glfw

I built mine locally:

cmake -B build-win32-shared-arm64 -G "Visual Studio 17 2022" -A arm64 -D BUILD_SHARED_LIBS=ON -D GLFW_BUILD_EXAMPLES=OFF -D GLFW_BUILD_TESTS=OFF -D GLFW_BUILD_DOCS=OFF
cmake --build build-win32-shared-arm64 --parallel

Then I copied the glfw3.dll file from glfw\build-win32-shared-arm64\src\Debug\glfw3.dll into my app.

You could also ty using vcpkg and build glfw3.

I also am attaching the binaries I built here just for quick reference (use at own risk): glfw3.zip

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

Successfully merging a pull request may close this issue.

2 participants