-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
feat: Convert from SharpDX to Silk.NET #1715
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
Conversation
|
i can't build this branch via some errors has not resolve |
|
@ly3027929699 Yeah, the PR is still marked as wip, you shouldn't expect it to work as is yet :P |
| HResult result = dxgi.CreateDXGIFactory2(debugFlag, SilkMarshal.GuidPtrOf<IDXGIFactory2>(), (void**) &factory2); | ||
|
|
||
| if (result.IsFailure) | ||
| result.Throw(); | ||
|
|
||
| NativeFactory = factory2; | ||
| ComPtr<IDXGIFactory2> adapterFactory = new() { Handle = factory2 }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FWIW we have overloads now that can simplify this
ComPtr<IDXGIFactory2> adapterFactory = dxgi.CreateDXGIFactory2<IDXGIFactory2>(debugFlag);It's mentioned in the 2.17 blog post: https://dotnet.github.io/Silk.NET/blog/apr-2023/silk2170.html
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've seen them. I'm first making it work and checking things, then I'll make it pretty using the overloads.
485258e to
0433695
Compare
31a2882 to
5a60210
Compare
sources/engine/Stride.Graphics/Direct3D/DebugHelpers.Direct3D.cs
Outdated
Show resolved
Hide resolved
|
nvm: I was able to fix the conflicts in the web editor |
|
@Kryptos-FR I can indeed add you as a contributor. No problem with that. However, I still have changes locally that I have not yet pushed. I'm gradually distilling the changes from another repo I have. As this has taken more time than I wanted it to take initially it has been a bit of a mess, where most of the changes I've made to a "prototype" repo where I try things. So, with this in mind, if you merge What I can do is push some of the changes I want to do today and then do a rebase to the current P.D: If you still want me to add you as contributor, as I said above, no problem. |
|
@Ethereal77 Oh oh. I saw your comment after merging master. You should be able to rebase on top of the commit before the merge to ignore it. If you are unsure how to do it (and not want to mess with your local branches), if you add me as a contributor I can restore the remote branch to where it was before the merge. |
|
Don't worry. I'll finish some changes I have in progress, rebase on |
6cba522 to
d81d300
Compare
|
@Kryptos-FR I've rebased on latest |
|
@Ethereal77 looks like, except maybe the reference to |
|
It looks like the package was named |
| <PackageReference Include="SharpDX.Direct3D12" Condition="'$(TargetFramework)' == '$(StrideFramework)'" /> | ||
| <PackageReference Include="SharpDX.D3DCompiler" Condition="'$(TargetFramework)' == '$(StrideFramework)' Or '$(TargetFramework)' == '$(StrideFrameworkUWP)'" /> | ||
| <PackageReference Include="Vortice.Vulkan" Condition="'$(TargetFramework)' == '$(StrideFramework)'" /> | ||
| <PackageReference Include="Silk.NET.Direct3D11" Condition="'$(TargetFramework)' == '$(StrideFramework)' Or '$(TargetFramework)' == '$(StrideFrameworkUWP)'" /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
UWP might be removed by #2450. Just to keep in mind in case it gets merged. No need to fix it now.
| <ItemGroup> | ||
| <ProjectReference Include="..\Stride.Shaders.Parser\Stride.Shaders.Parser.csproj" /> | ||
| <PackageReference Include="SharpDX.D3DCompiler" Condition="'$(TargetFramework)' == '$(StrideFramework)' Or '$(TargetFramework)' == '$(StrideFrameworkUWP)'" /> | ||
| <PackageReference Include="Silk.NET.Direct3D.Compilers" Condition="'$(TargetFramework)' == '$(StrideFramework)' Or '$(TargetFramework)' == '$(StrideFrameworkUWP)'" /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
UWP might be removed by #2450. Just to keep in mind in case it gets merged. No need to fix it now.
| <PackageReference Include="SharpDX.MediaFoundation" Condition="'$(TargetFramework)' == '$(StrideFramework)' Or '$(TargetFramework)' == '$(StrideFrameworkUWP)'" /> | ||
| <PackageReference Include="SharpDX.Direct3D11" Condition="'$(TargetFramework)' == '$(StrideFramework)' Or '$(TargetFramework)' == '$(StrideFrameworkUWP)'" /> | ||
| <PackageReference Include="SharpDX.Direct3D12" Condition="'$(TargetFramework)' == '$(StrideFramework)'" /> | ||
| <PackageReference Include="Silk.NET.Direct3D11" Condition="'$(TargetFramework)' == '$(StrideFramework)' Or '$(TargetFramework)' == '$(StrideFrameworkUWP)'" /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
UWP might be removed by #2450. Just to keep in mind in case it gets merged. No need to fix it now.
| <ProjectReference Include="..\..\engine\Stride.Graphics\Stride.Graphics.csproj" /> | ||
| <PackageReference Include="Microsoft.Win32.Registry" /> | ||
| <PackageReference Include="SharpDX.Direct3D11" Condition="'$(TargetFramework)' == '$(StrideFramework)' Or '$(TargetFramework)' == '$(StrideFrameworkUWP)'" /> | ||
| <PackageReference Include="Silk.NET.Direct3D11" Condition="'$(TargetFramework)' == '$(StrideFramework)' Or '$(TargetFramework)' == '$(StrideFrameworkUWP)'" /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
UWP might be removed by #2450. Just to keep in mind in case it gets merged. No need to fix it now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
microsoft/microsoft-ui-xaml#9983 (comment)
there is also the idea to make it available again
|
Yeah, I'm following the issue on UWP support. Will remove any reference entirely if not needed anymore. |
|
I'm starting to upload most of the changes that I think are mostly ready. As Direct3D 11 and 12 share a common way of doing things, I'm pushing just D3D 11 and DXGI for now. D3D 12 will come a bit later when I get feedback on D3D11. I've just started with the The question is: Should I do the documentation pass now? Or postpone it for a later time? |
|
Thank you @Ethereal77. Lots of updates here. I would be ok with docs later but in this case I woud like a feedback from @Eideren or @Kryptos-FR regarding the docs because in some cases it might be very important. |
|
I think it's fine to push the documentation here. As long as it's on a separate commit, it's always possible to do an offline review that ignore that particular commit. But let's wait for @Eideren's point of view. I'm not a graphics expert so my review will be a bit more superficial, and is less likely to be encumbered by lots of comments 😅. |
|
Yep, I agree with @Kryptos-FR, if you already have the docs, might as well include it. My thinking is that it may also help the reviewer |
|
I took the liberty to push some changes to your repo:
I will do some additional testing but hopefully we're getting very close to merging it in |
| // Somehow, this makes the compiler crash with internal errors in some cases when using loops | ||
| //if (profile >= GraphicsProfile.Level_10_0) | ||
| // shaderFlags |= D3DCOMPILE_SKIP_OPTIMIZATION; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@xen2 Have you noticed some regression with these? I had my reserves on this change, but couldn't test it properly yet.
|
Nice! I have some more improvements and docs in progress. Will better create new PRs for those, as this was becoming BIG already. |
|
@xen2 it looks like this PR wasn't merged correctly. Instead of doing the usual merge that either creates a merge commit or a squash merge that pushes a new commit on top of Instead we should always create a squash commit (I explain why in other PR's comment) and also never to manual merge locally bu use the merge feature on GitHub. I don't have the rights to force-push on master, so could you reset master to commit 1d45526, the merge this PR branch (commit b989a9c) to it and force push so that we get again a clean history. Then cherry-pick commits 0d02132 and 9a2f741. |
|
Apologies, I forgot left/right had a specific meaning/importance. |

PR Details
Replace SharpDX bindings for DXGI, Direct3D 11, Direct3D 12, the DirectX Shader Compiler, and any other use of SharpDX with Silk.NET bindings.
Description
SharpDX is the base for all the Direct3D (both 11 and 12) graphics frameworks in Stride. But SharpDX is no longer active nor mantained, the repository is archived, and the NuGets are still (and forever)
netstandard2.0. Also, it is based on aclass-based abstraction over the DirectX interfaces.Meanwhile, Silk.NET is a new bindings library created to take advantage of modern .NET, use the modern C# performance-oriented primitives and features (like
Span<T>, for example), and it's designed more as a raw bindings as close as possible to the underlying DirectX APIs, withoutclass-based abstractions. Its main drawback however is that it is inherentlyunsafe(in the context of using pointers and memory management directly) That however is of no importance to Stride as it will be under the hood of theStride.Graphicsframework.This PR consists of the following points:
Related Issue
This PR tries to solve issue #432. It is similar to PR #1123 by ykafia, but that one is pretty out of date at this point, so it was easier to start afresh branching the current
master.Motivation and Context
The motivation for converting to Silk.NET is twofold:
If all goes well with this PR, you should not see a difference in Stride. Maybe better performance and memory consumption. The improvement is mainly to be more up to date and more inline with modern .NET.
Types of changes
Checklist