2020-10-21 11:43:18 +08:00
|
|
|
|
#include<hgl/graph/VKDescriptorSets.h>
|
|
|
|
|
#include<hgl/graph/VKDevice.h>
|
|
|
|
|
#include<hgl/graph/VKBuffer.h>
|
|
|
|
|
#include<hgl/graph/VKTexture.h>
|
|
|
|
|
#include<hgl/graph/VKSampler.h>
|
2019-04-19 00:46:49 +08:00
|
|
|
|
|
|
|
|
|
VK_NAMESPACE_BEGIN
|
2019-05-21 12:02:57 +08:00
|
|
|
|
void DescriptorSets::Clear()
|
|
|
|
|
{
|
2020-09-07 20:07:08 +08:00
|
|
|
|
wds_list.ClearData();
|
2019-05-21 12:02:57 +08:00
|
|
|
|
desc_image_info.ClearData();
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-01 15:37:03 +08:00
|
|
|
|
bool DescriptorSets::BindUBO(const int binding,const Buffer *buf)
|
2019-04-19 00:46:49 +08:00
|
|
|
|
{
|
2019-08-01 15:37:03 +08:00
|
|
|
|
if(binding<0||!buf)
|
|
|
|
|
return(false);
|
|
|
|
|
|
2020-09-27 20:58:25 +08:00
|
|
|
|
WriteDescriptorSet wds;
|
2019-04-19 00:46:49 +08:00
|
|
|
|
|
2020-09-07 20:07:08 +08:00
|
|
|
|
wds.dstSet = desc_set;
|
|
|
|
|
wds.dstBinding = binding;
|
|
|
|
|
wds.dstArrayElement = 0;
|
|
|
|
|
wds.descriptorCount = 1;
|
|
|
|
|
wds.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
|
|
|
|
|
wds.pImageInfo = nullptr;
|
|
|
|
|
wds.pBufferInfo = buf->GetBufferInfo();
|
|
|
|
|
wds.pTexelBufferView = nullptr;
|
2019-06-25 21:38:12 +08:00
|
|
|
|
|
2020-09-07 20:07:08 +08:00
|
|
|
|
wds_list.Add(wds);
|
2019-06-25 21:38:12 +08:00
|
|
|
|
return(true);
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-01 15:37:03 +08:00
|
|
|
|
bool DescriptorSets::BindUBODynamic(const int binding,const Buffer *buf)
|
2019-06-25 21:38:12 +08:00
|
|
|
|
{
|
2019-08-01 15:37:03 +08:00
|
|
|
|
if(binding<0||!buf)
|
|
|
|
|
return(false);
|
2020-09-27 20:58:25 +08:00
|
|
|
|
|
|
|
|
|
WriteDescriptorSet wds;
|
2019-08-01 15:37:03 +08:00
|
|
|
|
|
2020-09-07 20:07:08 +08:00
|
|
|
|
wds.dstSet = desc_set;
|
|
|
|
|
wds.dstBinding = binding;
|
|
|
|
|
wds.dstArrayElement = 0;
|
|
|
|
|
wds.descriptorCount = 1;
|
|
|
|
|
wds.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
|
|
|
|
|
wds.pImageInfo = nullptr;
|
|
|
|
|
wds.pBufferInfo = buf->GetBufferInfo();
|
|
|
|
|
wds.pTexelBufferView = nullptr;
|
2019-04-23 02:46:47 +08:00
|
|
|
|
|
2020-09-07 20:07:08 +08:00
|
|
|
|
wds_list.Add(wds);
|
2019-05-20 17:52:23 +08:00
|
|
|
|
return(true);
|
2019-04-19 00:46:49 +08:00
|
|
|
|
}
|
|
|
|
|
|
2019-08-01 15:37:03 +08:00
|
|
|
|
bool DescriptorSets::BindSampler(const int binding,Texture *tex,Sampler *sampler)
|
2019-04-19 00:46:49 +08:00
|
|
|
|
{
|
2019-08-01 15:37:03 +08:00
|
|
|
|
if(binding<0||!tex||!sampler)
|
2019-05-21 12:02:57 +08:00
|
|
|
|
return(false);
|
|
|
|
|
|
2019-07-10 18:04:50 +08:00
|
|
|
|
VkDescriptorImageInfo *image_info=new VkDescriptorImageInfo;
|
2019-07-06 16:46:19 +08:00
|
|
|
|
image_info->imageView =tex->GetVulkanImageView();
|
2019-07-17 17:18:46 +08:00
|
|
|
|
//image_info->imageLayout =tex->GetImageLayout();
|
|
|
|
|
image_info->imageLayout =VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
|
2019-05-21 12:02:57 +08:00
|
|
|
|
image_info->sampler =*sampler;
|
|
|
|
|
|
2019-07-10 18:04:50 +08:00
|
|
|
|
desc_image_info.Add(image_info);
|
2020-09-27 20:58:25 +08:00
|
|
|
|
|
|
|
|
|
WriteDescriptorSet wds;
|
2019-07-10 18:04:50 +08:00
|
|
|
|
|
2020-09-07 20:07:08 +08:00
|
|
|
|
wds.dstSet = desc_set;
|
|
|
|
|
wds.dstBinding = binding;
|
|
|
|
|
wds.dstArrayElement = 0;
|
|
|
|
|
wds.descriptorCount = 1;
|
|
|
|
|
wds.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
|
|
|
|
|
wds.pImageInfo = image_info;
|
|
|
|
|
wds.pBufferInfo = nullptr;
|
|
|
|
|
wds.pTexelBufferView = nullptr;
|
2019-04-23 02:46:47 +08:00
|
|
|
|
|
2020-09-07 20:07:08 +08:00
|
|
|
|
wds_list.Add(wds);
|
2019-05-05 21:30:55 +08:00
|
|
|
|
return(true);
|
2019-04-19 00:46:49 +08:00
|
|
|
|
}
|
2019-05-21 12:02:57 +08:00
|
|
|
|
|
|
|
|
|
void DescriptorSets::Update()
|
|
|
|
|
{
|
2020-09-19 23:49:32 +08:00
|
|
|
|
vkUpdateDescriptorSets(device,wds_list.GetCount(),wds_list.GetData(),0,nullptr);
|
2019-05-21 12:02:57 +08:00
|
|
|
|
}
|
2019-04-19 00:46:49 +08:00
|
|
|
|
VK_NAMESPACE_END
|