Saturday, November 11, 2017

c++ - How to use UpdateSubresource and Map/Unmap?


From what I understood (from reading various pages) there are 2 ways to update a buffer:



  1. UpdateSubresource() (when buffer is created with DEFAULT usage)

  2. Map(), copy the new data, Unmap() (when buffer is created with DYNAMIC 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

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...