Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

helix upgrade #14134

Merged
merged 20 commits into from
Aug 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 10 additions & 26 deletions src/DynamoCoreWpf/DynamoCoreWpf.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -113,34 +113,20 @@
<None Remove="Views\Menu\TrustedPathView.xaml" />
<None Remove="Views\GuidedTour\HtmlPages\Resources\ConnectTheNode.gif" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'net48' ">
<Reference Include="System.Configuration" />
<Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" />
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Data" />
<Reference Include="System.Drawing" />
<Reference Include="System.Runtime.Serialization" />
<Reference Include="System.Web" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xaml" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Xml" />
<Reference Include="WindowsBase" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="DynamoVisualProgramming.LibG_229_0_0" Version="2.18.0.1400" />

<ItemGroup>
<PackageReference Include="HelixToolkit" Version="2.24.0" />
<PackageReference Include="HelixToolkit.Core.Wpf" Version="2.24.0" />
<PackageReference Include="HelixToolkit.SharpDX.Core.Wpf" Version="2.24.0" />
<PackageReference Include="System.Configuration.ConfigurationManager" Version="5.0.0" />
<PackageReference Include="DynamoVisualProgramming.LibG_229_0_0" Version="2.18.0.1400" />
<PackageReference Include="FontAwesome5" Version="2.1.11" />
<PackageReference Include="AvalonEdit" Version="6.3.0.90" CopyXML="true" />
<PackageReference Include="Greg" Version="2.5.0.5076" />
<PackageReference Include="Microsoft.Web.WebView2" Version="1.0.1264.42" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="RestSharp" Version="106.12.0" />
<PackageReference Include="Cyotek.Drawing.BitmapFont" Version="2.0.0" />
<PackageReference Include="HelixToolkit" Version="2.17.0" />
<PackageReference Include="HelixToolkit.Wpf" Version="2.17.0" />
<PackageReference Include="HelixToolkit.Wpf.SharpDX" Version="2.17.0" />
<PackageReference Include="SharpDX" Version="4.2.0" />
<PackageReference Include="SharpDX.D3DCompiler" Version="4.2.0">
<IncludeAssets>none</IncludeAssets>
Expand All @@ -154,11 +140,9 @@
<PackageReference Include="SharpDX.Mathematics" Version="4.2.0" />
<Reference Include="Dynamo.Microsoft.Xaml.Behaviors">
<HintPath>..\..\extern\Microsoft.Xaml.Behaviors\$(TargetFramework)\Dynamo.Microsoft.Xaml.Behaviors.dll</HintPath>
</Reference>
<PackageReference Include="Prism.Core" Version="8.1.97" Condition=" '$(TargetFramework)' != 'net48' "/>
<Reference Include="Microsoft.Practices.Prism" Condition=" '$(TargetFramework)' == 'net48' ">
<HintPath>..\..\extern\prism\Microsoft.Practices.Prism.dll</HintPath>
</Reference>
</Reference>

<PackageReference Include="Prism.Core" Version="8.1.97"/>
<PackageReference Include="DotNetProjects.Extended.Wpf.Toolkit" Version="5.0.103" />
</ItemGroup>
<ItemGroup>
Expand Down
1 change: 1 addition & 0 deletions src/DynamoCoreWpf/Rendering/HelixRenderPackage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Linq;
using Autodesk.DesignScript.Interfaces;
using Dynamo.Visualization;
using HelixToolkit.SharpDX.Core;
using HelixToolkit.Wpf.SharpDX;
using SharpDX;
using ITransformable = Autodesk.DesignScript.Interfaces.ITransformable;
Expand Down
4 changes: 2 additions & 2 deletions src/DynamoCoreWpf/ViewModels/Watch3D/DynamoEffectsManager.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using HelixToolkit.Wpf.SharpDX;
using HelixToolkit.Wpf.SharpDX.Shaders;
using HelixToolkit.SharpDX.Core;
using HelixToolkit.SharpDX.Core.Shaders;
using System;

namespace Dynamo.Wpf.ViewModels.Watch3D
Expand Down
14 changes: 8 additions & 6 deletions src/DynamoCoreWpf/ViewModels/Watch3D/DynamoGeometryModel3D.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
using System;
using System.Windows;
using System;
using System.Windows;
using HelixToolkit.Wpf.SharpDX;
using HelixToolkit.Wpf.SharpDX.Core;
using HelixToolkit.Wpf.SharpDX.Model.Scene;
using HelixToolkit.SharpDX.Core;
using HelixToolkit.SharpDX.Core.Core;
using HelixToolkit.SharpDX.Core.Model.Scene;


namespace Dynamo.Wpf.ViewModels.Watch3D
{
Expand Down Expand Up @@ -90,9 +92,9 @@ protected override RenderCore OnCreateRenderCore()
return new DynamoGeometryMeshCore();
}

protected override IRenderTechnique OnCreateRenderTechnique(IRenderHost host)
protected override IRenderTechnique OnCreateRenderTechnique(IEffectsManager effectsManager)
{
marbelarrietaGlobant marked this conversation as resolved.
Show resolved Hide resolved
return host.EffectsManager[DynamoEffectsManager.DynamoMeshShaderName];
return effectsManager[DynamoEffectsManager.DynamoMeshShaderName];
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
using System;
using System;
using HelixToolkit.Wpf.SharpDX;
using HelixToolkit.Wpf.SharpDX.Core;
using HelixToolkit.Wpf.SharpDX.Model.Scene;
using HelixToolkit.SharpDX.Core;
using HelixToolkit.SharpDX.Core.Core;
using HelixToolkit.SharpDX.Core.Model.Scene;


namespace Dynamo.Wpf.ViewModels.Watch3D
Expand Down Expand Up @@ -41,9 +42,9 @@ protected override RenderCore OnCreateRenderCore()
return new DynamoPointLineRenderCore();
}

protected override IRenderTechnique OnCreateRenderTechnique(IRenderHost host)
protected override IRenderTechnique OnCreateRenderTechnique(IEffectsManager effectsManager)
{
return host.EffectsManager[DynamoEffectsManager.DynamoLineShaderName];
return effectsManager[DynamoEffectsManager.DynamoLineShaderName];
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
using System;
using System;
using HelixToolkit.Wpf.SharpDX;
using HelixToolkit.Wpf.SharpDX.Core;
using HelixToolkit.Wpf.SharpDX.Model.Scene;
using HelixToolkit.SharpDX.Core;
using HelixToolkit.SharpDX.Core.Core;
using HelixToolkit.SharpDX.Core.Model.Scene;

namespace Dynamo.Wpf.ViewModels.Watch3D
{
Expand Down Expand Up @@ -31,9 +32,9 @@ protected override RenderCore OnCreateRenderCore()
return new DynamoPointLineRenderCore();
}

protected override IRenderTechnique OnCreateRenderTechnique(IRenderHost host)
protected override IRenderTechnique OnCreateRenderTechnique(IEffectsManager effectsManager)
{
return host.EffectsManager[DynamoEffectsManager.DynamoPointShaderName];
return effectsManager[DynamoEffectsManager.DynamoPointShaderName];
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Windows;
using System.Windows;
using HelixToolkit.Wpf.SharpDX;
using HelixToolkit.Wpf.SharpDX.Core;
marbelarrietaGlobant marked this conversation as resolved.
Show resolved Hide resolved
using HelixToolkit.SharpDX.Core.Core;

namespace Dynamo.Wpf.ViewModels.Watch3D
{
Expand Down
46 changes: 39 additions & 7 deletions src/DynamoCoreWpf/ViewModels/Watch3D/HelixWatch3DViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,19 @@
using Dynamo.Wpf.Rendering;
using DynamoUtilities;
using HelixToolkit.Wpf.SharpDX;
using HelixToolkit.Wpf.SharpDX.Shaders;
using HelixToolkit.Wpf.SharpDX.Utilities;
using HelixToolkit.SharpDX.Core;
using HelixToolkit.SharpDX.Core.Shaders;
using Newtonsoft.Json;
using SharpDX;
using Color = SharpDX.Color;
using ColorConverter = System.Windows.Media.ColorConverter;
using GeometryModel3D = HelixToolkit.Wpf.SharpDX.GeometryModel3D;
using Matrix = SharpDX.Matrix;
using MeshBuilder = HelixToolkit.Wpf.SharpDX.MeshBuilder;
using MeshGeometry3D = HelixToolkit.Wpf.SharpDX.MeshGeometry3D;
using PerspectiveCamera = HelixToolkit.Wpf.SharpDX.PerspectiveCamera;
using TextInfo = HelixToolkit.Wpf.SharpDX.TextInfo;
using Matrix = SharpDX.Matrix;
using MeshBuilder = HelixToolkit.SharpDX.Core.MeshBuilder;
using MeshGeometry3D = HelixToolkit.SharpDX.Core.MeshGeometry3D;
using TextInfo = HelixToolkit.SharpDX.Core.TextInfo;


namespace Dynamo.Wpf.ViewModels.Watch3D
{
Expand Down Expand Up @@ -209,10 +210,41 @@ public class HelixWatch3DViewModel : DefaultWatch3DViewModel
private readonly Dictionary<string, List<Tuple<string, Vector3>>> labelPlaces
= new Dictionary<string, List<Tuple<string, Vector3>>>();

//this code is grabbed from the helix source
//https://github.com/helix-toolkit/helix-toolkit/blob/develop/Source/HelixToolkit.SharpDX.Shared/Utilities/NVOptimusEnabler.cs#L15
//as of 2.24.0 this class is not compiled in their netcore targets.
/// <summary>
/// Enable dedicated graphics card for rendering. https://stackoverflow.com/questions/17270429/forcing-hardware-accelerated-rendering
/// </summary>
internal sealed class DYNNVOptimusEnabler
{
static DYNNVOptimusEnabler()
{
try
{

if (Environment.Is64BitProcess)
NativeMethods.LoadNvApi64();
else
NativeMethods.LoadNvApi32();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so we have 32 bit support here just because this code has been copy pasted right >?

Copy link
Member

@mjkkirschner mjkkirschner Aug 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, I also asked about this class being removed here:
helix-toolkit/helix-toolkit#2004 ... so - not sure it will work.

you can give this blog post on a related tool a read if you are interested -
https://www.toptensoftware.com/blog/nvpatch-how-it-works/
though it seems we might be able to do something now that .net supports native external callers ...

anyway, that blog post and this method don't seem to work the same way so there must be more to it than an exported member in the pe file. I guess?

For the time being, I think this is safe enough even if it does not work - we'll just have to pay attention to reports of users needing to explicitly set hardware accel again for sandbox - like back in the dark ages 😉 )

}
catch { } // will always fail since 'fake' entry point doesn't exists
}
};

internal static class NativeMethods
{
[System.Runtime.InteropServices.DllImport("nvapi64.dll", EntryPoint = "fake")]
internal static extern int LoadNvApi64();

[System.Runtime.InteropServices.DllImport("nvapi.dll", EntryPoint = "fake")]
internal static extern int LoadNvApi32();
}

// This makes sure the NVidia graphics card is used for rendering when available. In the absence of this
// there are found to be issues with Helix crashing when the app is used with external monitors.
// See: https://github.com/helix-toolkit/helix-toolkit/wiki/Tips-on-performance-optimization-(WPF.SharpDX-and-UWP)#2-laptops-with-nvidia-optimus-dual-graphics-cardhelixtoolkitsharpdx-only
private static NVOptimusEnabler nvEnabler = new NVOptimusEnabler();
private static DYNNVOptimusEnabler nvEnabler = new DYNNVOptimusEnabler();

#if DEBUG
private readonly Stopwatch renderTimer = new Stopwatch();
Expand Down
Binary file not shown.
Binary file modified src/DynamoCoreWpf/ViewModels/Watch3D/compiledShaders/psDynamoMesh
Binary file not shown.
Binary file not shown.
Binary file modified src/DynamoCoreWpf/ViewModels/Watch3D/compiledShaders/vsDynamoMesh
Binary file not shown.
Binary file not shown.
Loading
Loading