DX10 Should I save the ResourceView?

Started by
3 comments, last by Bangladesh 16 years, 3 months ago
I'm writing a texture-manager to load and store any texture I might need, but I have a problem: What is the best practice to save the resource in? For example, when storing a texture that is to be used as a sprite: First I load the texture from file into a Resource. Then I convert the Resource to a TextureResource. Then I convert the TextureResource into a ResourceView. What is the best practive here? 1. To save the Resource and on the fly create/convert to the other formats and release the temp when I don't need it anymore? 2. Save all three formats (and bloating the memory)? 3. Save only the TextureResource and create/convert to ResourceView on the fly? 4. Save only the ResourceView? What I'm asking is: Is it fast enough to convert on the fly to a temporary object, use it and then delete it, _or_ Save one, some, or all of the formats and convert, _or_ just save one final format (in that case; which one?) and ise it always.
Advertisement
Rule for any Direct3D Version: Avoid calling methods with a Create in the name like plague inside your render loop. Creating anything is always an expensive operation.

I am not sure what you do to “convert” your objects. I assume the following

“Then I convert the Resource to a TextureResource”: You use QueryInterface.
“Then I convert the TextureResource into a ResourceView.”: You use CreateShaderResourceView.

As any method that takes a ID3D10Resource will take any of the ID3D10Texture interfaces too you don’t need to store the Resource interface. But as this are only interfaces to the same object you would not really save memory.
Every resource view will hold an reference on the resource that was used to create it. Therefore even if you release the texture interface the view will still hold it in memory.

As you should not create views in your loop on the fly you need to hold at least the view interface. But holding the texture interface too will you cost only the memory to store a single pointer. Compared to the size that the view and the texture itself needs that’s nothing.
I would just store the view. The resource itself can be retrieved if needed with a call to GetResource, but most of the time you'll just need the view (binding inputs and outputs and the like).
I also just save the shader resource views because I have thus far not needed the original resource interface directly.
-----Quat
Thanks all! The info was indeed helpful!

This topic is closed to new replies.

Advertisement