Refactor allocation flags, SPMD API, and cleanup
Replaced HasFlag with HasOption for allocation flags to avoid boxing and improve performance. Added AllocationOptionExtensions. Reduced FreeListChunkSize default. Removed redundant allocation handle checks. Renamed MultipleAdd to MultiplyAdd in SPMD interfaces and implementations, updating all usages. Expanded SPMD lane interface with new mask/scatter methods and XML docs. Updated GGX jobs and allocation tests. Bumped assembly versions.
This commit is contained in:
@@ -246,11 +246,6 @@ public unsafe struct HashMapHelper<TKey> : IDisposable
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private void AllocateBuffer(int totalSize, int keyOffset, int nextOffset, int bucketOffset, AllocationOption allocationOption)
|
||||
{
|
||||
if (_allocationHandle.Alloc == null)
|
||||
{
|
||||
throw new InvalidOperationException("Target allocation handle does not support allocation.");
|
||||
}
|
||||
|
||||
var buf = (byte*)_allocationHandle.Alloc((uint)totalSize, (nuint)_alignment, allocationOption);
|
||||
|
||||
_buffer = buf;
|
||||
|
||||
@@ -136,11 +136,6 @@ public unsafe struct UnsafeArray<T> : IUnsafeCollection<T>
|
||||
{
|
||||
ArgumentOutOfRangeException.ThrowIfNegative(count);
|
||||
|
||||
if (handle.Alloc == null)
|
||||
{
|
||||
throw new InvalidOperationException("Target allocation handle does not support allocation.");
|
||||
}
|
||||
|
||||
_buffer = (T*)handle.Alloc((nuint)(count * sizeof(T)), AlignOf<T>(), allocationOption);
|
||||
#if MHP_ENABLE_SAFETY_CHECKS
|
||||
_memoryHandle = MemoryHandle.Create(_buffer, (nuint)(count * sizeof(T)));
|
||||
@@ -221,11 +216,6 @@ public unsafe struct UnsafeArray<T> : IUnsafeCollection<T>
|
||||
{
|
||||
ThrowIfNotCreated();
|
||||
|
||||
if (_allocationHandle.Realloc == null)
|
||||
{
|
||||
throw new InvalidOperationException("Target allocation handle does not support reallocation.");
|
||||
}
|
||||
|
||||
if (newSize == Count)
|
||||
{
|
||||
return;
|
||||
|
||||
@@ -272,7 +272,7 @@ public unsafe struct UnsafeBitSet : IDisposable, IEquatable<UnsafeBitSet>
|
||||
var length = RoundToPadding(uints);
|
||||
|
||||
_bits.Resize(length, option);
|
||||
if (!option.HasFlag(AllocationOption.Clear))
|
||||
if (!option.HasOption(AllocationOption.Clear))
|
||||
{
|
||||
_bits.AsSpan()[oldSize..].Clear();
|
||||
}
|
||||
|
||||
@@ -179,13 +179,8 @@ public unsafe struct UnsafeParallelHashMap<TKey, TValue> : IDisposable
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private void AllocateBuffer(UnsafeParallelHashMapData<TKey, TValue>* data, int totalSize, int keyOffset, int valueOffset, int nextOffset, int bucketOffset, AllocationOption allocationOption)
|
||||
private readonly void AllocateBuffer(UnsafeParallelHashMapData<TKey, TValue>* data, int totalSize, int keyOffset, int valueOffset, int nextOffset, int bucketOffset, AllocationOption allocationOption)
|
||||
{
|
||||
if (data->allocationHandle.Alloc == null)
|
||||
{
|
||||
throw new InvalidOperationException("Target allocation handle does not support allocation.");
|
||||
}
|
||||
|
||||
var buf = (byte*)data->allocationHandle.Alloc((uint)totalSize, (nuint)data->alignment, allocationOption);
|
||||
|
||||
data->buffer = buf;
|
||||
|
||||
@@ -135,7 +135,7 @@ public unsafe struct UnsafeSlotMap<T> : IUnsafeCollection<T>
|
||||
for (var i = 0; i < initialChunks; i++)
|
||||
{
|
||||
_chunks[i] = new UnsafeArray<SlotEntry>(_CHUNK_SIZE, handle, allocationOption);
|
||||
if (!allocationOption.HasFlag(AllocationOption.Clear))
|
||||
if (!allocationOption.HasOption(AllocationOption.Clear))
|
||||
{
|
||||
_chunks[i].AsSpan().Clear();
|
||||
}
|
||||
@@ -144,7 +144,7 @@ public unsafe struct UnsafeSlotMap<T> : IUnsafeCollection<T>
|
||||
_freeSlots = new UnsafeQueue<int>(capacity, handle, allocationOption);
|
||||
_validBits = new UnsafeBitSet(_capacity, handle, allocationOption);
|
||||
|
||||
if (!allocationOption.HasFlag(AllocationOption.Clear))
|
||||
if (!allocationOption.HasOption(AllocationOption.Clear))
|
||||
{
|
||||
_validBits.ClearAll();
|
||||
}
|
||||
@@ -190,7 +190,7 @@ public unsafe struct UnsafeSlotMap<T> : IUnsafeCollection<T>
|
||||
for (var i = _capacity / _CHUNK_SIZE; i < newChunkCount; i++)
|
||||
{
|
||||
_chunks[i] = new UnsafeArray<SlotEntry>(_CHUNK_SIZE, _handle, _allocationOption);
|
||||
if (!_allocationOption.HasFlag(AllocationOption.Clear))
|
||||
if (!_allocationOption.HasOption(AllocationOption.Clear))
|
||||
{
|
||||
_chunks[i].AsSpan().Clear();
|
||||
}
|
||||
|
||||
@@ -112,7 +112,7 @@ public unsafe struct UnsafeSparseSet<T> : IUnsafeCollection<T>
|
||||
_reverse = new UnsafeArray<int>(capacity, handle, allocationOption);
|
||||
_freeSparse = new UnsafeStack<int>(capacity, handle, allocationOption);
|
||||
|
||||
if (!allocationOption.HasFlag(AllocationOption.Clear))
|
||||
if (!allocationOption.HasOption(AllocationOption.Clear))
|
||||
{
|
||||
_generations.AsSpan().Clear();
|
||||
_sparse.AsSpan().Clear();
|
||||
|
||||
Reference in New Issue
Block a user