# How to update vertex buffer in DirectX 12

I would like to create cloth simulation. Which type of buffer should i use for vertices. I will need to update them on every frame. And how updates need to be done. I'm new to graphics programming, but still i'm mostly interesting in high level overview. If there is open-source project implementing it, reference to it would be of help.

For now i have only rigid body geometries. For this i create a resource with

    THROW_IF_FAILED(g_device->CreateCommittedResource(
&CD3DX12_HEAP_PROPERTIES(D3D12_HEAP_TYPE_DEFAULT),
D3D12_HEAP_FLAG_NONE,
&CD3DX12_RESOURCE_DESC::Buffer(byteSize),
D3D12_RESOURCE_STATE_COPY_DEST,
nullptr,


Then i update it with initial data using another upload buffer to initialize first buffer. Lastly i transition first buffer into D3D12_RESOURCE_STATE_VERTEX_AND_CONSTANT_BUFFER state.

Well, i got some comments directing me toward DirectX11, but for my purposes i will better use DirectX12, and again, i'm pretty matured programmer and just need a highlevel overview of what need to be done.

For example,

create default buffer with geometry, then create upload heap, and when needed create placed resource buffer to upload data into your default buffer.

But here a lot of questions arise. For now i use frame resources e.g. for transforms to update them on each frame and do not stall CPU. But if i will copy once a frame to the same default buffer will my it cause stalling? And should i use different queue for copying, and how then do resource state transitioning?

From what i understood for now, i need to implement this, but how to implement CopyResource functionality?

• Slightly off-topic: If you are new to graphics development you should most likely prefer using DX11. DX12 is intended for performance intensive applications (e.g.: games) and requires a lot of manual management from the programmer (while in older API versions those are handled by the OS and drivers). – UnholySheep Mar 28 '17 at 7:04
• @UnholySheep i spent a lot of time to start with DirectX12, and now i have simple rendering system using it, and i would like to continue this way:) – Yola Mar 28 '17 at 7:07
• In that case it's somewhat unclear what you want to do differently for your cloth simulation rendering (e.g.: what should be different from the way you render other objects, what have you tried doing and where are the problems). – UnholySheep Mar 28 '17 at 7:33
• "I pushed a boulder halfway up a mountain instead of a small rock, but since I'm already halfway, I might as well just continue" tis is basically you, but instead of being halfway up, you're only 5% up the mountain. – Bálint Mar 28 '17 at 8:21
• I agree with Sheep and Balint, DX 12 is only needed if you have cpu overhead issues, sure some of the advanced things like async compute and bindles resources can help but. In fact if you use it wrong then your perf will be lower than using DX11. If you are stuck here I would really go have a look at DX11. Why did you pick DX12? – Justin William Stanley Bryant Mar 28 '17 at 23:14