public static unsafe void RunIJob <T>(ref T jobData, JobRunWithoutJobSystemDelegate functionPointer) where T : unmanaged, IJob, IJobBase { var managedJobDataPtr = UnsafeUtility.AddressOf(ref jobData); var unmanagedSize = jobData.GetUnmanagedJobSize_Gen(); if (unmanagedSize != -1) { const int kAlignment = 16; int alignedSize = (unmanagedSize + kAlignment - 1) & ~(kAlignment - 1); byte * unmanagedJobData = stackalloc byte[alignedSize]; byte * alignedUnmanagedJobData = (byte *)((UInt64)(unmanagedJobData + kAlignment - 1) & ~(UInt64)(kAlignment - 1)); // DOTS Runtime job marshalling code assumes the job is wrapped so create the wrapper and assign the jobData IJobExtensions.JobProducer <T> jobStructData = default; jobStructData.JobData = jobData; byte *jobStructDataPtr = (byte *)UnsafeUtility.AddressOf(ref jobStructData); byte *dst = (byte *)alignedUnmanagedJobData; byte *src = (byte *)jobStructDataPtr; var marshalToBurstFnPtr = JobMarshalFnLookup <T> .GetMarshalToBurstFn(); UnsafeUtility.EnterTempScope(); try { UnsafeUtility.CallFunctionPtr_pp(marshalToBurstFnPtr.ToPointer(), dst, src); // In the case of JobStruct we know the jobwrapper doesn't add // anything to the jobData so just pass it along, no offset required unlike JobChunk functionPointer(alignedUnmanagedJobData); // Since Run can capture locals for write back, we must write back the marshalled jobData after the job executes var marshalFromBurstFnPtr = JobMarshalFnLookup <T> .GetMarshalFromBurstFn(); UnsafeUtility.CallFunctionPtr_pp(marshalFromBurstFnPtr.ToPointer(), src, dst); } finally { UnsafeUtility.ExitTempScope(); } jobData = jobStructData.JobData; } else { functionPointer(managedJobDataPtr); } }
public static JobRunWithoutJobSystemDelegate BurstCompile(JobRunWithoutJobSystemDelegate d) => #if !NET_DOTS BurstCompiler.CompileFunctionPointer(d).Invoke;
public static unsafe void RunIJob <T>(ref T jobData, JobRunWithoutJobSystemDelegate functionPointer) where T : unmanaged, IJob { functionPointer(UnsafeUtility.AddressOf(ref jobData)); }
// Unsafe methods used to provide access for source-generated code. // Do not use these methods outside of source-generated code. // Unsafe methods to run jobs (replacing ILPP invoked methods) public static unsafe void UnsafeRunIJob(void *jobPtr, JobRunWithoutJobSystemDelegate functionPointer) { functionPointer(jobPtr); }