mono / VulkanSharp

Open source .NET binding for the Vulkan API
MIT License
538 stars 61 forks source link

Not possible to create platform surface from NetStandard version. #77

Closed jcant0n closed 6 years ago

jcant0n commented 6 years ago

Hello Radek,

I'm testing the netstandard1.1 version on WaveEngine 3.0 and the issue is that the pinvokes to the platform surface creation are out of the vulkan.dll.

We need to call (vkCreateWin32SurfaceKHR, vkCreateAndroidSurfaceKHR,...) from the netstandard dll, otherwhise it is not possible to do that.

I have tried to copy those pinvokes to my project while this is being fixed but using the nuget package is not possible because the native pointers are internals and you have added this to the portable library to get access from the extensions libraries Windows, iOS, and Android:

[assembly: InternalsVisibleTo("Vulkan.Android")] [assembly: InternalsVisibleTo("Vulkan.Windows")] [assembly: InternalsVisibleTo("Vulkan.iOS")]

I think that you can put all this code in the same library and only leave the views in those (android, iOS, Windows) projects. To reference the specific dll from NetStandard, as these libraries are by default installed on the platform you can use something similar to this: https://github.com/mellinoe/vk/blob/master/src/vk/Commands.cs

We are working on this right now, so if you tell me how you want to organize this, I can help you with that.

Thank you

radekdoulik commented 6 years ago

I have added the visibility attributes to the .NETStandard assembly as well, that should hopefully fix it.

Please let me know whether it fixed your issue.

jcant0n commented 6 years ago

Hello Radek,

But the pinvokes continue to be out of Vulkan.dll. I'm writing a .Netstandard 2.0 library where I need to create the surface depending on the current platform, Here is my code:

public VKSwapChain(Common.Graphics.GraphicsContext context, Common.Graphics.SwapChainDescription description) { var vkContext = context as VKGraphicsContext; var platform = GetCurrentPlatfom(); switch (platform) { case OS.Windows: break; case OS.Linux: break; case OS.Android: break; case OS.MacOS: break; case OS.iOS: break; default: break; } }

I need all the pinvokes to be available from Vulkan.dll, because I'm coding an abstraction layer from a NetStandard library so all the specific Vulkan code should be inside of this. That is why I referenced this code https://github.com/mellinoe/vk/blob/master/src/vk/Commands.cs.

Let me know if you need more details.

Thanks

radekdoulik commented 6 years ago

What part of API do you need to use in that switch? The pinvokes itself or the platform specific code from Vulkan..dll?

I am not sure we want to put platform specific code to the VulkanSharp.dll itself. Couldn't you use the reflection here to load and use the platform specific VulkanSharp assemblies?