简体   繁体   English

Directx 11内存管理

[英]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. 我一直在研究Directx 11,但我仍然对Directx 11如何管理内存感到困惑。 For example, if I create a vertex buffer using ID3D11Device::CreateBuffer, where is the new buffer stored? 例如,如果我使用ID3D11Device :: CreateBuffer创建顶点缓冲区,那么新缓冲区存储在哪里? I know it returns a pointer to the buffer, so that means it must be stored on CPU RAM right? 我知道它返回一个指向缓冲区的指针,这意味着它必须存储在CPU RAM上吗? 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. 但是,我认为这会使ID3D11DeviceContext :: IASetVertexBuffers进程非常缓慢,因为它必须将缓冲区从CPU RAM复制到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? 但是如果使用ID3D11Device:CreateBuffer创建的所有缓冲区都存储在GPU RAM上,那么GPU RAM是否会很快填满? Basically I would like to know: when I create a buffer, where is that data stored? 基本上我想知道:当我创建一个缓冲区时,该数据存储在哪里? In CPU RAM or GPU RAM? 在CPU RAM或GPU RAM? Also, what is ID3D11DeviceContext::IASetVertexBuffers doing with the buffer (copying/setting?). 另外,ID3D11DeviceContext :: IASetVertexBuffers用缓冲区做什么(复制/设置?)。

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). 对于“DYNAMIC”资源,它们通常被放入CPU和GPU都可访问的内存中(在现代PC上,这是通过PCIe总线共享的)。 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. 对于“STATIC”资源,它们可以位于只能通过“共享”存储器窗口复制的GPU可访问的视频RAM上,或者如果空间有限,则将它们放入“共享”存储器窗口。 Render Targets are usually put in video RAM as well. 渲染目标通常也放在视频RAM中。

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?" 有关Direct3D视频内存管理的更深入了解,请查看“为什么您的Windows游戏无法在2,147,352,576中运行?” which is no longer on MSDN Downloads but can be found on my blog . 它不再在MSDN下载中,但可以在我的博客上找到。

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. 您还可以在MSDN代码库教育中找到视频内存示例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM