From c3a5518b3805812b4d9d148c5edb062931e62958 Mon Sep 17 00:00:00 2001 From: hyzboy Date: Wed, 6 Nov 2024 00:34:23 +0800 Subject: [PATCH] moved Swapchain's codes to SwapchainModule --- inc/hgl/graph/VKDevice.h | 4 ---- inc/hgl/graph/VKSwapchain.h | 2 ++ inc/hgl/graph/module/GraphModule.h | 14 ++++++++++---- inc/hgl/graph/module/SwapchainModule.h | 6 ++++++ src/SceneGraph/Vulkan/VKDeviceSwapchain.cpp | 16 +++++++++------- src/SceneGraph/module/GraphModule.cpp | 4 ---- 6 files changed, 27 insertions(+), 19 deletions(-) diff --git a/inc/hgl/graph/VKDevice.h b/inc/hgl/graph/VKDevice.h index 0bce63d4..cc73d686 100644 --- a/inc/hgl/graph/VKDevice.h +++ b/inc/hgl/graph/VKDevice.h @@ -51,10 +51,6 @@ private: VkCommandBuffer CreateCommandBuffer(const AnsiString &); - bool CreateSwapchainFBO(Swapchain *); - - Swapchain *CreateSwapchain(const VkExtent2D &acquire_extent); - private: friend class VulkanDeviceCreater; diff --git a/inc/hgl/graph/VKSwapchain.h b/inc/hgl/graph/VKSwapchain.h index 6ccfdf5d..9a509193 100644 --- a/inc/hgl/graph/VKSwapchain.h +++ b/inc/hgl/graph/VKSwapchain.h @@ -11,6 +11,8 @@ public: VkDevice device =VK_NULL_HANDLE; + VkExtent2D extent; + VkSwapchainKHR swap_chain =VK_NULL_HANDLE; uint32_t color_count =0; diff --git a/inc/hgl/graph/module/GraphModule.h b/inc/hgl/graph/module/GraphModule.h index 615ae582..f3f4ea12 100644 --- a/inc/hgl/graph/module/GraphModule.h +++ b/inc/hgl/graph/module/GraphModule.h @@ -1,6 +1,7 @@ #pragma once #include +#include #include VK_NAMESPACE_BEGIN @@ -19,7 +20,10 @@ public: GraphModuleManager(GPUDevice *dev){device=dev;} ~GraphModuleManager(); - GPUDevice *GetDevice()noexcept{return device;} ///<取得GPU设备 + GPUDevice * GetDevice ()noexcept{return device;} ///<取得GPU设备 + VkDevice GetVkDevice (){return device->GetDevice();} + const GPUPhysicalDevice * GetPhysicalDevice (){return device->GetPhysicalDevice();} ///<取得物理设备 + const GPUDeviceAttribute *GetDeviceAttribute (){return device->GetDeviceAttribute();} ///<取得设备属性 /** * 获取指定名称的模块 @@ -66,9 +70,11 @@ public: virtual const bool IsRender(){return false;} ///<是否为渲染模块 - GraphModuleManager *GetManager(){return module_manager;} ///<取得模块管理器 - GPUDevice * GetDevice(){return module_manager->GetDevice();} ///<取得GPU设备 - GPUDeviceAttribute *GetDeviceAttribute(); + 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();}///<取得设备属性 static const AnsiIDName *GetModuleName(){return nullptr;} ///<取得模块名称(标准通用的名称,比如Upscale,供通用模块使用) virtual const AnsiIDName *GetName()const{return &module_name;} ///<取得名称(完整的私有名称,比如FSR3Upscale,DLSS3Upscale) diff --git a/inc/hgl/graph/module/SwapchainModule.h b/inc/hgl/graph/module/SwapchainModule.h index c8a2bd80..47a89919 100644 --- a/inc/hgl/graph/module/SwapchainModule.h +++ b/inc/hgl/graph/module/SwapchainModule.h @@ -10,6 +10,12 @@ class SwapchainModule:public GraphModule RTSwapchain *swapchain_rt=nullptr; +private: + + bool CreateSwapchainFBO(Swapchain *); + + Swapchain *CreateSwapchain(const VkExtent2D &acquire_extent); + public: GRAPH_MODULE_CONSTRUCT(Swapchain) diff --git a/src/SceneGraph/Vulkan/VKDeviceSwapchain.cpp b/src/SceneGraph/Vulkan/VKDeviceSwapchain.cpp index c0686a23..ada8e4e4 100644 --- a/src/SceneGraph/Vulkan/VKDeviceSwapchain.cpp +++ b/src/SceneGraph/Vulkan/VKDeviceSwapchain.cpp @@ -1,6 +1,8 @@ #include #include #include +#include +#include #include VK_NAMESPACE_BEGIN @@ -82,17 +84,17 @@ namespace } }//namespace -bool GPUDevice::CreateSwapchainFBO(Swapchain *swapchain) +bool SwapchainModule::CreateSwapchainFBO(Swapchain *swapchain) { - if(vkGetSwapchainImagesKHR(attr->device,swapchain->swap_chain,&(swapchain->color_count),nullptr)!=VK_SUCCESS) + if(vkGetSwapchainImagesKHR(swapchain->device,swapchain->swap_chain,&(swapchain->color_count),nullptr)!=VK_SUCCESS) return(false); AutoDeleteArray sc_images(swapchain->color_count); - if(vkGetSwapchainImagesKHR(attr->device,swapchain->swap_chain,&(swapchain->color_count),sc_images)!=VK_SUCCESS) + if(vkGetSwapchainImagesKHR(swapchain->device,swapchain->swap_chain,&(swapchain->color_count),sc_images)!=VK_SUCCESS) return(false); - swapchain->sc_depth =CreateTexture2D(new SwapchainDepthTextureCreateInfo(attr->physical_device->GetDepthFormat(),swapchain->extent)); + swapchain->sc_depth =CreateTexture2D(new SwapchainDepthTextureCreateInfo(GetPhysicalDevice()->GetDepthFormat(),swapchain->extent)); if(!swapchain->sc_depth) return(false); @@ -134,14 +136,14 @@ bool GPUDevice::CreateSwapchainFBO(Swapchain *swapchain) return(true); } -Swapchain *GPUDevice::CreateSwapchain(const VkExtent2D &acquire_extent) +Swapchain *SwapchainModule::CreateSwapchain(const VkExtent2D &acquire_extent) { Swapchain *swapchain=new Swapchain; - swapchain->device =attr->device; + swapchain->device =GetVkDevice(); swapchain->extent =acquire_extent; - swapchain->swap_chain =CreateSwapChain(attr,acquire_extent); + swapchain->swap_chain =CreateSwapChain(GetDeviceAttribute(),acquire_extent); if(swapchain->swap_chain) if(CreateSwapchainFBO(swapchain)) diff --git a/src/SceneGraph/module/GraphModule.cpp b/src/SceneGraph/module/GraphModule.cpp index b6a9f960..b9166ddb 100644 --- a/src/SceneGraph/module/GraphModule.cpp +++ b/src/SceneGraph/module/GraphModule.cpp @@ -3,9 +3,5 @@ VK_NAMESPACE_BEGIN -GPUDeviceAttribute *GraphModule::GetDeviceAttribute() -{ - return module_manager->GetDevice()->GetDeviceAttribute(); -} VK_NAMESPACE_END