From f2d4f61997c9c3593445356992d9dad05aec757a Mon Sep 17 00:00:00 2001 From: OudomMunint Date: Sun, 7 Jul 2024 02:12:23 +1000 Subject: [PATCH] Added experimental GPU benchmark. --- MyBenchmark.cs | 53 ++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 49 insertions(+), 4 deletions(-) diff --git a/MyBenchmark.cs b/MyBenchmark.cs index 2a7a113..cd13f8e 100644 --- a/MyBenchmark.cs +++ b/MyBenchmark.cs @@ -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 { @@ -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 => { @@ -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 {