improved Swapchain&SwapchainRenderTarget
This commit is contained in:
parent
14b9369739
commit
ee9be8a4a2
@ -39,7 +39,6 @@ private:
|
||||
DeviceRenderPassManage *render_pass_manage;
|
||||
RenderPass *device_render_pass;
|
||||
|
||||
Swapchain *swapchain;
|
||||
SwapchainRenderTarget *swapchainRT;
|
||||
|
||||
SwapchainRenderTarget *CreateSwapchainRenderTarget();
|
||||
@ -51,10 +50,11 @@ private:
|
||||
|
||||
VkCommandBuffer CreateCommandBuffer();
|
||||
|
||||
bool CreateSwapchainColorTexture();
|
||||
bool CreateSwapchainDepthTexture();
|
||||
bool CreateSwapchainColorTexture(Swapchain *);
|
||||
bool CreateSwapchainDepthTexture(Swapchain *);
|
||||
void CreateSwapchainFBO(Swapchain *);
|
||||
|
||||
bool CreateSwapchain(const VkExtent2D &acquire_extent);
|
||||
Swapchain *CreateSwapchain(const VkExtent2D &acquire_extent);
|
||||
|
||||
private:
|
||||
|
||||
@ -81,13 +81,12 @@ public:
|
||||
VkQueue GetGraphicsQueue () {return attr->graphics_queue;}
|
||||
|
||||
RenderPass * GetRenderPass () {return device_render_pass;}
|
||||
Swapchain * GetSwapchain () {return swapchain;}
|
||||
|
||||
SwapchainRenderTarget * GetSwapchainRT () {return swapchainRT;}
|
||||
|
||||
public:
|
||||
const VkExtent2D & GetSwapchainSize ()const {return swapchainRT->GetExtent();}
|
||||
|
||||
const VkExtent2D & GetSwapchainSize ()const {return swapchain->extent;}
|
||||
public:
|
||||
|
||||
bool Resize (const VkExtent2D &);
|
||||
bool Resize (const uint32_t &w,const uint32_t &h)
|
||||
|
@ -66,29 +66,25 @@ class SwapchainRenderTarget:public RenderTarget
|
||||
{
|
||||
VkDevice device;
|
||||
Swapchain *swapchain;
|
||||
VkSwapchainKHR vk_swapchain;
|
||||
PresentInfo present_info;
|
||||
|
||||
GPUSemaphore *present_complete_semaphore=nullptr;
|
||||
|
||||
uint32_t swap_chain_count;
|
||||
|
||||
uint32_t current_frame;
|
||||
Framebuffer **render_frame;
|
||||
|
||||
public:
|
||||
|
||||
SwapchainRenderTarget(VkDevice dev,Swapchain *sc,GPUQueue *q,GPUSemaphore *rcs,GPUSemaphore *pcs,RenderPass *rp,Framebuffer **fbo_list);
|
||||
SwapchainRenderTarget(VkDevice dev,Swapchain *sc,GPUQueue *q,GPUSemaphore *rcs,GPUSemaphore *pcs,RenderPass *rp);
|
||||
~SwapchainRenderTarget();
|
||||
|
||||
Framebuffer * GetFramebuffer ()override {return render_frame[current_frame];}
|
||||
Framebuffer * GetFramebuffer (const uint32_t index) {return render_frame[index];}
|
||||
Framebuffer * GetFramebuffer ()override {return swapchain->render_frame[current_frame];}
|
||||
Framebuffer * GetFramebuffer (const uint32_t index) {return swapchain->render_frame[index];}
|
||||
|
||||
const uint32_t GetColorCount ()const override {return 1;}
|
||||
const uint32_t GetImageCount ()const {return swap_chain_count;}
|
||||
const uint32_t GetImageCount ()const {return swapchain->color_count;}
|
||||
|
||||
virtual Texture2D * GetColorTexture (const int index=0) override{return swapchain->GetColorTexture(index);}
|
||||
virtual Texture2D * GetDepthTexture () override{return swapchain->GetDepthTexture();}
|
||||
virtual Texture2D * GetColorTexture (const int index=0) override{return swapchain->sc_color[index];}
|
||||
virtual Texture2D * GetDepthTexture () override{return swapchain->sc_depth;}
|
||||
|
||||
public:
|
||||
|
||||
|
@ -13,23 +13,14 @@ public:
|
||||
|
||||
VkExtent2D extent;
|
||||
|
||||
VkQueue graphics_queue =VK_NULL_HANDLE;
|
||||
VkSwapchainKHR swap_chain =VK_NULL_HANDLE;
|
||||
|
||||
uint32_t swap_chain_count=0;
|
||||
uint32_t color_count=0;
|
||||
|
||||
ObjectList<Texture2D> sc_color;
|
||||
Texture2D ** sc_color =nullptr;
|
||||
Texture2D * sc_depth =nullptr;
|
||||
|
||||
public:
|
||||
|
||||
VkSwapchainKHR GetSwapchain () {return swap_chain;}
|
||||
const VkExtent2D & GetExtent ()const {return extent;}
|
||||
const uint32_t GetImageCount ()const {return sc_color.GetCount();}
|
||||
|
||||
Texture2D ** GetColorTextures () {return sc_color.GetData();}
|
||||
Texture2D * GetColorTexture (int index) {return sc_color[index];}
|
||||
Texture2D * GetDepthTexture () {return sc_depth;}
|
||||
Framebuffer ** render_frame =nullptr;
|
||||
|
||||
public:
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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,¤t_frame)==VK_SUCCESS)
|
||||
if(vkAcquireNextImageKHR(device,swapchain->swap_chain,UINT64_MAX,*(this->present_complete_semaphore),VK_NULL_HANDLE,¤t_frame)==VK_SUCCESS)
|
||||
return current_frame;
|
||||
|
||||
return -1;
|
||||
|
Loading…
x
Reference in New Issue
Block a user