[DON'T WORK] added dependent modules ....

This commit is contained in:
hyzboy 2024-12-17 13:57:21 +08:00
parent d1c3934beb
commit 34846acae0
12 changed files with 150 additions and 23 deletions

@ -1 +1 @@
Subproject commit 85436b5a7b0bc9347fcd3321a6895464470f1353
Subproject commit cf6a54d484436eea700bc4f4ea002ed23eed6dc8

2
CMCore

@ -1 +1 @@
Subproject commit 7295d68a5e6f2b9bc9ad08dc397375850af50bf7
Subproject commit ea101386d3705ee56b7a457b5b828c9f7894487d

View File

@ -26,7 +26,7 @@ private:
GRAPH_MODULE_CONSTRUCT(RenderPassManager)
~RenderPassManager();
bool Init() override;
bool Init(GraphModulesMap *) override;
private:

View File

@ -1,4 +1,4 @@
#pragma once
#pragma once
#include<hgl/graph/module/GraphModule.h>
#include<hgl/type/SortedSet.h>
@ -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;

View File

@ -11,14 +11,40 @@ class GraphModule;
class RenderFramework;
struct GraphModulesMap
{
List<GraphModule *> gm_list;
Map<AnsiIDName,GraphModule *> gm_map_by_name;
Map<size_t,GraphModule *> 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<typename T>
const bool Get(T *&gm)const
{
return gm_map_by_hash.Get(GetTypeHash<T>(),gm);
}
};
class GraphModuleManager
{
GPUDevice *device;
RenderFramework *framework;
List<GraphModule *> module_list; ///<模块列表
Map<AnsiIDName,GraphModule *> graph_module_map; ///<模块映射表
GraphModulesMap graph_module_map; ///<模块映射表
public:
@ -65,12 +91,19 @@ class GraphModule:public Comparator<GraphModule>
AnsiIDName module_name;
SortedSet<AnsiIDName> 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<typename T>
//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<typename T>
T * GetModule(bool create=false){return module_manager->GetModule<T>(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() \
{ \

View File

@ -28,7 +28,27 @@ public:
if(!gmm)
return(nullptr);
GraphModule *gm=new T(gmm);
Map<AnsiIDName,GraphModule *> 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())
{

View File

@ -1,4 +1,4 @@
#pragma once
#pragma once
#include<hgl/graph/module/RenderModule.h>
@ -32,7 +32,7 @@ public:
GRAPH_MODULE_CONSTRUCT(SwapchainModule)
virtual ~SwapchainModule();
bool Init() override;
bool Init(GraphModulesMap *) override;
bool BeginFrame();
void EndFrame();

2
res

@ -1 +1 @@
Subproject commit e1a36d78f0eead5f6bb65493432c4690637b991d
Subproject commit 475d8ad43ceee084cd24f5d0bed59de9f6aa36fd

View File

@ -1,4 +1,4 @@
#include<hgl/graph/VKDevice.h>
#include<hgl/graph/VKDevice.h>
#include<hgl/graph/manager/TextureManager.h>
#include<hgl/graph/manager/RenderPassManager.h>

View File

@ -1,4 +1,4 @@
#include<hgl/graph/manager/RenderPassManager.h>
#include<hgl/graph/manager/RenderPassManager.h>
#include<hgl/graph/VKRenderPass.h>
VK_NAMESPACE_BEGIN
@ -184,8 +184,13 @@ bool CreateDepthAttachment( List<VkAttachmentReference> &ref_list,List<VkAttachm
return(true);
}
bool RenderPassManager::Init()
bool RenderPassManager::Init(GraphModulesMap *gmm)
{
if(!GraphModule::Init(gmm))
return(false);
gmm->Get(rp_manager);
pipeline_cache=GetDeviceAttribute()->pipeline_cache;
hash=CreateRenderPassHash();

View File

@ -1,9 +1,20 @@
#include<hgl/graph/module/GraphModule.h>
#include<hgl/graph/module/GraphModule.h>
#include<hgl/graph/VKDevice.h>
#include<hgl/log/LogInfo.h>
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

View File

@ -1,4 +1,5 @@
#include<hgl/graph/module/GraphModule.h>
#include<hgl/graph/module/GraphModule.h>
#include<hgl/graph/RenderFramework.h>
#include<hgl/type/Map.h>
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()