Graphics Reference
In-Depth Information
Once the class linkage is bound to a shader, an ID3DllClassInstance interface
can be retrieved. A class instance represents one of the classes declared in the shader
that can be used to implement an interface. The simplest means to acquire one is to call
GetClassInstance on the ID3DllClassLinkage interface, and pass the name of a class
instance declared in the shader program. CreateClassInstance can also be used for
shader programs where a class instance wasn't declared in a constant buffer, which is use-
ful for classes that don't contain member variables. Listing 6.21 demonstrates the process
of acquiring a class instance interface.
ID3DllClassInstance* dLightlnstance = NULL;
classLinkage->GetClassLinkage( L"DLightInstance", 0 , & dLightlnstance );
Listing 6.21. Acquiring a class linkage.
The final step for using dynamic linkage is to specify an array of class instances
when binding a shader program to the pipeline. The ID3DllDeviceContext::*SSet
Shader methods all have a ppClassInstances parameter that accepts an array of
ID3DllClassInstance interfaces. This array must contain one class instance for each the
interfaces used in the shader program. Listing 6.22 demonstrates initializing and passing
such an array for a pixel shader.
ID3DllClassInstance* classlnstances[1];
classlnstances[0] = dLightlnstance;
deviceContext->PSSetShader( pixelShader, classlnstances, 1 );
Listing 6.22. Specifying class instances when binding a shader.
Each interface used in a shader program has a unique index, which corresponds to an
index of the array passed to *SSetShader containing the class instances. This index can
be retrieved using the ID3D11ShaderReflectionVariable interface, which is part of the
shader reflection APIs. See the "Shader Reflection" section for more details.
6.7 Intrinsic Functions
HLSL provides a built-in set of global functions known as intrinsics. Like intrinsics in C
or C++, HLSL intrinsics often directly map to specific shader assembly instructions. This
Search WWH ::




Custom Search