天天看点

Vulkan Specification(Vulkan规范):第十三章 13 资源描述符

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