Guidance Sought for DX12 with MonoGame

I’ve started reading Frank Luna’s new book, 3D Game Programming with DirectX 12, and I encountered this interesting statement in the Introduction: “Although Direct3D 12 is usually programmed from native C++, the SharpDX team (http://sharpdx.org/) is working on .NET wrappers so that you can access this powerful 3D graphics API from managed applications.” The book was released in March 2016, so that statement was written well before that.

I thought I might try giving it a shot with MonoGame as soon as I get tempted with a good example. (All of Luna’s sample programs are C++. I’ll try to reproduce them with C#.)

Does anyone care to give me some guidance?

sadly MonoGame does not incorporate the newest SharpDX and the MonoGame fx compiler works with DX11 only.

So unless you are willing to build your own fork of MonoGame with dx12 we can’t really give you guidance since it simply doesn’t support Dx12.

:frowning:

That is indeed sad. Depressing really. So, I guess it’s back to C++.

The plan is to create a new graphics API for MonoGame that can use DX12/Vulkan/Metal as backend. It won’t be easy to unify this all and it will take a bunch of planning, researching and implementing to get it all in working order so it will definitely take a while. AFAIK no one is actively working on the new API or implementing any of these in the existing API. If anyone is interested in contributing, check out https://github.com/MonoGame/MonoGame/issues/4571 and open an issue on GitHub or join chat on Gitter.

Once that’s all done there’s still the Effects that need to be compiled for different Graphics backends. A quick write-up on the status of Effects/shaders:

Currently proprietary Windows-only DX tools are used to optimize and precompile hlsl shaders. This is why you can only build effect on Windows. The plan is to support pure glsl, but another issue is it needs to be optimized (especially for mobile). MojoShader is used to translate (optimized) hlsl bytecode to glsl, so it outputs optimized glsl, but it requires building the hlsl first. It also doesn’t support geometry/hull/domain/compute shaders. Then there is the problem of fx specific stuff that needs to be put into the glsl format. The plan is to

  1. Replace MojoShader with a tool that translate hlsl source to glsl (HLSL2GLSL)
  2. Implement a glsl parser for 2MGFX (the MG effect building tool) to get necessary shader reflection data.
  3. Add a glsl optimizer (probably https://github.com/aras-p/glsl-optimizer/blob/master/README.md)

This skips over some details, read from https://github.com/MonoGame/MonoGame/issues/2167#issuecomment-173381161 to the end of the issue for the full status and plan.

I’m not sure if Vulkan changes any of this, but I don’t think so because Vulkan isn’t widely supported yet. Once the glsl pipeline is in place we just need to include glslang to translate shaders to SPIR-V for Vulkan. I think the glsl optimizer I linked can also output shaders for Metal. So when all previous steps are done there will a lot of freedom in shaders for MG. You can write shaders in hlsl or glsl and build for OpenGL, DX (on Windows only), Metal or Vulkan To be fully cross platform we should also be able to translate glsl to hlsl and compile hlsl from non-Windows OS’. I don’t know if Tom wants to include the last step in MG itself. Either way the glsl translation and optimization are priority.

It would be really neat if someone has time to work on this stuff!

I don’t think I can help you with that. Although I’m retired, at age 78 and in poor health, I can’t plan on taking a lot of time with anything.

Thanks for taking the time to explain the situation in some detail. I think, in my case, the best bet is for me to rejuvenate my C++.

Walt

In that case I wish you good health and good luck! I hope you’re still as eager when we get this all worked out :slight_smile: