[WIP]
This commit is contained in:
parent
76103a869b
commit
baa2e758f2
@ -1,10 +1,11 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include<hgl/graph/BlendMode.h>
|
|
||||||
#include<hgl/type/List.h>
|
#include<hgl/type/List.h>
|
||||||
|
#include<hgl/platform/Window.h>
|
||||||
|
#include<hgl/graph/BlendMode.h>
|
||||||
#include<hgl/graph/ViewportInfo.h>
|
#include<hgl/graph/ViewportInfo.h>
|
||||||
#include<hgl/graph/module/GraphModule.h>
|
#include<hgl/graph/module/GraphModuleMap.h>
|
||||||
#include<hgl/io/event/WindowEvent.h>
|
#include<hgl/graph/VKDevice.h>
|
||||||
|
|
||||||
VK_NAMESPACE_BEGIN
|
VK_NAMESPACE_BEGIN
|
||||||
|
|
||||||
@ -34,9 +35,7 @@ protected:
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
GraphModuleManager *graph_module_manager=nullptr;
|
GraphModulesMap graph_module_map;
|
||||||
|
|
||||||
ObjectList<GraphModule> module_list;
|
|
||||||
|
|
||||||
List<GraphModule *> per_frame_module_list;
|
List<GraphModule *> per_frame_module_list;
|
||||||
List<RenderModule *> render_module_list;
|
List<RenderModule *> render_module_list;
|
||||||
@ -59,35 +58,39 @@ private:
|
|||||||
double last_time =0;
|
double last_time =0;
|
||||||
double cur_time =0;
|
double cur_time =0;
|
||||||
|
|
||||||
uint64 frame_count =0;
|
int64 frame_count =0;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
const uint64 GetFrameCount ()const noexcept{return frame_count;} ///<取得当前帧数
|
const int64 GetFrameCount ()const noexcept{return frame_count;} ///<取得当前帧数
|
||||||
void RestartFrameCount ()noexcept{frame_count=0;} ///<重新开始统计帧数
|
void RestartFrameCount ()noexcept{frame_count=0;} ///<重新开始统计帧数
|
||||||
|
|
||||||
public: //module
|
public: //module
|
||||||
|
|
||||||
template<typename T> T *GetModule(){return graph_module_manager->GetModule<T>(false);} ///<获取指定类型的模块
|
template<typename T>
|
||||||
|
T * GetModule(){return graph_module_map.Get<T>();} ///<获取指定类型的模块
|
||||||
|
GraphModule * GetModule(const AnsiIDName &name,bool create=false); ///<获取指定名称的模块
|
||||||
|
|
||||||
template<typename T> T *AddModule()
|
//template<typename T> T *AddModule()
|
||||||
{
|
//{
|
||||||
T *tm=new T(graph_module_manager);
|
// T *tm=new T(graph_module_manager);
|
||||||
|
|
||||||
module_list.Add(tm);
|
// module_list.Add(tm);
|
||||||
|
|
||||||
if(tm->IsPerFrame())
|
// if(tm->IsPerFrame())
|
||||||
per_frame_module_list.Add(tm);
|
// per_frame_module_list.Add(tm);
|
||||||
|
|
||||||
if(tm->IsRender())
|
// if(tm->IsRender())
|
||||||
render_module_list.Add(tm);
|
// render_module_list.Add(tm);
|
||||||
|
|
||||||
return tm;
|
// return tm;
|
||||||
}
|
//}
|
||||||
|
|
||||||
GPUDevice * GetDevice (){return device;}
|
GPUDevice * GetDevice () {return device;}
|
||||||
VkDevice GetVkDevice (){return device->GetDevice();}
|
VkDevice GetVkDevice ()const {return device->GetDevice();}
|
||||||
SwapchainModule * GetSwapchain(){return swapchain_module;} ///<取得Swapchain模块
|
const GPUPhysicalDevice * GetPhysicalDevice ()const {return device->GetPhysicalDevice();} ///<取得物理设备
|
||||||
|
GPUDeviceAttribute *GetDeviceAttribute () {return device->GetDeviceAttribute();} ///<取得设备属性
|
||||||
|
SwapchainModule * GetSwapchain () {return swapchain_module;} ///<取得Swapchain模块
|
||||||
|
|
||||||
public: //manager
|
public: //manager
|
||||||
|
|
||||||
@ -104,7 +107,14 @@ public:
|
|||||||
|
|
||||||
NO_COPY_NO_MOVE(RenderFramework)
|
NO_COPY_NO_MOVE(RenderFramework)
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
RenderFramework();
|
RenderFramework();
|
||||||
|
|
||||||
|
friend RenderFramework *CreateRenderFramework();
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
virtual ~RenderFramework();
|
virtual ~RenderFramework();
|
||||||
|
|
||||||
virtual bool Init(uint w,uint h,const OSString &app_name); ///<初始化
|
virtual bool Init(uint w,uint h,const OSString &app_name); ///<初始化
|
||||||
@ -130,4 +140,6 @@ public: //TileData
|
|||||||
TileFont *CreateTileFont(FontSource *fs,int limit_count=-1); ///<创建一个Tile字体
|
TileFont *CreateTileFont(FontSource *fs,int limit_count=-1); ///<创建一个Tile字体
|
||||||
};//class RenderFramework
|
};//class RenderFramework
|
||||||
|
|
||||||
|
RenderFramework *CreateRenderFramework();
|
||||||
|
|
||||||
VK_NAMESPACE_END
|
VK_NAMESPACE_END
|
||||||
|
@ -26,8 +26,6 @@ private:
|
|||||||
GRAPH_MODULE_CONSTRUCT(RenderPassManager)
|
GRAPH_MODULE_CONSTRUCT(RenderPassManager)
|
||||||
~RenderPassManager();
|
~RenderPassManager();
|
||||||
|
|
||||||
bool Init() override;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
RenderPass * CreateRenderPass( const List<VkAttachmentDescription> &desc_list,
|
RenderPass * CreateRenderPass( const List<VkAttachmentDescription> &desc_list,
|
||||||
|
@ -10,6 +10,10 @@
|
|||||||
|
|
||||||
VK_NAMESPACE_BEGIN
|
VK_NAMESPACE_BEGIN
|
||||||
|
|
||||||
|
struct TextureManagerData
|
||||||
|
{
|
||||||
|
};
|
||||||
|
|
||||||
class TextureManager:public GraphModule
|
class TextureManager:public GraphModule
|
||||||
{
|
{
|
||||||
DeviceQueue *texture_queue=nullptr;
|
DeviceQueue *texture_queue=nullptr;
|
||||||
@ -40,10 +44,6 @@ public:
|
|||||||
GRAPH_MODULE_CONSTRUCT(TextureManager)
|
GRAPH_MODULE_CONSTRUCT(TextureManager)
|
||||||
virtual ~TextureManager();
|
virtual ~TextureManager();
|
||||||
|
|
||||||
static const char **GetDependentModules();
|
|
||||||
|
|
||||||
bool Init() override;
|
|
||||||
|
|
||||||
const VkFormatProperties GetFormatProperties(const VkFormat)const;
|
const VkFormatProperties GetFormatProperties(const VkFormat)const;
|
||||||
|
|
||||||
public: //Buffer
|
public: //Buffer
|
||||||
|
@ -1,107 +1,19 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include<hgl/graph/VK.h>
|
#include<hgl/graph/RenderFramework.h>
|
||||||
#include<hgl/graph/VKDevice.h>
|
#include<initializer_list>
|
||||||
#include<hgl/type/IDName.h>
|
|
||||||
#include<hgl/type/StrChar.h>
|
|
||||||
|
|
||||||
VK_NAMESPACE_BEGIN
|
VK_NAMESPACE_BEGIN
|
||||||
|
|
||||||
class RenderCmdBuffer;
|
class RenderCmdBuffer;
|
||||||
class GraphModule;
|
|
||||||
|
|
||||||
class RenderFramework;
|
class RenderFramework;
|
||||||
|
|
||||||
struct GraphModulesMap
|
using GraphModuleHashList=std::initializer_list<size_t>;
|
||||||
|
|
||||||
|
class GraphModule
|
||||||
{
|
{
|
||||||
SortedSet<GraphModule *> gm_set;
|
RenderFramework *render_framework;
|
||||||
|
|
||||||
Map<AnsiIDName,GraphModule *> gm_map_by_name;
|
|
||||||
Map<size_t,GraphModule *> gm_map_by_hash;
|
|
||||||
|
|
||||||
List<GraphModule *> gm_list; //按创建顺序记录,用于倒序释放
|
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
bool Add(GraphModule *gm);
|
|
||||||
|
|
||||||
const bool IsEmpty()const
|
|
||||||
{
|
|
||||||
return gm_set.IsEmpty();
|
|
||||||
}
|
|
||||||
|
|
||||||
GraphModule *Get(const AnsiIDName &name)const
|
|
||||||
{
|
|
||||||
GraphModule *gm;
|
|
||||||
|
|
||||||
if(gm_map_by_name.Get(name,gm))
|
|
||||||
return gm;
|
|
||||||
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
T *Get()const
|
|
||||||
{
|
|
||||||
GraphModule *gm;
|
|
||||||
|
|
||||||
return gm_map_by_hash.Get(GetTypeHash<T>(),gm)?(T *)gm:nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
const bool IsLoaded(const AnsiIDName &name)const{return gm_map_by_name.ContainsKey(name);}
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
const bool IsLoaded()const{return gm_map_by_hash.ContainsKey(T::GetTypeHash());}
|
|
||||||
|
|
||||||
bool Release(GraphModule *gm);
|
|
||||||
|
|
||||||
void Destory();
|
|
||||||
};
|
|
||||||
|
|
||||||
class GraphModuleManager
|
|
||||||
{
|
|
||||||
GPUDevice *device;
|
|
||||||
RenderFramework *framework;
|
|
||||||
|
|
||||||
GraphModulesMap graph_module_map; ///<模块映射表
|
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
GraphModuleManager(RenderFramework *);
|
|
||||||
virtual ~GraphModuleManager();
|
|
||||||
|
|
||||||
GPUDevice * GetDevice ()noexcept {return device;} ///<取得GPU设备
|
|
||||||
VkDevice GetVkDevice ()const {return device->GetDevice();}
|
|
||||||
const GPUPhysicalDevice * GetPhysicalDevice ()const {return device->GetPhysicalDevice();} ///<取得物理设备
|
|
||||||
GPUDeviceAttribute *GetDeviceAttribute () {return device->GetDeviceAttribute();} ///<取得设备属性
|
|
||||||
|
|
||||||
RenderFramework * GetFramework () {return framework;} ///<取得渲染框架
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取指定名称的模块
|
|
||||||
* @param create 如果不存在,是否创建新的
|
|
||||||
*/
|
|
||||||
GraphModule *GetModule(const AnsiIDName &name,bool create); ///<获取指定名称的模块
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取指定类型的模块
|
|
||||||
* @param create 如果不存在,是否创建新的
|
|
||||||
*/
|
|
||||||
template<typename T>
|
|
||||||
T *GetModule(bool create=false){return (T *)GetModule(T::GetModuleName(),create);} ///<获取指定类型的模块
|
|
||||||
|
|
||||||
void ReleaseModule(GraphModule *); ///<释放指定模块
|
|
||||||
|
|
||||||
public: //事件
|
|
||||||
|
|
||||||
void OnResize(const VkExtent2D &);
|
|
||||||
};//class GraphModuleManager
|
|
||||||
|
|
||||||
GraphModuleManager *GetGraphModuleManager(RenderFramework *);
|
|
||||||
|
|
||||||
class GraphModule:public Comparator<GraphModule>
|
|
||||||
{
|
|
||||||
GraphModuleManager *module_manager;
|
|
||||||
|
|
||||||
AnsiIDName module_name;
|
AnsiIDName module_name;
|
||||||
|
|
||||||
@ -111,10 +23,9 @@ class GraphModule:public Comparator<GraphModule>
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
GraphModule *GetModule(const AnsiIDName &name){return module_manager->GetModule(name,false);} ///<获取指定名称的模块
|
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
T *GetModule(){return module_manager->GetModule<T>();} ///<获取指定类型的模块
|
T * GetModule(bool create=false){return render_framework->GetModule<T>(create);} ///<获取指定类型的模块
|
||||||
|
GraphModule * GetModule(const AnsiIDName &name,bool create=false); ///<获取指定名称的模块
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
@ -123,13 +34,12 @@ protected:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
GraphModuleManager *GetManager () {return module_manager;} ///<取得模块管理器
|
GPUDevice * GetDevice () {return render_framework->GetDevice();} ///<取得GPU设备
|
||||||
GPUDevice * GetDevice () {return module_manager->GetDevice();} ///<取得GPU设备
|
VkDevice GetVkDevice ()const {return render_framework->GetVkDevice();} ///<取得VkDevice
|
||||||
VkDevice GetVkDevice ()const {return module_manager->GetVkDevice();} ///<取得VkDevice
|
const GPUPhysicalDevice * GetPhysicalDevice ()const {return render_framework->GetPhysicalDevice();} ///<取得物理设备
|
||||||
const GPUPhysicalDevice * GetPhysicalDevice ()const {return module_manager->GetPhysicalDevice();} ///<取得物理设备
|
GPUDeviceAttribute *GetDeviceAttribute () {return render_framework->GetDeviceAttribute();} ///<取得设备属性
|
||||||
GPUDeviceAttribute *GetDeviceAttribute () {return module_manager->GetDeviceAttribute();} ///<取得设备属性
|
|
||||||
|
|
||||||
RenderFramework * GetFramework () {return module_manager->GetFramework();} ///<取得渲染框架
|
RenderFramework * GetFramework () {return render_framework;} ///<取得渲染框架
|
||||||
|
|
||||||
const AnsiIDName & GetName ()const {return module_name;} ///<取得模块名称(标准通用的名称,比如Upscale,供通用模块使用)
|
const AnsiIDName & GetName ()const {return module_name;} ///<取得模块名称(标准通用的名称,比如Upscale,供通用模块使用)
|
||||||
virtual const AnsiIDName & GetFullName ()const {return module_name;} ///<取得名称(完整的私有名称,比如FSR3Upscale,DLSS3Upscale)
|
virtual const AnsiIDName & GetFullName ()const {return module_name;} ///<取得名称(完整的私有名称,比如FSR3Upscale,DLSS3Upscale)
|
||||||
@ -145,29 +55,17 @@ public:
|
|||||||
|
|
||||||
NO_COPY_NO_MOVE(GraphModule)
|
NO_COPY_NO_MOVE(GraphModule)
|
||||||
|
|
||||||
GraphModule(GraphModuleManager *gmm,const AnsiIDName &name);
|
protected:
|
||||||
|
|
||||||
|
GraphModule(RenderFramework *rf,const AnsiIDName &name);
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
virtual ~GraphModule();
|
virtual ~GraphModule();
|
||||||
|
|
||||||
virtual const size_t GetTypeHash()const=0;
|
virtual const size_t GetTypeHash()const=0;
|
||||||
|
|
||||||
virtual bool Init()=0; ///<初始化当前模块
|
static const GraphModuleHashList GetDependentModules(){return {};} ///<取得依赖的模块列表
|
||||||
|
|
||||||
static const char **GetDependentModules(){return nullptr;} ///<取得依赖的模块列表
|
|
||||||
|
|
||||||
const int compare(const GraphModule &gm)const override
|
|
||||||
{
|
|
||||||
const char **dependent_modules_list=GetDependentModules();
|
|
||||||
|
|
||||||
if(!dependent_modules_list)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
const char *self_module_name=gm.GetName().ToString();
|
|
||||||
|
|
||||||
if(string_in_list(dependent_modules_list,self_module_name))
|
|
||||||
return 1;//如果我依赖于他,那么我比他大
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public: //回调事件
|
public: //回调事件
|
||||||
|
|
||||||
@ -178,28 +76,43 @@ public: //回调事件
|
|||||||
virtual void OnPostFrame(){} ///<帧绘制后回调
|
virtual void OnPostFrame(){} ///<帧绘制后回调
|
||||||
};//class GraphModule
|
};//class GraphModule
|
||||||
|
|
||||||
#define GRAPH_MODULE_CONSTRUCT(name) public:\
|
using GraphModuleMapByIDName=Map<AnsiIDName,GraphModule *>;
|
||||||
NO_COPY_NO_MOVE(name) \
|
|
||||||
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); \
|
|
||||||
return id_name; \
|
|
||||||
} \
|
|
||||||
\
|
|
||||||
name(GraphModuleManager *gmm):GraphModule(gmm,GetModuleName()){}
|
|
||||||
|
|
||||||
#define RENDER_MODULE_CONSTRUCT(name) public:\
|
//template<typename T,typename BASE> class GraphModuleInherit:public BASE
|
||||||
|
//{
|
||||||
|
//public:
|
||||||
|
//
|
||||||
|
// GraphModuleInherit(RenderFramework *rf):BASE(rf,typeid(T))
|
||||||
|
// {}
|
||||||
|
//
|
||||||
|
// static const size_t StaticHash()
|
||||||
|
// {
|
||||||
|
// return typeid(T).hash_code();
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
//};//class GraphModuleInherit
|
||||||
|
|
||||||
|
#define GRAPH_MODULE_CREATE_FUNC(name) name *name::CreateModule(RenderFramework *rf,GraphModuleMapByIDName &dep_modules)
|
||||||
|
|
||||||
|
#define GRAPH_BASE_MODULE_CONSTRUCT(name,base_class) public:\
|
||||||
|
NO_COPY_NO_MOVE(name) \
|
||||||
static const size_t StaticHash(){return typeid(name).hash_code();} \
|
static const size_t StaticHash(){return typeid(name).hash_code();} \
|
||||||
const size_t GetTypeHash()const override{return name::StaticHash();} \
|
const size_t GetTypeHash()const override{return name::StaticHash();} \
|
||||||
NO_COPY_NO_MOVE(name) \
|
|
||||||
static const AnsiIDName &GetModuleName() \
|
static const AnsiIDName &GetModuleName() \
|
||||||
{ \
|
{ \
|
||||||
static const AnsiIDName id_name(#name); \
|
static const AnsiIDName id_name(#name); \
|
||||||
return id_name; \
|
return id_name; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
name(GraphModuleManager *gmm):RenderModule(gmm,GetModuleName()){}
|
private: \
|
||||||
|
name(RenderFramework *rf):base_class(rf,GetModuleName()){} \
|
||||||
|
\
|
||||||
|
public: \
|
||||||
|
static name *CreateModule(RenderFramework *rf,GraphModuleMapByIDName &); \
|
||||||
|
static const GraphModuleHashList GetDependentModules();
|
||||||
|
|
||||||
|
|
||||||
|
#define GRAPH_MODULE_CONSTRUCT(name) GRAPH_BASE_MODULE_CONSTRUCT(name,GraphModule)
|
||||||
|
#define RENDER_MODULE_CONSTRUCT(name) GRAPH_BASE_MODULE_CONSTRUCT(name,RenderModule)
|
||||||
|
|
||||||
VK_NAMESPACE_END
|
VK_NAMESPACE_END
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
#include<hgl/graph/VKNamespace.h>
|
#include<hgl/graph/VKNamespace.h>
|
||||||
#include<hgl/type/IDName.h>
|
#include<hgl/type/IDName.h>
|
||||||
#include<hgl/graph/module/GraphModule.h>
|
#include<hgl/graph/module/GraphModule.h>
|
||||||
|
#include<hgl/graph/RenderFramework.h>
|
||||||
|
|
||||||
VK_NAMESPACE_BEGIN
|
VK_NAMESPACE_BEGIN
|
||||||
|
|
||||||
@ -13,7 +14,7 @@ public:
|
|||||||
GraphModuleFactory()=default;
|
GraphModuleFactory()=default;
|
||||||
virtual ~GraphModuleFactory()=default;
|
virtual ~GraphModuleFactory()=default;
|
||||||
|
|
||||||
virtual GraphModule *Create(GraphModuleManager *)=0;
|
virtual GraphModule *Create(RenderFramework *)=0;
|
||||||
};//class GraphModuleFactory
|
};//class GraphModuleFactory
|
||||||
|
|
||||||
bool RegistryGraphModuleFactory(const char *module_name,GraphModuleFactory *);
|
bool RegistryGraphModuleFactory(const char *module_name,GraphModuleFactory *);
|
||||||
@ -22,9 +23,9 @@ template<typename T> class RegistryGraphModule:public GraphModuleFactory
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
GraphModule *Create(GraphModuleManager *gmm) override
|
GraphModule *Create(RenderFramework *rf) override
|
||||||
{
|
{
|
||||||
if(!gmm)
|
if(!rf)
|
||||||
return(nullptr);
|
return(nullptr);
|
||||||
|
|
||||||
Map<AnsiIDName,GraphModule *> dgm_map;
|
Map<AnsiIDName,GraphModule *> dgm_map;
|
||||||
@ -37,7 +38,7 @@ public:
|
|||||||
{
|
{
|
||||||
for(const AnsiIDName &name:dependent_modules)
|
for(const AnsiIDName &name:dependent_modules)
|
||||||
{
|
{
|
||||||
GraphModule *dgm=gmm->GetModule(name,true);
|
GraphModule *dgm=rf->GetModule(name,true);
|
||||||
|
|
||||||
if(!dgm)
|
if(!dgm)
|
||||||
return(nullptr);
|
return(nullptr);
|
||||||
@ -47,13 +48,7 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
GraphModule *gm=new T(gmm);
|
T *gm=T::CreateModule(rf,dgm_map);
|
||||||
|
|
||||||
if(!gm->Init())
|
|
||||||
{
|
|
||||||
delete gm;
|
|
||||||
return(nullptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
return(gm);
|
return(gm);
|
||||||
}
|
}
|
||||||
|
56
inc/hgl/graph/module/GraphModuleMap.h
Normal file
56
inc/hgl/graph/module/GraphModuleMap.h
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include<hgl/graph/VK.h>
|
||||||
|
#include<hgl/type/IDName.h>
|
||||||
|
|
||||||
|
VK_NAMESPACE_BEGIN
|
||||||
|
|
||||||
|
class GraphModule;
|
||||||
|
|
||||||
|
class GraphModulesMap
|
||||||
|
{
|
||||||
|
SortedSet<GraphModule *> gm_set;
|
||||||
|
|
||||||
|
Map<AnsiIDName,GraphModule *> gm_map_by_name;
|
||||||
|
Map<size_t,GraphModule *> gm_map_by_hash;
|
||||||
|
|
||||||
|
List<GraphModule *> gm_list; //按创建顺序记录,用于倒序释放
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
bool Add(GraphModule *gm);
|
||||||
|
|
||||||
|
const bool IsEmpty()const
|
||||||
|
{
|
||||||
|
return gm_set.IsEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
GraphModule *Get(const AnsiIDName &name)
|
||||||
|
{
|
||||||
|
GraphModule *gm;
|
||||||
|
|
||||||
|
if(gm_map_by_name.Get(name,gm))
|
||||||
|
return gm;
|
||||||
|
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
T *Get()
|
||||||
|
{
|
||||||
|
GraphModule *gm;
|
||||||
|
|
||||||
|
return gm_map_by_hash.Get(GetTypeHash<T>(),gm)?(T *)gm:nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
const bool IsLoaded()const{return gm_map_by_hash.ContainsKey(T::GetTypeHash());}
|
||||||
|
|
||||||
|
const bool IsLoaded(const AnsiIDName &name)const{return gm_map_by_name.ContainsKey(name);}
|
||||||
|
|
||||||
|
bool Release(GraphModule *gm); ///<释放一个模块
|
||||||
|
|
||||||
|
void Destory(); ///<销毁所有模块
|
||||||
|
};//class GraphModulesMap
|
||||||
|
|
||||||
|
VK_NAMESPACE_END
|
@ -1,6 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include<hgl/graph/module/RenderModule.h>
|
#include<hgl/graph/module/RenderModule.h>
|
||||||
|
#include<hgl/graph/VKRenderTarget.h>
|
||||||
|
|
||||||
VK_NAMESPACE_BEGIN
|
VK_NAMESPACE_BEGIN
|
||||||
|
|
||||||
@ -32,8 +33,6 @@ public:
|
|||||||
GRAPH_MODULE_CONSTRUCT(SwapchainModule)
|
GRAPH_MODULE_CONSTRUCT(SwapchainModule)
|
||||||
virtual ~SwapchainModule();
|
virtual ~SwapchainModule();
|
||||||
|
|
||||||
bool Init() override;
|
|
||||||
|
|
||||||
bool BeginFrame();
|
bool BeginFrame();
|
||||||
void EndFrame();
|
void EndFrame();
|
||||||
|
|
||||||
|
2
res
2
res
@ -1 +1 @@
|
|||||||
Subproject commit 475d8ad43ceee084cd24f5d0bed59de9f6aa36fd
|
Subproject commit e1a36d78f0eead5f6bb65493432c4690637b991d
|
@ -277,12 +277,12 @@ SOURCE_GROUP("Scene Graph\\Component" FILES ${SG_COMPONENT_HEADER} ${SG_COMPONEN
|
|||||||
SET(SG_MODULE_HEADER_PATH ${SG_INCLUDE_PATH}/module)
|
SET(SG_MODULE_HEADER_PATH ${SG_INCLUDE_PATH}/module)
|
||||||
|
|
||||||
SET(GRAPH_MODULE_HEADER ${SG_MODULE_HEADER_PATH}/GraphModule.h
|
SET(GRAPH_MODULE_HEADER ${SG_MODULE_HEADER_PATH}/GraphModule.h
|
||||||
|
${SG_MODULE_HEADER_PATH}/GraphModuleMap.h
|
||||||
${SG_MODULE_HEADER_PATH}/GraphModuleFactory.h
|
${SG_MODULE_HEADER_PATH}/GraphModuleFactory.h
|
||||||
${SG_MODULE_HEADER_PATH}/RenderModule.h
|
${SG_MODULE_HEADER_PATH}/RenderModule.h
|
||||||
${SG_MODULE_HEADER_PATH}/SwapchainModule.h)
|
${SG_MODULE_HEADER_PATH}/SwapchainModule.h)
|
||||||
|
|
||||||
SET(GRAPH_MODULE_SOURCE module/GraphModule.cpp
|
SET(GRAPH_MODULE_SOURCE module/GraphModule.cpp
|
||||||
module/GraphModuleManager.cpp
|
|
||||||
module/GraphModuleFactory.cpp
|
module/GraphModuleFactory.cpp
|
||||||
module/RenderModule.cpp
|
module/RenderModule.cpp
|
||||||
module/RegistryCommonModule.cpp
|
module/RegistryCommonModule.cpp
|
||||||
|
@ -12,8 +12,16 @@ VK_NAMESPACE_BEGIN
|
|||||||
bool InitShaderCompiler();
|
bool InitShaderCompiler();
|
||||||
void CloseShaderCompiler();
|
void CloseShaderCompiler();
|
||||||
|
|
||||||
GraphModuleManager *InitGraphModuleManager(RenderFramework *);
|
void InitGraphModuleFactory();
|
||||||
bool ClearGraphModuleManager(RenderFramework *);
|
void ClearGraphModuleFactory();
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
static int RENDER_FRAMEWORK_COUNT=0;
|
||||||
|
|
||||||
|
}//namespace
|
||||||
|
|
||||||
|
GraphModule *CreateGraphModule(const AnsiIDName &name,RenderFramework *rf);
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
@ -32,17 +40,43 @@ namespace
|
|||||||
}
|
}
|
||||||
}//namespace
|
}//namespace
|
||||||
|
|
||||||
RenderFramework::RenderFramework()
|
GraphModule *RenderFramework::GetModule(const AnsiIDName &name,bool create)
|
||||||
{
|
{
|
||||||
|
GraphModule *gm=graph_module_map.Get(name);
|
||||||
|
|
||||||
|
if(!gm)
|
||||||
|
{
|
||||||
|
gm=CreateGraphModule(name,this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RenderFramework *CreateRenderFramework()
|
||||||
|
{
|
||||||
|
if(RENDER_FRAMEWORK_COUNT==0)
|
||||||
|
{
|
||||||
|
if(!InitShaderCompiler())
|
||||||
|
return(nullptr);
|
||||||
|
|
||||||
|
InitGraphModuleFactory();
|
||||||
|
RegistryCommonGraphModule();
|
||||||
|
}
|
||||||
|
|
||||||
|
++RENDER_FRAMEWORK_COUNT;
|
||||||
|
}
|
||||||
|
|
||||||
|
RenderFramework::RenderFramework(){}
|
||||||
|
|
||||||
RenderFramework::~RenderFramework()
|
RenderFramework::~RenderFramework()
|
||||||
{
|
{
|
||||||
// if(swapchain_module)graph_module_manager->ReleaseModule(swapchain_module);
|
graph_module_map.Destory();
|
||||||
|
|
||||||
ClearGraphModuleManager(this);
|
--RENDER_FRAMEWORK_COUNT;
|
||||||
|
|
||||||
CloseShaderCompiler();
|
if(RENDER_FRAMEWORK_COUNT==0)
|
||||||
|
{
|
||||||
|
ClearGraphModuleFactory();
|
||||||
|
CloseShaderCompiler();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void RenderFramework::StartTime()
|
void RenderFramework::StartTime()
|
||||||
|
@ -9,28 +9,21 @@ const VkFormatProperties TextureManager::GetFormatProperties(const VkFormat form
|
|||||||
return GetPhysicalDevice()->GetFormatProperties(format);
|
return GetPhysicalDevice()->GetFormatProperties(format);
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace
|
const GraphModuleHashList TextureManager::GetDependentModules() ///<取得依赖的模块列表
|
||||||
{
|
{
|
||||||
const char *tex_manager_dep[]
|
return {RenderPassManager::StaticHash()};
|
||||||
{
|
|
||||||
"RenderPassManager",
|
|
||||||
nullptr //一定要0结尾
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const char **TextureManager::GetDependentModules() ///<取得依赖的模块列表
|
GRAPH_MODULE_CREATE_FUNC(TextureManager)
|
||||||
{
|
{
|
||||||
return tex_manager_dep;
|
GPUDevice *dev=rf->GetDevice();
|
||||||
}
|
|
||||||
|
|
||||||
bool TextureManager::Init()
|
|
||||||
{
|
|
||||||
GPUDevice *dev=GetDevice();
|
|
||||||
|
|
||||||
if(!dev)
|
if(!dev)
|
||||||
return(false);
|
return(false);
|
||||||
|
|
||||||
texture_cmd_buf=dev->CreateTextureCommandBuffer(GetPhysicalDevice()->GetDeviceName()+AnsiString(":TexCmdBuffer"));
|
auto phy_device=rf->GetPhysicalDevice();
|
||||||
|
|
||||||
|
texture_cmd_buf=dev->CreateTextureCommandBuffer(phy_device->GetDeviceName()+AnsiString(":TexCmdBuffer"));
|
||||||
|
|
||||||
if(!texture_cmd_buf)
|
if(!texture_cmd_buf)
|
||||||
return(false);
|
return(false);
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
#include<hgl/graph/module/GraphModule.h>
|
#include<hgl/graph/module/GraphModule.h>
|
||||||
|
#include<hgl/graph/RenderFramework.h>
|
||||||
#include<hgl/graph/VKDevice.h>
|
#include<hgl/graph/VKDevice.h>
|
||||||
#include<hgl/log/LogInfo.h>
|
#include<hgl/log/LogInfo.h>
|
||||||
|
|
||||||
@ -54,9 +55,9 @@ bool GraphModulesMap::Release(GraphModule *gm)
|
|||||||
return(true);
|
return(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
GraphModule::GraphModule(GraphModuleManager *gmm,const AnsiIDName &name)
|
GraphModule::GraphModule(RenderFramework *rf,const AnsiIDName &name)
|
||||||
{
|
{
|
||||||
module_manager=gmm;
|
render_framework=rf;
|
||||||
module_name=name;
|
module_name=name;
|
||||||
|
|
||||||
LOG_INFO("GraphModule::GraphModule: "+AnsiString(module_name.GetName()))
|
LOG_INFO("GraphModule::GraphModule: "+AnsiString(module_name.GetName()))
|
||||||
@ -67,4 +68,9 @@ GraphModule::~GraphModule()
|
|||||||
LOG_INFO("GraphModule::~GraphModule: "+AnsiString(module_name.GetName()))
|
LOG_INFO("GraphModule::~GraphModule: "+AnsiString(module_name.GetName()))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GraphModule *GraphModule::GetModule(const AnsiIDName &name,bool create)
|
||||||
|
{
|
||||||
|
render_framework->GetModule(name,create);
|
||||||
|
}
|
||||||
|
|
||||||
VK_NAMESPACE_END
|
VK_NAMESPACE_END
|
||||||
|
@ -43,9 +43,9 @@ bool RegistryGraphModuleFactory(const char *module_name,GraphModuleFactory *gmf)
|
|||||||
return(true);
|
return(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
GraphModule *CreateGraphModule(const AnsiIDName &name,GraphModuleManager *gmm)
|
GraphModule *CreateGraphModule(const AnsiIDName &name,RenderFramework *rf)
|
||||||
{
|
{
|
||||||
if(!gmm)
|
if(!rf)
|
||||||
return(nullptr);
|
return(nullptr);
|
||||||
|
|
||||||
if(!gmf_map)
|
if(!gmf_map)
|
||||||
@ -56,7 +56,7 @@ GraphModule *CreateGraphModule(const AnsiIDName &name,GraphModuleManager *gmm)
|
|||||||
if(!gmf_map->Get(name,gmf))
|
if(!gmf_map->Get(name,gmf))
|
||||||
return(nullptr);
|
return(nullptr);
|
||||||
|
|
||||||
return gmf->Create(gmm);
|
return gmf->Create(rf);
|
||||||
}
|
}
|
||||||
|
|
||||||
VK_NAMESPACE_END
|
VK_NAMESPACE_END
|
||||||
|
@ -1,134 +0,0 @@
|
|||||||
#include<hgl/graph/module/GraphModule.h>
|
|
||||||
#include<hgl/graph/RenderFramework.h>
|
|
||||||
#include<hgl/type/Map.h>
|
|
||||||
|
|
||||||
VK_NAMESPACE_BEGIN
|
|
||||||
|
|
||||||
void InitGraphModuleFactory();
|
|
||||||
void ClearGraphModuleFactory();
|
|
||||||
|
|
||||||
namespace
|
|
||||||
{
|
|
||||||
using GraphModuleManagerMap=Map<RenderFramework *,GraphModuleManager *>;
|
|
||||||
|
|
||||||
static GraphModuleManagerMap *graph_module_manager_map=nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
GraphModuleManager *InitGraphModuleManager(RenderFramework *rf)
|
|
||||||
{
|
|
||||||
if(!rf)
|
|
||||||
return(nullptr);
|
|
||||||
|
|
||||||
if(graph_module_manager_map)
|
|
||||||
{
|
|
||||||
if(graph_module_manager_map->ContainsKey(rf))
|
|
||||||
return(nullptr);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
InitGraphModuleFactory();
|
|
||||||
RegistryCommonGraphModule();
|
|
||||||
|
|
||||||
graph_module_manager_map=new GraphModuleManagerMap;
|
|
||||||
}
|
|
||||||
|
|
||||||
GraphModuleManager *gmm=new GraphModuleManager(rf);
|
|
||||||
|
|
||||||
graph_module_manager_map->Add(rf,gmm);
|
|
||||||
|
|
||||||
return gmm;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ClearGraphModuleManager(RenderFramework *rf)
|
|
||||||
{
|
|
||||||
if(!rf)
|
|
||||||
return(false);
|
|
||||||
|
|
||||||
if(!graph_module_manager_map)
|
|
||||||
return(false);
|
|
||||||
|
|
||||||
GraphModuleManager *gmm;
|
|
||||||
|
|
||||||
if(!graph_module_manager_map->Get(rf,gmm))
|
|
||||||
return(false);
|
|
||||||
|
|
||||||
graph_module_manager_map->DeleteByKey(rf);
|
|
||||||
|
|
||||||
delete gmm;
|
|
||||||
|
|
||||||
if(graph_module_manager_map->IsEmpty())
|
|
||||||
{
|
|
||||||
ClearGraphModuleFactory();
|
|
||||||
SAFE_CLEAR(graph_module_manager_map);
|
|
||||||
}
|
|
||||||
|
|
||||||
return(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
GraphModuleManager *GetGraphModuleManager(RenderFramework *rf)
|
|
||||||
{
|
|
||||||
if(!rf)
|
|
||||||
return(nullptr);
|
|
||||||
|
|
||||||
if(!graph_module_manager_map)
|
|
||||||
return(nullptr);
|
|
||||||
|
|
||||||
GraphModuleManager *gmm;
|
|
||||||
|
|
||||||
if(graph_module_manager_map->Get(rf,gmm))
|
|
||||||
return gmm;
|
|
||||||
|
|
||||||
return(nullptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
GraphModule *CreateGraphModule(const AnsiIDName &name,GraphModuleManager *gmm);
|
|
||||||
|
|
||||||
GraphModule *GraphModuleManager::GetModule(const AnsiIDName &name,bool create)
|
|
||||||
{
|
|
||||||
GraphModule *gm=graph_module_map.Get(name);
|
|
||||||
|
|
||||||
if(gm)
|
|
||||||
return gm;
|
|
||||||
|
|
||||||
if(create)
|
|
||||||
{
|
|
||||||
gm=CreateGraphModule(name,this);
|
|
||||||
|
|
||||||
if(gm)
|
|
||||||
graph_module_map.Add(gm);
|
|
||||||
}
|
|
||||||
|
|
||||||
return gm;
|
|
||||||
}
|
|
||||||
|
|
||||||
GraphModuleManager::GraphModuleManager(RenderFramework *rf)
|
|
||||||
{
|
|
||||||
framework=rf;
|
|
||||||
device=rf->GetDevice();
|
|
||||||
}
|
|
||||||
|
|
||||||
GraphModuleManager::~GraphModuleManager()
|
|
||||||
{
|
|
||||||
graph_module_map.Destory();
|
|
||||||
}
|
|
||||||
|
|
||||||
void GraphModuleManager::ReleaseModule(GraphModule *gm)
|
|
||||||
{
|
|
||||||
if(!gm)
|
|
||||||
return;
|
|
||||||
|
|
||||||
graph_module_map.Release(gm);
|
|
||||||
}
|
|
||||||
|
|
||||||
void GraphModuleManager::OnResize(const VkExtent2D &extent)
|
|
||||||
{
|
|
||||||
if(graph_module_map.IsEmpty())
|
|
||||||
return;
|
|
||||||
|
|
||||||
for(auto *gm:graph_module_map.gm_list)
|
|
||||||
{
|
|
||||||
gm->OnResize(extent);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
VK_NAMESPACE_END
|
|
Loading…
x
Reference in New Issue
Block a user