diff --git a/inc/hgl/graph/module/GraphModule.h b/inc/hgl/graph/module/GraphModule.h index 6fe43691..47c6cd14 100644 --- a/inc/hgl/graph/module/GraphModule.h +++ b/inc/hgl/graph/module/GraphModule.h @@ -13,7 +13,7 @@ class RenderFramework; struct GraphModulesMap { - List gm_list; + SortedSet gm_set; Map gm_map_by_name; Map gm_map_by_hash; @@ -22,6 +22,11 @@ public: bool Add(GraphModule *gm); + const bool IsEmpty()const + { + return gm_set.IsEmpty(); + } + GraphModule *Get(const AnsiIDName &name)const { GraphModule *gm; @@ -37,6 +42,11 @@ public: { return gm_map_by_hash.Get(GetTypeHash(),gm); } + + 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());} }; class GraphModuleManager @@ -49,7 +59,7 @@ class GraphModuleManager public: GraphModuleManager(RenderFramework *); - ~GraphModuleManager(); + virtual ~GraphModuleManager(); GPUDevice * GetDevice ()noexcept {return device;} ///<取得GPU设备 VkDevice GetVkDevice ()const {return device->GetDevice();} @@ -73,11 +83,6 @@ public: void ReleaseModule(GraphModule *); ///<释放指定模块 - const bool IsLoaded(const AnsiIDName &name){return graph_module_map.ContainsKey(name);} ///<是否已经加载了指定类型的模块 - - template - const bool IsLoaded(){return graph_module_map.ContainsKey(T::GetModuleName());} ///<是否已经加载了指定类型的模块 - public: //事件 void OnResize(const VkExtent2D &); @@ -90,6 +95,7 @@ class GraphModule:public Comparator GraphModuleManager *module_manager; AnsiIDName module_name; + AnsiIDName module_fullname; bool module_inited; bool module_enabled; @@ -119,8 +125,8 @@ public: RenderFramework * GetFramework () {return module_manager->GetFramework();} ///<取得渲染框架 - static const AnsiIDName * GetModuleName () {return nullptr;} ///<取得模块名称(标准通用的名称,比如Upscale,供通用模块使用) - virtual const AnsiIDName * GetName ()const {return &module_name;} ///<取得名称(完整的私有名称,比如FSR3Upscale,DLSS3Upscale) + const AnsiIDName & GetName ()const {return module_name;} ///<取得模块名称(标准通用的名称,比如Upscale,供通用模块使用) + const AnsiIDName & GetFullName ()const {return module_fullname;} ///<取得名称(完整的私有名称,比如FSR3Upscale,DLSS3Upscale) virtual const bool IsPerFrame () {return false;} ///<是否每帧运行 virtual const bool IsRender () {return false;} ///<是否为渲染模块 @@ -133,9 +139,11 @@ public: NO_COPY_NO_MOVE(GraphModule) - GraphModule(GraphModuleManager *gmm,const AnsiIDName &name); + GraphModule(GraphModuleManager *gmm,const AnsiIDName &name,const AnsiIDName &fullname); virtual ~GraphModule(); + virtual const size_t GetTypeHash()const=0; + virtual bool Init(GraphModulesMap *); ///<初始化当前模块 static const AnsiIDNameSet &GetDependentModules() ///<取得依赖的模块列表 @@ -154,10 +162,10 @@ public: public: - GraphModule * GetDependentModule(const AnsiIDName &name); ///<获取指定名称的模块 + GraphModule * GetDependentModule(const AnsiIDName &name){return dependent_modules.Get(name);} ///<获取指定名称的模块 template - T * GetDependentModule(){return GetDependentModule(T::GetName());} ///<获取指定类型的模块 + T * GetDependentModule(){return dependent_modules.Get();} ///<获取指定类型的模块 public: //回调事件 @@ -170,7 +178,8 @@ public: //回调事件 #define GRAPH_MODULE_CONSTRUCT(name) public:\ NO_COPY_NO_MOVE(name) \ - static const size_t GetTypeHash(){return typeid(name).hash_code();} \ + 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); \ @@ -180,7 +189,8 @@ public: //回调事件 name(GraphModuleManager *gmm):GraphModule(gmm,GetModuleName()){} #define RENDER_MODULE_CONSTRUCT(name) public:\ - static const size_t GetTypeHash(){return typeid(name).hash_code();} \ + 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() \ { \ 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/module/GraphModule.cpp b/src/SceneGraph/module/GraphModule.cpp index fec628a9..d6c37557 100644 --- a/src/SceneGraph/module/GraphModule.cpp +++ b/src/SceneGraph/module/GraphModule.cpp @@ -6,19 +6,23 @@ VK_NAMESPACE_BEGIN bool GraphModulesMap::Add(GraphModule *gm) { - if(!gm)return(false); - - if(gm_map.ContainsKey(gm->GetName())) + if(!gm) return(false); - gm_list.Add(gm); - gm_map.Add(gm->GetName(),gm); + if(gm_set.Contains(gm)) + return(false); + + + gm_set.Add(gm); + gm_map_by_name.Add(gm->GetName(),gm); + } -GraphModule::GraphModule(GraphModuleManager *gmm,const AnsiIDName &name) +GraphModule::GraphModule(GraphModuleManager *gmm,const AnsiIDName &name,const AnsiIDName &fullname) { module_manager=gmm; module_name=name; + module_fullname=fullname; LOG_INFO("GraphModule::GraphModule: "+AnsiString(module_name.GetName())) } @@ -28,16 +32,6 @@ GraphModule::~GraphModule() LOG_INFO("GraphModule::~GraphModule: "+AnsiString(module_name.GetName())) } -GraphModule *GraphModule::GetDependentModule(const AnsiIDName &name) -{ - GraphModule *dm; - - if(dependent_modules.Get(name,dm)) - return(dm); - - return(nullptr); -} - bool GraphModule::Init(GraphModulesMap *gmm) { auto dm_list=GetDependentModules(); @@ -57,7 +51,7 @@ bool GraphModule::Init(GraphModulesMap *gmm) { if(dm->IsInited()) { - dependent_modules.Add(dm_name,dm); + dependent_modules.Add(dm); continue; } } diff --git a/src/SceneGraph/module/GraphModuleManager.cpp b/src/SceneGraph/module/GraphModuleManager.cpp index a83a6b79..d5c94786 100644 --- a/src/SceneGraph/module/GraphModuleManager.cpp +++ b/src/SceneGraph/module/GraphModuleManager.cpp @@ -85,9 +85,9 @@ GraphModule *CreateGraphModule(const AnsiIDName &name,GraphModuleManager *gmm); GraphModule *GraphModuleManager::GetModule(const AnsiIDName &name,bool create) { - GraphModule *gm; + GraphModule *gm=graph_module_map.Get(name); - if(graph_module_map.Get(name,gm)) + if(gm) return gm; if(create) @@ -95,15 +95,10 @@ GraphModule *GraphModuleManager::GetModule(const AnsiIDName &name,bool create) gm=CreateGraphModule(name,this); if(gm) - { - graph_module_map.Add(name,gm); - module_list.Add(gm); - } - - return gm; + graph_module_map.Add(gm); } - return nullptr; + return gm; } GraphModuleManager::GraphModuleManager(RenderFramework *rf)