XNA ResourceManagementMode

Started by
2 comments, last by remigius 17 years, 5 months ago
First of all, I guess this is the right forum for XNA questions? I hope so at least. So the Managed and Default pools are now called ResourceManagementMode.Automatic and ResourceManagementMode.Manual... The default templates and most examples has this structure:

        protected override void LoadGraphicsContent(bool loadAllContent)
        {
            if (loadAllContent)
            {
                // Load ResourceManagementMode.Automatic here!
            }
            // Load ResourceManagementMode.Manual here!
        }

        protected override void UnloadGraphicsContent(bool unloadAllContent)
        {
            if (unloadAllContent)
            {
                // Unload ResourceManagementMode.Automatic here!
            }
            // Unload ResourceManagementMode.Manual here!
        }

I understand the structure and all, but the thing I don't see is how I choose in which mode to load a resource. I'm very new to XNA (been working with MDX before) so I'm not really sure what would be relevant. But take this code for loading a static .x-model for example: ContentManager content; content = new ContentManager(Services); Model model; model = content.Load<Model>(@"./Content/Models/model1"); I thought there would be an overload for Load which takes ResourceManagementMode as a parameter but there isn't... So how do I choose to load it in Automatic mode or Manual mode? Most likely I'm just incredibly stupid but then so be it :) Cheers
Advertisement
The ContentManager always seems to load resources with ResourceManagementMode.Automatic and I can't find anything to get around this. The only option I see so far would be to derive a class from the ContentManager so you can access the protected OpenStream method like this:

public Texture2D LoadManual(string assetName){    System.IO.Stream stream = base.OpenStream(assetName);    TextureCreationParameters tcp = TextureCreationParameters.Default;    tcp.ResourceManagementMode = ResourceManagementMode.Manual;    return Texture2D.FromFile(device, stream, tcp);}


That's just pieced together, so I doubt it will work out of the box (or at all :p). At best it's an ugly hack, so you might want to file a feature request through Microsoft Connect if you really need this. Most static resources should be fine in the Managed/Automatic pool though, so why would you want to do this?
Rim van Wersch [ MDXInfo ] [ XNAInfo ] [ YouTube ] - Do yourself a favor and bookmark this excellent free online D3D/shader book!
As far as I've understood it Manual mode (Default pool) is faster than Automatic/Managed? When I load textures/vertex buffers I can specify what mode to have them in. (at least it seems like I can do after a quick glance at MSDN, haven't really tried that yet).

But I'm still very new to XNA and I just assumed that I could load Models in Manual mode aswell... But maybe it isn't faster at all to have them in Manual mode or maybe they assume that all models that require that kind of performance will have an own / better model class than the one that comes with the XNA Framework?

EDIT:
Seems like I can specify ResourceManagementMode for a new texture:
Texture2D tex = new Texture2D(......., ResourceManagementMode.Manual);
but not when I load it, so then I'd have to go with the nice little "hack" posted by rem?

*shrug* I don't get it, isn't almost all big/important resources in Manual mode / Default pool...? (for bigger / more serious game projects that is)
I'm no expert on XNA either, just going from what I (hope I) know from MDX [smile]

When using the Automatic/Managed pool the runtime will try to put your resource data into video memory just like when using the Manual/Default pool, so there isn't any great speed difference in that. Resources in the managed pool however are backed by system memory on the PC, so the DirectX runtime can restore them back into video memory after a device reset occurs or when a resource was previously evicted from video memory to make room for other resources.

Copying this data to video memory may make using the Managed pool slower, but this should happen very infrequently (this is unrelated to locking the resource data, which is an entirely different matter). So if you manage your video memory correctly or just need little of it, you should be fine using the managed pool. In fact, with the new RenderTarget API in XNA beta 2, I think there's little need for an explicit Default pool anymore.

With the unified memory model the XBox 360 reportedly has, the difference between these two pools should matter even less, since system and video memory is the same for the XBox 360 (i.e. the memory is local to both the CPU and GPU). I don't have any experience with XBox development, but if this is indeed the case, the Automatic/Manual modes are just stubs for compatibility with the PC platform.

For more info you might want to check out this FAQ on video memory or the C++ docs in the DirectX SDK on resource pools. Hope this helps and is somewhat correct [wink]

[Edited by - remigius on November 15, 2006 7:40:51 AM]
Rim van Wersch [ MDXInfo ] [ XNAInfo ] [ YouTube ] - Do yourself a favor and bookmark this excellent free online D3D/shader book!

This topic is closed to new replies.

Advertisement