example 0/1 run OK on newly RenderTarget
This commit is contained in:
parent
0706f27354
commit
774f106738
@ -1,6 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include<hgl/WorkObject.h>
|
#include<hgl/WorkObject.h>
|
||||||
|
#include<hgl/graph/VKRenderTargetSwapchain.h>
|
||||||
|
|
||||||
namespace hgl
|
namespace hgl
|
||||||
{
|
{
|
||||||
@ -49,13 +50,13 @@ namespace hgl
|
|||||||
|
|
||||||
class SwapchainWorkManager:public WorkManager,public io::WindowEvent
|
class SwapchainWorkManager:public WorkManager,public io::WindowEvent
|
||||||
{
|
{
|
||||||
graph::SwapchainModule *swpachain_module;
|
graph::SwapchainModule *swapchain_module;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
SwapchainWorkManager(graph::RenderFramework *rf):WorkManager(rf)
|
SwapchainWorkManager(graph::RenderFramework *rf):WorkManager(rf)
|
||||||
{
|
{
|
||||||
swpachain_module=rf->GetSwapchainModule();
|
swapchain_module=rf->GetSwapchainModule();
|
||||||
|
|
||||||
render_framework->Join(this);
|
render_framework->Join(this);
|
||||||
}
|
}
|
||||||
|
@ -35,6 +35,8 @@ struct VertexAttribDataPtr
|
|||||||
using BindingMap =Map<AnsiString,int>;
|
using BindingMap =Map<AnsiString,int>;
|
||||||
using BindingMapArray =BindingMap[VK_DESCRIPTOR_TYPE_RANGE_SIZE];
|
using BindingMapArray =BindingMap[VK_DESCRIPTOR_TYPE_RANGE_SIZE];
|
||||||
|
|
||||||
|
class DescriptorBinding;
|
||||||
|
|
||||||
class GraphModule;
|
class GraphModule;
|
||||||
class RenderFramework;
|
class RenderFramework;
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include<hgl/graph/VKFramebuffer.h>
|
#include<hgl/graph/VK.h>
|
||||||
|
|
||||||
VK_NAMESPACE_BEGIN
|
VK_NAMESPACE_BEGIN
|
||||||
|
|
||||||
@ -26,6 +26,12 @@ public:
|
|||||||
return color_textures[index];
|
return color_textures[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Submit(Semaphore *wait_sem);
|
||||||
|
|
||||||
|
RenderCmdBuffer *BeginRender(DescriptorBinding *);
|
||||||
|
|
||||||
|
void EndRender();
|
||||||
|
|
||||||
virtual void Clear();
|
virtual void Clear();
|
||||||
};//struct RenderTargetData
|
};//struct RenderTargetData
|
||||||
|
|
||||||
|
@ -31,64 +31,66 @@ protected:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
virtual ~MultiFrameRenderTarget() override;
|
virtual ~MultiFrameRenderTarget() override
|
||||||
|
{
|
||||||
|
for(uint32_t i=0;i<frame_number;i++)
|
||||||
|
rtd_list[i].Clear();
|
||||||
|
|
||||||
virtual void NextFrame()
|
delete[] rtd_list;
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual bool NextFrame()
|
||||||
{
|
{
|
||||||
++current_frame;
|
++current_frame;
|
||||||
|
|
||||||
if(current_frame>=frame_number)
|
if(current_frame>=frame_number)
|
||||||
current_frame=0;
|
current_frame=0;
|
||||||
|
|
||||||
|
return(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t GetCurrentFrameIndices ()const{return current_frame;}
|
uint32_t GetCurrentFrameIndices ()const{return current_frame;}
|
||||||
uint32_t GetFrameCount ()const{return frame_number;}
|
uint32_t GetFrameCount ()const{return frame_number;}
|
||||||
RenderTarget * GetCurrentFrameRenderTarget (){return rt_list[current_frame];}
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
Framebuffer * GetFramebuffer ()override{return rt_list[current_frame]->GetFramebuffer();}
|
Framebuffer * GetFramebuffer ()override{return rtd_list[current_frame].fbo;}
|
||||||
RenderPass * GetRenderPass ()override{return rt_list[current_frame]->GetRenderPass();}
|
RenderPass * GetRenderPass ()override{return rtd_list[current_frame].fbo->GetRenderPass();}
|
||||||
|
|
||||||
uint32_t GetColorCount ()override{return rt_list[current_frame]->GetColorCount();}
|
uint32_t GetColorCount ()override{return rtd_list[current_frame].color_count;}
|
||||||
|
|
||||||
Texture2D * GetColorTexture (const int index=0) override{return rt_list[current_frame]->GetColorTexture(index);}
|
Texture2D * GetColorTexture (const int index=0) override{return rtd_list[current_frame].GetColorTexture(index);}
|
||||||
Texture2D * GetDepthTexture () override{return rt_list[current_frame]->GetDepthTexture();}
|
Texture2D * GetDepthTexture () override{return rtd_list[current_frame].depth_texture;}
|
||||||
|
|
||||||
|
|
||||||
bool hasDepth ()override{return rt_list[current_frame]->hasDepth();}
|
bool hasDepth ()override{return rtd_list[current_frame].depth_texture;}
|
||||||
|
|
||||||
public: // Command Buffer
|
public: // Command Buffer
|
||||||
|
|
||||||
DeviceQueue * GetQueue ()override{return rt_list[current_frame]->GetQueue();}
|
DeviceQueue * GetQueue ()override{return rtd_list[current_frame].queue;}
|
||||||
Semaphore * GetRenderCompleteSemaphore()override{return rt_list[current_frame]->GetRenderCompleteSemaphore();}
|
Semaphore * GetRenderCompleteSemaphore ()override{return rtd_list[current_frame].render_complete_semaphore;}
|
||||||
RenderCmdBuffer * GetRenderCmdBuffer ()override{return rt_list[current_frame]->GetRenderCmdBuffer();}
|
RenderCmdBuffer * GetRenderCmdBuffer ()override{return rtd_list[current_frame].cmd_buf;}
|
||||||
|
|
||||||
Framebuffer * GetFramebuffer (const uint32_t index){return rt_list[index]->GetFramebuffer();}
|
Framebuffer * GetFramebuffer (const uint32_t index){return rtd_list[index].fbo;}
|
||||||
RenderCmdBuffer * GetRenderCmdBuffer (const uint32_t index){return rt_list[index]->GetRenderCmdBuffer();}
|
RenderCmdBuffer * GetRenderCmdBuffer (const uint32_t index){return rtd_list[index].cmd_buf;}
|
||||||
|
|
||||||
virtual bool Submit ()override{return rt_list[current_frame]->Submit(nullptr);}
|
virtual bool Submit (Semaphore *wait_sem)override{return rtd_list[current_frame].Submit(wait_sem);}
|
||||||
|
|
||||||
virtual bool Submit (Semaphore *wait_sem) override
|
bool WaitQueue ()override{return rtd_list[current_frame].queue->WaitQueue();}
|
||||||
{
|
bool WaitFence ()override{return rtd_list[current_frame].queue->WaitFence();}
|
||||||
return rt_list[current_frame]->Submit(wait_sem);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool WaitQueue ()override{return rt_list[current_frame]->WaitQueue();}
|
|
||||||
bool WaitFence ()override{return rt_list[current_frame]->WaitFence();}
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
virtual RenderCmdBuffer *BeginRender()override
|
virtual RenderCmdBuffer *BeginRender()override
|
||||||
{
|
{
|
||||||
//std::cout<<"Begin Render frame="<<current_frame<<std::endl;
|
//std::cout<<"Begin Render frame="<<current_frame<<std::endl;
|
||||||
return rt_list[current_frame]->BeginRender();
|
return rtd_list[current_frame].BeginRender(GetDescriptorBinding());
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void EndRender() override
|
virtual void EndRender() override
|
||||||
{
|
{
|
||||||
//std::cout<<"End Render frame="<<current_frame<<std::endl;
|
//std::cout<<"End Render frame="<<current_frame<<std::endl;
|
||||||
rt_list[current_frame]->EndRender();
|
rtd_list[current_frame].EndRender();
|
||||||
}
|
}
|
||||||
};//class MultiFrameRenderTarget
|
};//class MultiFrameRenderTarget
|
||||||
|
|
||||||
|
@ -57,7 +57,7 @@ public: // Command Buffer
|
|||||||
if(!data)
|
if(!data)
|
||||||
return(false);
|
return(false);
|
||||||
|
|
||||||
return data->queue->Submit(data->cmd_buf,wait_sem,data->render_complete_semaphore);
|
return data->Submit(wait_sem);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool WaitQueue ()override{return data->queue->WaitQueue();}
|
bool WaitQueue ()override{return data->queue->WaitQueue();}
|
||||||
@ -67,21 +67,18 @@ public:
|
|||||||
|
|
||||||
virtual RenderCmdBuffer *BeginRender()override
|
virtual RenderCmdBuffer *BeginRender()override
|
||||||
{
|
{
|
||||||
if(!data->cmd_buf)
|
if(!data)
|
||||||
return(nullptr);
|
return(nullptr);
|
||||||
|
|
||||||
data->cmd_buf->Begin();
|
return data->BeginRender(GetDescriptorBinding());
|
||||||
data->cmd_buf->SetDescriptorBinding(GetDescriptorBinding());
|
|
||||||
data->cmd_buf->BindFramebuffer(data->fbo);
|
|
||||||
return data->cmd_buf;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void EndRender() override
|
virtual void EndRender() override
|
||||||
{
|
{
|
||||||
if(!data->cmd_buf)
|
if(!data)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
data->cmd_buf->End();
|
data->EndRender();
|
||||||
}
|
}
|
||||||
};//class RenderTarget
|
};//class RenderTarget
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@ class SwapchainRenderTarget:public MultiFrameRenderTarget
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
SwapchainRenderTarget(RenderFramework *rf,Swapchain *sc,Semaphore *pcs,RenderTarget **rtl);
|
SwapchainRenderTarget(RenderFramework *rf,Swapchain *sc,Semaphore *pcs,RenderTargetData *rtdl);
|
||||||
|
|
||||||
friend class SwapchainModule;
|
friend class SwapchainModule;
|
||||||
friend class RenderTargetManager;
|
friend class RenderTargetManager;
|
||||||
@ -27,7 +27,7 @@ public:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
IRenderTarget *AcquireNextImage(); ///<获取下一帧的索引
|
bool NextFrame ()override; ///<获取下一帧的索引
|
||||||
|
|
||||||
bool Submit ()override; ///<提交当前帧的渲染,交推送到前台
|
bool Submit ()override; ///<提交当前帧的渲染,交推送到前台
|
||||||
};//class SwapchainRenderTarget:public MultiFrameRenderTarget
|
};//class SwapchainRenderTarget:public MultiFrameRenderTarget
|
||||||
|
@ -40,7 +40,7 @@ public:
|
|||||||
bool GetSwapchainSize(VkExtent2D *)const;
|
bool GetSwapchainSize(VkExtent2D *)const;
|
||||||
|
|
||||||
SwapchainRenderTarget * GetRenderTarget ()const{return sc_render_target;}
|
SwapchainRenderTarget * GetRenderTarget ()const{return sc_render_target;}
|
||||||
IRenderTarget * AcquireNextImage()const;
|
bool AcquireNextImage()const;
|
||||||
};//class SwapchainModule:public GraphModule
|
};//class SwapchainModule:public GraphModule
|
||||||
|
|
||||||
VK_NAMESPACE_END
|
VK_NAMESPACE_END
|
||||||
|
@ -5,6 +5,33 @@
|
|||||||
|
|
||||||
VK_NAMESPACE_BEGIN
|
VK_NAMESPACE_BEGIN
|
||||||
|
|
||||||
|
bool RenderTargetData::Submit(Semaphore *wait_sem)
|
||||||
|
{
|
||||||
|
if(!queue||!cmd_buf||!render_complete_semaphore)
|
||||||
|
return(false);
|
||||||
|
|
||||||
|
return queue->Submit(cmd_buf,wait_sem,render_complete_semaphore);
|
||||||
|
}
|
||||||
|
|
||||||
|
RenderCmdBuffer *RenderTargetData::BeginRender(DescriptorBinding *db)
|
||||||
|
{
|
||||||
|
if(!cmd_buf)
|
||||||
|
return(nullptr);
|
||||||
|
|
||||||
|
cmd_buf->Begin();
|
||||||
|
cmd_buf->SetDescriptorBinding(db);
|
||||||
|
cmd_buf->BindFramebuffer(fbo);
|
||||||
|
return cmd_buf;
|
||||||
|
}
|
||||||
|
|
||||||
|
void RenderTargetData::EndRender()
|
||||||
|
{
|
||||||
|
if(!cmd_buf)
|
||||||
|
return;
|
||||||
|
|
||||||
|
cmd_buf->End();
|
||||||
|
}
|
||||||
|
|
||||||
void RenderTargetData::Clear()
|
void RenderTargetData::Clear()
|
||||||
{
|
{
|
||||||
SAFE_CLEAR(queue);
|
SAFE_CLEAR(queue);
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
#include<hgl/graph/VKRenderTarget.h>
|
#include<hgl/graph/VKRenderTargetSwapchain.h>
|
||||||
#include<hgl/graph/VKDevice.h>
|
#include<hgl/graph/VKDevice.h>
|
||||||
#include<hgl/graph/VKSemaphore.h>
|
#include<hgl/graph/VKSemaphore.h>
|
||||||
//#include<iostream>
|
//#include<iostream>
|
||||||
|
|
||||||
VK_NAMESPACE_BEGIN
|
VK_NAMESPACE_BEGIN
|
||||||
SwapchainRenderTarget::SwapchainRenderTarget(RenderFramework *rf,Swapchain *sc,Semaphore *pcs,RenderTarget **rtl):MultiFrameRenderTarget(rf,sc->image_count,rtl)
|
SwapchainRenderTarget::SwapchainRenderTarget(RenderFramework *rf,Swapchain *sc,Semaphore *pcs,RenderTargetData *rtl):MultiFrameRenderTarget(rf,sc->image_count,rtl)
|
||||||
{
|
{
|
||||||
swapchain=sc;
|
swapchain=sc;
|
||||||
|
|
||||||
@ -15,10 +15,6 @@ SwapchainRenderTarget::SwapchainRenderTarget(RenderFramework *rf,Swapchain *sc,S
|
|||||||
present_info.pSwapchains = &(swapchain->swap_chain);
|
present_info.pSwapchains = &(swapchain->swap_chain);
|
||||||
|
|
||||||
present_complete_semaphore=pcs;
|
present_complete_semaphore=pcs;
|
||||||
|
|
||||||
VkSemaphore sem=*present_complete_semaphore;
|
|
||||||
|
|
||||||
// std::cout<<"present complete semaphore : "<<std::hex<<sem<<std::endl;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SwapchainRenderTarget::~SwapchainRenderTarget()
|
SwapchainRenderTarget::~SwapchainRenderTarget()
|
||||||
@ -27,51 +23,37 @@ SwapchainRenderTarget::~SwapchainRenderTarget()
|
|||||||
delete swapchain;
|
delete swapchain;
|
||||||
}
|
}
|
||||||
|
|
||||||
IRenderTarget *SwapchainRenderTarget::AcquireNextImage()
|
bool SwapchainRenderTarget::NextFrame()
|
||||||
{
|
{
|
||||||
VkSemaphore sem=*present_complete_semaphore;
|
return(vkAcquireNextImageKHR(GetVkDevice(),
|
||||||
|
|
||||||
//std::cout<<"AcquireNextImage present_complete_semaphore : "<<std::hex<<sem<<std::endl;
|
|
||||||
|
|
||||||
if(vkAcquireNextImageKHR(GetVkDevice(),
|
|
||||||
swapchain->swap_chain,
|
swapchain->swap_chain,
|
||||||
UINT64_MAX,
|
UINT64_MAX,
|
||||||
sem,
|
*present_complete_semaphore,
|
||||||
VK_NULL_HANDLE,
|
VK_NULL_HANDLE,
|
||||||
¤t_frame)!=VK_SUCCESS)
|
¤t_frame)==VK_SUCCESS);
|
||||||
return(nullptr);
|
|
||||||
|
|
||||||
//std::cerr<<"AcquireNextImage current_frame="<<current_frame<<std::endl;
|
|
||||||
|
|
||||||
return rt_list[current_frame];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SwapchainRenderTarget::Submit()
|
bool SwapchainRenderTarget::Submit()
|
||||||
{
|
{
|
||||||
IRenderTarget *rt=rt_list[current_frame];
|
RenderTargetData *rtd=rtd_list+current_frame;
|
||||||
|
|
||||||
//std::cout<<"submit frame="<<current_frame<<std::endl;
|
if(!rtd->Submit(present_complete_semaphore))
|
||||||
|
|
||||||
if(!rt->Submit(present_complete_semaphore))
|
|
||||||
return(false);
|
return(false);
|
||||||
|
|
||||||
DeviceQueue *queue=GetQueue();
|
DeviceQueue *queue=GetQueue();
|
||||||
|
|
||||||
VkSemaphore wait_semaphores=*rt->GetRenderCompleteSemaphore();
|
VkSemaphore wait_semaphores=*rtd->render_complete_semaphore;
|
||||||
|
|
||||||
present_info.waitSemaphoreCount =1;
|
present_info.waitSemaphoreCount =1;
|
||||||
present_info.pWaitSemaphores =&wait_semaphores;
|
present_info.pWaitSemaphores =&wait_semaphores;
|
||||||
present_info.pImageIndices =¤t_frame;
|
present_info.pImageIndices =¤t_frame;
|
||||||
|
|
||||||
// std::cout<<"present frame="<<current_frame<<std::endl;
|
|
||||||
|
|
||||||
VkResult result=queue->Present(&present_info);
|
VkResult result=queue->Present(&present_info);
|
||||||
|
|
||||||
if (!((result == VK_SUCCESS) || (result == VK_SUBOPTIMAL_KHR)))
|
if (!((result == VK_SUCCESS) || (result == VK_SUBOPTIMAL_KHR)))
|
||||||
{
|
{
|
||||||
if (result == VK_ERROR_OUT_OF_DATE_KHR) {
|
if (result == VK_ERROR_OUT_OF_DATE_KHR)
|
||||||
// Swap chain is no longer compatible with the surface and needs to be recreated
|
{
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -199,14 +199,13 @@ bool SwapchainModule::CreateSwapchainRenderTarget()
|
|||||||
|
|
||||||
GPUDevice *device=GetDevice();
|
GPUDevice *device=GetDevice();
|
||||||
|
|
||||||
RenderTarget **rt_list=new RenderTarget*[swapchain->image_count];
|
SwapchainRenderTargetData *rtd_list=new SwapchainRenderTargetData[swapchain->image_count];
|
||||||
|
SwapchainRenderTargetData *rtd=rtd_list;
|
||||||
|
|
||||||
SwapchainImage *sc_image=swapchain->sc_image;
|
SwapchainImage *sc_image=swapchain->sc_image;
|
||||||
|
|
||||||
for(uint32_t i=0;i<swapchain->image_count;i++)
|
for(uint32_t i=0;i<swapchain->image_count;i++)
|
||||||
{
|
{
|
||||||
RenderTargetData *rtd=new SwapchainRenderTargetData{};
|
|
||||||
|
|
||||||
rtd->fbo =sc_image->fbo;
|
rtd->fbo =sc_image->fbo;
|
||||||
rtd->queue =device->CreateQueue(swapchain->image_count,false);
|
rtd->queue =device->CreateQueue(swapchain->image_count,false);
|
||||||
rtd->render_complete_semaphore =device->CreateGPUSemaphore();
|
rtd->render_complete_semaphore =device->CreateGPUSemaphore();
|
||||||
@ -218,15 +217,14 @@ bool SwapchainModule::CreateSwapchainRenderTarget()
|
|||||||
rtd->color_textures[0] =sc_image->color;
|
rtd->color_textures[0] =sc_image->color;
|
||||||
rtd->depth_texture =sc_image->depth;
|
rtd->depth_texture =sc_image->depth;
|
||||||
|
|
||||||
rt_list[i]=new RenderTarget(GetRenderFramework(),rtd);
|
++rtd;
|
||||||
|
|
||||||
++sc_image;
|
++sc_image;
|
||||||
}
|
}
|
||||||
|
|
||||||
sc_render_target=new SwapchainRenderTarget( GetRenderFramework(),
|
sc_render_target=new SwapchainRenderTarget( GetRenderFramework(),
|
||||||
swapchain,
|
swapchain,
|
||||||
device->CreateGPUSemaphore(),
|
device->CreateGPUSemaphore(),
|
||||||
rt_list
|
rtd_list
|
||||||
);
|
);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -293,12 +291,12 @@ void SwapchainModule::OnResize(const VkExtent2D &extent)
|
|||||||
return(true);
|
return(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
IRenderTarget * SwapchainModule::AcquireNextImage()const
|
bool SwapchainModule::AcquireNextImage()const
|
||||||
{
|
{
|
||||||
if(!sc_render_target)
|
if(!sc_render_target)
|
||||||
return(nullptr);
|
return(false);
|
||||||
|
|
||||||
return sc_render_target->AcquireNextImage();
|
return sc_render_target->NextFrame();
|
||||||
}
|
}
|
||||||
|
|
||||||
VK_NAMESPACE_END
|
VK_NAMESPACE_END
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include<hgl/WorkManager.h>
|
#include<hgl/WorkManager.h>
|
||||||
#include<hgl/graph/VKRenderTarget.h>
|
#include<hgl/graph/VKRenderTargetSwapchain.h>
|
||||||
|
|
||||||
namespace hgl
|
namespace hgl
|
||||||
{
|
{
|
||||||
@ -40,7 +40,10 @@ namespace hgl
|
|||||||
|
|
||||||
void SwapchainWorkManager::Render(WorkObject *wo)
|
void SwapchainWorkManager::Render(WorkObject *wo)
|
||||||
{
|
{
|
||||||
graph::IRenderTarget *rt=swpachain_module->AcquireNextImage();
|
if(!swapchain_module->AcquireNextImage())
|
||||||
|
return;
|
||||||
|
|
||||||
|
graph::SwapchainRenderTarget *rt=swapchain_module->GetRenderTarget();
|
||||||
|
|
||||||
wo->MarkRenderDirty(); //临时的,未来会被更好的机制替代
|
wo->MarkRenderDirty(); //临时的,未来会被更好的机制替代
|
||||||
WorkManager::Render(wo);
|
WorkManager::Render(wo);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user