To learn about d3d, we should understand the three memories. We collected relevant information online and collected it.
Three types of memory (non-local memory), memory (local memory), and system memory, among which we all know that the system memory is our memory. What kind of memory is this? In fact, it was because the memory of the video card was very small in the past. At that time, when the memory size was 16 MB and 32 MB was the mainstream, if you were running a 3D program that needed a lot of textures, so the memory will not be enough for a while. What should we do? I have to ask if the system memory usage is used! This is the origin of the AGP memory. In our computer bios, there is an option to set the AGP aperture. Here we set the maximum allowable value for the video card to use the system memory, which is usually set to 64 MB. Note: Here we only talk about the maximum allowed value. Instead of taking the 64 m off the server, your 256 memory will become 192! However, your memory is still 256 MB, but you can limit the maximum usage of 64 MB system memory for the video card.
Let's talk about the speed of these three memories!
Of course, the system memory is the fastest CPU read and write operations! The graphics card will be much slower than using your own video memory!
The speed of reading and writing video card memory is normal, of course, no video card is faster! The CPU is relatively complex. The speed of reading the memory from the CPU is very slow, but the write speed is not slow, but the speed is average, which is a little slower than using the system memory, that is to say, it is suitable for CPU to write but not suitable for reading. Someone may ask, the same is that the system memory name is just different. What is the difference in speed? Well, I am not quite clear about this. Foreigners just need to remember it!
The last point is the video memory. This is very simple. Of course, the speed of reading and writing the video card is the fastest, and the speed of reading and writing the CPU must be much slower!
After talking about the differences between the three memories, let's talk about their usefulness! Here a d3dusage enumeration volume is involved:
D3dusage_dynamic: this variable is used when you create a resource. It indicates that d3d specifies the resource as dynamic, and dynamic means that it needs to be modified frequently. Generally, the CPU modifies the resource, therefore, dynamic resources should be stored in the AGP memory. This can minimize the impact on speed.
D3dusage_writeonly indicates that only write operations are allowed on the created resource. Using this flag allows devices to place this resource in the most suitable area of memory for write processing and rendering. If the d3dusage_writeonly flag is not used, the device may select a memory area if the created resource is used for both reading and writing, the speed of read and write operations is moderate. This sacrifices some processing and rendering speeds.
The d3dlock flag and Resource Creation type are also affected.
However, the three memory types are another method to optimize access, because for example, the particle system needs to use the AGP memory, because it requires frequent CPU modifications and frequent reading by the graphics processing card, if it is stored in the video memory, the CPU modification efficiency is too low! If it is stored in the memory, the access speed of the graphics processing card is too slow! Therefore, the three types of memory must be clear!
We can use the following two methods to create a vertex cache and index cache:
Hresult idirect3ddevice9: createvertexbuffer (
Uint length,
DWORD usage,
DWORD fvf,
D3dpool pool
Idirect3dvertexbuffer9 ** ppvertexbuffer,
Handle * psharedhandle
);
Hresult idirect3ddevice9: createindexbuffer (
Uint length,
DWORD usage,
D3dformat format,
D3dpool pool,
Idirect3dindexbuffer9 ** ppindexbuffer,
Handle * psharedhandle
);
Most of the parameters of these two methods are the same, so we will introduce them together.
Length -- size of the bytes allocated to the cache. If you want to get a vertex cache that can store 8 vertices, then I
We need to set this parameter to 8 * sizeof (vertex) in the vertex structure ).
Usage -- specify additional information about how to use the cache. This value can be 0, not marked, or the following mark
One or more combinations of records:
D3dusage_dynamic -- set this parameter to make the cache dynamic. Static and
Dynamic cache.
D3dusage_points -- this parameter specifies the original cache point. The original point will be in Chapter 1 Particle System
Introduction. This parameter is only used in vertex buffering.
D3dusage_softwareprocessing -- use software vertex Processing
D3dusage_writeonly -- specifies that the application can only write to the cache. It allows the driver to allocate the most suitable
As the write cache. Note: If you read data from the created cache, an error message is returned.
Fvf-vertex format stored in cache
Pool -- Memory Pool in which the cache is stored
Ppvertexbuffer -- returns the pointer of the created vertex cache.
Psharedhandle -- not used; set to 0.
Format -- specify the index size; Use d3dfmt _ index16 to set a 16-bit index, and use d3dfmt _ index32
Set 32-bit indexes. Note that not all devices support 32-bit indexing. Check the device capabilities.
Ppindexbuffer -- returns the pointer of the created index cache.
Note: cache created without the d3dusage_dynamic parameter is called static cache. Static cache is usually stored in the video memory.
Data in it can be effectively processed. However, for static cache, It is very slow to read and write data from it, because
The Display memory is slow. For this reason, we use static cache to store static data (without frequently changing data ). For static
State cache terrain and buildings are good examples of post-selection, because they usually do not need to be changed in applications. The static cache should be in
The application is filled in at the beginning, rather than at the runtime.
Note: The cache created using the d3dusage_dynamic parameter is called dynamic cache. Dynamic cache is usually placed in The AGP
Memory, data in this memory can be quickly updated. Processing data in the dynamic cache is not faster than processing data in the static cache,
Because the data must be transferred to the video memory before rendering, the advantage of dynamic cache is that they can be updated a little faster (compared
CPU writes fast ). Therefore, if you need to update the data in the cache frequently, you should use dynamic cache. For dynamic cache
Particle systems are a good application because they are dynamic and they are usually updated at each frame.
Note: reading the video memory and The AGP memory in the program are very slow. Therefore, if you need to read your geometric objects during operation,
The best solution is to specify a system memory in which all copies and reads data.