Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ID3DInclude] Custom include handler for D3D.Compile2() #2205

Open
d3-denis-zaporozhets opened this issue May 31, 2024 · 1 comment
Open
Milestone

Comments

@d3-denis-zaporozhets
Copy link

Hi. I am trying to implement custom include handler for D3DCompiler.
In C++ there is ID3DInclude which developer could inherit from and then override methods, but here in C# there is no such possibility because of how structs work in C#.

So, my question is - how to implement custom include handler in Silk.Net?

@Sizaar
Copy link

Sizaar commented Jun 21, 2024

You don't need to implement your own handler if all you need is just a simple include behavior, just pass (ID3DInclude*)1 as value for pInclude argument in Compile/Compile2.

If you need more elaborate handler logic you can use this:

static unsafe int Open(ID3DInclude* include, D3DIncludeType IncludeType, byte* pFileName, void* pParentData, void** ppData, uint* pBytes)
{
    // Your implementation here
}

static unsafe int Close(ID3DInclude* include, void* pData)
{
    // Your implementation here
}

var lpVtbl = stackalloc void*[2];

delegate*<ID3DInclude*, D3DIncludeType, byte*, void*, void**, uint*, int> d0 = &Open;
lpVtbl[0] = d0;

delegate*<ID3DInclude*, void*, int> d1 = &Close;
lpVtbl[1] = d1;

var include = new ID3DInclude(lpVtbl);

You can read more about Open/Close functions here:
https://learn.microsoft.com/en-us/windows/win32/api/d3dcommon/nf-d3dcommon-id3dinclude-open
https://learn.microsoft.com/en-us/windows/win32/api/d3dcommon/nf-d3dcommon-id3dinclude-close

@Perksey Perksey added this to the 3.0 milestone Oct 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Todo
Development

No branches or pull requests

3 participants