Sign in to follow this  
RobMaddison

Memory management and GPU memory

Recommended Posts

I'm starting to think bout memory management for my game engine (dx9, c++). I understand the principles of basic memory management but what happens when you allocate memory for an object that should primarily resde within video memory? When you create such an object, eg a textre or something, is it first created in system RAM and then pushed to the card or is it allocated directly in video memory. I guess my question is what happens if an object is allocated in video memory but then is swapped out due to lack of usage, if it was initially created in video RAM, will the drivers copy it to system RAM wherever it feels like? Thanks (apologies if this is probably aimed more at the GPU drivers than general game programming).

Share this post


Link to post
Share on other sites
On the PC you don't have any direct control over video memory. All video memory management is done by the driver and/or DirectX runtime. DirectX 9 allows you to specify the 'pool' you want resource memory to be allocated in (D3DPOOL_DEFAULT, D3DPOOL_MANAGED, D3DPOOL_SYSTEMMEM or D3DPOOL_SCRATCH) and also provide hints to the driver with usage flags. Depending on the resource and the particular combination of pool and usage flags, the way memory is handled will vary and the way you're allowed to use the resource will vary. The rules can get quite complex with DX9. Memory management by the driver and runtime is also quite different between XP and Vista/Win7. DirectX 10 simplifies things a bit compared the the DX9 model but still has the concept of usage patterns and allows you to specify whether a resource is for use by the CPU, GPU or both.

Managed pool resources in D3D9 perform most of the work of transferring data between system and video memory as necessary for you. Default pool resources put more of the burden on the programmer to manage moving data between system and video memory and you can generally think of them as representing fixed video memory resources but the reality of what the driver and runtime are doing may not be quite that simple. Since you have no control over it though it's not something to worry about too much.

On consoles you generally have direct control over video memory (or over the attributes of memory on UMA systems like the Xbox 360) and memory management for graphics resources can be handled more like regular memory management.

Share this post


Link to post
Share on other sites
Thanks for the response. So is it fair to say that for PC, don't custom allocate and handle memory for resources that you expect to stay resident on the card's memory per game level, but moving to XBOX360, you can handle everything in a custom allocator due to the nature of the unified architecture?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this