3

I have a handle to ID3D11Texture2D, but no access to it's ID3D11DeviceContext or ID3D11Device. I want to copy that texture to other texture on other ID3D11Device. Texture is not created with any sharing flags. If I try to copy with ID3D11DeviceContext::CopyResource I get warning "D3D11 CORRUPTION parameter does not match device". How can I copy the texture or it's contents? I guess this is possible, since for example OpenVR API only uses texture handle without any context.

superg
  • 379
  • 1
  • 6
  • 19

1 Answers1

5

If a texture is not created with the sharing flag, you cannot use it between two devices.

But you have the texture object, that is a ID3D11DeviceChild and it is enough to get access to ID3D11DeviceChild::GetDevice to retrieve the device and by extension ID3D11Device::GetImmediateContext

Now that you have access to the device and the context, you can create an extra texture with the sharing flag D3D11_RESOURCE_MISC_SHARED on the original device or your own and retrieve back the object on the other one with ID3D11Device::OpenSharedResource. And finally copy the original texture to the new object with CopyResource

Don't forget that all theses Get add reference to the objects that need to be released once you are done with them.

galop1n
  • 8,573
  • 22
  • 36
  • 1
    Works like a charm and solves my problem perfectly. Thanks a lot! – superg Nov 16 '16 at 12:33
  • Hi galop1n, can I ask you for your help, I've tried what you had described here but without any success. Here is my original question https://stackoverflow.com/questions/58342736/copy-ffmpeg-d3dva-texture-resource-to-shared-rendering-texture. Thank you for any kind of help – Teamol Oct 12 '19 at 12:34