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

Update TextureAnimatorSystem to compile under 2018.1 when !USE_SAFE_JOBS #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
54 changes: 28 additions & 26 deletions StressTesting/Assets/Scripts/Components/TextureAnimatorSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ struct CullAndComputeParameters : IJobParallelFor
[ReadOnly]
public NativeArray<IntPtr> BufferPointers;

public void Execute(int i)
public unsafe void Execute(int i)
{
var unitTransform = unitTransformData[i];
float distance = math.length(CameraPosition - unitTransform.Position);
Expand All @@ -249,52 +249,52 @@ public void Execute(int i)
int writeIndex = BufferCounterLod0.Increment();

//unitPositions[writeIndex] = unitTransform.Position;
UnsafeUtility.WriteArrayElement(BufferPointers[0], writeIndex, position);
UnsafeUtility.WriteArrayElement((void*) BufferPointers[0], writeIndex, position);

//unitRotations[writeIndex] = Quaternion.LookRotation(unitTransform.Forward, new Vector3(0.0f, 1.0f, 0.0f) /* Vector3.up */);
UnsafeUtility.WriteArrayElement(BufferPointers[1], writeIndex, rotation);
UnsafeUtility.WriteArrayElement((void*) BufferPointers[1], writeIndex, rotation);

//textureCoordinates[writeIndex] = animationData[i].AnimationNormalizedTime * clip.TextureRange + clip.TextureOffset;
UnsafeUtility.WriteArrayElement(BufferPointers[2], writeIndex, texturePosition);
UnsafeUtility.WriteArrayElement((void*) BufferPointers[2], writeIndex, texturePosition);
}
else if (distance < DistanceMaxLod1)
{
int writeIndex = BufferCounterLod1.Increment();

//unitPositions[writeIndex] = unitTransform.Position;
UnsafeUtility.WriteArrayElement(BufferPointers[3], writeIndex, position);
UnsafeUtility.WriteArrayElement((void*) BufferPointers[3], writeIndex, position);

//unitRotations[writeIndex] = Quaternion.LookRotation(unitTransform.Forward, new Vector3(0.0f, 1.0f, 0.0f) /* Vector3.up */);
UnsafeUtility.WriteArrayElement(BufferPointers[4], writeIndex, rotation);
UnsafeUtility.WriteArrayElement((void*) BufferPointers[4], writeIndex, rotation);

//textureCoordinates[writeIndex] = animationData[i].AnimationNormalizedTime * clip.TextureRange + clip.TextureOffset;
UnsafeUtility.WriteArrayElement(BufferPointers[5], writeIndex, texturePosition);
UnsafeUtility.WriteArrayElement((void*) BufferPointers[5], writeIndex, texturePosition);
}
else if (distance < DistanceMaxLod2)
{
int writeIndex = BufferCounterLod2.Increment();

//unitPositions[writeIndex] = unitTransform.Position;
UnsafeUtility.WriteArrayElement(BufferPointers[6], writeIndex, position);
UnsafeUtility.WriteArrayElement((void*) BufferPointers[6], writeIndex, position);

//unitRotations[writeIndex] = Quaternion.LookRotation(unitTransform.Forward, new Vector3(0.0f, 1.0f, 0.0f) /* Vector3.up */);
UnsafeUtility.WriteArrayElement(BufferPointers[7], writeIndex, rotation);
UnsafeUtility.WriteArrayElement((void*) BufferPointers[7], writeIndex, rotation);

//textureCoordinates[writeIndex] = animationData[i].AnimationNormalizedTime * clip.TextureRange + clip.TextureOffset;
UnsafeUtility.WriteArrayElement(BufferPointers[8], writeIndex, texturePosition);
UnsafeUtility.WriteArrayElement((void*) BufferPointers[8], writeIndex, texturePosition);
}
else
{
int writeIndex = BufferCounterLod3.Increment();

//unitPositions[writeIndex] = unitTransform.Position;
UnsafeUtility.WriteArrayElement(BufferPointers[9], writeIndex, position);
UnsafeUtility.WriteArrayElement((void*) BufferPointers[9], writeIndex, position);

//unitRotations[writeIndex] = Quaternion.LookRotation(unitTransform.Forward, new Vector3(0.0f, 1.0f, 0.0f) /* Vector3.up */);
UnsafeUtility.WriteArrayElement(BufferPointers[10], writeIndex, rotation);
UnsafeUtility.WriteArrayElement((void*) BufferPointers[10], writeIndex, rotation);

//textureCoordinates[writeIndex] = animationData[i].AnimationNormalizedTime * clip.TextureRange + clip.TextureOffset;
UnsafeUtility.WriteArrayElement(BufferPointers[11], writeIndex, texturePosition);
UnsafeUtility.WriteArrayElement((void*) BufferPointers[11], writeIndex, texturePosition);
}
}
}
Expand Down Expand Up @@ -688,11 +688,12 @@ private void ComputeFences(ComponentDataArray<TextureAnimatorData> textureAnimat

#if !USE_SAFE_JOBS
[NativeContainer]
public struct IntHolder
public struct IntHolder : IDisposable
{
#if ENABLE_UNITY_COLLECTIONS_CHECKS
public AtomicSafetyHandle m_Safety;
public DisposeSentinel m_DisposeSentinel;
internal AtomicSafetyHandle m_Safety;
[NativeSetClassTypeToNullOnSchedule]
internal DisposeSentinel m_DisposeSentinel;
#endif

[NativeContainer]
Expand All @@ -707,6 +708,7 @@ public struct InnerData
public int Integer;
}

[NativeDisableUnsafePtrRestriction]
public IntPtr Data;

public bool IsCreated { get { return Data != IntPtr.Zero; } }
Expand All @@ -716,12 +718,12 @@ public struct InnerData
public unsafe IntHolder(Allocator allocator)
{
this.allocator = allocator;
Data = UnsafeUtility.Malloc(sizeof(HolderData), 4, this.allocator);
((HolderData*)Data)->InnerData = UnsafeUtility.Malloc((ulong)sizeof(InnerData), 4, this.allocator);
Data = (IntPtr) UnsafeUtility.Malloc(sizeof(HolderData), 4, this.allocator);
((HolderData*)Data)->InnerData = (IntPtr) UnsafeUtility.Malloc(sizeof(InnerData), 4, this.allocator);
((InnerData*)((HolderData*)Data)->InnerData)->Integer = -1;

#if ENABLE_UNITY_COLLECTIONS_CHECKS
DisposeSentinel.Create(Data, this.allocator, out m_Safety, out m_DisposeSentinel, 0, Deallocate);
DisposeSentinel.Create(out m_Safety, out m_DisposeSentinel, 0);
#endif
}

Expand All @@ -739,9 +741,9 @@ private static unsafe void Deallocate(IntPtr data, Allocator alloc)
{
HolderData* holderData = (HolderData*)data;

UnsafeUtility.Free(holderData->InnerData, alloc);
UnsafeUtility.Free((void*) holderData->InnerData, alloc);
holderData->InnerData = IntPtr.Zero;
UnsafeUtility.Free(data, alloc);
UnsafeUtility.Free((void*) data, alloc);
}

public unsafe int Increment()
Expand Down Expand Up @@ -791,9 +793,9 @@ public class InstancedSkinningDrawer : IDisposable
private ComputeBuffer objectPositionsBuffer;

#if !USE_SAFE_JOBS
public NativeArray<float> TextureCoordinates;
public NativeArray<float3> TextureCoordinates;
public NativeArray<float4> ObjectPositions;
public NativeArray<quaternion> ObjectRotations;
public NativeArray<float4> ObjectRotations;

public NativeArray<IntPtr> BufferPointers;
public IntHolder BufferCounter;
Expand Down Expand Up @@ -841,9 +843,9 @@ public unsafe InstancedSkinningDrawer(TextureAnimatorSystem.DataPerUnitType data
#if !USE_SAFE_JOBS
BufferPointers = new NativeArray<IntPtr>(3, Allocator.Persistent);

BufferPointers[0] = ObjectPositions.GetUnsafeBufferPointerWithoutChecks();
BufferPointers[1] = ObjectRotations.GetUnsafeBufferPointerWithoutChecks();
BufferPointers[2] = TextureCoordinates.GetUnsafeBufferPointerWithoutChecks();
BufferPointers[0] = (IntPtr) NativeArrayUnsafeUtility.GetUnsafeBufferPointerWithoutChecks(ObjectPositions);
BufferPointers[1] = (IntPtr) NativeArrayUnsafeUtility.GetUnsafeBufferPointerWithoutChecks(ObjectRotations);
BufferPointers[2] = (IntPtr) NativeArrayUnsafeUtility.GetUnsafeBufferPointerWithoutChecks(TextureCoordinates);
BufferCounter = new IntHolder(Allocator.Persistent);
#endif

Expand Down