Skip to content

Commit

Permalink
Added experimental GPU benchmark.
Browse files Browse the repository at this point in the history
  • Loading branch information
OudomMunint committed Jul 6, 2024
1 parent f81b91b commit f2d4f61
Showing 1 changed file with 49 additions and 4 deletions.
53 changes: 49 additions & 4 deletions MyBenchmark.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
using System.Timers;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;
using NvAPIWrapper;
using NvAPIWrapper.Display;
using NvAPIWrapper.GPU;
using SharpDX.Direct3D11;
using SharpDX.DXGI;
using Device = SharpDX.Direct3D11.Device;

namespace Benchmark
{
Expand Down Expand Up @@ -87,10 +93,10 @@ public void FullCpuLoad()
MaxDegreeOfParallelism = Environment.ProcessorCount,
};

if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
Process.GetCurrentProcess().ProcessorAffinity = (IntPtr)0xFF;
}
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
Process.GetCurrentProcess().ProcessorAffinity = (IntPtr)0xFF;
}

Parallel.For(0, NumIterations, options, i =>
{
Expand All @@ -112,6 +118,45 @@ private void DoWork(int index)
}
}
}

public class GpuBenchmark
{
private const int NumIterations = 1000;
private Device? device;

[GlobalSetup]
public void Setup()
{
device = new Device(SharpDX.Direct3D.DriverType.Hardware, DeviceCreationFlags.None);
}

[GlobalCleanup]
public void Cleanup()
{
device?.Dispose();
}

[Benchmark]
public void FullGpuLoad()
{
for (int i = 0; i < NumIterations; i++)
{
using var texture = new SharpDX.Direct3D11.Texture2D(device!, new SharpDX.Direct3D11.Texture2DDescription
{
Width = 1920,
Height = 1080,
ArraySize = 1,
BindFlags = SharpDX.Direct3D11.BindFlags.RenderTarget,
Usage = SharpDX.Direct3D11.ResourceUsage.Default,
CpuAccessFlags = SharpDX.Direct3D11.CpuAccessFlags.None,
Format = Format.R8G8B8A8_UNorm,
MipLevels = 1,
OptionFlags = SharpDX.Direct3D11.ResourceOptionFlags.None,
SampleDescription = new SharpDX.DXGI.SampleDescription(1, 0),
});
}
}
}

public class Program
{
Expand Down

0 comments on commit f2d4f61

Please sign in to comment.