# DX11 Resource Sharing between Directx11 and DirectX9

This topic is 1693 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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


thanks.

##### Share on other sites

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.

##### Share on other sites

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.

##### Share on other sites

@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.

• 10
• 11
• 9
• 16
• 19
• ### Similar Content

• I wanted to see how others are currently handling descriptor heap updates and management.
I've read a few articles and there tends to be three major strategies :
1 ) You split up descriptor heaps per shader stage ( i.e one for vertex shader , pixel , hull, etc)
2) You have one descriptor heap for an entire pipeline
3) You split up descriptor heaps for update each update frequency (i.e EResourceSet_PerInstance , EResourceSet_PerPass , EResourceSet_PerMaterial, etc)
The benefits of the first two approaches is that it makes it easier to port current code, and descriptor / resource descriptor management and updating tends to be easier to manage, but it seems to be not as efficient.
The benefits of the third approach seems to be that it's the most efficient because you only manage and update objects when they change.

• hi,
until now i use typical vertexshader approach for skinning with a Constantbuffer containing the transform matrix for the bones and an the vertexbuffer containing bone index and bone weight.
Now i have implemented realtime environment  probe cubemaping so i have to render my scene from many point of views and the time for skinning takes too long because it is recalculated for every side of the cubemap.
For Info i am working on Win7 an therefore use one Shadermodel 5.0 not 5.x that have more options, or is there a way to use 5.x in Win 7
My Graphic Card is Directx 12 compatible NVidia GTX 960
the member turanszkij has posted a good for me understandable compute shader. ( for Info: in his engine he uses an optimized version of it )
Now my questions
is it possible to feed the compute shader with my orignial vertexbuffer or do i have to copy it in several ByteAdressBuffers as implemented in the following code ?
the same question is about the constant buffer of the matrixes
my more urgent question is how do i feed my normal pipeline with the result of the compute Shader which are 2 RWByteAddressBuffers that contain position an normal
for example i could use 2 vertexbuffer bindings
1 containing only the uv coordinates
2.containing position and normal
How do i copy from the RWByteAddressBuffers to the vertexbuffer ?

(Code from turanszkij )
Here is my shader implementation for skinning a mesh in a compute shader:

• Hi, can someone please explain why this is giving an assertion EyePosition!=0 exception?

It looks like DirectX doesnt want the 2nd parameter to be a zero vector in the assertion, but I passed in a zero vector with this exact same code in another program and it ran just fine. (Here is the version of the code that worked - note XMLoadFloat3(&m_lookAt) parameter value is (0,0,0) at runtime - I debugged it - but it throws no exceptions.
m_viewMatrix = DirectX::XMMatrixLookAtLH(XMLoadFloat3(&m_position), XMLoadFloat3(&m_lookAt), XMLoadFloat3(&up)); Here is the repo for the broken code (See LightClass) https://github.com/mister51213/DirectX11Engine/blob/master/DirectX11Engine/LightClass.cpp
and here is the repo with the alternative version of the code that is working with a value of (0,0,0) for the second parameter.

• Hi, can somebody please tell me in clear simple steps how to debug and step through an hlsl shader file?
I already did Debug > Start Graphics Debugging > then captured some frames from Visual Studio and
double clicked on the frame to open it, but no idea where to go from there.

I've been searching for hours and there's no information on this, not even on the Microsoft Website!
They say "open the  Graphics Pixel History window" but there is no such window!
Then they say, in the "Pipeline Stages choose Start Debugging"  but the Start Debugging option is nowhere to be found in the whole interface.
Also, how do I even open the hlsl file that I want to set a break point in from inside the Graphics Debugger?

All I want to do is set a break point in a specific hlsl file, step thru it, and see the data, but this is so unbelievably complicated