D3DCompile function (d3dcompiler.h)

Compile HLSL code or an effect file into bytecode for a given target.

Syntax

HRESULT D3DCompile(
  [in]            LPCVOID                pSrcData,
  [in]            SIZE_T                 SrcDataSize,
  [in, optional]  LPCSTR                 pSourceName,
  [in, optional]  const D3D_SHADER_MACRO *pDefines,
  [in, optional]  ID3DInclude            *pInclude,
  [in, optional]  LPCSTR                 pEntrypoint,
  [in]            LPCSTR                 pTarget,
  [in]            UINT                   Flags1,
  [in]            UINT                   Flags2,
  [out]           ID3DBlob               **ppCode,
  [out, optional] ID3DBlob               **ppErrorMsgs
);

Parameters

[in] pSrcData

Type: LPCVOID

A pointer to uncompiled shader data; either ASCII HLSL code or a compiled effect.

[in] SrcDataSize

Type: SIZE_T

Length of pSrcData.

[in, optional] pSourceName

Type: LPCSTR

You can use this parameter for strings that specify error messages. If not used, set to NULL.

[in, optional] pDefines

Type: const D3D_SHADER_MACRO*

An optional array of D3D_SHADER_MACRO structures that define shader macros. Each macro definition contains a name and a null-terminated definition. If not used, set to NULL. The last structure in the array serves as a terminator and must have all members set to NULL.

[in, optional] pInclude

Type: ID3DInclude*

Optional. A pointer to an ID3DInclude for handling include files. Setting this to NULL will cause a compile error if a shader contains a #include. You can pass the D3D_COMPILE_STANDARD_FILE_INCLUDE macro, which is a pointer to a default include handler. This default include handler includes files that are relative to the current directory and files that are relative to the directory of the initial source file. When you use D3D_COMPILE_STANDARD_FILE_INCLUDE, you must specify the source file name in the pSourceName parameter; the compiler will derive the initial relative directory from pSourceName.

#define D3D_COMPILE_STANDARD_FILE_INCLUDE ((ID3DInclude*)(UINT_PTR)1)

[in, optional] pEntrypoint

Type: LPCSTR

The name of the shader entry point function where shader execution begins. When you compile using a fx profile (for example, fx_4_0, fx_5_0, and so on), D3DCompile ignores pEntrypoint. In this case, we recommend that you set pEntrypoint to NULL because it is good programming practice to set a pointer parameter to NULL if the called function will not use it. For all other shader profiles, a valid pEntrypoint is required.

[in] pTarget

Type: LPCSTR

A string that specifies the shader target or set of shader features to compile against. The shader target can be shader model 2, shader model 3, shader model 4, or shader model 5. The target can also be an effect type (for example, fx_4_1). For info about the targets that various profiles support, see Specifying Compiler Targets.

[in] Flags1

Type: UINT

Flags defined by D3D compile constants.

[in] Flags2

Type: UINT

Flags defined by D3D compile effect constants. When you compile a shader and not an effect file, D3DCompile ignores Flags2; we recommend that you set Flags2 to zero because it is good programming practice to set a nonpointer parameter to zero if the called function will not use it.

[out] ppCode

Type: ID3DBlob**

A pointer to a variable that receives a pointer to the ID3DBlob interface that you can use to access the compiled code.

[out, optional] ppErrorMsgs

Type: ID3DBlob**

A pointer to a variable that receives a pointer to the ID3DBlob interface that you can use to access compiler error messages, or NULL if there are no errors.

Return value

Type: HRESULT

Returns one of the Direct3D 11 return codes.

Remarks

The difference between D3DCompile and D3DCompile2 is that the latter method takes some optional parameters that can be used to control some aspects of how bytecode is generated. If this extra flexibility is not required, there is no performance gain from using D3DCompile2.

Requirements

Requirement Value
Target Platform Windows
Header d3dcompiler.h
Library d3dcompiler.lib
DLL d3dcompiler_47.dll

See also

Functions