Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Copying Direct3D11 texture on other D3D11 device

Tags:

direct3d11

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.

like image 522
superg Avatar asked Oct 15 '25 02:10

superg


1 Answers

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.

like image 151
galop1n Avatar answered Oct 19 '25 13:10

galop1n