public void OnCreate()
        {
            m_TypeArrayIndices = (ushort *)UnsafeUtility.Malloc(sizeof(ushort) * kMaxTypes, 16, Allocator.Persistent);
            UnsafeUtility.MemSet(m_TypeArrayIndices, 0xFF, sizeof(ushort) * kMaxTypes);

#if ENABLE_UNITY_COLLECTIONS_CHECKS
            m_TempSafety = AtomicSafetyHandle.Create();
#endif
            m_ReadJobFences = (JobHandle *)UnsafeUtility.Malloc(sizeof(JobHandle) * kMaxReadJobHandles * kMaxTypes, 16,
                                                                Allocator.Persistent);
            UnsafeUtility.MemClear(m_ReadJobFences, sizeof(JobHandle) * kMaxReadJobHandles * kMaxTypes);

            m_ComponentSafetyHandles =
                (ComponentSafetyHandle *)UnsafeUtility.Malloc(sizeof(ComponentSafetyHandle) * kMaxTypes, 16,
                                                              Allocator.Persistent);
            UnsafeUtility.MemClear(m_ComponentSafetyHandles, sizeof(ComponentSafetyHandle) * kMaxTypes);

            m_JobDependencyCombineBufferCount = 4 * 1024;
            m_JobDependencyCombineBuffer      = (JobHandle *)UnsafeUtility.Malloc(
                sizeof(ComponentSafetyHandle) * m_JobDependencyCombineBufferCount, 16, Allocator.Persistent);

            m_TypeCount     = 0;
            IsInTransaction = false;
            IsInForEachDisallowStructuralChange = 0;
            m_ExclusiveTransactionDependency    = default(JobHandle);
        }
        public void OnCreate()
        {
#if ENABLE_UNITY_COLLECTIONS_CHECKS
            m_TempSafety = AtomicSafetyHandle.Create();
#endif
            m_ReadJobFences = (JobHandle *)UnsafeUtility.Malloc(sizeof(JobHandle) * kMaxReadJobHandles * kMaxTypes, 16,
                                                                Allocator.Persistent);
            UnsafeUtility.MemClear(m_ReadJobFences, sizeof(JobHandle) * kMaxReadJobHandles * kMaxTypes);

            m_ComponentSafetyHandles =
                (ComponentSafetyHandle *)UnsafeUtility.Malloc(sizeof(ComponentSafetyHandle) * kMaxTypes, 16,
                                                              Allocator.Persistent);
            UnsafeUtility.MemClear(m_ComponentSafetyHandles, sizeof(ComponentSafetyHandle) * kMaxTypes);

            m_JobDependencyCombineBufferCount = 4 * 1024;
            m_JobDependencyCombineBuffer      = (JobHandle *)UnsafeUtility.Malloc(
                sizeof(ComponentSafetyHandle) * m_JobDependencyCombineBufferCount, 16, Allocator.Persistent);

#if ENABLE_UNITY_COLLECTIONS_CHECKS
            CreateComponentSafetyHandles(kMaxTypes);
#endif

            m_HasCleanHandles = true;
            IsInTransaction   = false;
            m_ExclusiveTransactionDependency = default(JobHandle);
        }
示例#3
0
        public ComponentJobSafetyManager()
        {
#if ENABLE_UNITY_COLLECTIONS_CHECKS
            m_TempSafety = AtomicSafetyHandle.Create();
#endif


            m_ReadJobFences = (JobHandle *)UnsafeUtility.Malloc(sizeof(JobHandle) * kMaxReadJobHandles * kMaxTypes, 16,
                                                                Allocator.Persistent);
            UnsafeUtility.MemClear(m_ReadJobFences, sizeof(JobHandle) * kMaxReadJobHandles * kMaxTypes);

            m_ComponentSafetyHandles =
                (ComponentSafetyHandle *)UnsafeUtility.Malloc(sizeof(ComponentSafetyHandle) * kMaxTypes, 16,
                                                              Allocator.Persistent);
            UnsafeUtility.MemClear(m_ComponentSafetyHandles, sizeof(ComponentSafetyHandle) * kMaxTypes);

            m_JobDependencyCombineBufferCount = 4 * 1024;
            m_JobDependencyCombineBuffer      = (JobHandle *)UnsafeUtility.Malloc(
                sizeof(ComponentSafetyHandle) * m_JobDependencyCombineBufferCount, 16, Allocator.Persistent);

#if ENABLE_UNITY_COLLECTIONS_CHECKS
            for (var i = 0; i != kMaxTypes; i++)
            {
                m_ComponentSafetyHandles[i].SafetyHandle = AtomicSafetyHandle.Create();
                AtomicSafetyHandle.SetAllowSecondaryVersionWriting(m_ComponentSafetyHandles[i].SafetyHandle, false);
            }
#endif

            m_HasCleanHandles = true;
        }
示例#4
0
        public void Dispose()
        {
            for (var i = 0; i < kMaxTypes; i++)
            {
                m_ComponentSafetyHandles[i].WriteFence.Complete();
            }

            for (var i = 0; i < kMaxTypes * kMaxReadJobHandles; i++)
            {
                m_ReadJobFences[i].Complete();
            }

#if ENABLE_UNITY_COLLECTIONS_CHECKS
            for (var i = 0; i < kMaxTypes; i++)
            {
                var res = AtomicSafetyHandle.EnforceAllBufferJobsHaveCompletedAndRelease(m_ComponentSafetyHandles[i]
                                                                                         .SafetyHandle);
                if (res == EnforceJobResult.DidSyncRunningJobs)
                {
                    Debug.LogError(
                        "Disposing EntityManager but a job is still running against the ComponentData. It appears the job has not been registered with JobComponentSystem.AddDependency.");
                }
            }

            AtomicSafetyHandle.Release(m_TempSafety);
#endif

            UnsafeUtility.Free(m_JobDependencyCombineBuffer, Allocator.Persistent);

            UnsafeUtility.Free(m_ComponentSafetyHandles, Allocator.Persistent);
            m_ComponentSafetyHandles = null;

            UnsafeUtility.Free(m_ReadJobFences, Allocator.Persistent);
            m_ReadJobFences = null;
        }
        public ComponentJobSafetyManager()
        {
#if ENABLE_UNITY_COLLECTIONS_CHECKS
            m_TempSafety = AtomicSafetyHandle.Create();
#endif


            m_ReadJobFences = (JobHandle *)UnsafeUtility.Malloc(sizeof(JobHandle) * kMaxReadJobHandles * kMaxTypes, 16,
                                                                Allocator.Persistent);
            UnsafeUtility.MemClear(m_ReadJobFences, sizeof(JobHandle) * kMaxReadJobHandles * kMaxTypes);

            m_ComponentSafetyHandles =
                (ComponentSafetyHandle *)UnsafeUtility.Malloc(sizeof(ComponentSafetyHandle) * kMaxTypes, 16,
                                                              Allocator.Persistent);
            UnsafeUtility.MemClear(m_ComponentSafetyHandles, sizeof(ComponentSafetyHandle) * kMaxTypes);

            m_JobDependencyCombineBufferCount = 4 * 1024;
            m_JobDependencyCombineBuffer      = (JobHandle *)UnsafeUtility.Malloc(
                sizeof(ComponentSafetyHandle) * m_JobDependencyCombineBufferCount, 16, Allocator.Persistent);

#if ENABLE_UNITY_COLLECTIONS_CHECKS
            CreateComponentSafetyHandles(kMaxTypes);
#endif

            m_HasCleanHandles = true;
        }
示例#6
0
        public void OnCreate()
        {
            m_TypeArrayIndices = (ushort *)UnsafeUtility.Malloc(sizeof(ushort) * kMaxTypes, 16, Allocator.Persistent);
            UnsafeUtility.MemSet(m_TypeArrayIndices, 0xFF, sizeof(ushort) * kMaxTypes);

            m_ComponentSafetyHandles = (ComponentSafetyHandle *)UnsafeUtility.Malloc(sizeof(ComponentSafetyHandle) * kMaxTypes, 16, Allocator.Persistent);
            UnsafeUtility.MemClear(m_ComponentSafetyHandles, sizeof(ComponentSafetyHandle) * kMaxTypes);

            m_TempSafety = AtomicSafetyHandle.Create();
            m_ComponentSafetyHandlesCount = 0;
        }
示例#7
0
        public void Dispose()
        {
            for (var i = 0; i < m_ComponentSafetyHandlesCount; i++)
            {
                var res0 = AtomicSafetyHandle.EnforceAllBufferJobsHaveCompletedAndRelease(m_ComponentSafetyHandles[i].SafetyHandle);
                var res1 = AtomicSafetyHandle.EnforceAllBufferJobsHaveCompletedAndRelease(m_ComponentSafetyHandles[i].BufferHandle);

                if (res0 == EnforceJobResult.DidSyncRunningJobs || res1 == EnforceJobResult.DidSyncRunningJobs)
                {
                    Debug.LogError(
                        "Disposing EntityManager but a job is still running against the ComponentData. It appears the job has not been registered with JobComponentSystem.AddDependency.");
                }
            }

            AtomicSafetyHandle.Release(m_TempSafety);

            UnsafeUtility.Free(m_TypeArrayIndices, Allocator.Persistent);
            UnsafeUtility.Free(m_ComponentSafetyHandles, Allocator.Persistent);
            m_ComponentSafetyHandles = null;
        }
示例#8
0
        public void OnCreate()
        {
            m_TypeArrayIndices = (ushort *)UnsafeUtility.Malloc(sizeof(ushort) * kMaxTypes, 16, Allocator.Persistent);
            UnsafeUtility.MemSet(m_TypeArrayIndices, 0xFF, sizeof(ushort) * kMaxTypes);

            m_ComponentSafetyHandles = (ComponentSafetyHandle *)UnsafeUtility.Malloc(sizeof(ComponentSafetyHandle) * kMaxTypes, 16, Allocator.Persistent);
            UnsafeUtility.MemClear(m_ComponentSafetyHandles, sizeof(ComponentSafetyHandle) * kMaxTypes);

            m_TempSafety = AtomicSafetyHandle.Create();
            m_ComponentSafetyHandlesCount = 0;

            m_InvalidateArraysMarker = new ProfilerMarker("InvalidateArrays");
#if UNITY_2020_1_OR_NEWER
            if (m_StaticSafetyIdsForComponentDataFromEntity == null)
            {
                m_StaticSafetyIdsForComponentDataFromEntity =
                    (int *)UnsafeUtility.Malloc(sizeof(int) * kMaxTypes, 16, Allocator.Persistent);
                UnsafeUtility.MemClear(m_StaticSafetyIdsForComponentDataFromEntity, sizeof(int) * kMaxTypes);
            }
            if (m_StaticSafetyIdsForArchetypeChunkArrays == null)
            {
                m_StaticSafetyIdsForArchetypeChunkArrays =
                    (int *)UnsafeUtility.Malloc(sizeof(int) * kMaxTypes, 16, Allocator.Persistent);
                UnsafeUtility.MemClear(m_StaticSafetyIdsForArchetypeChunkArrays, sizeof(int) * kMaxTypes);
            }

            m_StaticSafetyIdForDynamicComponentTypeHandle = AtomicSafetyHandle.NewStaticSafetyId <DynamicComponentTypeHandle>();
            SetCustomErrorMessage(m_StaticSafetyIdForDynamicComponentTypeHandle, AtomicSafetyErrorType.Deallocated,
                                  m_CustomDeallocatedErrorMessageBytes);
            SetCustomErrorMessage(m_StaticSafetyIdForDynamicComponentTypeHandle, AtomicSafetyErrorType.DeallocatedFromJob,
                                  m_CustomDeallocatedFromJobErrorMessageBytes);

            m_StaticSafetyIdForEntityTypeHandle = AtomicSafetyHandle.NewStaticSafetyId <EntityTypeHandle>();
            SetCustomErrorMessage(m_StaticSafetyIdForEntityTypeHandle, AtomicSafetyErrorType.Deallocated,
                                  m_CustomDeallocatedErrorMessageBytes);
            SetCustomErrorMessage(m_StaticSafetyIdForEntityTypeHandle, AtomicSafetyErrorType.DeallocatedFromJob,
                                  m_CustomDeallocatedFromJobErrorMessageBytes);
#endif
        }