2019-04-30 16:42:59 +08:00
|
|
|
|
#include<hgl/graph/vulkan/VKDescriptorSets.h>
|
|
|
|
|
#include<hgl/graph/vulkan/VKDevice.h>
|
2019-07-06 16:46:19 +08:00
|
|
|
|
#include<hgl/graph/vulkan/VKBuffer.h>
|
2019-05-21 12:02:57 +08:00
|
|
|
|
#include<hgl/graph/vulkan/VKTexture.h>
|
|
|
|
|
#include<hgl/graph/vulkan/VKSampler.h>
|
2019-04-19 00:46:49 +08:00
|
|
|
|
|
|
|
|
|
VK_NAMESPACE_BEGIN
|
2019-05-21 12:02:57 +08:00
|
|
|
|
void DescriptorSets::Clear()
|
|
|
|
|
{
|
|
|
|
|
write_desc_sets.ClearData();
|
|
|
|
|
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);
|
|
|
|
|
|
2019-07-01 19:25:07 +08:00
|
|
|
|
VkWriteDescriptorSet writeDescriptorSet;
|
2019-04-19 00:46:49 +08:00
|
|
|
|
|
2019-07-01 19:25:07 +08:00
|
|
|
|
writeDescriptorSet.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
|
|
|
|
|
writeDescriptorSet.pNext = nullptr;
|
|
|
|
|
writeDescriptorSet.dstSet = desc_set;
|
|
|
|
|
writeDescriptorSet.dstBinding = binding;
|
|
|
|
|
writeDescriptorSet.dstArrayElement = 0;
|
|
|
|
|
writeDescriptorSet.descriptorCount = 1;
|
|
|
|
|
writeDescriptorSet.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
|
|
|
|
|
writeDescriptorSet.pImageInfo = nullptr;
|
2019-07-06 16:46:19 +08:00
|
|
|
|
writeDescriptorSet.pBufferInfo = buf->GetBufferInfo();
|
2019-07-01 19:25:07 +08:00
|
|
|
|
writeDescriptorSet.pTexelBufferView = nullptr;
|
2019-06-25 21:38:12 +08:00
|
|
|
|
|
|
|
|
|
write_desc_sets.Add(writeDescriptorSet);
|
|
|
|
|
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);
|
|
|
|
|
|
2019-07-01 19:25:07 +08:00
|
|
|
|
VkWriteDescriptorSet writeDescriptorSet;
|
2019-06-25 21:38:12 +08:00
|
|
|
|
|
2019-07-01 19:25:07 +08:00
|
|
|
|
writeDescriptorSet.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
|
|
|
|
|
writeDescriptorSet.pNext = nullptr;
|
|
|
|
|
writeDescriptorSet.dstSet = desc_set;
|
|
|
|
|
writeDescriptorSet.dstBinding = binding;
|
|
|
|
|
writeDescriptorSet.dstArrayElement = 0;
|
|
|
|
|
writeDescriptorSet.descriptorCount = 1;
|
|
|
|
|
writeDescriptorSet.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
|
|
|
|
|
writeDescriptorSet.pImageInfo = nullptr;
|
2019-12-04 21:05:09 +08:00
|
|
|
|
writeDescriptorSet.pBufferInfo = buf->GetBufferInfo();
|
2019-07-01 19:25:07 +08:00
|
|
|
|
writeDescriptorSet.pTexelBufferView = nullptr;
|
2019-04-23 02:46:47 +08:00
|
|
|
|
|
2019-05-21 12:02:57 +08:00
|
|
|
|
write_desc_sets.Add(writeDescriptorSet);
|
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);
|
|
|
|
|
|
2019-07-01 19:25:07 +08:00
|
|
|
|
VkWriteDescriptorSet writeDescriptorSet;
|
2019-04-28 16:06:53 +08:00
|
|
|
|
|
2019-12-27 19:31:42 +08:00
|
|
|
|
writeDescriptorSet.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
|
2019-07-01 19:25:07 +08:00
|
|
|
|
writeDescriptorSet.pNext = nullptr;
|
|
|
|
|
writeDescriptorSet.dstSet = desc_set;
|
|
|
|
|
writeDescriptorSet.dstBinding = binding;
|
|
|
|
|
writeDescriptorSet.dstArrayElement = 0;
|
|
|
|
|
writeDescriptorSet.descriptorCount = 1;
|
|
|
|
|
writeDescriptorSet.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
|
|
|
|
|
writeDescriptorSet.pImageInfo = image_info;
|
|
|
|
|
writeDescriptorSet.pBufferInfo = nullptr;
|
|
|
|
|
writeDescriptorSet.pTexelBufferView = nullptr;
|
2019-04-23 02:46:47 +08:00
|
|
|
|
|
2019-05-21 12:02:57 +08:00
|
|
|
|
write_desc_sets.Add(writeDescriptorSet);
|
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()
|
|
|
|
|
{
|
|
|
|
|
vkUpdateDescriptorSets(*device,write_desc_sets.GetCount(),write_desc_sets.GetData(),0,nullptr);
|
|
|
|
|
}
|
2019-04-19 00:46:49 +08:00
|
|
|
|
VK_NAMESPACE_END
|