集合中的“绑定”对于制服来说必须是唯一的吗?
Do `bindings` within a set have to be unique for a uniform?
layout (set = 0, binding = 0) uniform sampler2D sampler;
layout (set = 0, binding = 0) uniform Test{
mat4 m;
} test;
这与 glslang
编译没有任何错误。我认为集合内的绑定必须是唯一的?
如果确实允许这样做,您将如何向 sampler
和 test
发送数据?
typedef struct VkWriteDescriptorSet {
VkStructureType sType;
const void* pNext;
VkDescriptorSet dstSet;
uint32_t dstBinding;
uint32_t dstArrayElement;
uint32_t descriptorCount;
VkDescriptorType descriptorType;
const VkDescriptorImageInfo* pImageInfo;
const VkDescriptorBufferInfo* pBufferInfo;
const VkBufferView* pTexelBufferView;
} VkWriteDescriptorSet;
Vulkan 1.0.58 澄清了这一点,明确声明上述代码是非法的:
It is valid for multiple shader variables to be assigned the same descriptor set and binding values, as long as all those that are statically used by the entry point being compiled are compatible with the descriptor type in the descriptor set layout binding.
您的描述符集布局类型几乎不可能与 VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER/_DYNAMIC
和 VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER
兼容。所以这将失败。
除了 Nicol Bolas 引用的要求之外,还有一些其他相关部分:
Valid Usage for VkDescriptorSetLayoutCreateInfo 说:
The VkDescriptorSetLayoutBinding::binding
members of the elements of the pBindings
array must each have different values.
这意味着您不能拥有一个描述符集布局,该布局使用多个具有特定(集、绑定)的变量。因此,您也不能创建描述符集或具有多个具有相同绑定的变量的管道。因此,即使 GLSL 和 SPIR-V 本身有效,也无法使用变量或消除在 Vulkan 中使用哪个变量的歧义。
第 13.2.2 Pipeline Layouts 节说:
All resource variables statically used in all shaders in a pipeline must be declared with a (set,binding,arrayElement) that exists in the corresponding descriptor set layout and is of an appropriate descriptor type and includes the set of shader stages it is used by in stageFlags.
由于这将管线着色器中的 SPIR-V 变量绑定到描述符集布局中的绑定,因此 SPIR-V 在 Vulkan 管线中使用无效,因为无法满足此要求:您只能满足具有相同 (set,binding) 的变量之一。
layout (set = 0, binding = 0) uniform sampler2D sampler;
layout (set = 0, binding = 0) uniform Test{
mat4 m;
} test;
这与 glslang
编译没有任何错误。我认为集合内的绑定必须是唯一的?
如果确实允许这样做,您将如何向 sampler
和 test
发送数据?
typedef struct VkWriteDescriptorSet {
VkStructureType sType;
const void* pNext;
VkDescriptorSet dstSet;
uint32_t dstBinding;
uint32_t dstArrayElement;
uint32_t descriptorCount;
VkDescriptorType descriptorType;
const VkDescriptorImageInfo* pImageInfo;
const VkDescriptorBufferInfo* pBufferInfo;
const VkBufferView* pTexelBufferView;
} VkWriteDescriptorSet;
Vulkan 1.0.58 澄清了这一点,明确声明上述代码是非法的:
It is valid for multiple shader variables to be assigned the same descriptor set and binding values, as long as all those that are statically used by the entry point being compiled are compatible with the descriptor type in the descriptor set layout binding.
您的描述符集布局类型几乎不可能与 VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER/_DYNAMIC
和 VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER
兼容。所以这将失败。
除了 Nicol Bolas 引用的要求之外,还有一些其他相关部分:
Valid Usage for VkDescriptorSetLayoutCreateInfo 说:
The
VkDescriptorSetLayoutBinding::binding
members of the elements of thepBindings
array must each have different values.
这意味着您不能拥有一个描述符集布局,该布局使用多个具有特定(集、绑定)的变量。因此,您也不能创建描述符集或具有多个具有相同绑定的变量的管道。因此,即使 GLSL 和 SPIR-V 本身有效,也无法使用变量或消除在 Vulkan 中使用哪个变量的歧义。
第 13.2.2 Pipeline Layouts 节说:
All resource variables statically used in all shaders in a pipeline must be declared with a (set,binding,arrayElement) that exists in the corresponding descriptor set layout and is of an appropriate descriptor type and includes the set of shader stages it is used by in stageFlags.
由于这将管线着色器中的 SPIR-V 变量绑定到描述符集布局中的绑定,因此 SPIR-V 在 Vulkan 管线中使用无效,因为无法满足此要求:您只能满足具有相同 (set,binding) 的变量之一。