From d1c3934bebd0398787681799de044978e98be3ee Mon Sep 17 00:00:00 2001 From: hyzboy Date: Mon, 16 Dec 2024 23:24:08 +0800 Subject: [PATCH] Use RenderFramework instead of GPUDevice at Init GraphModuleManager --- inc/hgl/graph/module/GraphModule.h | 28 +++++++++----------- src/SceneGraph/RenderFramework.cpp | 14 +++++----- src/SceneGraph/module/GraphModuleManager.cpp | 26 +++++++++--------- 3 files changed, 33 insertions(+), 35 deletions(-) diff --git a/inc/hgl/graph/module/GraphModule.h b/inc/hgl/graph/module/GraphModule.h index dd4ab235..3014db58 100644 --- a/inc/hgl/graph/module/GraphModule.h +++ b/inc/hgl/graph/module/GraphModule.h @@ -57,7 +57,7 @@ public: //事件 void OnResize(const VkExtent2D &); };//class GraphModuleManager -GraphModuleManager *GetGraphModuleManager(GPUDevice *); +GraphModuleManager *GetGraphModuleManager(RenderFramework *); class GraphModule:public Comparator { @@ -65,22 +65,19 @@ class GraphModule:public Comparator AnsiIDName module_name; - SortedSet dependent_module; ///<依赖的模块 + SortedSet dependent_module; ///<依赖的模块 - bool module_init; - bool module_enable; + bool module_inited; + bool module_enabled; bool module_ready; protected: - virtual void SetModuleEnable(bool e){module_enable=e;} + virtual void SetModuleEnabled(bool e){module_enabled=e;} virtual void SetModuleReady(bool r){module_ready=r;} public: - virtual const bool IsPerFrame () {return false;} ///<是否每帧运行 - virtual const bool IsRender () {return false;} ///<是否为渲染模块 - GraphModuleManager *GetManager () {return module_manager;} ///<取得模块管理器 GPUDevice * GetDevice () {return module_manager->GetDevice();} ///<取得GPU设备 VkDevice GetVkDevice ()const {return module_manager->GetVkDevice();} ///<取得VkDevice @@ -89,14 +86,15 @@ public: RenderFramework * GetFramework () {return module_manager->GetFramework();} ///<取得渲染框架 - static const AnsiIDName * GetModuleName (){return nullptr;} ///<取得模块名称(标准通用的名称,比如Upscale,供通用模块使用) - virtual const AnsiIDName * GetName ()const{return &module_name;} ///<取得名称(完整的私有名称,比如FSR3Upscale,DLSS3Upscale) + static const AnsiIDName * GetModuleName () {return nullptr;} ///<取得模块名称(标准通用的名称,比如Upscale,供通用模块使用) + virtual const AnsiIDName * GetName ()const {return &module_name;} ///<取得名称(完整的私有名称,比如FSR3Upscale,DLSS3Upscale) - virtual const bool IsRender (){return false;} ///<是否为渲染模块 + virtual const bool IsPerFrame () {return false;} ///<是否每帧运行 + virtual const bool IsRender () {return false;} ///<是否为渲染模块 - const bool IsInit ()const{return module_init;} ///<是否已经初始化 - const bool IsEnable ()const noexcept{return module_enable;} ///<当前模块是否启用 - const bool IsReady ()const noexcept{return module_ready;} ///<当前模块是否准备好 + const bool IsInited ()const {return module_inited;} ///<是否已经初始化 + const bool IsEnabled ()const noexcept{return module_enabled;} ///<当前模块是否启用 + const bool IsReady ()const noexcept{return module_ready;} ///<当前模块是否准备好 public: @@ -105,7 +103,7 @@ public: GraphModule(GraphModuleManager *gmm,const AnsiIDName &name); virtual ~GraphModule(); - virtual bool Init(){module_init=true;return true;} ///<初始化当前模块 + virtual bool Init(){module_inited=true;return true;} ///<初始化当前模块 const int compare(const GraphModule &gm)const override { diff --git a/src/SceneGraph/RenderFramework.cpp b/src/SceneGraph/RenderFramework.cpp index 520820c4..70e01556 100644 --- a/src/SceneGraph/RenderFramework.cpp +++ b/src/SceneGraph/RenderFramework.cpp @@ -12,8 +12,8 @@ VK_NAMESPACE_BEGIN bool InitShaderCompiler(); void CloseShaderCompiler(); -GraphModuleManager *InitGraphModuleManager(GPUDevice *dev); -bool ClearGraphModuleManager(GPUDevice *dev); +GraphModuleManager *InitGraphModuleManager(RenderFramework *); +bool ClearGraphModuleManager(RenderFramework *); namespace { @@ -40,7 +40,7 @@ RenderFramework::~RenderFramework() { // if(swapchain_module)graph_module_manager->ReleaseModule(swapchain_module); - ClearGraphModuleManager(device); + ClearGraphModuleManager(this); CloseShaderCompiler(); } @@ -56,7 +56,7 @@ void RenderFramework::BeginFrame() for(GraphModule *rm:per_frame_module_list) { - if(rm->IsEnable()) + if(rm->IsEnabled()) rm->OnPreFrame(); } @@ -69,7 +69,7 @@ void RenderFramework::EndFrame() for(GraphModule *rm:per_frame_module_list) { - if(rm->IsEnable()) + if(rm->IsEnabled()) rm->OnPostFrame(); } @@ -92,7 +92,7 @@ void RenderFramework::MainLoop() for(RenderModule *rm:render_module_list) { - if(rm->IsEnable()) + if(rm->IsEnabled()) rm->OnFrameRender(delta_time,rcb); } @@ -148,7 +148,7 @@ bool RenderFramework::Init(uint w,uint h,const OSString &app_name) if(!device) return(false); - graph_module_manager=InitGraphModuleManager(device,this); + graph_module_manager=InitGraphModuleManager(this); render_pass_manager =graph_module_manager->GetModule(true); texture_manager =graph_module_manager->GetModule(true); diff --git a/src/SceneGraph/module/GraphModuleManager.cpp b/src/SceneGraph/module/GraphModuleManager.cpp index d83ac09c..743581f7 100644 --- a/src/SceneGraph/module/GraphModuleManager.cpp +++ b/src/SceneGraph/module/GraphModuleManager.cpp @@ -8,19 +8,19 @@ void ClearGraphModuleFactory(); namespace { - using GraphModuleManagerMap=Map; + using GraphModuleManagerMap=Map; static GraphModuleManagerMap *graph_module_manager_map=nullptr; } -GraphModuleManager *InitGraphModuleManager(GPUDevice *dev) +GraphModuleManager *InitGraphModuleManager(RenderFramework *rf) { - if(!dev) + if(!rf) return(nullptr); if(graph_module_manager_map) { - if(graph_module_manager_map->ContainsKey(dev)) + if(graph_module_manager_map->ContainsKey(rf)) return(nullptr); } else @@ -31,16 +31,16 @@ GraphModuleManager *InitGraphModuleManager(GPUDevice *dev) graph_module_manager_map=new GraphModuleManagerMap; } - GraphModuleManager *gmm=new GraphModuleManager(dev); + GraphModuleManager *gmm=new GraphModuleManager(rf); - graph_module_manager_map->Add(dev,gmm); + graph_module_manager_map->Add(rf,gmm); return gmm; } -bool ClearGraphModuleManager(GPUDevice *dev) +bool ClearGraphModuleManager(RenderFramework *rf) { - if(!dev) + if(!rf) return(false); if(!graph_module_manager_map) @@ -48,10 +48,10 @@ bool ClearGraphModuleManager(GPUDevice *dev) GraphModuleManager *gmm; - if(!graph_module_manager_map->Get(dev,gmm)) + if(!graph_module_manager_map->Get(rf,gmm)) return(false); - graph_module_manager_map->DeleteByKey(dev); + graph_module_manager_map->DeleteByKey(rf); delete gmm; @@ -64,9 +64,9 @@ bool ClearGraphModuleManager(GPUDevice *dev) return(true); } -GraphModuleManager *GetGraphModuleManager(GPUDevice *dev) +GraphModuleManager *GetGraphModuleManager(RenderFramework *rf) { - if(!dev) + if(!rf) return(nullptr); if(!graph_module_manager_map) @@ -74,7 +74,7 @@ GraphModuleManager *GetGraphModuleManager(GPUDevice *dev) GraphModuleManager *gmm; - if(graph_module_manager_map->Get(dev,gmm)) + if(graph_module_manager_map->Get(rf,gmm)) return gmm; return(nullptr);