From e52f7c13a96f3fe195a69ae33b1d5951bdceef93 Mon Sep 17 00:00:00 2001 From: hyzboy Date: Wed, 23 Oct 2024 23:22:41 +0800 Subject: [PATCH] use AnsiIDName instead of AnsiString in GraphModuleMap --- CMCore | 2 +- inc/hgl/graph/module/GraphModule.h | 89 ++++++++++++-------- inc/hgl/graph/module/SwapchainModule.h | 8 +- src/SceneGraph/RenderAssignBuffer.cpp | 4 +- src/SceneGraph/RenderAssignBuffer.h | 4 +- src/SceneGraph/module/GraphModule.cpp | 4 +- src/SceneGraph/module/GraphModuleFactory.cpp | 10 +-- src/SceneGraph/module/SwapchainModule.cpp | 2 +- 8 files changed, 67 insertions(+), 56 deletions(-) diff --git a/CMCore b/CMCore index 5443a589..6316f3cd 160000 --- a/CMCore +++ b/CMCore @@ -1 +1 @@ -Subproject commit 5443a58987ec4fd3fdfb1df72f602c728940321a +Subproject commit 6316f3cd59aa749ca31226f82fc764dd77ac40ff diff --git a/inc/hgl/graph/module/GraphModule.h b/inc/hgl/graph/module/GraphModule.h index bcc62154..8d72a956 100644 --- a/inc/hgl/graph/module/GraphModule.h +++ b/inc/hgl/graph/module/GraphModule.h @@ -1,17 +1,56 @@ #pragma once #include +#include VK_NAMESPACE_BEGIN class RenderCmdBuffer; -class GraphModuleManager; +class GraphModule; + +class GraphModuleManager +{ + GPUDevice *device; + + Map graph_module_map; + +public: + + GraphModuleManager(GPUDevice *dev){device=dev;} + ~GraphModuleManager(); + + GPUDevice *GetDevice(){return device;} ///<取得GPU设备 + + /** + * 获取指定名称的模块 + * @param create 如果不存在,是否创建新的 + */ + GraphModule *GetModule(const AnsiIDName &name,bool create); ///<获取指定名称的模块 + + /** + * 获取指定类型的模块 + * @param create 如果不存在,是否创建新的 + */ + template + T *GetModule(bool create=false){return (T *)GetModule(T::GetModuleName(),create);} ///<获取指定类型的模块 + + const bool IsLoaded(const AnsiIDName &name){return graph_module_map.ContainsKey(name);} ///<是否已经加载了指定类型的模块 + + template + const bool IsLoaded(){return graph_module_map.ContainsKey(T::GetModuleName());} ///<是否已经加载了指定类型的模块 + +public: //事件 + + void OnResize(const VkExtent2D &); +};//class GraphModuleManager + +GraphModuleManager *GetGraphModuleManager(GPUDevice *); class GraphModule { GraphModuleManager *module_manager; - AnsiString module_name; + AnsiIDName module_name; bool module_enable; bool module_ready; @@ -26,9 +65,10 @@ public: virtual const bool IsRender(){return false;} ///<是否为渲染模块 GraphModuleManager *GetManager(){return module_manager;} ///<取得模块管理器 + GPUDevice *GetDevice(){return module_manager->GetDevice();} ///<取得GPU设备 - static const char *GetModuleName(){return nullptr;} ///<取得模块名称(标准通用的名称,比如Upscale,供通用模块使用) - virtual const char *GetName()const{return module_name.c_str();} ///<取得名称(完整的私有名称,比如FSR3Upscale,DLSS3Upscale) + static const AnsiIDName *GetModuleName(){return nullptr;} ///<取得模块名称(标准通用的名称,比如Upscale,供通用模块使用) + virtual const AnsiIDName *GetName()const{return &module_name;} ///<取得名称(完整的私有名称,比如FSR3Upscale,DLSS3Upscale) const bool IsEnable ()const noexcept{return module_enable;} ///<当前模块是否启用 const bool IsReady ()const noexcept{return module_ready;} ///<当前模块是否准备好 @@ -37,7 +77,7 @@ public: NO_COPY_NO_MOVE(GraphModule) - GraphModule(GraphModuleManager *gmm,const AnsiString &name) + GraphModule(GraphModuleManager *gmm,const AnsiIDName &name) { module_manager=gmm; module_name=name; @@ -56,35 +96,14 @@ public: //回调事件 virtual void OnPostFrame(){} ///<帧绘制后回调 };//class GraphModule -class GraphModuleManager -{ - GPUDevice *device; - - Map graph_module_map; - -protected: - - GraphModule *GetModule(const AnsiString &name,bool create); - -public: - - GraphModuleManager(GPUDevice *dev){device=dev;} - ~GraphModuleManager(); - - /** - * 获取指定类型的模块 - * @param create 如果不存在,是否创建新的 - */ - template T *GetModule(bool create=false) - { - return (T *)GetModule(T::GetModuleName(),create); - } - -public: //事件 - - void OnResize(const VkExtent2D &); -};//class GraphModuleManager - -GraphModuleManager *GetGraphModuleManager(GPUDevice *); +#define GRAPH_MODULE_CONSTRUCT(name) public:\ + NO_COPY_NO_MOVE(name##Module) \ + static const AnsiIDName &GetModuleName() \ + { \ + static const AnsiIDName id_name(#name); \ + return id_name; \ + } \ + \ + name##Module(GraphModuleManager *gmm):GraphModule(gmm,GetModuleName()){} VK_NAMESPACE_END diff --git a/inc/hgl/graph/module/SwapchainModule.h b/inc/hgl/graph/module/SwapchainModule.h index 3a810697..344547d2 100644 --- a/inc/hgl/graph/module/SwapchainModule.h +++ b/inc/hgl/graph/module/SwapchainModule.h @@ -8,13 +8,7 @@ class SwapchainModule:public GraphModule { public: - static const char *GetModuleName(){return "Swapchain";} - -public: - - NO_COPY_NO_MOVE(SwapchainModule); - - SwapchainModule(GraphModuleManager *gmm):GraphModule(gmm,"Swapchain"){} + GRAPH_MODULE_CONSTRUCT(Swapchain) virtual ~SwapchainModule()=default; };//class SwapchainModule:public RenderModule diff --git a/src/SceneGraph/RenderAssignBuffer.cpp b/src/SceneGraph/RenderAssignBuffer.cpp index 46660ddb..ed721895 100644 --- a/src/SceneGraph/RenderAssignBuffer.cpp +++ b/src/SceneGraph/RenderAssignBuffer.cpp @@ -71,7 +71,7 @@ void RenderAssignBuffer::StatL2W(const RenderNodeList &rn_list) RenderNode *rn=rn_list.GetData(); Matrix4f *l2wp=(Matrix4f *)(l2w_buffer->DeviceBuffer::Map()); - for(uint i=0;iscene_node->GetLocalToWorldMatrix(); ++l2wp; @@ -215,7 +215,7 @@ void RenderAssignBuffer::WriteNode(const RenderNodeList &rn_list) AssignData *adp=(AssignData *)(assign_vab->DeviceBuffer::Map()); - for(uint i=0;il2w_index=i; diff --git a/src/SceneGraph/RenderAssignBuffer.h b/src/SceneGraph/RenderAssignBuffer.h index d387e5d9..9ae38b16 100644 --- a/src/SceneGraph/RenderAssignBuffer.h +++ b/src/SceneGraph/RenderAssignBuffer.h @@ -47,7 +47,7 @@ private: private: //LocalToWorld矩阵数据 - uint32 l2w_buffer_max_count; /// +#include #include #include @@ -6,7 +7,7 @@ VK_NAMESPACE_BEGIN namespace { - using GraphModuleFactoryMap=ObjectMap; + using GraphModuleFactoryMap=ObjectMap; static GraphModuleFactoryMap *gmf_map=nullptr; } @@ -32,7 +33,7 @@ bool RegistryGraphModuleFactory(const char *module_name,GraphModuleFactory *gmf) if(!gmf_map) InitGraphModuleFactory(); - AnsiString name=module_name; + AnsiIDName name(module_name); if(gmf_map->ContainsKey(name)) return(false); @@ -42,14 +43,11 @@ bool RegistryGraphModuleFactory(const char *module_name,GraphModuleFactory *gmf) return(true); } -GraphModule *CreateGraphModule(const AnsiString &name,GraphModuleManager *gmm) +GraphModule *CreateGraphModule(const AnsiIDName &name,GraphModuleManager *gmm) { if(!gmm) return(nullptr); - if(name.IsEmpty()) - return(nullptr); - if(!gmf_map) return(nullptr); diff --git a/src/SceneGraph/module/SwapchainModule.cpp b/src/SceneGraph/module/SwapchainModule.cpp index d555fbd1..e127bd57 100644 --- a/src/SceneGraph/module/SwapchainModule.cpp +++ b/src/SceneGraph/module/SwapchainModule.cpp @@ -3,6 +3,6 @@ VK_NAMESPACE_BEGIN -REGISTRY_GRAPH_MODULE(SwapchainModule) +//REGISTRY_GRAPH_MODULE(SwapchainModule) VK_NAMESPACE_END