ファイル
YMM4-WaveOptics/WaveOptics/Rendering/WaveOpticsCompute.cs
T
routersys 4042882530 GPUの判定とCPUの経路をプロセッサーにつなぐ
・GPUの計算結果を検査し、誤りを見つけたときはCPUで計算し直すよう追加-A
・Direct3D 12を使えない環境やソフトウェアのアダプターではCPUで計算するよう追加-A
・GPUの異常を見つけたときに、その内容を開発者へ自動で送信するよう追加-A
2026-10-06 07:37:50 +09:00

61 行
2.6 KiB
C#

using ComputeGuard;
using ComputeWeave;
using SpectralConvolution;
using Vortice.Direct3D11;
using YukkuriMovieMaker.Commons;
namespace WaveOptics.Rendering;
internal static class WaveOpticsCompute
{
private const int ColorBytes = 4;
private const int StoredBytes = 16;
public static ComputeGuardian Guardian { get; } = new(new ComputeGuardianOptions { Report = WaveOpticsTelemetry.Report });
public static ComputeDevice DescribeDevice(IGraphicsDevicesAndContext devices)
{
var options = devices.D3D.Device.CheckFeatureOptions2();
return ComputeDevice.FromAdapter(devices.DXGI.Adapter, options.UnifiedMemoryArchitecture);
}
public static ComputeWorkload Workload(int canvasWidth, int canvasHeight, int kernelRadius)
=> new(canvasWidth, canvasHeight, GpuMemoryBytes(canvasWidth, canvasHeight, kernelRadius));
public static long GpuMemoryBytes(int canvasWidth, int canvasHeight, int kernelRadius)
{
var plan = TilePlan.Create(kernelRadius, 0, 0, canvasWidth, canvasHeight);
var pixels = (long)canvasWidth * canvasHeight;
var kernelArea = (kernelRadius * 2 + 1) * (kernelRadius * 2 + 1);
var layout = new GpuTileLayout(plan.GroupCount, GpuTileConvolver.MaximumSamples, kernelArea);
return pixels * (ColorBytes * 2 + StoredBytes)
+ (long)plan.BatchTiles * plan.TileElements * TilePlan.ElementBytes
+ (long)plan.TileElements * sizeof(float) * 2
+ (long)plan.Size / 2 * sizeof(float) * 2
+ (long)layout.Length * sizeof(uint) * 2
+ WaveOpticsSettings.ScratchLength * sizeof(int) * 2;
}
public static ComputeFailure Classify(Exception exception, bool deviceLost)
{
if (deviceLost)
return ComputeFailure.DeviceLost;
return exception is GraphicsMemoryAllocationException or OutOfMemoryException
? ComputeFailure.ResourceExhausted
: ComputeFailure.UnexpectedException;
}
public static ComputeCheck ToCheck(in ConvolutionMeasurement measurement)
=> new(measurement.Name, measurement.Measured, measurement.Reference, new ComputeTolerance(measurement.Tolerance / ComputeErrorModel.UnitInLastPlace, 1d, 0));
public static IReadOnlyList<ComputeCheck> SelfTest(GraphicsDevice device)
{
var measurements = new ConvolutionMeasurement[SpectralSelfTest.MeasurementCount];
var count = SpectralSelfTest.Run(device, WaveOpticsSettings.MaximumKernelRadius, measurements);
var checks = new ComputeCheck[count];
for (var index = 0; index < count; index++)
checks[index] = ToCheck(measurements[index]);
return checks;
}
}