public static unsafe IntPtr CreateJobReflectionData(Type type, Delegate executeDelegate, Delegate cleanupDelegate = null, ManagedJobForEachDelegate codegenExecuteDelegate = null, ManagedJobDelegate codegenCleanupDelegate = null, int codegenUnmanagedJobSize = -1, ManagedJobMarshalDelegate codegenMarshalToBurstDelegate = null) { return(CreateJobReflectionData(type, type, executeDelegate, cleanupDelegate, codegenExecuteDelegate, codegenCleanupDelegate, codegenUnmanagedJobSize, codegenMarshalToBurstDelegate)); }
public static unsafe IntPtr CreateJobReflectionData(Type type, Type _, JobType jobType, Delegate executeDelegate, Delegate cleanupDelegate = null, ManagedJobForEachDelegate codegenExecuteDelegate = null, // Note that the 2 param form is used for both Normal and ParallelFor ManagedJobDelegate codegenCleanupDelegate = null) { // Tiny doesn't use this on any codepath currently; may need future support for custom jobs. if (cleanupDelegate != null) { throw new ArgumentException("Runtime needs support for cleanup delegates in jobs."); } if (codegenExecuteDelegate == null) { throw new CodegenShouldReplaceException("Code gen should have supplied an execute wrapper."); } if (jobType == JobType.ParallelFor) { if (codegenCleanupDelegate == null) { throw new CodegenShouldReplaceException("For ParallelFor jobs, code gen should have supplied a cleanup wrapper."); } } var reflectionDataPtr = UnsafeUtility.Malloc(UnsafeUtility.SizeOf <ReflectionDataProxy>(), UnsafeUtility.AlignOf <ReflectionDataProxy>(), Allocator.Persistent); var reflectionData = new ReflectionDataProxy(); reflectionData.JobType = jobType; // Protect against garbage collector relocating delegate ReflectionDataStore store = new ReflectionDataStore(executeDelegate, codegenCleanupDelegate, codegenExecuteDelegate); store.next = reflectionDataStoreRoot; reflectionDataStoreRoot = store; reflectionData.GenExecuteFunctionPtr = Marshal.GetFunctionPointerForDelegate(codegenExecuteDelegate); if (codegenCleanupDelegate != null) { reflectionData.GenCleanupFunctionPtr = Marshal.GetFunctionPointerForDelegate(codegenCleanupDelegate); } UnsafeUtility.CopyStructureToPtr(ref reflectionData, reflectionDataPtr); return(new IntPtr(reflectionDataPtr)); }
public static unsafe IntPtr CreateJobReflectionData(Type type, Type _, Delegate executeDelegate, Delegate cleanupDelegate = null, ManagedJobForEachDelegate codegenExecuteDelegate = null, ManagedJobDelegate codegenCleanupDelegate = null, int codegenUnmanagedJobSize = -1, ManagedJobMarshalDelegate codegenMarshalToBurstDelegate = null) { // Tiny doesn't use this on any codepath currently; may need future support for custom jobs. Assert.IsTrue(cleanupDelegate == null, "Runtime needs support for cleanup delegates in jobs."); Assert.IsTrue(codegenExecuteDelegate != null, "Code gen should have supplied an execute wrapper."); #if ENABLE_UNITY_COLLECTIONS_CHECKS && !UNITY_DOTSRUNTIME_IL2CPP Assert.IsTrue((codegenUnmanagedJobSize != -1 && codegenMarshalToBurstDelegate != null) || (codegenUnmanagedJobSize == -1 && codegenMarshalToBurstDelegate == null), "Code gen should have supplied a marshal wrapper."); #endif ReflectionDataProxy *reflectionDataPtr = (ReflectionDataProxy *)UnsafeUtility.Malloc(UnsafeUtility.SizeOf <ReflectionDataProxy>(), UnsafeUtility.AlignOf <ReflectionDataProxy>(), Allocator.Persistent); var reflectionData = new ReflectionDataProxy(); // Protect against garbage collector relocating delegate ReflectionDataStore store = new ReflectionDataStore(executeDelegate, codegenCleanupDelegate, codegenExecuteDelegate, codegenMarshalToBurstDelegate); store.next = Managed.reflectionDataStoreRoot; Managed.reflectionDataStoreRoot = store; reflectionData.ExecuteFunctionPtr = store.CodeGenExecuteFunctionPtr; if (codegenCleanupDelegate != null) { reflectionData.CleanupFunctionPtr = store.CodeGenCleanupFunctionPtr; } #if ENABLE_UNITY_COLLECTIONS_CHECKS && !UNITY_DOTSRUNTIME_IL2CPP reflectionData.UnmanagedSize = codegenUnmanagedJobSize; if (codegenUnmanagedJobSize != -1) { reflectionData.MarshalToBurstFunctionPtr = store.CodeGenMarshalToBurstFunctionPtr; } #endif UnsafeUtility.CopyStructureToPtr(ref reflectionData, reflectionDataPtr); return((IntPtr)reflectionDataPtr); }