DescriptorSets多次update合并为一次
This commit is contained in:
parent
214079653e
commit
220a6798d2
@ -89,7 +89,11 @@ private:
|
||||
if(!ubo_mvp)
|
||||
return(false);
|
||||
|
||||
return desciptor_sets->UpdateUBO(material->GetUBO("world"),*ubo_mvp);
|
||||
if(!desciptor_sets->BindUBO(material->GetUBO("world"),*ubo_mvp))
|
||||
return(false);
|
||||
|
||||
desciptor_sets->Update();
|
||||
return(true);
|
||||
}
|
||||
|
||||
void InitVBO()
|
||||
|
@ -90,7 +90,11 @@ private:
|
||||
if(!ubo_mvp)
|
||||
return(false);
|
||||
|
||||
return desciptor_sets->UpdateUBO(material->GetUBO("world"),*ubo_mvp); //material中这里可以改成不区分类型,返回的值包含类型和ID,这样descriptor_sets->Update也不再需要类型
|
||||
if(!desciptor_sets->BindUBO(material->GetUBO("world"),*ubo_mvp))
|
||||
return(false);
|
||||
|
||||
desciptor_sets->Update();
|
||||
return(true);
|
||||
}
|
||||
|
||||
void InitVBO()
|
||||
|
@ -13,8 +13,8 @@ VK_NAMESPACE_BEGIN
|
||||
Texture2D *LoadTGATexture(const OSString &filename,Device *device);
|
||||
VK_NAMESPACE_END
|
||||
|
||||
constexpr uint32_t SCREEN_WIDTH=512;
|
||||
constexpr uint32_t SCREEN_HEIGHT=512;
|
||||
constexpr uint32_t SCREEN_WIDTH=128;
|
||||
constexpr uint32_t SCREEN_HEIGHT=128;
|
||||
|
||||
struct WorldConfig
|
||||
{
|
||||
@ -113,12 +113,10 @@ private:
|
||||
|
||||
sampler=device->CreateSampler(&sampler_create_info);
|
||||
|
||||
VkDescriptorImageInfo image_info;
|
||||
image_info.imageView =*texture;
|
||||
image_info.imageLayout =*texture;
|
||||
image_info.sampler =*sampler;
|
||||
desciptor_sets->BindSampler(material->GetSampler("texture_lena"),texture,sampler);
|
||||
desciptor_sets->BindUBO(material->GetUBO("world"),*ubo_mvp);
|
||||
desciptor_sets->Update();
|
||||
|
||||
desciptor_sets->UpdateSampler(material->GetSampler("texture_lena"),&image_info);
|
||||
return(true);
|
||||
}
|
||||
|
||||
@ -130,10 +128,7 @@ private:
|
||||
|
||||
ubo_mvp=device->CreateUBO(sizeof(WorldConfig),&world);
|
||||
|
||||
if(!ubo_mvp)
|
||||
return(false);
|
||||
|
||||
return desciptor_sets->UpdateUBO(material->GetUBO("world"),*ubo_mvp);
|
||||
return ubo_mvp;
|
||||
}
|
||||
|
||||
void InitVBO()
|
||||
@ -197,10 +192,10 @@ public:
|
||||
|
||||
swap_chain_count=device->GetSwapChainImageCount();
|
||||
|
||||
if(!InitMaterial())
|
||||
if(!InitUBO())
|
||||
return(false);
|
||||
|
||||
if(!InitUBO())
|
||||
if(!InitMaterial())
|
||||
return(false);
|
||||
|
||||
InitVBO();
|
||||
|
@ -19,6 +19,7 @@ class Device;
|
||||
class ImageView;
|
||||
class Framebuffer;
|
||||
|
||||
class Texture;
|
||||
class Texture1D;
|
||||
class Texture1DArray;
|
||||
class Texture2D;
|
||||
|
@ -15,6 +15,9 @@ class DescriptorSets
|
||||
|
||||
VkPipelineLayout pipeline_layout;
|
||||
|
||||
List<VkDescriptorImageInfo> desc_image_info;
|
||||
List<VkWriteDescriptorSet> write_desc_sets;
|
||||
|
||||
private:
|
||||
|
||||
friend class DescriptorSetLayoutCreater;
|
||||
@ -35,11 +38,10 @@ public:
|
||||
const VkDescriptorSet * GetDescriptorSets ()const{return &desc_set;}
|
||||
const VkPipelineLayout GetPipelineLayout ()const{return pipeline_layout;}
|
||||
|
||||
//未来统合所有的write descriptor sets,这里的update改为只是添加记录
|
||||
//最终bind到cmd时一次性写入。
|
||||
|
||||
bool UpdateUBO(const uint32_t binding,const VkDescriptorBufferInfo *);
|
||||
bool UpdateSampler(const uint32_t binding,const VkDescriptorImageInfo *);
|
||||
void Clear();
|
||||
bool BindUBO(const uint32_t binding,const VkDescriptorBufferInfo *);
|
||||
bool BindSampler(const uint32_t binding,Texture *,Sampler *);
|
||||
void Update();
|
||||
};//class DescriptorSets
|
||||
VK_NAMESPACE_END
|
||||
#endif//HGL_GRAPH_VULKAN_DESCRIPTOR_SETS_LAYOUT_INCLUDE
|
||||
|
@ -1,8 +1,16 @@
|
||||
#include<hgl/graph/vulkan/VKDescriptorSets.h>
|
||||
#include<hgl/graph/vulkan/VKDevice.h>
|
||||
#include<hgl/graph/vulkan/VKTexture.h>
|
||||
#include<hgl/graph/vulkan/VKSampler.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
bool DescriptorSets::UpdateUBO(const uint32_t binding,const VkDescriptorBufferInfo *buf_info)
|
||||
void DescriptorSets::Clear()
|
||||
{
|
||||
write_desc_sets.ClearData();
|
||||
desc_image_info.ClearData();
|
||||
}
|
||||
|
||||
bool DescriptorSets::BindUBO(const uint32_t binding,const VkDescriptorBufferInfo *buf_info)
|
||||
{
|
||||
VkWriteDescriptorSet writeDescriptorSet = {};
|
||||
|
||||
@ -13,12 +21,20 @@ bool DescriptorSets::UpdateUBO(const uint32_t binding,const VkDescriptorBufferIn
|
||||
writeDescriptorSet.pBufferInfo = buf_info;
|
||||
writeDescriptorSet.dstBinding = binding;
|
||||
|
||||
vkUpdateDescriptorSets(*device,1,&writeDescriptorSet,0,nullptr);
|
||||
write_desc_sets.Add(writeDescriptorSet);
|
||||
return(true);
|
||||
}
|
||||
|
||||
bool DescriptorSets::UpdateSampler(const uint32_t binding,const VkDescriptorImageInfo *image_info)
|
||||
bool DescriptorSets::BindSampler(const uint32_t binding,Texture *tex,Sampler *sampler)
|
||||
{
|
||||
if(!tex||!sampler)
|
||||
return(false);
|
||||
|
||||
VkDescriptorImageInfo *image_info=desc_image_info.Add();
|
||||
image_info->imageView =*tex;
|
||||
image_info->imageLayout =*tex;
|
||||
image_info->sampler =*sampler;
|
||||
|
||||
VkWriteDescriptorSet writeDescriptorSet = {};
|
||||
|
||||
writeDescriptorSet.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
|
||||
@ -28,7 +44,12 @@ bool DescriptorSets::UpdateSampler(const uint32_t binding,const VkDescriptorImag
|
||||
writeDescriptorSet.pImageInfo = image_info;
|
||||
writeDescriptorSet.dstBinding = binding;
|
||||
|
||||
vkUpdateDescriptorSets(*device,1,&writeDescriptorSet,0,nullptr);
|
||||
write_desc_sets.Add(writeDescriptorSet);
|
||||
return(true);
|
||||
}
|
||||
|
||||
void DescriptorSets::Update()
|
||||
{
|
||||
vkUpdateDescriptorSets(*device,write_desc_sets.GetCount(),write_desc_sets.GetData(),0,nullptr);
|
||||
}
|
||||
VK_NAMESPACE_END
|
||||
|
Loading…
x
Reference in New Issue
Block a user