-
-
Notifications
You must be signed in to change notification settings - Fork 1k
[WIP] 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
base: master
Are you sure you want to change the base?
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 |
* GraphicsException is the base of all exceptions for Stride.Graphics * GraphicsDeviceException is now the base exception for when GraphicsDevice.Status is the culprit
6641453
to
40b9fcd
Compare
* Also, some more ComPtrs instead of pointers
* To aid in debugging of resource lifetimes
* Also add the ability to set a name for a Graphics Resource in construction
* For now, non-configurable
* Also improves some of the debug facilities to better identify resources in logs and debugger
* Improve the documentation on Stride.Core types related to memory / disposables / reference counting * Improve the documentation on platform type enums
@Ethereal77 Curious, what's the state of this PR? (seeing it's still marked as draft) |
@Ethereal77 Also, considering the huge amount of effort, we would like to offer a bounty of $1500 (at least) once this task is completed. |
The PR is almost done. I'm running the test projects and correcting / fixing some small quirks. My intent is to have it ready as soon as possible. I can rebase it and push the current state if people want to start testing / reviewing. I'm currently tracking down some tests that fail with invalid output (wrong alpha blending due to some zeroed-out description struct), or produce exceptions due to wrong parameters, but right now ~90% of the graphics tests pass with resulting images similar to reference.
Thank you. I appreciate it. |
Btw, tests are quite difficult to debug with RenderDoc since the migration to Avalonia (it throwns an exception inside the MicroCom interop layer of AvaloniaUI). Attach to running process doesn't work either for some reason. That is making finding some problems a little hard. Do someone know how to make it work? I've seen |
Oh, and another thing that crossed my mind the other day @xen2 (for a different PR, not this one) Would it make sense to, for the graphics tests when the platform is Direct3D, to use WARP as the adapter? If the goal is to test the renderer and catch regressions, the GPU is not very important, just the results of the rendering. WARP is always present, it is slower, but for tests ran sporadically it won't matter much, and it would make the need to still count with that GTX 960 redundant. Finally, as WARP is software based, everyone that runs the tests will get a consistent 1:1 output unless there are true regressions or changes. (with WARP I mean the Windows Advanced Rasterization Platform) |
We have this section in the manual about render doc https://doc.stride3d.net/latest/en/manual/troubleshooting/profiling.html?q=renderdoc#use-renderdoc not sure how useful that could be in your particular case but might as well share just in case |
I've managed to get the tests to generate a RenderDoc capture by forcing it in GameTestBase (although it can also be done via an environment variable). With this, I can now review the tests that are behaving strangely. |
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.Graphics
framework.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