ImGui.NET icon indicating copy to clipboard operation
ImGui.NET copied to clipboard

Update sample to be able use NativeAOT

Open kant2002 opened this issue 2 years ago • 10 comments

rd.xml file is workaround to SharpDx limitations.

kant2002 avatar Jan 04 '23 17:01 kant2002

Hey @kant2002, thanks for the submission here. In newer versions of Veldrid (of which there are only beta releases...), SharpDX has actually been replaced by Vortice. I think a better approach here would be to update the sample projects to reference Veldrid 4.9.0-beta2 and see if NativeAOT works out of the box. If it doesn't, we will probably need a slightly different rd.xml file, but chances are much higher that it will work.

mellinoe avatar Jan 17 '23 23:01 mellinoe

I did update to beta, and problem just move to Vortice. Actual root cause is missing trimming annotations for SharpGen.Runtime, so I will try to fix issue there.

kant2002 avatar Jan 18 '23 05:01 kant2002

sigh, https://github.com/SharpGenTools/SharpGenTools/blob/7917a51b8203bcdd3e3fc0750b7f93f1888838ea/SharpGen.Runtime/MarshallingHelpers.cs#L18-L20 we already have annotations, but they are not part of latest release and Jeremy is overworked. Probably have to live with this for now.

kant2002 avatar Jan 18 '23 05:01 kant2002

Let's see how it goes with https://github.com/SharpGenTools/SharpGenTools/issues/229

kant2002 avatar Jan 18 '23 06:01 kant2002

good news: https://github.com/amerkoleci/Vortice.Windows/discussions/379#discussioncomment-4731623

zaafar avatar Jan 19 '23 20:01 zaafar

I think Veldrid should be recompiled, since If I manually bump version by adding <PackageReference Include="Vortice.Direct3D11" Version="2.3.0" /> then app brokes in NativeAOT and in runtime.

Unhandled Exception: System.MissingMethodException: Method not found: 'Vortice.Direct3D11.Texture2DDescription.CpuAccessFlags'.
   at Internal.Runtime.TypeLoaderExceptionHelper.CreateMissingMethodException(ExceptionStringID, String) + 0x40
   at Internal.Runtime.CompilerHelpers.ThrowHelpers.ThrowMissingMethodException(ExceptionStringID, String) + 0x9
   at Veldrid.D3D11.D3D11Texture..ctor(ID3D11Texture2D, TextureType, PixelFormat) + 0x15
   at Veldrid.D3D11.D3D11Swapchain.Resize(UInt32, UInt32) + 0x22b
   at Veldrid.D3D11.D3D11Swapchain..ctor(D3D11GraphicsDevice, SwapchainDescription&) + 0x511
   at Veldrid.D3D11.D3D11GraphicsDevice..ctor(D3D11DeviceOptions, Nullable`1) + 0x445
   at Veldrid.GraphicsDevice.CreateD3D11(GraphicsDeviceOptions, SwapchainDescription) + 0xf8
   at Veldrid.StartupUtilities.VeldridStartup.CreateDefaultD3D11GraphicsDevice(GraphicsDeviceOptions, Sdl2Window) + 0xa6
   at Veldrid.StartupUtilities.VeldridStartup.CreateGraphicsDevice(Sdl2Window, GraphicsDeviceOptions, GraphicsBackend) + 0x4a
   at Veldrid.StartupUtilities.VeldridStartup.CreateWindowAndGraphicsDevice(WindowCreateInfo, GraphicsDeviceOptions, GraphicsBackend, Sdl2Window&, GraphicsDevice&) + 0x79
   at ImGuiNET.Program.Main(String[]) + 0x152
   at ImGui.NET.SampleProgram!<BaseAddress>+0x2ef85b

kant2002 avatar Jan 20 '23 04:01 kant2002

I would suggest to update vortice to latest 2.3.0 in veldrid and then use that veldrid build for imgui.

I'll try to keep method names backward compatible in future.

amerkoleci avatar Jan 20 '23 08:01 amerkoleci

that's what I plan to do. Thankfully in my case Veldrid and ImGui.Net have same maintainer, so things would be easiers to handle. I just let you know that renamig in minor version cause problems. I understand that if you are alone, it's hard to keep track of everything.

kant2002 avatar Jan 20 '23 08:01 kant2002

that's what I plan to do. Thankfully in my case Veldrid and ImGui.Net have same maintainer, so things would be easiers to handle. I just let you know that renamig in minor version cause problems. I understand that if you are alone, it's hard to keep track of everything.

PR ready: https://github.com/mellinoe/veldrid/pull/478

amerkoleci avatar Jan 25 '23 09:01 amerkoleci

After updating to latest Veldrid ImgUI.Net works with NativeAOT out of the box! Thank you guys!

kant2002 avatar Mar 25 '23 17:03 kant2002