Sign in to follow this  
saiwaifengyun

[d3d10] shared resource from Direct3D9 to Direct 3D10

Recommended Posts

I am looking for help about sharing resource from Direct3D9 to Direct3D10. The function of OpenSharedResource did not work at all.Even I used the referece hardware for D3D9 and D3D10, it did not work either. HANDLE SharedHandle=NULL; LPDIRECT3DTEXTURE9 pTexture9=NULL; hr = m_pd3d9_device->CreateTexture(720, 480, 1, D3DUSAGE_RENDERTARGET,D3DFMT_A8R8G8B8,D3DPOOL_DEFAULT,&pTexture9, &SharedHandle); ID3D10Texture2D *pTexture10 = NULL; ID3D10Resource* tempResource10 =NULL; hr = m_pd3d10_device->OpenSharedResource(SharedHandle,__uuidof(ID3D10Resource), (void**)(&tempResource10)); //here it will return the invalid arg error. hr = tempResource10->QueryInterface(__uuidof(ID3D10Texture2D), (void**)(&pTexture10)); hr = tempResource10->Release();

Share this post


Link to post
Share on other sites
Quote:
Original post by saiwaifengyun
I am looking for help about sharing resource from Direct3D9 to Direct3D10. The function of OpenSharedResource did not work at all.Even I used the referece hardware for D3D9 and D3D10, it did not work either.

HANDLE SharedHandle=NULL;

LPDIRECT3DTEXTURE9 pTexture9=NULL;
hr = m_pd3d9_device->CreateTexture(720, 480, 1, D3DUSAGE_RENDERTARGET,D3DFMT_A8R8G8B8,D3DPOOL_DEFAULT,&pTexture9, &SharedHandle);

ID3D10Texture2D *pTexture10 = NULL;
ID3D10Resource* tempResource10 =NULL;
hr = m_pd3d10_device->OpenSharedResource(SharedHandle,__uuidof(ID3D10Resource), (void**)(&tempResource10));
//here it will return the invalid arg error.
hr = tempResource10->QueryInterface(__uuidof(ID3D10Texture2D), (void**)(&pTexture10));
hr = tempResource10->Release();
You can't share a resource between D3D9 and D3D10 - the drivers are completely different, and the underlying representation could be different. You'll have to duplicate the data instead.

Share this post


Link to post
Share on other sites
However, according to the MSDN of D3D10, it seems that the resource can be shared:
http://msdn.microsoft.com/en-us/library/bb173598(VS.85).aspx?wt.slv=ColumnA

To share a resource between a Direct3D 9 device and a Direct3D 10 device the texture must have been created using the pSharedHandle argument of IDirect3DDevice9::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);
...
pDevice10->OpenSharedResource(sharedHandle, __uuidof(ID3D10Resource), (void**)(&tempResource10));
tempResource10->QueryInterface(__uuidof(ID3D10Texture2D), (void**)(&pTex2D_10));
tempResource10->Release();
// now use pTex2D_10 with pDevice10
Textures being shared from D3D9 to D3D10 have the following restrictions.

Textures must be 2D
Only 1 mip level is allowed
Texture must have default usage
Texture must be write only
MSAA textures are not allowed
Bind flags must have SHADER_RESOURCE and RENDER_TARGET set
Only R10G10B10A2_UNORM, R16G16B16A16_FLOAT and R8G8B8A8_UNORM formats are allowed
If a shared texture is updated on one device ID3D10Device::Flush must be called on that device.

Share this post


Link to post
Share on other sites
To [K1nG Gr4H4m]

These restrictions are not clear at all(even the description for opensharedresource of MSDN). Textures of D3D9 can be not created with R8G8B8A8_UNORM or SHADER_RESOURCE.

Textures being shared from D3D9 to D3D10 have the following restrictions.
Textures must be 2D
Only 1 mip level is allowed
Texture must have default usage
Texture must be write only
MSAA textures are not allowed
Bind flags must have SHADER_RESOURCE and RENDER_TARGET set
Only R10G10B10A2_UNORM, R16G16B16A16_FLOAT and R8G8B8A8_UNORM formats are allowed

Share this post


Link to post
Share on other sites
Quote:
Original post by saiwaifengyun
To share a resource between a Direct3D 9 device and a Direct3D 10 device the texture must have been created using the pSharedHandle argument of IDirect3DDevice9::CreateTexture. The shared Direct3D 9 handle is then passed to OpenSharedResource in the hResource argument.
Is that not only for D3D9Ex? (I'm not a D3D10 person at all).

Share this post


Link to post
Share on other sites
yes, only D3D9ex supports shared resource, since the handle in the CreateTexture can be effective under D3D9ex. The MSDN document shows D3D9 can share resource to D3D10, however, it doesn't support it actually. It is not caused by the driver, because the OpenSharedResource return the D3D10 E_INVALIDARG error.

Share this post


Link to post
Share on other sites
That's really strange. Everything looks good. The only thing I found about that is, the device (ID3D10Device) needs to be created with the "D3D10_RESOURCE_MISC_SHARED" flag, unless it was created with the IDXGIDevice.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this