public static unsafe void Execute(ref JobNativeMultiHashMapMergedSharedKeyIndicesProducer <TJob> jobProducer, IntPtr additionalPtr, IntPtr bufferRangePatchData, ref JobRanges ranges, int jobIndex)
            {
                while (true)
                {
                    int begin;
                    int end;

                    if (!JobsUtility.GetWorkStealingRange(ref ranges, jobIndex, out begin, out end))
                    {
                        return;
                    }

                    var bucketData = jobProducer.HashMap.GetUnsafeBucketData();
                    var buckets    = (int *)bucketData.buckets;
                    var nextPtrs   = (int *)bucketData.next;
                    var keys       = bucketData.keys;
                    var values     = bucketData.values;

                    for (int i = begin; i < end; i++)
                    {
                        int entryIndex = buckets[i];

                        while (entryIndex != -1)
                        {
                            var key   = UnsafeUtility.ReadArrayElement <int>(keys, entryIndex);
                            var value = UnsafeUtility.ReadArrayElement <int>(values, entryIndex);
                            int firstValue;

                            NativeMultiHashMapIterator <int> it;
                            jobProducer.HashMap.TryGetFirstValue(key, out firstValue, out it);

                            // [macton] Didn't expect a usecase for this with multiple same values
                            // (since it's intended use was for unique indices.)
                            // https://forum.unity.com/threads/ijobnativemultihashmapmergedsharedkeyindices-unexpected-behavior.569107/#post-3788170
                            if (entryIndex == it.GetEntryIndex())
                            {
#if ENABLE_UNITY_COLLECTIONS_CHECKS
                                JobsUtility.PatchBufferMinMaxRanges(bufferRangePatchData, UnsafeUtility.AddressOf(ref jobProducer), value, 1);
#endif
                                jobProducer.JobData.ExecuteFirst(value);
                            }
                            else
                            {
#if ENABLE_UNITY_COLLECTIONS_CHECKS
                                var startIndex  = math.min(firstValue, value);
                                var lastIndex   = math.max(firstValue, value);
                                var rangeLength = (lastIndex - startIndex) + 1;

                                JobsUtility.PatchBufferMinMaxRanges(bufferRangePatchData, UnsafeUtility.AddressOf(ref jobProducer), startIndex, rangeLength);
#endif
                                jobProducer.JobData.ExecuteNext(firstValue, value);
                            }

                            entryIndex = nextPtrs[entryIndex];
                        }
                    }
                }
            }
Example #2
0
    public static unsafe JobHandle Schedule <TJob>(this TJob jobData, NativeMultiHashMap <int, int> hashMap, int minIndicesPerJobCount, JobHandle dependsOn = new JobHandle())
        where TJob : struct, IJobNativeMultiHashMapMergedSharedKeyIndices
    {
        var jobProducer = new JobNativeMultiHashMapMergedSharedKeyIndicesProducer <TJob>
        {
            HashMap = hashMap,
            JobData = jobData
        };

        var scheduleParams = new JobsUtility.JobScheduleParameters(
            UnsafeUtility.AddressOf(ref jobProducer)
            , JobNativeMultiHashMapMergedSharedKeyIndicesProducer <TJob> .Initialize()
            , dependsOn
            , ScheduleMode.Parallel
            );

        return(JobsUtility.ScheduleParallelFor(ref scheduleParams, hashMap.GetUnsafeBucketData().bucketCapacityMask + 1, minIndicesPerJobCount));
    }