I’d like to share a UTexture2D and UVolumeTexture with another process (CUDA).
According to the UE4 code, TexCreate_Shared flag seems to be the option to do so.
// Texture that may be shared with DX9 or other devices
TexCreate_Shared = 1 << 24,
In fact, D3D11_RESOURCE_MISC_SHARED flag has been added.
https://github.com/EpicGames/UnrealEngine/blob/master/Engine/Source/Runtime/Windows/D3D11RHI/Private/D3D11Texture.cpp#L622
if (Flags & TexCreate_Shared)
{
TextureDesc.MiscFlags |= D3D11_RESOURCE_MISC_SHARED;
}
(I think it is better to replace D3D11_RESOURCE_MISC_SHARED with D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX, though.)
However, the format of the texture with TexCreate_Shared flag has been forcibly limited to DXGI_FORMAT_B8G8R8A8_UNORM.
https://github.com/EpicGames/UnrealEngine/blob/master/Engine/Source/Runtime/Windows/D3D11RHI/Private/D3D11Texture.cpp#L439
https://github.com/EpicGames/UnrealEngine/blob/master/Engine/Source/Runtime/D3D12RHI/Public/D3D12Util.h#L789
// DX 11(12) Shared textures must be B8G8R8A8_UNORM
if (InFlags & TexCreate_Shared)
{
return DXGI_FORMAT_B8G8R8A8_UNORM;
}
Is there any reason for it? If I’m correct, there is no DirectX 11 or 12’s limitation that the texture with D3D11_RESOURCE_MISC_SHARED flag has to be DXGI_FORMAT_B8G8R8A8_UNORM format, and as far as I looked into the UE4’s code, I could not find the place where the format has to be limited to DXGI_FORMAT_B8G8R8A8_UNORM.
Thank you.