From baa2e758f2ded2ea449951735b9633b71861886b Mon Sep 17 00:00:00 2001 From: hyzboy Date: Thu, 9 Jan 2025 00:48:15 +0800 Subject: [PATCH] [WIP] --- inc/hgl/graph/RenderFramework.h | 56 +++--- inc/hgl/graph/manager/RenderPassManager.h | 2 - inc/hgl/graph/manager/TextureManager.h | 8 +- inc/hgl/graph/module/GraphModule.h | 187 +++++-------------- inc/hgl/graph/module/GraphModuleFactory.h | 17 +- inc/hgl/graph/module/GraphModuleMap.h | 56 ++++++ inc/hgl/graph/module/SwapchainModule.h | 3 +- res | 2 +- src/SceneGraph/CMakeLists.txt | 2 +- src/SceneGraph/RenderFramework.cpp | 46 ++++- src/SceneGraph/manager/TextureManager.cpp | 21 +-- src/SceneGraph/module/GraphModule.cpp | 10 +- src/SceneGraph/module/GraphModuleFactory.cpp | 6 +- src/SceneGraph/module/GraphModuleManager.cpp | 134 ------------- 14 files changed, 211 insertions(+), 339 deletions(-) create mode 100644 inc/hgl/graph/module/GraphModuleMap.h delete mode 100644 src/SceneGraph/module/GraphModuleManager.cpp diff --git a/inc/hgl/graph/RenderFramework.h b/inc/hgl/graph/RenderFramework.h index 8e1f3916..fc94814c 100644 --- a/inc/hgl/graph/RenderFramework.h +++ b/inc/hgl/graph/RenderFramework.h @@ -1,10 +1,11 @@ #pragma once -#include #include +#include +#include #include -#include -#include +#include +#include VK_NAMESPACE_BEGIN @@ -34,9 +35,7 @@ protected: protected: - GraphModuleManager *graph_module_manager=nullptr; - - ObjectList module_list; + GraphModulesMap graph_module_map; List per_frame_module_list; List render_module_list; @@ -59,35 +58,39 @@ private: double last_time =0; double cur_time =0; - uint64 frame_count =0; + int64 frame_count =0; public: - const uint64 GetFrameCount ()const noexcept{return frame_count;} ///<取得当前帧数 + const int64 GetFrameCount ()const noexcept{return frame_count;} ///<取得当前帧数 void RestartFrameCount ()noexcept{frame_count=0;} ///<重新开始统计帧数 public: //module - template T *GetModule(){return graph_module_manager->GetModule(false);} ///<获取指定类型的模块 + template + T * GetModule(){return graph_module_map.Get();} ///<获取指定类型的模块 + GraphModule * GetModule(const AnsiIDName &name,bool create=false); ///<获取指定名称的模块 - template T *AddModule() - { - T *tm=new T(graph_module_manager); + //template T *AddModule() + //{ + // T *tm=new T(graph_module_manager); - module_list.Add(tm); + // module_list.Add(tm); - if(tm->IsPerFrame()) - per_frame_module_list.Add(tm); + // if(tm->IsPerFrame()) + // per_frame_module_list.Add(tm); - if(tm->IsRender()) - render_module_list.Add(tm); + // if(tm->IsRender()) + // render_module_list.Add(tm); - return tm; - } + // return tm; + //} - GPUDevice * GetDevice (){return device;} - VkDevice GetVkDevice (){return device->GetDevice();} - SwapchainModule * GetSwapchain(){return swapchain_module;} ///<取得Swapchain模块 + GPUDevice * GetDevice () {return device;} + VkDevice GetVkDevice ()const {return device->GetDevice();} + const GPUPhysicalDevice * GetPhysicalDevice ()const {return device->GetPhysicalDevice();} ///<取得物理设备 + GPUDeviceAttribute *GetDeviceAttribute () {return device->GetDeviceAttribute();} ///<取得设备属性 + SwapchainModule * GetSwapchain () {return swapchain_module;} ///<取得Swapchain模块 public: //manager @@ -104,7 +107,14 @@ public: NO_COPY_NO_MOVE(RenderFramework) +private: + RenderFramework(); + + friend RenderFramework *CreateRenderFramework(); + +public: + virtual ~RenderFramework(); virtual bool Init(uint w,uint h,const OSString &app_name); ///<初始化 @@ -130,4 +140,6 @@ public: //TileData TileFont *CreateTileFont(FontSource *fs,int limit_count=-1); ///<创建一个Tile字体 };//class RenderFramework +RenderFramework *CreateRenderFramework(); + VK_NAMESPACE_END diff --git a/inc/hgl/graph/manager/RenderPassManager.h b/inc/hgl/graph/manager/RenderPassManager.h index ade8c1d5..53c60b6d 100644 --- a/inc/hgl/graph/manager/RenderPassManager.h +++ b/inc/hgl/graph/manager/RenderPassManager.h @@ -26,8 +26,6 @@ private: GRAPH_MODULE_CONSTRUCT(RenderPassManager) ~RenderPassManager(); - bool Init() override; - private: RenderPass * CreateRenderPass( const List &desc_list, diff --git a/inc/hgl/graph/manager/TextureManager.h b/inc/hgl/graph/manager/TextureManager.h index 64dbb752..c9fe6aae 100644 --- a/inc/hgl/graph/manager/TextureManager.h +++ b/inc/hgl/graph/manager/TextureManager.h @@ -10,6 +10,10 @@ VK_NAMESPACE_BEGIN +struct TextureManagerData +{ +}; + class TextureManager:public GraphModule { DeviceQueue *texture_queue=nullptr; @@ -40,10 +44,6 @@ public: GRAPH_MODULE_CONSTRUCT(TextureManager) virtual ~TextureManager(); - static const char **GetDependentModules(); - - bool Init() override; - const VkFormatProperties GetFormatProperties(const VkFormat)const; public: //Buffer diff --git a/inc/hgl/graph/module/GraphModule.h b/inc/hgl/graph/module/GraphModule.h index df0e4ef9..0293be23 100644 --- a/inc/hgl/graph/module/GraphModule.h +++ b/inc/hgl/graph/module/GraphModule.h @@ -1,107 +1,19 @@ #pragma once -#include -#include -#include -#include +#include +#include VK_NAMESPACE_BEGIN class RenderCmdBuffer; -class GraphModule; class RenderFramework; -struct GraphModulesMap +using GraphModuleHashList=std::initializer_list; + +class GraphModule { - SortedSet gm_set; - - Map gm_map_by_name; - Map gm_map_by_hash; - - List gm_list; //按创建顺序记录,用于倒序释放 - -public: - - bool Add(GraphModule *gm); - - const bool IsEmpty()const - { - return gm_set.IsEmpty(); - } - - GraphModule *Get(const AnsiIDName &name)const - { - GraphModule *gm; - - if(gm_map_by_name.Get(name,gm)) - return gm; - - return nullptr; - } - - template - T *Get()const - { - GraphModule *gm; - - return gm_map_by_hash.Get(GetTypeHash(),gm)?(T *)gm:nullptr; - } - - const bool IsLoaded(const AnsiIDName &name)const{return gm_map_by_name.ContainsKey(name);} - - template - const bool IsLoaded()const{return gm_map_by_hash.ContainsKey(T::GetTypeHash());} - - bool Release(GraphModule *gm); - - void Destory(); -}; - -class GraphModuleManager -{ - GPUDevice *device; - RenderFramework *framework; - - GraphModulesMap graph_module_map; ///<模块映射表 - -public: - - GraphModuleManager(RenderFramework *); - virtual ~GraphModuleManager(); - - GPUDevice * GetDevice ()noexcept {return device;} ///<取得GPU设备 - VkDevice GetVkDevice ()const {return device->GetDevice();} - const GPUPhysicalDevice * GetPhysicalDevice ()const {return device->GetPhysicalDevice();} ///<取得物理设备 - GPUDeviceAttribute *GetDeviceAttribute () {return device->GetDeviceAttribute();} ///<取得设备属性 - - RenderFramework * GetFramework () {return framework;} ///<取得渲染框架 - - /** - * 获取指定名称的模块 - * @param create 如果不存在,是否创建新的 - */ - GraphModule *GetModule(const AnsiIDName &name,bool create); ///<获取指定名称的模块 - - /** - * 获取指定类型的模块 - * @param create 如果不存在,是否创建新的 - */ - template - T *GetModule(bool create=false){return (T *)GetModule(T::GetModuleName(),create);} ///<获取指定类型的模块 - - void ReleaseModule(GraphModule *); ///<释放指定模块 - -public: //事件 - - void OnResize(const VkExtent2D &); -};//class GraphModuleManager - -GraphModuleManager *GetGraphModuleManager(RenderFramework *); - -class GraphModule:public Comparator -{ - GraphModuleManager *module_manager; + RenderFramework *render_framework; AnsiIDName module_name; @@ -111,10 +23,9 @@ class GraphModule:public Comparator protected: - GraphModule *GetModule(const AnsiIDName &name){return module_manager->GetModule(name,false);} ///<获取指定名称的模块 - template - T *GetModule(){return module_manager->GetModule();} ///<获取指定类型的模块 + T * GetModule(bool create=false){return render_framework->GetModule(create);} ///<获取指定类型的模块 + GraphModule * GetModule(const AnsiIDName &name,bool create=false); ///<获取指定名称的模块 protected: @@ -122,14 +33,13 @@ protected: virtual void SetModuleReady(bool r){module_ready=r;} public: + + GPUDevice * GetDevice () {return render_framework->GetDevice();} ///<取得GPU设备 + VkDevice GetVkDevice ()const {return render_framework->GetVkDevice();} ///<取得VkDevice + const GPUPhysicalDevice * GetPhysicalDevice ()const {return render_framework->GetPhysicalDevice();} ///<取得物理设备 + GPUDeviceAttribute *GetDeviceAttribute () {return render_framework->GetDeviceAttribute();} ///<取得设备属性 - GraphModuleManager *GetManager () {return module_manager;} ///<取得模块管理器 - GPUDevice * GetDevice () {return module_manager->GetDevice();} ///<取得GPU设备 - VkDevice GetVkDevice ()const {return module_manager->GetVkDevice();} ///<取得VkDevice - const GPUPhysicalDevice * GetPhysicalDevice ()const {return module_manager->GetPhysicalDevice();} ///<取得物理设备 - GPUDeviceAttribute *GetDeviceAttribute () {return module_manager->GetDeviceAttribute();} ///<取得设备属性 - - RenderFramework * GetFramework () {return module_manager->GetFramework();} ///<取得渲染框架 + RenderFramework * GetFramework () {return render_framework;} ///<取得渲染框架 const AnsiIDName & GetName ()const {return module_name;} ///<取得模块名称(标准通用的名称,比如Upscale,供通用模块使用) virtual const AnsiIDName & GetFullName ()const {return module_name;} ///<取得名称(完整的私有名称,比如FSR3Upscale,DLSS3Upscale) @@ -145,29 +55,17 @@ public: NO_COPY_NO_MOVE(GraphModule) - GraphModule(GraphModuleManager *gmm,const AnsiIDName &name); +protected: + + GraphModule(RenderFramework *rf,const AnsiIDName &name); + +public: + virtual ~GraphModule(); virtual const size_t GetTypeHash()const=0; - virtual bool Init()=0; ///<初始化当前模块 - - static const char **GetDependentModules(){return nullptr;} ///<取得依赖的模块列表 - - const int compare(const GraphModule &gm)const override - { - const char **dependent_modules_list=GetDependentModules(); - - if(!dependent_modules_list) - return -1; - - const char *self_module_name=gm.GetName().ToString(); - - if(string_in_list(dependent_modules_list,self_module_name)) - return 1;//如果我依赖于他,那么我比他大 - - return 0; - } + static const GraphModuleHashList GetDependentModules(){return {};} ///<取得依赖的模块列表 public: //回调事件 @@ -178,28 +76,43 @@ public: //回调事件 virtual void OnPostFrame(){} ///<帧绘制后回调 };//class GraphModule -#define GRAPH_MODULE_CONSTRUCT(name) public:\ - NO_COPY_NO_MOVE(name) \ - static const size_t StaticHash(){return typeid(name).hash_code();} \ - const size_t GetTypeHash()const override{return name::StaticHash();} \ - static const AnsiIDName &GetModuleName() \ - { \ - static const AnsiIDName id_name(#name); \ - return id_name; \ - } \ - \ - name(GraphModuleManager *gmm):GraphModule(gmm,GetModuleName()){} +using GraphModuleMapByIDName=Map; -#define RENDER_MODULE_CONSTRUCT(name) public:\ +//template class GraphModuleInherit:public BASE +//{ +//public: +// +// GraphModuleInherit(RenderFramework *rf):BASE(rf,typeid(T)) +// {} +// +// static const size_t StaticHash() +// { +// return typeid(T).hash_code(); +// } +// +//};//class GraphModuleInherit + +#define GRAPH_MODULE_CREATE_FUNC(name) name *name::CreateModule(RenderFramework *rf,GraphModuleMapByIDName &dep_modules) + +#define GRAPH_BASE_MODULE_CONSTRUCT(name,base_class) public:\ + NO_COPY_NO_MOVE(name) \ static const size_t StaticHash(){return typeid(name).hash_code();} \ const size_t GetTypeHash()const override{return name::StaticHash();} \ - NO_COPY_NO_MOVE(name) \ static const AnsiIDName &GetModuleName() \ { \ static const AnsiIDName id_name(#name); \ return id_name; \ } \ \ - name(GraphModuleManager *gmm):RenderModule(gmm,GetModuleName()){} + private: \ + name(RenderFramework *rf):base_class(rf,GetModuleName()){} \ + \ + public: \ + static name *CreateModule(RenderFramework *rf,GraphModuleMapByIDName &); \ + static const GraphModuleHashList GetDependentModules(); + + +#define GRAPH_MODULE_CONSTRUCT(name) GRAPH_BASE_MODULE_CONSTRUCT(name,GraphModule) +#define RENDER_MODULE_CONSTRUCT(name) GRAPH_BASE_MODULE_CONSTRUCT(name,RenderModule) VK_NAMESPACE_END diff --git a/inc/hgl/graph/module/GraphModuleFactory.h b/inc/hgl/graph/module/GraphModuleFactory.h index 5a3c1344..65d716dd 100644 --- a/inc/hgl/graph/module/GraphModuleFactory.h +++ b/inc/hgl/graph/module/GraphModuleFactory.h @@ -3,6 +3,7 @@ #include #include #include +#include VK_NAMESPACE_BEGIN @@ -13,7 +14,7 @@ public: GraphModuleFactory()=default; virtual ~GraphModuleFactory()=default; - virtual GraphModule *Create(GraphModuleManager *)=0; + virtual GraphModule *Create(RenderFramework *)=0; };//class GraphModuleFactory bool RegistryGraphModuleFactory(const char *module_name,GraphModuleFactory *); @@ -22,9 +23,9 @@ template class RegistryGraphModule:public GraphModuleFactory { public: - GraphModule *Create(GraphModuleManager *gmm) override + GraphModule *Create(RenderFramework *rf) override { - if(!gmm) + if(!rf) return(nullptr); Map dgm_map; @@ -37,7 +38,7 @@ public: { for(const AnsiIDName &name:dependent_modules) { - GraphModule *dgm=gmm->GetModule(name,true); + GraphModule *dgm=rf->GetModule(name,true); if(!dgm) return(nullptr); @@ -47,13 +48,7 @@ public: } } - GraphModule *gm=new T(gmm); - - if(!gm->Init()) - { - delete gm; - return(nullptr); - } + T *gm=T::CreateModule(rf,dgm_map); return(gm); } diff --git a/inc/hgl/graph/module/GraphModuleMap.h b/inc/hgl/graph/module/GraphModuleMap.h new file mode 100644 index 00000000..50b6a5c7 --- /dev/null +++ b/inc/hgl/graph/module/GraphModuleMap.h @@ -0,0 +1,56 @@ +#pragma once + +#include +#include + +VK_NAMESPACE_BEGIN + +class GraphModule; + +class GraphModulesMap +{ + SortedSet gm_set; + + Map gm_map_by_name; + Map gm_map_by_hash; + + List gm_list; //按创建顺序记录,用于倒序释放 + +public: + + bool Add(GraphModule *gm); + + const bool IsEmpty()const + { + return gm_set.IsEmpty(); + } + + GraphModule *Get(const AnsiIDName &name) + { + GraphModule *gm; + + if(gm_map_by_name.Get(name,gm)) + return gm; + + return nullptr; + } + + template + T *Get() + { + GraphModule *gm; + + return gm_map_by_hash.Get(GetTypeHash(),gm)?(T *)gm:nullptr; + } + + template + const bool IsLoaded()const{return gm_map_by_hash.ContainsKey(T::GetTypeHash());} + + const bool IsLoaded(const AnsiIDName &name)const{return gm_map_by_name.ContainsKey(name);} + + bool Release(GraphModule *gm); ///<释放一个模块 + + void Destory(); ///<销毁所有模块 +};//class GraphModulesMap + +VK_NAMESPACE_END diff --git a/inc/hgl/graph/module/SwapchainModule.h b/inc/hgl/graph/module/SwapchainModule.h index d4f064e9..21f87567 100644 --- a/inc/hgl/graph/module/SwapchainModule.h +++ b/inc/hgl/graph/module/SwapchainModule.h @@ -1,6 +1,7 @@ #pragma once #include +#include VK_NAMESPACE_BEGIN @@ -32,8 +33,6 @@ public: GRAPH_MODULE_CONSTRUCT(SwapchainModule) virtual ~SwapchainModule(); - bool Init() override; - bool BeginFrame(); void EndFrame(); diff --git a/res b/res index 475d8ad4..e1a36d78 160000 --- a/res +++ b/res @@ -1 +1 @@ -Subproject commit 475d8ad43ceee084cd24f5d0bed59de9f6aa36fd +Subproject commit e1a36d78f0eead5f6bb65493432c4690637b991d diff --git a/src/SceneGraph/CMakeLists.txt b/src/SceneGraph/CMakeLists.txt index 83bbfcb5..ce63be97 100644 --- a/src/SceneGraph/CMakeLists.txt +++ b/src/SceneGraph/CMakeLists.txt @@ -277,12 +277,12 @@ SOURCE_GROUP("Scene Graph\\Component" FILES ${SG_COMPONENT_HEADER} ${SG_COMPONEN SET(SG_MODULE_HEADER_PATH ${SG_INCLUDE_PATH}/module) SET(GRAPH_MODULE_HEADER ${SG_MODULE_HEADER_PATH}/GraphModule.h + ${SG_MODULE_HEADER_PATH}/GraphModuleMap.h ${SG_MODULE_HEADER_PATH}/GraphModuleFactory.h ${SG_MODULE_HEADER_PATH}/RenderModule.h ${SG_MODULE_HEADER_PATH}/SwapchainModule.h) SET(GRAPH_MODULE_SOURCE module/GraphModule.cpp - module/GraphModuleManager.cpp module/GraphModuleFactory.cpp module/RenderModule.cpp module/RegistryCommonModule.cpp diff --git a/src/SceneGraph/RenderFramework.cpp b/src/SceneGraph/RenderFramework.cpp index 70e01556..86bbde70 100644 --- a/src/SceneGraph/RenderFramework.cpp +++ b/src/SceneGraph/RenderFramework.cpp @@ -12,8 +12,16 @@ VK_NAMESPACE_BEGIN bool InitShaderCompiler(); void CloseShaderCompiler(); -GraphModuleManager *InitGraphModuleManager(RenderFramework *); -bool ClearGraphModuleManager(RenderFramework *); +void InitGraphModuleFactory(); +void ClearGraphModuleFactory(); + +namespace +{ + static int RENDER_FRAMEWORK_COUNT=0; + +}//namespace + +GraphModule *CreateGraphModule(const AnsiIDName &name,RenderFramework *rf); namespace { @@ -32,17 +40,43 @@ namespace } }//namespace -RenderFramework::RenderFramework() +GraphModule *RenderFramework::GetModule(const AnsiIDName &name,bool create) { + GraphModule *gm=graph_module_map.Get(name); + + if(!gm) + { + gm=CreateGraphModule(name,this); + } } +RenderFramework *CreateRenderFramework() +{ + if(RENDER_FRAMEWORK_COUNT==0) + { + if(!InitShaderCompiler()) + return(nullptr); + + InitGraphModuleFactory(); + RegistryCommonGraphModule(); + } + + ++RENDER_FRAMEWORK_COUNT; +} + +RenderFramework::RenderFramework(){} + RenderFramework::~RenderFramework() { -// if(swapchain_module)graph_module_manager->ReleaseModule(swapchain_module); + graph_module_map.Destory(); - ClearGraphModuleManager(this); + --RENDER_FRAMEWORK_COUNT; - CloseShaderCompiler(); + if(RENDER_FRAMEWORK_COUNT==0) + { + ClearGraphModuleFactory(); + CloseShaderCompiler(); + } } void RenderFramework::StartTime() diff --git a/src/SceneGraph/manager/TextureManager.cpp b/src/SceneGraph/manager/TextureManager.cpp index 6c3ba9c1..4d80fc9c 100644 --- a/src/SceneGraph/manager/TextureManager.cpp +++ b/src/SceneGraph/manager/TextureManager.cpp @@ -9,28 +9,21 @@ const VkFormatProperties TextureManager::GetFormatProperties(const VkFormat form return GetPhysicalDevice()->GetFormatProperties(format); } -namespace +const GraphModuleHashList TextureManager::GetDependentModules() ///<取得依赖的模块列表 { - const char *tex_manager_dep[] - { - "RenderPassManager", - nullptr //一定要0结尾 - }; + return {RenderPassManager::StaticHash()}; } -const char **TextureManager::GetDependentModules() ///<取得依赖的模块列表 +GRAPH_MODULE_CREATE_FUNC(TextureManager) { - return tex_manager_dep; -} - -bool TextureManager::Init() -{ - GPUDevice *dev=GetDevice(); + GPUDevice *dev=rf->GetDevice(); if(!dev) return(false); - texture_cmd_buf=dev->CreateTextureCommandBuffer(GetPhysicalDevice()->GetDeviceName()+AnsiString(":TexCmdBuffer")); + auto phy_device=rf->GetPhysicalDevice(); + + texture_cmd_buf=dev->CreateTextureCommandBuffer(phy_device->GetDeviceName()+AnsiString(":TexCmdBuffer")); if(!texture_cmd_buf) return(false); diff --git a/src/SceneGraph/module/GraphModule.cpp b/src/SceneGraph/module/GraphModule.cpp index 63d9ce60..d61c418f 100644 --- a/src/SceneGraph/module/GraphModule.cpp +++ b/src/SceneGraph/module/GraphModule.cpp @@ -1,4 +1,5 @@ #include +#include #include #include @@ -54,9 +55,9 @@ bool GraphModulesMap::Release(GraphModule *gm) return(true); } -GraphModule::GraphModule(GraphModuleManager *gmm,const AnsiIDName &name) +GraphModule::GraphModule(RenderFramework *rf,const AnsiIDName &name) { - module_manager=gmm; + render_framework=rf; module_name=name; LOG_INFO("GraphModule::GraphModule: "+AnsiString(module_name.GetName())) @@ -67,4 +68,9 @@ GraphModule::~GraphModule() LOG_INFO("GraphModule::~GraphModule: "+AnsiString(module_name.GetName())) } +GraphModule *GraphModule::GetModule(const AnsiIDName &name,bool create) +{ + render_framework->GetModule(name,create); +} + VK_NAMESPACE_END diff --git a/src/SceneGraph/module/GraphModuleFactory.cpp b/src/SceneGraph/module/GraphModuleFactory.cpp index ab8cab56..9d5729a8 100644 --- a/src/SceneGraph/module/GraphModuleFactory.cpp +++ b/src/SceneGraph/module/GraphModuleFactory.cpp @@ -43,9 +43,9 @@ bool RegistryGraphModuleFactory(const char *module_name,GraphModuleFactory *gmf) return(true); } -GraphModule *CreateGraphModule(const AnsiIDName &name,GraphModuleManager *gmm) +GraphModule *CreateGraphModule(const AnsiIDName &name,RenderFramework *rf) { - if(!gmm) + if(!rf) return(nullptr); if(!gmf_map) @@ -56,7 +56,7 @@ GraphModule *CreateGraphModule(const AnsiIDName &name,GraphModuleManager *gmm) if(!gmf_map->Get(name,gmf)) return(nullptr); - return gmf->Create(gmm); + return gmf->Create(rf); } VK_NAMESPACE_END diff --git a/src/SceneGraph/module/GraphModuleManager.cpp b/src/SceneGraph/module/GraphModuleManager.cpp deleted file mode 100644 index 7865e0cc..00000000 --- a/src/SceneGraph/module/GraphModuleManager.cpp +++ /dev/null @@ -1,134 +0,0 @@ -#include -#include -#include - -VK_NAMESPACE_BEGIN - -void InitGraphModuleFactory(); -void ClearGraphModuleFactory(); - -namespace -{ - using GraphModuleManagerMap=Map; - - static GraphModuleManagerMap *graph_module_manager_map=nullptr; -} - -GraphModuleManager *InitGraphModuleManager(RenderFramework *rf) -{ - if(!rf) - return(nullptr); - - if(graph_module_manager_map) - { - if(graph_module_manager_map->ContainsKey(rf)) - return(nullptr); - } - else - { - InitGraphModuleFactory(); - RegistryCommonGraphModule(); - - graph_module_manager_map=new GraphModuleManagerMap; - } - - GraphModuleManager *gmm=new GraphModuleManager(rf); - - graph_module_manager_map->Add(rf,gmm); - - return gmm; -} - -bool ClearGraphModuleManager(RenderFramework *rf) -{ - if(!rf) - return(false); - - if(!graph_module_manager_map) - return(false); - - GraphModuleManager *gmm; - - if(!graph_module_manager_map->Get(rf,gmm)) - return(false); - - graph_module_manager_map->DeleteByKey(rf); - - delete gmm; - - if(graph_module_manager_map->IsEmpty()) - { - ClearGraphModuleFactory(); - SAFE_CLEAR(graph_module_manager_map); - } - - return(true); -} - -GraphModuleManager *GetGraphModuleManager(RenderFramework *rf) -{ - if(!rf) - return(nullptr); - - if(!graph_module_manager_map) - return(nullptr); - - GraphModuleManager *gmm; - - if(graph_module_manager_map->Get(rf,gmm)) - return gmm; - - return(nullptr); -} - -GraphModule *CreateGraphModule(const AnsiIDName &name,GraphModuleManager *gmm); - -GraphModule *GraphModuleManager::GetModule(const AnsiIDName &name,bool create) -{ - GraphModule *gm=graph_module_map.Get(name); - - if(gm) - return gm; - - if(create) - { - gm=CreateGraphModule(name,this); - - if(gm) - graph_module_map.Add(gm); - } - - return gm; -} - -GraphModuleManager::GraphModuleManager(RenderFramework *rf) -{ - framework=rf; - device=rf->GetDevice(); -} - -GraphModuleManager::~GraphModuleManager() -{ - graph_module_map.Destory(); -} - -void GraphModuleManager::ReleaseModule(GraphModule *gm) -{ - if(!gm) - return; - - graph_module_map.Release(gm); -} - -void GraphModuleManager::OnResize(const VkExtent2D &extent) -{ - if(graph_module_map.IsEmpty()) - return; - - for(auto *gm:graph_module_map.gm_list) - { - gm->OnResize(extent); - } -} - -VK_NAMESPACE_END