0

I have a DirectX shader (.fx and .fxo) and am trying to implement it into my own DirectX9.0 project but when using

HRESULT hr = (D3DXCreateEffectFromFile(mD3DDevice, "Terrain.fx",
    0, 0, D3DXSHADER_DEBUG, 0, &mFX, &errors));

where mD3DDevice is a pointer to my LPDIRECT3DEVICE9

I get the error

ID3DXEffectCompiler: There was an error initializing the compiler

I have tried compiling with a different shader and that compiles, so it must be a problem with compatabilty with the shader. I know the Shader works though as I have used it in a different engine (DirectX9.0c).

Is it something I need to change in the shader? or is it something else?

The beginnig of the Shader written for the DirectX 9.0c engine starts with using a constant buffer. Is that the issue? Can DirectX9 not handle the buffer? If So, how would I have to change the shader or engine to make it work?

Many thanks for any help.

cbuffer cbPerFrame
{
    DirectionalLight gDirLights[3];
    float3 gEyePosW;

    float  gFogStart;
    float  gFogRange;
    float4 gFogColor;

    float gMinDist;
    float gMaxDist;

    float gMinTess;
    float gMaxTess;

    float gTexelCellSpaceU;
    float gTexelCellSpaceV;
    float gWorldCellSpace;
    float2 gTexScale = 50.0f;

    float4 gWorldFrustumPlanes[6];
};
unknownSPY
  • 706
  • 4
  • 15
  • 27
  • 1
    Constant buffers are DX10+, so indeed: DirectX9 can not handle the buffer. – Paul-Jan May 19 '15 at 16:13
  • @Paul-Jan But the Shader came from a different engine running on DirectX9.... (and it works on that engine) – unknownSPY May 19 '15 at 16:17
  • I think @Paul-Jan is correct, `cbuffer` is a ShaderModel 4.0 construct, and D3D9(c) only supports ShaderModel 3.0. However, apparently `D3DXCreateEffectFromFile` (https://msdn.microsoft.com/en-us/library/windows/desktop/bb172768(v=vs.85).aspx): "The Direct3D 10 HLSL compiler is now the default. See Effect-Compiler Tool for details.". So, while the file could compile, it probably won't actually work. – MuertoExcobito May 19 '15 at 19:21
  • A key question is which version of the legacy DirectX SDK are you using, and specifically which deprecated version of D3DX9 are you using? Also, show the part of your shader where you declare the effects/passes. – Chuck Walbourn May 19 '15 at 19:26
  • @ChuckWalbourn I'm using the June2010 SDK and how do I know which version of D3DX9 I am using? Also it never gets to the effect passes as the mFX effect object is returned NULL and the produces the error – unknownSPY May 19 '15 at 19:39
  • @MuertoExcobito Really not sure what's happening then as the shader is from a DirectX9c book in which the sole purpose of one of the examples is to use this shader and it definitely works with their example. What is the Effect-Compiler Tool? – unknownSPY May 19 '15 at 19:43
  • Effect-Compiler Tools is `fxc.exe` - the offline shader compiler. Perhaps the bytecode produced is compatible with D3D9, even if the language construct isn't. Anyhow, if the shader compiles under similar circumstances, that's unlikely the problem, and you would expect a compile error message instead. – MuertoExcobito May 19 '15 at 19:47
  • @MuertoExcobito I just cant work out the difference then between the two projects. They are (as far as I can see) creating the exact same D3D environment yet one program allows the shader to compile and the other doesn't. Are there any IDE (VS2010) setting that might have an effect? – unknownSPY May 19 '15 at 19:50
  • Can you send a link to the ``Terrain.fx`` file? – Chuck Walbourn May 19 '15 at 19:54
  • Will send a link in the morning. but I have a feeling I might no what it is. – unknownSPY May 19 '15 at 21:28
  • Sigh, Figured it out. When you use `D3DXCreateEffectFromFile()` you don't specify a specific path and it just so happened that there were 2 versions of the terrain.fx shader. So thats my fault. So as Paul-Jan first confirmed, you can't use cbuffers in DX9. thanks for the help guys. – unknownSPY May 20 '15 at 07:13

0 Answers0