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
|
2020-10-29 16:50:19 +08:00
|
|
|
|
namespace
|
|
|
|
|
{
|
|
|
|
|
struct WriteDescriptorSet:public vkstruct<VkWriteDescriptorSet,VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET>
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
|
|
WriteDescriptorSet(VkDescriptorSet desc_set,const uint32_t binding,const VkDescriptorType desc_type)
|
|
|
|
|
{
|
|
|
|
|
dstSet = desc_set;
|
|
|
|
|
dstBinding = binding;
|
|
|
|
|
dstArrayElement = 0;
|
|
|
|
|
descriptorCount = 1;
|
|
|
|
|
descriptorType = desc_type;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
WriteDescriptorSet(VkDescriptorSet desc_set,const uint32_t binding,const VkDescriptorBufferInfo *buf_info,const VkDescriptorType desc_type=VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER):WriteDescriptorSet(desc_set,binding,desc_type)
|
|
|
|
|
{
|
|
|
|
|
pImageInfo = nullptr;
|
|
|
|
|
pBufferInfo = buf_info;
|
|
|
|
|
pTexelBufferView = nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
WriteDescriptorSet(VkDescriptorSet desc_set,const uint32_t binding,const VkDescriptorImageInfo *img_info):WriteDescriptorSet(desc_set,binding,VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER)
|
|
|
|
|
{
|
|
|
|
|
pImageInfo = img_info;
|
|
|
|
|
pBufferInfo = nullptr;
|
|
|
|
|
pTexelBufferView= nullptr;
|
|
|
|
|
}
|
|
|
|
|
};//struct WriteDescriptorSet
|
|
|
|
|
}//namespace
|
|
|
|
|
|
2019-05-21 12:02:57 +08:00
|
|
|
|
void DescriptorSets::Clear()
|
|
|
|
|
{
|
2020-10-29 16:50:19 +08:00
|
|
|
|
buffer_list.ClearData();
|
|
|
|
|
image_list.ClearData();
|
2020-09-07 20:07:08 +08:00
|
|
|
|
wds_list.ClearData();
|
2019-05-21 12:02:57 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-10-21 12:09:15 +08:00
|
|
|
|
bool DescriptorSets::BindUBO(const int binding,const GPUBuffer *buf)
|
2019-04-19 00:46:49 +08:00
|
|
|
|
{
|
2019-08-01 15:37:03 +08:00
|
|
|
|
if(binding<0||!buf)
|
|
|
|
|
return(false);
|
|
|
|
|
|
2020-10-29 16:50:19 +08:00
|
|
|
|
WriteDescriptorSet wds(desc_set,binding,buf->GetBufferInfo());
|
2019-04-19 00:46:49 +08:00
|
|
|
|
|
2020-10-29 16:50:19 +08:00
|
|
|
|
wds_list.Add(wds);
|
|
|
|
|
return(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool DescriptorSets::BindUBO(const int binding,const GPUBuffer *buf,const VkDeviceSize offset,const VkDeviceSize range)
|
|
|
|
|
{
|
|
|
|
|
if(binding<0||!buf)
|
|
|
|
|
return(false);
|
|
|
|
|
|
|
|
|
|
VkDescriptorBufferInfo *buf_info=new VkDescriptorBufferInfo;
|
|
|
|
|
|
|
|
|
|
buf_info->buffer=buf->GetBuffer();
|
|
|
|
|
buf_info->offset=offset;
|
|
|
|
|
buf_info->range=range;
|
|
|
|
|
|
|
|
|
|
buffer_list.Add(buf_info);
|
|
|
|
|
|
|
|
|
|
WriteDescriptorSet wds(desc_set,binding,buf_info);
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-21 12:09:15 +08:00
|
|
|
|
bool DescriptorSets::BindUBODynamic(const int binding,const GPUBuffer *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
|
|
|
|
|
2020-10-29 16:50:19 +08:00
|
|
|
|
WriteDescriptorSet wds(desc_set,binding,buf->GetBufferInfo(),VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC);
|
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;
|
2020-10-29 16:50:19 +08:00
|
|
|
|
|
2019-07-06 16:46:19 +08:00
|
|
|
|
image_info->imageView =tex->GetVulkanImageView();
|
2020-10-29 16:50:19 +08:00
|
|
|
|
// image_info.imageLayout =tex->GetImageLayout();
|
2019-07-17 17:18:46 +08:00
|
|
|
|
image_info->imageLayout =VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
|
2019-05-21 12:02:57 +08:00
|
|
|
|
image_info->sampler =*sampler;
|
|
|
|
|
|
2020-10-29 16:50:19 +08:00
|
|
|
|
image_list.Add(image_info);
|
|
|
|
|
|
|
|
|
|
WriteDescriptorSet wds(desc_set,binding,image_info);
|
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
|