Sign in to follow this  
BMKane

Weak references in DX10

Recommended Posts

I was looking at the documentation for ID3D10Device::IASetVertexBuffers, and it says "The method will not hold a reference to the interfaces passed in. For that reason, applications should be careful not to release an interface currently in use by the device." Apparently, NONE of the Set functions hold references to interfaces passed in. I'm assuming that when you make a Draw() call, THAT'S when the device acquires a reference, and it holds that reference until it finishes with the buffer, but the docs don't say that. Does anyone know for sure if this is the case? The problem is, if that's not how it works, there's really no way to know when it's safe to release a vertex buffer. Draw() calls don't happen immediately, they go into a command queue and DirectX gets to them in its own time. So, there's no way to tell when DirectX is finished with your vertex buffer. Except, I suppose, waiting until every backbuffer in your swap chain is presented, guaranteeing that DirectX must have finished that original frame. Personally, I've never run into any problems with this myself, and I know I've released vertex buffers immediately after draw calls before, so presumably Draw() is indeed calling AddRef() on my buffers, but I'd like to know for sure. Anyone have any more information on this? Thanks!

Share this post


Link to post
Share on other sites
I don't think draw calls AddRef. The thing about calling Release on resources is that the actual GPU resource doesn't actually get deleted right away. The driver will have its own internal reference counts, and it will clean things up once it's actually done with it. This is the same reason why you can't depend on your GPU memory being freed up immediately after releasing your D3D objects.

Share this post


Link to post
Share on other sites
D3D keeps internal reference counts and external (user) reference counts. It's just stating that if the user ref count goes to zero that the resource is essentially slated for destruction -- to prevent that it's important to maintain user ref counts.

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

Sign in to follow this