Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CDFE and DBFE writers - Disable safety and document issue #209

Merged
merged 1 commit into from
Apr 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Scripts/Runtime/Entities/Data/CDFEWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ namespace Anvil.Unity.DOTS.Entities
[BurstCompatible]
public struct CDFEWriter<T> 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<T> m_CDFE;

Expand Down
12 changes: 11 additions & 1 deletion Scripts/Runtime/Entities/Data/DBFEForExclusiveWrite.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Unity.Collections;
using Unity.Collections.LowLevel.Unsafe;
using Unity.Entities;

namespace Anvil.Unity.DOTS.Entities
Expand All @@ -10,10 +11,19 @@ namespace Anvil.Unity.DOTS.Entities
/// To be used in jobs that allow for updating a specific instance in the DBFE
/// </summary>
/// <typeparam name="T">The type of <see cref="IBufferElementData"/> to update.</typeparam>
/// <remarks>
/// NOTE: The <see cref="BufferFromEntity{T}"/> has the
/// <see cref="NativeDisableContainerSafetyRestrictionAttribute"/> 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 <see cref="AbstractTaskDriver"/>s and Unity's safety system gets upset if you straddle
/// across the jobs.
/// </remarks>
[BurstCompatible]
public struct DBFEForExclusiveWrite<T> 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<T> m_DBFE;

public DBFEForExclusiveWrite(SystemBase system)
Expand Down