1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-06 12:20:30 +00:00

C#: Replace P/Invoke with delegate pointers

- Moves interop functions to UnmanagedCallbacks struct that
  contains the function pointers and is passed to C#.

- Implements UnmanagedCallbacksGenerator, a C# source generator that
  generates the UnmanagedCallbacks struct in C# and the body for the
  NativeFuncs methods (their implementation just calls the function
  pointer in the UnmanagedCallbacks). The generated methods are needed
  because .NET pins byref parameters of native calls, even if they are
  'ref struct's, which don't need pinning. The generated methods use
  `Unsafe.AsPointer` so that we can benefit from byref parameters
  without suffering overhead of pinning.

Co-authored-by: Raul Santos <raulsntos@gmail.com>
This commit is contained in:
Ignacio Roldán Etcheverry
2022-08-05 03:32:59 +02:00
parent 186d7f6239
commit 2c180f62d9
21 changed files with 1314 additions and 740 deletions

View File

@@ -0,0 +1,6 @@
namespace Godot.SourceGenerators.Internal;
internal static class GeneratorClasses
{
public const string GenerateUnmanagedCallbacksAttr = "Godot.SourceGenerators.Internal.GenerateUnmanagedCallbacksAttribute";
}