The Pipeline Resource Layout defines how shader resource variables are used and categorized by their update frequency. This allows the engine to optimize bindings.
Variable Classifications
- Static variables (
SHADER_RESOURCE_VARIABLE_TYPE_STATIC): Expected to be set once (e.g., global camera or light constants). The binding must not change once set, though the resource content can. - Mutable variables (
SHADER_RESOURCE_VARIABLE_TYPE_MUTABLE): Expected to change per-material (e.g., diffuse textures). - Dynamic variables (
SHADER_RESOURCE_VARIABLE_TYPE_DYNAMIC): Expected to change frequently and randomly.
Immutable Samplers
You can permanently assign immutable samplers to textures within the PSO. If an immutable sampler is assigned, it will always be used instead of the sampler initialized in the texture's shader resource view. It is highly recommended to use immutable samplers whenever possible. These can be assigned to any variable type, allowing the texture binding to change at runtime while the sampler remains fixed.
To define these, populate PSODesc.ResourceLayout.Variables and PSODesc.ResourceLayout.ImmutableSamplers.
// Define variable types
ShaderResourceVariableDesc ShaderVars[] =
{
{SHADER_TYPE_PIXEL, "g_StaticTexture", SHADER_RESOURCE_VARIABLE_TYPE_STATIC},
{SHADER_TYPE_PIXEL, "g_MutableTexture", SHADER_RESOURCE_VARIABLE_TYPE_MUTABLE},
{SHADER_TYPE_PIXEL, "g_DynamicTexture", SHADER_RESOURCE_VARIABLE_TYPE_DYNAMIC}
};
PSODesc.ResourceLayout.Variables = ShaderVars;
PSODesc.ResourceLayout.NumVariables = _countof(ShaderVars);
PSODesc.ResourceLayout.DefaultVariableType = SHADER_RESOURCE_VARIABLE_TYPE_STATIC;
// Define immutable samplers
ImmutableSamplerDesc ImtblSampler;
ImtblSampler.ShaderStages = SHADER_TYPE_PIXEL;
ImtblSampler.Desc.MinFilter = FILTER_TYPE_LINEAR;
ImtblSampler.Desc.MagFilter = FILTER_TYPE_LINEAR;
ImtblSampler.Desc.MipFilter = FILTER_TYPE_LINEAR;
ImtblSampler.TextureName = "g_MutableTexture";
PSODesc.ResourceLayout.NumImmutableSamplers = 1;
PSODesc.ResourceLayout.ImmutableSamplers = &ImtblSampler;