Jump to content
  • Advertisement
Holy Fuzz

DX11 Why do D3D11_USAGE_DEFAULT and D3D11_USAGE_IMMUTABLE textures use system RAM?

Recommended Posts

I am making a game using a custom graphics engine written in Direct3D 11. I've been working to lower the amount of system RAM the game uses, and I noticed something that, to me, was surprising and went against my expectations:

Textures that are using D3D11_USAGE_DEFAULT or D3D11_USAGE_IMMUTABLE (along with a D3D11_CPU_ACCESS_FLAG of 0) are increasing my system RAM usage according to the size of the texture (i.e., a 1024x1024x32bpp texture adds about 4MB of system RAM usage). I had thought that the point of the D3D11_USAGE_DEFAULT and (especially) D3D11_USAGE_IMMUTABLE usage modes was to put the texture in VRAM instead of system RAM?

I might expect this behavior on a system with integrated graphics and shared memory, but I'm seeing this on a desktop with no integrated graphics and only a GTX 1070 GPU.

So am I just not understanding how this works? Is there any way I can make sure textures are allocated only in VRAM?

Thanks for your help!

Share this post


Link to post
Share on other sites
Advertisement

Drivers do this to enable very quick paging of GPU memory. If the OS tells your application that it needs all the GPU memory for another process (e.g. the user just alt+tabbed to chrome), the driver can instantly discard all your textures in the GPU, safe in the knowledge that it still has a copy of them in system RAM that it can use to recreate them when you alt+tab back into the game. You're kind of at the mercy of your GPU drivers here.

You could try using D3D11_BIND_RENDER_TARGET, but even if it does trick the driver into not holding onto a system memory cache/copy, it will have potential performance impacts of its own...

Share this post


Link to post
Share on other sites

The driver can decide to put an immutable or default resource to a sys memory pool and it is out of your control ( and not only at creation but defrag operation happens too ), but i doubt it would duplicate any large resources. Any decent large video game studio developer would have put them at shame for doing so… 

I would question how you measure your system memory usage, it is likely that your GPU share the process address space, if you create a texture in VRAM, for driver operation, this address space may have also been reserved on the CPU side, but won't be committed to physical pages of RAM unless it has to spill to it.

Share this post


Link to post
Share on other sites

Thanks for the info, that's very informative!

I was looking at memory usage as reported by the memory profiler I've been using (specificially DotMemory), which appears to be reporting total committed memory because it's value (791MB) is a lot closer to what Task Manager reports for its Commit Size (811MB) than than its Private Working Set (359MB).

My main goal has been to try to reduce the number of "out of memory" crashes for players with very low-spec (2-4 GB RAM) computers. I take it there's not much I can do to reduce committed memory usage by textures besides using texture compression or smaller textures?

Share this post


Link to post
Share on other sites

You should already be using Texture Compression, right? If you aren't, then GPU performance is going to be suffering.

BC1 will give you the smallest footprint for a given resolution, half that of BC3 or BC7 for a moderate loss of quality.

Edited by ajmiles

Share this post


Link to post
Share on other sites
34 minutes ago, ajmiles said:

You should already be using Texture Compression, right? If you aren't, then GPU performance is going to be suffering.

BC1 will give you the smallest footprint for a given resolution, half that of BC3 or BC7 for a moderate loss of quality.

it's a 2D pixel art game. Every texture compression format I've tried makes it look pretty terrible. It's also not anywhere close to being GPU-bound.

Share this post


Link to post
Share on other sites
1 minute ago, Holy Fuzz said:

it's a 2D pixel art game. Every texture compression format I've tried makes it look pretty terrible. It's also not anywhere close to being GPU-bound.

Well, if you aren't using any at all yet, then BC7 is probably the best place to start. It's 4x smaller then an uncompressed RGBA8 texture and the quality from a good compressor like ISPC is pretty good.

BC1 is 8x smaller than an uncompressed texture, so you could even afford to double the dimensions on every texture and still end up with a texture that's 2x smaller than the original uncompressed-but-lower-resolution version.

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

  • 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!