Weak references in DX10

Started by
1 comment, last by DieterVW 13 years, 12 months ago
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!
Advertisement
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.
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.

This topic is closed to new replies.

Advertisement