WPF and hardware acceleration with a discrete graphics card

432 views Asked by At

I need to display a point cloud. For this I use C# and WPF (HelixToolkit). Each point is displayed as a tetrahedron (because the minimum number of triangles). Problem: while the cloud is moving, it is slowing down!

Here's what Process Explorer shows:

enter image description here

CPU load 15-18% (one logical processor equals 12.5%), GPU load 20-40%. 1.7Gb in main memory.

How to make WPF take full of discrete graphics card resources and hardware acceleration (GPU and video memory)? And why the cloud slows down if the CPU and GPU are not fully loaded?

DirectX 11 and NVIDIA GeForce GTX 780

C#, WPF, HelixToolkit, Windows 7, discrete graphics card, video card

UPDATE

Build settings (platform target) and CPU/GPU load

  1. Any CPU with Prefer 32-bit

    CPU: 15-20%, GPU: 25-40%

  2. Any CPU without Prefer 32-bit

    x64

    CPU: 15-20%, GPU: 40-50%

  3. x86

    OutOfMemoryException


HelixToolkit.Wpf.MeshBuilder meshBuilder = new HelixToolkit.Wpf.MeshBuilder();

meshBuilder.AddTetrahedron(new Point3D(pointCoordinates[0], pointCoordinates[1], pointCoordinates[2]), new Vector3D(1, 0, 0), new Vector3D(0, 1, 0), 0.01);

GeometryModel3D geometryModel3D = new GeometryModel3D();

geometryModel3D.Geometry = meshBuilder.ToMesh();

geometryModel3D.Material = new DiffuseMaterial()
{
    Color = Colors.Green,
    AmbientColor = Colors.Green,
    Brush = new SolidColorBrush(Colors.Green)
};

ModelVisual3D modelVisual3D = new HelixToolkit.Wpf.MeshVisual3D();

modelVisual3D.Content = geometryModel3D;


HelixViewport3D.Children.Add(modelVisual3D);


<h:HelixViewport3D RotateAroundMouseDownPoint="True" x:Name="HelixViewport3D"/>
2

There are 2 answers

2
TomTom On

You have a TON of problems with your argumentation.

CPU load 15-18% (one logical processor equals 12.5%),

So, you have a CPU core running full and another doing some small stuff. So, the algorithm is single threaded. How you expect the graphics card to speed that up?

How to make WPF take full of discrete graphics card resources and hardware acceleration

By providing it with enough data to do that, which it seems your CPU is incapable of - and you blame the graphics card.

And why the cloud slows down if the CPU and GPU are not fully loaded?

You need to learn some basic programming - the difference between single threaded and multi threaded and how a single threaded application cannot use all the CPU by definition of having only one thread. WPF likely offloads some stuff to a second thread, but essentially you have a CPU bottleneck that is either inherent or crappy programming of some sort. Either you (and you show a lot of ignorance to basics), or the Helix Toolkit is not using multiple CPU cores in a way that is effective. Or, as I said, it is just not possible, though a point cloud moving should be something you can parallelize - heck, it should be something that runs TOTALLY on the graphics card.

2
Anton On

Hardware acceleraton dependent on your videocard\drivers and system settings (for example you can check whether it enalbed via using DxDiag.exe).

enter image description here

But as developer you can optimize your code and use less vertex in scene

<hx:PointsVisual3D Points={Binding PointCollection} />

or even better to use

<hx:PointGeometryModel3D
         Geometry="{Binding PointsGeometry}" 
         Color="{x:Static sdx:Color.White}" />

HelixToolkit have a collection of samples on GitHub which might be useful for learn this library.