stride3d / stride

Stride (formerly Xenko), a free and open-source cross-platform C# game engine.
https://stride3d.net
MIT License
6.62k stars 958 forks source link

NativeAOT compilation support for projects #2069

Open Yushu2606 opened 11 months ago

Yushu2606 commented 11 months ago

Is your feature request related to a problem? Please describe. .NET 8 adds NativeAOT support for more platforms. This may be used to replace the mono runtime to improve performance on some platforms that JIT compilers (such as iOS) are not allowed

Describe the solution you'd like Add NativeAOT compilation output support for projects

Describe alternatives you've considered Use the source generator instead of reflection

Additional context https://learn.microsoft.com/dotnet/core/deploying/native-aot/

IXLLEGACYIXL commented 11 months ago

2 big problems exist with aot

  1. reflection
  2. assemblyprocessor

reflection doesnt work in aot like it does in normal code, trimming works also with normal compilation but assume we want trimming also with AOT

if your script has 0 references which is normal for scriptcomponents then its gone from the build output so that is an issue, this would break assemblyprocessor and all serializers in stride

so

  1. object descriptor needs to work with aot
  2. yaml serializer needs to work with aot
  3. assemblyprocessor needs to work with aot

for the object descriptor, im on it to rewrite it into roslyn as its the more simple part i only rewrite the scanning of the class into roslyn to reduce the reflection, but i cant get entirely rid of it which is an issue so i hope that the reflection that is needed works in aot for yaml, the custom stuff stride has is big, mainly the resolving of the references is complex, the yaml serializer without references is ready for most of what stride needs for the assemblyprocessor, manio wrote a pr to replace it with roslyn, i think best would be to rewrite first object descriptor and making an overall api in between for the rules these serializers follow which i have mostly

these topics are big and complicated and will take a long time to finish idk what else will break with aot as reflection is so much used all over the engien and this just covers reflection with serialization..many other topics to identify and consider

Doprez commented 11 months ago

Adding some info related to what is needed for future AOT work: https://devblogs.microsoft.com/dotnet/creating-aot-compatible-libraries/

MeharDT commented 5 months ago

Since this is our defacto NativeAOT thread, another possible issue we'll have to deal with to add support.

Attempting to publish a Windows SDL build with NativeAOT enabled will show errors in the Output window referring to Windows Forms. These errors are not shown when NativeAOT is disabled.

3>ILC: Method '[Stride.Games]Stride.Games.GameContextFactory.NewGameContextDesktop(int32,int32,bool)' will always throw because: Failed to load assembly 'System.Windows.Forms'
3>ILC: Method '[Stride.Games]Stride.Games.GamePlatformDesktop.GetSupportedGameWindow(AppContextType)' will always throw because: Failed to load assembly 'System.Windows.Forms'
3>ILC: Method '[Stride.Input]Stride.Input.InputSourceFactory.NewWindowInputSource(GameContext)' will always throw because: Failed to load assembly 'System.Windows.Forms'

Steps to Reproduce