I'm requesting your help as I know there is a lot of D3D11 experts here.
First, let me tell you about the background that led me to create this topic:
I use Ogre for the graphic part of my game engine, and Ogre has a nice heightfield module that allows dynamic sculpting of the terrain.
However, if the sculpting (and, in the background, the update of the vertex buffer) is fast enough in DirectX 9, it is way too much slow in DirectX 11, and I would like to improve its speed.
Basically, here is the global setup of the buffers:
- The terrain hardware buffer is created with an usage==D3D11_USAGE_DEFAULT and CPUAccessFlags==0
- At initialisation:
- A staging buffer is created with an usage==D3D11_USAGE_STAGING and CPUAccessFlags == D3D11_CPU_ACCESS_WRITE|3D11_CPU_ACCESS_READ
- The staging buffer is mapped with flags D3D11_MAP_WRITE to get a pointer to the vertex data.
- vertex data is written at the previously given location.
- Stating buffer is unmapped.
- Using ID3D11Device::GetImmediateContext()::CopyResource the vertex position is copied from the staging buffer to the original terrain vertex buffer.
- Stating buffer is deleted.
When editing the terrain dynamically, it is the same global process described in "2" that is made, but after some debugging I've seen that the ID3D11Device::Map call on the staging buffer is really slow (basically using the "break all" technique to see where the program is spending time.) During this operation, the whole original buffer is updated which is not performance friendly, but the same was done in Direct3d 9 without a huge performance hit.
I know that Direct3D 11 api is really different from the Direct3D 9 one, but is there a way to achieve fast update of a vertex buffer like with the old IDirect3DVertexBuffer9::Lock/Unlock ?
I'm sorry if it's not really clear, english is not my native language and I'm still beginning with all this D3D11 stuff.
If you need more details, please ask.
Thanks.