/// <summary> /// Schedule the job for execution on worker threads. /// list.Length is used as the iteration count. /// Note that it is required to embed the list on the job struct as well. /// </summary> /// <param name="jobData">The job and data to schedule.</param> /// <param name="list">list.Length is used as the iteration count.</param> /// <param name="innerloopBatchCount">Granularity in which workstealing is performed. A value of 32, means the job queue will steal 32 iterations and then perform them in an efficient inner loop.</param> /// <param name="dependsOn">Dependencies are used to ensure that a job executes on workerthreads after the dependency has completed execution. Making sure that two jobs reading or writing to same data do not run in parallel.</param> /// <returns>JobHandle The handle identifying the scheduled job. Can be used as a dependency for a later job or ensure completion on the main thread.</returns> public static unsafe JobHandle Schedule <T, U>(this T jobData, NativeList <U> list, int innerloopBatchCount, JobHandle dependsOn = new JobHandle()) where T : struct, IJobParallelForDefer where U : struct { void *atomicSafetyHandlePtr = null; // Calculate the deferred atomic safety handle before constructing JobScheduleParameters so // DOTS Runtime can validate the deferred list statically similar to the reflection based // validation in Big Unity. #if ENABLE_UNITY_COLLECTIONS_CHECKS var safety = NativeListUnsafeUtility.GetAtomicSafetyHandle(ref list); atomicSafetyHandlePtr = UnsafeUtility.AddressOf(ref safety); #endif var scheduleParams = new JobsUtility.JobScheduleParameters( UnsafeUtility.AddressOf(ref jobData), JobParallelForDeferProducer <T> .Initialize(), dependsOn, #if UNITY_2020_2_OR_NEWER ScheduleMode.Parallel #else ScheduleMode.Batched #endif ); return(JobsUtility.ScheduleParallelForDeferArraySize(ref scheduleParams, innerloopBatchCount, NativeListUnsafeUtility.GetInternalListDataPtrUnchecked(ref list), atomicSafetyHandlePtr)); }
public static unsafe void Run <T>(this T jobData, int arrayLength) where T : struct, IJobParallelFor { var parallelForJobProducer = new JobParallelForProducer <T>() { JobData = jobData, #if ENABLE_UNITY_COLLECTIONS_CHECKS Sentinel = 37 + arrayLength // check that code is patched as expected #endif }; var scheduleParams = new JobsUtility.JobScheduleParameters(UnsafeUtility.AddressOf(ref parallelForJobProducer), JobParallelForProducer <T> .Initialize(),
public static unsafe JobHandle ScheduleBatch <T>(this T jobData, int arrayLength, int minIndicesPerJobCount, JobHandle dependsOn = new JobHandle()) where T : struct, IJobParallelForBatch { var scheduleParams = new JobsUtility.JobScheduleParameters( UnsafeUtility.AddressOf(ref jobData), JobParallelForBatchProducer <T> .Initialize(), dependsOn, #if UNITY_2020_2_OR_NEWER ScheduleMode.Parallel #else ScheduleMode.Batched #endif ); return(JobsUtility.ScheduleParallelFor(ref scheduleParams, arrayLength, minIndicesPerJobCount)); }
/// <summary> /// Schedule the job for execution on worker threads. /// forEachCount is a pointer to the number of iterations, when dependsOn has completed. /// This API is unsafe, it is recommended to use the NativeList based Schedule method instead. /// </summary> /// <param name="jobData"></param> /// <param name="forEachCount"></param> /// <param name="innerloopBatchCount"></param> /// <param name="dependsOn"></param> /// <typeparam name="T"></typeparam> /// <returns></returns> public static unsafe JobHandle Schedule <T>(this T jobData, int *forEachCount, int innerloopBatchCount, JobHandle dependsOn = new JobHandle()) where T : struct, IJobParallelForDefer { var scheduleParams = new JobsUtility.JobScheduleParameters( UnsafeUtility.AddressOf(ref jobData), JobParallelForDeferProducer <T> .Initialize(), dependsOn, #if UNITY_2020_2_OR_NEWER ScheduleMode.Parallel #else ScheduleMode.Batched #endif ); var forEachListPtr = (byte *)forEachCount - sizeof(void *); return(JobsUtility.ScheduleParallelForDeferArraySize(ref scheduleParams, innerloopBatchCount, forEachListPtr, null)); }
public static unsafe JobHandle ScheduleFilter <T>(this T jobData, NativeList <int> indices, int innerloopBatchCount, JobHandle dependsOn = new JobHandle()) where T : struct, IJobParallelForFilter { JobParallelForFilterProducer <T> .JobWrapper jobWrapper = new JobParallelForFilterProducer <T> .JobWrapper() { JobData = jobData, outputIndices = indices, appendCount = -1 }; var scheduleParams = new JobsUtility.JobScheduleParameters(UnsafeUtility.AddressOf(ref jobWrapper), JobParallelForFilterProducer <T> .Initialize(), dependsOn, #if UNITY_2020_2_OR_NEWER ScheduleMode.Parallel #else ScheduleMode.Batched #endif ); return(JobsUtility.Schedule(ref scheduleParams)); }
public static unsafe JobHandle ScheduleTest <T>(this T jobData, NativeArray <byte> dataForProducer, JobHandle dependsOn = new JobHandle()) where T : struct, IJobTest { JobTestWrapper <T> jobTestWrapper = new JobTestWrapper <T> { JobData = jobData, ProducerResourceToClean = dataForProducer }; var scheduleParams = new JobsUtility.JobScheduleParameters( UnsafeUtility.AddressOf(ref jobTestWrapper), JobTestProducer <T> .Initialize(), dependsOn, #if UNITY_2020_2_OR_NEWER ScheduleMode.Parallel #else ScheduleMode.Batched #endif ); return(JobsUtility.Schedule(ref scheduleParams)); }
public static unsafe void RunReadOnly <T>(this T jobData, TransformAccessArray transforms) where T : struct, IJobParallelForTransform { var scheduleParams = new JobsUtility.JobScheduleParameters(UnsafeUtility.AddressOf(ref jobData), GetReflectionData <T>(), default, ScheduleMode.Run);