D3DX11CompileFromResource function

Note  The D3DX (D3DX 9, D3DX 10, and D3DX 11) utility library is deprecated for Windows 8 and is not supported for Windows Store apps.
Note  Instead of using this function, we recommend that you use resource functions, then compile offline by using the Fxc.exe command-line compiler or use one of the HLSL compile APIs, like the D3DCompile API.

Compile a shader or an effect from a resource.


HRESULT D3DX11CompileFromResource(
  _In_        HMODULE            hSrcModule,
  _In_        LPCTSTR            pSrcResource,
  _In_        LPCTSTR            pSrcFileName,
  _In_  const D3D10_SHADER_MACRO *pDefines,
  _In_        LPD3D10INCLUDE     pInclude,
  _In_        LPCSTR             pFunctionName,
  _In_        LPCSTR             pProfile,
  _In_        UINT               Flags1,
  _In_        UINT               Flags2,
  _In_        ID3DX11ThreadPump  *pPump,
  _Out_       ID3D10Blob         **ppShader,
  _Out_       ID3D10Blob         **ppErrorMsgs,
  _Out_       HRESULT            *pHResult


hSrcModule [in]


Handle to the resource module containing the shader. HMODULE can be obtained with GetModuleHandle Function.

pSrcResource [in]


Name of the resource containing the shader. If the compiler settings require Unicode, the data type LPCTSTR resolves to LPCWSTR. Otherwise, the data type resolves to LPCSTR.

pSrcFileName [in]


Optional. Effect file name, which is used for error messages only. Can be NULL.

pDefines [in]

Type: const D3D10_SHADER_MACRO*

Optional. Pointer to an array of macro definitions (see D3D10_SHADER_MACRO). The last structure in the array serves as a terminator and must have all members set to 0. If not used, set pDefines to NULL.

pInclude [in]


Optional. Pointer to an interface for handling include files. Setting this to NULL will cause a compile error if a shader contains a #include.

pFunctionName [in]


Name of the shader-entry point function where shader execution begins. When you compile an effect, D3DX11CompileFromResource ignores pFunctionName; we recommend that you set pFunctionName to NULL because it is good programming practice to set a pointer parameter to NULL if the called function will not use it.

pProfile [in]


A string that specifies the shader model; can be any profile in shader model 2, shader model 3, shader model 4, or shader model 5. The profile can also be for effect type (for example, fx_4_1).

Flags1 [in]

Type: UINT

Shader compile flags.

Flags2 [in]

Type: UINT

Effect compile flags. When you compile a shader and not an effect file, D3DX11CompileFromResource 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.

pPump [in]

Type: ID3DX11ThreadPump*

A pointer to a thread pump interface (see ID3DX11ThreadPump Interface). Use NULL to specify that this function should not return until it is completed.

ppShader [out]

Type: ID3D10Blob**

A pointer to memory which contains the compiled shader, as well as any embedded debug and symbol-table information.

ppErrorMsgs [out]

Type: ID3D10Blob**

A pointer to memory which contains a listing of errors and warnings that occurred during compilation. These errors and warnings are identical to the debug output from a debugger.

pHResult [out]


A pointer to the return value. May be NULL. If pPump is not NULL, then pHResult must be a valid memory location until the asynchronous execution completes.

Return value


The return value is one of the values listed in Direct3D 11 Return Codes.

D3DX11CompileFromResource returns E_INVALIDARG if you supply non-NULL to the pHResult parameter when you supply NULL to the pPump parameter. For more information about this situation, see Remarks.


For more information about D3DX11CompileFromResource, see D3DCompile.

You must supply NULL to the pHResult parameter if you also supply NULL to the pPump parameter. Otherwise, you cannot subsequently create a shader by using the compiled shader code that D3DX11CompileFromResource returns in the memory that the ppShader parameter points to. To create a shader from complied shader code, you call one of the following ID3D11Device interface methods:

In addition, if you supply a non-NULL value to pHResult when you supply NULL to pPump, D3DX11CompileFromResource returns the E_INVALIDARG error code.






See also

D3DX Functions