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

[dotnet6 branch] Move runtime_interop P/Invoke to function pointers #59588

Closed

Conversation

raulsntos
Copy link
Member

@raulsntos raulsntos commented Mar 27, 2022

  • Moves runtime_interop methods to UnmanagedCallbacks struct that contains the methods as 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 purpose of moving to function pointers is being able to call these methods when Godot is compiled with target=release_debug.

For convenience these are the files output by the source generator:
Godot.SourceGenerators.UnmanagedCallbacksGenerator.zip

TODO:

  • We have the same problem in GodotTools.Internals.Internal. I guess we'll want to use the source generator there too.
  • Methods that have a parameter of type DebuggingUtils.godot_stack_info_vector can't be generated because it's not one of the GodotInteropStructs and it's a ref struct so I can't use Unsafe or CustomUnsafe to get the pointer. These methods are now generated using by-ref parameters or copying to the stack so no need to convert to pointer.
  • I created a separate Godot.SourceGenerators project for the GodotSharp assembly since we only want to run this generator and not the others but I should probably move this generator to the original Godot.SourceGenerators assembly. Alternatively we can have separate source generators projects for GodotSharp and for user projects that could share common code with a shared library.
  • out parameters are assigned default, otherwise the compiler complains that they are not assigned before leaving the method. Can we really avoid this?

@raulsntos raulsntos added this to the 4.0 milestone Mar 27, 2022
@raulsntos raulsntos force-pushed the dotnet6-runtime-interop branch 4 times, most recently from 3c2062f to 7547107 Compare March 28, 2022 00:25
@GeorgeS2019
Copy link

GeorgeS2019 commented Mar 28, 2022

#warning TODO hot-reload

Cause compiling problem in Windows (MSVC) as discussed.

@raulsntos
Copy link
Member Author

@GeorgeS2019 I'm aware of this. This PR intends to solve a different problem. I didn't want to fix the warnings in this one because it was getting big enough already as it is.

@GeorgeS2019
Copy link

@raulsntos A quick feedback, I tried introduced the changes and it builds without problem for Windows MSVC.

@raulsntos raulsntos force-pushed the dotnet6-runtime-interop branch 3 times, most recently from d462e01 to acb6837 Compare March 29, 2022 02:26
- Moves runtime_interop methods to UnmanagedCallbacks struct that
contains the methods as 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).
@raulsntos raulsntos force-pushed the dotnet6-runtime-interop branch from acb6837 to eecd262 Compare April 16, 2022 19:54
@neikeq
Copy link
Contributor

neikeq commented Aug 8, 2022

Superseded by #64089 (I cherry-picked your changes there with some modifications)

@neikeq neikeq closed this Aug 8, 2022
@neikeq neikeq added the archived label Aug 8, 2022
@raulsntos raulsntos deleted the dotnet6-runtime-interop branch August 8, 2022 02:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants