[英]Descriptor Set count ambiguity in Vulkan
I want to draw two objects in vulkan. 我想在vulkan中绘制两个对象。 To achieve this I follow the procedure where you create two different descriptor sets for each model.
为此,我按照为每个模型创建两个不同描述符集的过程进行操作。 However, I am confused about the structs that specify the required descriptor set count.
但是,我对指定所需描述符集计数的结构感到困惑。 The points that confuses me are as follows:
困扰我的要点如下:
specifying the descriptor count at VkDescriptorSetLayoutBinding 在VkDescriptorSetLayoutBinding指定描述符计数
VkDescriptorSetLayoutBinding stagingLayoutBinding = {}; ... stagingLayoutBinding.descriptorCount = 1; <- i have one mat4 element for each descriptors
specifying the descriptor count at VkDescriptorPoolSize 在VkDescriptorPoolSize指定描述符计数
VkDescriptorPoolSize stagingPoolSize = {}; ... stagingPoolSize.descriptorCount = static_cast<uint32_t>(model.size()); <- allocate two descriptor sets from one descriptor pool
specifying the max sets at VkDescriptorPoolCreateInfo 在VkDescriptorPoolCreateInfo中指定最大值集
VkDescriptorPoolCreateInfo poolInfo = {}; ... poolInfo.maxSets = model.size(); <- max descriptor sets = 2
finally specifying the descriptor set creation at VkDescriptorSetAllocateInfo 最后在VkDescriptorSetAllocateInfo中指定描述符集创建
VkDescriptorSetAllocateInfo allocInfo = {}; ... allocInfo.descriptorSetCount = static_cast<uint32_t>(model.size());
however, an exception is thrown at vkAllocateDescriptorSets(device, &allocInfo, descriptorSet.data())
and the debugging message in validation layer is as follows:- 但是,在
vkAllocateDescriptorSets(device, &allocInfo, descriptorSet.data())
抛出异常,验证层中的调试消息如下: -
validation Layer: Object: 0xcccccccccccccccc (Type = 20) | Invalid DescriptorSetLayout Object 0xcccccccccccccccc. The spec valid usage text states 'pSetLayouts must be a valid pointer to an array of descriptorSetCount valid VkDescriptorSetLayout handles' (https://www.khronos.org/registry/vulkan/specs/1.0/html/vkspec.html#VUID-VkDescriptorSetAllocateInfo-pSetLayouts-parameter)
my descriptor creation code is as follows: 我的描述符创建代码如下:
VkDescriptorSetLayout layouts[] = { descriptorSetLayout };
descriptorSet.resize(model.size());
VkDescriptorSetAllocateInfo allocInfo = {};
allocInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
allocInfo.descriptorPool = descriptorPool[0];
allocInfo.descriptorSetCount = static_cast<uint32_t>(model.size());
allocInfo.pSetLayouts = layouts;
if (vkAllocateDescriptorSets(device, &allocInfo, descriptorSet.data()) != VK_SUCCESS)
{
throw std::runtime_error("failed to allocate descriptor set !");
}
I presume I am feeding the wrong descriptor set count somewhere. 我认为我在某处提供错误的描述符集计数。
The problem lays probably here: 问题可能在这里:
allocInfo.descriptorSetCount = static_cast<uint32_t>(model.size());
If You want to draw 2 objects than I assume model.size()
returns 2
. 如果你想绘制2个对象而不是我假设
model.size()
返回2
。 Yet, You provide only one descriptor set layout: 但是,您只提供一个描述符集布局:
VkDescriptorSetLayout layouts[] = { descriptorSetLayout };
If You want to allocate 2 (or more) descriptor sets, You need to provide 2 (or more) descriptor set layouts. 如果要分配2个(或更多)描述符集,则需要提供2个(或更多)描述符集布局。 If You want the descriptor sets to share the layout, You just need to provide the same layout multiple times.
如果您希望描述符集共享布局,则只需多次提供相同的布局。
As for the confusing fields: 至于令人困惑的领域:
descriptorCount
member of the VkDescriptorSetLayoutBinding
structure is the number of descriptors contained in the binding, accessed in a shader as an array. VkDescriptorSetLayoutBinding
结构的descriptorCount
成员是绑定中包含的描述符数,在着色器中作为数组访问。 Usually 1
will be provided here, unless You want to create an array of descriptors of a given type (for example an array of sampled images), then You need to provide a larger value. 1
,除非您想要创建给定类型的描述符数组(例如采样图像数组),那么您需要提供更大的值。 descriptorCount
member of the VkDescriptorPoolSize
specifies how many descriptors of a given type can be allocated from a given pool. VkDescriptorPoolSize
descriptorCount
成员指定可以从给定池分配给定类型的描述符的数量。 This value is independent of the total descriptor sets, for example You can create a descriptor pool from which You can allocate 3 descriptor sets in total, but only 2 storage images in total. maxSets
member of the VkDescriptorPoolCreateInfo
structure defines how many descriptor sets can be allocated from a given pool (the total number of sets which can be allocated from the pool). maxSets
所述的构件VkDescriptorPoolCreateInfo
结构限定多少描述符集可以从一个给定的池(其中可以从池中被分配集的总数目)进行分配。 Again, this value defines "whole" sets, while the previous value (from the bullet 2) defines specific descriptors. descriptorSetCount
member of the VkDescriptorSetAllocateInfo
structure specifies how many descriptor sets You want to allocate at a given moment (during vkAllocateDescriptorSets()
function call). VkDescriptorSetAllocateInfo
结构的descriptorSetCount
成员指定在给定时刻(在vkAllocateDescriptorSets()
函数调用期间vkAllocateDescriptorSets()
要分配的描述符集数量。 For example, You can create a pool from which You can allocate 10 descriptor sets, but You want to allocate only one descriptor set at a time, by calling the vkAllocateDescriptorSets()
function 10 times. vkAllocateDescriptorSets()
函数10次。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.