Enhance mathematical capabilities and job system

Added new numeric types for unsigned integers, including uint2, uint3, and uint4, along with their matrix types.
Added a new `quaternion` struct with constructors and methods for creating and manipulating quaternions.
Added methods for projecting and reflecting vectors, enhancing geometric operations.
Added utility functions for generating orthonormal bases and changing vector signs.
Added comprehensive unit tests for new mathematical functions and quaternion operations.
Added a high-performance job scheduling system with job management features and worker thread management.
Added new structs for job execution, allowing efficient job scheduling and execution.
Added utility functions for job execution, including methods for obtaining unique job IDs.

Changed access modifiers and property definitions in several files for improved clarity and maintainability.
Changed property definitions and method implementations in `ImageInfo.cs`, `ImageResult.cs`, and `ImageResultFloat.cs` for better readability.
Changed memory management functions in `CRuntime.cs` and improved memory allocation tracking in `MemoryStats.cs`.
Changed the project file to include references to necessary projects and enable unsafe code blocks.

Removed the `WorkerThreadPool.cs` file, integrating worker thread management directly into the `JobScheduler`.
Removed the `float4` struct and its associated methods and properties, transitioning to a new code generation strategy.
Removed the `float4.tt` template and other related files, indicating a shift in code generation approach.
Removed the `Vectorize.cs` file, indicating a change in how vector operations are handled.

Updated the `.gitignore` file to include IDE-specific settings.
Updated various XML files to define project components and structure.
Updated the `AllocationManager.cs` to improve memory allocation management and introduce new strategies.
Updated the `UnsafeArray.cs`, `UnsafeHashMap.cs`, and `UnsafeList.cs` to enhance performance and safety in unsafe contexts.
Updated error handling and function pointer management in `MemoryLeakException.cs` and `FunctionPointer.cs`.
Updated the `AssemblyInfo.cs` file to include global using directives for better code organization.
This commit is contained in:
2025-09-06 12:07:02 +09:00
parent eeff3313b5
commit a2a760594e
114 changed files with 20826 additions and 7217 deletions

View File

@@ -0,0 +1,94 @@
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
namespace Misaki.HighPerformance.Jobs;
/// <summary>
/// A handle that represents a scheduled job and can be used to manage dependencies and wait for completion.
/// JobHandle is designed to be a lightweight value type to avoid allocations.
/// </summary>
[StructLayout(LayoutKind.Sequential)]
public readonly struct JobHandle : IEquatable<JobHandle>
{
internal readonly ulong _id;
internal readonly int _version;
internal JobHandle(ulong id, int version)
{
_id = id;
_version = version;
}
/// <summary>
/// A completed job handle that can be used as a dependency that is already satisfied.
/// </summary>
public static JobHandle Completed => new(0, 0);
/// <summary>
/// Gets whether this job handle represents a completed job.
/// </summary>
public bool IsCompleted => _id == 0 || JobScheduler.IsCompleted(this);
/// <summary>
/// Blocks the calling thread until the job completes.
/// </summary>
public void Complete()
{
if (_id != 0)
{
JobScheduler.Complete(this);
}
}
/// <summary>
/// Combines multiple job handles into a single dependency.
/// The resulting handle will be complete when all input handles are complete.
/// </summary>
/// <param name="dependencies">The job handles to combine.</param>
/// <returns>A new job handle that depends on all input handles.</returns>
public static JobHandle CombineDependencies(params ReadOnlySpan<JobHandle> dependencies)
{
if (dependencies.Length == 0)
{
return Completed;
}
if (dependencies.Length == 1)
{
return dependencies[0];
}
return JobScheduler.CombineDependencies(dependencies);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool Equals(JobHandle other)
{
return _id == other._id && _version == other._version;
}
public override bool Equals(object? obj)
{
return obj is JobHandle other && Equals(other);
}
public override int GetHashCode()
{
return HashCode.Combine(_id, _version);
}
public static bool operator ==(JobHandle left, JobHandle right)
{
return left.Equals(right);
}
public static bool operator !=(JobHandle left, JobHandle right)
{
return !left.Equals(right);
}
public override string ToString()
{
return _id == 0 ? "JobHandle(Completed)" : $"JobHandle(ID:{_id}, Version:{_version})";
}
}