Skip to content

Commit

Permalink
Version 0.7.3 Release [Bugfix]
Browse files Browse the repository at this point in the history
Bugfix release
  • Loading branch information
Dreaming381 committed Jun 18, 2023
1 parent 9ea1ce3 commit c1e73e9
Show file tree
Hide file tree
Showing 13 changed files with 168 additions and 55 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@ Versioning](http://semver.org/spec/v2.0.0.html).
You can find changelogs for the individual modules inside the Documentation\~
directory.

## [0.7.4] – 2023-6-18

Officially supports Entities [1.0.10]

### Changed

- Updated Core to v0.7.4
- Updated Kinemation to v0.7.4

## [0.7.3] – 2023-6-10

Officially supports Entities [1.0.10]
Expand Down
1 change: 1 addition & 0 deletions Core/Containers/DestroyCommandBuffer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ namespace Latios
/// A specialized variant of the EntityCommandBuffer exclusively for destroying entities.
/// Destroyed entities automatically account for LinkedEntityGroup at the time of playback.
/// </summary>
[BurstCompile]
public unsafe struct DestroyCommandBuffer : INativeDisposable
{
#region Structure
Expand Down
10 changes: 7 additions & 3 deletions Kinemation/Components/InternalComponents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -383,16 +383,20 @@ public JobHandle TryDispose(JobHandle inputDeps)

internal partial struct ExposedSkeletonBoundsArrays : ICollectionComponent
{
public NativeList<AABB> allAabbs;
public NativeList<AABB> batchedAabbs;
public const int kCountPerBatch = 1 << 32; // Todo: Is there a better size?
public NativeList<AABB> allAabbs;
public NativeList<AABB> batchedAabbs;
public NativeList<AABB> allAabbsPreOffset;
public NativeList<float> meshOffsets;
public const int kCountPerBatch = 1 << 32; // Todo: Is there a better size?

public JobHandle TryDispose(JobHandle inputDeps)
{
if (!allAabbs.IsCreated)
return inputDeps;

inputDeps = allAabbs.Dispose(inputDeps);
inputDeps = allAabbsPreOffset.Dispose(inputDeps);
inputDeps = meshOffsets.Dispose(inputDeps);
return batchedAabbs.Dispose(inputDeps);
}
}
Expand Down
4 changes: 2 additions & 2 deletions Kinemation/Components/OptimizedSkeletonAspect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,10 @@ public void SyncHistory()
{
if (needsHistorySync)
{
m_skeletonState.ValueRW.state &= ~OptimizedSkeletonState.Flags.NeedsHistorySync;
if (m_currentBaseRootIndexWrite != 0)
{
// The buffers have already been rotated once. Nothing to sync.
m_skeletonState.ValueRW.state &= ~OptimizedSkeletonState.Flags.NeedsHistorySync;
}
else
{
Expand Down Expand Up @@ -191,7 +191,7 @@ public void ForceInitialize()
array.GetSubArray(requiredBones * 2, requiredBones * 2).CopyFrom(array.GetSubArray(0, requiredBones * 2));
array.GetSubArray(requiredBones * 4, requiredBones * 2).CopyFrom(array.GetSubArray(0, requiredBones * 2));
}
else
else if (boneCount < requiredBones)
{
m_boneTransforms.Resize(requiredBones * 6, NativeArrayOptions.ClearMemory);
m_skeletonState.ValueRW.state |= OptimizedSkeletonState.Flags.NeedsHistorySync;
Expand Down
2 changes: 1 addition & 1 deletion Kinemation/Systems/Culling/SkinningDispatchSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ protected override IEnumerable<bool> UpdatePhase()
var perChunkPrefixSums = CollectionHelper.CreateNativeArray<PerChunkPrefixSums>(skeletonChunkCount,
WorldUpdateAllocator,
NativeArrayOptions.UninitializedMemory);
var meshChunks = new NativeList<ArchetypeChunk>(m_skinnedMeshMetaQuery.CalculateChunkCountWithoutFiltering(), WorldUpdateAllocator);
var meshChunks = new NativeList<ArchetypeChunk>(m_skinnedMeshMetaQuery.CalculateEntityCountWithoutFiltering(), WorldUpdateAllocator);
var requestsBlockList =
new UnsafeParallelBlockList(UnsafeUtility.SizeOf<MeshSkinningRequestWithSkeletonTarget>(), 256, WorldUpdateAllocator);
var groupedSkinningRequestsStartsAndCounts = new NativeList<int2>(WorldUpdateAllocator);
Expand Down
122 changes: 90 additions & 32 deletions Kinemation/Systems/PostBatching/CombineExposedBonesSystem.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#if !LATIOS_TRANSFORMS_UNCACHED_QVVS && !LATIOS_TRANSFORMS_UNITY
using Latios;
using Latios.Psyshock;
using Unity.Burst;
using Unity.Burst.Intrinsics;
Expand All @@ -10,14 +9,17 @@
using Unity.Jobs.LowLevel.Unsafe;
using Unity.Mathematics;

using static Unity.Entities.SystemAPI;

namespace Latios.Kinemation
{
[RequireMatchingQueriesForUpdate]
[DisableAutoCreation]
[BurstCompile]
public partial struct CombineExposedBonesSystem : ISystem
{
EntityQuery m_query;
EntityQuery m_boneQuery;
EntityQuery m_skeletonQuery;

LatiosWorldUnmanaged latiosWorld;

Expand All @@ -28,12 +30,15 @@ public void OnCreate(ref SystemState state)
{
latiosWorld = state.GetLatiosWorldUnmanaged();

m_query = state.Fluent().WithAll<BoneWorldBounds>(true).WithAll<BoneCullingIndex>(true).Build();
m_boneQuery = state.Fluent().WithAll<BoneWorldBounds>(true).WithAll<BoneCullingIndex>(true).Build();
m_skeletonQuery = state.Fluent().WithAll<ExposedSkeletonCullingIndex>(true).WithAll<SkeletonBoundsOffsetFromMeshes>(true).Build();

latiosWorld.worldBlackboardEntity.AddOrSetCollectionComponentAndDisposeOld(new ExposedSkeletonBoundsArrays
{
allAabbs = new NativeList<AABB>(Allocator.Persistent),
batchedAabbs = new NativeList<AABB>(Allocator.Persistent)
allAabbs = new NativeList<AABB>(Allocator.Persistent),
batchedAabbs = new NativeList<AABB>(Allocator.Persistent),
allAabbsPreOffset = new NativeList<AABB>(Allocator.Persistent),
meshOffsets = new NativeList<float>(Allocator.Persistent)
});

m_boneWorldBoundsHandle = state.GetComponentTypeHandle<BoneWorldBounds>(true);
Expand All @@ -58,44 +63,55 @@ public void OnUpdate(ref SystemState state)
for (int i = 0; i < JobsUtility.MaxJobThreadCount; i++)
perThreadBitArrays[i] = default;

state.Dependency = new FindDirtyBoundsJob
var bonesJH = new FindDirtyBoundsJob
{
boundsHandle = m_boneWorldBoundsHandle,
indexHandle = m_boneCullingIndexHandle,
maxBitIndex = exposedCullingIndexManager.maxIndex,
perThreadBitArrays = perThreadBitArrays,
allocator = state.WorldUpdateAllocator,
lastSystemVersion = state.LastSystemVersion,
}.ScheduleParallel(m_query, state.Dependency);
}.ScheduleParallel(m_boneQuery, state.Dependency);

state.Dependency = new CollapseBitsJob
bonesJH = new CollapseBitsJob
{
perThreadBitArrays = perThreadBitArrays
}.Schedule(state.Dependency);
}.Schedule(bonesJH);

var perThreadBoundsArrays = state.WorldUnmanaged.UpdateAllocator.AllocateNativeArray<UnsafeList<Aabb> >(JobsUtility.MaxJobThreadCount);
for (int i = 0; i < JobsUtility.MaxJobThreadCount; i++)
perThreadBoundsArrays[i] = default;

state.Dependency = new CombineBoundsPerThreadJob
bonesJH = new CombineBoundsPerThreadJob
{
boundsHandle = m_boneWorldBoundsHandle,
indexHandle = m_boneCullingIndexHandle,
maxBitIndex = exposedCullingIndexManager.maxIndex,
perThreadBitArrays = perThreadBitArrays,
perThreadBoundsArrays = perThreadBoundsArrays,
allocator = state.WorldUpdateAllocator,
finalAabbsToResize = boundsArrays.allAabbs,
finalBatchAabbsToResize = boundsArrays.batchedAabbs,
finalAabbsPreOffsetsToResize = boundsArrays.allAabbsPreOffset,
offsetsByIndexToResize = boundsArrays.meshOffsets,
}.ScheduleParallel(m_boneQuery, bonesJH);

var skeletonsJH = new CollectSkeletonMeshBoundsOffsetJob
{
boundsHandle = m_boneWorldBoundsHandle,
indexHandle = m_boneCullingIndexHandle,
maxBitIndex = exposedCullingIndexManager.maxIndex,
perThreadBitArrays = perThreadBitArrays,
perThreadBoundsArrays = perThreadBoundsArrays,
allocator = state.WorldUpdateAllocator,
finalAabbsToResize = boundsArrays.allAabbs,
finalBatchAabbsToResize = boundsArrays.batchedAabbs
}.ScheduleParallel(m_query, state.Dependency);
indexHandle = GetComponentTypeHandle<ExposedSkeletonCullingIndex>(true),
offsetsHandle = GetComponentTypeHandle<SkeletonBoundsOffsetFromMeshes>(true),
offsetsByIndex = boundsArrays.meshOffsets.AsDeferredJobArray()
}.ScheduleParallel(m_skeletonQuery, bonesJH);

state.Dependency = new MergeThreadBoundsJob
{
perThreadBitArrays = perThreadBitArrays,
perThreadBoundsArrays = perThreadBoundsArrays,
finalAabbs = boundsArrays.allAabbs,
finalBatchAabbs = boundsArrays.batchedAabbs
}.ScheduleBatch(exposedCullingIndexManager.maxIndex.Value + 1, 32, state.Dependency);
offsetsByIndex = boundsArrays.meshOffsets.AsDeferredJobArray(),
finalAabbsPreOffsets = boundsArrays.allAabbsPreOffset.AsDeferredJobArray(),
finalAabbs = boundsArrays.allAabbs.AsDeferredJobArray(),
finalBatchAabbs = boundsArrays.batchedAabbs.AsDeferredJobArray()
}.ScheduleBatch(exposedCullingIndexManager.maxIndex.Value + 1, 32, skeletonsJH);
}

[BurstCompile]
Expand Down Expand Up @@ -184,8 +200,10 @@ struct CombineBoundsPerThreadJob : IJobChunk
[NativeDisableParallelForRestriction] public NativeArray<UnsafeList<Aabb> > perThreadBoundsArrays;
public Allocator allocator;

[NativeDisableParallelForRestriction] public NativeList<AABB> finalAabbsToResize;
[NativeDisableParallelForRestriction] public NativeList<AABB> finalBatchAabbsToResize;
[NativeDisableParallelForRestriction] public NativeList<AABB> finalAabbsToResize;
[NativeDisableParallelForRestriction] public NativeList<AABB> finalAabbsPreOffsetsToResize;
[NativeDisableParallelForRestriction] public NativeList<AABB> finalBatchAabbsToResize;
[NativeDisableParallelForRestriction] public NativeList<float> offsetsByIndexToResize;

[NativeSetThreadIndex] int m_NativeThreadIndex;

Expand Down Expand Up @@ -223,7 +241,9 @@ public void Execute(in ArchetypeChunk chunk, int unfilteredChunkIndex, bool useE
int indexCount = maxBitIndex.Value + 1;
if (finalAabbsToResize.Length < indexCount)
{
finalAabbsToResize.Length = indexCount;
finalAabbsToResize.Length = indexCount;
finalAabbsPreOffsetsToResize.Length = indexCount;
offsetsByIndexToResize.Length = indexCount;

int batchCount = indexCount / 32;
if (indexCount % 32 != 0)
Expand All @@ -238,14 +258,42 @@ public void Execute(in ArchetypeChunk chunk, int unfilteredChunkIndex, bool useE
}
}

[BurstCompile]
struct CollectSkeletonMeshBoundsOffsetJob : IJobChunk
{
[ReadOnly] public ComponentTypeHandle<ExposedSkeletonCullingIndex> indexHandle;
[ReadOnly] public ComponentTypeHandle<SkeletonBoundsOffsetFromMeshes> offsetsHandle;

[NativeDisableParallelForRestriction] public NativeArray<float> offsetsByIndex;
public uint lastSystemVersion;

public void Execute(in ArchetypeChunk chunk, int unfilteredChunkIndex, bool useEnabledMask, in v128 chunkEnabledMask)
{
if (!(chunk.DidChange(ref indexHandle, lastSystemVersion) || chunk.DidChange(ref offsetsHandle, lastSystemVersion)))
return;

var indices = chunk.GetNativeArray(ref indexHandle);
var srcOffsets = chunk.GetNativeArray(ref offsetsHandle);

for (int i = 0; i < chunk.Count; i++)
{
var index = indices[i].cullingIndex;
if (index < offsetsByIndex.Length)
offsetsByIndex[index] = srcOffsets[i].radialBoundsInWorldSpace;
}
}
}

[BurstCompile]
struct MergeThreadBoundsJob : IJobParallelForBatch
{
[ReadOnly] public NativeArray<UnsafeBitArray> perThreadBitArrays;
[ReadOnly] public NativeArray<UnsafeList<Aabb> > perThreadBoundsArrays;
[ReadOnly] public NativeArray<float> offsetsByIndex;

[NativeDisableParallelForRestriction] public NativeList<AABB> finalAabbs;
[NativeDisableParallelForRestriction] public NativeList<AABB> finalBatchAabbs;
[NativeDisableParallelForRestriction] public NativeArray<AABB> finalAabbs;
[NativeDisableParallelForRestriction] public NativeArray<AABB> finalAabbsPreOffsets;
[NativeDisableParallelForRestriction] public NativeArray<AABB> finalBatchAabbs;

public void Execute(int startIndex, int count)
{
Expand All @@ -264,14 +312,20 @@ public void Execute(int startIndex, int count)
}
else
{
var aabb = new Aabb(finalAabbs[startIndex + i].Min, finalAabbs[startIndex + i].Max);
var aabb = new Aabb(finalAabbsPreOffsets[startIndex + i].Min, finalAabbsPreOffsets[startIndex + i].Max);
cache.Add(aabb);
batchAabb = Physics.CombineAabb(batchAabb, aabb);
aabb.min -= offsetsByIndex[startIndex + i];
aabb.max += offsetsByIndex[startIndex + i];
finalAabbs[startIndex + i] = FromAabb(aabb);
batchAabb = Physics.CombineAabb(batchAabb, aabb);
}
}

if (mergeMask.Value == 0)
{
finalBatchAabbs[startIndex / 32] = FromAabb(batchAabb);
return;
}

for (int threadIndex = 0; threadIndex < perThreadBoundsArrays.Length; threadIndex++)
{
Expand All @@ -281,16 +335,20 @@ public void Execute(int startIndex, int count)
var tempMask = mergeMask;
for (int i = tempMask.CountTrailingZeros(); i < count; tempMask.SetBits(i, false), i = tempMask.CountTrailingZeros())
{
cache[i] = Physics.CombineAabb(cache[i], perThreadBoundsArrays[threadIndex][startIndex + i]);
batchAabb = Physics.CombineAabb(batchAabb, perThreadBoundsArrays[threadIndex][startIndex + i]);
cache[i] = Physics.CombineAabb(cache[i], perThreadBoundsArrays[threadIndex][startIndex + i]);
}
}

{
var tempMask = mergeMask;
for (int i = tempMask.CountTrailingZeros(); i < count; tempMask.SetBits(i, false), i = tempMask.CountTrailingZeros())
{
finalAabbs[startIndex + i] = FromAabb(cache[i]);
var aabb = cache[i];
finalAabbsPreOffsets[startIndex + i] = FromAabb(aabb);
aabb.min -= offsetsByIndex[startIndex + i];
aabb.max += offsetsByIndex[startIndex + i];
finalAabbs[startIndex + i] = FromAabb(aabb);
batchAabb = Physics.CombineAabb(batchAabb, aabb);
}
finalBatchAabbs[startIndex / 32] = FromAabb(batchAabb);
}
Expand Down
Loading

0 comments on commit c1e73e9

Please sign in to comment.