/// <summary> /// Compile the following delegate into a function pointer with burst. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="delegateMethod"></param> /// <returns></returns> public static unsafe FunctionPointer <T> CompileFunctionPointer <T>(T delegateMethod) where T : class { // We have added support for runtime CompileDelegate in 2018.2+ void *function = BurstCompilerInternal.Compile(delegateMethod); if (function == null) { throw new InvalidOperationException($"Burst failed to compile the given delegate."); } return(new FunctionPointer <T>(new IntPtr(function))); }
/// <summary> /// Compile the following delegate with burst and return a new delegate. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="delegateMethod"></param> /// <returns></returns> public static unsafe T CompileDelegate <T>(T delegateMethod) where T : class { // We have added support for runtime CompileDelegate in 2018.2+ void *function = BurstCompilerInternal.Compile(delegateMethod); if (function == null) { return(delegateMethod); } object res = System.Runtime.InteropServices.Marshal.GetDelegateForFunctionPointer((IntPtr)function, delegateMethod.GetType()); return((T)res); }