Resource Sharing between Directx11 and DirectX9

Started by
2 comments, last by crazy_crab 10 years, 10 months ago

Hi

I am trying to share resource between directx9 and directx11,having some problems regarding this.

what i am doing is this :-

STEP1: created a shared texture with format D3DFMT_A8R8G8B8 in directx9 and get its shared handle.

STEP2: open the shared texture with directx11 device using the handle.

STEP3: create UAV of texture creating in step3.

but step 3 fails with error


D3D11: ERROR: ID3D11Device::CreateUnorderedAccessView: The format (0x57, B8G8R8A8_UNORM) cannot be used with a Typed Unordered Access View. [ STATE_CREATION ERROR #2097344: CREATEUNORDEREDACCESSVIEW_INVALIDFORMAT ]
D3D11: ERROR: ID3D11Device::CreateUnorderedAccessView: A UnorderedAccessView cannot be created of a Resource that did not specify the D3D11_BIND_UNORDERED_ACCESS BindFlag. [ STATE_CREATION ERROR #2097342: CREATEUNORDEREDACCESSVIEW_INVALIDRESOURCE ]
 

please help me here that how can i create UAV of a shared texture which is created in directx9.


//code
//DX9
HRESULT hr = g_pd3dDevice9->CreateTexture( Width , Height , 1 , D3DUSAGE_RENDERTARGET , D3DFMT_A8R8G8B8 ,D3DPOOL_DEFAULT , &g_pTexture , &g_pSharedHandleTex9 );

//DX11
hr = m_pDevice11->OpenSharedResource( g_pSharedHandleTex9 , __uuidof(ID3D11Texture2D) , (void**)&m_pTetxure); //success
hr = m_pDevice11->CreateUnorderedAccessView( m_pTetxure, NULL, &m_pTetxureUAV); //fails
 

so,instead of this, I tried to do

STEP1: create a texture in directx11 format DXGI_FORMAT_R8G8B8A8_UNORM (with UAV bind flag)

STEP2: created a shared texture with format D3DFMT_A8R8G8B8 in directx9 and get its shared handle.

STEP3: open the shared texture with directx11 device using the handle.

STEP4: CopyResource() from the texture created on step 1 to the shared texture.

but the step4 failed,with error


D3D11: ERROR: ID3D11DeviceContext::CopyResource: Cannot invoke CopyResource when the Formats of each Resource are not the same or at least castable to each other, unless one format is compressed (DXGI_FORMAT_R9G9B9E5_SHAREDEXP, or DXGI_FORMAT_BC[1,2,3,4,5]_* ) and the source format is similar to the dest according to: BC[1|4] ~= R16G16B16A16|R32G32, BC[2|3|5] ~= R32G32B32A32, R9G9B9E5_SHAREDEXP ~= R32. [ RESOURCE_MANIPULATION ERROR #284: COPYRESOURCE_INVALIDSOURCE ]
 

I thought that D3DFMT_A8R8G8B8 and DXGI_FORMAT_R8G8B8A8_UNORM should match , just like DXGI_FORMAT_R32_FLOAT and D3DFMT_R32F matches.please help me here.

code:


//DX9
HRESULT hr = g_pd3dDevice9->CreateTexture( Width , Height , 1 , D3DUSAGE_RENDERTARGET , D3DFMT_A8R8G8B8 ,D3DPOOL_DEFAULT , &g_pTexture , &g_pSharedHandleTex9 );

//DX11
D3D11_TEXTURE2D_DESC desc;
desc.Width              = width;
desc.Height             = height;
....
desc.Format             = DXGI_FORMAT_R8G8B8A8_UNORM;

hr = m_pDevice11->CreateTexture2D(&desc, NULL, &m_pTetxure); //success
...
...
hr = m_pDevice->OpenSharedResource( g_pSharedHandleTex9 , __uuidof(ID3D11Texture2D) , (void**)&m_pSTexture);
m_pDeviceContext11->CopyResource( m_pSTexture, m_pTetxure ); //fails
 

please help me.
thanks.

Advertisement

I haven't ever heard of anyone doing something like this before... I would be interested to hear what use case requires both D3D9 and D3D11 support for the same texture! Since D3D11 is based on DXGI, I would expect the formats to be considered different from the D3D9 ones even if they are bitwise compatible. One thing you could try is to open up the appropriate header files and see which format's enumeration values can match one another (if any).

If that doesn't work, you could always use the CPU as the sharing point and copy the texture contents directly between the two devices when needed. I know that isn't the ideal thing, but it would give you a possible workaround if this doesn't work.

The question is more why are you using DX9 as you can talk to DX9 hardware with the DX11 runtime with feature levels it supports. If you are porting a DX9 renderer to DX11 you are better of reading the documentation on DX11 of moving from DX9 to 11.

Worked on titles: CMR:DiRT2, DiRT 3, DiRT: Showdown, GRID 2, theHunter, theHunter: Primal, Mad Max, Watch Dogs: Legion

@Jason Z and NightCreature83

thanks,

actually i have engine in dx9 ,but wanted to process some raw data in gpu and give output to a texture.so i choose compute shader of dx11 and I dont want to change existing source which is written in dx9.

however I figured out the problem as D3DFMT_A8R8G8B8 will match to DXGI_FORMAT_B8G8R8A8_UNORM.however you cant then create UAV from that format.You have to create texture with DXGI_FORMAT_B8G8R8A8_TYPELESS.then create UAV with castable format like DXGI_FORMAT_R32_UINT and then do your work on shader.


thanks.

This topic is closed to new replies.

Advertisement