Announcing Silk.NET 2.17: Cleaner Code, Smoother Experience.
Are you tired of wading through messy code to achieve the smooth performance you need for your GPU applications? If so, it's time to upgrade to Silk.NET 2.17. This latest update delivers faster, cleaner code and a smoother experience than ever before, making it the easiest way to achieve top-tier performance without sacrificing usability. With Silk.NET 2.17, you can experience the power of clean code, achieve silky-smooth performance, and write code that feels right at home with the rest of your C# code.
Reworked DirectX bindings, added new WebGPU, Direct2D, DirectComposition, DirectWrite, and D3D11-on-12 bindings, as well as better support for Android 12, Windows on ARM64, reflection-free NativeAOT, and drop-in DXVK support. This, coupled with a whole lot of other enhancements & bugfixes mean there's something for everyone in Silk.NET 2.17, the largest user experience improvement update to date. Find out what's new in 2.17!
Today, we’re releasing Silk.NET 2.17, and we're not kidding when we say it's this is the largest user experience improvement we've done so far. Silk.NET 2.17 is the culmination of just over 8 months of work by lots of people, and we're so glad to finally release it!
You can download Silk.NET 2.17 from NuGet: https://nuget.org/packages/Silk.NET/2.17.0
Patch notes at a glance
Don't need the full scoop? No worries, here's a summary of what's been going on:
- Added zero-cost extension methods for ComPtrs, making our DirectX bindings easier to use and higher quality than ever before.
- Added WebGPU bindings for Dawn and WGPU.
- Added Direct2D bindings. (massive thank you to @curin)
- Added DirectComposition bindings. (again, massive preesh to @curin)
- Added DirectWrite bindings.
- Added d3d11on12 bindings.
- Added WGL bindings.
- Added support for Android 12.
- Added support for OpenAL disconnect extension. (thanks @okaniku)
- Added GLFW API constants for ANGLE. (thanks @cyraid)
- Added extension functions for OpenAL BufferData to make use of AL_EXT_float32 enums.
- Added ReopenDevices extension for OpenAL Soft. (thanks @LeNitrous)
- Added BufferCallback extension for OpenAL Soft.
- Added Vulkan structure chain polymorphism. (thanks @Khitiara for the proposal)
- Added SDL/GLFW native libraries for Windows on ARM64.
- Added IsScancodePressed function in Silk.NET Input.
- Added TopMost in Silk.NET Windowing (thanks @MarioGK)
- Added EGL display and surface to INativeWindow.
- Added an explicit check against calling Reset on a window while within the render loop of said window.
- Added support for multiple native binary candidate paths for a single binding.
- Improved support for WASM and AOT in the Silk.NET loader.
- Improved support for Windows on ARM64.
- Improved Silk.NET.Maths generic specialization codegen.
- Improved support for DXVK, including a new DXHandle property in INativeWindow for getting Linux HWND equivalents.
- Improved support for Silk.NET.Windowing under reflection-free NativeAOT
- Updated to SDL 2.24.
- Updated to Vulkan 1.3.246.
- Updated to DirectStorage 1.1.1.
- Updated to OpenXR 1.0.27.
- Updated to Assimp 5.2.5.
- Updated to latest OpenCL specifications.
- Updated to latest OpenGL specifications.
- Updated to latest ImGui.
- Fixed XInput GetApi not being implemented. (thanks @skyebird189)
- Fixed TransparentBuffer not being applied correctly without specifying a PreferredBitDepth. (thanks @MarioGK)
- Fixed wide string marshalling.
- Fixed string array marshalling on systems where the max DBCS character size is insufficient for UTF8.
- Fixed Span overloads not calculating the correct length value for ommitted (implicit) length parameters.
- Fixed copying of native libraries under .NET Framework 4.6.1. (thanks @paralaxsd)
- Fixed SDL crashing on Android when the screen rotates in some cases.
- Fixed a memory leak when using GlobalMemory to marshal string arrays instead of StringArrayToPtr. (thanks @Khitiara)
I know what you're thinking, they're longer patch notes than I was expecting too! That's in no small part due to the passionate community that has contributed a lot towards this release.
Migration Guidance
This is a minor release (albeit as major as minor releases get), so we're not going to go into too much detail here. However we'll note a few things to keep in mind when upgrading to this version:
- We have updated the versions of some of our BCL libraries, such as System.Memory. If you explicitly import these into your projects, you will also need to upgrade to the latest versions of these libraries.
- You may get some obsolete warnings when you upgrade from a pre-2.16 version of Silk.NET. This is because we have deprecated some enum names that were needlessly verbose, and trimmed any common elements of these. Your compiler and IDE should be good at telling you what the recommended alternative is. This isn't new for 2.17, but because we didn't write a blog post/migration guidance for 2.16 we thought it was worth calling this one out.
- We have removed some overloads that were causing widespread confusion and/or misuse in the pre-2.17 Silk.NET versions. This is mostly pertaining to in/out/ref for opaque types, but there may be more. Chances are if you have to make any changes as a result of this update, your existing code was likely non-functional and/or sub-optimal (be that in terms of either performance or readability).
Other than that, your code should work as-is with this new verison, but we do recommend taking time to take advantage of the new user experience improvements (particularly with DirectX)! As always, please let us know in GitHub Discussions or our Discord server if you have issues migrating to this verison of Silk.NET.
DirectX usability improvements
Development Lead: Dylan Perks (@Perksey)
If you're a fan of DirectX, you'll be pleased to hear that 2.17 includes major improvements in usability for our DirectX family of bindings. With this update, you can now call methods directly off of a ComPtr<T> of your type, making it easier than ever to work with DirectX. Plus, you no longer need to deal with interface GUIDs yourself - we've done our best to abstract this away the same way IID_PPV_ARGS
abstracts it away in C++ land. This massive user experience improvement for our DirectX family of bindings is sure to make your life easier and your code cleaner than ever before. Let's take a look at some samples:
Before
// Declare our IDXGIFactory2 output pointer
void* factoryOut = null;
// Manually get GUID to get factory interface pointer.
dxgi.CreateDXGIFactory2(0, SilkMarshal.GuidPtrOf<IDXGIFactory2>(), ref factoryOut);
// Cast the output to the correct type and store the interface pointer.
_factory = (IDXGIFactory2*) factoryOut;
// Manually get the IUnknown pointer to the device for CreateSwapChainForHwnd
void* swapChainOut = null;
fixed (IUnknown* device = &_device)
{
_factory->CreateSwapChainForHwnd(device, window.Native.Win32.Value.Hwnd, ref swapChainDesc, ref fullscreenDesc, null, ref swapChainOut);
}
_swapchain = (IDXGISwapChain1*) swapChainOut;
After
// Create the factory, storing the interface pointer safely as a ComPtr<IDXGIFactory2>.
_factory = dxgi.CreateDXGIFactory2<IDXGIFactory2>();
// Create the swapchain, calling the method directly on the ComPtr and once again storing safely as a ComPtr<IDXGISwapChain1>
// DEVELOPER NOTE: We know that the Unsafe.NullRef isn't the prettiest and we are working on a fix!
_factory.CreateSwapChainForHwnd(device, window.Native.Win32.Value.Hwnd, ref swapChainDesc, ref fullscreenDesc, ref Unsafe.NullRef<IDXGIOutput>(), ref _swapchain);
Much cleaner! The goal here is to place an emphasis on properly managing your COM pointers through ComPtr
. And don't worry about overhead, the codegen for these new abstractions is identical to doing all of this yourself.
Behind the Scenes
To improve the usability of our DirectX family of bindings, we took several steps in Silk.NET 2.17. First, we added extension methods to the ComPtr
To address this, we introduced two new overloaders: the ComPtrOverloader and the NonKhrReturnTypeOverloader. The ComPtrOverloader looks for parameter signatures that match the IID_PPV_ARGS pattern, and creates a generic ref ComPtr
The NonKhrReturnTypeOverloader takes things a step further by identifying functions whose last argument is a ref (which, after the ComPtrOverloader has worked its magic, will be the case for methods that return COM pointers). It changes that parameter to be the return type of that function instead. This is what gives users the nice CreateDXGIFactory2 experience seen in the example snippet earlier in this post.
We're always trying to improve the experience of using our bindings, so please let us know in this tracking issue if you have any feedback or ideas for improvements! As always, you can also reach us in Discord or GitHub Discussions.
WebGPU bindings
Development Lead: Beyley Thomas (@Beyley)
We've added bindings to the experimental webgpu-headers maintained by the various vendors of WebGPU drivers! WebGPU is an API that exposes the capabilities of GPU hardware for the Web. The API is designed from the ground up to efficiently map to modern native GPU APIs such as Vulkan and Direct3D 12, and is touted to be the modern replacement for WebGL.
While these bindings have "web" in the name, using either the Dawn or WGPU implementations of WebGPU (for which we ship native binaries) you can use this as a single API to target all of the various platforms that would otherwise have platform-specific APIs! This allows you to write truly write-once-run-everywhere code.
The Silk.NET logo rendered using WebGPU.
Please note these bindings do not work in browsers yet due to issues with the .NET WebAssembly runtime.
More DirectX Bindings
Development Lead: Andrew Davis (@curin) [Silk.NET Community]
In addition to the major improvements in usability for our DirectX family of bindings, we're excited to announce that Silk.NET 2.17 also includes bindings for Direct2D, DirectComposition, and DirectWrite. Direct2D has been among the most requested features from our users, and we're thrilled to be able to deliver on them with this release.
Direct2D is a 2D vector graphics application programming interface (API) that allows for the creation of visually rich 2D graphics. This marks our first binding to a native library dedicated solely to vector graphics. On the other hand, DirectComposition provides advanced compositing and visual effects capabilities to enable high-performance bitmap composition with transforms, effects, and animations. You can use our DirectComposition bindings to create visually engaging user interfaces that feature rich and fluid animated transitions from one visual to another. Finally, DirectWrite is a text layout and rendering API that supports high-quality text rendering for both display and print, quite 5closely integrated with Direct2D.
We're especially proud to note that much of the work on these new bindings was done by a community member, @curin, who took the initiative to drive these additions. The Silk.NET team only had to do minor rework to integrate them into the library. This is a great example of how Silk.NET is a true community-driven project, with users and contributors working together to create a better development experience for everyone.
Platform Expansion
Development Lead: Dylan Perks (@Perksey) / Beyley Thomas (@Beyley)
In Silk.NET 2.17, we focused heavily on expanding platform support and increasing the portability of Silk.NET code. To achieve this, we made Silk.NET compatible with reflection-free NativeAOT, previously known as CoreRT, which enables developers to create minimal distributions of their games and applications. Additionally, we added support for Android 12, which was previously incompatible with Silk.NET 2.16 due to recent changes in the Android permissions API.
In addition to expanding platform support and portability, we have also been doing increased testing on Windows on ARM using the Volterra development kit. As a result, we're excited to announce that Silk.NET is now fully compatible with Windows on ARM. While your mileage with the Volterra graphics drivers may vary, we have added D3D11-on-12 bindings in 2.17 to allow developers to wield the Direct3D 11 API you all know and love using the Direct3D 12 drivers, which tend to be in better shape on newer devices.
But perhaps the biggest news is the newfound portability of Silk.NET across different operating systems. For developers who prefer DirectX over other graphics APIs, they can now use the Direct3D bindings they love almost out-of-the-box on Linux using the DXVK and VKD3D native libraries, which Silk.NET now has full support for. In fact, we've made one of our examples DXVK compatible, and it only took just a few lines of code changes to make it fully portable across Windows and Linux using Silk.NET.Windowing. We also support DXVK to be used manually with our GLFW or SDL bindings, for those who are inclined to do so!
Note: While we do use VKD3D's shader compiler to replace D3DCompiler on Windows, D3D12 through VKD3D is not supported at the moment, only D3D9 and D3D11 code will work natively on Linux. (community contributions welcome!)
Closing
Silk.NET 2.17 is here, and it brings a lot of improvements to the table. With faster, cleaner code and a smoother experience, Silk.NET 2.17 is the best way to achieve top-tier performance while also writing code that feels right at home with the rest of your C# codebase. This latest update delivers reworked DirectX bindings, WebGPU bindings, Direct2D, DirectComposition, DirectWrite, D3D11-on-12, Android 12, Windows on ARM64 support, better AOT support, drop-in DXVK support, and a host of enhancements and bug fixes. In short, Silk.NET 2.17 is the largest user experience improvement we've done so far, and we've barely even scratched the surface in this blog post! (Did you see those patch notes?!)
You can download Silk.NET 2.17, as you always have, from NuGet.