着色器通過使用特殊的着色器變量(通過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
...