diff --git a/inc/hgl/graph/VKFramebuffer.h b/inc/hgl/graph/VKFramebuffer.h index 5f80a34d..7e9e4a56 100644 --- a/inc/hgl/graph/VKFramebuffer.h +++ b/inc/hgl/graph/VKFramebuffer.h @@ -16,7 +16,7 @@ class Framebuffer private: - friend class GPUDevice; + friend class TextureManager; Framebuffer(VkDevice,VkFramebuffer,const VkExtent2D &,VkRenderPass,uint32_t color_count,bool depth); diff --git a/inc/hgl/graph/manager/TextureManager.h b/inc/hgl/graph/manager/TextureManager.h index 27f54472..d6397b67 100644 --- a/inc/hgl/graph/manager/TextureManager.h +++ b/inc/hgl/graph/manager/TextureManager.h @@ -1,6 +1,6 @@ #pragma once -#include +#include #include #include #include @@ -10,14 +10,14 @@ VK_NAMESPACE_BEGIN -class TextureManager:public GraphManager +class TextureManager:public GraphModule { - DeviceQueue *texture_queue; - TextureCmdBuffer *texture_cmd_buf; + DeviceQueue *texture_queue=nullptr; + TextureCmdBuffer *texture_cmd_buf=nullptr; private: - TextureID texture_serial; + TextureID texture_serial=0; const TextureID AcquireID(){return texture_serial++;} ///<取得一个新的纹理ID @@ -37,9 +37,11 @@ private: public: - TextureManager(GPUDevice *); + GRAPH_MODULE_CONSTRUCT(TextureManager) virtual ~TextureManager(); + bool Init() override; + public: //Buffer DeviceBuffer *CreateTransferSourceBuffer(const VkDeviceSize,const void *data_ptr=nullptr); @@ -119,6 +121,17 @@ public: // Load Texture2DArray * CreateTexture2DArray(const AnsiString &name,const uint32_t width,const uint32_t height,const uint32_t layer,const VkFormat &fmt,bool auto_mipmaps=false); bool LoadTexture2DToArray(Texture2DArray *,const uint32_t layer,const OSString &); +public: //FrameBuffer相关 + + Framebuffer *CreateFBO(RenderPass *rp,ImageView **color_list,const uint color_count,ImageView *depth); +// Framebuffer *CreateFBO(RenderPass *,List &color,ImageView *depth); + Framebuffer *CreateFBO(RenderPass *,ImageView *color,ImageView *depth); + Framebuffer *CreateFBO(RenderPass *,ImageView *); + +public: + + RenderTarget *CreateRT( const FramebufferInfo *fbi,RenderPass *,const uint32_t fence_count=1); + RenderTarget *CreateRT( const FramebufferInfo *fbi,const uint32_t fence_count=1); };//class TextureManager VK_NAMESPACE_END diff --git a/inc/hgl/graph/module/GraphModule.h b/inc/hgl/graph/module/GraphModule.h index f3f4ea12..f102147a 100644 --- a/inc/hgl/graph/module/GraphModule.h +++ b/inc/hgl/graph/module/GraphModule.h @@ -68,7 +68,7 @@ protected: public: - virtual const bool IsRender(){return false;} ///<是否为渲染模块 + virtual const bool IsRender(){return false;} ///<是否为渲染模块 GraphModuleManager *GetManager (){return module_manager;} ///<取得模块管理器 GPUDevice * GetDevice (){return module_manager->GetDevice();} ///<取得GPU设备 @@ -76,11 +76,11 @@ public: const GPUPhysicalDevice * GetPhysicalDevice (){return module_manager->GetPhysicalDevice();} ///<取得物理设备 const GPUDeviceAttribute *GetDeviceAttribute (){return module_manager->GetDeviceAttribute();}///<取得设备属性 - static const AnsiIDName *GetModuleName(){return nullptr;} ///<取得模块名称(标准通用的名称,比如Upscale,供通用模块使用) - virtual const AnsiIDName *GetName()const{return &module_name;} ///<取得名称(完整的私有名称,比如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;} ///<当前模块是否准备好 + const bool IsEnable ()const noexcept{return module_enable;} ///<当前模块是否启用 + const bool IsReady ()const noexcept{return module_ready;} ///<当前模块是否准备好 public: @@ -93,26 +93,34 @@ public: } virtual ~GraphModule()=default; - virtual bool Init(){return true;} ///<初始化当前模块 + virtual bool Init(){return true;} ///<初始化当前模块 + +public: + + GraphModule * GetModule(const AnsiIDName &name,bool create=false){return module_manager->GetModule(name,create);} ///<获取指定名称的模块 + + template + T * GetModule(bool create=false){return module_manager->GetModule(create);} ///<获取指定类型的模块 + public: //回调事件 - virtual void OnRenderTarget(RenderTarget *){} ///<设置渲染目标 - virtual void OnResize(const VkExtent2D &){} ///<窗口大小改变 + virtual void OnRenderTarget(RenderTarget *){} ///<设置渲染目标 + virtual void OnResize(const VkExtent2D &){} ///<窗口大小改变 - virtual void OnPreFrame(){} ///<帧绘制前回调 + virtual void OnPreFrame(){} ///<帧绘制前回调 virtual void OnExecute(const double,RenderCmdBuffer *){} - virtual void OnPostFrame(){} ///<帧绘制后回调 + virtual void OnPostFrame(){} ///<帧绘制后回调 };//class GraphModule #define GRAPH_MODULE_CONSTRUCT(name) public:\ - NO_COPY_NO_MOVE(name##Module) \ + NO_COPY_NO_MOVE(name) \ static const AnsiIDName &GetModuleName() \ { \ static const AnsiIDName id_name(#name); \ return id_name; \ } \ \ - name##Module(GraphModuleManager *gmm):GraphModule(gmm,GetModuleName()){} + name(GraphModuleManager *gmm):GraphModule(gmm,GetModuleName()){} VK_NAMESPACE_END diff --git a/inc/hgl/graph/module/GraphModuleFactory.h b/inc/hgl/graph/module/GraphModuleFactory.h index 88fdfdce..b0803edb 100644 --- a/inc/hgl/graph/module/GraphModuleFactory.h +++ b/inc/hgl/graph/module/GraphModuleFactory.h @@ -28,7 +28,15 @@ public: if(!gmm) return(nullptr); - return(new T(gmm)); + GraphModule *gm=new T(gmm); + + if(!gm->Init()) + { + delete gm; + return(nullptr); + } + + return(true); } };//template class RegistryGraphModule:public GraphModuleFactory diff --git a/src/SceneGraph/CMakeLists.txt b/src/SceneGraph/CMakeLists.txt index 02f33b2c..00f6e78c 100644 --- a/src/SceneGraph/CMakeLists.txt +++ b/src/SceneGraph/CMakeLists.txt @@ -298,10 +298,8 @@ SOURCE_GROUP("Render Framework\\Module" FILES ${GRAPH_MODULE_HEADER} SET(SG_MANAGER_HEADER_PATH ${SG_INCLUDE_PATH}/manager) -SET(GRAPH_MANAGER_HEADER ${SG_MANAGER_HEADER_PATH}/GraphManager.h - ${SG_MANAGER_HEADER_PATH}/TextureManager.h) -SET(GRAPH_MANAGER_SOURCE manager/GraphManager.cpp - manager/TextureManager.cpp) +SET(GRAPH_MANAGER_HEADER ${SG_MANAGER_HEADER_PATH}/TextureManager.h) +SET(GRAPH_MANAGER_SOURCE manager/TextureManager.cpp) SOURCE_GROUP("Render Framework\\Manager" FILES ${GRAPH_MANAGER_HEADER} ${GRAPH_MANAGER_SOURCE}) diff --git a/src/SceneGraph/Vulkan/VKDeviceFramebuffer.cpp b/src/SceneGraph/Vulkan/VKDeviceFramebuffer.cpp index 61200448..6fe4f795 100644 --- a/src/SceneGraph/Vulkan/VKDeviceFramebuffer.cpp +++ b/src/SceneGraph/Vulkan/VKDeviceFramebuffer.cpp @@ -1,4 +1,5 @@ #include +#include VK_NAMESPACE_BEGIN VkFramebuffer CreateVulkanFramebuffer(VkDevice device,RenderPass *rp,const VkExtent2D &extent,VkImageView *attachments,const uint attachmentCount) @@ -20,7 +21,7 @@ VkFramebuffer CreateVulkanFramebuffer(VkDevice device,RenderPass *rp,const VkExt return fb; } -Framebuffer *GPUDevice::CreateFBO(RenderPass *rp,ImageView **color_list,const uint color_count,ImageView *depth) +Framebuffer *TextureManager::CreateFBO(RenderPass *rp,ImageView **color_list,const uint color_count,ImageView *depth) { uint att_count=color_count; @@ -70,12 +71,12 @@ Framebuffer *GPUDevice::CreateFBO(RenderPass *rp,ImageView **color_list,const ui extent.height=color_list[0]->GetExtent().height; } - VkFramebuffer fbo=CreateVulkanFramebuffer(GetDevice(),rp,extent,attachments,att_count); + VkFramebuffer fbo=CreateVulkanFramebuffer(GetVkDevice(),rp,extent,attachments,att_count); if(!fbo) return(nullptr); - return(new Framebuffer(GetDevice(),fbo,extent,rp->GetVkRenderPass(),color_count,depth)); + return(new Framebuffer(GetVkDevice(),fbo,extent,rp->GetVkRenderPass(),color_count,depth)); } // //Framebuffer *GPUDevice::CreateFBO(RenderPass *rp,List &color,ImageView *depth) @@ -89,7 +90,7 @@ Framebuffer *GPUDevice::CreateFBO(RenderPass *rp,ImageView **color_list,const ui // return CreateFBO(rp,color.GetData(),color.GetCount(),depth); //} -Framebuffer *GPUDevice::CreateFBO(RenderPass *rp,ImageView *color,ImageView *depth) +Framebuffer *TextureManager::CreateFBO(RenderPass *rp,ImageView *color,ImageView *depth) { if(!rp)return(nullptr); if(!color&&!depth)return(nullptr); @@ -97,7 +98,7 @@ Framebuffer *GPUDevice::CreateFBO(RenderPass *rp,ImageView *color,ImageView *dep return CreateFBO(rp,&color,1,depth); } -Framebuffer *GPUDevice::CreateFBO(RenderPass *rp,ImageView *iv) +Framebuffer *TextureManager::CreateFBO(RenderPass *rp,ImageView *iv) { if(!rp)return(nullptr); if(!iv)return(nullptr); diff --git a/src/SceneGraph/Vulkan/VKDeviceRenderTarget.cpp b/src/SceneGraph/Vulkan/VKDeviceRenderTarget.cpp index d7df9916..e51dfff0 100644 --- a/src/SceneGraph/Vulkan/VKDeviceRenderTarget.cpp +++ b/src/SceneGraph/Vulkan/VKDeviceRenderTarget.cpp @@ -1,7 +1,8 @@ #include +#include VK_NAMESPACE_BEGIN -RenderTarget *GPUDevice::CreateRT(const FramebufferInfo *fbi,RenderPass *rp,const uint32_t fence_count) +RenderTarget *TextureManager::CreateRT(const FramebufferInfo *fbi,RenderPass *rp,const uint32_t fence_count) { if(!fbi)return(nullptr); if(!rp)return(nullptr); @@ -46,7 +47,7 @@ RenderTarget *GPUDevice::CreateRT(const FramebufferInfo *fbi,RenderPass *rp,cons return nullptr; } -RenderTarget *GPUDevice::CreateRT(const FramebufferInfo *fbi,const uint32_t fence_count) +RenderTarget *TextureManager::CreateRT(const FramebufferInfo *fbi,const uint32_t fence_count) { if(!fbi)return(nullptr); @@ -57,25 +58,4 @@ RenderTarget *GPUDevice::CreateRT(const FramebufferInfo *fbi,const uint32_t fenc return CreateRT(fbi,rp,fence_count); } -RTSwapchain *GPUDevice::CreateSwapchainRenderTarget() -{ - Swapchain *sc=CreateSwapchain(attr->surface_caps.currentExtent); - - if(!sc) - return(nullptr); - - DeviceQueue *q=CreateQueue(sc->color_count,false); - Semaphore *render_complete_semaphore=CreateGPUSemaphore(); - Semaphore *present_complete_semaphore=CreateGPUSemaphore(); - - RTSwapchain *srt=new RTSwapchain( attr->device, - sc, - q, - render_complete_semaphore, - present_complete_semaphore, - device_render_pass - ); - - return srt; -} VK_NAMESPACE_END diff --git a/src/SceneGraph/manager/TextureManager.cpp b/src/SceneGraph/manager/TextureManager.cpp index ae4bd6bd..a1493cc3 100644 --- a/src/SceneGraph/manager/TextureManager.cpp +++ b/src/SceneGraph/manager/TextureManager.cpp @@ -4,12 +4,26 @@ VK_NAMESPACE_BEGIN -TextureManager::TextureManager(GPUDevice *dev):GraphManager(dev) +bool TextureManager::Init() { + GPUDevice *dev=GetDevice(); + + if(!dev) + return(false); + texture_cmd_buf=dev->CreateTextureCommandBuffer(GetPhysicalDevice()->GetDeviceName()+AnsiString(":TexCmdBuffer")); + + if(!texture_cmd_buf) + return(false); + texture_queue=dev->CreateQueue(); + if(!texture_queue) + return(false); + texture_serial=0; + + return(true); } TextureManager::~TextureManager() diff --git a/src/SceneGraph/module/RegistryCommonModule.cpp b/src/SceneGraph/module/RegistryCommonModule.cpp index f517961e..b1838d8f 100644 --- a/src/SceneGraph/module/RegistryCommonModule.cpp +++ b/src/SceneGraph/module/RegistryCommonModule.cpp @@ -1,10 +1,12 @@ #include +#include #include VK_NAMESPACE_BEGIN void RegistryCommonGraphModule() { + REGISTRY_GRAPH_MODULE(TextureManager) REGISTRY_GRAPH_MODULE(Swapchain) }