着色器通過使用特殊的着色器變量(通過API間接綁定到緩沖區或者圖像視圖)來通路緩沖區和圖像資源。 這些變量被組織進入集合,每一個綁定的集合都通過API的一個 描述符集合 對象來表示,描述符集合隻能被綁定一次。 一個 描述符 是一個不透明的資料類型,表示一個着色器資源,諸如緩沖區視圖、圖像視圖、采樣器或者被綁定的着色器資源。 每一個集合的内容由它自己的 描述集合布局 來決定,可以被管線内部的着色器資源變量使用的集合布局的序列由 pipeline layout 指定。
每一個着色器可以使用最多
maxBoundDescriptorSets
個描述符集合(參考Limits), 每一個描述符集合可以包含所有類型描述符的綁定。 每一個着色器資源變量都被指派為一個tuple(集合個數,綁定個數,數組元素),定義了它在描述集合布局中的位置。 在GLSL中,集合個數和綁定個數是通過布局限定符指派的,數組元素是被連續的指派到其中,數組中第一個元素的索引為0(非數組變量的位置用0填充)。
GLSL example
// Assign set number = M, binding number = N, array element = 0
layout (set=M, binding=N) uniform sampler2D variableName;
// Assign set number = M, binding number = N for all array elements, and
// array element = I for the I'th member of the array.
layout (set=M, binding=N) uniform sampler2D variableNameArray[I];
SPIR-V example
// Assign set number = M, binding number = N, array element = 0
...
%1 = OpExtInstImport "GLSL.std.450"
...
OpName %10 "variableName"
OpDecorate %10 DescriptorSet M
OpDecorate %10 Binding N
%2 = OpTypeVoid
%3 = OpTypeFunction %2
%6 = OpTypeFloat 32
%7 = OpTypeImage %6 2D 0 0 0 1 Unknown
%8 = OpTypeSampledImage %7
%9 = OpTypePointer UniformConstant %8
%10 = OpVariable %9 UniformConstant
...
// Assign set number = M, binding number = N for all array elements, and
// array element = I for the I'th member of the array.
...
%1 = OpExtInstImport "GLSL.std.450"
...
OpName %13 "variableNameArray"
OpDecorate %13 DescriptorSet M
OpDecorate %13 Binding N
%2 = OpTypeVoid
%3 = OpTypeFunction %2
%6 = OpTypeFloat 32
%7 = OpTypeImage %6 2D 0 0 0 1 Unknown
%8 = OpTypeSampledImage %7
%9 = OpTypeInt 32 0
%10 = OpConstant %9 I
%11 = OpTypeArray %8 %10
%12 = OpTypePointer UniformConstant %11
%13 = OpVariable %12 UniformConstant
...