Give a device access to a shared resource created on a different device.
public:
HRESULT OpenSharedResource(
HANDLE hResource,
REFIID ReturnedInterface,
void **ppResource
)
hResource
Type: HANDLE
[in] A resource handle. See remarks.
ReturnedInterface
Type: REFIID
[in] The globally unique identifier (GUID) for the resource interface. See remarks.
ppResource
Type: void **
[out, optional] Address of a pointer to the resource we are gaining access to.
Type: HRESULT
This method returns one of the following Direct3D 11 return codes.
The REFIID, or GUID, of the interface to the resource can be obtained by using the __uuidof() macro. For example, __uuidof(ID3D11Buffer) will get the GUID of the interface to a buffer resource.
The unique handle of the resource is obtained differently depending on the type of device that originally created the resource.
To share a resource between two Direct3D 11 devices the resource must have been created with the D3D11_RESOURCE_MISC_SHARED flag, if it was created using the ID3D11Device interface. If it was created using a DXGI device interface, then the resource is always shared.
The REFIID, or GUID, of the interface to the resource can be obtained by using the __uuidof() macro. For example, __uuidof(ID3D11Buffer) will get the GUID of the interface to a buffer resource.
When sharing a resource between two Direct3D 10/11 devices the unique handle of the resource can be obtained by querying the resource for the IDXGIResource interface and then calling GetSharedHandle.
IDXGIResource* pOtherResource(NULL);
hr = pOtherDeviceResource->QueryInterface( __uuidof(IDXGIResource), (void**)&pOtherResource );
HANDLE sharedHandle;
pOtherResource->GetSharedHandle(&sharedHandle);
The only resources that can be shared are 2D non-mipmapped textures.
To share a resource between a Direct3D 9 device and a Direct3D 11 device the texture must have been created using the pSharedHandle argument of CreateTexture. The shared Direct3D 9 handle is then passed to OpenSharedResource in the hResource argument.
The following code illustrates the method calls involved.
sharedHandle = NULL; // must be set to NULL to create, can use a valid handle here to open in D3D9
pDevice9->CreateTexture(..., pTex2D_9, &sharedHandle);
...
pDevice11->OpenSharedResource(sharedHandle, __uuidof(ID3D11Resource), (void**)(&tempResource11));
tempResource11->QueryInterface(__uuidof(ID3D11Texture2D), (void**)(&pTex2D_11));
tempResource11->Release();
// now use pTex2D_11 with pDevice11
Textures being shared from D3D9 to D3D11 have the following restrictions.
If a shared texture is updated on one device ID3D11DeviceContext::Flush must be called on that device.
Header: Declared in d3d11_x.h (d3d11.h on other Windows platforms).
Library: Use d3d11_x.lib (d3d11.lib on other Windows platforms).