Hello,
This topic is super confusing for me and I hope you'll help me to understand it better. Here several usage scenarios:
1. I have n objects and for every object I need to change a constant data before draw. Let's say the constant data ConstData have one integer field and is different for every object. I have a constant buffer consBuffer and I need to update it. In pseudo code:
ConstData cd;
cd.data = 1;
ptr = consBuffer.Map();
memcpy(ptr, cd);
constBuffer.Unmap();
draw(obj1);
cd.data = 2;
ptr = consBuffer.Map();
memcpy(ptr, cd);
constBuffer.Unmap();
draw(obj2);
...
It well known that draw doesn't happen immediately but goes to the gpu queue for later execution. And from the code I wrote I see that when the gpu is ready to actually draw object1 the constant data will be overridden by later calls to memcpy. Does that mean that I need to have a different constant buffer for every object? So if I have 100 objects and 2 back buffers I need 100 * 2 = 200 constant buffers. Is it right?
2. If I want to store a constant data directly in root signature, can I update the root signature before every draw call? Taking my previous example, I will not have calls to Map()/memcpy()/Unmap(), but will write directly to signature. Do I need to wait until previous object or frame finished rendering?
3. If I have rarely changed constant buffer, a projection matrix, for example, do I need to have different constant buffers for every render target? In other words, if projection matrix was changed can I safely update buffer only once and hope that changes will propagate to all frames in the queue?