Transferring textures across adapters in DirectX 1

2019-07-02 06:10发布

I'm capturing the desktop with the Desktop Duplication API from one GPU and need to copy the texture (which is in GPU memory) to another GPU. To do this I have a capture thread that acquires the desktop image then copies it to a staging resource (created on the same device) using ID3D11DeviceContext::CopyResource. I then map that staging resource with Read, map the destination dynamic resource (which was created on the other device) with WriteDiscard and copy the data. On the rendering thread, I do a ID3D11DeviceContext::CopyResource from the dynamic texture onto the final render target.

This works but I will get a random crash in nvwgf2umx.dll (Exception code: 0xc0000005) after a while (usually within 30 seconds). Both devices are created without the SingleThreaded creation flag. I did a bit of research and using a dynamic texture seemed like the best way to do this.

Any ideas on what's causing the crash? Could it be a bug specific to the Nvidia driver?

1条回答
ら.Afraid
2楼-- · 2019-07-02 06:48

You have to QueryInterface for a shared resource with the other device you are using. This would look like this in C# (what I guess you are really using beside given snippets in C++)

var sharedResource = aquiredDesktopTexture11.QueryInterface<SharpDX.DXGI.Resource>();
var sharedSurfDesktop = device11.OpenSharedResource<SharpDX.Direct3D11.Texture2D>(sharedResource.SharedHandle);

..were aquiredDesktopTexture11 is the copyed resource from the original capture, and sharedSurfDesktop then can be used by the other device. Also make sure the usage is mutual exclusive.

查看更多
登录 后发表回答