microsoft / D3D11On12

The Direct3D11-On-12 mapping layer
MIT License
274 stars 33 forks source link

MediaFoundation / DirectX 12 interop #24

Closed jmoguillansky-gpsw closed 3 years ago

jmoguillansky-gpsw commented 3 years ago

Hi, I'm trying to enable direct mapping of decoded buffers from Media Foundation as DirectX 12 textures. The problem is MediaFoundation doesn't support DirectX 12.
I tried two approaches: 1) Create a DirectX 11 device. Use CreateSharedHandle to create a shared NT handle from the IMFDXGIBuffer. I get an error "Parameter is incorrect".
2) Create a D3D11On12Device. Use CreateSharedHandle to create a shared NT handle from the IMFDXGIBuffer. I also get the same error "Parameter is incorrect".

My question is: how do we enable interop between MediaFoundation and DirectX 12? It seems that the IMFDXGIBuffer is not an NT handle while DirectX 12 requires an "NT handle"?

I also set MF_SA_D3D11_SHARED to true. It doesn't seem that Media Foundation provides any option to allocate an "NT handle"?

Please advise.

jenatali commented 3 years ago

D3D12 does support opening non-NT handles. However, be aware that once you're going cross-device, you need to worry about synchronization, either with keyed mutexes or fences.

You can use D3D11On12 with the ID3D11On12Device2 methods (UnwrapUnderlyingResource and ReturnUnderlyingResource) to avoid having to use a second device. These operations allow you to synchronize to a specific queue on the same D3D12 device.

jmoguillansky-gpsw commented 3 years ago

Perfect, thanks!