Sign in to follow this  
AlexandreMutel

SharpDX 1.0 released. A new .Net managed DirectX API

Recommended Posts

AlexandreMutel    1105
Hi all,

I'm pleased to announce the 1st release of SharpDX 1.0, an opensource project that provides a new plartform independent .Net managed DirectX API.

Key features of this project are:
  • API is generated from DirectX SDK headers : meaning a complete and reliable API and an easy support for future API.

  • Full support for the following DirectX API:
    • Direct3D10
    • Direct3D10.1
    • Direct3D11
    • Direct2D1 (including custom rendering, tessellation callbacks)
    • DirectWrite (including custom client callbacks)
    • D3DCompiler
    • DXGI
    • DXGI 1.1
    • DirectSound
    • XAudio2
    • XAPO
    • An integrated math API directly ported from SlimMath

  • Pure managed .NET API, platform independent : assemblies are compiled with AnyCpu target. You can run your code on a x64 or a x86 machine with the same assemblies, without recompiling your project.

  • Lightweight individual assemblies : a core assembly - SharpDX - containing common classes and an assembly for each subgroup API (Direct3D10, Direct3D11, DXGI, D3DCompiler...etc.). Assemblies are also lightweight.

  • C++/CLI Speed : the framework is using a genuine way to avoid any C++/CLI while still achieving comparable performance.

  • API naming convention mostly compatible with SlimDX API.

  • Raw DirectX object life management : No overhead of ObjectTable or RCW mechanism, the API is using direct native management with classic COM method "Release".

  • Easily mergeable / obfuscatable : If you need to obfuscate SharpDX assemblies, they are easily obfusctable due to the fact the framework is not using any mixed assemblies. You can also merge SharpDX assemblies into a single exe using with tool like ILMerge.

You will also find a growing collection of samples in the Samples Gallery of SharpDX. Most notably with some additional support for Direct2D1 and DirectWrite client callbacks.

Share this post


Link to post
Share on other sites
MJP    19755
Quote:
Original post by AlexandreMutel
C++/CLI Speed : the framework is using a genuine way to avoid any C++/CLI while still achieving comparable performance.


Have you run any benchmarks comparing your new library to SlimDX?

Share this post


Link to post
Share on other sites
AlexandreMutel    1105
Quote:
Original post by MJP
Have you run any benchmarks comparing your new library to SlimDX?


Sure, here is a micro-benchmark on two methods, ID3D10Device1::GetFeatureLevel (alias Device.FeatureLevel) and ID3D10Device::CheckCounterInfo (alias Device.GetCounterCapabilities).

The test consist of 100,000,000 calls on each methods (inside a for, with (10 calls to device.FeatureLevel) * 10,000,000 times) and is repeated 10 times and averaged. Repeated two times (results in ms, lower is better) :

Method SlimDX SharpDX SharpDX vs SlimDX
device.FeatureLevel 3700 3650 1,37%
device.GetCounterCapabilities() 4684 4259 9,98%

For FeatureLevel, sometimes, the test was sometimes around +/-0.5%.
For GetCounterCapabilities(), the main difference between SharpDX and SlimDX implementation is that SlimDX perform a copy from the native struct to .Net struct while SharpDX is directly passing a pointer to the .Net struct.

This test is of course a micro benchmark and doesn't reflect a real-world usage, and thus, should be taken with caution. Some part of the API could be in favor of SlimDX (for example, sometimes, SlimDX doesn't test the HRESULT returned by some methods), but I'm pretty confident that SharpDX is much more consistent in the way structures are passed to the native functions (due to the fact that the marshaling code is generated), avoiding as much as possible marshaling structures that doesn't need any custom marshaling (unlike SlimDX that is performing most of a time a marshaling between .Net/Native structure, besides they are binary compatible).

I have been able to port a pretty large engine that was using Direct3D10 SlimDX, and FPS performance were at least equal, if not slightly better for SharpDX (though tests were probably more GPU bounded than CPU bounded).

SharpDX is using a custom interop and marshaling layer that doesn't rely on default p/invoke .Net marshaling, being able to achieve identical performance to raw C++/CLI, everything else being equal.

Share this post


Link to post
Share on other sites
JohnnyCode    1046
Quote:

the main difference between SharpDX and SlimDX implementation is that SlimDX perform a copy from the native struct to .Net struct while SharpDX is directly passing a pointer to the .Net struct.


C# applications can be faster then c++ becouse c++ on every call to 'new' allocates a memory from OS while C# uses a preallocated memory pool, restriction is you can't read the memory in c++.

But if in c++ you use preallocated pool for all local variables that sets the persistent data, then it is a question wheather C# managed pool is faster then OS managed pool working with unmanaged local pool. Managing memory is a very difficult task and if you write a managed pool with two features
1- to memory of this continuos length program can write , give the pointer to such a memory
2- OK Pool, I know you can run out of memory, so I am freeing this memory back to you

If this pool with those two features will perform faster than OS you are a must-meet with Bill Gates.

Also, you can use Pascal c++ aprouch- allocating all variables before the program is run and in the program still have a feature of allocating memory.

You can make a very fast managed pool if you will allocate only a certain data type-class (know amount of size allways).
So if you have classes in your project that you need to allocate during the program, make an allocator for them.



Share this post


Link to post
Share on other sites
AlexandreMutel    1105
Quote:
Original post by JohnnyCode
C# applications can be faster then c++ becouse c++ on every call to 'new' allocates a memory from OS while C# uses a preallocated memory pool, restriction is you can't read the memory in c++.

Indeed, I'm aware about this. ;)

But I was talking about c++/CLI, which in this case is slightly different than pure c++. When using c++/cli, most of a code, even written in c++ (even accessing c++ structures, calling c++ methods...etc.) will be in fact translated in pure managed code without using any c++ allocation memory function (allocation, memcpy... etc.) The CLI bytecode for C++/CLI is the same as the one generated by C#, but C# doesn't give an access to some of those usefull CLI bytecode instructions that C++/CLI is using directly. SharpDX bring some of those CIL instructions directly in order to get rid of c++/cli usage.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this