Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I started working with shaders recently in DirectX9. I noticed that there is a D3DXCompileShaderFromFile function for IDirect3DVertexShader9 and pixel shader. Which compiles the shader and gives you the compiled code so you can put that into a file and then read it.

But is there a way to do it with the ID3DXEffect or is IDirect3DVertexShader9 the only way?

share|improve this question
Take a look at D3DXCreateEffectFromFile. – user000user Jun 9 '14 at 12:52
up vote 4 down vote accepted

Use the D3DXCreateEffectFromFile function.

The parameter list is a bit daunting, but most of the parameters are optional and can support null values. Do note, however, the comment for the flags parameter:

If pSrcFile contains a text effect, flags can be a combination of D3DXSHADER Flags and D3DXFX flags; otherwise, pSrcFile contains a binary effect and the only flags honored are D3DXFX flags. The Direct3D 10 HLSL compiler is now the default. See Effect-Compiler Tool for details.

Typical usage would be:

LPD3DXEFFECT effect = nullptr;
LPD3DXBUFFER errors = nullptr;
HRESULT result = D3DXCreateEffectFromFile(

If the HRESULT isn't successful, compilation errors can be recovered from the errors buffer (it's just a string; you can case the void * returned from GetBufferPointer).

share|improve this answer
Thanks for the answer. I currently use this function to create the effects. Just to make sure I've got everything right. If I compile the effect with the Effect-Compiler tool and then try to load it with this function it will work fine correct? – MisterArch Jun 9 '14 at 16:11
The function supports binary effects, yes. Although not all the flags are supported (it's covered in the docs). – Josh Petrie Jun 9 '14 at 16:18
Thank you again! – MisterArch Jun 9 '14 at 16:47
Note you can actually use D3DCompile directly and not use D3DX at all to compile. Of course, if you are using the FX9 framework, you have to use D3DX9. – Chuck Walbourn Jul 15 '14 at 7:00

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.