Resource binding

AdvancedProgrammer

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

  1. // Create a EffectInstance and use it to set up the pipeline
  2. var effectInstance = new EffectInstance(EffectSystem.LoadEffect("MyEffect").WaitForResult());
  3. pipelineStateDescription.EffectBytecode = effectInstance.Effect.Bytecode;
  4. pipelineStateDescription.RootSignature = effectInstance.RootSignature;
  5. // Update constant buffers and bind resources
  6. 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.