用于设置 HLSL 着色器参数的 DirectX API 采用相应参数占用的插槽的参数。这些槽号是在所有资源类型之间全局共享的,还是每种类型都有自己独特的槽号集。“类型”是指内在的 HLSL 结构,如 cbuffers、纹理、采样器等。
这是一个假设的 HLSL 着色器文件,它说明了我的问题。
// Note the order I declare things here is for the purpose of the question,
// not how I would declare them in a real shader file.
// First constant buffer and first item, definitely at index 0.
cbuffer PerFrameData
{
// stuff
};
// Is this texture at index 0 because its the first texture
// declared, or index 1 because it's the second item declared?
Texture2D firstTexture;
// Second cbuffer, third declared - index 1 or 2?
cbuffer PerObjectData
{
// stuff
};
// Second texture, fourth declared - index 1 or 3?
Texture2D secondTexture;
// This sampler is declared last, do I use index 0 or 4?
SamplerState texSampler;