Sign in to follow this  
shadowomf

D3DXCreateEffect

Recommended Posts

Hello, I have the following problem when I use D3DXCreateEffectFromFile() i get the error X3000 syntax error: unexpected integer constant. But when I use fxc.exe it compiles without problems. What is the Problem? The following code should create the effect. It uses Nebula2 and Mangalore but should be selfexplaining.
//------------------------------------------------------------------------------
/**
    Creates an Effect Compiler from a file. 
*/
ID3DXEffect*
nDebugShaderCompiler::CreateEffect(const nString& srcFile, const ShaderModel& shaderModel)
{
    n_assert(srcFile.IsValid());
    HRESULT hr;

    if (!nFileServer2::Instance()->FileExists(srcFile))
    {
        n_error("\nnDebugShaderCompiler::CreateEffectCompiler: source file doesn't exists");
    }
    nString mangledPath = nFileServer2::Instance()->ManglePath(srcFile);

    // create a d3d device
    LPDIRECT3DDEVICE9 dx_device = this->CreateReferenceDevice();

    // set the preprocessor macros
    D3DXMACRO defines[] = {
        { "VS_PROFILE", shaderModel.vsModel.AsCharPtr() },
        { "PS_PROFILE", shaderModel.psModel.AsCharPtr() },
        { 0, 0 },
    };

    // create the effect
    ID3DXBuffer* compileErrors = 0;
    //LPD3DXEFFECT* effect = 0;
    ID3DXEffect* effect = 0;
    hr = D3DXCreateEffectFromFile(dx_device,
                                  mangledPath.AsCharPtr(),
                                  defines,
                                  0,
                                  0,
                                  0,
                                  &effect,
                                  &compileErrors);
    
    if (FAILED(hr))
    {
        if (0 != compileErrors)
        {
            n_error("Failed compiling effect '%s' with '%s'\n",
                srcFile.AsCharPtr(), compileErrors->GetBufferPointer());
            compileErrors->Release();
        }
        else
        {
            n_error("Failed compiling effect '%s' without any D3DErrors\n", srcFile.AsCharPtr());
        }
    }

    // release the device
    dx_device->Release();

    return effect;
}

//------------------------------------------------------------------------------
/**
    Create a D3D reference device. 
*/
LPDIRECT3DDEVICE9
nDebugShaderCompiler::CreateReferenceDevice()
{
    HRESULT hr;

    // create a d3d object
    LPDIRECT3D9 dx_object = Direct3DCreate9(D3D_SDK_VERSION);
    if (0 == dx_object)
    {
        n_error("Failed creating the D3D object\n");
    }

    // set the parameters for the reference device
    D3DPRESENT_PARAMETERS dx_params;
    ZeroMemory(&dx_params, sizeof(dx_params));
    dx_params.Windowed = TRUE;
    dx_params.SwapEffect = D3DSWAPEFFECT_DISCARD;
    dx_params.BackBufferFormat = D3DFMT_UNKNOWN;

    // create a d3d reference device
    LPDIRECT3DDEVICE9 dx_device;
    hr = dx_object->CreateDevice(D3DADAPTER_DEFAULT,
                                 D3DDEVTYPE_REF,
                                 this->window, // this need the window handle
                                 D3DCREATE_SOFTWARE_VERTEXPROCESSING,
                                 &dx_params,
                                 &dx_device);
    if (FAILED(hr))
    {
        n_error("Failed creating the D3D reference device\n");
    }

    return dx_device;
}

Thanks in advance, Christoph [Edited by - shadowomf on December 15, 2006 1:37:24 AM]

Share this post


Link to post
Share on other sites
Not sure if this will help you in any way but this is how I use that command:


bool CDXEffect::CreateFromFile(void)
{

m_dwShaderFlags = D3DXSHADER_DEBUG | D3DXSHADER_SKIPOPTIMIZATION;
HRESULT hr = D3DXCreateEffectFromFile(m_pD3DDevice,m_szFileName, m_pD3DDefines,m_pD3DInclude, m_dwShaderFlags,m_pD3DPool, &m_pD3DEffect,&m_pD3DCompileErrors);
if (hr == D3D_OK)
{
m_bCreated = true;
return true;
}
if (hr == D3DERR_INVALIDCALL)
{
MessageBox(NULL,"Invalid Call","Create Effect from File",MB_OK);
return false;
}
if (hr == D3DXERR_INVALIDDATA)
{
MessageBox(NULL,"Invalid Data","Create Effect from File",MB_OK);
return false;
}
if (hr == E_OUTOFMEMORY)
{
MessageBox(NULL,"Out of Memory","Create Effect from File",MB_OK);
return false;
}

if (!m_pD3DEffect)
{
LPCTSTR buff = (LPCTSTR)m_pD3DCompileErrors->GetBufferPointer();
MessageBox(NULL,buff,"Compiler Errors",MB_OK);
return false;
}
return true;
}



The variables used are stored in the class header file as such:


LPDIRECT3DDEVICE9 m_pD3DDevice;
LPD3DXEFFECT m_pD3DEffect;
LPD3DXBUFFER m_pD3DCompileErrors;
LPD3DXMACRO m_pD3DDefines;
LPD3DXINCLUDE m_pD3DInclude;
LPD3DXEFFECTPOOL m_pD3DPool;
DWORD m_dwShaderFlags;



and initialised as follows:

m_pD3DDevice = pD3DDevice;
m_pD3DEffect = NULL;
m_pD3DDefines = NULL;
m_pD3DInclude = NULL;
m_pD3DPool = NULL;
m_pD3DCompileErrors = NULL;
m_dwShaderFlags = NULL;



Here's hoping that little lot has helped locate the problems you are getting.

Share this post


Link to post
Share on other sites
I tried to find the mistake but everything seems fine.

I try to compile an effect file named blended.fx, this file include another .fx file named defaultfuncs.fx and in this file the error occurs, but with fxc it compiles without any problems.

Failed compiling effect 'proj:work/shaders/2.0/blended.fx' with 'C:\radonlabs\work\shaders\2.0\lib\defaultfuncs.fx(111): error X3000: syntax error: unexpected integer constant'

Is the (111) the line number?

Maybe something is wrong with my Macros because line 111 uses one of them.

VertexShader = compile VS_PROFILE vsStaticDepth(); // line 111



And the Macro is something like VS_PROFILE = 2_0 (at least thats what the Debugger says).

// set the preprocessor macros
D3DXMACRO defines[] = {
{ "VS_PROFILE", shaderModel.vsModel.AsCharPtr() },
{ "PS_PROFILE", shaderModel.psModel.AsCharPtr() },
{ 0, 0 },
};



Regards,
Christoph

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