Jump to content
  • Advertisement
YixunLiu

DX11 Update vertex buffer in non UI thread using DirectX11

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi,

 
 

I want to render a object with a dynamic vertex buffer and I do rendering in UI thread. I am thinking is it possible to change this vertex buffer content in a non UI thread using Map and Unmap.

Thanks.

YL

Share this post


Link to post
Share on other sites
Advertisement

Yes, you can either call Map/Unmap on the main thread, but use another thread to fill the buffer.
e.g. Thread#1 calls Map, Thread#2 fills the buffer, Thread#1 calls Unmap.

Or, you can use a deferred context:
Thread #2 calls Map/Unmap and FinishCommandList, then Thread#1 calls ExecuteCommandList

Share this post


Link to post
Share on other sites

Thanks Hodgman.

I am not clear about the first method you mentioned.

For example, I can run the following code in main thread,

m_d3dContext->Map(vertexBuffer2.Get(), 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);
	//	Update the vertex buffer here.
	memcpy(mappedResource.pData, vertices, sizeof(vertices));
	//	Reenable GPU access to the vertex buffer data.
	m_d3dContext->Unmap(vertexBuffer2.Get(), 0);

 

To run the above code in two threads, I run map and unmap in main thread and memcpy in another thread.

However, is it safe to call unmap while another thread is updating the buffer?

Thanks.

 

Share this post


Link to post
Share on other sites

No that's unsafe.

You need to synchronise your threads so that the memcpy doesn't begin until after the call to Map, and the call to Unmap doesn't occur until some time after the memcpy is complete.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!