Vertex Buffer Sharing between DirectX11 and Directx9(转自GAMEDEV)
来源:互联网 发布:巨杉数据库java笔试 编辑:程序博客网 时间:2024/05/18 02:23
In my d3d9 engine i want to take benifit of compute shader of d3d11. So firstly I created a vertex buffer in d3d11 with D3D11_BIND_UNORDERED_ACCESS and then tried to create the d3d9 vertex buffer with the Handle. like
D3D11_BUFFER_DESC bd;ZeroMemory(&bd, sizeof(bd));bd.ByteWidth = sizeof(stVertex) * 100; bd.BindFlags = D3D11_BIND_UNORDERED_ACCESS | D3D11_BIND_VERTEX_BUFFER ;bd.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS | D3D11_RESOURCE_MISC_SHARED;hr = dev->CreateBuffer(&bd, NULL, &pVBuffer); // create the bufferhr = CreateBufferUAV( dev, pVBuffer, &m_pBufOutUAV );....HANDLE sharedHandle = NULL;IDXGIResource* pDXGIResource = NULL;pVBuffer->QueryInterface(__uuidof(IDXGIResource), (LPVOID*) &pDXGIResource);pDXGIResource->GetSharedHandle(&sharedHandle);hr = g_pd3dDevice9->CreateVertexBuffer( 100*sizeof(stVertex), NULL , VERTEX::FVF_Flags, D3DPOOL_DEFAULT, &g_pVertexBuffer9, &sharedHandle ); //ERROR :
which gives error :
Direct3D9: (ERROR) :Opened and created resources don't match, unable to open the shared resource. Direct3D9: (ERROR) :Cannot create Vidmem or Driver managed vertex buffer. WillNOT failover to Sysmem. Direct3D9: (ERROR) :Failure trying to create Vertex Buffer
After that i tried to create vertex buffer in directx9 first and tries to share that in direct11 but still it gave error.
HANDLE sharedHandle9 = NULL; hr = g_pd3dDevice9->CreateVertexBuffer( 100*sizeof(VERTEX), NULL , VERTEX::FVF_Flags, D3DPOOL_DEFAULT, &g_pVertexBuffer9, &sharedHandle9 );ID3D11Resource* pTempResource11 = NULL; hr = dev->OpenSharedResource( sharedHandle9 , __uuidof(ID3D11Buffer) ,(LPVOID*) &pTempResource11 ); //Error
D3D11: ERROR: ID3D11Device::OpenSharedResource: Returning E_INVALIDARG, meaning invalid parameters were passed. [ STATE_CREATION ERROR #381: DEVICE_OPEN_SHARED_RESOURCE_INVALIDARG_RETURN ]
I am able to share textures but not buffers.please help me here.
thanks.
1 Answer
Well, I'm surprised about the stuff you can learn when researching stuff for answering a question.
Short answer: you can't.
This stuff you probably already know, but I'll cover it in case other people find it useful.
At first I thought you can't share handles among Direct3D devices, let alone versions, but it turns out that you can actually do that! In fact, there are three things you can do:
Share data, including vertex buffers across Direct3D 9 instances
You can even do this across processes! According to this article:
Direct3D resources can now be shared between devices or processes. This applies to any Direct3D resource including textures, vertex buffers, index buffers, or surfaces (such as render targets, depth stencil buffers or off-screen plain surfaces). To be shared, you need to designate a resource for sharing at the time of creation, and locate the resource in the default pool (D3DPOOL_DEFAULT). Once a resource is created for sharing, it can be shared across devices within a process, or shared across processes.
The key to do this, as you already know, is the last parameter of CreateVertexBuffer
. Remember that this is part of DirectX9Ex, which is only available on Vista and up.
Share a surface across different versions of Direct3D
You create a surface on one API, and render from another one.
This is not trivial, especially when one of the APIs is Direct3D 9, as it uses a completely different subsystem than DirectX 11 (DXGI 1.1). You also have to synchronize access to the surface, but in general, is very doable, according tothis article.
Share textures across Direct3D 11 instances, or even across Direct3D versions
So you create a buffer with CreateBuffer
and then retrieve it with OpenSharedResource
. However, unlike Direct3D 9, in Direct3D 11, you can only create a sharable buffer for 2D non-mipmapped textures, according tothis article (emphasis mine):
D3D11_RESOURCE_MISC_SHARED
Enables resource data sharing between two or more Direct3D devices. The only resources that can be shared are 2D non-mipmapped textures.
Also, in here:
The only resources that can be shared are 2D non-mipmapped textures.
In fact, you can share a texture across Direct3D versions, with some restrictions. According to the same article:
Textures being shared from D3D9 to D3D11 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
andRENDER_TARGET
set- Only
R10G10B10A2_UNORM
,R16G16B16A16_FLOAT
andR8G8B8A8_UNORM
formats are allowed
So, unfortunately you're out of luck. You can't share a vertex buffer across Direct3D versions. In fact, you can't share anything different from 2D non-mipmapped textures when you're using Direct3D 11.
- Vertex Buffer Sharing between DirectX11 and Directx9(转自GAMEDEV)
- Render to Texture2DArray slices in DirectX11?(转自GAMEDEV)
- DirectX11笔记(六)--Direct3D渲染2--VERTEX BUFFER
- Difference Between Buffer and Cache
- Difference between Cache and Buffer
- Difference Between Buffer and Cache
- Sharing files between windows and linux
- Sharing Message Loops Between Win32 and WPF
- Vertex Buffer in Direct3D 10[转]
- OpenGL Vertex Buffer Object (VBO)【转】
- [转]OpenGL Vertex Buffer Object (VBO)
- file sharing between globle and non-global zones
- Sharing Files Between Ubuntu Flash Drive and Windows
- Sharing Files between RHEL 6 and Windows Systems with Samba
- Node(25) sharing code between client and server
- Sharing a C++ solution between Visual Studio 2010 and 11
- Configure Samba Sharing between Ubuntu and Windows (Screenshot Tour)
- ZZ - Sharing files between Guest and Host Operating System
- 白话经典算法系列之六 快速排序 快速搞定
- KMP算法
- Eclipse中设置编码的方式
- iOS7判断获取相册和拍照的权限
- 【marks】rails资料
- Vertex Buffer Sharing between DirectX11 and Directx9(转自GAMEDEV)
- vxworks6.6移植日记
- 查某个表的扩展信息,字段的扩展信息及列的其他详细信息
- 互联网业务测试团队如果快速构建轻量级的自动化
- Zigbee 2.4G频段中不与WIFI相互干扰的几个信道。
- 数据结构基础(5)------------二叉排序树(BST)
- 学习java从length和length()开始
- ClassNotFoundException和NoClassDefFoundError的区别
- 百度地图SDK