How does Unreal Engine interact with DirectX?

Hey Everyone! This is my first post. I want to get a better understanding of the relationship between UE4 and DirectX 11.

At this point I understand that DirectX is a set of APIs and that you can add to it using the SDK that Microsoft provides. But what goes on between the UE4 code and those DX APIs? Specifically how does the engine or the editor’s renderer interact with Directx?

More importantly, would it be useful to write new functions using the DirectX SDK if I want to render my graphics using unreal engine? Or would that be redundant?

What you are looking for is called RHI, RenderHardwareInterface.

Each graphics api that UE support has implements a RHI with api specific calls.

D3D11 is located in Source/Runtime/Windows/D3D11RHI
D3D12 is located in Source/Runtime/D3D12RHI
OGL is located in Source/Runtime/OGLDrv
Vulken is located in Source/Runtime/VulkenRHI

Also look at FDynamicRHI, this is the base interface that is implemented by the RHIs above, each function of this interface is implemented with api specific calls.

Beyond that you have the resources (Textures, Buffers ect.) they are also api specific and their base classes are located in Source/Runtime/RHI/Public/RHIResources.h

The api specific resources are derived from FRHIBuffer,FRHITexture… and the contain the wrapper of the api specific resource that in it’s turn holds the native api resource.

When unreal starts up it creates the requested DynamicRHI and stores it as a pointer to the base interface and from this point you call the functions of that.

There are some rare cases when the DynamicRHI dose not implement some feature of the api that you need or you work with middleware that needs access to the native api you can call the api directly, but those cases are rare (one of them can be found in the oculuse plugin: Plugins\Runtime\OculusRift\Source\OculusRift\Private\OculusRiftRenderD3D12.cpp, Plugins\Runtime\OculusRift\Source\OculusRift\Private\OculusRiftRenderD3D11.cpp, Plugins\Runtime\OculusRift\Source\OculusRift\Private\OculusRiftRenderGLcpp).

3 Likes

Wow, big thanks lion032.