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-07-06 16:46:19 +08:00
|
|
|
|
bool DescriptorSets::BindUBO(const uint32_t binding,const Buffer *buf)
|
2019-04-19 00:46:49 +08:00
|
|
|
|
{
|
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-07-06 16:46:19 +08:00
|
|
|
|
bool DescriptorSets::BindUBODynamic(const uint32_t binding,const Buffer *buf)
|
2019-06-25 21:38:12 +08:00
|
|
|
|
{
|
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-07-06 16:46:19 +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-05-21 12:02:57 +08:00
|
|
|
|
bool DescriptorSets::BindSampler(const uint32_t binding,Texture *tex,Sampler *sampler)
|
2019-04-19 00:46:49 +08:00
|
|
|
|
{
|
2019-05-21 12:02:57 +08:00
|
|
|
|
if(!tex||!sampler)
|
|
|
|
|
return(false);
|
|
|
|
|
|
|
|
|
|
VkDescriptorImageInfo *image_info=desc_image_info.Add();
|
2019-07-06 16:46:19 +08:00
|
|
|
|
image_info->imageView =tex->GetVulkanImageView();
|
|
|
|
|
image_info->imageLayout =tex->GetImageLayout();
|
2019-05-21 12:02:57 +08:00
|
|
|
|
image_info->sampler =*sampler;
|
|
|
|
|
|
2019-07-01 19:25:07 +08:00
|
|
|
|
VkWriteDescriptorSet writeDescriptorSet;
|
2019-04-28 16:06:53 +08:00
|
|
|
|
|
2019-05-05 21:30:55 +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
|