Reputation: 197
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
Upvotes: 1
Views: 683
Reputation: 41057
The Direct3D 11 multi-threading model is fairly simple:
Calls to the ID3D11Device
are thread-safe (unless you used the D3D11_CREATE_DEVICE_SINGLETHREADED
flag when you created the device). You can call the methods on this interface from any thread.
Calls to the ID3D11DeviceContext11
are not thread-safe, and you should only call methods on this interface for a given context from a single thread at a time.
This is why Map
and Unmap
are part of the ID3D11DeviceContext11
rather than ID3D11Device
or on the ID3D11Resource
itself like it was in Direct3D 10. The operation is inherently serial with other operations.
This means you should have a single thread using the immediate device context (and DXGI), and this should probably be the same thread as your main windows message pump (for the reasons covered in DirectX Graphics Infrastructure (DXGI): Best Practices.
You could Map
on the same thread as the one using the immediate context, marshal the pointer to another thread, and then Unmap
it from the original thread when that thread completes but this is highly unlikely to improve performance.
See Introduction to Multithreading in Direct3D 11
Upvotes: 2