Index cache and vertex Cache
Index cache and vertex cache resources are frequently used in the example engine and are useful as independent resources. For most of the data in our engine, it is our basic requirement to retain them when traditional models do not provide indexes and vertex caches and then overwrite the entire model at some point. Indexing and vertex caching are especially useful for dynamic data. When using devices to rely on resources, they must be processed with caution. Using the dynamic vertex and index cache enables us to create a ry or animation of an existing object on the CPU at any time. We use these two methods when building a terrain engine.
To clarify, what we call dynamic means completely replacement. Locking a vertex or index cache to change some random values will result in poor performance that is staggered on most graphics cards. Therefore, these resources are not supported in our interfaces. In our engine, we replace the entire dynamic cache every time we need to update it. This allows the driver to maintain a single-direction dynamic data. Once the data is transferred back to the video card, it will not try to read the data into the system memory to update some special values.
Class objects cvertexbuffer and cindexbuffer provide the basic operations required by our cache. These objects also contain our regular cache and dynamic cache. To support dynamic (can be considered as a replacement) caching of data, we use the best method recognized by nvidia and Microsoft to update dynamic data.
This function uses a super large cache to store dynamic data. For example, if your dynamic data is composed of 10 vertices, you will create a dynamic cache that can hold 100 data. With this large space, you can use only 10 vertex data at a time. In the first frame, you use vertex 0 ~ 9. Index 10 ~ 19 is used in the second frame and continues. When you use all the space, the entire cached content will be destroyed and processed from vertex 0. This sliding window scheme is considered friendly because it can interrupt the most direct memory access (DMA) operations. Listing 4.5 shows how to use Algorithm Pseudo code.