Graphics Reference
In-Depth Information
compilation completes, or it can be configured to output the assembly listing to a file. In
addition, PIX can be used to inspect D3D11 shader objects and view the assembly code.
For more information on shader assembly, see the HLSL reference section in the DirectX
SDK documentation.
6.2.3 Runtime Shader Objects
Once the bytecode is produced for a shader program, it is ready to be used to create a D3D11
shader object. The ID3D11Device interface provides six methods for creating shader objects,
one for each programmable stage of the pipeline. These methods are CreateVertexShader,
CreateHullShader,CreateDomainShader,CreateGeometryShader,CreatePixelShader,
and CreateComputeShader. Each of these accepts a bytecode stream and produces an
ID3Dll*Shader interface that represents the runtime shader object that can be bound to the
pipeline. See Listing 6.1 for a simple example of compiling a vertex shader and creating a
runtime shader object.
ID3D10Blob* compiledShader;
ID3D10Blob* errorMessages;
HRESULT hr = D3DXllCompileFromFile( filePath, NULL, NULL, "VSMain",
"vs_5_0", 0, 0, NULL, &compiledShader,
&errorMessages, NULL );
if ( FAILED( hr ) )
{
if ( errorMessages )
{
const char* msg = (char*)( errorMessages->GetBufferPointer() );
Log::6et() .Write( msg );
}
else
{
Log:: Get ().Write( "D3DXllCompileFromFile failed" );
}
}
else
{
ID3DllVertexShader* vertexShader = NULL;
device- >CreateVertexShader( compiledShader->GetBufferPointer(),
compiledShader->GetBufferSize(),
NULL,
&vertexShader );
}
Listing 6.1. Compiling a vertex shader from a file.
Search WWH ::




Custom Search