microsoft / media-foundation

Repository for Windows Media Foundation related tools and samples
MIT License
145 stars 31 forks source link

DirectX 12 Support #21

Closed jmoguillansky-gpsw closed 3 years ago

jmoguillansky-gpsw commented 3 years ago

It seems that Microsoft's Media Foundation APIs don't currently support DirectX 12?

What is the timeline?

See: https://docs.microsoft.com/en-us/windows/win32/api/mfobjects/nf-mfobjects-imfdxgidevicemanager-getvideoservice

mattrwoz commented 3 years ago

DX12 is supported in some scenarios (primarily: decoding, video processing, SourceReader). It is also supported by the IMFDXGIDeviceManager API, it looks like the documentation has not been properly updated however.

IMFDXGIDeviceManager::GetVideoService specifically will work fine when using a ID3D12Device pointer and IID_ID3D12Device. ResetDevice will also accept a ID3D12Device. Note that LockDevice, UnlockDevice and TestDevice should generally not be used with DX12 (DX12 is fully asynchronous and device removal is not possible).

Note that not all APIs will work if you pass a DX12 device to them. Notably SinkWriter, and MediaEngine both will fail when given a DX12 device. DX12 support for these APIs is still in progress.

jmoguillansky-gpsw commented 3 years ago

Hi, So currently it seems we need to use Directx11 as the decoding device (with Media Foundation), and DirectX 12 as the rendering device, and share the resources between DX11 and DX12?

It seems that DirectX 12 requires an "NT Handle". Is there any API in Media Foundation to create the resource as an "NT Handle" Then we can share it with directx 12?

robUx4 commented 2 years ago

IMFDXGIDeviceManager::GetVideoService specifically will work fine when using a ID3D12Device pointer and IID_ID3D12Device.

There's also ID3D12VideoDevice which is equivalent to ID3D11VideoDevice.

BTW a simple sample would be helpful. I have some code working but when closing everything it seems the underlying D3D12+DXVA decoder is leaking some ID3D12Fence (Win10 with NVIDIA GPU). On Xbox there's IMFD3D12SynchronizationObjectCommands to handle synchronization. ~But on desktop this interface doesn't exist~. It also available in Win10 21H1 (and Win11 I suppose).

In other cases on closing, it complains that there are some pending operations on a ID3D12CommandQueue that are still pending. After analysis it's some pictures that are "decoding" but were never sent to the display. Except there is no way to wait until these pending operations are done without faking use in another command queue and wait until the buffers are ready...

I suppose I'm missing something on the exit. I'm doing all these (in that order):