Here's how I understand Map() and UpdateSubResource() - someone please correct me if I'm wrong about something:
- Map(): You get a pointer directly to the driver's memory for that resource. You can write directly to it without incurring any other system memory copies, possibly causing a stall if you use _DISCARD while the resource is in use by the GPU and the driver runs out of temporary buffers. Good for gathering inputs from various memory locations and writing directly into the buffer without incurring any other extra copy.
- UpdateSubResource(): Copies the whole structure from an area of system memory to the driver's memory for that resource. Useful when you already have a copy of the buffer in memory already.
So based on this understanding, I have a few questions:- What's the general limit of temporary buffers that are used when using _DISCARD with Map()? Tens? Hundreds? I assume it's different per driver, but would like at least some general guidelines.
- What happens when you use UpdateSubResource() and the resource is being used by the GPU? Is it subject to the same process of using temporary buffers and possibly stalling if the drivers runs out of temporary buffers? Take an example of five objects drawn one after another, using the same shared constant buffer, and the constant buffer needs to be updated for each object. Using Map() for each constant buffer update, every update after the first one will cause the driver to use a temporary buffer, as the previous one will not have been used yet. What will happen when using UpdateSubResource() in this case?
- How is it advantageous to use one over the other? Is it purely how much data is being moved around? As far as I can tell, the same amount of memory is being copied around no matter which method you use - but I suspect I'm missing something here.
- What's the general limit of temporary buffers that are used when using _DISCARD with Map()? Tens? Hundreds? I assume it's different per driver, but would like at least some general guidelines.