Microsoft DirectX 8.0 (C++)

D3DXAssembleShaderFromFileW

Assembles an ASCII description of a shader into binary form, where the source file name is a Unicode string.

HRESULT D3DXAssembleShaderFromFileW(
  LPCWSTR pSrcFile,
  DWORD Flags,
  LPD3DXBUFFER* ppConstants,
  LPD3DXBUFFER* ppCompiledShader,
  LPD3DXBUFFER* ppCompilationErrors
);

Parameters

pSrcFile
[in] Pointer to the source file name, in Unicode format.
Flags
[in] A combination of the following flags, specifying assembly options.
D3DXASM_DEBUG
Inserts debugging information as comments in the assembled shader.
D3DXASM_SKIPVALIDATION
Do not validate the generated code against known capabilities and constraints. This option is recommended only when assembling a shader you know will function (that is, the shader has been assembled before without this option.)
ppConstants
[out] Returns a pointer to an ID3DXBuffer interface, representing the returned constant declarations. These constants are returned as a vertex shader declaration fragment. It is up to the application to insert the contents of this buffer into their declaration. For pixel shaders this parameter is meaningless because constant declarations are included in the assembled shader. This parameter is ignored if it is NULL.
ppCompiledShader
[out] Returns a pointer to an ID3DXBuffer interface, representing the returned compiled object code. This parameter is ignored if it is NULL.
ppCompilationErrors
[out] Returns a pointer to an ID3DXBuffer interface, representing the returned ASCII error messages. This parameter is ignored if it is NULL.

Return Values

If the function succeeds, the return value is D3D_OK.

If the function fails, the return value can be one of the following values.

D3DERR_INVALIDCALL
D3DXERR_INVALIDDATA
E_OUTOFMEMORY

Remarks

D3DXAssemblePixelShaderFromFile maps to either D3DXAssembleShaderFromFileA or D3DXAssembleShaderFromFileW, depending on the inclusion or exclusion of the #define UNICODE switch. Include or exclude the #define UNICODE switch to specify whether your application expects Unicode or ANSI strings.

The following code fragment shows how D3DXAssembleShaderFromFile is defined.

#ifdef UNICODE
#define D3DXAssembleShaderFromFile D3DXAssembleShaderFromFileW
#else
#define D3DXAssembleShaderFromFile D3DXAssembleShaderFromFileA
#endif

The following example wrapper function, PreprocessAndAssembleShaderFromFile, shows how you can invoke the C preprocessor on your vertex shader code before invoking the assembler with D3DXAssembleShaderFromFile.

HRESULT
    PreprocessAndAssembleShaderFromFile(
        LPCSTR          szFile, 
        DWORD           Flags,
        LPD3DXBUFFER*   ppConstants, 
        LPD3DXBUFFER*   ppCode, 
        LPD3DXBUFFER*   ppErrors)
{
    char szPath[_MAX_PATH];
    char szTemp[_MAX_PATH];
    char szCmd [_MAX_PATH];

    GetTempPath(sizeof(szPath), szPath);
    GetTempFileName(szPath, "vsa", 0, szTemp);

    _snprintf(szCmd, sizeof(szCmd), "cl /nologo /E %s > %s", szFile, szTemp);

    if(0 != system(szCmd))
        return D3DERR_INVALIDCALL;

    return D3DXAssembleShaderFromFile(szTemp, Flags, ppConstants, ppCode, ppErrors);
}

Note that for this function to work you must have Microsoft®Visual C++® installed and your environment set up so that Cl.exe is in your path.

Requirements

  Header: Declared in D3dx8core.h.
  Import Library: Use D3dx8.lib.

See Also

D3DXAssembleShaderFromFileA