From adc3c5bd81c0f9d5b0f0891491bd6feb4c343f17 Mon Sep 17 00:00:00 2001 From: hyzboy Date: Sat, 9 Nov 2024 19:28:31 +0800 Subject: [PATCH] all compile OK! but 100% can't run. --- inc/hgl/graph/VKDevice.h | 10 --- inc/hgl/graph/VKRenderTarget.h | 2 +- inc/hgl/graph/VKSwapchain.h | 8 +- inc/hgl/graph/font/FontSource.h | 4 +- inc/hgl/graph/font/TileFont.h | 4 +- inc/hgl/graph/manager/TextureManager.h | 2 + inc/hgl/graph/module/GraphModule.h | 12 +-- inc/hgl/graph/module/GraphModuleFactory.h | 4 +- inc/hgl/graph/module/SwapchainModule.h | 5 ++ src/SceneGraph/RenderFramework.cpp | 1 + src/SceneGraph/Vulkan/Texture/VKTexture.cpp | 2 +- src/SceneGraph/Vulkan/VKDevice.cpp | 17 ---- .../Vulkan/VKDeviceRenderTarget.cpp | 11 ++- src/SceneGraph/Vulkan/VKTexture.cpp | 2 +- src/SceneGraph/Vulkan/VKTileFont.cpp | 6 +- src/SceneGraph/manager/TextureManager.cpp | 4 + src/SceneGraph/mesh/StaticMesh.cpp | 1 + .../module/RegistryCommonModule.cpp | 4 +- src/SceneGraph/module/SwapchainModule.cpp | 77 +++++++++++-------- 19 files changed, 95 insertions(+), 81 deletions(-) diff --git a/inc/hgl/graph/VKDevice.h b/inc/hgl/graph/VKDevice.h index 44d28292..d4ee7452 100644 --- a/inc/hgl/graph/VKDevice.h +++ b/inc/hgl/graph/VKDevice.h @@ -67,16 +67,6 @@ public: DebugUtils * GetDebugUtils (){return attr->debug_utils;} -public: - - bool Resize (const VkExtent2D &); - bool Resize (const uint32_t &w,const uint32_t &h) - { - VkExtent2D extent={w,h}; - - return Resize(extent); - } - public: //内存相关 DeviceMemory *CreateMemory(const VkMemoryRequirements &,const uint32_t properties); diff --git a/inc/hgl/graph/VKRenderTarget.h b/inc/hgl/graph/VKRenderTarget.h index fbd933f7..d99ece3a 100644 --- a/inc/hgl/graph/VKRenderTarget.h +++ b/inc/hgl/graph/VKRenderTarget.h @@ -32,7 +32,7 @@ protected: protected: - friend class GPUDevice; + friend class TextureManager; RenderTarget(DeviceQueue *,Semaphore *); RenderTarget(DeviceQueue *,Semaphore *,RenderPass *_rp,Framebuffer *_fb,Texture2D **color_texture_list,const uint32_t color_count,Texture2D *depth_texture); diff --git a/inc/hgl/graph/VKSwapchain.h b/inc/hgl/graph/VKSwapchain.h index 6ccfdf5d..e7c5437f 100644 --- a/inc/hgl/graph/VKSwapchain.h +++ b/inc/hgl/graph/VKSwapchain.h @@ -10,9 +10,15 @@ struct Swapchain public: VkDevice device =VK_NULL_HANDLE; - + + VkExtent2D extent; + VkSurfaceTransformFlagBitsKHR transform; + VkSwapchainKHR swap_chain =VK_NULL_HANDLE; + VkSurfaceFormatKHR surface_format; + VkFormat depth_format; + uint32_t color_count =0; Texture2D ** sc_color =nullptr; diff --git a/inc/hgl/graph/font/FontSource.h b/inc/hgl/graph/font/FontSource.h index f8d2ac01..cc5a64fe 100644 --- a/inc/hgl/graph/font/FontSource.h +++ b/inc/hgl/graph/font/FontSource.h @@ -3,7 +3,7 @@ #include #include -#include +#include #include #include @@ -71,7 +71,7 @@ namespace hgl { protected: - SortedSets ref_object; + SortedSet ref_object; ObjectMap cla_cache; diff --git a/inc/hgl/graph/font/TileFont.h b/inc/hgl/graph/font/TileFont.h index 74e31ab5..0844388b 100644 --- a/inc/hgl/graph/font/TileFont.h +++ b/inc/hgl/graph/font/TileFont.h @@ -24,7 +24,7 @@ namespace hgl TileResPool to_res; - SortedSets not_bitmap_chars; + SortedSet not_bitmap_chars; public: @@ -37,7 +37,7 @@ namespace hgl TileFont(TileData *td,FontSource *fs); virtual ~TileFont(); - bool Registry(TileUVFloatMap &,SortedSets &chars_sets); ///<注册要使用的字符 + bool Registry(TileUVFloatMap &,SortedSet &chars_sets); ///<注册要使用的字符 void Unregistry(const List &); ///<注销要使用的字符 };//class TileFont }//namespace graph diff --git a/inc/hgl/graph/manager/TextureManager.h b/inc/hgl/graph/manager/TextureManager.h index d6397b67..3a725c28 100644 --- a/inc/hgl/graph/manager/TextureManager.h +++ b/inc/hgl/graph/manager/TextureManager.h @@ -42,6 +42,8 @@ public: bool Init() override; + const VkFormatProperties GetFormatProperties(const VkFormat)const; + public: //Buffer DeviceBuffer *CreateTransferSourceBuffer(const VkDeviceSize,const void *data_ptr=nullptr); diff --git a/inc/hgl/graph/module/GraphModule.h b/inc/hgl/graph/module/GraphModule.h index f102147a..88002a00 100644 --- a/inc/hgl/graph/module/GraphModule.h +++ b/inc/hgl/graph/module/GraphModule.h @@ -21,9 +21,9 @@ public: ~GraphModuleManager(); GPUDevice * GetDevice ()noexcept{return device;} ///<取得GPU设备 - VkDevice GetVkDevice (){return device->GetDevice();} - const GPUPhysicalDevice * GetPhysicalDevice (){return device->GetPhysicalDevice();} ///<取得物理设备 - const GPUDeviceAttribute *GetDeviceAttribute (){return device->GetDeviceAttribute();} ///<取得设备属性 + VkDevice GetVkDevice ()const{return device->GetDevice();} + const GPUPhysicalDevice * GetPhysicalDevice ()const{return device->GetPhysicalDevice();} ///<取得物理设备 + GPUDeviceAttribute *GetDeviceAttribute (){return device->GetDeviceAttribute();} ///<取得设备属性 /** * 获取指定名称的模块 @@ -72,9 +72,9 @@ public: GraphModuleManager *GetManager (){return module_manager;} ///<取得模块管理器 GPUDevice * GetDevice (){return module_manager->GetDevice();} ///<取得GPU设备 - VkDevice GetVkDevice (){return module_manager->GetVkDevice();} ///<取得VkDevice - const GPUPhysicalDevice * GetPhysicalDevice (){return module_manager->GetPhysicalDevice();} ///<取得物理设备 - const GPUDeviceAttribute *GetDeviceAttribute (){return module_manager->GetDeviceAttribute();}///<取得设备属性 + VkDevice GetVkDevice ()const{return module_manager->GetVkDevice();} ///<取得VkDevice + const GPUPhysicalDevice * GetPhysicalDevice ()const{return module_manager->GetPhysicalDevice();} ///<取得物理设备 + GPUDeviceAttribute *GetDeviceAttribute (){return module_manager->GetDeviceAttribute();}///<取得设备属性 static const AnsiIDName *GetModuleName(){return nullptr;} ///<取得模块名称(标准通用的名称,比如Upscale,供通用模块使用) virtual const AnsiIDName *GetName()const{return &module_name;} ///<取得名称(完整的私有名称,比如FSR3Upscale,DLSS3Upscale) diff --git a/inc/hgl/graph/module/GraphModuleFactory.h b/inc/hgl/graph/module/GraphModuleFactory.h index b0803edb..2a83dfa3 100644 --- a/inc/hgl/graph/module/GraphModuleFactory.h +++ b/inc/hgl/graph/module/GraphModuleFactory.h @@ -36,10 +36,10 @@ public: return(nullptr); } - return(true); + return(gm); } };//template class RegistryGraphModule:public GraphModuleFactory -#define REGISTRY_GRAPH_MODULE(Class) {RegistryGraphModuleFactory(#Class,new RegistryGraphModule);} +#define REGISTRY_GRAPH_MODULE(Class) {RegistryGraphModuleFactory(#Class,new RegistryGraphModule);} VK_NAMESPACE_END \ No newline at end of file diff --git a/inc/hgl/graph/module/SwapchainModule.h b/inc/hgl/graph/module/SwapchainModule.h index 44e7a23a..67701304 100644 --- a/inc/hgl/graph/module/SwapchainModule.h +++ b/inc/hgl/graph/module/SwapchainModule.h @@ -16,6 +16,11 @@ protected: bool CreateSwapchainFBO(); bool CreateSwapchain(); + bool CreateSwapchainRenderTarget(); + +public: + + virtual void OnResize(const VkExtent2D &)override; ///<窗口大小改变 public: diff --git a/src/SceneGraph/RenderFramework.cpp b/src/SceneGraph/RenderFramework.cpp index dd476a7b..60d01590 100644 --- a/src/SceneGraph/RenderFramework.cpp +++ b/src/SceneGraph/RenderFramework.cpp @@ -1,4 +1,5 @@ #include +#include #include #include diff --git a/src/SceneGraph/Vulkan/Texture/VKTexture.cpp b/src/SceneGraph/Vulkan/Texture/VKTexture.cpp index f14150d1..efadaed5 100644 --- a/src/SceneGraph/Vulkan/Texture/VKTexture.cpp +++ b/src/SceneGraph/Vulkan/Texture/VKTexture.cpp @@ -16,7 +16,7 @@ DeviceBuffer *TextureManager::CreateTransferSourceBuffer(const VkDeviceSize size bool TextureManager::CheckFormatSupport(const VkFormat format,const uint32_t bits,ImageTiling tiling) const { - const VkFormatProperties fp=GetPhysicalDevice()->GetFormatProperties(format); + const VkFormatProperties fp=GetFormatProperties(format); if(tiling==ImageTiling::Optimal) return(fp.optimalTilingFeatures&bits); diff --git a/src/SceneGraph/Vulkan/VKDevice.cpp b/src/SceneGraph/Vulkan/VKDevice.cpp index 9537ecf6..e0f39a23 100644 --- a/src/SceneGraph/Vulkan/VKDevice.cpp +++ b/src/SceneGraph/Vulkan/VKDevice.cpp @@ -8,7 +8,6 @@ #include #include #include -#include #include #include @@ -19,27 +18,11 @@ bool ClearGraphModuleManager(GPUDevice *dev); GPUDevice::GPUDevice(GPUDeviceAttribute *da) { attr=da; - - Resize(attr->surface_caps.currentExtent); } GPUDevice::~GPUDevice() { delete attr; - - //按设计,上面那些rt/queue/cmdbuf都需要走graph_module_manager释放和申请 - ClearGraphModuleManager(this); -} - -bool GPUDevice::Resize(const VkExtent2D &extent) -{ - SAFE_CLEAR(sc_rt); - - attr->RefreshSurfaceCaps(); - - sc_rt=CreateSwapchainRenderTarget(); - - return(sc_rt); } VkCommandBuffer GPUDevice::CreateCommandBuffer(const AnsiString &name) diff --git a/src/SceneGraph/Vulkan/VKDeviceRenderTarget.cpp b/src/SceneGraph/Vulkan/VKDeviceRenderTarget.cpp index e51dfff0..0c55e78a 100644 --- a/src/SceneGraph/Vulkan/VKDeviceRenderTarget.cpp +++ b/src/SceneGraph/Vulkan/VKDeviceRenderTarget.cpp @@ -1,5 +1,6 @@ #include #include +#include VK_NAMESPACE_BEGIN RenderTarget *TextureManager::CreateRT(const FramebufferInfo *fbi,RenderPass *rp,const uint32_t fence_count) @@ -34,8 +35,10 @@ RenderTarget *TextureManager::CreateRT(const FramebufferInfo *fbi,RenderPass *rp if(fb) { - DeviceQueue *q=CreateQueue(fence_count,false); - Semaphore *render_complete_semaphore=CreateGPUSemaphore(); + auto *dev=GetDevice(); + + DeviceQueue *q=dev->CreateQueue(fence_count,false); + Semaphore *render_complete_semaphore=dev->CreateGPUSemaphore(); RenderTarget *rt=new RenderTarget(q,render_complete_semaphore,rp,fb,color_texture_list,color_count,depth_texture); @@ -51,7 +54,9 @@ RenderTarget *TextureManager::CreateRT(const FramebufferInfo *fbi,const uint32_t { if(!fbi)return(nullptr); - RenderPass *rp=AcquireRenderPass(fbi); + RenderPassManager *rpm=GetModule(); + + RenderPass *rp=rpm->AcquireRenderPass(fbi); if(!rp)return(nullptr); diff --git a/src/SceneGraph/Vulkan/VKTexture.cpp b/src/SceneGraph/Vulkan/VKTexture.cpp index af541e52..a7c95b30 100644 --- a/src/SceneGraph/Vulkan/VKTexture.cpp +++ b/src/SceneGraph/Vulkan/VKTexture.cpp @@ -17,7 +17,7 @@ Texture::~Texture() delete data->memory; if(data->image) - vkDestroyImage(device,data->image,nullptr); + vkDestroyImage(manager->GetVkDevice(),data->image,nullptr); } } VK_NAMESPACE_END diff --git a/src/SceneGraph/Vulkan/VKTileFont.cpp b/src/SceneGraph/Vulkan/VKTileFont.cpp index 6df1822b..7c7428cb 100644 --- a/src/SceneGraph/Vulkan/VKTileFont.cpp +++ b/src/SceneGraph/Vulkan/VKTileFont.cpp @@ -1,5 +1,7 @@ #include -#include +#include +#include + VK_NAMESPACE_BEGIN /** @@ -15,7 +17,7 @@ TileFont *RenderFramework::CreateTileFont(FontSource *fs,int limit_count) if(limit_count<=0) { - const VkExtent2D &ext=GetSwapchainSize(); + const VkExtent2D &ext=swapchain_module->GetSwapchainSize(); limit_count=(ext.width/height)*(ext.height/height); //按全屏幕放满不一样的字符为上限 } diff --git a/src/SceneGraph/manager/TextureManager.cpp b/src/SceneGraph/manager/TextureManager.cpp index a1493cc3..8a616168 100644 --- a/src/SceneGraph/manager/TextureManager.cpp +++ b/src/SceneGraph/manager/TextureManager.cpp @@ -3,6 +3,10 @@ #include VK_NAMESPACE_BEGIN +const VkFormatProperties TextureManager::GetFormatProperties(const VkFormat format) const +{ + return GetPhysicalDevice()->GetFormatProperties(format); +} bool TextureManager::Init() { diff --git a/src/SceneGraph/mesh/StaticMesh.cpp b/src/SceneGraph/mesh/StaticMesh.cpp index 8cbe2849..278c338f 100644 --- a/src/SceneGraph/mesh/StaticMesh.cpp +++ b/src/SceneGraph/mesh/StaticMesh.cpp @@ -1,5 +1,6 @@ #include #include +#include VK_NAMESPACE_BEGIN diff --git a/src/SceneGraph/module/RegistryCommonModule.cpp b/src/SceneGraph/module/RegistryCommonModule.cpp index b1838d8f..37adfaf2 100644 --- a/src/SceneGraph/module/RegistryCommonModule.cpp +++ b/src/SceneGraph/module/RegistryCommonModule.cpp @@ -1,5 +1,6 @@ #include #include +#include #include VK_NAMESPACE_BEGIN @@ -7,7 +8,8 @@ VK_NAMESPACE_BEGIN void RegistryCommonGraphModule() { REGISTRY_GRAPH_MODULE(TextureManager) - REGISTRY_GRAPH_MODULE(Swapchain) + REGISTRY_GRAPH_MODULE(RenderPassManager) + REGISTRY_GRAPH_MODULE(SwapchainModule) } VK_NAMESPACE_END diff --git a/src/SceneGraph/module/SwapchainModule.cpp b/src/SceneGraph/module/SwapchainModule.cpp index 991baf73..51e9a2ba 100644 --- a/src/SceneGraph/module/SwapchainModule.cpp +++ b/src/SceneGraph/module/SwapchainModule.cpp @@ -95,13 +95,12 @@ bool SwapchainModule::CreateSwapchainFBO() if(vkGetSwapchainImagesKHR(swapchain->device,swapchain->swap_chain,&(swapchain->color_count),sc_images)!=VK_SUCCESS) return(false); - const auto *dev_attr=GetDeviceAttribute(); TextureManager *tex_manager=GetModule(); if(!tex_manager) return(false); - swapchain->sc_depth =tex_manager->CreateTexture2D(new SwapchainDepthTextureCreateInfo(GetPhysicalDevice()->GetDepthFormat(),dev_attr->surface_caps.currentExtent)); + swapchain->sc_depth =tex_manager->CreateTexture2D(new SwapchainDepthTextureCreateInfo(GetPhysicalDevice()->GetDepthFormat(),swapchain->extent)); if(!swapchain->sc_depth) return(false); @@ -120,7 +119,7 @@ bool SwapchainModule::CreateSwapchainFBO() for(uint32_t i=0;icolor_count;i++) { - swapchain->sc_color[i]=tex_manager->CreateTexture2D(new SwapchainColorTextureCreateInfo(dev_attr->surface_format.format,dev_attr->surface_caps.currentExtent,sc_images[i])); + swapchain->sc_color[i]=tex_manager->CreateTexture2D(new SwapchainColorTextureCreateInfo(swapchain->surface_format.format,swapchain->extent,sc_images[i])); if(!swapchain->sc_color[i]) return(false); @@ -155,7 +154,11 @@ bool SwapchainModule::CreateSwapchain() swapchain=new Swapchain; - swapchain->device=dev_attr->device; + swapchain->device =dev_attr->device; + swapchain->extent =dev_attr->surface_caps.currentExtent; + swapchain->transform =dev_attr->surface_caps.currentTransform; + swapchain->surface_format =dev_attr->surface_format; + swapchain->depth_format =dev_attr->physical_device->GetDepthFormat(); swapchain->swap_chain=CreateVulkanSwapChain(dev_attr); @@ -170,6 +173,25 @@ bool SwapchainModule::CreateSwapchain() return(false); } +bool SwapchainModule::CreateSwapchainRenderTarget() +{ + GPUDevice *device=GetDevice(); + + DeviceQueue *q=device->CreateQueue(swapchain->color_count,false); + Semaphore *render_complete_semaphore=device->CreateGPUSemaphore(); + Semaphore *present_complete_semaphore=device->CreateGPUSemaphore(); + + swapchain_rt=new RTSwapchain( device->GetDevice(), + swapchain, + q, + render_complete_semaphore, + present_complete_semaphore, + swapchain_rp + ); + + return true; +} + SwapchainModule::~SwapchainModule() { if(swapchain_rt) @@ -181,45 +203,36 @@ SwapchainModule::~SwapchainModule() bool SwapchainModule::Init() { + if(!CreateSwapchain()) + return(false); + RenderPassManager *rpm=GetModule(); if(!rpm) return(false); - { - auto *dev_attr=GetDeviceAttribute(); + SwapchainRenderbufferInfo rbi(swapchain->surface_format.format,swapchain->depth_format); - SwapchainRenderbufferInfo rbi(dev_attr->surface_format.format,dev_attr->physical_device->GetDepthFormat()); + swapchain_rp=rpm->AcquireRenderPass(&rbi); - swapchain_rp=rpm->AcquireRenderPass(&rbi); + //#ifdef _DEBUG + // if(dev_attr->debug_utils) + // dev_attr->debug_utils->SetRenderPass(swapchain_rp->GetVkRenderPass(),"SwapchainRenderPass"); + //#endif//_DEBUG - #ifdef _DEBUG - if(dev_attr->debug_utils) - dev_attr->debug_utils->SetRenderPass(swapchain_rp->GetVkRenderPass(),"SwapchainRenderPass"); - #endif//_DEBUG - } - - - if(!CreateSwapchain()) + if(!CreateSwapchainRenderTarget()) return(false); - { - GPUDevice *device=GetDevice(); - - DeviceQueue *q=device->CreateQueue(swapchain->color_count,false); - Semaphore *render_complete_semaphore=device->CreateGPUSemaphore(); - Semaphore *present_complete_semaphore=device->CreateGPUSemaphore(); - - swapchain_rt=new RTSwapchain( device->GetDevice(), - swapchain, - q, - render_complete_semaphore, - present_complete_semaphore, - swapchain_rp - ); - } - return true; } +void SwapchainModule::OnResize(const VkExtent2D &extent) +{ + SAFE_CLEAR(swapchain_rt) + + GetDeviceAttribute()->RefreshSurfaceCaps(); + + CreateSwapchainRenderTarget(); +} + VK_NAMESPACE_END