diff --git a/Misaki.HighPerformance.Image/AnimatedGifEnumerator.cs b/Misaki.HighPerformance.Image/AnimatedGifEnumerator.cs index 137cd51..d92c55f 100644 --- a/Misaki.HighPerformance.Image/AnimatedGifEnumerator.cs +++ b/Misaki.HighPerformance.Image/AnimatedGifEnumerator.cs @@ -1,4 +1,4 @@ -using Misaki.HighPerformance.Image.Runtime; +using Misaki.HighPerformance.Image.Runtime; using System; using System.Collections; using System.Collections.Generic; @@ -86,7 +86,7 @@ internal class AnimatedGifEnumerator : IEnumerator Dispose(false); } - protected unsafe virtual void Dispose(bool disposing) + protected virtual unsafe void Dispose(bool disposing) { if (_gif != null) { diff --git a/Misaki.HighPerformance.Image/Runtime/MemoryStats.cs b/Misaki.HighPerformance.Image/Runtime/MemoryStats.cs index 2fa7880..eefc0b8 100644 --- a/Misaki.HighPerformance.Image/Runtime/MemoryStats.cs +++ b/Misaki.HighPerformance.Image/Runtime/MemoryStats.cs @@ -1,8 +1,8 @@ -using System.Threading; +using System.Threading; namespace Misaki.HighPerformance.Image.Runtime { - internal unsafe static class MemoryStats + internal static unsafe class MemoryStats { private static int _allocations; diff --git a/Misaki.HighPerformance.Jobs/JobExecutor.cs b/Misaki.HighPerformance.Jobs/JobExecutor.cs index 16a125d..455ec37 100644 --- a/Misaki.HighPerformance.Jobs/JobExecutor.cs +++ b/Misaki.HighPerformance.Jobs/JobExecutor.cs @@ -1,6 +1,6 @@ -namespace Misaki.HighPerformance.Jobs; +namespace Misaki.HighPerformance.Jobs; -internal unsafe static class JobExecutor +internal static unsafe class JobExecutor { public static bool Execute(void* pJobData, ref JobRanges jobRanges, ref int remainingBatches, int threadIndex) where T : unmanaged, IJob diff --git a/Misaki.HighPerformance.Jobs/JobScheduler.cs b/Misaki.HighPerformance.Jobs/JobScheduler.cs index 19b661c..9464071 100644 --- a/Misaki.HighPerformance.Jobs/JobScheduler.cs +++ b/Misaki.HighPerformance.Jobs/JobScheduler.cs @@ -1,4 +1,4 @@ -using Misaki.HighPerformance.Collections; +using Misaki.HighPerformance.Collections; using Misaki.HighPerformance.LowLevel.Buffer; using Misaki.HighPerformance.LowLevel.Utilities; using System.Collections.Concurrent; @@ -15,7 +15,7 @@ namespace Misaki.HighPerformance.Jobs; /// of worker threads through job batching and work-stealing mechanisms. This class is thread-safe and can be used in /// multi-threaded environments. However, it must be disposed when no longer needed to release resources and terminate /// worker threads. -public unsafe sealed class JobScheduler : IDisposable +public sealed unsafe class JobScheduler : IDisposable { private const int _SLEEP_THRESHOLD = 100; diff --git a/Misaki.HighPerformance.LowLevel/AssemblyInfo.cs b/Misaki.HighPerformance.LowLevel/AssemblyInfo.cs index e2369bd..4eaa2b2 100644 --- a/Misaki.HighPerformance.LowLevel/AssemblyInfo.cs +++ b/Misaki.HighPerformance.LowLevel/AssemblyInfo.cs @@ -1,6 +1,4 @@ -global using static Misaki.HighPerformance.LowLevel.Utilities.MemoryUtility; - - +global using static Misaki.HighPerformance.LowLevel.Utilities.MemoryUtility; global using unsafe AllocFunc = delegate*; +global using unsafe FreeFunc = delegate*; global using unsafe ReallocFunc = delegate*; -global using unsafe FreeFunc = delegate*; \ No newline at end of file diff --git a/Misaki.HighPerformance.LowLevel/Buffer/MemoryBlock.cs b/Misaki.HighPerformance.LowLevel/Buffer/MemoryBlock.cs index 85aa346..5da2798 100644 --- a/Misaki.HighPerformance.LowLevel/Buffer/MemoryBlock.cs +++ b/Misaki.HighPerformance.LowLevel/Buffer/MemoryBlock.cs @@ -1,4 +1,4 @@ -using System.Runtime.InteropServices; +using System.Runtime.InteropServices; namespace Misaki.HighPerformance.LowLevel.Buffer; @@ -6,7 +6,7 @@ namespace Misaki.HighPerformance.LowLevel.Buffer; /// Represents an allocated memory block with metadata. /// [StructLayout(LayoutKind.Sequential)] -public unsafe readonly struct MemoryBlock +public readonly unsafe struct MemoryBlock { /// /// Pointer to the actual allocated memory. diff --git a/Misaki.HighPerformance.LowLevel/Collections/Contracts/IUnsafeCollection.cs b/Misaki.HighPerformance.LowLevel/Collections/Contracts/IUnsafeCollection.cs index 45e86f8..7478c54 100644 --- a/Misaki.HighPerformance.LowLevel/Collections/Contracts/IUnsafeCollection.cs +++ b/Misaki.HighPerformance.LowLevel/Collections/Contracts/IUnsafeCollection.cs @@ -1,4 +1,4 @@ -using Misaki.HighPerformance.LowLevel.Buffer; +using Misaki.HighPerformance.LowLevel.Buffer; namespace Misaki.HighPerformance.LowLevel.Collections.Contracts; @@ -7,7 +7,7 @@ public unsafe interface IUnsafeCollection : IDisposable /// /// Indicates whether the object has been created. Returns true if the object is created, otherwise false. /// - public bool IsCreated + bool IsCreated { get; } @@ -15,13 +15,13 @@ public unsafe interface IUnsafeCollection : IDisposable /// /// Removes all elements from the collection. The collection will be empty after this operation. /// - public void Clear(); + void Clear(); /// /// Returns a pointer to an unmanaged memory location. This pointer can be used for low-level memory operations. /// /// The method returns a void pointer to the unsafe memory location. - public void* GetUnsafePtr(); + void* GetUnsafePtr(); } public unsafe interface IUnsafeCollection : IUnsafeCollection, IEnumerable @@ -30,7 +30,7 @@ public unsafe interface IUnsafeCollection : IUnsafeCollection, IEnumerable /// /// Gets the number of elements in a collection. The value is read-only. /// - public int Count + int Count { get; } @@ -40,7 +40,7 @@ public unsafe interface IUnsafeCollection : IUnsafeCollection, IEnumerable /// /// This is to adjust the element count of the collection, not the size of the underlying buffer in memory. /// Specifies the new size to which the collection should be adjusted. - public void Resize(int newSize, AllocationOption option); + void Resize(int newSize, AllocationOption option); } public unsafe interface IUnTypedCollection : IUnsafeCollection @@ -48,11 +48,11 @@ public unsafe interface IUnTypedCollection : IUnsafeCollection /// /// The total size of the buffer in bytes. /// - public uint Size + uint Size { get; } - public ref T GetElementAt(uint index) + ref T GetElementAt(uint index) where T : unmanaged; } \ No newline at end of file diff --git a/Misaki.HighPerformance.LowLevel/Collections/UnsafeSlotMap.cs b/Misaki.HighPerformance.LowLevel/Collections/UnsafeSlotMap.cs index 6ff7feb..9a1a6e0 100644 --- a/Misaki.HighPerformance.LowLevel/Collections/UnsafeSlotMap.cs +++ b/Misaki.HighPerformance.LowLevel/Collections/UnsafeSlotMap.cs @@ -1,4 +1,4 @@ -using Misaki.HighPerformance.LowLevel.Buffer; +using Misaki.HighPerformance.LowLevel.Buffer; using Misaki.HighPerformance.LowLevel.Collections.Contracts; using Misaki.HighPerformance.LowLevel.Contracts; using Misaki.HighPerformance.LowLevel.Utilities; @@ -93,7 +93,7 @@ public unsafe struct UnsafeSlotMap : IUnsafeCollection { throw new ArgumentOutOfRangeException(nameof(capacity), "Capacity must be greater than zero."); } - + _data = new UnsafeArray(capacity, ref handle, allocationOption); _freeSlots = new UnsafeQueue(capacity, ref handle, allocationOption); _count = 0; @@ -266,7 +266,7 @@ public unsafe struct UnsafeSlotMap : IUnsafeCollection ref var slot = ref _data[slotIndex]; - if (!slot.isValid|| slot.generation != generation) + if (!slot.isValid || slot.generation != generation) { exist = false; return ref Unsafe.NullRef(); @@ -292,7 +292,7 @@ public unsafe struct UnsafeSlotMap : IUnsafeCollection _count = 0; } - public unsafe readonly void* GetUnsafePtr() + public readonly unsafe void* GetUnsafePtr() { return _data.GetUnsafePtr(); } diff --git a/Misaki.HighPerformance.LowLevel/Collections/UnsafeSparseSet.cs b/Misaki.HighPerformance.LowLevel/Collections/UnsafeSparseSet.cs index 6d88139..c109adb 100644 --- a/Misaki.HighPerformance.LowLevel/Collections/UnsafeSparseSet.cs +++ b/Misaki.HighPerformance.LowLevel/Collections/UnsafeSparseSet.cs @@ -1,4 +1,4 @@ -using Misaki.HighPerformance.LowLevel.Buffer; +using Misaki.HighPerformance.LowLevel.Buffer; using Misaki.HighPerformance.LowLevel.Collections.Contracts; using Misaki.HighPerformance.LowLevel.Contracts; using Misaki.HighPerformance.LowLevel.Utilities; @@ -61,7 +61,7 @@ public unsafe struct UnsafeSparseSet : IUnsafeCollection get => Current; } - public unsafe readonly void Dispose() + public readonly unsafe void Dispose() { } } diff --git a/Misaki.HighPerformance.LowLevel/Contracts/IAllocator.cs b/Misaki.HighPerformance.LowLevel/Contracts/IAllocator.cs index 6f123f6..a676753 100644 --- a/Misaki.HighPerformance.LowLevel/Contracts/IAllocator.cs +++ b/Misaki.HighPerformance.LowLevel/Contracts/IAllocator.cs @@ -1,9 +1,9 @@ -namespace Misaki.HighPerformance.LowLevel.Contracts; +namespace Misaki.HighPerformance.LowLevel.Contracts; /// /// A structure that encapsulates function pointers for memory allocation operations. /// -public unsafe readonly struct AllocationHandle +public readonly unsafe struct AllocationHandle { /// /// Gets a pointer to the allocator instance associated with this allocation handle. diff --git a/Misaki.HighPerformance.LowLevel/Utilities/UnsafeCollectionExtensions.cs b/Misaki.HighPerformance.LowLevel/Utilities/UnsafeCollectionExtensions.cs index 2a240d7..a5f3d73 100644 --- a/Misaki.HighPerformance.LowLevel/Utilities/UnsafeCollectionExtensions.cs +++ b/Misaki.HighPerformance.LowLevel/Utilities/UnsafeCollectionExtensions.cs @@ -1,4 +1,4 @@ -using Misaki.HighPerformance.LowLevel.Buffer; +using Misaki.HighPerformance.LowLevel.Buffer; using Misaki.HighPerformance.LowLevel.Collections; using Misaki.HighPerformance.LowLevel.Collections.Contracts; using System.Runtime.InteropServices; @@ -9,7 +9,7 @@ namespace Misaki.HighPerformance.LowLevel.Utilities; /// Provides extension methods for copying elements between unsafe collections and spans, converting collections to /// arrays or lists, and searching for values. /// -public unsafe static class UnsafeCollectionExtensions +public static unsafe class UnsafeCollectionExtensions { /// /// Copies elements from a source UnsafeCollection to a destination Span, ensuring both have the same size. diff --git a/Misaki.HighPerformance.Mathematics.CodeGen/Generators/VectorGenerator.cs b/Misaki.HighPerformance.Mathematics.CodeGen/Generators/VectorGenerator.cs index f48208d..b429c16 100644 --- a/Misaki.HighPerformance.Mathematics.CodeGen/Generators/VectorGenerator.cs +++ b/Misaki.HighPerformance.Mathematics.CodeGen/Generators/VectorGenerator.cs @@ -1,8 +1,6 @@ using Microsoft.CodeAnalysis; -using System; using System.Collections.Generic; using System.Linq; -using System.Text; namespace Misaki.HighPerformance.Mathematics.CodeGen.Generators { diff --git a/Misaki.HighPerformance.Mathematics.CodeGen/NumericType.cs b/Misaki.HighPerformance.Mathematics.CodeGen/NumericType.cs deleted file mode 100644 index e09af27..0000000 --- a/Misaki.HighPerformance.Mathematics.CodeGen/NumericType.cs +++ /dev/null @@ -1,109 +0,0 @@ -using System; - -namespace Misaki.HighPerformance.Mathematics.CodeGen -{ - [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct, Inherited = false)] - public class NumericTypeAttribute : Attribute - { - public NumericTypeAttribute(Type componentType, int componentSize, int row, int column, string typePrefix, bool arithmetic = true, bool canInverse = true, Type? elementType = default, Type? vectorType = default) - { - } - } - - [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct, Inherited = false, AllowMultiple = true)] - public class NumericConvertableAttribute : Attribute - { - public NumericConvertableAttribute(string template, params Type[] types) - { - } - } - - [Flags] - public enum SupportedVectorMath - { - None = 0, - Min = 1 << 0, - Max = 1 << 1, - Lerp = 1 << 2, - Unlerp = 1 << 3, - Remap = 1 << 4, - Mad = 1 << 5, - Clamp = 1 << 6, - Saturate = 1 << 7, - Abs = 1 << 8, - Dot = 1 << 9, - Tan = 1 << 10, - TanH = 1 << 11, - Atan = 1 << 12, - Atan2 = 1 << 13, - Cos = 1 << 14, - CosH = 1 << 15, - Acos = 1 << 16, - Sin = 1 << 17, - SinH = 1 << 18, - Asin = 1 << 19, - Floor = 1 << 20, - Ceil = 1 << 21, - Round = 1 << 22, - Trunc = 1 << 23, - Frac = 1 << 24, - Rcp = 1 << 25, - Sign = 1 << 26, - Pow = 1 << 27, - Exp = 1 << 28, - Exp2 = 1 << 29, - Exp10 = 1 << 30, - Log = 1 << 31, - Log2 = 1 << 32, - Log10 = 1 << 33, - Fmod = 1 << 34, - Modf = 1 << 35, - Sqrt = 1 << 36, - Rsqrt = 1 << 37, - Length = 1 << 38, - LengthSq = 1 << 39, - Distance = 1 << 40, - DistanceSq = 1 << 41, - Cross = 1 << 42, - SmoothStep = 1 << 43, - Select = 1 << 44, - Step = 1 << 45, - FaceForward = 1 << 46, - SinCos = 1 << 47, - Any = 1 << 48, - All = 1 << 49, - Normalize = 1 << 50, - Reflect = 1 << 51, - Refract = 1 << 52, - Project = 1 << 53, - CountBits = 1 << 54, - Lzcnt = 1 << 55, - Tzcnt = 1 << 56, - ReverseBits = 1 << 57, - Rol = 1 << 58, - Ror = 1 << 59, - CeilPow2 = 1 << 60, - CeilLog2 = 1 << 61, - FloorLog2 = 1 << 62, - Radians = 1 << 63, - Degrees = 1 << 64, - Cmin = 1 << 65, - Cmax = 1 << 66, - - FloatingPointMask = ~0 & ~(CountBits | Lzcnt | Tzcnt | ReverseBits | Rol | Ror | CeilPow2 | CeilLog2 | FloorLog2), - IntegerMask = Min | Max | Mad | Clamp | Abs | Dot | Sign | Any | All | Select | CountBits | Lzcnt | Tzcnt | ReverseBits | Rol | Ror | CeilPow2 | CeilLog2 | FloorLog2 | Cmin | Cmax, - UnsignedIntegerMask = IntegerMask & ~(Sign), - } - - [Flags] - public enum SupportedMatrixMath - { - Transpose = 1 << 0, - Determinant = 1 << 1, - Inverse = 1 << 2, - Adjugate = 1 << 3, - Cofactor = 1 << 4, - Minor = 1 << 5, - OuterProduct = 1 << 6, - } -} \ No newline at end of file diff --git a/Misaki.HighPerformance.Mathematics.CodeGen/NumericTypesGenerator.cs b/Misaki.HighPerformance.Mathematics.CodeGen/NumericTypesGenerator.cs index d67fa24..e7d6a66 100644 --- a/Misaki.HighPerformance.Mathematics.CodeGen/NumericTypesGenerator.cs +++ b/Misaki.HighPerformance.Mathematics.CodeGen/NumericTypesGenerator.cs @@ -1,4 +1,4 @@ -using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp.Syntax; using Misaki.HighPerformance.Mathematics.CodeGen.Generators; using Misaki.HighPerformance.Mathematics.CodeGen.Models; @@ -14,7 +14,7 @@ namespace Misaki.HighPerformance.Mathematics.CodeGen // Create a provider that finds all types with NumericTypeAttribute var typesWithAttribute = context.SyntaxProvider .ForAttributeWithMetadataName( - fullyQualifiedMetadataName: typeof(NumericTypeAttribute).FullName, + fullyQualifiedMetadataName: "Misaki.HighPerformance.Mathematics.NumericTypeAttribute", predicate: static (node, _) => node is ClassDeclarationSyntax or StructDeclarationSyntax, transform: static (context, _) => GetTypeInfo(context)) .Where(static typeInfo => typeInfo is not null); @@ -52,10 +52,10 @@ namespace Misaki.HighPerformance.Mathematics.CodeGen // Get the attribute data var attribute = typeSymbol.GetAttributes() - .FirstOrDefault(a => a.AttributeClass?.ToDisplayString() == typeof(NumericTypeAttribute).FullName); + .FirstOrDefault(a => a.AttributeClass?.ToDisplayString() == "Misaki.HighPerformance.Mathematics.NumericTypeAttribute"); var convertableAttributes = typeSymbol.GetAttributes() - .Where(a => a.AttributeClass?.ToDisplayString() == typeof(NumericConvertableAttribute).FullName); + .Where(a => a.AttributeClass?.ToDisplayString() == "Misaki.HighPerformance.Mathematics.NumericConvertableAttribute"); if (attribute == null) { diff --git a/Misaki.HighPerformance.Mathematics/Geometry/AABB.cs b/Misaki.HighPerformance.Mathematics/Geometry/AABB.cs index 077ffb9..6e37712 100644 --- a/Misaki.HighPerformance.Mathematics/Geometry/AABB.cs +++ b/Misaki.HighPerformance.Mathematics/Geometry/AABB.cs @@ -1,4 +1,4 @@ -using System.Runtime.CompilerServices; +using System.Runtime.CompilerServices; namespace Misaki.HighPerformance.Mathematics.Geometry; @@ -232,13 +232,13 @@ public struct AABB : IEquatable return !(left == right); } - public readonly override int GetHashCode() + public override readonly int GetHashCode() { return HashCode.Combine(Min, Max); } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly override string ToString() + public override readonly string ToString() { return string.Format("AABB({0}, {1})", Min, Max); } diff --git a/Misaki.HighPerformance.Mathematics/Geometry/OBB.cs b/Misaki.HighPerformance.Mathematics/Geometry/OBB.cs index 31820d4..cfe61e8 100644 --- a/Misaki.HighPerformance.Mathematics/Geometry/OBB.cs +++ b/Misaki.HighPerformance.Mathematics/Geometry/OBB.cs @@ -1,4 +1,4 @@ -namespace Misaki.HighPerformance.Mathematics.Geometry; +namespace Misaki.HighPerformance.Mathematics.Geometry; public struct OBB : IEquatable { @@ -38,7 +38,7 @@ public struct OBB : IEquatable max = centerProjection + r; } - public unsafe readonly bool Overlaps(OBB other) + public readonly unsafe bool Overlaps(OBB other) { // Using the Separating Axis Theorem (SAT) for OBB-OBB intersection test var axes = stackalloc float3[15]; @@ -109,12 +109,12 @@ public struct OBB : IEquatable return Rotation.Equals(other.Rotation) && Center.Equals(other.Center) && Extents.Equals(other.Extents); } - public readonly override bool Equals(object? obj) + public override readonly bool Equals(object? obj) { return obj is OBB obb && Equals(obb); } - public readonly override int GetHashCode() + public override readonly int GetHashCode() { return HashCode.Combine(Rotation, Center, Extents); } diff --git a/Misaki.HighPerformance.Mathematics/Geometry/SphereBounds.cs b/Misaki.HighPerformance.Mathematics/Geometry/SphereBounds.cs index 0e49a63..1c71509 100644 --- a/Misaki.HighPerformance.Mathematics/Geometry/SphereBounds.cs +++ b/Misaki.HighPerformance.Mathematics/Geometry/SphereBounds.cs @@ -1,4 +1,4 @@ -using System.Runtime.CompilerServices; +using System.Runtime.CompilerServices; namespace Misaki.HighPerformance.Mathematics.Geometry; @@ -98,12 +98,12 @@ public struct SphereBounds : IEquatable } } - public readonly override string ToString() + public override readonly string ToString() { return $"Center: {Center}, Radius: {Radius}"; } - public readonly override int GetHashCode() + public override readonly int GetHashCode() { return HashCode.Combine(Center, Radius); } diff --git a/Misaki.HighPerformance.Mathematics/Misaki.HighPerformance.Mathematics.csproj b/Misaki.HighPerformance.Mathematics/Misaki.HighPerformance.Mathematics.csproj index 6b5cca8..2a8e84a 100644 --- a/Misaki.HighPerformance.Mathematics/Misaki.HighPerformance.Mathematics.csproj +++ b/Misaki.HighPerformance.Mathematics/Misaki.HighPerformance.Mathematics.csproj @@ -6,14 +6,14 @@ enable True Misaki - 1.2.5 + 1.2.6 True https://git.personalnas.com/Misaki/Misaki.HighPerformance.git https://git.personalnas.com/Misaki/Misaki.HighPerformance.git - + diff --git a/Misaki.HighPerformance.Mathematics/NumericType.cs b/Misaki.HighPerformance.Mathematics/NumericType.cs new file mode 100644 index 0000000..6c5e6f5 --- /dev/null +++ b/Misaki.HighPerformance.Mathematics/NumericType.cs @@ -0,0 +1,106 @@ +namespace Misaki.HighPerformance.Mathematics; + +[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct, Inherited = false)] +public class NumericTypeAttribute : Attribute +{ + public NumericTypeAttribute(Type componentType, int componentSize, int row, int column, string typePrefix, bool arithmetic = true, bool canInverse = true, Type? elementType = default, Type? vectorType = default) + { + } +} + +[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct, Inherited = false, AllowMultiple = true)] +public class NumericConvertableAttribute : Attribute +{ + public NumericConvertableAttribute(string template, params Type[] types) + { + } +} + +[Flags] +public enum SupportedVectorMath +{ + None = 0, + Min = 1 << 0, + Max = 1 << 1, + Lerp = 1 << 2, + Unlerp = 1 << 3, + Remap = 1 << 4, + Mad = 1 << 5, + Clamp = 1 << 6, + Saturate = 1 << 7, + Abs = 1 << 8, + Dot = 1 << 9, + Tan = 1 << 10, + TanH = 1 << 11, + Atan = 1 << 12, + Atan2 = 1 << 13, + Cos = 1 << 14, + CosH = 1 << 15, + Acos = 1 << 16, + Sin = 1 << 17, + SinH = 1 << 18, + Asin = 1 << 19, + Floor = 1 << 20, + Ceil = 1 << 21, + Round = 1 << 22, + Trunc = 1 << 23, + Frac = 1 << 24, + Rcp = 1 << 25, + Sign = 1 << 26, + Pow = 1 << 27, + Exp = 1 << 28, + Exp2 = 1 << 29, + Exp10 = 1 << 30, + Log = 1 << 31, + Log2 = 1 << 32, + Log10 = 1 << 33, + Fmod = 1 << 34, + Modf = 1 << 35, + Sqrt = 1 << 36, + Rsqrt = 1 << 37, + Length = 1 << 38, + LengthSq = 1 << 39, + Distance = 1 << 40, + DistanceSq = 1 << 41, + Cross = 1 << 42, + SmoothStep = 1 << 43, + Select = 1 << 44, + Step = 1 << 45, + FaceForward = 1 << 46, + SinCos = 1 << 47, + Any = 1 << 48, + All = 1 << 49, + Normalize = 1 << 50, + Reflect = 1 << 51, + Refract = 1 << 52, + Project = 1 << 53, + CountBits = 1 << 54, + Lzcnt = 1 << 55, + Tzcnt = 1 << 56, + ReverseBits = 1 << 57, + Rol = 1 << 58, + Ror = 1 << 59, + CeilPow2 = 1 << 60, + CeilLog2 = 1 << 61, + FloorLog2 = 1 << 62, + Radians = 1 << 63, + Degrees = 1 << 64, + Cmin = 1 << 65, + Cmax = 1 << 66, + + FloatingPointMask = ~0 & ~(CountBits | Lzcnt | Tzcnt | ReverseBits | Rol | Ror | CeilPow2 | CeilLog2 | FloorLog2), + IntegerMask = Min | Max | Mad | Clamp | Abs | Dot | Sign | Any | All | Select | CountBits | Lzcnt | Tzcnt | ReverseBits | Rol | Ror | CeilPow2 | CeilLog2 | FloorLog2 | Cmin | Cmax, + UnsignedIntegerMask = IntegerMask & ~(Sign), +} + +[Flags] +public enum SupportedMatrixMath +{ + Transpose = 1 << 0, + Determinant = 1 << 1, + Inverse = 1 << 2, + Adjugate = 1 << 3, + Cofactor = 1 << 4, + Minor = 1 << 5, + OuterProduct = 1 << 6, +} \ No newline at end of file diff --git a/Misaki.HighPerformance.Mathematics/bool.cs b/Misaki.HighPerformance.Mathematics/bool.cs index 97b5efc..a859332 100644 --- a/Misaki.HighPerformance.Mathematics/bool.cs +++ b/Misaki.HighPerformance.Mathematics/bool.cs @@ -1,5 +1,3 @@ -using Misaki.HighPerformance.Mathematics.CodeGen; - namespace Misaki.HighPerformance.Mathematics; [NumericType(typeof(bool), sizeof(bool), 2, 1, "global::Misaki.HighPerformance.Mathematics.bool", false, vectorType: typeof(byte))] diff --git a/Misaki.HighPerformance.Mathematics/double.cs b/Misaki.HighPerformance.Mathematics/double.cs index 9f0c371..b1fdec4 100644 --- a/Misaki.HighPerformance.Mathematics/double.cs +++ b/Misaki.HighPerformance.Mathematics/double.cs @@ -1,5 +1,3 @@ -using Misaki.HighPerformance.Mathematics.CodeGen; - namespace Misaki.HighPerformance.Mathematics; [NumericType(typeof(double), sizeof(double), 2, 1, "global::Misaki.HighPerformance.Mathematics.double")] diff --git a/Misaki.HighPerformance.Mathematics/float.cs b/Misaki.HighPerformance.Mathematics/float.cs index 18a5b3e..919fc36 100644 --- a/Misaki.HighPerformance.Mathematics/float.cs +++ b/Misaki.HighPerformance.Mathematics/float.cs @@ -1,6 +1,3 @@ -using Misaki.HighPerformance.Mathematics.CodeGen; -using System.Runtime.InteropServices; - namespace Misaki.HighPerformance.Mathematics; [NumericType(typeof(float), sizeof(float), 2, 1, "global::Misaki.HighPerformance.Mathematics.float")] diff --git a/Misaki.HighPerformance.Mathematics/int.cs b/Misaki.HighPerformance.Mathematics/int.cs index aac56b7..5396404 100644 --- a/Misaki.HighPerformance.Mathematics/int.cs +++ b/Misaki.HighPerformance.Mathematics/int.cs @@ -1,5 +1,3 @@ -using Misaki.HighPerformance.Mathematics.CodeGen; - namespace Misaki.HighPerformance.Mathematics; [NumericType(typeof(int), sizeof(int), 2, 1, "global::Misaki.HighPerformance.Mathematics.int")] diff --git a/Misaki.HighPerformance.Mathematics/math.cs b/Misaki.HighPerformance.Mathematics/math.cs index 2742dbc..7739e38 100644 --- a/Misaki.HighPerformance.Mathematics/math.cs +++ b/Misaki.HighPerformance.Mathematics/math.cs @@ -4724,9 +4724,9 @@ public static partial class math /// Vector to return if normalized vector is not finite. /// The normalized vector or the default value if the normalized vector is not finite. [MethodImpl(MethodImplOptions.AggressiveInlining)] - static public float2 normalizesafe(float2 x, float2 defaultvalue = new float2()) + public static float2 normalizesafe(float2 x, float2 defaultvalue = new float2()) { - float len = math.dot(x, x); + var len = math.dot(x, x); return math.select(defaultvalue, x * math.rsqrt(len), len > FLT_MIN_NORMAL); } @@ -4738,9 +4738,9 @@ public static partial class math /// Vector to return if normalized vector is not finite. /// The normalized vector or the default value if the normalized vector is not finite. [MethodImpl(MethodImplOptions.AggressiveInlining)] - static public float3 normalizesafe(float3 x, float3 defaultvalue = new float3()) + public static float3 normalizesafe(float3 x, float3 defaultvalue = new float3()) { - float len = math.dot(x, x); + var len = math.dot(x, x); return math.select(defaultvalue, x * math.rsqrt(len), len > FLT_MIN_NORMAL); } @@ -4752,9 +4752,9 @@ public static partial class math /// Vector to return if normalized vector is not finite. /// The normalized vector or the default value if the normalized vector is not finite. [MethodImpl(MethodImplOptions.AggressiveInlining)] - static public float4 normalizesafe(float4 x, float4 defaultvalue = new float4()) + public static float4 normalizesafe(float4 x, float4 defaultvalue = new float4()) { - float len = math.dot(x, x); + var len = math.dot(x, x); return math.select(defaultvalue, x * math.rsqrt(len), len > FLT_MIN_NORMAL); } @@ -4767,9 +4767,9 @@ public static partial class math /// Vector to return if normalized vector is not finite. /// The normalized vector or the default value if the normalized vector is not finite. [MethodImpl(MethodImplOptions.AggressiveInlining)] - static public double2 normalizesafe(double2 x, double2 defaultvalue = new double2()) + public static double2 normalizesafe(double2 x, double2 defaultvalue = new double2()) { - double len = math.dot(x, x); + var len = math.dot(x, x); return math.select(defaultvalue, x * math.rsqrt(len), len > FLT_MIN_NORMAL); } @@ -4781,9 +4781,9 @@ public static partial class math /// Vector to return if normalized vector is not finite. /// The normalized vector or the default value if the normalized vector is not finite. [MethodImpl(MethodImplOptions.AggressiveInlining)] - static public double3 normalizesafe(double3 x, double3 defaultvalue = new double3()) + public static double3 normalizesafe(double3 x, double3 defaultvalue = new double3()) { - double len = math.dot(x, x); + var len = math.dot(x, x); return math.select(defaultvalue, x * math.rsqrt(len), len > FLT_MIN_NORMAL); } @@ -4795,9 +4795,9 @@ public static partial class math /// Vector to return if normalized vector is not finite. /// The normalized vector or the default value if the normalized vector is not finite. [MethodImpl(MethodImplOptions.AggressiveInlining)] - static public double4 normalizesafe(double4 x, double4 defaultvalue = new double4()) + public static double4 normalizesafe(double4 x, double4 defaultvalue = new double4()) { - double len = math.dot(x, x); + var len = math.dot(x, x); return math.select(defaultvalue, x * math.rsqrt(len), len > FLT_MIN_NORMAL); } @@ -6039,7 +6039,7 @@ public static partial class math [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float2 refract(float2 i, float2 n, float indexOfRefraction) { - float ni = dot(n, i); + var ni = dot(n, i); var k = 1.0f - indexOfRefraction * indexOfRefraction * (1.0f - ni * ni); return select(0.0f, indexOfRefraction * i - (indexOfRefraction * ni + sqrt(k)) * n, k >= 0); } @@ -6052,7 +6052,7 @@ public static partial class math [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float3 refract(float3 i, float3 n, float indexOfRefraction) { - float ni = dot(n, i); + var ni = dot(n, i); var k = 1.0f - indexOfRefraction * indexOfRefraction * (1.0f - ni * ni); return select(0.0f, indexOfRefraction * i - (indexOfRefraction * ni + sqrt(k)) * n, k >= 0); } @@ -6065,7 +6065,7 @@ public static partial class math [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float4 refract(float4 i, float4 n, float indexOfRefraction) { - float ni = dot(n, i); + var ni = dot(n, i); var k = 1.0f - indexOfRefraction * indexOfRefraction * (1.0f - ni * ni); return select(0.0f, indexOfRefraction * i - (indexOfRefraction * ni + sqrt(k)) * n, k >= 0); } @@ -6079,7 +6079,7 @@ public static partial class math [MethodImpl(MethodImplOptions.AggressiveInlining)] public static double2 refract(double2 i, double2 n, double indexOfRefraction) { - double ni = dot(n, i); + var ni = dot(n, i); var k = 1.0 - indexOfRefraction * indexOfRefraction * (1.0 - ni * ni); return select(0.0f, indexOfRefraction * i - (indexOfRefraction * ni + sqrt(k)) * n, k >= 0); } @@ -6092,7 +6092,7 @@ public static partial class math [MethodImpl(MethodImplOptions.AggressiveInlining)] public static double3 refract(double3 i, double3 n, double indexOfRefraction) { - double ni = dot(n, i); + var ni = dot(n, i); var k = 1.0 - indexOfRefraction * indexOfRefraction * (1.0 - ni * ni); return select(0.0f, indexOfRefraction * i - (indexOfRefraction * ni + sqrt(k)) * n, k >= 0); } @@ -6105,7 +6105,7 @@ public static partial class math [MethodImpl(MethodImplOptions.AggressiveInlining)] public static double4 refract(double4 i, double4 n, double indexOfRefraction) { - double ni = dot(n, i); + var ni = dot(n, i); var k = 1.0 - indexOfRefraction * indexOfRefraction * (1.0 - ni * ni); return select(0.0f, indexOfRefraction * i - (indexOfRefraction * ni + sqrt(k)) * n, k >= 0); } @@ -8470,7 +8470,7 @@ public static partial class math const uint Prime4 = 668265263; const uint Prime5 = 374761393; - uint4* p = (uint4*)pBuffer; + var p = (uint4*)pBuffer; var hash = seed + Prime5; if (numBytes >= 16) { diff --git a/Misaki.HighPerformance.Mathematics/quaternion.cs b/Misaki.HighPerformance.Mathematics/quaternion.cs index 5ec0678..8e39421 100644 --- a/Misaki.HighPerformance.Mathematics/quaternion.cs +++ b/Misaki.HighPerformance.Mathematics/quaternion.cs @@ -1,4 +1,4 @@ -using System.Runtime.CompilerServices; +using System.Runtime.CompilerServices; using static Misaki.HighPerformance.Mathematics.math; diff --git a/Misaki.HighPerformance.Mathematics/uint.cs b/Misaki.HighPerformance.Mathematics/uint.cs index 1c9f8a1..4c09705 100644 --- a/Misaki.HighPerformance.Mathematics/uint.cs +++ b/Misaki.HighPerformance.Mathematics/uint.cs @@ -1,5 +1,3 @@ -using Misaki.HighPerformance.Mathematics.CodeGen; - namespace Misaki.HighPerformance.Mathematics; [NumericType(typeof(uint), sizeof(uint), 2, 1, "global::Misaki.HighPerformance.Mathematics.uint")] diff --git a/Misaki.HighPerformance.Test/Program.cs b/Misaki.HighPerformance.Test/Program.cs index a6cc127..13aaf49 100644 --- a/Misaki.HighPerformance.Test/Program.cs +++ b/Misaki.HighPerformance.Test/Program.cs @@ -1,4 +1,4 @@ -//var threadCount = 8; +//var threadCount = 8; //var map = new ConcurrentSlotMap(); //var barrier = new Barrier(threadCount); @@ -43,4 +43,4 @@ using Misaki.HighPerformance.LowLevel.Buffer; using Misaki.HighPerformance.LowLevel.Collections; -var array = new UnsafeArray(10, Allocator.Persistent); \ No newline at end of file +var array = new UnsafeArray(10, Allocator.Persistent); diff --git a/Misaki.HighPerformance.Test/UnitTest/Collections/TestUnsafeSparseSet.cs b/Misaki.HighPerformance.Test/UnitTest/Collections/TestUnsafeSparseSet.cs index c5f2a97..17dc515 100644 --- a/Misaki.HighPerformance.Test/UnitTest/Collections/TestUnsafeSparseSet.cs +++ b/Misaki.HighPerformance.Test/UnitTest/Collections/TestUnsafeSparseSet.cs @@ -1,4 +1,4 @@ -using Misaki.HighPerformance.LowLevel.Buffer; +using Misaki.HighPerformance.LowLevel.Buffer; using Misaki.HighPerformance.LowLevel.Collections; namespace Misaki.HighPerformance.Test.UnitTest.Collections; @@ -127,7 +127,7 @@ public class TestUnsafeSparseSet _sparseSet.Remove(ids[1], gens[1]); // Remove the second element (20) var ptr = (int*)_sparseSet.GetUnsafePtr(); - + Assert.AreEqual(2, _sparseSet.Count); var index = 0; diff --git a/Misaki.HighPerformance/Utilities/CollectionUtility.cs b/Misaki.HighPerformance/Utilities/CollectionUtility.cs index 01af713..ffe2b19 100644 --- a/Misaki.HighPerformance/Utilities/CollectionUtility.cs +++ b/Misaki.HighPerformance/Utilities/CollectionUtility.cs @@ -17,7 +17,7 @@ public static class CollectionUtility { return CollectionsMarshal.AsSpan(list); } - + /// /// Removes the element at the specified index from the list by replacing it with the last element, then removing /// the last element. This operation does not preserve the order of elements. @@ -34,12 +34,12 @@ public static class CollectionUtility { throw new ArgumentOutOfRangeException(nameof(index)); } - + if (index != lastIndex) { list[index] = list[lastIndex]; } - + list.RemoveAt(lastIndex); return list; }