microsoft / WPFDXInterop

Repo for WPF DX Interop support
MIT License
307 stars 98 forks source link

WPFDXInterop with DirectX 12 (it throws exception on m_d3dDevice11on12->OpenSharedResource call #34

Open MartynSloss opened 6 years ago

MartynSloss commented 6 years ago

I can use DirectX 12 to write to a D3D11Image on a number of Windows 10 machines using a D3D11On12CreateDevice dx11 device.

{ .. IUnknown pUnk = (IUnknown)pResource; IDXGIResource pDXGIResource; ID3D11Resource pDx11Resource; HANDLE sharedHandle; ID3D11Resource tempResource11; ID3D11Texture2D pOutputResource; D3D11_RENDER_TARGET_VIEW_DESC rtDesc; rtDesc.Format = DXGI_FORMAT_B8G8R8A8_UNORM; rtDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D; rtDesc.Texture2D.MipSlice = 0;

pUnk->QueryInterface(uuidof(IDXGIResource), (void**)&pDXGIResource); pUnk->QueryInterface(uuidof(ID3D11Resource), (void)&pDx11Resource); pDXGIResource->GetSharedHandle(&sharedHandle)))return hr; m_d3dDevice11on12->OpenSharedResource(sharedHandle, __uuidof(ID3D11Resource), (void)(&tempResource11)); tempResource11->QueryInterface(__uuidof(ID3D11Texture2D), (void**)(&pOutputResource)); m_d3dDevice11on12->CreateRenderTargetView(pOutputResource, &rtDesc, &m_pRenderTargetView1);

pDXGIResource->Release(); tempResource11->Release(); ... }

However as soon as I enable debugging

ComPtr debugController; D3D12GetDebugInterface(IID_PPV_ARGS(debugController.GetAddressOf()); debugController->EnableDebugLayer();

I get the following error (exception thrown)

D3D12 ERROR: ID3D12CompatibilityDevice::ReflectSharedProperties: Resource provided was not shared by D3D11, or with a D3D11 desc. [ MISCELLANEOUS ERROR #916: REFLECTSHAREDPROPERTIES_INVALIDOBJECT]

Anyone have any idea what I am doing wrong?

MartynSloss commented 6 years ago

| suspect D2DImage11 is not being created as SHARED

MartynSloss commented 6 years ago

Not Closed: WPFDXInterop should be creating D2DImage11 as a shared resource So I can open it with OpenSharedResource

roman380 commented 6 years ago

Seeing the same problem in another context (and there seem to be no other mention of it)

D3D12 ERROR: ID3D12CompatibilityDevice::ReflectSharedProperties: Resource provided was not shared by D3D11, or with a D3D11 desc. [ MISCELLANEOUS ERROR #916: REFLECTSHAREDPROPERTIES_INVALIDOBJECT]

It looks like it's okay to create 11on12's texture and share it to 12. However if I try to share in the opposite direction the problem pops up...