[Plugin] Including D3D11RHI & D3D12RHI at the same time.


I’m in the middle of the process of porting our plugin to Dx12. This week I started to integrate it with Unreal. As far as I can tell, Unreal works both with Dx12 and Dx11 without needing a recompile or anything like that, you just need to set the -d3d12 argument when launching the engine and then the appropriate RHI will be created.
That being said I need to include both RHIs in my “Plugin.Build.cs”:

// Include paths            
PublicIncludePaths.AddRange(new string] {

(Ignore the modules for now). The fact of only adding the dx12 include paths, and including lets say “D3D12RHIPrivate.h” from one of my cpp will cause errors like:

d:\unreal\4.17\unrealenginedx12\engine\source\runtime\d3d12rhi\private\../Public/D3D12Util.h(791): error C2084: function 'DXGI_FORMAT FindShaderResourceDXGIFormat(DXGI_FORMAT,bool)' already has a body

d:\unreal\4.17\unrealenginedx12\engine\source\runtime\d3d12rhi\private\../Public/D3D12Util.h(831): error C2084: function 'DXGI_FORMAT FindUnorderedAccessDXGIFormat(DXGI_FORMAT)' already has a body

I’m only adding the DX11RHI module to my plugin build script, so I understand that the problem is more basic, there is a collision of methods declared mutiple times.

How could I handle this problem? I need to support dx11 and dx12 from the plugin.



I would like to add an extra sample of the problem:

static DXGI_FORMAT GetRenderTargetFormat()

static DXGI_FORMAT GetRenderTargetFormat()

This is reporting a: error C2084: function ‘DXGI_FORMAT GetRenderTargetFormat(EPixelFormat)’ already has a body.

Unreal uses:

DynamicRHIModule = &FModuleManager::LoadModuleChecked<IDynamicRHIModule>(TEXT("D3D12RHI")); 

To select the RHI I guess that this will ensure that only one will be created, I’m wondering if what I want to do is possible (or at least in the way I want).

I solved this by doing some hacking. In my custom cpp that includes the D3D12RHI methods, I declare a few macros that override the name of the conflicting methods. At the end of my file I restore this macros to have the initial name. It is hacky, but it is working…

#define FindShaderResourceDXGIFormat    FindShaderResourceDXGIFormat_D3D12

// code...

#undef FindShaderResourceDXGIFormat