C# 9.0 Function Pointers

First off, I want to say I’ve been keeping an eye on the C# 9 function pointers, and I really appreciate the efforts the scripting team has made so far with its support. I was excited to use them in Burst with the hope that they can be used to overcome the generic delegate limitation when using FunctionPointer in non-bursted code.

Currently running Unity 2021.2.0a13 with Burst 1.6.0-pre.2, I am running into
```Burst error BC1054: Unable to resolve type `method System.Int32 *(System.Int32). Reason: Unknown.````

Here’s a snip of the failing Job:

[BurstCompile]
public unsafe struct CallFuncJob : IJob
{
    [NativeDisableUnsafePtrRestriction]
    public IntPtr FuncPtr;
    public NativeArray<int> In;
    public NativeArray<int> Out;

    public void Execute()
    {
        Out[0] = ((delegate* unmanaged[Cdecl]<int, int>)FuncPtr)(In[0]);
    }
}

Ideally, I hope it can support something like this:

public unsafe struct BurstFunc<T, TResult>
  where T : struct
  where TResult : struct
{
  readonly delegate* unmanaged[Cdecl]<T, TResult> _ptr;

  public BurstFunc(IntPtr ptr)
  {
    _ptr = ptr;
  }

  public TResult Invoke(T arg0) => _ptr(arg0);

  public static BurstFunc<T, TResult> Compile(Func<T, TResult> func)
  {
    var ptr = BurstCompiler.CompileFunctionPointer(func);
    return new BurstFunc<T, TResult>(ptr.Value);
  }
}

Yes, function pointers should be fixed/supported for Burst 1.6

Note that Burst compilation of open generics is not supported for delegate (they are not supported by .NET with interop either see this)

There’s also this now that I am looking into after a tip from elsewhere on these here fora:
https://docs.unity3d.com/Packages/com.unity.burst@1.6/manual/docs/AdvancedUsages.html#function-pointers