This commit is contained in:
hyzboy 2025-01-08 13:26:27 +08:00
parent 5738837008
commit 76103a869b
10 changed files with 58 additions and 52 deletions

@ -1 +1 @@
Subproject commit 878335ba9c4159d558f41c47783447092e0602c9
Subproject commit 0fae462338cd01c5a26d0a8f0175fe3729a65c94

2
CMCore

@ -1 +1 @@
Subproject commit 77a3a9d26e0f3b38c8d8b46b24aff22b1738d10e
Subproject commit 8c86a153ebe97bb03a6abf4bb7c0ac7bebb8eb4f

2
CMUtil

@ -1 +1 @@
Subproject commit f330a6672e9b3124e83ce527d2db747b6ee3226b
Subproject commit 57ff3a70c99265ed7bb97b3b6840709e84bac0c1

View File

@ -19,6 +19,8 @@ struct GraphModulesMap
Map<AnsiIDName,GraphModule *> gm_map_by_name;
Map<size_t,GraphModule *> gm_map_by_hash;
List<GraphModule *> gm_list; //按创建顺序记录,用于倒序释放
public:
bool Add(GraphModule *gm);
@ -50,6 +52,10 @@ public:
template<typename T>
const bool IsLoaded()const{return gm_map_by_hash.ContainsKey(T::GetTypeHash());}
bool Release(GraphModule *gm);
void Destory();
};
class GraphModuleManager
@ -99,17 +105,16 @@ class GraphModule:public Comparator<GraphModule>
AnsiIDName module_name;
bool module_inited_dependent;
bool module_inited;
bool module_enabled;
bool module_ready;
protected:
//GraphModule *GetModule(const AnsiIDName &name){return module_manager->GetModule(name,true);} ///<获取指定名称的模块
GraphModule *GetModule(const AnsiIDName &name){return module_manager->GetModule(name,false);} ///<获取指定名称的模块
//template<typename T>
//T *GetModule(){return (T *)GetModule(T::GetModuleName());} ///<获取指定类型的模块
template<typename T>
T *GetModule(){return module_manager->GetModule<T>();} ///<获取指定类型的模块
protected:
@ -132,7 +137,6 @@ public:
virtual const bool IsPerFrame () {return false;} ///<是否每帧运行
virtual const bool IsRender () {return false;} ///<是否为渲染模块
const bool IsInitedDependent ()const {return module_inited_dependent;} ///<是否已经初始化依赖的模块
const bool IsInited ()const {return module_inited;} ///<是否已经初始化
const bool IsEnabled ()const noexcept{return module_enabled;} ///<当前模块是否启用
const bool IsReady ()const noexcept{return module_ready;} ///<当前模块是否准备好
@ -146,11 +150,6 @@ public:
virtual const size_t GetTypeHash()const=0;
/**
* new之前就获取的
*/
virtual bool InitDependentModules(GraphModulesMap &){module_inited_dependent=true;return true;} ///<初始化依赖的模块
virtual bool Init()=0; ///<初始化当前模块
static const char **GetDependentModules(){return nullptr;} ///<取得依赖的模块列表

View File

@ -1,12 +1,11 @@
#pragma once
#include<hgl/graph/VKNamespace.h>
#include<hgl/type/IDName.h>
#include<hgl/graph/module/GraphModule.h>
VK_NAMESPACE_BEGIN
class GraphModule;
class GraphModuleManager;
class GraphModuleFactory
{
public:
@ -50,12 +49,6 @@ public:
GraphModule *gm=new T(gmm);
if(!gm->InitDependentModules(dgm))
{
delete gm;
return(nullptr);
}
if(!gm->Init())
{
delete gm;

View File

@ -32,8 +32,6 @@ public:
GRAPH_MODULE_CONSTRUCT(SwapchainModule)
virtual ~SwapchainModule();
bool InitDependentModules(GraphModulesMap &) override;
bool Init() override;
bool BeginFrame();

2
res

@ -1 +1 @@
Subproject commit e1a36d78f0eead5f6bb65493432c4690637b991d
Subproject commit 475d8ad43ceee084cd24f5d0bed59de9f6aa36fd

View File

@ -12,9 +12,46 @@ bool GraphModulesMap::Add(GraphModule *gm)
if(gm_set.Contains(gm))
return(false);
gm_list.Add(gm);
gm_set.Add(gm);
gm_map_by_name.Add(gm->GetName(),gm);
gm_map_by_hash.Add(gm->GetTypeHash(),gm);
}
void GraphModulesMap::Destory()
{
//按顺序加入module_list的要倒着释放
auto *m=gm_list.last();
auto *begin=gm_list.begin();
while(m>=begin)
{
delete m;
--m;
}
gm_list.Clear();
gm_set.Clear();
gm_map_by_name.Clear();
gm_map_by_hash.Clear();
}
bool GraphModulesMap::Release(GraphModule *gm)
{
if(!gm)
return(false);
if(!gm_set.Contains(gm))
return(false);
//因为总计就没几个数据,所以无序关心效能
gm_set.Delete(gm);
gm_list.DeleteByValue(gm);
gm_map_by_name.DeleteByValue(gm);
gm_map_by_hash.DeleteByValue(gm);
return(true);
}
GraphModule::GraphModule(GraphModuleManager *gmm,const AnsiIDName &name)

View File

@ -109,19 +109,7 @@ GraphModuleManager::GraphModuleManager(RenderFramework *rf)
GraphModuleManager::~GraphModuleManager()
{
//按顺序加入module_list的要倒着释放
GraphModule **gm=module_list.end();
while(gm>module_list.begin())
{
--gm;
delete *gm;
}
//其实下面释不释放都无所谓了
module_list.Clear();
graph_module_map.Clear();
graph_module_map.Destory();
}
void GraphModuleManager::ReleaseModule(GraphModule *gm)
@ -129,8 +117,7 @@ void GraphModuleManager::ReleaseModule(GraphModule *gm)
if(!gm)
return;
graph_module_map.DeleteByValue(gm);
delete gm;
graph_module_map.Release(gm);
}
void GraphModuleManager::OnResize(const VkExtent2D &extent)
@ -138,9 +125,9 @@ void GraphModuleManager::OnResize(const VkExtent2D &extent)
if(graph_module_map.IsEmpty())
return;
for(auto *gm:graph_module_map)
for(auto *gm:graph_module_map.gm_list)
{
gm->value->OnResize(extent);
gm->OnResize(extent);
}
}

View File

@ -230,7 +230,7 @@ SwapchainModule::~SwapchainModule()
delete swapchain;
}
bool SwapchainModule::InitDependentModules(GraphModulesMap &dep_gmm)
bool SwapchainModule::Init()
{
RenderPassManager *rp_manager=dep_gmm.Get<RenderPassManager>();
@ -240,18 +240,10 @@ bool SwapchainModule::InitDependentModules(GraphModulesMap &dep_gmm)
SwapchainRenderbufferInfo rbi(swapchain->surface_format.format,swapchain->depth_format);
swapchain_rp=rp_manager->AcquireRenderPass(&rbi);
}
bool SwapchainModule::Init()
{
if(!CreateSwapchain())
return(false);
RenderPassManager *rpm=GetModule<RenderPassManager>();
if(!rpm)
return(false);
//#ifdef _DEBUG
// if(dev_attr->debug_utils)
// dev_attr->debug_utils->SetRenderPass(swapchain_rp->GetVkRenderPass(),"SwapchainRenderPass");