Sign in to follow this  
schupf

D3DXCompileShader parameter

Recommended Posts

Hi,

you may know the function D3DXCompileShader ( http://msdn.microsoft.com/en-us/library/bb172731%28v=vs.85%29.aspx ) to compile a shader from a string.
I don't understand the 4th paramater:
[quote] __in LPD3DXINCLUDE pInclude
Type: LPD3DXINCLUDE

Optional interface pointer, ID3DXInclude, to use for handling #include directives. If this value is NULL, #includes will either be honored when compiling from a file or will cause an error when compiled from a resource or memory.
[/quote]
Does anyone know what this parameter is used for and can give me a little example?

BTW: I want to use pure shaders (no .fx) and include a file in another file (something like #include "Common.sh"). Could this parameter help solving my problem?

Share this post


Link to post
Share on other sites
Are you using D3DXCompileShader(), D3DXCompileShaderFromFile(), or D3DXCompileShaderFromResource() ?

If you use D3DXCompileShaderFromFile(), then you may use NULL for the LPD3DXINCLUDE parameter and it should work. If you use the other two functions, I think you need to supply your own ID3DXInclude object that handles Open() and Close() functions. Here's the reference:

[url="http://msdn.microsoft.com/en-us/library/bb173986(v=vs.85).aspx"]http://msdn.microsof...6(v=vs.85).aspx[/url]

EDIT: a brief explanation... if you're using D3DXCompileShaderFromFile(), then that means that you're letting DirectX decide how to open and close your files. If you're using D3DXCompileShader(), then that means you've either made your own file open/close functions, or you have the shader code already in memory somehow (hardcoded perhaps). So DirectX won't make any assumptions as to how you want to deal with #includes. Instead of using its own open/close method, it'll ask you to provide a method, via an interface it understands (ID3DXInclude). I guess D3DXCompileShaderFromResource() works in a similar way to D3DXCompileShader() and can't make any assumptions either.

Share this post


Link to post
Share on other sites
Thanks for your answer!

So you mean if my shader is stored in a file foo.vsh and I compile with D3DXCompileShaderFromFile(), then using #include in foo.vsh will automatically work? How does the syntax look like? #include otherfile.sh or #include "otherfile.sh" or #include <otherfile.sh> or ...? (Why the hell the docu just can't give a little sample?!)
Doesn't this mean the LPD3DXINCLUDE parameter in D3DXCompileShaderFromFile() is useless, since DX will handle the include anywy?

Regarding: D3DXCompileShader: I thought D3DXCompileShader() is used to compile a shader that is completely stored in a C-String (first parameter)?

Share this post


Link to post
Share on other sites
[quote name='schupf' timestamp='1311626871' post='4840188']
Thanks for your answer!

So you mean if my shader is stored in a file foo.vsh and I compile with D3DXCompileShaderFromFile(), then using #include in foo.vsh will automatically work? How does the syntax look like? #include otherfile.sh or #include "otherfile.sh" or #include <otherfile.sh> or ...? (Why the hell the docu just can't give a little sample?!)
Doesn't this mean the LPD3DXINCLUDE parameter in D3DXCompileShaderFromFile() is useless, since DX will handle the include anywy?

Regarding: D3DXCompileShader: I thought D3DXCompileShader() is used to compile a shader that is completely stored in a C-String (first parameter)?
[/quote]

I honestly haven't tried it myself, so I can't give you an actual example. You can check the #include syntax here:

[url="http://msdn.microsoft.com/en-us/library/dd607349(v=vs.85).aspx"]http://msdn.microsof...9(v=vs.85).aspx[/url]

The LPD3DXINCLUDE parameter is not useless in D3DXCompileShaderFromFile(). If you provide NULL, it'll handle it in the default way. But if you provide a pointer to an object, it'll handle it using your method. And regarding D3DXCompileShader()... you're right, it is stored in a C-String, but that doesn't mean it can't #include other files. Say, for example you have a std::map that maps filename strings to shader code strings. So when you call D3DXCompileShader() and it comes across an #include, you may want to provide a ID3DXInclude object that, upon Open(), does a lookup on your map... it sends the filename and gets the code... and now you've provided the #include's code to DirectX via the ID3DXInclude object.

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