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

Does ID3D10Effect really support IUnknown ?

Last post 11-05-2007 1:49 PM by David Weller. 8 replies.
  • 10-20-2007 6:23 AM

    Does ID3D10Effect really support IUnknown ?

    I'm trying to do some COM Interop with Direct3D 10 and i have a strange problem with the ID3D10Effect interface.

    I'm currently working with D3DX10CreateEffectFromFileW. This function take many input parameters and return an effect object implementing ID3D10Effect and errors in an object implementing ID3D10Blob.

    My C# declaration of this function in P/Invoke seem to work and i can even step into the x86 code and see that the calling of the function is correct (symbols tell me that i'm in the good place). The problem occure when the function return and when the CLR try to marshal the outputs parameters. The CLR throw a System.InvalidCastException exception that wrap a E_NOINTERFACE (0x80004002) error.

    So i tryed to do the marshaling myself. I have modified my P/Invoke call to return me a pointer (IntPtr) instead of a RCW.
    This pointer behave correctly with Marshal.AddRef or Marshal.Release (wrappers for calling IUnknown.AddRef and IUnknown.Release). But it don't work at all with Marshal.QueryInterface with IID_ID3D10Effect and IID_IUnknown (and this is a BIG issue).

    Any ideas, Is it a "by design" behavior ?
    Eric
  • 10-20-2007 7:01 AM In reply to

    Re: Does ID3D10Effect really support IUnknown ?

    Answer

    Direct3D classes and interfaces were never "good" COM objects.  In the case of the effect framework things goes even worse as the sub objects of an effect uses interfaces that doesn’t inherited from IUnknown at all.

    I have give up writing working DirectX wrappers with C# long time ago. The only way that seems to work is using C++/CLR. I have written a nearly complete Direct3D 10 wrapper using it: http://www.codeplex.com/MD3D10

  • 10-20-2007 11:03 AM In reply to

    Re: Does ID3D10Effect really support IUnknown ?

    I saw your codeplex project but my goal was to  see if it is possible to write a Direct3D 10 managed library using without using C++/CLI (with C#). Today the answer seem to be NO...

    I also saw that the other effect's interfaces don't implement IUnknown (but i have a plan for that). I'm sad to see that even a company like Microsoft can produce such ugly code. What does it cost to correctly implement IUnknown ?
  • 10-20-2007 11:47 AM In reply to

    Re: Does ID3D10Effect really support IUnknown ?

    I have escalated the problem. I am sorry but this is all I can do right now. I am sure that’s a bug that slips trough as the COM aspect of Direct3D is beside of AddRef and Release hardly used.

  • 10-21-2007 4:56 AM In reply to

    Re: Does ID3D10Effect really support IUnknown ?

    I don't blame you for anything. You was kind enough to give me the answer i feared !

    What i espected by posting on this forum was that someone who have access to the Direct3D 10 source code give me the confirmation that the IUnknown implementatation on ID3D10Effect objects is flawed and if a correction is planed.

  • 10-21-2007 1:26 PM In reply to

    Re: Does ID3D10Effect really support IUnknown ?

    Answer
    I believe this is going to be fixed for the next version of the FX runtime. What this means is it likely won't be fixed for ID3D10Effect. What at least one person has done is implement a wrapper object that forwards calls to the ID3D10Effect interface and properly implements QI.
  • 11-04-2007 12:33 PM In reply to

    Re: Does ID3D10Effect really support IUnknown ?

    Answer
    I wrote a custom wrapper in C# that directly call methods in the VTable and that's works (but it's really painful to write) so thanks for the suggestion.
  • 11-04-2007 5:24 PM In reply to

    Re: Does ID3D10Effect really support IUnknown ?

    The DirectX team has publicly said that it's not a design goal to be a good COM citizen. They use COM mostly as a language neutral way of accessing created interfaces (calling convention), and doing ref counting. Note that many DX functions that take an COM interface will actually fail if you implement the interface yourself, because the functions up-cast to the internal type they "know" the interface to be.

    And, yes, implementing proper COM would add overhead to the D3D implementation, which would slow things down, which would be bad.

    Jon Watte, Direct3D MVP kW X-port 3ds Max .X exporter kW Animation source code
  • 11-05-2007 1:49 PM In reply to

    Re: Does ID3D10Effect really support IUnknown ?

    FYI, the D3D team has indicated that this would be addressed, where appropriate, in future releases of DX.  That's a pretty vague answer for you, but they DO acknowledge the issues you're having.

     

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