Exemple #1
0
        private JobHandle MergeSortedLists(JobHandle inputDeps, int sortedCount, int outputBuffer)
        {
            JobHandle handle4;
            int       arrayLength = this.m_Source.Length / (sortedCount * 2);
            JobHandle dependsOn   = inputDeps;

            if (arrayLength > 4)
            {
                dependsOn = new MergeSortedPairs <T> {
                    buffer       = this.m_Buffer,
                    source       = this.m_Source,
                    sortedCount  = sortedCount,
                    outputBuffer = outputBuffer
                }.Schedule <MergeSortedPairs <T> >(arrayLength, (arrayLength + 1) / 8, inputDeps);
            }
            else
            {
                int num3 = 0;
                while (true)
                {
                    if (num3 >= arrayLength)
                    {
                        break;
                    }
                    MergeLeft <T> jobData = new MergeLeft <T> {
                        startIndex   = (num3 * sortedCount) * 2,
                        buffer       = this.m_Buffer,
                        source       = this.m_Source,
                        leftCount    = sortedCount,
                        rightCount   = sortedCount,
                        outputBuffer = outputBuffer
                    };
                    dependsOn = jobData.Schedule <MergeLeft <T> >(sortedCount, 0x40, dependsOn);
                    MergeRight <T> right2 = new MergeRight <T> {
                        startIndex   = (num3 * sortedCount) * 2,
                        buffer       = this.m_Buffer,
                        source       = this.m_Source,
                        leftCount    = sortedCount,
                        rightCount   = sortedCount,
                        outputBuffer = outputBuffer
                    };
                    dependsOn = right2.Schedule <MergeRight <T> >(sortedCount, 0x40, dependsOn);
                    num3++;
                }
            }
            int num2 = this.m_Source.Length - ((arrayLength * sortedCount) * 2);

            if (num2 <= sortedCount)
            {
                if (num2 <= 0)
                {
                    handle4 = dependsOn;
                }
                else
                {
                    handle4 = new CopyRemainder <T> {
                        startIndex   = (arrayLength * sortedCount) * 2,
                        buffer       = this.m_Buffer,
                        source       = this.m_Source,
                        outputBuffer = outputBuffer
                    }.Schedule <CopyRemainder <T> >(num2, (arrayLength + 1) / 8, dependsOn);
                }
            }
            else
            {
                JobHandle handle2 = new MergeLeft <T> {
                    startIndex   = (arrayLength * sortedCount) * 2,
                    buffer       = this.m_Buffer,
                    source       = this.m_Source,
                    leftCount    = sortedCount,
                    rightCount   = num2 - sortedCount,
                    outputBuffer = outputBuffer
                }.Schedule <MergeLeft <T> >(sortedCount, 0x40, dependsOn);
                handle4 = new MergeRight <T> {
                    startIndex   = (arrayLength * sortedCount) * 2,
                    buffer       = this.m_Buffer,
                    source       = this.m_Source,
                    leftCount    = sortedCount,
                    rightCount   = num2 - sortedCount,
                    outputBuffer = outputBuffer
                }.Schedule <MergeRight <T> >(num2 - sortedCount, 0x40, handle2);
            }
            return(handle4);
        }
        private JobHandle MergeSortedLists(JobHandle inputDeps, int sortedCount, int sortBufferIndex)
        {
            var pairCount = m_SourceBuffer.Length / (sortedCount * 2);

            var mergeSortedPairsJobHandle = inputDeps;

            if (pairCount <= 4)
            {
                for (var i = 0; i < pairCount; i++)
                {
                    var mergeRemainderLeftJob = new MergeLeft
                    {
                        startIndex      = i * sortedCount * 2,
                        workingBuffer   = m_WorkingBuffer,
                        sourceBuffer    = m_SourceBuffer,
                        leftCount       = sortedCount,
                        rightCount      = sortedCount,
                        sortBufferIndex = sortBufferIndex
                    };
                    // There's no overlap, but write to the same array, so extra dependency:
                    mergeSortedPairsJobHandle =
                        mergeRemainderLeftJob.Schedule(sortedCount, 64, mergeSortedPairsJobHandle);

                    var mergeRemainderRightJob = new MergeRight
                    {
                        startIndex      = i * sortedCount * 2,
                        workingBuffer   = m_WorkingBuffer,
                        sourceBuffer    = m_SourceBuffer,
                        leftCount       = sortedCount,
                        rightCount      = sortedCount,
                        sortBufferIndex = sortBufferIndex
                    };
                    // There's no overlap, but write to the same array, so extra dependency:
                    mergeSortedPairsJobHandle =
                        mergeRemainderRightJob.Schedule(sortedCount, 64, mergeSortedPairsJobHandle);
                }
            }
            else
            {
                var mergeSortedPairsJob = new MergeSortedPairs
                {
                    workingBuffer   = m_WorkingBuffer,
                    sourceBuffer    = m_SourceBuffer,
                    sortedCount     = sortedCount,
                    sortBufferIndex = sortBufferIndex
                };
                mergeSortedPairsJobHandle = mergeSortedPairsJob.Schedule(pairCount, (pairCount + 1) / 8, inputDeps);
            }

            var remainder = m_SourceBuffer.Length - pairCount * sortedCount * 2;

            if (remainder > sortedCount)
            {
                var mergeRemainderLeftJob = new MergeLeft
                {
                    startIndex      = pairCount * sortedCount * 2,
                    workingBuffer   = m_WorkingBuffer,
                    sourceBuffer    = m_SourceBuffer,
                    leftCount       = sortedCount,
                    rightCount      = remainder - sortedCount,
                    sortBufferIndex = sortBufferIndex
                };
                // There's no overlap, but write to the same array, so extra dependency:
                var mergeLeftJobHandle = mergeRemainderLeftJob.Schedule(sortedCount, 64, mergeSortedPairsJobHandle);

                var mergeRemainderRightJob = new MergeRight
                {
                    startIndex      = pairCount * sortedCount * 2,
                    workingBuffer   = m_WorkingBuffer,
                    sourceBuffer    = m_SourceBuffer,
                    leftCount       = sortedCount,
                    rightCount      = remainder - sortedCount,
                    sortBufferIndex = sortBufferIndex
                };
                // There's no overlap, but write to the same array, so extra dependency:
                var mergeRightJobHandle =
                    mergeRemainderRightJob.Schedule(remainder - sortedCount, 64, mergeLeftJobHandle);
                return(mergeRightJobHandle);
            }

            if (remainder > 0)
            {
                var copyRemainderPairJob = new CopyRemainder
                {
                    startIndex      = pairCount * sortedCount * 2,
                    workingBuffer   = m_WorkingBuffer,
                    sourceBuffer    = m_SourceBuffer,
                    sortBufferIndex = sortBufferIndex
                };

                // There's no overlap, but write to the same array, so extra dependency:
                var copyRemainderPairJobHandle =
                    copyRemainderPairJob.Schedule(remainder, (pairCount + 1) / 8, mergeSortedPairsJobHandle);
                return(copyRemainderPairJobHandle);
            }

            return(mergeSortedPairsJobHandle);
        }