2019-04-19 00:46:49 +08:00
|
|
|
|
#include"VKDescriptorSets.h"
|
|
|
|
|
#include"VKDevice.h"
|
|
|
|
|
|
|
|
|
|
VK_NAMESPACE_BEGIN
|
2019-04-23 02:46:47 +08:00
|
|
|
|
namespace
|
2019-04-19 00:46:49 +08:00
|
|
|
|
{
|
2019-04-23 02:46:47 +08:00
|
|
|
|
void DestroyDescriptorSetLayout(VkDevice device,List<VkDescriptorSetLayout> &dsl_list)
|
2019-04-19 00:46:49 +08:00
|
|
|
|
{
|
2019-04-23 02:46:47 +08:00
|
|
|
|
const int count=dsl_list.GetCount();
|
2019-04-20 00:45:11 +08:00
|
|
|
|
|
2019-04-23 02:46:47 +08:00
|
|
|
|
if(count>0)
|
|
|
|
|
{
|
|
|
|
|
VkDescriptorSetLayout *dsl=dsl_list.GetData();
|
2019-04-19 00:46:49 +08:00
|
|
|
|
|
2019-04-23 02:46:47 +08:00
|
|
|
|
for(int i=0;i<count;i++)
|
|
|
|
|
{
|
|
|
|
|
vkDestroyDescriptorSetLayout(device,*dsl,nullptr);
|
|
|
|
|
++dsl;
|
|
|
|
|
}
|
2019-04-19 00:46:49 +08:00
|
|
|
|
|
2019-04-23 02:46:47 +08:00
|
|
|
|
dsl_list.Clear();
|
2019-04-19 00:46:49 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2019-04-23 02:46:47 +08:00
|
|
|
|
}//namespace
|
2019-04-19 00:46:49 +08:00
|
|
|
|
|
2019-04-23 02:46:47 +08:00
|
|
|
|
DescriptorSetLayout::~DescriptorSetLayout()
|
2019-04-19 00:46:49 +08:00
|
|
|
|
{
|
2019-04-23 02:46:47 +08:00
|
|
|
|
// 这里注释掉是因为从来不见那里的范例有FREE过,但又有vkFreeDescriptorSets这个函数。如发现此注释,请使用工具查是否有资源泄露
|
|
|
|
|
//{
|
|
|
|
|
//const int count=desc_sets.GetCount();
|
2019-04-19 00:46:49 +08:00
|
|
|
|
|
2019-04-23 02:46:47 +08:00
|
|
|
|
//if(count>0)
|
|
|
|
|
// vkFreeDescriptorSets(device->GetDevice(),device->GetDescriptorPool(),count,desc_sets.GetData());
|
|
|
|
|
//}
|
2019-04-19 00:46:49 +08:00
|
|
|
|
|
2019-04-23 02:46:47 +08:00
|
|
|
|
DestroyDescriptorSetLayout(*device,desc_set_layout_list);
|
|
|
|
|
}
|
2019-04-19 00:46:49 +08:00
|
|
|
|
|
2019-04-23 22:07:26 +08:00
|
|
|
|
bool DescriptorSetLayout::UpdateUBO(const uint32_t binding,const VkDescriptorBufferInfo *buf_info)
|
2019-04-23 02:46:47 +08:00
|
|
|
|
{
|
|
|
|
|
int index;
|
|
|
|
|
|
|
|
|
|
if(!binding_index.Get(binding,index))
|
|
|
|
|
return(false);
|
|
|
|
|
|
|
|
|
|
VkDescriptorSet set;
|
|
|
|
|
if(!desc_sets.Get(index,set))
|
|
|
|
|
return(false);
|
|
|
|
|
|
|
|
|
|
VkWriteDescriptorSet writeDescriptorSet = {};
|
|
|
|
|
|
|
|
|
|
writeDescriptorSet.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
|
|
|
|
|
writeDescriptorSet.dstSet = set;
|
|
|
|
|
writeDescriptorSet.descriptorCount = 1;
|
|
|
|
|
writeDescriptorSet.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
|
|
|
|
|
writeDescriptorSet.pBufferInfo = buf_info;
|
|
|
|
|
writeDescriptorSet.dstBinding = binding;
|
|
|
|
|
|
|
|
|
|
vkUpdateDescriptorSets(device->GetDevice(), 1, &writeDescriptorSet, 0, nullptr);
|
|
|
|
|
return(true);
|
2019-04-19 00:46:49 +08:00
|
|
|
|
}
|
|
|
|
|
|
2019-04-22 00:33:48 +08:00
|
|
|
|
void DescriptorSetLayoutCreater::Bind(const uint32_t binding,VkDescriptorType desc_type,VkShaderStageFlagBits stageFlags)
|
2019-04-19 00:46:49 +08:00
|
|
|
|
{
|
|
|
|
|
VkDescriptorSetLayoutBinding layout_binding = {};
|
|
|
|
|
layout_binding.binding = binding;
|
|
|
|
|
layout_binding.descriptorType = desc_type;
|
|
|
|
|
layout_binding.descriptorCount = 1;
|
|
|
|
|
layout_binding.stageFlags = stageFlags;
|
|
|
|
|
layout_binding.pImmutableSamplers = nullptr;
|
|
|
|
|
|
2019-04-23 02:46:47 +08:00
|
|
|
|
const int index=layout_binding_list.Add(layout_binding);
|
|
|
|
|
|
|
|
|
|
binding_index.Add(binding,index);
|
2019-04-19 00:46:49 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DescriptorSetLayout *DescriptorSetLayoutCreater::Create()
|
|
|
|
|
{
|
2019-04-19 22:27:12 +08:00
|
|
|
|
const int count=layout_binding_list.GetCount();
|
|
|
|
|
|
|
|
|
|
if(count<=0)
|
|
|
|
|
return(nullptr);
|
|
|
|
|
|
2019-04-19 00:46:49 +08:00
|
|
|
|
VkDescriptorSetLayoutCreateInfo descriptor_layout = {};
|
|
|
|
|
descriptor_layout.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
|
|
|
|
|
descriptor_layout.pNext = nullptr;
|
2019-04-19 22:27:12 +08:00
|
|
|
|
descriptor_layout.bindingCount = count;
|
2019-04-19 00:46:49 +08:00
|
|
|
|
descriptor_layout.pBindings = layout_binding_list.GetData();
|
|
|
|
|
|
|
|
|
|
List<VkDescriptorSetLayout> dsl_list;
|
|
|
|
|
|
2019-04-19 22:27:12 +08:00
|
|
|
|
dsl_list.SetCount(count);
|
2019-04-19 00:46:49 +08:00
|
|
|
|
if(vkCreateDescriptorSetLayout(device->GetDevice(),&descriptor_layout, nullptr, dsl_list.GetData())!=VK_SUCCESS)
|
2019-04-20 00:45:11 +08:00
|
|
|
|
return(nullptr);
|
2019-04-19 00:46:49 +08:00
|
|
|
|
|
2019-04-23 02:46:47 +08:00
|
|
|
|
VkDescriptorSetAllocateInfo alloc_info;
|
|
|
|
|
alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
|
|
|
|
|
alloc_info.pNext = nullptr;
|
|
|
|
|
alloc_info.descriptorPool = device->GetDescriptorPool();
|
|
|
|
|
alloc_info.descriptorSetCount = count;
|
|
|
|
|
alloc_info.pSetLayouts = dsl_list.GetData();
|
|
|
|
|
|
|
|
|
|
List<VkDescriptorSet> desc_set;
|
|
|
|
|
|
|
|
|
|
desc_set.SetCount(count);
|
|
|
|
|
|
|
|
|
|
if(vkAllocateDescriptorSets(device->GetDevice(), &alloc_info, desc_set.GetData())!=VK_SUCCESS)
|
|
|
|
|
{
|
|
|
|
|
DestroyDescriptorSetLayout(*device,dsl_list);
|
|
|
|
|
return(nullptr);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return(new DescriptorSetLayout(device,dsl_list,desc_set,binding_index));
|
2019-04-19 00:46:49 +08:00
|
|
|
|
}
|
|
|
|
|
VK_NAMESPACE_END
|