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.
Asked
Active
Viewed 2,655 times
3
-
If you don't use sharing, you have to copy it back via CPU memory which is going to be terribly slow. – Chuck Walbourn Nov 11 '16 at 23:25
-
@ChuckWalbourn To copy texture to CPU I would need to copy it to staging texture first? And to do that I would need device context which I don't have? – superg Nov 12 '16 at 07:26
-
You can't do any copies without the immediate device context. – Chuck Walbourn Nov 13 '16 at 21:57
-
@ChuckWalbourn In theory it looks like that, but in practise copying between device context works just fine if I ignore debug flags. – superg Nov 15 '16 at 16:47
-
Which means you are using undefined behavior that may work on some driver/video cards, but not others. – Chuck Walbourn Nov 15 '16 at 17:23
1 Answers
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
-
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