コード例 #1
0
        public static unsafe JobHandle ScheduleParallelFor(ref JobScheduleParameters parameters, int arrayLength, int innerloopBatchCount)
        {
            UnsafeUtility.AssertHeap(parameters.JobDataPtr.ToPointer());
            UnsafeUtility.AssertHeap(parameters.ReflectionData.ToPointer());
            ReflectionDataProxy jobReflectionData = UnsafeUtility.AsRef <ReflectionDataProxy>(parameters.ReflectionData.ToPointer());

            Assert.IsFalse(jobReflectionData.GenExecuteFunctionPtr.ToPointer() == null);
            Assert.IsFalse(jobReflectionData.GenCleanupFunctionPtr.ToPointer() == null);

            void *      jobMetaPtr  = parameters.JobDataPtr.ToPointer();
            JobMetaData jobMetaData = default;

            jobMetaData.JobRanges.ArrayLength     = arrayLength;
            jobMetaData.JobRanges.IndicesPerPhase = GetDefaultIndicesPerPhase(arrayLength);
            UnsafeUtility.CopyStructureToPtr(ref jobMetaData, jobMetaPtr);

#if UNITY_SINGLETHREADED_JOBS
            // In the single threaded case, this is synchronous execution.
            UnsafeUtility.CallFunctionPtr_pi(jobReflectionData.GenExecuteFunctionPtr.ToPointer(), jobMetaPtr, 0);
            UnsafeUtility.CallFunctionPtr_p(jobReflectionData.GenCleanupFunctionPtr.ToPointer(), jobMetaPtr);

            // This checks that the generated code was actually called; the last responsibility of
            // the generated code is to clean up the memory. Unfortunately only works in single threaded mode,
            Assert.IsTrue(UnsafeUtility.GetLastFreePtr() == jobMetaPtr);
            return(new JobHandle());
#else
            return(ScheduleJobParallelFor(jobReflectionData.GenExecuteFunctionPtr, jobReflectionData.GenCleanupFunctionPtr,
                                          parameters.JobDataPtr, arrayLength, innerloopBatchCount, parameters.Dependency));
#endif
        }
コード例 #2
0
        public static unsafe JobHandle Schedule(ref JobScheduleParameters parameters)
        {
            // Heap memory must be passed to schedule, so that Cleanup can free() it.
            UnsafeUtility.AssertHeap(parameters.JobDataPtr.ToPointer());
            UnsafeUtility.AssertHeap(parameters.ReflectionData.ToPointer());
            ReflectionDataProxy jobReflectionData = UnsafeUtility.AsRef <ReflectionDataProxy>(parameters.ReflectionData.ToPointer());

            Assert.IsFalse(jobReflectionData.GenExecuteFunctionPtr.ToPointer() == null);
            Assert.IsTrue(jobReflectionData.GenCleanupFunctionPtr.ToPointer() == null);

            void *jobMetaPtr = parameters.JobDataPtr.ToPointer();

#if UNITY_SINGLETHREADED_JOBS
            // In the single threaded case, this is synchronous execution.
            UnsafeUtility.CallFunctionPtr_pi(jobReflectionData.GenExecuteFunctionPtr.ToPointer(), jobMetaPtr, 0);

            // This checks that the generated code was actually called; the last responsibility of
            // the generated code is to clean up the memory. Unfortunately only works in single threaded mode,
            Assert.IsTrue(UnsafeUtility.GetLastFreePtr() == jobMetaPtr);
            return(new JobHandle());
#else
            return(ScheduleJob(jobReflectionData.GenExecuteFunctionPtr, parameters.JobDataPtr, parameters.Dependency));
#endif
        }