Jump to content
  • Advertisement
Sign in to follow this  
SKonen

D3D Texture Memory Allocations

This topic is 4849 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'm currently working on a Direct3D framework/game engine and have run into an issue regarding retrieving the memory usage of a texture. With my texture resource cache manager I need to know how many bytes each texture is currently using in RAM, the problem is: I'm not entirely sure how to do this. Taking Width*Height*Depth will of course, not always produce the proper results do to proper compression. I have thought about checking for the DDSD_LINEARSIZE flag after retrieving the DDSURFACEDESC and using the linearsize value for compressed textures, or otherwise using the WxHxD calculation. But the problem is future hardware compatibility ( more advanced compression systems ). I need a solution. Any suggestions?

Share this post


Link to post
Share on other sites
Advertisement
hi,

knowing texture size and the format of it, you can have a good estimate of the memory needed (but think about DXTn compression, for example). but they say this is not exact due to internal differences.
have a look at IDirect3DDevice9::GetAvailableTextureMem() but keep in mind that this isn't exact either, moreover it doesnt not return videomem only but the agp aperture too (as far as i know), and you might not want to load so many textures so that it goes to zero due to trashing.
anyway.. you said you write a resource cache manager? in which pool do you load textures? isn't the managed pool good enough for the purpose?

kp

Share this post


Link to post
Share on other sites
GetAvailableTextureMem only returns the total amount of memory available, it has nothing to do with a specific texture. But I believe I have created a solution to my problem in the form of this function:

int GetTextureMemoryUsage( LPDIRECT3DTEXTURE9 pTexture, int nLevel = 0 )
{
D3DLOCKED_RECT lockedRect;
D3DSURFACE_DESC desc;

// Attempt to retrieve the texture pitch:

if (FAILED(
pTexture->LockRect( nLevel, &lockedRect, NULL, D3DLOCK_READONLY )
))
{
return 0;
}
pTexture->UnlockRect( 0 );


// Get the texture level description:

if (FAILED( pTexture->GetLevelDesc( nLevel, &desc ) ))
{
return 0;
}

return desc.Height * lockedRect.Pitch;
}


The reasoning for the creation of this caching system is to give more control to the developer. It uses the D3D managed memory pool, but has an additional layer of functionality.

Share this post


Link to post
Share on other sites
hi,

if you read the free mem before and after loading a texture, then yes, it can give you some info about the size of the texture. this is why I mentioned it.

kp

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!