From what I understood (from reading various pages) there are 2 ways to update a buffer:
UpdateSubresource()
(when buffer is created withDEFAULT
usage)Map()
, copy the new data,Unmap()
(when buffer is created withDYNAMIC
usage)
In the first case do I only call this one function (nothing more)? Because I've seen people say they map the buffer and then update subresource, or maybe I misunderstood them.
Also is there any other way (doubt it :P)? Do I understand things correctly?
Answer
There's a good presentation about this: Don't Throw It All Away: Efficient Buffer Management by John McDonald at NVIDIA. It covers various topics, but on the subject of your question, the general advice is to create buffers with dynamic usage and use Map()
with D3D11_MAP_WRITE_DISCARD
, when the data needs to be updated frequently (like every frame, or multiple times per frame). This would be used for constant buffers, vertex buffers for particle systems, and suchlike.
According to the presentation, default usage / UpdateSubresource()
incurs more CPU overhead than dynamic usage / Map()
. However, he does recommend default usage / UpdateSubresource()
for data that needs to be updated only once in awhile, such as data streamed in from disk in an open-world game.
And yes, in the case where you use UpdateSubresource()
, you would use it by itself, not in combination with Map()
.
No comments:
Post a Comment