Archived

This topic is now archived and is closed to further replies.

level10boy

D3D and Resource Management?

Recommended Posts

level10boy    122
Does anyone know what is best, D3DPOOL_DEFAULT or D3DPOOL_MANAGED. The DirectX SDK seems to contradict itself all the time about this and now I''m just plain confused.

Share this post


Link to post
Share on other sites
siaspete    208
They basically tell D3D how the memory for the objects should be managed.

If they''re in the managed pool, D3D manages the objects, and if they get lost from video memory (the user alt-tabbing out of the game for example) then D3D will restore them when the game comes back.

If they''re in the default pool, you have to restore them yourself.

This sounds like an easy one - use managed all the time! But I''m afraid it''s not so easy. As far as I know, dynamic vertex buffers have to be in the default pool.

Also, you should make sure that you create your default pool objects before the managed ones, so D3D knows how much memory it has to play with for the managed ones. Sounds dumb but it''s true.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster

siaspete is correct, to elaborate:

What the D3DPOOL_ is all about is telling (suggesting to) D3D which memory to use, ie video or system.
For example, if you have a static vertex buffer or a texture which you will never read from, it would be better if it was in video memory, whereas if you had to read from it, it would be better situated in system mem (memory reads from the GPU take longer that from noraml mem.)

whenever the d3d device is lost (from ALT-TAB etc)the device has to be reset, but before this can happen any resources stored in the video memory have to be released (the video memory has to be flushed)

for managed resources D3D keeps a copy so that it can automatically restore the video mem if necessary.
Whenever the resource used it is copied into the best memory location as required.

default resources are kept in driver optimal memory (ie in the vid memory.) making them slightly faster (no copying) but more of a pain to restore after a lost device.

sysmem resources are kept in system memory, so they would probably be quicker to modify (r/w) but may take longer to render / send to GPU etc.

from what i can gather:
- its usually better to use MANAGED for textures (all)
- better to use MANAGED for static resources (vert,indx buffers)
- MUST use DEFAULT (or SYSMEM) for D3DUSAGE_DYNAMIC
-ie dynamic vert buffers, render targets?

i think the SDK recommends MANAGED because it means that the app doesnt have to worry about doing the copying into the optimal memory location. (worrying about which resources should persist in memory, and which ones should be moved to make room for others etc)

If all your level data can fit into video mem though, i imagine there would be a speed advantage, whether or not it is large enough to make a difference is another thing.

my advice for handling objects which need to be allocated as DEFAULT is to register them with some sort of manager, which stores a pointer to the resource.
A need for a reset can then be handled easier by moving through the list of default objects, destroying them, reseting the device and then moving back through the list to restore the objects.

who knows what D3D thinks about the MANAGED memory pool after this. re:
"make sure that you create your default pool objects before the managed ones, so D3D knows how much memory it has to play with for the managed ones. "

it would also be advisable to register ALL device dependent objects with some sort of manager. think about what happens when a new device needs to be created to use HW / SW.


I hope this helps everyones understanding.
I hope this is all correct.

later

Marc



Share this post


Link to post
Share on other sites
Imois    122
I think that if you place textures in the MANAGED pool D3D keeps a copy in system memory. That would mean that you use system memory for storing textures! I think this is a waste of memory, especially since devices don''t get lost very often.
My advice would be to reload all textures and stuff when your device is lost.

Share this post


Link to post
Share on other sites
d9930380    122
I agree, D3D_MANAGED is the easier method but for efficiency I use DEFAULT and then depending on it''s other flags. It gets placed in Vid or Sys Memory.

However that said - Because D3D is handling the Resource Management, it could be faster to use Managed (The Driver could make optimisations etc).

Again, its another case of profiling.

Share this post


Link to post
Share on other sites