Add image processing and memory management features
Added new namespace `Misaki.HighPerformance.Image` for image processing, including classes for animated GIF handling and memory management. Added `AnimatedFrameResult` class for individual frames in animated images. Added `AnimatedGifEnumerator` class for enumerating frames in animated GIFs. Added `ColorComponents` enum for different color formats. Added `ImageInfo` struct for image dimensions and color components. Added `CRuntime` class for low-level memory management functions. Added `MemoryStats` class to track memory allocation statistics. Added utility functions for creating multi-dimensional arrays. Added new structures for fixed-size UTF-8 encoded strings. Added benchmarking classes to test new memory management features. Changed `StbImage.cs` to include new namespaces and functionality for image data manipulation. Changed project files to target .NET 9.0 and enable new features. Changed `Arena.cs` and `DynamicArena.cs` to use `nuint` for size parameters. Changed `BitSet.cs` to enhance bit manipulation methods. Changed `Program.cs` to run `FunctionPtrBenchmark` for performance testing. Removed memory tracking code from `AllocationManager.cs`, including the `_allocated` dictionary and related logic. Removed `Free` method from `IAllocator.cs` interface. Removed `UNSAFE_COLLECTION_CHECK` preprocessor directive from the codebase. Refactored various files to improve organization, moving from `Unsafe` to `LowLevel` namespace. Refactored `MemoryUtilities` class to include new memory operation methods. Refactored `UnsafeUtilities.cs` to support new collection structures.
This commit is contained in:
140
Misaki.HighPerformance.Mathematics/float3.tt
Normal file
140
Misaki.HighPerformance.Mathematics/float3.tt
Normal file
@@ -0,0 +1,140 @@
|
||||
<#@ template debug="false" hostspecific="false" language="C#" #>
|
||||
<#@ assembly name="System.Core" #>
|
||||
<#@ import namespace="System.Linq" #>
|
||||
<#@ import namespace="System.Text" #>
|
||||
<#@ import namespace="System.Collections.Generic" #>
|
||||
<#@ include file="Utilities.ttinclude" #>
|
||||
<#@ output extension=".gen.cs" #>
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace Misaki.HighPerformance.Mathematics;
|
||||
|
||||
<#
|
||||
var dimension = 3;
|
||||
var components = new[] { "x", "y", "z" };
|
||||
var structName = $"float{dimension}";
|
||||
|
||||
#>
|
||||
public struct <#= structName #>
|
||||
{
|
||||
<# for(int i = 0; i < dimension; i++) { #>
|
||||
public float <#= components[i] #>;
|
||||
<# } #>
|
||||
|
||||
public <#= structName #>(float value)
|
||||
{
|
||||
<# for(int i = 0; i < dimension; i++) { #>
|
||||
this.<#= components[i] #> = value;
|
||||
<# } #>
|
||||
}
|
||||
|
||||
public <#= structName #>(<#= string.Join(", ", components.Take(dimension).Select(c => $"float {c}")) #>)
|
||||
{
|
||||
<# for(int i = 0; i < dimension; i++) { #>
|
||||
this.<#= components[i] #> = <#= components[i] #>;
|
||||
<# } #>
|
||||
}
|
||||
|
||||
<# foreach (var otherDim in dimensions.Where(d => d != dimension))
|
||||
{
|
||||
string otherStructName = $"float{otherDim}";
|
||||
|
||||
if (otherDim < dimension)
|
||||
{
|
||||
#>
|
||||
public <#= structName #>(<#= otherStructName #> value)
|
||||
{
|
||||
<# for(int i = 0; i < Math.Min(dimension, otherDim); i++) { #>
|
||||
this.<#= components[i] #> = value.<#= components[i] #>;
|
||||
<#
|
||||
}
|
||||
// Fill remaining components with 0
|
||||
for(int i = otherDim; i < dimension; i++) {
|
||||
#>
|
||||
this.<#= components[i] #> = 0.0f;
|
||||
<# } #>
|
||||
}
|
||||
|
||||
<# }
|
||||
else
|
||||
{ #>
|
||||
public <#= structName #>(<#= otherStructName #> value)
|
||||
{
|
||||
<#
|
||||
for(int i = 0; i < dimension; i++) {
|
||||
#>
|
||||
this.<#= components[i] #> = value.<#= components[i] #>;
|
||||
<# } #>
|
||||
}
|
||||
<#
|
||||
}
|
||||
}
|
||||
#>
|
||||
|
||||
public static <#= structName #> operator +(<#= structName #> lhs, <#= structName #> rhs)
|
||||
{
|
||||
return (lhs.AsVector128() + rhs.AsVector128()).AsFloat<#= dimension #>();
|
||||
}
|
||||
|
||||
public static <#= structName #> operator +(<#= structName #> lhs, float rhs)
|
||||
{
|
||||
return lhs + new <#= structName #>(rhs);
|
||||
}
|
||||
|
||||
public static <#= structName #> operator -(<#= structName #> lhs, <#= structName #> rhs)
|
||||
{
|
||||
return (lhs.AsVector128() - rhs.AsVector128()).AsFloat<#= dimension #>();
|
||||
}
|
||||
|
||||
public static <#= structName #> operator -(<#= structName #> lhs, float rhs)
|
||||
{
|
||||
return lhs - new <#= structName #>(rhs);
|
||||
}
|
||||
|
||||
public static <#= structName #> operator *(<#= structName #> lhs, <#= structName #> rhs)
|
||||
{
|
||||
return (lhs.AsVector128() * rhs.AsVector128()).AsFloat<#= dimension #>();
|
||||
}
|
||||
|
||||
public static <#= structName #> operator *(<#= structName #> lhs, float rhs)
|
||||
{
|
||||
return (lhs.AsVector128() * rhs).AsFloat<#= dimension #>();
|
||||
}
|
||||
|
||||
public static <#= structName #> operator /(<#= structName #> lhs, <#= structName #> rhs)
|
||||
{
|
||||
return (lhs.AsVector128() / rhs.AsVector128()).AsFloat<#= dimension #>();
|
||||
}
|
||||
|
||||
public static <#= structName #> operator /(<#= structName #> lhs, float rhs)
|
||||
{
|
||||
return (lhs.AsVector128() / rhs).AsFloat<#= dimension #>();
|
||||
}
|
||||
|
||||
public static <#= structName #> operator -(<#= structName #> value)
|
||||
{
|
||||
return (-value.AsVector128()).AsFloat<#= dimension #>();
|
||||
}
|
||||
|
||||
<#
|
||||
var validComponents = components.Take(dimension).ToArray();
|
||||
var swizzles = GenerateSwizzles(validComponents, 4);
|
||||
foreach (var swizzle in swizzles)
|
||||
{
|
||||
var targetDim = swizzle.Length;
|
||||
var targetStruct = $"float{targetDim}";
|
||||
#>
|
||||
public <#= targetStruct #> <#= swizzle #>
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get => new <#= targetStruct #>(<#= string.Join(", ", swizzle.Select(c => $"this.{c}")) #>);
|
||||
}
|
||||
|
||||
<#
|
||||
}
|
||||
#>
|
||||
public override readonly string ToString()
|
||||
{
|
||||
return $"(<#= string.Join(", ", components.Take(dimension).Select(c => $"{c}: {{this.{c}}}")) #>)";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user