示例#1
0
 public void Dispose()
 {
     Clear();
     _linePrimitives.Dispose();
     _trianglePrimitives.Dispose();
     _trianglePrimitives.Dispose();
     _rasterizedFragments.Dispose();
     _renderedColors.Dispose();
 }
示例#2
0
    public unsafe void UnsafeUtility_ReadArrayElement_Performance()
    {
        const int numElements = 16 << 10;

        var list = new UnsafeList <TestStruct>(numElements, Allocator.Persistent, NativeArrayOptions.ClearMemory);

        for (int i = 0; i < numElements; ++i)
        {
            list.Add(new TestStruct {
                x = i, y = (short)(i + 1), z = true
            });
        }

        Measure.Method(() =>
        {
            for (int i = 0; i < numElements; ++i)
            {
                UnsafeUtility.ReadArrayElement <TestStruct>(list.Ptr, i);
            }
        })
        .WarmupCount(100)
        .MeasurementCount(1000)
        .Run();

        list.Dispose();
    }
示例#3
0
        internal void Dispose()
        {
            var e = GetEdgeEnumerator();

            while (e.MoveNext())
            {
                e.Current->QuadEdge->Crep.Dispose();
            }

            for (int i = 0; i < _creps.Count; i++)
            {
                _creps[i].Dispose();
            }
            _creps.Dispose();

            _vertices.Dispose();
            _verticesSeq.Dispose();
            _constraints.Dispose();
            _quadEdges.Dispose();
            V.Dispose();
            C.Dispose();
            _qt.Dispose();
            _edgeSearch.Dispose();
            _flipStack.Dispose();
            _insertedPoints.Dispose();
            _open.Dispose();
            _vlist.Dispose();
            _elist.Dispose();
            DestroyedTriangles.Dispose();
            _refinementQueue.Dispose();
        }
示例#4
0
    public unsafe void UnsafeUtility_ReadArrayElementBoundsChecked_Performance()
    {
        const int numElements = 16 << 10;
        var       sizeOf      = UnsafeUtility.SizeOf <TestStruct>();
        var       alignOf     = UnsafeUtility.AlignOf <TestStruct>();

        var list = new UnsafeList(sizeOf, alignOf, numElements, Allocator.Persistent, NativeArrayOptions.ClearMemory);

        for (int i = 0; i < numElements; ++i)
        {
            list.Add(new TestStruct {
                x = i, y = (short)(i + 1), z = true
            });
        }

        Measure.Method(() =>
        {
            for (int i = 0; i < numElements; ++i)
            {
                UnsafeUtilityExtensions.ReadArrayElementBoundsChecked <TestStruct>(list.Ptr, i, numElements);
            }
        })
        .WarmupCount(100)
        .MeasurementCount(1000)
        .Run();

        list.Dispose();
    }
示例#5
0
    public unsafe void UnsafeList_TrimExcess()
    {
        var sizeOf  = UnsafeUtility.SizeOf <int>();
        var alignOf = UnsafeUtility.AlignOf <int>();

        UnsafeList list     = new UnsafeList(sizeOf, alignOf, 32, Allocator.Persistent, NativeArrayOptions.ClearMemory);
        var        capacity = list.Capacity;

        list.Add(1);
        list.TrimExcess <int>();
        Assert.AreEqual(1, list.Length);
        Assert.AreEqual(1, list.Capacity);

        list.RemoveAtSwapBack <int>(0);
        Assert.AreEqual(list.Length, 0);
        list.TrimExcess <int>();
        Assert.AreEqual(list.Capacity, 0);

        list.Add(1);
        Assert.AreEqual(list.Length, 1);
        Assert.AreNotEqual(list.Capacity, 0);

        list.Clear();
        list.Dispose();
    }
示例#6
0
 public unsafe void Dispose()
 {
     try
     {
         initialized = false;
         if (vertices.Ptr != null && vertices.IsCreated)
         {
             vertices.Dispose();
         }
         if (visibleOuterLines.Ptr != null && visibleOuterLines.IsCreated)
         {
             visibleOuterLines.Dispose();
         }
         if (surfaceVisibleOuterLines.Ptr != null && surfaceVisibleOuterLines.IsCreated)
         {
             surfaceVisibleOuterLines.Dispose();
         }
         if (surfaceVisibleOuterLineRanges.Ptr != null && surfaceVisibleOuterLineRanges.IsCreated)
         {
             surfaceVisibleOuterLineRanges.Dispose();
         }
     }
     catch (Exception ex)
     {
         UnityEngine.Debug.LogException(ex);
     }
     finally
     {
         vertices                      = default;
         visibleOuterLines             = default;
         surfaceVisibleOuterLines      = default;
         surfaceVisibleOuterLineRanges = default;
     }
 }
示例#7
0
    public unsafe void UnsafeUtility_WriteArrayElement_Performance()
    {
        const int numElements = 16 << 10;
        var       sizeOf      = UnsafeUtility.SizeOf <TestStruct>();
        var       alignOf     = UnsafeUtility.AlignOf <TestStruct>();

        var list = new UnsafeList(sizeOf, alignOf, numElements, Allocator.Persistent, NativeArrayOptions.ClearMemory);

        var test = new TestStruct {
            x = 0, y = 1, z = true
        };

        Measure.Method(() =>
        {
            for (int i = 0; i < numElements; ++i)
            {
                UnsafeUtility.WriteArrayElement(list.Ptr, i, test);
            }
        })
        .WarmupCount(100)
        .MeasurementCount(1000)
        .Run();

        list.Dispose();
    }
示例#8
0
    public unsafe void UnsafeList_Resize_ClearMemory()
    {
        var sizeOf  = UnsafeUtility.SizeOf <int>();
        var alignOf = UnsafeUtility.AlignOf <int>();

        UnsafeList list = new UnsafeList(sizeOf, alignOf, 5, Allocator.Persistent, NativeArrayOptions.ClearMemory);

        list.SetCapacity <int>(32);
        var capacity = list.Capacity;

        list.Resize(sizeOf, alignOf, 5, NativeArrayOptions.UninitializedMemory);
        Assert.AreEqual(capacity, list.Capacity); // list capacity should not change on resize

        for (var i = 0; i < 5; ++i)
        {
            UnsafeUtility.WriteArrayElement(list.Ptr, i, i);
        }

        list.Resize(sizeOf, alignOf, 10, NativeArrayOptions.ClearMemory);
        Assert.AreEqual(capacity, list.Capacity); // list capacity should not change on resize

        for (var i = 0; i < 5; ++i)
        {
            Assert.AreEqual(i, UnsafeUtility.ReadArrayElement <int>(list.Ptr, i));
        }

        for (var i = 5; i < list.Length; ++i)
        {
            Assert.AreEqual(0, UnsafeUtility.ReadArrayElement <int>(list.Ptr, i));
        }

        list.Dispose();
    }
 public void Dispose()
 {
     if (sections.IsCreated)
     {
         sections.Dispose();
     }
     sections = default;
 }
 protected override void OnDestroy()
 {
     m_MasterUpdateList.Dispose();
     m_UnmanagedSystemsToRemove.Dispose();
     m_UnmanagedSystemsToUpdate.Dispose();
     base.OnDestroy();
     Created = false;
 }
示例#11
0
 internal void Dispose()
 {
     ComponentQueue.Dispose();
     ActiveArchetypeChunks.Dispose();
     InactiveFullArchetypeChunks.Dispose();
     ActiveFullArchetypeChunks.Dispose();
     InactivePartialArchetypeChunk.Dispose();
     ActivePartialArchetypeChunk.Dispose();
 }
 public void Dispose()
 {
     CreateChunks.Dispose();
     AddComponentToChunks.Dispose();
     RemoveComponentFromChunks.Dispose();
     AddComponentBatches.Dispose();
     RemoveComponentBatches.Dispose();
     ChunkScratch.Dispose();
     BatchScratch.Dispose();
 }
示例#13
0
        public bool ConvexPartition(int curveSegments, out UnsafeList <SegmentVertex> polygonVerticesArray, out UnsafeList <int> polygonVerticesSegments, Allocator allocator)
        {
            using (var shapeVertices = new NativeList <SegmentVertex>(Allocator.Temp))
            {
                GetPathVertices(curveSegments, shapeVertices);

                //Profiler.BeginSample("ConvexPartition");
                if (shapeVertices.Length == 3)
                {
                    polygonVerticesArray    = new UnsafeList <SegmentVertex>(3, allocator);
                    polygonVerticesSegments = new UnsafeList <int>(1, allocator);

                    polygonVerticesArray.Resize(3, NativeArrayOptions.UninitializedMemory);
                    polygonVerticesArray[0] = shapeVertices[0];
                    polygonVerticesArray[1] = shapeVertices[1];
                    polygonVerticesArray[2] = shapeVertices[2];

                    polygonVerticesSegments.Resize(1, NativeArrayOptions.UninitializedMemory);
                    polygonVerticesSegments[0] = polygonVerticesArray.Length;
                }
                else
                {
                    polygonVerticesArray    = new UnsafeList <SegmentVertex>(shapeVertices.Length * math.max(1, shapeVertices.Length / 2), allocator);
                    polygonVerticesSegments = new UnsafeList <int>(shapeVertices.Length, allocator);
                    if (!External.BayazitDecomposerBursted.ConvexPartition(shapeVertices,
                                                                           ref polygonVerticesArray,
                                                                           ref polygonVerticesSegments))
                    {
                        polygonVerticesArray.Dispose();
                        polygonVerticesSegments.Dispose();
                        polygonVerticesArray    = default;
                        polygonVerticesSegments = default;
                        return(false);
                    }
                }

                for (int i = 0; i < polygonVerticesSegments.Length; i++)
                {
                    var range = new Range
                    {
                        start = i == 0 ? 0 : polygonVerticesSegments[i - 1],
                        end   = polygonVerticesSegments[i]
                    };

                    if (CalculateOrientation(polygonVerticesArray, range) < 0)
                    {
                        External.BayazitDecomposerBursted.Reverse(polygonVerticesArray, range);
                    }
                }
                //Profiler.EndSample();

                //Debug.Assert(polygonVerticesArray.Length == 0 || polygonVerticesArray.Length == polygonVerticesSegments[polygonVerticesSegments.Length - 1]);
                return(true);
            }
        }
 public void Dispose()
 {
     for (var i = 1; i != m_SharedComponentData.Count; i++)
     {
         (m_SharedComponentData[i] as IRefCounted)?.Release();
     }
     m_SharedComponentInfo.Dispose();
     m_SharedComponentData.Clear();
     m_SharedComponentData = null;
     m_HashLookup.Dispose();
 }
示例#15
0
    public unsafe void UnsafeList_Init_ClearMemory()
    {
        UnsafeList list = new UnsafeList(UnsafeUtility.SizeOf <int>(), UnsafeUtility.AlignOf <int>(), 10, Allocator.Persistent, NativeArrayOptions.ClearMemory);

        for (var i = 0; i < list.Length; ++i)
        {
            Assert.AreEqual(0, UnsafeUtility.ReadArrayElement <int>(list.Ptr, i));
        }

        list.Dispose();
    }
 public void Dispose()
 {
     Chunk = null;
     if (AddedEntities.IsCreated)
     {
         AddedEntities.Dispose();
     }
     if (RemovedEntities.IsCreated)
     {
         RemovedEntities.Dispose();
     }
 }
示例#17
0
    public unsafe void UnsafeList_Allocate_Deallocate_Read_Write()
    {
        var list = new UnsafeList(Allocator.Persistent);

        list.Add(1);
        list.Add(2);

        Assert.AreEqual(2, list.Length);
        Assert.AreEqual(1, UnsafeUtility.ReadArrayElement <int>(list.Ptr, 0));
        Assert.AreEqual(2, UnsafeUtility.ReadArrayElement <int>(list.Ptr, 1));

        list.Dispose();
    }
示例#18
0
        internal void Dispose()
        {
            for (int i = 0; i < m_Delegates.Length; ++i)
            {
                m_Delegates[i].Dispose();
            }

            m_DebugNames.Dispose();
            m_Delegates.Dispose();
            m_TypeHashToIndex.Dispose();

            this = default;
        }
示例#19
0
    public unsafe void UnsafeList_Resize_ClearMemory()
    {
        var sizeOf  = UnsafeUtility.SizeOf <int>();
        var alignOf = UnsafeUtility.AlignOf <int>();

        UnsafeList list = new UnsafeList(sizeOf, alignOf, 5, Allocator.Persistent, NativeArrayOptions.ClearMemory);

        list.Resize(sizeOf, alignOf, 5, NativeArrayOptions.UninitializedMemory);
        list.Resize(sizeOf, alignOf, 10, NativeArrayOptions.ClearMemory);

        for (var i = 0; i < list.Length; ++i)
        {
            Assert.AreEqual(0, UnsafeUtility.ReadArrayElement <int>(list.Ptr, i));
        }

        list.Dispose();
    }
示例#20
0
        /// <summary>
        /// Modifies this container to keep only values that are present in both containers.
        /// </summary>
        /// <typeparam name="T">Source type of elements</typeparam>
        /// <param name="container">Container to modify.</param>
        /// <param name="other">The container to compare to this container.</param>
        public static void IntersectWith <T>(this NativeHashSet <T> container, FixedList32 <T> other)
            where T : unmanaged, IEquatable <T>
        {
            var result = new UnsafeList <T>(container.Count(), Allocator.Temp);

            foreach (var item in other)
            {
                if (container.Contains(item))
                {
                    result.Add(item);
                }
            }

            container.Clear();
            container.UnionWith(result);

            result.Dispose();
        }
示例#21
0
    public unsafe void UnsafeList_Resize_Zero()
    {
        var sizeOf  = UnsafeUtility.SizeOf <int>();
        var alignOf = UnsafeUtility.AlignOf <int>();

        UnsafeList list     = new UnsafeList(sizeOf, alignOf, 5, Allocator.Persistent, NativeArrayOptions.ClearMemory);
        var        capacity = list.Capacity;

        list.Add(1);
        list.Resize <int>(0);
        Assert.AreEqual(0, list.Length);
        Assert.AreEqual(capacity, list.Capacity); // list capacity should not change on resize

        list.Add(2);
        list.Clear();
        Assert.AreEqual(0, list.Length);
        Assert.AreEqual(capacity, list.Capacity); // list capacity should not change on resize

        list.Dispose();
    }
示例#22
0
    public void UnsafeList_Performance_Add()
    {
        const int numElements = 16 << 10;

        var sizeOf  = UnsafeUtility.SizeOf <int>();
        var alignOf = UnsafeUtility.AlignOf <int>();
        var list    = new UnsafeList(sizeOf, alignOf, 1, Allocator.Persistent, NativeArrayOptions.ClearMemory);

        Measure.Method(() =>
        {
            list.SetCapacity <int>(1);
            for (int i = 0; i < numElements; ++i)
            {
                list.Add(i);
            }
        })
        .WarmupCount(100)
        .MeasurementCount(1000)
        .Run();

        list.Dispose();
    }
示例#23
0
    public void UnsafeListT_Performance_Add()
    {
        const int numElements = 16 << 10;

        var list = new UnsafeList <int>(1, Allocator.Persistent, NativeArrayOptions.ClearMemory);

        Measure.Method(() =>
        {
            list.Length = 1;
            list.TrimExcess();

            for (int i = 0; i < numElements; ++i)
            {
                list.Add(i);
            }
        })
        .WarmupCount(100)
        .MeasurementCount(1000)
        .Run();

        list.Dispose();
    }
示例#24
0
    public void CustomAllocatorUnsafeListWorks()
    {
        AllocatorManager.Initialize();
        var parent    = AllocatorManager.Persistent;
        var allocator = ClearToValueAllocator.New(0xFE, ref parent);

        allocator.Register();
        for (byte ClearValue = 0; ClearValue < 0xF; ++ClearValue)
        {
            allocator.m_clearValue = ClearValue;
            var       unsafelist = new UnsafeList <byte>(1, allocator.Handle);
            const int kLength    = 100;
            unsafelist.Resize(kLength);
            for (int i = 0; i < kLength; ++i)
            {
                Assert.AreEqual(ClearValue, unsafelist[i]);
            }
            unsafelist.Dispose();
        }
        allocator.Dispose();
        AllocatorManager.Shutdown();
    }
示例#25
0
 public void Dispose()
 {
     if (idToIndex.IsCreated)
     {
         idToIndex.Dispose();
     }
     idToIndex = default;
     if (indexToID.IsCreated)
     {
         indexToID.Dispose();
     }
     indexToID = default;
     if (sectionManager.IsCreated)
     {
         sectionManager.Dispose();
     }
     sectionManager = default;
     if (freeIDs.IsCreated)
     {
         freeIDs.Dispose();
     }
     freeIDs = default;
 }
示例#26
0
    public unsafe void UnsafeUtility_WriteArrayElementBoundsChecked_Performance()
    {
        const int numElements = 16 << 10;

        var list = new UnsafeList <TestStruct>(numElements, Allocator.Persistent, NativeArrayOptions.ClearMemory);

        var test = new TestStruct {
            x = 0, y = 1, z = true
        };

        Measure.Method(() =>
        {
            for (int i = 0; i < numElements; ++i)
            {
                UnsafeUtilityExtensions.WriteArrayElementBoundsChecked(list.Ptr, i, test, numElements);
            }
        })
        .WarmupCount(100)
        .MeasurementCount(1000)
        .Run();

        list.Dispose();
    }
        public static unsafe void RunWithoutJobsInternal <T>(ref T jobData, ref EntityQuery query, Entity *limitToEntityArray, int limitToEntityArrayLength)
            where T : struct, IJobEntityBatch
        {
            var prebuiltBatchList = new UnsafeList(Allocator.TempJob);

            try
            {
                ChunkIterationUtility.FindFilteredBatchesForEntityArrayWithQuery(
                    query._GetImpl(),
                    limitToEntityArray, limitToEntityArrayLength,
                    ref prebuiltBatchList);

                ArchetypeChunk *chunks      = (ArchetypeChunk *)prebuiltBatchList.Ptr;
                int             chunkCounts = prebuiltBatchList.Length;
                for (int i = 0; i != chunkCounts; i++)
                {
                    jobData.Execute(chunks[i], i);
                }
            }
            finally
            {
                prebuiltBatchList.Dispose();
            }
        }
示例#28
0
        internal static unsafe JobHandle ScheduleInternal <T>(
            ref T jobData,
            EntityQuery query,
            JobHandle dependsOn,
            ScheduleMode mode,
            int batchesPerChunk,
            bool isParallel = true,
            NativeArray <Entity> limitToEntityArray = default(NativeArray <Entity>))
            where T : struct, IJobEntityBatchWithIndex
        {
            var queryImpl = query._GetImpl();
            var queryData = queryImpl->_QueryData;

            var batchCount                     = 0;
            var filteredChunkCount             = 0;
            var useEntityArray                 = limitToEntityArray.IsCreated;
            var prebuiltBatchList              = new UnsafeList(Allocator.TempJob);
            var perBatchMatchingArchetypeIndex = new UnsafeIntList(0, Allocator.TempJob);

            if (useEntityArray)
            {
                // Forces the creation of an EntityQueryMask, which is necessary to filter batches.
                var access = queryImpl->_Access;
                access->EntityQueryManager->GetEntityQueryMask(queryData, access->EntityComponentStore);

                ChunkIterationUtility.FindBatchesForEntityArrayWithQuery(
                    queryImpl->_Access->EntityComponentStore,
                    queryData,
                    ref queryImpl->_Filter,
                    (Entity *)limitToEntityArray.GetUnsafePtr(),
                    limitToEntityArray.Length,
                    ref prebuiltBatchList,
                    ref perBatchMatchingArchetypeIndex);

                batchCount = prebuiltBatchList.Length;
            }
            else
            {
                filteredChunkCount = query.CalculateChunkCount();
                batchCount         = filteredChunkCount * batchesPerChunk;
            }

            // Allocate one buffer for all prefilter data and distribute it
            // We keep the full buffer as a "dummy array" so we can deallocate it later with [DeallocateOnJobCompletion]
            var sizeofBatchArray  = sizeof(ArchetypeChunk) * batchCount;
            var sizeofIndexArray  = sizeof(int) * batchCount;
            var prefilterDataSize = sizeofBatchArray + sizeofIndexArray + sizeof(int);

            var prefilterData      = (byte *)Memory.Unmanaged.Allocate(prefilterDataSize, 64, Allocator.TempJob);
            var prefilterDataArray = NativeArrayUnsafeUtility.ConvertExistingDataToNativeArray <byte>(prefilterData, prefilterDataSize, Allocator.TempJob);

#if ENABLE_UNITY_COLLECTIONS_CHECKS
            NativeArrayUnsafeUtility.SetAtomicSafetyHandle(ref prefilterDataArray, AtomicSafetyHandle.Create());
#endif

            var prefilterHandle = dependsOn;
            if (useEntityArray)
            {
                var prefilterJob = new PrefilterForJobEntityBatchWithIndex_EntityArray
                {
                    MatchingArchetypes             = queryImpl->_QueryData->MatchingArchetypes,
                    Filter                         = queryImpl->_Filter,
                    EntityComponentStore           = queryImpl->_Access->EntityComponentStore,
                    PrefilterData                  = prefilterData,
                    PrebuiltBatches                = prebuiltBatchList,
                    PerBatchMatchingArchetypeIndex = perBatchMatchingArchetypeIndex
                };

                if (mode != ScheduleMode.Run)
                {
                    prefilterHandle = prefilterJob.Schedule(dependsOn);
                }
                else
                {
                    prefilterJob.Run();
                }

                prefilterHandle = prebuiltBatchList.Dispose(prefilterHandle);
                prefilterHandle = perBatchMatchingArchetypeIndex.Dispose(prefilterHandle);
            }
            else
            {
                var prefilterJob = new PrefilterForJobEntityBatchWithIndex
                {
                    MatchingArchetypes   = queryImpl->_QueryData->MatchingArchetypes,
                    Filter               = queryImpl->_Filter,
                    BatchesPerChunk      = batchesPerChunk,
                    EntityComponentStore = queryImpl->_Access->EntityComponentStore,
                    PrefilterData        = prefilterData,
                    FilteredChunkCount   = filteredChunkCount
                };

                if (mode != ScheduleMode.Run)
                {
                    prefilterHandle = prefilterJob.Schedule(dependsOn);
                }
                else
                {
                    prefilterJob.Run();
                }
            }


            JobEntityBatchIndexWrapper <T> jobEntityBatchIndexWrapper = new JobEntityBatchIndexWrapper <T>
            {
#if ENABLE_UNITY_COLLECTIONS_CHECKS
                // All IJobEntityBatchWithIndex jobs have a EntityManager safety handle to ensure that BeforeStructuralChange throws an error if
                // jobs without any other safety handles are still running (haven't been synced).
                safety = new EntitySafetyHandle {
                    m_Safety = queryImpl->SafetyHandles->GetEntityManagerSafetyHandle()
                },
#endif

                JobData       = jobData,
                PrefilterData = prefilterDataArray,

                JobsPerChunk = batchesPerChunk,
                IsParallel   = isParallel ? 1 : 0
            };

            var scheduleParams = new JobsUtility.JobScheduleParameters(
                UnsafeUtility.AddressOf(ref jobEntityBatchIndexWrapper),
                isParallel
                ? JobEntityBatchIndexProducer <T> .InitializeParallel()
                : JobEntityBatchIndexProducer <T> .InitializeSingle(),
                prefilterHandle,
                mode);

#if UNITY_DOTSRUNTIME
            // This should just be a call to FinalizeScheduleChecked, but DOTSR requires the JobsUtility calls to be
            // in this specific function.
#if ENABLE_UNITY_COLLECTIONS_CHECKS
            try
            {
#endif
            if (!isParallel)
            {
                return(JobsUtility.Schedule(ref scheduleParams));
            }
            else
            {
                return(JobsUtility.ScheduleParallelFor(ref scheduleParams, batchCount, 1));
            }
#if ENABLE_UNITY_COLLECTIONS_CHECKS
        }

        catch (InvalidOperationException e)
        {
            prefilterHandle.Complete();
            prefilterDataArray.Dispose();
            throw e;
        }
#endif
#else
            // We can't use try {} catch {} with 2020.2 as we will be burst compiling the schedule code.
            // Burst doesn't support exception handling.
            bool executedManaged = false;
            JobHandle result     = default;
            FinalizeScheduleChecked(isParallel, batchCount, prefilterHandle, prefilterDataArray, ref scheduleParams, ref executedManaged, ref result);

            if (executedManaged)
            {
                return(result);
            }

            return(FinalizeScheduleNoExceptions(isParallel, batchCount, ref scheduleParams));
#endif
        }
示例#29
0
 public void Destroy()
 {
     contents.Dispose();
 }
 internal void Dispose()
 {
     _unmanagedSlotByTypeHash.Dispose();
     _pendingDestroys.Dispose();
     _stateMemory.Dispose();
 }