示例#1
0
        public unsafe static JobHandle SortJob <T>(T *array, int length, JobHandle inputDeps = new JobHandle()) where T : unmanaged, IComparable <T>
        {
            if (length == 0)
            {
                return(inputDeps);
            }

            var segmentCount = (length + 1023) / 1024;

#if UNITY_2019_3_OR_NEWER || UNITY_DOTSPLAYER
            var workerCount = JobsUtility.JobWorkerCount;
#else
            var workerCount = JobsUtility.MaxJobThreadCount;
#endif
            workerCount = math.max(1, workerCount);
            var workerSegmentCount = segmentCount / workerCount;
            var segmentSortJob     = new SegmentSort <T> {
                Data = array, Length = length, SegmentWidth = 1024
            };
            var segmentSortJobHandle = segmentSortJob.Schedule(segmentCount, workerSegmentCount, inputDeps);
            var segmentSortMergeJob  = new SegmentSortMerge <T> {
                Data = array, Length = length, SegmentWidth = 1024
            };
            var segmentSortMergeJobHandle = segmentSortMergeJob.Schedule(segmentSortJobHandle);
            return(segmentSortMergeJobHandle);
        }
示例#2
0
        unsafe public static JobHandle SortJob <T>(T *array, int length, JobHandle inputDeps = new JobHandle()) where T : unmanaged, IComparable <T>
        {
            if (length == 0)
            {
                return(inputDeps);
            }

            var segmentCount       = (length + 1023) / 1024;
            var workerSegmentCount = segmentCount / JobsUtility.MaxJobThreadCount; // .JobsWorkerCount
            var segmentSortJob     = new SegmentSort <T> {
                Data = array, Length = length, SegmentWidth = 1024
            };
            var segmentSortJobHandle = segmentSortJob.Schedule(segmentCount, workerSegmentCount, inputDeps);
            var segmentSortMergeJob  = new SegmentSortMerge <T> {
                Data = array, Length = length, SegmentWidth = 1024
            };
            var segmentSortMergeJobHandle = segmentSortMergeJob.Schedule(segmentSortJobHandle);

            return(segmentSortMergeJobHandle);
        }
示例#3
0
        /// <summary>
        /// Sorts an array using a custom comparison function.
        /// </summary>
        /// <typeparam name="T">Source type of elements</typeparam>
        /// <typeparam name="U">The comparer type.</typeparam>
        /// <param name="array">Array to perform sort.</param>
        /// <param name="length">Number of elements to perform sort.</param>
        /// <param name="comp">A comparison function that indicates whether one element in the array is less than, equal to, or greater than another element.</param>
        /// <param name="inputDeps">The job handle or handles for any scheduled jobs that use this container.</param>
        /// <returns>A new job handle containing the prior handles as well as the handle for the job that sorts
        /// the container.</returns>
        public unsafe static JobHandle Sort <T, U>(T *array, int length, U comp, JobHandle inputDeps)
            where T : unmanaged
            where U : IComparer <T>
        {
            if (length == 0)
            {
                return(inputDeps);
            }

            var segmentCount = (length + 1023) / 1024;

            var workerCount        = math.max(1, JobsUtility.MaxJobThreadCount);
            var workerSegmentCount = segmentCount / workerCount;
            var segmentSortJob     = new SegmentSort <T, U> {
                Data = array, Comp = comp, Length = length, SegmentWidth = 1024
            };
            var segmentSortJobHandle = segmentSortJob.Schedule(segmentCount, workerSegmentCount, inputDeps);
            var segmentSortMergeJob  = new SegmentSortMerge <T, U> {
                Data = array, Comp = comp, Length = length, SegmentWidth = 1024
            };
            var segmentSortMergeJobHandle = segmentSortMergeJob.Schedule(segmentSortJobHandle);

            return(segmentSortMergeJobHandle);
        }