简体   繁体   English

描述符设置Vulkan中的计数歧义

[英]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: 困扰我的要点如下:

  1. specifying the descriptor count at VkDescriptorSetLayoutBinding VkDescriptorSetLayoutBinding指定描述符计数

     VkDescriptorSetLayoutBinding stagingLayoutBinding = {}; ... stagingLayoutBinding.descriptorCount = 1; <- i have one mat4 element for each descriptors 
  2. 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 
  3. specifying the max sets at VkDescriptorPoolCreateInfo VkDescriptorPoolCreateInfo中指定最大值集

     VkDescriptorPoolCreateInfo poolInfo = {}; ... poolInfo.maxSets = model.size(); <- max descriptor sets = 2 
  4. 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: 至于令人困惑的领域:

  1. 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 ,除非您想要创建给定类型的描述符数组(例如采样图像数组),那么您需要提供更大的值。
  2. 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. 此值与总描述符集无关,例如,您可以创建一个描述符池,您可以从中分配总共3个描述符集,但总共只能分配2个存储库。
  3. 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. 同样,此值定义“整个”集,而前一个值(来自项目符号2)定义特定描述符。
  4. 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. 例如,您可以创建一个池,您可以从中分配10个描述符集,但是您希望一次只调用一个描述符集,方法是调用vkAllocateDescriptorSets()函数10次。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Vulkan:添加第三个描述符时出错 - Vulkan: Errors when adding 3rd descriptor Vulkan:屏幕不同部分的不同样本计数 - Vulkan: Different sample count in different part of the screen 将一组类转换为类模板,并避免构造函数的歧义 - Converting a set of classes to class templates and avoiding constructor ambiguity 将文件描述符添加到事件设置为零的epoll是否有效? - Is it valid to add a file descriptor to epoll with events set to zero? 套接字选择可减少文件描述符集中的套接字数量 - Socket select reducing the number of sockets in file descriptor set Vulkan:为什么主要命令缓冲区和辅助命令缓冲区都需要设置帧缓冲区和renderpass? - Vulkan: why both primary command buffer and secondary command buffers need to set framebuffer and renderpass? 无论如何将 VkDescriptorImageInfo 设置为 null 或有某种方式使用 VkWriteDescriptorSet 跳过而不会抱怨 vulkan - Is there anyway to set the VkDescriptorImageInfo to null or have some way of skipping using a VkWriteDescriptorSet without vulkan complaining 一组元素的数量(不是总数) - count of elements in a set (not total count) 模板含糊不清 - Ambiguity with templates 歧义解决方案 - Ambiguity Resolution
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM