Refactor job system and update project configuration

Added:
- Added `JobExecutor.cs` for job execution management.
- Added `JobInfo.cs` to hold job execution information.
- Added `TestJobSystem.cs` for unit tests of the job system.
- Added `TestJobs.cs` for additional job implementation tests.
- Added `WorkerThread.cs` to manage worker threads for jobs.

Changed:
- Changed `AssemblyInfo.cs.cs` to include a global using directive for `unsafe JobExecuteFunc`.
- Changed `IJob.cs` to include an overload of the `Execute` method with a `threadIndex` parameter.
- Changed `JobHandle.cs` to include an `IsValid` property and updated internal structure.
- Changed `JobScheduler.cs` to improve job scheduling and management.
- Changed `JobsUtility.cs` to enhance job management functions.
- Changed `MemoryBlock.cs` to reference the heap from which memory was allocated.
- Changed `ParallelNoiseBenchmark.cs` to include benchmarks for the job system.
- Changed `Program.cs` to execute benchmarks instead of previous test code.

Removed:
- Removed `.gitignore` entries for default ignored files.
- Removed `JobBase.cs` to shift from structs to classes for jobs.
- Removed `JobExtensions.cs` indicating a change in job scheduling.
- Removed `JobStruct.cs` indicating a change in job structure.
- Removed `encodings.xml`, `indexLayout.xml`, and `vcs.xml` files to simplify project configuration.
- Removed fields from `JobData.cs` to simplify the job data structure.
- Removed `TestJobSystem.csproj` entries related to old project structure.
This commit is contained in:
2025-09-08 23:17:22 +09:00
parent a2a760594e
commit 07c99b8a5a
31 changed files with 1392 additions and 1204 deletions

View File

@@ -34,7 +34,7 @@ public unsafe class CollectionBenchmark
array[i] = i;
}
((ArenaAllocator*)AllocationManager.TempHandle.Allocator)->Reset();
AllocationManager.ResetTempAllocator();
}
[Benchmark]

View File

@@ -1,4 +1,5 @@
using BenchmarkDotNet.Attributes;
using Misaki.HighPerformance.Jobs;
using Misaki.HighPerformance.LowLevel.Buffer;
using Misaki.HighPerformance.LowLevel.Collections;
using Misaki.HighPerformance.Test.Jobs;
@@ -9,61 +10,62 @@ namespace Misaki.HighPerformance.Test.Benchmark;
[MemoryDiagnoser]
public class ParallelNoiseBenchmark
{
private const int _WIDTH = 512;
private const int _HEIGHT = 512;
private const int _WIDTH = 64;
private const int _HEIGHT = 64;
private const int _LENGTH = _WIDTH * _HEIGHT;
//[GlobalSetup]
//public void Setup()
//{
// JobScheduler.Initialize();
//}
internal JobScheduler _jobScheduler = null!;
private UnsafeArray<float> _buffers;
//[GlobalCleanup]
//public void Cleanup()
//{
// JobScheduler.Shutdown();
//}
[GlobalSetup]
public void Setup()
{
_jobScheduler = new JobScheduler(Environment.ProcessorCount - 1);
_buffers = new UnsafeArray<float>(_LENGTH, Allocator.Persistent);
}
//[Benchmark]
//public void JobSystem()
//{
// using var buffers = new UnsafeArray<float>(_LENGTH, Allocator.Persistent, AllocationOption.None);
// var job = new NoiseJob()
// {
// buffers = buffers,
// width = _WIDTH,
// height = _HEIGHT
// };
[GlobalCleanup]
public void Cleanup()
{
_jobScheduler.Dispose();
_buffers.Dispose();
}
// var handle = job.Schedule(_LENGTH, 64);
// handle.Complete();
//}
[Benchmark]
public void JobSystem()
{
var job = new NoiseJob()
{
buffers = _buffers,
width = _WIDTH,
height = _HEIGHT
};
var handle = _jobScheduler.ScheduleParallel(ref job, _LENGTH, 64, -1);
_jobScheduler.WaitComplete(handle);
}
[Benchmark]
public void ParallelFor()
{
using var buffers = new UnsafeArray<float>(_LENGTH, Allocator.Persistent, AllocationOption.None);
Parallel.For(0, _LENGTH, i =>
{
var x = i % _WIDTH;
var y = i / _HEIGHT;
var uv = new Vector2(x, y);
buffers[i] = NoiseJob.GradientNoise(uv);
_buffers[i] = NoiseJob.GradientNoise(uv);
});
}
[Benchmark(Baseline = true)]
public void For()
{
using var buffers = new UnsafeArray<float>(_LENGTH, Allocator.Persistent, AllocationOption.None);
for (var i = 0; i < _LENGTH; i++)
{
var x = i % _WIDTH;
var y = i / _HEIGHT;
var uv = new Vector2(x, y);
buffers[i] = NoiseJob.GradientNoise(uv);
_buffers[i] = NoiseJob.GradientNoise(uv);
}
}
}