Files
Misaki.HighPerformance/Misaki.HighPerformance.Test/Benchmark/SPMDBenchmark.cs
Misaki cfd01eb9b6 Refactor SPMD job system, add GGX mipmap benchmark
- Replace IJobSPMD with T4-generated, multi-type SPMD job interfaces and wrappers (up to 8 numeric types)
- Extend ISPMD with Cast/BitCast; implement for ScalarLane and WideLane (SIMD-aware)
- Add unary minus, scalar-lane, and lane-scalar operators to Vector2/3/4; improve Select methods
- WideLane now partial with T4-generated Cast/BitCast (SIMD conversions)
- SPMD job Execute now requires unmanaged TLane; update all usages and benchmarks
- Add GGXMipGenerationBenchmark with vectorized and scalar paths, SkiaSharp output
- Update project files: add generated code, SkiaSharp, bump version to 1.3.0
- Misc: fix formatting, method signatures, FreeList logic
2026-04-25 01:50:06 +09:00

100 lines
2.2 KiB
C#

using BenchmarkDotNet.Attributes;
using Misaki.HighPerformance.Jobs;
using Misaki.HighPerformance.Mathematics.SPMD;
using System.Runtime.InteropServices;
namespace Misaki.HighPerformance.Test.Benchmark;
public unsafe class SPMDBenchmark
{
private const int _SIZE = 512;
private JobScheduler _scheduler = null!;
private float* _buf;
[GlobalSetup]
public void Setup()
{
_scheduler = new JobScheduler(Environment.ProcessorCount);
_buf = (float*)NativeMemory.Alloc(sizeof(float) * _SIZE * _SIZE);
}
[GlobalCleanup]
public void Cleanup()
{
_scheduler.Dispose();
NativeMemory.Free(_buf);
}
[Benchmark(Baseline = true)]
public void SPMDNoise()
{
var job = new Jobs.NoiseJobMathSPMD
{
buffers = _buf,
width = _SIZE,
height = _SIZE,
};
var handle = _scheduler.ScheduleParallelSPDM<Jobs.NoiseJobMathSPMD, float>(ref job, _SIZE * _SIZE, 64, false, JobPriority.Normal);
_scheduler.Wait(handle);
}
[Benchmark]
public void JobNoise()
{
var job = new Jobs.NoiseJobVectorFor
{
buffers = _buf,
width = _SIZE,
height = _SIZE,
};
var handle = _scheduler.ScheduleParallelFor(ref job, _SIZE * _SIZE, 64);
_scheduler.Wait(handle);
}
//[Benchmark]
public void MathJobNoise()
{
var job = new Jobs.NoiseJobMath
{
buffers = _buf,
width = _SIZE,
height = _SIZE,
};
var handle = _scheduler.ScheduleParallel(ref job, _SIZE * _SIZE, 64);
_scheduler.Wait(handle);
}
//[Benchmark]
public void ParallelNoise()
{
var job = new Jobs.NoiseJobVectorFor
{
buffers = _buf,
width = _SIZE,
height = _SIZE,
};
Parallel.For(0, _SIZE * _SIZE, (i) =>
{
job.Execute(i, default);
});
}
[Benchmark]
public void SingleThreadNoise()
{
var job = new Jobs.NoiseJobVectorFor
{
buffers = _buf,
width = _SIZE,
height = _SIZE,
};
job.Run(_SIZE * _SIZE, default);
}
}