SHOP TALK: STATIC AND DYNAMIC BUFFERS Before getting into the last two methods that reside on the buffers, now seems like the perfect time to discuss the differences between static and dynamic buffers. The concepts here apply equally well to both vertex and index buffers. So, obviously the first question would be, "What is the difference between a static and a dynamic buffer?" As luck would have it, I happen to have an answer for that. If the buffer was created with the usage flag Usage.Dynamic, the buffer is a dynamic buffer; any other buffer is a static buffer. Static buffers are designed for items that do not change very often, while dynamic buffers are more easily used for buffers that have constantly changing data. You can see where the names come from. Just because a buffer is static, though, doesn't mean it cannot be modified. However, locking a static buffer while that buffer is already in use can have a very significant performance penalty. Before the data can be modified, the GPU needs to finish reading the current set of data, which can be very time consuming. Doing this several times in the same frame is even worse, because now you've eliminated the buffering the driver can do, and you are forcing your GPU to sit around idling waiting for you to finish modifying your buffer's data. Graphics cards are extremely powerful today; you do not want them idling when they could be busy drawing triangles. If you expect your buffer's data to be modified frequently, it should be created with Usage.Dynamic. This flag allows Direct3D to optimize the pipeline for frequent data modification. You will receive no speed enhancements by specifying a buffer as dynamic, and then never modifying it; as a matter of fact, it will be slower than if you simply made a static buffer to begin with. Always know the amount of "churn" you expect on your buffers per frame and create accordingly. For maximum performance, it is recommended that you have one large static vertex buffer for each vertex format you wish to render. It's sometimes not feasible to have only these static buffers, though, and in those cases, the dynamic buffers are there for you. |