I do know this. I remember that delegate* managed means that this function pointer should only be invoked by the C# managed environment, and I do not invoke these delegate* managed in Burst code, but pass them to the managed system to be invoked by the managed code later. Delegate* managed is just a pointer type, and passing them in Burst does not seem to be a problem.
I do use Burst function pointers, but Burst function pointers can only be created by completely unmanaged functions, which is not my use case here (and it requires more boilerplate code and is not convenient for using generics).
More specifically, it would be very convenient if Burst could be improved so that the following simple example can run:
public class Context {
...
}
public unsafe struct CommandFunctionPointer {
public delegate* managed<Context, void> FunctionPointer;
}
[BurstCompile]
public unsafe partial struct CommandGenerateBurstSystem : ISystem {
public static void Command1(Context context) { ... }
public static void Command2(Context context) { ... }
public static void Command3(Context context) { ... }
[BurstCompile]
void OnUpdate(ref SystemState state) {
...
if (...) ManagedSystem.FP.Data.FunctionPointer = &Command1;
else if (...) ManagedSystem.FP.Data.FunctionPointer = &Command2;
else if (...) ManagedSystem.FP.Data.FunctionPointer = &Command3;
else ManagedSystem.FP.Data.FunctionPointer = null;
}
}
public unsafe partial class ManagedSystem : SystemBase {
public Context Context;
public static readonly SharedStatic<CommandFunctionPointer> FP = SharedStatic<CommandFunctionPointer>.GetOrCreate<ManagedSystem>();
protected override void OnUpdate() {
...
if (FP.Data.FunctionPointer != null)
FP.Data.FunctionPointer(Context);
...
}
}