Compiles Microsoft High Level Shader Language (HLSL) code into bytecode for a given target.
HRESULT D3DCompile2(
LPCVOID pSrcData,
SIZE_T SrcDataSize,
LPCSTR pSourceName,
const D3D_SHADER_MACRO *pDefines,
ID3DInclude *pInclude,
LPCSTR pEntrypoint,
LPCSTR pTarget,
UINT Flags1,
UINT Flags2,
UINT SecondaryDataFlags,
LPCVOID pSecondaryData,
SIZE_T SecondaryDataSize,
ID3DBlob **ppCode,
ID3DBlob **ppErrorMsgs
)
pSrcData
Type: LPCVOID
[in] A pointer to uncompiled shader data (ASCII Microsoft High Level Shader Language (HLSL) code).
SrcDataSize
Type: SIZE_T
[in] The size, in bytes, of the block of memory that pSrcData points to.
pSourceName
Type: LPCSTR
[in, optional] An optional pointer to a constant null-terminated string containing the name that identifies the source data to use in error messages. If not used, set to NULL.
pDefines
Type: D3D_SHADER_MACRO *
[in, optional] 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.
pInclude
Type: ID3DInclude *
[in, optional] An optional pointer to an ID3DInclude interface that the compiler uses to handle include files. If you set this parameter to NULL and the shader contains a #include, a compile error occurs. 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)
pEntrypoint
Type: LPCSTR
[in] A pointer to a constant null-terminated string that contains the name of the shader entry point function where shader execution begins. When you compile an effect, D3DCompile2 ignores pEntrypoint; 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.
pTarget
Type: LPCSTR
[in] A string that specifies the shader target or set of shader features to compile against. For Xbox One, the shader target can be shader model 4.0, 4.1, or 5.0. For info about the targets that various profiles support, see Specifying Compiler Targets.
Flags1
Type: UINT
[in] A combination of shader compile options that are combined by using a bitwise OR operation. The resulting value specifies how the compiler compiles the Microsoft High Level Shader Language (HLSL) code.
Flags2
Type: UINT
[in] A combination of effect compile options that are combined by using a bitwise OR operation. The resulting value specifies how the compiler compiles the effect. When you compile a shader and not an effect file, D3DCompile2 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.
SecondaryDataFlags
Type: UINT
[in] A combination of the following flags that are combined by using a bitwise OR operation. The resulting value specifies how the compiler compiles the Microsoft High Level Shader Language (HLSL) code.
| Flag | Description |
|---|---|
| D3DCOMPILE_SECDATA_MERGE_UAV_SLOTS (0x01) | Merge unordered access view (UAV) slots in the secondary data that the pSecondaryData parameter points to. |
| D3DCOMPILE_SECDATA_PRESERVE_TEMPLATE_SLOTS (0x02) | Preserve template slots in the secondary data that the pSecondaryData parameter points to. |
| D3DCOMPILE_SECDATA_REQUIRE_TEMPLATE_MATCH (0x04) | Require that templates in the secondary data that the pSecondaryData parameter points to match when the compiler compiles the HLSL code. |
If pSecondaryData is NULL, set to zero.
pSecondaryData
Type: LPCVOID
[in, optional] An optional pointer to secondary data. If you do not pass secondary data, set to NULL.
SecondaryDataSize
Type: SIZE_T
[in] The size, in bytes, of the block of memory that pSecondaryData points to. If pSecondaryData is NULL, set to zero.
ppCode
Type: ID3DBlob **
[out] A pointer to a variable that receives a pointer to the ID3DBlob interface that you can use to access the compiled code.
ppErrorMsgs
Type: ID3DBlob **
[out, optional] An optional 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.
Type: HRESULT
Returns one of the Direct3D 11 return codes.
Note
The D3dcompiler_44.dll or later version of the file contains the D3DCompile2 compiler function.
Header: Declared in d3dcompiler.h.
Library: Use d3d11.lib.