Use RenderFramework instead of GPUDevice at Init GraphModuleManager

This commit is contained in:
hyzboy 2024-12-16 23:24:08 +08:00
parent 7dd075b495
commit d1c3934beb
3 changed files with 33 additions and 35 deletions

View File

@ -57,7 +57,7 @@ public: //事件
void OnResize(const VkExtent2D &); void OnResize(const VkExtent2D &);
};//class GraphModuleManager };//class GraphModuleManager
GraphModuleManager *GetGraphModuleManager(GPUDevice *); GraphModuleManager *GetGraphModuleManager(RenderFramework *);
class GraphModule:public Comparator<GraphModule> class GraphModule:public Comparator<GraphModule>
{ {
@ -65,22 +65,19 @@ class GraphModule:public Comparator<GraphModule>
AnsiIDName module_name; AnsiIDName module_name;
SortedSet<AnsiIDName> dependent_module; ///<依赖的模块 SortedSet<AnsiIDName> dependent_module; ///<依赖的模块
bool module_init; bool module_inited;
bool module_enable; bool module_enabled;
bool module_ready; bool module_ready;
protected: 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;} virtual void SetModuleReady(bool r){module_ready=r;}
public: public:
virtual const bool IsPerFrame () {return false;} ///<是否每帧运行
virtual const bool IsRender () {return false;} ///<是否为渲染模块
GraphModuleManager *GetManager () {return module_manager;} ///<取得模块管理器 GraphModuleManager *GetManager () {return module_manager;} ///<取得模块管理器
GPUDevice * GetDevice () {return module_manager->GetDevice();} ///<取得GPU设备 GPUDevice * GetDevice () {return module_manager->GetDevice();} ///<取得GPU设备
VkDevice GetVkDevice ()const {return module_manager->GetVkDevice();} ///<取得VkDevice VkDevice GetVkDevice ()const {return module_manager->GetVkDevice();} ///<取得VkDevice
@ -89,14 +86,15 @@ public:
RenderFramework * GetFramework () {return module_manager->GetFramework();} ///<取得渲染框架 RenderFramework * GetFramework () {return module_manager->GetFramework();} ///<取得渲染框架
static const AnsiIDName * GetModuleName (){return nullptr;} ///<取得模块名称(标准通用的名称比如Upscale供通用模块使用) static const AnsiIDName * GetModuleName () {return nullptr;} ///<取得模块名称(标准通用的名称比如Upscale供通用模块使用)
virtual const AnsiIDName * GetName ()const{return &module_name;} ///<取得名称(完整的私有名称比如FSR3Upscale,DLSS3Upscale) 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 IsInited ()const {return module_inited;} ///<是否已经初始化
const bool IsEnable ()const noexcept{return module_enable;} ///<当前模块是否启用 const bool IsEnabled ()const noexcept{return module_enabled;} ///<当前模块是否启用
const bool IsReady ()const noexcept{return module_ready;} ///<当前模块是否准备好 const bool IsReady ()const noexcept{return module_ready;} ///<当前模块是否准备好
public: public:
@ -105,7 +103,7 @@ public:
GraphModule(GraphModuleManager *gmm,const AnsiIDName &name); GraphModule(GraphModuleManager *gmm,const AnsiIDName &name);
virtual ~GraphModule(); 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 const int compare(const GraphModule &gm)const override
{ {

View File

@ -12,8 +12,8 @@ VK_NAMESPACE_BEGIN
bool InitShaderCompiler(); bool InitShaderCompiler();
void CloseShaderCompiler(); void CloseShaderCompiler();
GraphModuleManager *InitGraphModuleManager(GPUDevice *dev); GraphModuleManager *InitGraphModuleManager(RenderFramework *);
bool ClearGraphModuleManager(GPUDevice *dev); bool ClearGraphModuleManager(RenderFramework *);
namespace namespace
{ {
@ -40,7 +40,7 @@ RenderFramework::~RenderFramework()
{ {
// if(swapchain_module)graph_module_manager->ReleaseModule(swapchain_module); // if(swapchain_module)graph_module_manager->ReleaseModule(swapchain_module);
ClearGraphModuleManager(device); ClearGraphModuleManager(this);
CloseShaderCompiler(); CloseShaderCompiler();
} }
@ -56,7 +56,7 @@ void RenderFramework::BeginFrame()
for(GraphModule *rm:per_frame_module_list) for(GraphModule *rm:per_frame_module_list)
{ {
if(rm->IsEnable()) if(rm->IsEnabled())
rm->OnPreFrame(); rm->OnPreFrame();
} }
@ -69,7 +69,7 @@ void RenderFramework::EndFrame()
for(GraphModule *rm:per_frame_module_list) for(GraphModule *rm:per_frame_module_list)
{ {
if(rm->IsEnable()) if(rm->IsEnabled())
rm->OnPostFrame(); rm->OnPostFrame();
} }
@ -92,7 +92,7 @@ void RenderFramework::MainLoop()
for(RenderModule *rm:render_module_list) for(RenderModule *rm:render_module_list)
{ {
if(rm->IsEnable()) if(rm->IsEnabled())
rm->OnFrameRender(delta_time,rcb); rm->OnFrameRender(delta_time,rcb);
} }
@ -148,7 +148,7 @@ bool RenderFramework::Init(uint w,uint h,const OSString &app_name)
if(!device) if(!device)
return(false); return(false);
graph_module_manager=InitGraphModuleManager(device,this); graph_module_manager=InitGraphModuleManager(this);
render_pass_manager =graph_module_manager->GetModule<RenderPassManager>(true); render_pass_manager =graph_module_manager->GetModule<RenderPassManager>(true);
texture_manager =graph_module_manager->GetModule<TextureManager>(true); texture_manager =graph_module_manager->GetModule<TextureManager>(true);

View File

@ -8,19 +8,19 @@ void ClearGraphModuleFactory();
namespace namespace
{ {
using GraphModuleManagerMap=Map<GPUDevice *,GraphModuleManager *>; using GraphModuleManagerMap=Map<RenderFramework *,GraphModuleManager *>;
static GraphModuleManagerMap *graph_module_manager_map=nullptr; static GraphModuleManagerMap *graph_module_manager_map=nullptr;
} }
GraphModuleManager *InitGraphModuleManager(GPUDevice *dev) GraphModuleManager *InitGraphModuleManager(RenderFramework *rf)
{ {
if(!dev) if(!rf)
return(nullptr); return(nullptr);
if(graph_module_manager_map) if(graph_module_manager_map)
{ {
if(graph_module_manager_map->ContainsKey(dev)) if(graph_module_manager_map->ContainsKey(rf))
return(nullptr); return(nullptr);
} }
else else
@ -31,16 +31,16 @@ GraphModuleManager *InitGraphModuleManager(GPUDevice *dev)
graph_module_manager_map=new GraphModuleManagerMap; 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; return gmm;
} }
bool ClearGraphModuleManager(GPUDevice *dev) bool ClearGraphModuleManager(RenderFramework *rf)
{ {
if(!dev) if(!rf)
return(false); return(false);
if(!graph_module_manager_map) if(!graph_module_manager_map)
@ -48,10 +48,10 @@ bool ClearGraphModuleManager(GPUDevice *dev)
GraphModuleManager *gmm; GraphModuleManager *gmm;
if(!graph_module_manager_map->Get(dev,gmm)) if(!graph_module_manager_map->Get(rf,gmm))
return(false); return(false);
graph_module_manager_map->DeleteByKey(dev); graph_module_manager_map->DeleteByKey(rf);
delete gmm; delete gmm;
@ -64,9 +64,9 @@ bool ClearGraphModuleManager(GPUDevice *dev)
return(true); return(true);
} }
GraphModuleManager *GetGraphModuleManager(GPUDevice *dev) GraphModuleManager *GetGraphModuleManager(RenderFramework *rf)
{ {
if(!dev) if(!rf)
return(nullptr); return(nullptr);
if(!graph_module_manager_map) if(!graph_module_manager_map)
@ -74,7 +74,7 @@ GraphModuleManager *GetGraphModuleManager(GPUDevice *dev)
GraphModuleManager *gmm; GraphModuleManager *gmm;
if(graph_module_manager_map->Get(dev,gmm)) if(graph_module_manager_map->Get(rf,gmm))
return gmm; return gmm;
return(nullptr); return(nullptr);