diff --git a/inc/hgl/graph/VKDevice.h b/inc/hgl/graph/VKDevice.h index b9cf7446..b495aee8 100644 --- a/inc/hgl/graph/VKDevice.h +++ b/inc/hgl/graph/VKDevice.h @@ -18,6 +18,9 @@ #include VK_NAMESPACE_BEGIN + +class SwapchainModule; + class TileData; class TileFont; class FontSource; @@ -30,7 +33,14 @@ struct CopyBufferToImageInfo; class GPUDevice { +private: //module + GraphModuleManager *graph_module_manager; + + SwapchainModule *swapchain_module; + +private: + GPUDeviceAttribute *attr; DeviceQueue *texture_queue; diff --git a/inc/hgl/graph/module/GraphModule.h b/inc/hgl/graph/module/GraphModule.h index 2c9fe95a..bcc62154 100644 --- a/inc/hgl/graph/module/GraphModule.h +++ b/inc/hgl/graph/module/GraphModule.h @@ -23,11 +23,12 @@ protected: public: - virtual const bool IsRender()=0; ///<是否为渲染模块 + virtual const bool IsRender(){return false;} ///<是否为渲染模块 GraphModuleManager *GetManager(){return module_manager;} ///<取得模块管理器 - const AnsiString &GetModuleName()const{return module_name;} ///<取得模块名称 + static const char *GetModuleName(){return nullptr;} ///<取得模块名称(标准通用的名称,比如Upscale,供通用模块使用) + virtual const char *GetName()const{return module_name.c_str();} ///<取得名称(完整的私有名称,比如FSR3Upscale,DLSS3Upscale) const bool IsEnable ()const noexcept{return module_enable;} ///<当前模块是否启用 const bool IsReady ()const noexcept{return module_ready;} ///<当前模块是否准备好 @@ -36,7 +37,11 @@ public: NO_COPY_NO_MOVE(GraphModule) - GraphModule(const AnsiString &name){module_name=name;} + GraphModule(GraphModuleManager *gmm,const AnsiString &name) + { + module_manager=gmm; + module_name=name; + } virtual ~GraphModule()=default; virtual bool Init(){return true;} ///<初始化当前模块 @@ -57,13 +62,23 @@ class GraphModuleManager Map graph_module_map; +protected: + + GraphModule *GetModule(const AnsiString &name,bool create); + public: GraphModuleManager(GPUDevice *dev){device=dev;} ~GraphModuleManager(); - bool Registry(const AnsiString &name,GraphModule *gm); - GraphModule *GetModule(const AnsiString &name); + /** + * 获取指定类型的模块 + * @param create 如果不存在,是否创建新的 + */ + template T *GetModule(bool create=false) + { + return (T *)GetModule(T::GetModuleName(),create); + } public: //事件 diff --git a/inc/hgl/graph/module/GraphModuleFactory.h b/inc/hgl/graph/module/GraphModuleFactory.h new file mode 100644 index 00000000..2a0d5853 --- /dev/null +++ b/inc/hgl/graph/module/GraphModuleFactory.h @@ -0,0 +1,47 @@ +#pragma once + +#include + +VK_NAMESPACE_BEGIN + +class GraphModule; +class GraphModuleManager; + +class GraphModuleFactory +{ +public: + + GraphModuleFactory()=default; + virtual ~GraphModuleFactory()=default; + + virtual GraphModule *Create(GraphModuleManager *)=0; +};//class GraphModuleFactory + +bool RegistryGraphModuleFactory(const char *module_name,GraphModuleFactory *); + +template class RegistryGraphModule:public GraphModuleFactory +{ + bool registry_success; + +public: + + RegistryGraphModule() + { + registry_success=RegistryGraphModuleFactory(T::GetModuleName(),this); + } + + GraphModule *Create(GraphModuleManager *gmm) override + { + if(!registry_success) + return(nullptr); + + if(!gmm) + return(nullptr); + + return(new T(gmm)); + } +};//template class RegistryGraphModule:public GraphModuleFactory + +#define REGISTRY_GRAPH_MODULE(Class) namespace{static RegistryGraphModule registry_##Class;} + +VK_NAMESPACE_END \ No newline at end of file diff --git a/inc/hgl/graph/module/RenderModule.h b/inc/hgl/graph/module/RenderModule.h index 5cf61a2b..03e16570 100644 --- a/inc/hgl/graph/module/RenderModule.h +++ b/inc/hgl/graph/module/RenderModule.h @@ -11,20 +11,19 @@ VK_NAMESPACE_BEGIN class RenderModule:public GraphModule { VkExtent2D current_extent; - RenderTarget *render_target; public: - + const bool IsRender()const noexcept{return true;} public: NO_COPY_NO_MOVE(RenderModule) - RenderModule(const AnsiString &name):GraphModule(name){} + using GraphModule::GraphModule; virtual ~RenderModule()=default; - - virtual void OnRenderTarget(RenderTarget *rt)override{render_target=rt;} virtual void OnResize(const VkExtent2D &ext)override{current_extent=ext;} };//class RenderModule + +VK_NAMESPACE_END diff --git a/inc/hgl/graph/module/SwapchainModule.h b/inc/hgl/graph/module/SwapchainModule.h new file mode 100644 index 00000000..3a810697 --- /dev/null +++ b/inc/hgl/graph/module/SwapchainModule.h @@ -0,0 +1,22 @@ +#pragma once + +#include + +VK_NAMESPACE_BEGIN + +class SwapchainModule:public GraphModule +{ +public: + + static const char *GetModuleName(){return "Swapchain";} + +public: + + NO_COPY_NO_MOVE(SwapchainModule); + + SwapchainModule(GraphModuleManager *gmm):GraphModule(gmm,"Swapchain"){} + virtual ~SwapchainModule()=default; + +};//class SwapchainModule:public RenderModule + +VK_NAMESPACE_END diff --git a/src/SceneGraph/CMakeLists.txt b/src/SceneGraph/CMakeLists.txt index f135985d..339bfb4b 100644 --- a/src/SceneGraph/CMakeLists.txt +++ b/src/SceneGraph/CMakeLists.txt @@ -279,10 +279,14 @@ SOURCE_GROUP("Scene Graph\\Component" FILES ${SG_COMPONENT_HEADER} ${SG_COMPONEN SET(SGM_HEADER_PATH ${SG_INCLUDE_PATH}/module) SET(GRAPH_MODULE_HEADER ${SGM_HEADER_PATH}/GraphModule.h - ${SGM_HEADER_PATH}/RenderModule.h) + ${SGM_HEADER_PATH}/GraphModuleFactory.h + ${SGM_HEADER_PATH}/RenderModule.h + ${SGM_HEADER_PATH}/SwapchainModule.h) SET(GRAPH_MODULE_SOURCE module/GraphModule.cpp - module/RenderModule.cpp) + module/GraphModuleFactory.cpp + module/RenderModule.cpp + module/SwapchainModule.cpp) SET(RENDER_FRAMEWORK_FILES ${SG_INCLUDE_PATH}/RenderFramework.h RenderFramework.cpp) diff --git a/src/SceneGraph/Vulkan/VKDevice.cpp b/src/SceneGraph/Vulkan/VKDevice.cpp index 0d438b10..0985bae7 100644 --- a/src/SceneGraph/Vulkan/VKDevice.cpp +++ b/src/SceneGraph/Vulkan/VKDevice.cpp @@ -10,6 +10,7 @@ #include #include #include +#include VK_NAMESPACE_BEGIN @@ -25,6 +26,8 @@ GPUDevice::GPUDevice(GPUDeviceAttribute *da) graph_module_manager=InitGraphModuleManager(this); + swapchain_module=graph_module_manager->GetModule(true); + InitRenderPassManage(); sc_rt=nullptr; diff --git a/src/SceneGraph/module/GraphModule.cpp b/src/SceneGraph/module/GraphModule.cpp index c202e211..998da46d 100644 --- a/src/SceneGraph/module/GraphModule.cpp +++ b/src/SceneGraph/module/GraphModule.cpp @@ -67,27 +67,25 @@ GraphModuleManager *GetGraphModuleManager(GPUDevice *dev) return(nullptr); } -bool GraphModuleManager::Registry(const AnsiString &name,GraphModule *gm) -{ - if(!gm) - return(false); - if(name.IsEmpty()) - return(false); +GraphModule *CreateGraphModule(const AnsiString &name,GraphModuleManager *gmm); - if(graph_module_map.ContainsKey(name)) - return(false); - - graph_module_map.Add(name,gm); - return(true); -} - -GraphModule *GraphModuleManager::GetModule(const AnsiString &name) +GraphModule *GraphModuleManager::GetModule(const AnsiString &name,bool create) { GraphModule *gm; if(graph_module_map.Get(name,gm)) return gm; + if(create) + { + gm=CreateGraphModule(name,this); + + if(gm) + graph_module_map.Add(name,gm); + + return gm; + } + return nullptr; } diff --git a/src/SceneGraph/module/GraphModuleFactory.cpp b/src/SceneGraph/module/GraphModuleFactory.cpp new file mode 100644 index 00000000..35f6b59d --- /dev/null +++ b/src/SceneGraph/module/GraphModuleFactory.cpp @@ -0,0 +1,64 @@ +#include +#include +#include + +VK_NAMESPACE_BEGIN + +namespace +{ + using GraphModuleFactoryMap=ObjectMap; + + static GraphModuleFactoryMap *gmf_map=nullptr; +} + +void InitGraphModuleFactory() +{ + if(gmf_map) + return; + + gmf_map=new GraphModuleFactoryMap; +} + +void ClearGraphModuleFactory() +{ + SAFE_CLEAR(gmf_map); +} + +bool RegistryGraphModuleFactory(const char *module_name,GraphModuleFactory *gmf) +{ + if(!module_name||!gmf) + return(false); + + if(!gmf_map) + InitGraphModuleFactory(); + + AnsiString name=module_name; + + if(gmf_map->ContainsKey(name)) + return(false); + + gmf_map->Add(name,gmf); + + return(true); +} + +GraphModule *CreateGraphModule(const AnsiString &name,GraphModuleManager *gmm) +{ + if(!gmm) + return(nullptr); + + if(name.IsEmpty()) + return(nullptr); + + if(!gmf_map) + return(nullptr); + + GraphModuleFactory *gmf; + + if(!gmf_map->Get(name,gmf)) + return(nullptr); + + return gmf->Create(gmm); +} + +VK_NAMESPACE_END diff --git a/src/SceneGraph/module/SwapchainModule.cpp b/src/SceneGraph/module/SwapchainModule.cpp new file mode 100644 index 00000000..d555fbd1 --- /dev/null +++ b/src/SceneGraph/module/SwapchainModule.cpp @@ -0,0 +1,8 @@ +#include +#include + +VK_NAMESPACE_BEGIN + +REGISTRY_GRAPH_MODULE(SwapchainModule) + +VK_NAMESPACE_END