windows 报告 Direct3D 内存使用情况
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/427707/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Report Direct3D memory usage
提问by Jazz
I have a Direct3D 9 application and I would like to monitor the memory usage. Is there a tool to know how much system and video memory is used by Direct3D? Ideally, it would also report how much is allocated for textures, vertex buffers, index buffers...
我有一个 Direct3D 9 应用程序,我想监视内存使用情况。有没有工具可以知道 Direct3D 使用了多少系统和视频内存?理想情况下,它还会报告为纹理、顶点缓冲区、索引缓冲区分配了多少……
回答by Nils Pipenbrinck
You can use the old DirectDraw interface to query the total and available memory.
您可以使用旧的 DirectDraw 界面来查询总内存和可用内存。
The numbers you get that way are not reliable though.
但是,您通过这种方式获得的数字并不可靠。
The free memory may change at any instant and the available memory often takes the AGP-memory into account (which is strictly not video-memory). You can use the numbers to do a good guess about the default texture-resolutions and detail-level of your application/game, but that's it.
空闲内存可能随时更改,可用内存通常会考虑 AGP 内存(严格来说不是视频内存)。您可以使用这些数字很好地猜测应用程序/游戏的默认纹理分辨率和细节级别,但仅此而已。
You may wonder why is there no way to get better numbers, after all it can't be to hard to track the resource-usage.
您可能想知道为什么没有办法获得更好的数字,毕竟跟踪资源使用情况并不难。
From an application point of view this is correct. You may think that the video memory just contains surfaces, textures, index- and vertex buffers and some shader-programs, but that's not true on the low-level side.
从应用的角度来看,这是正确的。您可能认为视频内存仅包含表面、纹理、索引和顶点缓冲区以及一些着色器程序,但在低级方面并非如此。
There are lots of other resources as well. All these are created and managed by the Direct3D driver to make the rendering as fast as possible. Among others there are hirarchical z-buffer acceleration structures, pre-compiled command lists (e.g. the data required to render something in the format as understood by the GPU). The driver also may queue rendering-commands for multiple frames in advance to even out the frame-rate and increase parallelity between the GPU and CPU.
还有很多其他资源。所有这些都由 Direct3D 驱动程序创建和管理,以使渲染尽可能快。其中包括分层 z 缓冲区加速结构、预编译的命令列表(例如,以 GPU 理解的格式呈现某些内容所需的数据)。驱动程序还可以提前为多个帧排队渲染命令,以平衡帧速率并增加 GPU 和 CPU 之间的并行性。
The driver also does a lot of work under the hood for you. Heuristics are used to detect draw-calls with static geometry and constant rendering-settings. A driver may decide to optimize the geometry in these cases for better cache-usage. This all happends in parallel and under the control of the driver. All this stuff needs space as well so the free memory may changes at any time.
驱动程序还在引擎盖下为您做了很多工作。启发式用于检测具有静态几何和恒定渲染设置的绘制调用。在这些情况下,驱动程序可能会决定优化几何形状以更好地使用缓存。这一切都是在司机的控制下并行发生的。所有这些东西也需要空间,所以空闲内存可能会随时改变。
However, the driver also does caching for your resources, so you don't really need to know the resource-usage at the first place.
但是,驱动程序也会缓存您的资源,因此您一开始就不需要真正了解资源使用情况。
If you need more space than available the that's no problem. The driver will move the data between system-ram, AGP-memory and video ram for you. In practice you never have to worry that you run out of video-memory. Sure - once you need more video-memory than available the performance will suffer, but that's life :-)
如果您需要比可用空间更多的空间,那没问题。驱动程序将为您在系统内存、AGP 内存和视频内存之间移动数据。在实践中,您永远不必担心视频内存不足。当然 - 一旦你需要比可用内存更多的视频内存,性能就会受到影响,但这就是生活:-)
回答by Ofek Shilon
Two suggestions:
两个建议:
You can call GetAvailableTextureMemin various times to obtain a (rough) estimate of overall memory usage progression.
您可以在不同时间调用GetAvailableTextureMem以获得对整体内存使用进展的(粗略)估计。
Assuming you develop on nVidia's, PerfHUDincludes a graphical representation of consumed AGP/VID memory (separated).
假设您在 nVidia 上开发,PerfHUD包括消耗的 AGP/VID 内存(分离)的图形表示。
You probably won't be able to obtain a nice clean matrix of memory consumers (vertex buffers etc.) vs. memory location (AGP, VID, system), as -
您可能无法获得一个干净的内存使用者(顶点缓冲区等)与内存位置(AGP、VID、系统)矩阵,因为 -
(1) the driver has a lot of freedom in transferring resources between memory types, and
(1) 驱动程序在内存类型之间传输资源有很大的自由度,并且
(2) the actual variety of memory consumers is far greater than the exposed D3D interfaces.
(2) 实际内存消费者的种类远远大于暴露的D3D接口。