improved Swapchain&SwapchainRenderTarget

This commit is contained in:
2021-12-15 20:46:33 +08:00
parent 14b9369739
commit ee9be8a4a2
8 changed files with 64 additions and 81 deletions

View File

@@ -5,7 +5,6 @@
#include<hgl/graph/VKImageView.h>
#include<hgl/graph/VKPipeline.h>
#include<hgl/graph/VKCommandBuffer.h>
//#include<hgl/graph/VKDescriptorSet.h>
#include<hgl/graph/VKRenderPass.h>
#include<hgl/graph/VKFramebuffer.h>
#include<hgl/graph/VKDescriptorSets.h>
@@ -42,7 +41,6 @@ GPUDevice::GPUDevice(GPUDeviceAttribute *da)
InitRenderPassManage();
swapchain=nullptr;
swapchainRT=nullptr;
Resize(attr->surface_caps.currentExtent);
@@ -57,7 +55,6 @@ GPUDevice::~GPUDevice()
ClearRenderPassManage();
SAFE_CLEAR(swapchainRT);
SAFE_CLEAR(swapchain);
SAFE_CLEAR(texture_queue);
SAFE_CLEAR(texture_cmd_buf);
@@ -68,13 +65,9 @@ GPUDevice::~GPUDevice()
bool GPUDevice::Resize(const VkExtent2D &extent)
{
SAFE_CLEAR(swapchainRT);
SAFE_CLEAR(swapchain);
attr->RefreshSurfaceCaps();
if(!CreateSwapchain(attr->surface_caps.currentExtent))
return(false);
swapchainRT=CreateSwapchainRenderTarget();
return(true);

View File

@@ -59,30 +59,21 @@ RenderTarget *GPUDevice::CreateRenderTarget(const FramebufferInfo *fbi,const uin
SwapchainRenderTarget *GPUDevice::CreateSwapchainRenderTarget()
{
const uint32_t count=swapchain->GetImageCount();
Swapchain *sc=CreateSwapchain(attr->surface_caps.currentExtent);
GPUQueue *q=CreateQueue(count,false);
if(!sc)
return(false);
GPUQueue *q=CreateQueue(sc->color_count,false);
GPUSemaphore *render_complete_semaphore=CreateGPUSemaphore();
GPUSemaphore *present_complete_semaphore=CreateGPUSemaphore();
Texture2D **sc_color=swapchain->GetColorTextures();
Texture2D *sc_depth=swapchain->GetDepthTexture();
Framebuffer **render_frame=new Framebuffer *[count];
for(uint32_t i=0;i<count;i++)
{
render_frame[i]=CreateFramebuffer(device_render_pass,(*sc_color)->GetImageView(),sc_depth->GetImageView());
++sc_color;
}
SwapchainRenderTarget *srt=new SwapchainRenderTarget( attr->device,
swapchain,
sc,
q,
render_complete_semaphore,
present_complete_semaphore,
device_render_pass,
render_frame
device_render_pass
);
return srt;

View File

@@ -68,46 +68,63 @@ namespace
}
}//namespace
bool GPUDevice::CreateSwapchainColorTexture()
bool GPUDevice::CreateSwapchainColorTexture(Swapchain *swapchain)
{
if(vkGetSwapchainImagesKHR(attr->device,swapchain->swap_chain,&(swapchain->swap_chain_count),nullptr)!=VK_SUCCESS)
if(vkGetSwapchainImagesKHR(attr->device,swapchain->swap_chain,&(swapchain->color_count),nullptr)!=VK_SUCCESS)
return(false);
AutoDeleteArray<VkImage> sc_images(swapchain->swap_chain_count);
AutoDeleteArray<VkImage> sc_images(swapchain->color_count);
if(vkGetSwapchainImagesKHR(attr->device,swapchain->swap_chain,&(swapchain->swap_chain_count),sc_images)!=VK_SUCCESS)
if(vkGetSwapchainImagesKHR(attr->device,swapchain->swap_chain,&(swapchain->color_count),sc_images)!=VK_SUCCESS)
return(false);
for(VkImage ip:sc_images)
swapchain->sc_color.Add(CreateTexture2D(new SwapchainColorTextureCreateInfo(attr->surface_format.format,swapchain->extent,ip)));
swapchain->sc_color=new Texture2D *[swapchain->color_count];
for(uint32_t i=0;i<swapchain->color_count;i++)
swapchain->sc_color[i]=CreateTexture2D(new SwapchainColorTextureCreateInfo(attr->surface_format.format,swapchain->extent,sc_images[i]));
return(true);
}
bool GPUDevice::CreateSwapchainDepthTexture()
bool GPUDevice::CreateSwapchainDepthTexture(Swapchain *swapchain)
{
swapchain->sc_depth=CreateTexture2D(new SwapchainDepthTextureCreateInfo(attr->physical_device->GetDepthFormat(),swapchain->extent));
return swapchain->sc_depth;
}
bool GPUDevice::CreateSwapchain(const VkExtent2D &acquire_extent)
void GPUDevice::CreateSwapchainFBO(Swapchain *swapchain)
{
swapchain=new Swapchain;
swapchain->render_frame=new Framebuffer *[swapchain->color_count];
for(uint32_t i=0;i<swapchain->color_count;i++)
{
swapchain->render_frame[i]=CreateFramebuffer( device_render_pass,
swapchain->sc_color[i]->GetImageView(),
swapchain->sc_depth->GetImageView());
}
}
Swapchain *GPUDevice::CreateSwapchain(const VkExtent2D &acquire_extent)
{
Swapchain *swapchain=new Swapchain;
swapchain->device =attr->device;
swapchain->extent =acquire_extent;
swapchain->graphics_queue =attr->graphics_queue;
swapchain->swap_chain =CreateSwapChain(attr,swapchain->extent);
swapchain->swap_chain =CreateSwapChain(attr,acquire_extent);
if(swapchain->swap_chain)
if(CreateSwapchainColorTexture())
if(CreateSwapchainDepthTexture())
return(true);
if(CreateSwapchainColorTexture(swapchain))
if(CreateSwapchainDepthTexture(swapchain))
{
CreateSwapchainFBO(swapchain);
return(swapchain);
}
delete swapchain;
swapchain=nullptr;
return(false);
return(nullptr);
}
VK_NAMESPACE_END

View File

@@ -1,10 +1,12 @@
#include<hgl/graph/VKSwapchain.h>
#include<hgl/graph/VKFramebuffer.h>
VK_NAMESPACE_BEGIN
Swapchain::~Swapchain()
{
SAFE_CLEAR_OBJECT_ARRAY(render_frame,color_count);
SAFE_CLEAR(sc_depth);
sc_color.Clear();
SAFE_CLEAR_OBJECT_ARRAY(sc_color,color_count)
if(swap_chain)
{
@@ -12,6 +14,6 @@ Swapchain::~Swapchain()
swap_chain=VK_NULL_HANDLE;
}
swap_chain_count=0;
color_count=0;
}
VK_NAMESPACE_END

View File

@@ -3,26 +3,21 @@
#include<hgl/graph/VKSemaphore.h>
VK_NAMESPACE_BEGIN
SwapchainRenderTarget::SwapchainRenderTarget(VkDevice dev,Swapchain *sc,GPUQueue *q,GPUSemaphore *rcs,GPUSemaphore *pcs,RenderPass *rp,Framebuffer **fbo_list):RenderTarget(q,rcs)
SwapchainRenderTarget::SwapchainRenderTarget(VkDevice dev,Swapchain *sc,GPUQueue *q,GPUSemaphore *rcs,GPUSemaphore *pcs,RenderPass *rp):RenderTarget(q,rcs)
{
device=dev;
swapchain=sc;
vk_swapchain=swapchain->GetSwapchain();
present_info.waitSemaphoreCount = 0;
present_info.pWaitSemaphores = nullptr;
present_info.swapchainCount = 1;
present_info.pResults = nullptr;
present_info.pSwapchains = &vk_swapchain;
present_info.pSwapchains = &(swapchain->swap_chain);
render_pass=rp;
swap_chain_count=swapchain->GetImageCount();
extent=swapchain->GetExtent();
render_frame=fbo_list;
extent=swapchain->extent;
current_frame=0;
@@ -31,14 +26,13 @@ SwapchainRenderTarget::SwapchainRenderTarget(VkDevice dev,Swapchain *sc,GPUQueue
SwapchainRenderTarget::~SwapchainRenderTarget()
{
SAFE_CLEAR_OBJECT_ARRAY(render_frame,swap_chain_count);
delete present_complete_semaphore;
delete swapchain;
}
int SwapchainRenderTarget::AcquireNextImage()
{
if(vkAcquireNextImageKHR(device,vk_swapchain,UINT64_MAX,*(this->present_complete_semaphore),VK_NULL_HANDLE,&current_frame)==VK_SUCCESS)
if(vkAcquireNextImageKHR(device,swapchain->swap_chain,UINT64_MAX,*(this->present_complete_semaphore),VK_NULL_HANDLE,&current_frame)==VK_SUCCESS)
return current_frame;
return -1;