Download

Expose some DirectX 12's flags.

Recently I managed to connect Unreal Engine 4 and CUDA via DirectX 11 without custom engine build. “Connect” here means using some result on GPU memory by CUDA as a resource of Unreal Engine 4 directly, without passing CPU memory.

Now I’d like to do the same thing via DirectX 12, instead of DirectX 11.

In order to do so, ID3D12Resource such as vertex buffers or index buffers seem to have to be initialized with


D3D12_HEAP_FLAGS::D3D12_HEAP_FLAG_SHARED

and the fence, ID3D12Fence with


D3D12_FENCE_FLAGS::D3D12_FENCE_FLAG_SHARED

according to NVIDIA’s official sample code.
https://github.com/NVIDIA/cuda-sampl…es/simpleD3D12

However, RHI on DirectX 12 always uses either


D3D12_HEAP_FLAG_ALLOW_ONLY_BUFFERS | D3D12RHI_HEAP_FLAG_ALLOW_INDIRECT_BUFFERS

or


D3D12_HEAP_FLAG_ALLOW_ONLY_BUFFERS

https://github.com/EpicGames/UnrealE…tion.cpp#L1051

and the D3D12_FENCE_FLAGS is always


D3D12_FENCE_FLAG_NONE

https://github.com/EpicGames/UnrealE…anager.cpp#L64

We cannot change or add the flags without custom engine build (if I’m correct).

So it would be great if we can choose the flags freely like we can choose D3D12_RESOURCE_FLAGS (and D3D11_RESOURCE_FLAGS) through the argument


uint32 InUsage

(EBufferUsageFlags such as BUF_Static, BUF_UnorderedAccess) whenever we call RHICreateVertexBuffer.

Maybe we have to change all the RHICreateVertexBuffer, RHIAsyncCreateVertexBuffer, RHICreateAndLockVertexBuffer, or some other CreateBuffer-related functions by adding an extra argument such as InFlags, and change the default fence flag to D3D12_FENCE_FLAG_SHARED, but this kind of improved freedom will make it possible to connect CUDA and Unreal Engine 4 via DirectX 12.

It would be appreciated if I get some comments on this.
Thank you.