Graphics Reference
In-Depth Information
6.8.1 Shader Program Information
General information and statistics regarding a single shader program can be queried
through the ID3D11ShaderReflection interface. This interface also provides the means for
accessing the interfaces used for querying constant buffer, variable, or type information. To
obtain the ID3D11ShaderReflection interface for a compiled shader program, an applica-
tion must call the D3D11Reflect function exported by the D3DCompiler DLL. Note that this
function is actually just a wrapper for D3DReflect, which it simply calls with the interface
ID of ID3D11ShaderReflection. Listing 6.23 demonstrates a simple case of compiling a
vertex shader program, and obtaining its reflection interface.
ID3D10Blob* compiledShader;
ID3D10Blob* errorMessages;
HRESULT hr = D3DXllCompileFromFile( filePath, NULL, NULL, "VSMain",
"vs_5_0", 0, 0, NULL, &compiledShader,
&errorMessages, NULL );
ID3D11ShaderReflection* reflection = NULL;
if ( SUCCEEDED( hr ) )
D3DllReflect( compiledShader->GetBufferPointer(),
compiledShader->GetBufferSize(),
&reflection );
Listing 6.23. Obtaining the reflection interface for a shader program.
Once the reflection interface is obtained, it can be queried for information by call-
ing its various methods. These include methods for retrieving the thread group size, the
minimum device feature level required to run the shader, and the frequency of execution
for a pixel shader to name just a few. See the SDK documentation for a full list of available
methods.
Most of the information provided by the ID3D11ShaderReflection interface is avail-
able by calling the GetDesc method. This method returns a D3D11_SHADER_DESC structure
containing a wealth of information. Listing 6.24 contains the declaration of this structure.
struct D3D11_SHADER_DESC {
UINT
Version;
LPCSTR
Creator;
UINT
Flags;
UINT
ConstantBuffers;
UINT
BoundResources;
UINT
InputParameters;
UINT
OutputParameters;
UINT
InstructionCount;
Search WWH ::




Custom Search