1
\$\begingroup\$

I have over 2GB of textures that I need to put in D3D9's D3DPOOL_MANAGED pool.

D3D9 charges the system copy of anything in the D3DPOOL_MANAGED to my process space. I'm working on a 32-bit system so I have less than 1.7GB of available process space.

Is there a way to limit the size of the pool D3D9 stores in my process, that is to tell it to keep anything else it needs to cache on disk?

\$\endgroup\$

1 Answer 1

2
\$\begingroup\$

No. You will need to implement that behavior yourself.

A simple way to do this is to wrap the D3D texture object in your own type (in order to allow you to keep the references to that texture while still dropping and reallocating the underlying D3D texture):

struct TextureReference {
  IDirect3DTexture9 * GetTextureObject();

  std::size_t GetSize() const;     
};

Keeping all these in a central pool via a dictionary or set will allow you to know the size consumption of all textures. When you start to reach a limit, you can evict textures based on size or last-recently-used timestamps or whatever else you'd want to track.

It's tricky because getting the in-memory consumption of a texture from D3D is not reliable, so you'll be leveraging guesswork most of the time to implement GetSize. You can use the on-disk size of the texture as a baseline and add padding as necessary.

This method also allows you sufficient abstraction to implement this pooling as one giant "megatexture-like" back-end D3D texture, where you load new textures by rendering them into available regions on the single backing texture and evict them by marking the regions as empty. This does require a good bin-packing algorithm, but it could help with problems related to GPU-memory fragmentation (since you can allocate a fixed-size texture as large as you can get away with and that consumption stays fixed). However, if you find yourself needing to swap textures frequently it could be a performance issue. It is probably worth considering, though.

\$\endgroup\$
2
  • \$\begingroup\$ So this sounds a little like texture tiling if I'm understanding you correctly, where I'd just mark a tile as dirty? But wouldn't that meant that I need to do texture management rather than letting DX9 do texture management, which would effectively mean that I needed to simply stuff my mega-texture in the D3DPOOL_DEFAULT? \$\endgroup\$ Commented Jan 3, 2014 at 20:06
  • \$\begingroup\$ You will need to do more management, yes. But you could use either pool in theory. \$\endgroup\$
    – user1430
    Commented Jan 3, 2014 at 20:12

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .