stride icon indicating copy to clipboard operation
stride copied to clipboard

[WIP] Convert from SharpDX to Silk.NET.

Open Ethereal77 opened this issue 2 years ago • 40 comments

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 a class-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, without class-based abstractions. Its main drawback however is that it is inherently unsafe (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 the Stride.Graphics framework.

This PR consists of the following points:

  • [x] Convert Direct3D 11 framework to Silk.NET.Direct3D11.
  • [x] Convert Direct3D 12 framework to Silk.NET.Direct3D12.
  • [x] Convert DirectX Shader Compiler to Silk.NET.Direct3D.Compilers.
  • [x] Improve the documentation on DirectX-related methods and types, removing references to SharpDX or to the native constants, types, or functions where appropriate.
  • [x] Introduce small convenience types and helper functions to aid in the implementation of interop improvements like this one, now and in the future.

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:

  • The SharpDX libraries are pretty solid and stable at this point. However its design filosophy (more to be used as a framework itself ala XNA) and its age makes us lose opportunities to improve performance, control memory allocations more tightly and take advantage of modern C#. Also it is no longer mantained, so no more bug fixes or improvements of any kind.
  • Silk.NET is actively mantained and uses all the utilities modern C# and .NET has to offer. As it is actively mantained it's easier to get bug fixes and improvements, and more importantly, access to future (and current) technologies we may be interested in (like DirectStorage, DXVA, etc).

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

  • [x] Docs change / refactoring / dependency upgrade
  • [ ] Bug fix (non-breaking change which fixes an issue)
  • [ ] New feature (non-breaking change which adds functionality)
  • [ ] Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • [x] My change requires a change to the documentation.
  • [ ] I have added tests to cover my changes.
  • [ ] All new and existing tests passed.

Ethereal77 avatar Jul 18 '23 20:07 Ethereal77

i can't build this branch via some errors has not resolve

ly3027929699 avatar Oct 21 '23 09:10 ly3027929699

@ly3027929699 Yeah, the PR is still marked as wip, you shouldn't expect it to work as is yet :P

Eideren avatar Oct 21 '23 14:10 Eideren