public static unsafe JobHandle ScheduleBatch <T>(this T jobData, int arrayLength, int minIndicesPerJobCount, JobHandle dependsOn = new JobHandle()) where T : struct, IJobParallelForBatch
        {
#if UNITY_SINGLETHREADED_JOBS
            jobData.Execute(0, arrayLength);
            DoDeallocateOnJobCompletion(jobData);
            return(new JobHandle());
#elif UNITY_DOTSPLAYER
            var jobStruct = new ParallelForBatchJobStruct <T>()
            {
                JobData = jobData,
                Ranges  = new JobRanges()
                {
                    ArrayLength     = arrayLength,
                    IndicesPerPhase = JobsUtility.GetDefaultIndicesPerPhase(arrayLength)
                },
            };

            var jobDataPtr = UnsafeUtility.Malloc(UnsafeUtility.SizeOf <ParallelForBatchJobStruct <T> >(),
                                                  UnsafeUtility.AlignOf <ParallelForBatchJobStruct <T> >(), Allocator.TempJob);
            UnsafeUtility.CopyStructureToPtr(ref jobStruct, jobDataPtr);

            var scheduleParams = new JobsUtility.JobScheduleParameters(jobDataPtr, ParallelForBatchJobStruct <T> .Initialize(),
                                                                       dependsOn, ScheduleMode.Batched);
            return(JobsUtility.ScheduleParallelFor(ref scheduleParams, arrayLength, minIndicesPerJobCount));
#else
            var scheduleParams = new JobsUtility.JobScheduleParameters(UnsafeUtility.AddressOf(ref jobData), ParallelForBatchJobStruct <T> .Initialize(), dependsOn, ScheduleMode.Batched);
            return(JobsUtility.ScheduleParallelFor(ref scheduleParams, arrayLength, minIndicesPerJobCount));
#endif
        }
Exemplo n.º 2
0
        public static unsafe void RunBatch <T>(this T jobData, int arrayLength) where T : struct, IJobParallelForBatch
        {
            var scheduleParams =
                new JobsUtility.JobScheduleParameters(UnsafeUtility.AddressOf(ref jobData),
                                                      ParallelForBatchJobStruct <T> .Initialize(), new JobHandle(), ScheduleMode.Run);

            JobsUtility.ScheduleParallelFor(ref scheduleParams, arrayLength, arrayLength);
        }
Exemplo n.º 3
0
        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),
                ParallelForBatchJobStruct <T> .Initialize(),
                dependsOn,
                ScheduleMode.Batched);

            return(JobsUtility.ScheduleParallelFor(ref scheduleParams, arrayLength, minIndicesPerJobCount));
        }
Exemplo n.º 4
0
        public static unsafe JobHandle ScheduleBatch <T>(this T jobData, int arrayLength, int minIndicesPerJobCount, JobHandle dependsOn = new JobHandle()) where T : struct, IJobParallelForBatch
        {
#if UNITY_AVOID_REFLECTION
            // Protect against garbage collection
            if (!ParallelForBatchJobStruct <T> .ExecuteHandle.IsAllocated)
            {
                ParallelForBatchJobStruct <T> .ExecuteDelegate    = ParallelForBatchJobStruct <T> .Execute;
                ParallelForBatchJobStruct <T> .ExecuteHandle      = GCHandle.Alloc(ParallelForBatchJobStruct <T> .ExecuteDelegate);
                ParallelForBatchJobStruct <T> .ExecuteFunctionPtr = Marshal.GetFunctionPointerForDelegate(ParallelForBatchJobStruct <T> .ExecuteDelegate);
            }

            // Protect against garbage collection
            if (!ParallelForBatchJobStruct <T> .CleanupHandle.IsAllocated)
            {
                ParallelForBatchJobStruct <T> .CleanupDelegate    = ParallelForBatchJobStruct <T> .Cleanup;
                ParallelForBatchJobStruct <T> .CleanupHandle      = GCHandle.Alloc(ParallelForBatchJobStruct <T> .CleanupDelegate);
                ParallelForBatchJobStruct <T> .CleanupFunctionPtr = Marshal.GetFunctionPointerForDelegate(ParallelForBatchJobStruct <T> .CleanupDelegate);
            }

            var jobFunctionPtr    = ParallelForBatchJobStruct <T> .ExecuteFunctionPtr;
            var completionFuncPtr = ParallelForBatchJobStruct <T> .CleanupFunctionPtr;

            var jobStruct = new ParallelForBatchJobStruct <T>()
            {
                JobData = jobData,
                Ranges  = new JobRanges()
                {
                    ArrayLength     = arrayLength,
                    IndicesPerPhase = JobsUtility.GetDefaultIndicesPerPhase(arrayLength)
                },
            };

            var jobDataPtr = UnsafeUtility.Malloc(UnsafeUtility.SizeOf <ParallelForBatchJobStruct <T> >(),
                                                  UnsafeUtility.AlignOf <ParallelForBatchJobStruct <T> >(), Allocator.TempJob);
            UnsafeUtility.CopyStructureToPtr(ref jobStruct, jobDataPtr);

            return(JobsUtility.ScheduleJobForEach(jobFunctionPtr, completionFuncPtr, new IntPtr(jobDataPtr),
                                                  arrayLength, minIndicesPerJobCount, dependsOn));
#else
            var scheduleParams = new JobsUtility.JobScheduleParameters(UnsafeUtility.AddressOf(ref jobData), ParallelForBatchJobStruct <T> .Initialize(), dependsOn, ScheduleMode.Batched);
            return(JobsUtility.ScheduleParallelFor(ref scheduleParams, arrayLength, minIndicesPerJobCount));
#endif
        }
Exemplo n.º 5
0
        unsafe static public JobHandle ScheduleBatch <T>(this T jobData, int arrayLength, int minIndicesPerJobCount, JobHandle dependsOn = new JobHandle()) where T : struct, IJobParallelForBatched
        {
#if UNITY_2020_2_OR_NEWER
            // This was renamed in Unity 2020.2
            var scheduleMode = ScheduleMode.Parallel;
#else
            var scheduleMode = ScheduleMode.Batched;
#endif
            var scheduleParams = new JobsUtility.JobScheduleParameters(UnsafeUtility.AddressOf(ref jobData), ParallelForBatchJobStruct <T> .Initialize(), dependsOn, scheduleMode);

            return(JobsUtility.ScheduleParallelFor(ref scheduleParams, arrayLength, minIndicesPerJobCount));
        }
Exemplo n.º 6
0
        public static unsafe void RunBatch <T>(this T jobData, int arrayLength) where T : struct, IJobParallelForBatch
        {
#if UNITY_AVOID_REFLECTION
            ScheduleBatch(jobData, arrayLength, arrayLength).Complete();
#else
            var scheduleParams = new JobsUtility.JobScheduleParameters(UnsafeUtility.AddressOf(ref jobData), ParallelForBatchJobStruct <T> .Initialize(), new JobHandle(), ScheduleMode.Run);
            JobsUtility.ScheduleParallelFor(ref scheduleParams, arrayLength, arrayLength);
#endif
        }