Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
The shader is typically stored in an HLSL text file. To use it, it must be loaded and compiled. It is possible to precompile shaders, saving some loading time, but it can be useful to compile them at runtime so that different levels of shaders on the target machine can be supported.
Compiling a shader file is done with this helper function: CompileShader():
HRESULT CompileShader(
LPCSTR pSrcData,
SIZE_T SrcDataLen,
LPCSTR pFileName,
LPCSTR szEntryPoint,
LPCSTR szShaderModel,
ID3DBlob** ppBlobOut )
{
HRESULT hr = S_OK;
DWORD dwShaderFlags = D3DCOMPILE_ENABLE_STRICTNESS;
#if defined( DEBUG ) || defined( _DEBUG )
// Set the D3DCOMPILE_DEBUG flag to embed debug information in the shaders.
// Setting this flag improves the shader debugging experience, but still
// allows the shaders to be optimized and to run exactly the way they will
// run in the release configuration of this program.
dwShaderFlags |= D3DCOMPILE_DEBUG;
#endif
ID3DBlob* pErrorBlob;
hr = D3DX11CompileFromMemory( pSrcData, SrcDataLen,
pFileName, NULL, NULL, szEntryPoint, szShaderModel,
dwShade....