Alex Borgue
Alex Borgue

Reputation: 153

Sharing ID3D11Buffer and ID3D12Resource

In D3D11/D3D12, Is it at all possible to share an ID3D11Buffer with an ID3D12Resource one way or the other? I know it's possible to share ID3D11Texture2D, but it seems like ID3D11Buffer sharing across API versions is not possible. I see no no valid reasons why it wouldn't be allowed since an ID3D12Resource can represent a buffer as well as a texture2d.

I don't really care what the direction of the sharing is (D3D11 -> D3D12 or D3D12 -> D3D11 is fine). I just need to find a way to share that resource since we have an hybrid application for now, and we don't want to uselessly copy the data. Texture2D doesn't work as width/height and color format don't really make sense for our use case.

Upvotes: 2

Views: 4678

Answers (1)

Chuck Walbourn
Chuck Walbourn

Reputation: 41047

You can indeed share resources between Direct3D 11 and Direct3D 12. I do so in the VideoTexture sample (UWP version / PC version) which you can reference.

  • You create the resource in one API.

If you create the ID3D12Resource to share, you need to use D3D12_HEAP_FLAG_SHARED when creating the resource, and you need to use D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET | D3D12_RESOURCE_FLAG_ALLOW_SIMULTANEOUS_ACCESS in the resource description. For Direct3D 11.1 creating a resource, you need to use D3D11_RESOURCE_MISC_SHARED_NTHANDLE because DirectX 12 only supports the newer "NT handle" model.

  • You then obtain the share handle.

For Direct3D 12, this is done with CreateSharedHandle on the Direct3D 12 device. For Direct3D 11.x, you have to query the IDXGIResource1 interface in order to call this method.

  • You then use the shared handle to create the resource instance in the other API.

For Direct3D 11.x sharing a resource created by DirectX 12, use OpenSharedResource1. For DirectX 12, use OpenSharedResource.

See the docs.

Upvotes: 5

Related Questions