XNA Creators Club Online
Page 1 of 1 (7 items)
Sort Posts: Previous Next

ID3D10Device::SetPrivateDataInterface method - does this API work?

Last post 03-04-2008 12:52 PM by LuxRGB. 6 replies.
  • 03-03-2008 5:10 PM

    ID3D10Device::SetPrivateDataInterface method - does this API work?

    In the past I've seen people use the old IDirect3DResource9::SetPrivateData/GetPrivateData to bury device9 resources such that when the device went away, it took resources with them provided that they were derived from IUnknown.

     

    It looks like this API has been revisited in DX10 and is now SetPrivateDataInterface although it is:

     

    1. Unclear how to get the object that was set in the interface - GetPrivateData doesn't work for these objects!

    2. Unclear if the API even works correctly because I've seen the objects Release() method called when the device's reference count is not 0 (e.g. it seems like any time a device's ::Release() method is called these objects are also destroyed, contrary to the MSDN documentation which states that the object added by SetPrivateDataInterface will only be Released() when the device is *destroyed*.

     

    Has anyone seen an example of how to use this API or any other way to make it work?  Peculiarly enough, if you use GetPrivateData on an object set by SetPrivateDataInterface, you get a NULL object but S_OK for a return code.  If you call SetPrivateData as well, you end up overwriting that object and DirectX will output a debug string noting htat the same GUID object was overwritten, hinting that SetPrivateData is called internally by SetPrivateDataInterface.

     

    Any examples on this API anyone?  I'm thinking of filing an MSDN Premier issue...

     

    Regards,

    LuxRGB

  • 03-04-2008 2:13 AM In reply to

    Re: ID3D10Device::SetPrivateDataInterface method - does this API work?

    I use these functions to track object destruction. They work fine for me.

    Do you use the set and get method with the same object?

  • 03-04-2008 11:15 AM In reply to

    Re: ID3D10Device::SetPrivateDataInterface method - does this API work?

    I have a ID3DX10Font* that I want to have automatically destroyed when the ID3D10Device object is destroyed so I first tried to:

     

    If my global GUID var isn't assigned, CoCreateGuid( &g_FontGuid )

    Set the pDataSize to sizeof(IUnknown*) and attempt to GetPrivateData( g_FontGuid, &dwDataSize, pFont) for that object in case it already exists

    If not, SetPrivateDataInterface( g_FontGuid, (ID3DX10Font*)pFont )

     

    I found that if I also try SetPrivateData before or after the SetPrivateDataInterface call, the object will get overwritten and I see a debug notice from DX saying the object was destroyed.  With the code above, I do see AddRef get called (I tested this with my own object inheriting from IUnknown to be sure).  Later down the line in the DXUT samplke code that I'm testing with the DXUT code makes a check from pD3D10Device->Release and there are still references open and pops up a dialog saying that resources are not freed.  I also never hit my breakpoint in the Release method of my own object so I know that Release() wasn't called.

     

    Is there an order dependency on calling the Get/Set/SetInterface calls that needs to be done?  I assumed based on the MSDN documentation that any object inheriting IUnknown will be OK so I assumed that this would apply to a ID3DX10Font object.

    It looks like the old DX9/8/7 SetPrivateData and GetPrivateData calls no longer perform the IUnknown destruction so I decided to use SetPrivateDataInterface...any chance you can post some pseudo code that works on your end?

     

    Regards,

    LuxRGB

  • 03-04-2008 12:07 PM In reply to

    Re: ID3D10Device::SetPrivateDataInterface method - does this API work?

    SetPrivateData and SetPrivateDataInterface use the same storage so you can only use one with the same GUID.  You may notice that SetPrivateData doesn’t support the flag to tell Direct3D that you provide an IUnknown anymore Therefore SetPrivateDataInterface is the right method.

    Your problem is based on circular reference counting. The D3DX10Font object holds a reference of the device that was used to create the font. Therefore the Release call in DXUT will not release the last reference. The device object will never be destroyed and therefore it never calls release for the ID3DX10Font interface that.

  • 03-04-2008 12:24 PM In reply to

    Re: ID3D10Device::SetPrivateDataInterface method - does this API work?

    Interesting, I would have thought that ID3D10Device::Release would first free any elements registered in its SetPrivateDataInterface before performing a delete, or at least that's how I would have implemented it...

    All I need to do really is draw text, is there any other method that can draw text to a device (quickly) without creating a device dependency that prevents ID3D10Device::Release from misbehaving and leaving the object open?

    -LuxRGB

  • 03-04-2008 12:39 PM In reply to

    Re: ID3D10Device::SetPrivateDataInterface method - does this API work?

    The releasing of the attached interfaces is part of the destruction. But as long as there are references it is impossible to destroy the device.

    As any possible way to render something (including text) requires resources you will always cause additional references. But as you use DXUT you can release the font object in the OnD3D10DestroyDevice function.

  • 03-04-2008 12:52 PM In reply to

    Re: ID3D10Device::SetPrivateDataInterface method - does this API work?

    In this case I'm not actually in DXUT, but rather drawing into another process that just happens to be DXUT, displaying my own overlay. (You might remember me from past posts as I'm writing a DX10 overlay).

     

    I've hooked into Release() in a prior attempt in the hopes of determining if the device object was indeed going to be destroyed but I've found that the device gets an unpredictable number of references built up even if the only object left to be destroyed is my ID3DX10Font such that it's pretty much impossible to prevent the device from freeing.  I tried s9imply creating the font each time in the Present() loop but discovered that while on DX9 there is very little overhead in doing so, there is a very significant performance hit (almost 50% framerate loss) on DX10 so I was lookign for a way to only dispose of the object when the device is truly going away.

     

    Any clues on how I might intelligently dispose of my font object when the device is going away?  There is definitely a way of achieving this as some commercial projects do very much the same thing.

     

    Regards,

    LuxRGB

Page 1 of 1 (7 items) Previous Next
var gDomain='m.webtrends.com'; var gDcsId='dcschd84w10000w4lw9hcqmsz_8n3x'; var gTrackEvents=1; var gFpc='WT_FPC'; /*<\/scr"+"ipt>");} /*]]>*/
DCSIMG