Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Directx 11 Memory Management

I've been studying Directx 11 for a while now, but I'm still confused on how Directx 11 manages memory. For example, if I create a vertex buffer using ID3D11Device::CreateBuffer, where is the new buffer stored? I know it returns a pointer to the buffer, so that means it must be stored on CPU RAM right? However, I thought that this would make ID3D11DeviceContext::IASetVertexBuffers a very slow process, because it would have to copy the buffer from CPU RAM to GPU RAM. But if all of the buffers created with ID3D11Device:CreateBuffer were stored on GPU RAM, then wouldn't the GPU RAM fill up really quickly? Basically I would like to know: when I create a buffer, where is that data stored? In CPU RAM or GPU RAM? Also, what is ID3D11DeviceContext::IASetVertexBuffers doing with the buffer (copying/setting?).

like image 254
Sully Chen Avatar asked Oct 17 '14 02:10

Sully Chen


People also ask

What is the difference between d3d11 and d3d12?

The most obvious difference that DirectX 12 requires Windows 10, while DirectX 11 requires Windows 7 or later. DirectX 12 also requires that your video card driver supports it as well. This means you need to have a relatively recent AMD, NVIDIA or Intel video card with updated drivers.

Is DirectX 11 or 12 better?

More Cores = More Better With DirectX 12 DirectX 12 moves a lot of the work to get games working over multiple CPUs away from developers and builds it into the API itself. This is part of the drive with DirectX 12 to get the most out of your PC hardware, rather than only using a portion of its potential.


1 Answers

The general answer is that "it's wherever the driver wants it to be". For "DYNAMIC" resources, they are typically put into memory that is accessible to both the CPU and the GPU (on modern PCs this is shared across the PCIe bus). For "STATIC" resources, they can be on video RAM that is only accessible by the GPU which is copied via the 'shared' memory window, or if there's limited space they are put in the 'shared' memory window. Render Targets are usually put in video RAM as well.

For a deeper dive on Direct3D video memory management, check out the talk "Why Your Windows Game Won't Run In 2,147,352,576?" which is no longer on MSDN Downloads but can be found on my blog.

If you want the nitty-gritty hardware details, read the driver writer's documentation.

You may also find the Video Memory sample on MSDN Code Gallery educational.

like image 109
Chuck Walbourn Avatar answered Oct 10 '22 04:10

Chuck Walbourn