views:

1072

answers:

2

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...

+5  A: 

You can use the old DirectDraw interface to query the total and available memory.

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.

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.

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 :-)

Nils Pipenbrinck
I'm not afraid of running out of video-memory, I'm afraid of using too much system-memory in Direct3D ;)
Jazz
+2  A: 

Two suggestions:

You can call GetAvailableTextureMem in various times to obtain a (rough) estimate of overall memory usage progression.

Assuming you develop on nVidia's, PerfHUD includes a graphical representation of consumed AGP/VID memory (separated).

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 -

(1) the driver has a lot of freedom in transferring resources between memory types, and

(2) the actual variety of memory consumers is far greater than the exposed D3D interfaces.

Ofek Shilon