From e0918b225cb5e2181859c8970c8d74228d12cbfe Mon Sep 17 00:00:00 2001 From: Mike Baker <1426795+mbaker3@users.noreply.github.com> Date: Tue, 11 Apr 2023 15:11:28 -0400 Subject: [PATCH] CDFE and DBFE writers - Disable safety and document issue --- Scripts/Runtime/Entities/Data/CDFEWriter.cs | 2 ++ .../Runtime/Entities/Data/DBFEForExclusiveWrite.cs | 12 +++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/Scripts/Runtime/Entities/Data/CDFEWriter.cs b/Scripts/Runtime/Entities/Data/CDFEWriter.cs index a8e65e27..c3fe8959 100644 --- a/Scripts/Runtime/Entities/Data/CDFEWriter.cs +++ b/Scripts/Runtime/Entities/Data/CDFEWriter.cs @@ -20,6 +20,8 @@ namespace Anvil.Unity.DOTS.Entities [BurstCompatible] public struct CDFEWriter where T : struct, IComponentData { + // TODO: #197 - Improve Safety. Currently unable to detect parallel writing from multiple jobs. + // Required to allow JobPart patterns [NativeDisableContainerSafetyRestriction] [NativeDisableParallelForRestriction] private ComponentDataFromEntity m_CDFE; diff --git a/Scripts/Runtime/Entities/Data/DBFEForExclusiveWrite.cs b/Scripts/Runtime/Entities/Data/DBFEForExclusiveWrite.cs index 9bbc85b6..ffdd47ff 100644 --- a/Scripts/Runtime/Entities/Data/DBFEForExclusiveWrite.cs +++ b/Scripts/Runtime/Entities/Data/DBFEForExclusiveWrite.cs @@ -1,4 +1,5 @@ using Unity.Collections; +using Unity.Collections.LowLevel.Unsafe; using Unity.Entities; namespace Anvil.Unity.DOTS.Entities @@ -10,10 +11,19 @@ namespace Anvil.Unity.DOTS.Entities /// To be used in jobs that allow for updating a specific instance in the DBFE /// /// The type of to update. + /// + /// NOTE: The has the + /// applied meaning that Unity will not issue + /// safety warnings when using it in jobs. This is because there might be many jobs of the same type but + /// representing different s and Unity's safety system gets upset if you straddle + /// across the jobs. + /// [BurstCompatible] public struct DBFEForExclusiveWrite where T : struct, IBufferElementData { - [NativeDisableParallelForRestriction] [WriteOnly] + // TODO: #197 - Improve Safety. Currently unable to detect parallel writing from multiple jobs. + // Required to allow JobPart patterns + [NativeDisableContainerSafetyRestriction] [NativeDisableParallelForRestriction] [WriteOnly] private BufferFromEntity m_DBFE; public DBFEForExclusiveWrite(SystemBase system)