preparing newly GraphModule/RenderModule/RenderPassManager/RenderFramework
This commit is contained in:
parent
bd0a3d8be1
commit
911afc06f6
46
inc/hgl/graph/RenderFramework.h
Normal file
46
inc/hgl/graph/RenderFramework.h
Normal file
@ -0,0 +1,46 @@
|
||||
#pragma once
|
||||
|
||||
#include<hgl/graph/VK.h>
|
||||
#include<hgl/platform/Window.h>
|
||||
#include<hgl/graph/module/GraphModuleManager.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
|
||||
class RenderPassManager;
|
||||
|
||||
class RenderFramework:public io::WindowEvent
|
||||
{
|
||||
OSString app_name;
|
||||
|
||||
Window * win =nullptr;
|
||||
VulkanInstance * inst =nullptr;
|
||||
|
||||
GPUDevice * device =nullptr;
|
||||
|
||||
protected:
|
||||
|
||||
GraphModuleManager *module_manager =nullptr;
|
||||
|
||||
RenderPassManager * render_pass_manager =nullptr;
|
||||
RenderPass * device_render_pass =nullptr;
|
||||
|
||||
public:
|
||||
|
||||
Window * GetWindow (){return win;}
|
||||
GPUDevice * GetDevice (){return device;}
|
||||
|
||||
public:
|
||||
|
||||
GraphModuleManager *GetModuleManager(){return module_manager;}
|
||||
RenderPassManager * GetRenderPassManager(){return render_pass_manager;}
|
||||
|
||||
public:
|
||||
|
||||
RenderFramework(const OSString &);
|
||||
virtual ~RenderFramework();
|
||||
|
||||
virtual bool Init(uint w,uint h);
|
||||
|
||||
};//class RenderFramework
|
||||
|
||||
VK_NAMESPACE_END
|
@ -37,7 +37,6 @@ class GPUDevice
|
||||
|
||||
private:
|
||||
|
||||
DeviceRenderPassManage *render_pass_manage;
|
||||
RenderPass *device_render_pass;
|
||||
|
||||
RTSwapchain *sc_rt;
|
||||
@ -231,8 +230,6 @@ public: //Command Buffer 相关
|
||||
|
||||
public:
|
||||
|
||||
RenderPass * AcquireRenderPass( const RenderbufferInfo *,const uint subpass_count=2);
|
||||
|
||||
Fence * CreateFence(bool);
|
||||
Semaphore * CreateGPUSemaphore();
|
||||
|
||||
|
@ -29,7 +29,7 @@ protected:
|
||||
|
||||
private:
|
||||
|
||||
friend class DeviceRenderPassManage;
|
||||
friend class RenderPassManager;
|
||||
|
||||
RenderPass(VkDevice d,VkPipelineCache pc,VkRenderPass rp,const List<VkFormat> &cf,VkFormat df);
|
||||
|
||||
|
58
inc/hgl/graph/module/GraphModule.h
Normal file
58
inc/hgl/graph/module/GraphModule.h
Normal file
@ -0,0 +1,58 @@
|
||||
#pragma once
|
||||
|
||||
#include<hgl/graph/VKDevice.h>
|
||||
#include<hgl/type/TypeInfo.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
|
||||
class GraphModule
|
||||
{
|
||||
GPUDevice *device;
|
||||
|
||||
public:
|
||||
|
||||
GPUDevice * GetDevice () {return device;} ///<取得GPU设备
|
||||
VkDevice GetVkDevice ()const {return device->GetDevice();} ///<取得VkDevice
|
||||
const GPUPhysicalDevice * GetPhysicalDevice ()const {return device->GetPhysicalDevice();} ///<取得物理设备
|
||||
GPUDeviceAttribute *GetDeviceAttribute () {return device->GetDeviceAttribute();} ///<取得设备属性
|
||||
|
||||
public:
|
||||
|
||||
GraphModule(GPUDevice *dev){device=dev;}
|
||||
virtual ~GraphModule()=default;
|
||||
|
||||
virtual const size_t GetTypeHash()const noexcept=0;
|
||||
virtual const AnsiString &GetName()const=0;
|
||||
};//class GraphModule
|
||||
|
||||
template<typename T> class GraphModuleInherit:public GraphModule
|
||||
{
|
||||
AnsiString manager_name;
|
||||
|
||||
public:
|
||||
|
||||
const size_t GetTypeHash()const noexcept override
|
||||
{
|
||||
return typeid(T).hash_code();
|
||||
}
|
||||
|
||||
const AnsiString &GetName()const override
|
||||
{
|
||||
return manager_name;
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
GraphModuleInherit(GPUDevice *dev,const AnsiString &name):GraphModule(dev)
|
||||
{
|
||||
manager_name=name;
|
||||
}
|
||||
|
||||
virtual ~GraphModuleInherit()=default;
|
||||
};//class GraphModuleInherit
|
||||
|
||||
#define GRAPH_MODULE_CLASS(class_name) class class_name:public GraphModuleInherit<class_name>
|
||||
|
||||
#define GRAPH_MODULE_CONSTRUCT(class_name) class_name::class_name(GPUDevice *dev):GraphModuleInherit<class_name>(dev,#class_name)
|
||||
|
||||
VK_NAMESPACE_END
|
41
inc/hgl/graph/module/GraphModuleManager.h
Normal file
41
inc/hgl/graph/module/GraphModuleManager.h
Normal file
@ -0,0 +1,41 @@
|
||||
#pragma once
|
||||
|
||||
#include<hgl/graph/VK.h>
|
||||
#include<hgl/type/Map.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
|
||||
class GraphModule;
|
||||
|
||||
class GraphModuleManager
|
||||
{
|
||||
GPUDevice *device;
|
||||
|
||||
protected:
|
||||
|
||||
List<GraphModule *> module_list;
|
||||
Map<size_t,GraphModule *> module_map;
|
||||
|
||||
public:
|
||||
|
||||
GraphModuleManager(GPUDevice *dev){device=dev;}
|
||||
|
||||
virtual ~GraphModuleManager();
|
||||
|
||||
public:
|
||||
|
||||
GPUDevice * GetDevice() {return device;} ///<取得GPU设备
|
||||
|
||||
public:
|
||||
|
||||
GraphModule * GetModule(const size_t type_hash) {return GetObjectFromList(module_map,type_hash);} ///<取得指定类型的模块
|
||||
template<typename T>
|
||||
T * GetModule() {return(GetModule(typeid(T).hash_code()));} ///<取得指定类型的模块
|
||||
|
||||
bool ConatainsModule(const size_t &type_hash)const {return module_map.ContainsKey(type_hash);} ///<确认是否包含指定类型的模块
|
||||
|
||||
bool Registry(GraphModule *); ///<注册一个模块
|
||||
bool Unregistry(GraphModule *); ///<注销一个模块
|
||||
};//class GraphModuleManager
|
||||
|
||||
VK_NAMESPACE_END
|
27
inc/hgl/graph/module/RenderModule.h
Normal file
27
inc/hgl/graph/module/RenderModule.h
Normal file
@ -0,0 +1,27 @@
|
||||
#pragma once
|
||||
|
||||
#include<hgl/graph/module/GraphModule.h>
|
||||
#include<hgl/type/Size2.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
|
||||
/**
|
||||
* 渲染模块基类
|
||||
*/
|
||||
class RenderModule:public GraphModule
|
||||
{
|
||||
VkExtent2D current_extent;
|
||||
|
||||
public:
|
||||
|
||||
NO_COPY_NO_MOVE(RenderModule)
|
||||
|
||||
using GraphModule::GraphModule;
|
||||
virtual ~RenderModule()=default;
|
||||
|
||||
virtual void OnResize(const VkExtent2D &ext){current_extent=ext;} ///<窗口大小改变
|
||||
|
||||
virtual void OnFrameRender(const double,RenderCmdBuffer *)=0; ///<帧绘制回调
|
||||
};//class RenderModule
|
||||
|
||||
VK_NAMESPACE_END
|
@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include<hgl/graph/VK.h>
|
||||
#include<hgl/graph/module/GraphModule.h>
|
||||
#include<hgl/type/Map.h>
|
||||
#include<hgl/util/hash/Hash.h>
|
||||
|
||||
@ -12,9 +12,8 @@ inline util::Hash *CreateRenderPassHash()
|
||||
return util::CreateHash(util::HASH::xxH3_128);
|
||||
}
|
||||
|
||||
class DeviceRenderPassManage
|
||||
class RenderPassManager:public GraphModuleInherit<RenderPassManager>
|
||||
{
|
||||
VkDevice device;
|
||||
VkPipelineCache pipeline_cache;
|
||||
|
||||
util::Hash *hash;
|
||||
@ -23,10 +22,8 @@ class DeviceRenderPassManage
|
||||
|
||||
private:
|
||||
|
||||
friend class GPUDevice;
|
||||
|
||||
DeviceRenderPassManage(VkDevice,VkPipelineCache);
|
||||
~DeviceRenderPassManage();
|
||||
RenderPassManager(GPUDevice *);
|
||||
~RenderPassManager();
|
||||
|
||||
private:
|
||||
|
||||
@ -35,6 +32,9 @@ private:
|
||||
const List<VkSubpassDependency> &dependency,
|
||||
const RenderbufferInfo *);
|
||||
|
||||
public:
|
||||
|
||||
RenderPass * AcquireRenderPass( const RenderbufferInfo *,const uint subpass_count=2);
|
||||
};//class DeviceRenderPassManage
|
||||
};//class RenderPassManager
|
||||
|
||||
VK_NAMESPACE_END
|
@ -41,6 +41,26 @@ SET(LIGHT_FILES ${SG_INCLUDE_PATH}/Light.h
|
||||
|
||||
source_group("Light" FILES ${LIGHT_FILES})
|
||||
|
||||
SET(SGM_HEADER_PATH ${SG_INCLUDE_PATH}/module)
|
||||
SET(SGM_SOURCE_PATH module)
|
||||
|
||||
SET(GRAPH_MODULE_FILES ${SGM_HEADER_PATH}/GraphModule.h
|
||||
${SGM_HEADER_PATH}/GraphModuleManager.h
|
||||
${SGM_HEADER_PATH}/RenderPassManager.h
|
||||
|
||||
${SGM_HEADER_PATH}/RenderModule.h
|
||||
|
||||
${SGM_SOURCE_PATH}/GraphModuleManager.cpp
|
||||
${SGM_SOURCE_PATH}/RenderPassManager.cpp
|
||||
)
|
||||
|
||||
source_group("Framework\\Module" FILES ${GRAPH_MODULE_FILES})
|
||||
|
||||
SET(GRAPH_FRAMEWORK_FILES ${SG_INCLUDE_PATH}/RenderFramework.h
|
||||
RenderFramework.cpp)
|
||||
|
||||
source_group("Framework" FILES ${GRAPH_FRAMEWORK_FILES})
|
||||
|
||||
SET(SCENE_GRAPH_HEADER ${SG_INCLUDE_PATH}/SceneManager.h
|
||||
${SG_INCLUDE_PATH}/SceneNodeAttributes.h
|
||||
${SG_INCLUDE_PATH}/SceneNode.h
|
||||
@ -164,7 +184,6 @@ SET(VK_DEVICE_SOURCE Vulkan/VKDeviceMemory.cpp
|
||||
Vulkan/VKDeviceFramebuffer.cpp
|
||||
Vulkan/VKDeviceSwapchain.cpp
|
||||
Vulkan/VKDeviceRenderPass.cpp
|
||||
Vulkan/VKDeviceRenderPassManage.cpp
|
||||
Vulkan/VKDeviceRenderTarget.cpp)
|
||||
|
||||
SET(VK_PHYSICAL_DEVICE_SOURCE ${SG_INCLUDE_PATH}/VKPhysicalDevice.h
|
||||
@ -315,6 +334,9 @@ add_cm_library(ULRE.SceneGraph "ULRE" ${SCENE_GRAPH_HEADER}
|
||||
${GEOMETRY_FILES}
|
||||
${LIGHT_FILES}
|
||||
|
||||
${GRAPH_MODULE_FILES}
|
||||
${GRAPH_FRAMEWORK_FILES}
|
||||
|
||||
${SG_TEXTURE_SOURCE}
|
||||
${TILE_SOURCE}
|
||||
${SG_VDM_SOURCE}
|
||||
|
45
src/SceneGraph/RenderFramework.cpp
Normal file
45
src/SceneGraph/RenderFramework.cpp
Normal file
@ -0,0 +1,45 @@
|
||||
#include<hgl/graph/RenderFramework.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
|
||||
bool InitShaderCompiler();
|
||||
void CloseShaderCompiler();
|
||||
|
||||
namespace
|
||||
{
|
||||
static int RENDER_FRAMEWORK_COUNT=0;
|
||||
|
||||
}//namespace
|
||||
|
||||
RenderFramework::RenderFramework(const OSString &an)
|
||||
{
|
||||
app_name=an;
|
||||
|
||||
|
||||
}
|
||||
|
||||
RenderFramework::~RenderFramework()
|
||||
{
|
||||
--RENDER_FRAMEWORK_COUNT;
|
||||
|
||||
if(RENDER_FRAMEWORK_COUNT==0)
|
||||
{
|
||||
CloseShaderCompiler();
|
||||
}
|
||||
}
|
||||
|
||||
bool RenderFramework::Init(uint w,uint h)
|
||||
{
|
||||
if(RENDER_FRAMEWORK_COUNT==0)
|
||||
{
|
||||
if(!InitShaderCompiler())
|
||||
return(false);
|
||||
|
||||
logger::InitLogger(app_name);
|
||||
}
|
||||
|
||||
++RENDER_FRAMEWORK_COUNT;
|
||||
|
||||
|
||||
}
|
||||
VK_NAMESPACE_END
|
@ -1,12 +1,12 @@
|
||||
#include<hgl/graph/VKDevice.h>
|
||||
#include<hgl/graph/VKDeviceAttribute.h>
|
||||
#include<hgl/graph/VKPhysicalDevice.h>
|
||||
#include<hgl/graph/VKDeviceRenderPassManage.h>
|
||||
#include<hgl/graph/manager/RenderPassManage.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
void GPUDevice::InitRenderPassManage()
|
||||
{
|
||||
render_pass_manage=new DeviceRenderPassManage(attr->device,attr->pipeline_cache);
|
||||
render_pass_manage=new RenderPassManager(this);
|
||||
|
||||
SwapchainRenderbufferInfo rbi(attr->surface_format.format,attr->physical_device->GetDepthFormat());
|
||||
|
||||
@ -22,17 +22,4 @@ void GPUDevice::ClearRenderPassManage()
|
||||
{
|
||||
SAFE_CLEAR(render_pass_manage);
|
||||
}
|
||||
|
||||
RenderPass *GPUDevice::AcquireRenderPass(const RenderbufferInfo *rbi,const uint subpass_count)
|
||||
{
|
||||
for(const VkFormat &fmt:rbi->GetColorFormatList())
|
||||
if(!attr->physical_device->IsColorAttachmentOptimal(fmt))
|
||||
return(nullptr);
|
||||
|
||||
if(rbi->HasDepthOrStencil())
|
||||
if(!attr->physical_device->IsDepthAttachmentOptimal(rbi->GetDepthFormat()))
|
||||
return(nullptr);
|
||||
|
||||
return render_pass_manage->AcquireRenderPass(rbi,subpass_count);
|
||||
}
|
||||
VK_NAMESPACE_END
|
||||
|
53
src/SceneGraph/module/GraphModuleManager.cpp
Normal file
53
src/SceneGraph/module/GraphModuleManager.cpp
Normal file
@ -0,0 +1,53 @@
|
||||
#include<hgl/graph/module/GraphModule.h>
|
||||
#include<hgl/graph/module/GraphModuleManager.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
|
||||
bool GraphModuleManager::Registry(GraphModule *gm)
|
||||
{
|
||||
if(!gm)
|
||||
return(false);
|
||||
|
||||
const size_t type_hash=gm->GetTypeHash();
|
||||
|
||||
if(module_map.ContainsKey(type_hash))
|
||||
return(false);
|
||||
|
||||
module_list.Add(gm);
|
||||
module_map.Add(type_hash,gm);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
bool GraphModuleManager::Unregistry(GraphModule *gm)
|
||||
{
|
||||
if(!gm)
|
||||
return(false);
|
||||
|
||||
const size_t type_hash=gm->GetTypeHash();
|
||||
|
||||
if(!module_map.ContainsKey(type_hash))
|
||||
return(false);
|
||||
|
||||
if(module_list.DeleteByValue(gm)<0)
|
||||
return(false);
|
||||
|
||||
delete gm;
|
||||
return(true);
|
||||
}
|
||||
|
||||
GraphModuleManager::~GraphModuleManager()
|
||||
{
|
||||
GraphModule **gm=module_list.last();
|
||||
GraphModule **begin=module_list.begin();
|
||||
|
||||
while(gm>=begin)
|
||||
{
|
||||
delete *gm;
|
||||
--gm;
|
||||
}
|
||||
|
||||
module_list.Clear();
|
||||
}
|
||||
|
||||
VK_NAMESPACE_END
|
@ -1,4 +1,4 @@
|
||||
#include<hgl/graph/VKDeviceRenderPassManage.h>
|
||||
#include<hgl/graph/module/RenderPassManager.h>
|
||||
#include<hgl/graph/VKRenderPass.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
@ -74,9 +74,9 @@ inline void CreateInputAttachmentReference(VkAttachmentReference *ref_list, uint
|
||||
|
||||
bool CreateAttachmentDescription(List<VkAttachmentDescription> &desc_list,const RenderbufferInfo *rbi)
|
||||
{
|
||||
const uint color_count=rbi->GetColorCount();
|
||||
const uint image_count=rbi->GetColorCount();
|
||||
|
||||
const uint count=(rbi->HasDepthOrStencil())?color_count+1:color_count;
|
||||
const uint count=(rbi->HasDepthOrStencil())?image_count+1:image_count;
|
||||
|
||||
desc_list.SetCount(count);
|
||||
|
||||
@ -97,7 +97,7 @@ bool CreateAttachmentDescription(List<VkAttachmentDescription> &desc_list,const
|
||||
|
||||
desc=desc_list.GetData();
|
||||
const VkFormat *cf=rbi->GetColorFormat();
|
||||
for(uint i=0;i<color_count;i++)
|
||||
for(uint i=0;i<image_count;i++)
|
||||
{
|
||||
desc->finalLayout = rbi->GetColorLayout();
|
||||
desc->format = *cf;
|
||||
@ -184,15 +184,14 @@ bool CreateDepthAttachment( List<VkAttachmentReference> &ref_list,List<VkAttachm
|
||||
return(true);
|
||||
}
|
||||
|
||||
DeviceRenderPassManage::DeviceRenderPassManage(VkDevice dev,VkPipelineCache pc)
|
||||
GRAPH_MODULE_CONSTRUCT(RenderPassManager)
|
||||
{
|
||||
device=dev;
|
||||
pipeline_cache=pc;
|
||||
pipeline_cache=GetDeviceAttribute()->pipeline_cache;
|
||||
|
||||
hash=CreateRenderPassHash();
|
||||
}
|
||||
|
||||
DeviceRenderPassManage::~DeviceRenderPassManage()
|
||||
RenderPassManager::~RenderPassManager()
|
||||
{
|
||||
SAFE_CLEAR(hash);
|
||||
|
||||
@ -265,7 +264,7 @@ namespace
|
||||
}
|
||||
}
|
||||
|
||||
RenderPass *DeviceRenderPassManage::CreateRenderPass( const List<VkAttachmentDescription> &desc_list,
|
||||
RenderPass *RenderPassManager::CreateRenderPass(const List<VkAttachmentDescription> &desc_list,
|
||||
const List<VkSubpassDescription> &subpass,
|
||||
const List<VkSubpassDependency> &dependency,
|
||||
const RenderbufferInfo *rbi)
|
||||
@ -285,14 +284,26 @@ RenderPass *DeviceRenderPassManage::CreateRenderPass( const List<VkAttachmentD
|
||||
|
||||
VkRenderPass render_pass;
|
||||
|
||||
if(vkCreateRenderPass(device,&rp_info,nullptr,&render_pass)!=VK_SUCCESS)
|
||||
if(vkCreateRenderPass(GetVkDevice(),&rp_info,nullptr,&render_pass)!=VK_SUCCESS)
|
||||
return(nullptr);
|
||||
|
||||
return(new RenderPass(device,pipeline_cache,render_pass,rbi->GetColorFormatList(),depth_format));
|
||||
return(new RenderPass(GetVkDevice(),pipeline_cache,render_pass,rbi->GetColorFormatList(),depth_format));
|
||||
}
|
||||
|
||||
RenderPass *DeviceRenderPassManage::AcquireRenderPass(const RenderbufferInfo *rbi,const uint subpass_count)
|
||||
RenderPass *RenderPassManager::AcquireRenderPass(const RenderbufferInfo *rbi,const uint subpass_count)
|
||||
{
|
||||
{
|
||||
const auto *phy_dev=GetPhysicalDevice();
|
||||
|
||||
for(const VkFormat &fmt:rbi->GetColorFormatList())
|
||||
if(!phy_dev->IsColorAttachmentOptimal(fmt))
|
||||
return(nullptr);
|
||||
|
||||
if(rbi->HasDepthOrStencil())
|
||||
if(!phy_dev->IsDepthAttachmentOptimal(rbi->GetDepthFormat()))
|
||||
return(nullptr);
|
||||
}
|
||||
|
||||
RenderPassHASHCode hash;
|
||||
RenderPass *rp=nullptr;
|
||||
|
Loading…
x
Reference in New Issue
Block a user