used DescriptorBinding in Global Binding
This commit is contained in:
parent
fefdc19674
commit
6c3e674d23
@ -60,7 +60,7 @@ private:
|
||||
if(!material_instance)
|
||||
return(false);
|
||||
|
||||
db->BindGlobalDescriptor(material_instance);
|
||||
db->BindGlobal(material_instance);
|
||||
|
||||
// pipeline=db->CreatePipeline(material_instance,sc_render_target,OS_TEXT("res/pipeline/solid2d"));
|
||||
pipeline=CreatePipeline(material_instance,InlinePipeline::Solid2D,Prim::Triangles); //等同上一行,为Framework重载,默认使用swapchain的render target
|
||||
|
@ -142,7 +142,7 @@ public:
|
||||
|
||||
ubo_vp_info=db->CreateUBO(sizeof(ViewportInfo),&vp_info);
|
||||
|
||||
db->SetGlobal(GlobalDescriptor::ViewportInfo.name,ubo_vp_info);
|
||||
db->AddGlobalUBO(GlobalDescriptor::ViewportInfo.name,ubo_vp_info);
|
||||
}
|
||||
|
||||
return(true);
|
||||
|
91
inc/hgl/graph/VKDescriptorBindingManage.h
Normal file
91
inc/hgl/graph/VKDescriptorBindingManage.h
Normal file
@ -0,0 +1,91 @@
|
||||
#ifndef HGL_GRAPH_DESCRIPTOR_BINDING_MANAGE_INCLUDE
|
||||
#define HGL_GRAPH_DESCRIPTOR_BINDING_MANAGE_INCLUDE
|
||||
|
||||
#include<hgl/type/Map.h>
|
||||
namespace hgl
|
||||
{
|
||||
namespace graph
|
||||
{
|
||||
class DeviceBuffer;
|
||||
class Texture;
|
||||
class MaterialParameters;
|
||||
|
||||
class DescriptorBinding
|
||||
{
|
||||
Map<AnsiString,DeviceBuffer *> ubo_map;
|
||||
Map<AnsiString,DeviceBuffer *> ssbo_map;
|
||||
Map<AnsiString,Texture *> texture_map;
|
||||
|
||||
public:
|
||||
|
||||
bool AddUBO(const AnsiString &name,DeviceBuffer *buf)
|
||||
{
|
||||
if(!buf)return(false);
|
||||
if(name.IsEmpty())return(false);
|
||||
|
||||
return ubo_map.Add(name,buf);
|
||||
}
|
||||
|
||||
DeviceBuffer *GetUBO(const AnsiString &name)
|
||||
{
|
||||
if(name.IsEmpty())return(nullptr);
|
||||
|
||||
return GetListObject(ubo_map,name);
|
||||
}
|
||||
|
||||
void RemoveUBO(DeviceBuffer *buf)
|
||||
{
|
||||
if(!buf)return;
|
||||
|
||||
ubo_map.DeleteByValue(buf);
|
||||
}
|
||||
|
||||
bool AddSSBO(const AnsiString &name,DeviceBuffer *buf)
|
||||
{
|
||||
if(!buf)return(false);
|
||||
if(name.IsEmpty())return(false);
|
||||
|
||||
return ssbo_map.Add(name,buf);
|
||||
}
|
||||
|
||||
DeviceBuffer *GetSSBO(const AnsiString &name)
|
||||
{
|
||||
if(name.IsEmpty())return(nullptr);
|
||||
|
||||
return GetListObject(ssbo_map,name);
|
||||
}
|
||||
|
||||
void RemoveSSBO(DeviceBuffer *buf)
|
||||
{
|
||||
if(!buf)return;
|
||||
|
||||
ssbo_map.DeleteByValue(buf);
|
||||
}
|
||||
|
||||
bool AddTexture(const AnsiString &name,Texture *tex)
|
||||
{
|
||||
if(!tex)return(false);
|
||||
if(name.IsEmpty())return(false);
|
||||
|
||||
return texture_map.Add(name,tex);
|
||||
}
|
||||
|
||||
Texture *GetTexture(const AnsiString &name)
|
||||
{
|
||||
if(name.IsEmpty())return(nullptr);
|
||||
|
||||
return GetListObject(texture_map,name);
|
||||
}
|
||||
|
||||
void RemoveTexture(Texture *tex)
|
||||
{
|
||||
if(!tex)return;
|
||||
|
||||
texture_map.DeleteByValue(tex);
|
||||
}
|
||||
|
||||
bool Bind(MaterialParameters *);
|
||||
};//class DescriptorBinding
|
||||
}//namespace graph
|
||||
}//namespace hgl
|
||||
#endif//HGL_GRAPH_DESCRIPTOR_BINDING_MANAGE_INCLUDE
|
@ -15,6 +15,8 @@
|
||||
#include<hgl/graph/font/TextPrimitive.h>
|
||||
#include<hgl/type/ResManage.h>
|
||||
#include<hgl/shadergen/MaterialCreateInfo.h>
|
||||
#include<hgl/graph/VKDescriptorBindingManage.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
using MaterialID =int;
|
||||
using MaterialInstanceID =int;
|
||||
@ -47,8 +49,7 @@ class RenderResource
|
||||
IDResManage<TextureID, Texture> rm_textures; ///<纹理合集
|
||||
IDResManage<RenderableID, Renderable> rm_renderables; ///<渲染实例集合集
|
||||
|
||||
Map<AnsiString,DeviceBuffer *> global_buffer_map; ///<全局Buffer(UBO/SSBO)
|
||||
Map<AnsiString,Texture *> global_texture_map; ///<全局Texture
|
||||
DescriptorBinding global_binding; ///<全局属性描述符绑定管理
|
||||
|
||||
public:
|
||||
|
||||
@ -68,13 +69,10 @@ public: //Add
|
||||
|
||||
public: //全局属性(对应shader中的PerGlobal set合集)
|
||||
|
||||
void SetGlobal(const AnsiString &name,DeviceBuffer *buf);
|
||||
void AddGlobalUBO(const AnsiString &name,DeviceBuffer *buf){global_binding.AddUBO(name,buf);}
|
||||
void AddGlobalSSBO(const AnsiString &name,DeviceBuffer *buf){global_binding.AddSSBO(name,buf);}
|
||||
|
||||
DeviceBuffer *GetGlobal(const AnsiString &name);
|
||||
|
||||
void Free(DeviceBuffer *);
|
||||
|
||||
void BindGlobalDescriptor(MaterialInstance *);
|
||||
bool BindGlobal(MaterialInstance *mi){return global_binding.Bind(mi->GetMP(DescriptorSetType::Global));}
|
||||
|
||||
public: // VBO/VAO
|
||||
|
||||
|
@ -184,6 +184,8 @@ SET(VK_TEXTURE_SOURCE ${SG_INCLUDE_PATH}/VKImageView.h
|
||||
SET(VK_MATERIAL_SOURCE ${SG_INCLUDE_PATH}/VKMaterial.h
|
||||
${SG_INCLUDE_PATH}/VKMaterialParameters.h
|
||||
${SG_INCLUDE_PATH}/VKMaterialInstance.h
|
||||
${SG_INCLUDE_PATH}/VKDescriptorBindingManage.h
|
||||
Vulkan/VKDescriptorBindingManage.cpp
|
||||
Vulkan/VKMaterial.cpp
|
||||
Vulkan/VKMaterialParameters.cpp
|
||||
Vulkan/VKMaterialInstance.cpp)
|
||||
|
44
src/SceneGraph/Vulkan/VKDescriptorBindingManage.cpp
Normal file
44
src/SceneGraph/Vulkan/VKDescriptorBindingManage.cpp
Normal file
@ -0,0 +1,44 @@
|
||||
#include<hgl/graph/VKDescriptorBindingManage.h>
|
||||
#include<hgl/graph/VKMaterialParameters.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
bool DescriptorBinding::Bind(MaterialParameters *mp)
|
||||
{
|
||||
if(!mp)return(false);
|
||||
|
||||
{
|
||||
const auto *dp=ubo_map.GetDataList();
|
||||
|
||||
for(uint i=0;i<ubo_map.GetCount();i++)
|
||||
{
|
||||
mp->BindUBO((*dp)->left,(*dp)->right);
|
||||
|
||||
++dp;
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
const auto *dp=ssbo_map.GetDataList();
|
||||
|
||||
for(uint i=0;i<ssbo_map.GetCount();i++)
|
||||
{
|
||||
mp->BindSSBO((*dp)->left,(*dp)->right);
|
||||
|
||||
++dp;
|
||||
}
|
||||
}
|
||||
|
||||
//{
|
||||
// const auto *dp=texture_map.GetDataList();
|
||||
|
||||
// for(uint i=0;i<texture_map.GetCount();i++)
|
||||
// {
|
||||
// mp->BindImageSampler((*dp)->left,(*dp)->right);
|
||||
|
||||
// ++dp;
|
||||
// }
|
||||
//}
|
||||
|
||||
mp->Update();
|
||||
}
|
||||
VK_NAMESPACE_END
|
@ -5,61 +5,6 @@
|
||||
#include<hgl/graph/VKVertexAttribBuffer.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
void RenderResource::SetGlobal(const AnsiString &name,DeviceBuffer *buf)
|
||||
{
|
||||
if(!buf)return;
|
||||
if(name.IsEmpty())return;
|
||||
|
||||
global_buffer_map.Add(name,buf);
|
||||
}
|
||||
|
||||
DeviceBuffer *RenderResource::GetGlobal(const AnsiString &name)
|
||||
{
|
||||
if(name.IsEmpty())return(nullptr);
|
||||
|
||||
DeviceBuffer *buf;
|
||||
|
||||
if(global_buffer_map.Get(name,buf))
|
||||
return buf;
|
||||
else
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void RenderResource::Free(DeviceBuffer *buf)
|
||||
{
|
||||
rm_buffers.Release(buf);
|
||||
|
||||
global_buffer_map.DeleteByValue(buf);
|
||||
}
|
||||
|
||||
void RenderResource::BindGlobalDescriptor(MaterialInstance *mi)
|
||||
{
|
||||
if(!mi)return;
|
||||
|
||||
const uint count=global_buffer_map.GetCount();
|
||||
|
||||
if(count<=0)return;
|
||||
|
||||
auto **gb_list=global_buffer_map.GetDataList();
|
||||
|
||||
auto *mp=mi->GetMP(DescriptorSetType::Global);
|
||||
|
||||
if(!mp)
|
||||
return;
|
||||
|
||||
if(mp->GetDescriptorCount()<=0)
|
||||
return;
|
||||
|
||||
for(uint i=0;i<count;i++)
|
||||
{
|
||||
mp->BindUBO((*gb_list)->left,(*gb_list)->right);
|
||||
|
||||
++gb_list;
|
||||
}
|
||||
|
||||
mp->Update();
|
||||
}
|
||||
|
||||
VBO *RenderResource::CreateVBO(VkFormat format,uint32_t count,const void *data,SharingMode sharing_mode)
|
||||
{
|
||||
VBO *vb=device->CreateVBO(format,count,data,sharing_mode);
|
||||
|
Loading…
x
Reference in New Issue
Block a user