Jump to content
  • Advertisement
Sign in to follow this  
XeonXT

Memory Management and VRAM in DX

This topic is 2856 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'd like to implement my own resource management system in a project of mine. I'm aware of D3DPOOL_MANAGED, but I would prefer to have tighter control over my assets, so I'm going to create my own system for loading and unloading things to/from the GPU.

My first stumbling block - how can I detect how much VRAM the GPU has left?

The only thing I have seen like this before is device->GetAvailableTextureMem(). From my experiments, this function seems to query total memory available, not necessarily what is left after allocations that have already been made.

Bottom line is that my resource management system needs to know how much VRAM it has left to work with. Am I going to have to manually keep track of the VRAM or can the device give me this information?

Thanks very much!

Share this post


Link to post
Share on other sites
Advertisement
Define "tighter control". I seriously doubt that you'd get better than the managed pool already offers, unless you have some very specific (and very weird!) requirements. What's more, you'll be compilcating lost device recovery a lot more than you'd probably like.

GetAvailableTextureMem does work, but maybe not the way you think. Firstly, virtualisation of video RAM in Vista and 7 means that it will always return gigabytes of available RAM (1.5 GB on one machine I have vs 128 MB in XP) and secondly even if it was accurate the amount it returns does not always mean that you'll be able to create a resource exactly that size, due to driver overhead, possible padding of allocations, etc.

Share this post


Link to post
Share on other sites
Quote:

My first stumbling block - how can I detect how much VRAM the GPU has left?

You can't detect this in a reliable fashion.

Quote:

Am I going to have to manually keep track of the VRAM or can the device give me this information?

As above, the device can't give you this reliably. Furthermore, you can't even track it yourself -- you can only look at system memory, and the amount of bytes a resource takes up when mapped in system memory may not be the same as the amount of memory it takes on the GPU.

What do you think you will gain by this "tighter control?"

Share this post


Link to post
Share on other sites
Yes, I do have some very weird requirements. I'll try to explain my motivations here.

All content in my project is procedural and, essentially, infinite. Needless to say it's going to take some tight asset control to have the generation algorithms running in a parallel thread such that the user experiences no hitches while new content is being created. In order to achieve this experience, I feel that I need to have some idea of where I stand on VRAM - so that I can create and unload content as appropriate. I obviously can't just load it all at once and throw it in the managed pool, since "all" really isn't defined. And I'd like to do better than a portal system.

Also, my engine is build around proper response to lost/reset, so I am not having problems with resetting the device even though I am using the default pool at the moment.

jpetrie has confirmed my fear, which is what I suspected - that there is no reliable method of querying VRAM usage. So I suppose I'll try to track it manually. I know it won't be perfect, but it should still give me a rough estimate of usage.

Thanks to both of you for the information. If anyone has any further ideas on the subject or links to articles on content/memory management, please, don't hesitate!

Share this post


Link to post
Share on other sites
Why not have the amount of memory your app reserves set as a config value? For instance, if this is for a game, you could have a "graphics quality" slider or something similar, which would map to how much memory your manager manages (Among other things). You could Probably get a rough starting value by looking at other caps values to see how generally powerful it is (I.e. vertex and pixel shader version supported, max texture size, and so on)

Share this post


Link to post
Share on other sites
Quote:
Original post by Evil Steve
Why not have the amount of memory your app reserves set as a config value? For instance, if this is for a game, you could have a "graphics quality" slider or something similar, which would map to how much memory your manager manages (Among other things). You could Probably get a rough starting value by looking at other caps values to see how generally powerful it is (I.e. vertex and pixel shader version supported, max texture size, and so on)

Yes, this sounds like a solid approach to me as well.

Thanks for the advice.

Share this post


Link to post
Share on other sites
I wonder whats about memory fragmentation? If there is no method "getFreeVMem", then I suppose there is also no real memory manager build exclusively for the VRAM.

I can imagine, that a texture or other data in VRAM has to be in a single strip. So if this is true, then maybe the OS memory manager is responsible for reorganising the video memory like other memory too. Maybe we need to look for a OS method to retrieve the free VRAM? There must be a possibility to do that :)

Share this post


Link to post
Share on other sites
Quote:
Original post by Pyrogame
I wonder whats about memory fragmentation? If there is no method "getFreeVMem", then I suppose there is also no real memory manager build exclusively for the VRAM.

I can imagine, that a texture or other data in VRAM has to be in a single strip. So if this is true, then maybe the OS memory manager is responsible for reorganising the video memory like other memory too. Maybe we need to look for a OS method to retrieve the free VRAM? There must be a possibility to do that :)
Fragmentation will be managed by the driver, the OS doesn't care about it at all.

The only way you'd get information about fragmentation, or more accurate information about total or free VRAM would be to query the driver - which means a separate codepath for every graphics card you want to support.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!