Resource binding
Advanced Programmer
When drawing vertices using an effect, the shaders expect certain resources to be available, including:
- textures and buffers
- samplers
- constant buffers
Automatic resource binding
The EffectInstance class handles the details of enumerating these resources from a loaded effect as well as binding them.
It exposes the RootSignature, which has to be set as pipeline state, and allows to fill constant buffers and bind resources based on a ParameterCollection.
Code: Using an EffectInstance
// Create a EffectInstance and use it to set up the pipeline
var effectInstance = new EffectInstance(EffectSystem.LoadEffect("MyEffect").WaitForResult());
pipelineStateDescription.EffectBytecode = effectInstance.Effect.Bytecode;
pipelineStateDescription.RootSignature = effectInstance.RootSignature;
// Update constant buffers and bind resources
effectInstance.Apply(context.GraphicsContext);
Manual resource binding
When more optimized code is required (eg in the rendering pipeline), constant buffer updates and resource binding can be done manually.