Knowing which RHI has been used in a project from the code?

Is there any way which RHI has been used in a project from the code?
I’d like to handle DirectX directly so I’d like to know especially which of the DirectX (11 or 12) has been used in the project from the code.

I wonder if there are some macros like D3D11, or D3D12, and if I can write something like the following,

#ifdef D3D11
...
#elif D3D12
...
#else
...
#endif

I’d like to write some CUDA DirectX interoperability, and for that, I need to know the DirectX version being used, and I think I have to write both code for the packaged game.

Or is the default DirectX version used in 4.22 or 4.23 DirectX 11 unless we use Ray Tracing?

Thank you.

There no way to do this in compilation time as RHI is fully dynamic and can be switched on runtime, so on compilation time there no way to figure which RHI gonna be used and not mention as enigne is already compiled in launcher build. You need to check this on runtime, if you can not build specific functions if RHI is not active, you could do sperate module which loaded manually when specific RHI is used. You can get RHI information from here in im not mistaken

https://docs.unrealengine.com/en-US/API/Runtime/RHI/GetDynamicRHI/index.html

Pretty much everything in UE4 is modular and dynamic, only thing that i know that is statically build is platform support (FPlatform), but since platform can have multiple rendering library rendering is not part of it. No to mention Reader Hardware Interface has Interface in name for the reason

Thank you so much for your super quick reply!

I found the following question

and found that FHardwareInfo::GetHardwareInfo(NAME_RHI) mentioned above returns RHI name on runtime.

As far as I’ve searched the code, I think the return value is one of the followings, “D3D11”, “D3D12”, “OpenGL”, or “”.

And according to my experience (at least on my PC), if the Default RHI in Project Settings is set to “Default”, Direct3D 11 seems to be selected.