diff --git a/CMAssetsManage b/CMAssetsManage index 85436b5a..cf6a54d4 160000 --- a/CMAssetsManage +++ b/CMAssetsManage @@ -1 +1 @@ -Subproject commit 85436b5a7b0bc9347fcd3321a6895464470f1353 +Subproject commit cf6a54d484436eea700bc4f4ea002ed23eed6dc8 diff --git a/CMCore b/CMCore index 7295d68a..ea101386 160000 --- a/CMCore +++ b/CMCore @@ -1 +1 @@ -Subproject commit 7295d68a5e6f2b9bc9ad08dc397375850af50bf7 +Subproject commit ea101386d3705ee56b7a457b5b828c9f7894487d diff --git a/inc/hgl/graph/manager/RenderPassManager.h b/inc/hgl/graph/manager/RenderPassManager.h index ade8c1d5..c3eb7383 100644 --- a/inc/hgl/graph/manager/RenderPassManager.h +++ b/inc/hgl/graph/manager/RenderPassManager.h @@ -26,7 +26,7 @@ private: GRAPH_MODULE_CONSTRUCT(RenderPassManager) ~RenderPassManager(); - bool Init() override; + bool Init(GraphModulesMap *) override; private: diff --git a/inc/hgl/graph/manager/TextureManager.h b/inc/hgl/graph/manager/TextureManager.h index 824d095b..dc618fa2 100644 --- a/inc/hgl/graph/manager/TextureManager.h +++ b/inc/hgl/graph/manager/TextureManager.h @@ -1,4 +1,4 @@ -#pragma once +#pragma once #include #include @@ -12,6 +12,8 @@ VK_NAMESPACE_BEGIN class TextureManager:public GraphModule { + RenderPassManager *rp_manager=nullptr; + DeviceQueue *texture_queue=nullptr; TextureCmdBuffer *texture_cmd_buf=nullptr; @@ -40,7 +42,7 @@ public: GRAPH_MODULE_CONSTRUCT(TextureManager) virtual ~TextureManager(); - bool Init() override; + bool Init(GraphModulesMap *) override; const VkFormatProperties GetFormatProperties(const VkFormat)const; diff --git a/inc/hgl/graph/module/GraphModule.h b/inc/hgl/graph/module/GraphModule.h index 3014db58..6fe43691 100644 --- a/inc/hgl/graph/module/GraphModule.h +++ b/inc/hgl/graph/module/GraphModule.h @@ -11,14 +11,40 @@ class GraphModule; class RenderFramework; +struct GraphModulesMap +{ + List gm_list; + + Map gm_map_by_name; + Map gm_map_by_hash; + +public: + + bool Add(GraphModule *gm); + + GraphModule *Get(const AnsiIDName &name)const + { + GraphModule *gm; + + if(gm_map_by_name.Get(name,gm)) + return gm; + + return nullptr; + } + + template + const bool Get(T *&gm)const + { + return gm_map_by_hash.Get(GetTypeHash(),gm); + } +}; + class GraphModuleManager { GPUDevice *device; RenderFramework *framework; - List module_list; ///<模块列表 - - Map graph_module_map; ///<模块映射表 + GraphModulesMap graph_module_map; ///<模块映射表 public: @@ -65,12 +91,19 @@ class GraphModule:public Comparator AnsiIDName module_name; - SortedSet dependent_module; ///<依赖的模块 - bool module_inited; bool module_enabled; bool module_ready; + GraphModulesMap dependent_modules; + +protected: + + //GraphModule *GetModule(const AnsiIDName &name){return module_manager->GetModule(name,true);} ///<获取指定名称的模块 + + //template + //T *GetModule(){return (T *)GetModule(T::GetModuleName());} ///<获取指定类型的模块 + protected: virtual void SetModuleEnabled(bool e){module_enabled=e;} @@ -103,19 +136,28 @@ public: GraphModule(GraphModuleManager *gmm,const AnsiIDName &name); virtual ~GraphModule(); - virtual bool Init(){module_inited=true;return true;} ///<初始化当前模块 + virtual bool Init(GraphModulesMap *); ///<初始化当前模块 + + static const AnsiIDNameSet &GetDependentModules() ///<取得依赖的模块列表 + { + static const AnsiIDNameSet empty; + + return empty; + } const int compare(const GraphModule &gm)const override { - return(dependent_module.Contains(gm.module_name)?1:-1); //如果我依赖于他,那么我比他大 + auto &dependent_modules_name=GetDependentModules(); + + return(dependent_modules_name.Contains(gm.module_name)?1:-1); //如果我依赖于他,那么我比他大 } public: - GraphModule * GetModule(const AnsiIDName &name,bool create=false){return module_manager->GetModule(name,create);} ///<获取指定名称的模块 + GraphModule * GetDependentModule(const AnsiIDName &name); ///<获取指定名称的模块 template - T * GetModule(bool create=false){return module_manager->GetModule(create);} ///<获取指定类型的模块 + T * GetDependentModule(){return GetDependentModule(T::GetName());} ///<获取指定类型的模块 public: //回调事件 @@ -128,6 +170,7 @@ public: //回调事件 #define GRAPH_MODULE_CONSTRUCT(name) public:\ NO_COPY_NO_MOVE(name) \ + static const size_t GetTypeHash(){return typeid(name).hash_code();} \ static const AnsiIDName &GetModuleName() \ { \ static const AnsiIDName id_name(#name); \ @@ -137,6 +180,7 @@ public: //回调事件 name(GraphModuleManager *gmm):GraphModule(gmm,GetModuleName()){} #define RENDER_MODULE_CONSTRUCT(name) public:\ + static const size_t GetTypeHash(){return typeid(name).hash_code();} \ NO_COPY_NO_MOVE(name) \ static const AnsiIDName &GetModuleName() \ { \ diff --git a/inc/hgl/graph/module/GraphModuleFactory.h b/inc/hgl/graph/module/GraphModuleFactory.h index 1a70bd7f..d7ea6ed5 100644 --- a/inc/hgl/graph/module/GraphModuleFactory.h +++ b/inc/hgl/graph/module/GraphModuleFactory.h @@ -28,7 +28,27 @@ public: if(!gmm) return(nullptr); - GraphModule *gm=new T(gmm); + Map dgm_map; + + //检查依赖模块 + { + const auto &dependent_modules=T::GetDependentModules(); + + if(!dependent_modules.IsEmpty()) + { + for(const AnsiIDName &name:dependent_modules) + { + GraphModule *dgm=gmm->GetModule(name,true); + + if(!dgm) + return(nullptr); + + dgm_map.Add(name,dgm); + } + } + } + + GraphModule *gm=new T(gmm,dgm_map); if(!gm->Init()) { diff --git a/inc/hgl/graph/module/SwapchainModule.h b/inc/hgl/graph/module/SwapchainModule.h index 9aac6bdb..835a0a06 100644 --- a/inc/hgl/graph/module/SwapchainModule.h +++ b/inc/hgl/graph/module/SwapchainModule.h @@ -1,4 +1,4 @@ -#pragma once +#pragma once #include @@ -32,7 +32,7 @@ public: GRAPH_MODULE_CONSTRUCT(SwapchainModule) virtual ~SwapchainModule(); - bool Init() override; + bool Init(GraphModulesMap *) override; bool BeginFrame(); void EndFrame(); diff --git a/res b/res index e1a36d78..475d8ad4 160000 --- a/res +++ b/res @@ -1 +1 @@ -Subproject commit e1a36d78f0eead5f6bb65493432c4690637b991d +Subproject commit 475d8ad43ceee084cd24f5d0bed59de9f6aa36fd diff --git a/src/SceneGraph/Vulkan/VKDeviceRenderTarget.cpp b/src/SceneGraph/Vulkan/VKDeviceRenderTarget.cpp index f0567b41..2963c904 100644 --- a/src/SceneGraph/Vulkan/VKDeviceRenderTarget.cpp +++ b/src/SceneGraph/Vulkan/VKDeviceRenderTarget.cpp @@ -1,4 +1,4 @@ -#include +#include #include #include diff --git a/src/SceneGraph/manager/RenderPassManager.cpp b/src/SceneGraph/manager/RenderPassManager.cpp index dc16ddb0..658af3d2 100644 --- a/src/SceneGraph/manager/RenderPassManager.cpp +++ b/src/SceneGraph/manager/RenderPassManager.cpp @@ -1,4 +1,4 @@ -#include +#include #include VK_NAMESPACE_BEGIN @@ -184,8 +184,13 @@ bool CreateDepthAttachment( List &ref_list,ListGet(rp_manager); + pipeline_cache=GetDeviceAttribute()->pipeline_cache; hash=CreateRenderPassHash(); diff --git a/src/SceneGraph/module/GraphModule.cpp b/src/SceneGraph/module/GraphModule.cpp index 4d6f2117..fec628a9 100644 --- a/src/SceneGraph/module/GraphModule.cpp +++ b/src/SceneGraph/module/GraphModule.cpp @@ -1,9 +1,20 @@ -#include +#include #include #include VK_NAMESPACE_BEGIN +bool GraphModulesMap::Add(GraphModule *gm) +{ + if(!gm)return(false); + + if(gm_map.ContainsKey(gm->GetName())) + return(false); + + gm_list.Add(gm); + gm_map.Add(gm->GetName(),gm); +} + GraphModule::GraphModule(GraphModuleManager *gmm,const AnsiIDName &name) { module_manager=gmm; @@ -17,4 +28,47 @@ 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(); + + if(!dm_list.IsEmpty()) + { + if(!gmm) + return(false); + + if(!gmm->IsEmpty()) + { + for(auto dm_name:dm_list) + { + GraphModule *dm; + + if(gmm->Get(dm_name,dm)) + { + if(dm->IsInited()) + { + dependent_modules.Add(dm_name,dm); + continue; + } + } + + return(false); + } + } + } + + module_inited=true; + return(true); +} + VK_NAMESPACE_END diff --git a/src/SceneGraph/module/GraphModuleManager.cpp b/src/SceneGraph/module/GraphModuleManager.cpp index 743581f7..a83a6b79 100644 --- a/src/SceneGraph/module/GraphModuleManager.cpp +++ b/src/SceneGraph/module/GraphModuleManager.cpp @@ -1,4 +1,5 @@ -#include +#include +#include #include VK_NAMESPACE_BEGIN @@ -108,6 +109,7 @@ GraphModule *GraphModuleManager::GetModule(const AnsiIDName &name,bool create) GraphModuleManager::GraphModuleManager(RenderFramework *rf) { framework=rf; + device=rf->GetDevice(); } GraphModuleManager::~GraphModuleManager()