newly RenderTarget&SwapchainRenderTarget class
This commit is contained in:
parent
96dc95276b
commit
87293f778c
@ -48,9 +48,9 @@ namespace hgl
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
GPUBuffer *tile_buffer; ///<Tile暂存缓冲区
|
GPUBuffer *tile_buffer; ///<Tile暂存缓冲区
|
||||||
|
|
||||||
List<ImageRegion> commit_list;
|
List<Image2DRegion> commit_list;
|
||||||
uint8 *commit_ptr;
|
uint8 *commit_ptr;
|
||||||
|
|
||||||
bool CommitTile(TileObject *,const void *,const uint,const int,const int); ///<提交一个Tile数据
|
bool CommitTile(TileObject *,const void *,const uint,const int,const int); ///<提交一个Tile数据
|
||||||
|
@ -33,6 +33,7 @@ class VulkanInstance;
|
|||||||
class GPUPhysicalDevice;
|
class GPUPhysicalDevice;
|
||||||
class GPUDevice;
|
class GPUDevice;
|
||||||
struct GPUDeviceAttribute;
|
struct GPUDeviceAttribute;
|
||||||
|
class GPUQueue;
|
||||||
class ImageView;
|
class ImageView;
|
||||||
class Framebuffer;
|
class Framebuffer;
|
||||||
struct Swapchain;
|
struct Swapchain;
|
||||||
|
@ -11,10 +11,12 @@ VK_NAMESPACE_BEGIN
|
|||||||
/**
|
/**
|
||||||
* 渲染目标
|
* 渲染目标
|
||||||
*/
|
*/
|
||||||
class RenderTarget:public GPUQueue
|
class RenderTarget
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
|
GPUQueue *queue;
|
||||||
|
|
||||||
RenderPass *render_pass;
|
RenderPass *render_pass;
|
||||||
Framebuffer *fbo;
|
Framebuffer *fbo;
|
||||||
|
|
||||||
@ -32,8 +34,8 @@ protected:
|
|||||||
|
|
||||||
friend class GPUDevice;
|
friend class GPUDevice;
|
||||||
|
|
||||||
RenderTarget(GPUDevice *dev,Framebuffer *_fb,const uint32_t fence_count=1);
|
RenderTarget(GPUQueue *,GPUSemaphore *);
|
||||||
RenderTarget(GPUDevice *dev,RenderPass *_rp,Framebuffer *_fb,Texture2D **color_texture_list,const uint32_t color_count,Texture2D *depth_texture,const uint32_t fence_count=1);
|
RenderTarget(GPUQueue *,GPUSemaphore *,RenderPass *_rp,Framebuffer *_fb,Texture2D **color_texture_list,const uint32_t color_count,Texture2D *depth_texture);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
@ -52,6 +54,9 @@ public: // command buffer
|
|||||||
|
|
||||||
GPUSemaphore * GetRenderCompleteSemaphore (){return render_complete_semaphore;}
|
GPUSemaphore * GetRenderCompleteSemaphore (){return render_complete_semaphore;}
|
||||||
virtual bool Submit (RenderCmdBuffer *,GPUSemaphore *present_complete_semaphore=nullptr);
|
virtual bool Submit (RenderCmdBuffer *,GPUSemaphore *present_complete_semaphore=nullptr);
|
||||||
|
|
||||||
|
bool WaitQueue(){return queue->WaitQueue();}
|
||||||
|
bool WaitFence(){return queue->WaitFence();}
|
||||||
};//class RenderTarget
|
};//class RenderTarget
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -59,6 +64,7 @@ public: // command buffer
|
|||||||
*/
|
*/
|
||||||
class SwapchainRenderTarget:public RenderTarget
|
class SwapchainRenderTarget:public RenderTarget
|
||||||
{
|
{
|
||||||
|
VkDevice device;
|
||||||
Swapchain *swapchain;
|
Swapchain *swapchain;
|
||||||
VkSwapchainKHR vk_swapchain;
|
VkSwapchainKHR vk_swapchain;
|
||||||
PresentInfo present_info;
|
PresentInfo present_info;
|
||||||
@ -72,7 +78,7 @@ class SwapchainRenderTarget:public RenderTarget
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
SwapchainRenderTarget(GPUDevice *dev,Swapchain *sc);
|
SwapchainRenderTarget(VkDevice dev,Swapchain *sc,GPUQueue *q,GPUSemaphore *rcs,GPUSemaphore *pcs,RenderPass *rp,Framebuffer **fbo_list);
|
||||||
~SwapchainRenderTarget();
|
~SwapchainRenderTarget();
|
||||||
|
|
||||||
Framebuffer * GetFramebuffer ()override {return render_frame[current_frame];}
|
Framebuffer * GetFramebuffer ()override {return render_frame[current_frame];}
|
||||||
|
@ -33,7 +33,10 @@ RenderTarget *GPUDevice::CreateRenderTarget(const FramebufferInfo *fbi,RenderPas
|
|||||||
|
|
||||||
if(fb)
|
if(fb)
|
||||||
{
|
{
|
||||||
RenderTarget *rt=new RenderTarget(this,rp,fb,color_texture_list,color_count,depth_texture,fence_count);
|
GPUQueue *q=CreateQueue(fence_count,false);
|
||||||
|
GPUSemaphore *render_complete_semaphore=CreateGPUSemaphore();
|
||||||
|
|
||||||
|
RenderTarget *rt=new RenderTarget(q,render_complete_semaphore,rp,fb,color_texture_list,color_count,depth_texture);
|
||||||
|
|
||||||
color_texture_list.DiscardObject();
|
color_texture_list.DiscardObject();
|
||||||
return rt;
|
return rt;
|
||||||
@ -53,4 +56,35 @@ RenderTarget *GPUDevice::CreateRenderTarget(const FramebufferInfo *fbi,const uin
|
|||||||
|
|
||||||
return CreateRenderTarget(fbi,rp,fence_count);
|
return CreateRenderTarget(fbi,rp,fence_count);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SwapchainRenderTarget *GPUDevice::CreateSwapchainRT()
|
||||||
|
{
|
||||||
|
const uint32_t count=swapchain->GetImageCount();
|
||||||
|
|
||||||
|
GPUQueue *q=CreateQueue(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,
|
||||||
|
q,
|
||||||
|
render_complete_semaphore,
|
||||||
|
present_complete_semaphore,
|
||||||
|
device_render_pass,
|
||||||
|
render_frame
|
||||||
|
);
|
||||||
|
|
||||||
|
return srt;
|
||||||
|
}
|
||||||
VK_NAMESPACE_END
|
VK_NAMESPACE_END
|
@ -6,23 +6,21 @@
|
|||||||
#include<hgl/graph/VKFramebuffer.h>
|
#include<hgl/graph/VKFramebuffer.h>
|
||||||
|
|
||||||
VK_NAMESPACE_BEGIN
|
VK_NAMESPACE_BEGIN
|
||||||
RenderTarget::RenderTarget(GPUDevice *dev,Framebuffer *_fb,const uint32_t fence_count):GPUQueue(dev,dev->GetGraphicsQueue(),fence_count)
|
RenderTarget::RenderTarget(GPUQueue *q,GPUSemaphore *s)
|
||||||
{
|
{
|
||||||
|
queue=q;
|
||||||
render_pass=nullptr;
|
render_pass=nullptr;
|
||||||
fbo=_fb;
|
fbo=nullptr;
|
||||||
|
|
||||||
if(fbo)
|
|
||||||
color_count=fbo->GetColorCount();
|
|
||||||
else
|
|
||||||
color_count=0;
|
|
||||||
|
|
||||||
|
color_count=0;
|
||||||
color_textures=nullptr;
|
color_textures=nullptr;
|
||||||
depth_texture=nullptr;
|
depth_texture=nullptr;
|
||||||
render_complete_semaphore=dev->CreateGPUSemaphore();
|
render_complete_semaphore=s;
|
||||||
}
|
}
|
||||||
|
|
||||||
RenderTarget::RenderTarget(GPUDevice *dev,RenderPass *_rp,Framebuffer *_fb,Texture2D **ctl,const uint32_t cc,Texture2D *dt,const uint32_t fence_count):GPUQueue(dev,dev->GetGraphicsQueue(),fence_count)
|
RenderTarget::RenderTarget(GPUQueue *q,GPUSemaphore *s,RenderPass *_rp,Framebuffer *_fb,Texture2D **ctl,const uint32_t cc,Texture2D *dt)
|
||||||
{
|
{
|
||||||
|
queue=q;
|
||||||
render_pass=_rp;
|
render_pass=_rp;
|
||||||
fbo=_fb;
|
fbo=_fb;
|
||||||
|
|
||||||
@ -48,11 +46,12 @@ RenderTarget::RenderTarget(GPUDevice *dev,RenderPass *_rp,Framebuffer *_fb,Textu
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
render_complete_semaphore=dev->CreateGPUSemaphore();
|
render_complete_semaphore=s;
|
||||||
}
|
}
|
||||||
|
|
||||||
RenderTarget::~RenderTarget()
|
RenderTarget::~RenderTarget()
|
||||||
{
|
{
|
||||||
|
SAFE_CLEAR(queue);
|
||||||
SAFE_CLEAR(depth_texture);
|
SAFE_CLEAR(depth_texture);
|
||||||
SAFE_CLEAR_OBJECT_ARRAY(color_textures,color_count);
|
SAFE_CLEAR_OBJECT_ARRAY(color_textures,color_count);
|
||||||
|
|
||||||
@ -62,6 +61,6 @@ RenderTarget::~RenderTarget()
|
|||||||
|
|
||||||
bool RenderTarget::Submit(RenderCmdBuffer *command_buffer,GPUSemaphore *present_complete_semaphore)
|
bool RenderTarget::Submit(RenderCmdBuffer *command_buffer,GPUSemaphore *present_complete_semaphore)
|
||||||
{
|
{
|
||||||
return this->GPUQueue::Submit(*command_buffer,present_complete_semaphore,render_complete_semaphore);
|
return queue->Submit(*command_buffer,present_complete_semaphore,render_complete_semaphore);
|
||||||
}
|
}
|
||||||
VK_NAMESPACE_END
|
VK_NAMESPACE_END
|
@ -3,8 +3,10 @@
|
|||||||
#include<hgl/graph/VKSemaphore.h>
|
#include<hgl/graph/VKSemaphore.h>
|
||||||
|
|
||||||
VK_NAMESPACE_BEGIN
|
VK_NAMESPACE_BEGIN
|
||||||
SwapchainRenderTarget::SwapchainRenderTarget(GPUDevice *dev,Swapchain *sc):RenderTarget(dev,nullptr,sc->GetImageCount())
|
SwapchainRenderTarget::SwapchainRenderTarget(VkDevice dev,Swapchain *sc,GPUQueue *q,GPUSemaphore *rcs,GPUSemaphore *pcs,RenderPass *rp,Framebuffer **fbo_list):RenderTarget(q,rcs)
|
||||||
{
|
{
|
||||||
|
device=dev;
|
||||||
|
|
||||||
swapchain=sc;
|
swapchain=sc;
|
||||||
vk_swapchain=swapchain->GetSwapchain();
|
vk_swapchain=swapchain->GetSwapchain();
|
||||||
|
|
||||||
@ -14,26 +16,17 @@ SwapchainRenderTarget::SwapchainRenderTarget(GPUDevice *dev,Swapchain *sc):Rende
|
|||||||
present_info.pResults = nullptr;
|
present_info.pResults = nullptr;
|
||||||
present_info.pSwapchains = &vk_swapchain;
|
present_info.pSwapchains = &vk_swapchain;
|
||||||
|
|
||||||
Texture2D **sc_color=swapchain->GetColorTextures();
|
render_pass=rp;
|
||||||
Texture2D *sc_depth=swapchain->GetDepthTexture();
|
|
||||||
|
|
||||||
render_pass=dev->GetRenderPass();
|
|
||||||
|
|
||||||
swap_chain_count=swapchain->GetImageCount();
|
swap_chain_count=swapchain->GetImageCount();
|
||||||
|
|
||||||
extent=swapchain->GetExtent();
|
extent=swapchain->GetExtent();
|
||||||
|
|
||||||
render_frame=new Framebuffer *[swap_chain_count];
|
render_frame=fbo_list;
|
||||||
|
|
||||||
for(uint i=0;i<swap_chain_count;i++)
|
|
||||||
{
|
|
||||||
render_frame[i]=device->CreateFramebuffer(render_pass,(*sc_color)->GetImageView(),sc_depth->GetImageView());
|
|
||||||
++sc_color;
|
|
||||||
}
|
|
||||||
|
|
||||||
current_frame=0;
|
current_frame=0;
|
||||||
|
|
||||||
present_complete_semaphore=dev->CreateGPUSemaphore();
|
present_complete_semaphore=pcs;
|
||||||
}
|
}
|
||||||
|
|
||||||
SwapchainRenderTarget::~SwapchainRenderTarget()
|
SwapchainRenderTarget::~SwapchainRenderTarget()
|
||||||
@ -45,7 +38,7 @@ SwapchainRenderTarget::~SwapchainRenderTarget()
|
|||||||
|
|
||||||
int SwapchainRenderTarget::AcquireNextImage()
|
int SwapchainRenderTarget::AcquireNextImage()
|
||||||
{
|
{
|
||||||
if(vkAcquireNextImageKHR(device->GetDevice(),vk_swapchain,UINT64_MAX,*(this->present_complete_semaphore),VK_NULL_HANDLE,¤t_frame)==VK_SUCCESS)
|
if(vkAcquireNextImageKHR(device,vk_swapchain,UINT64_MAX,*(this->present_complete_semaphore),VK_NULL_HANDLE,¤t_frame)==VK_SUCCESS)
|
||||||
return current_frame;
|
return current_frame;
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
@ -57,7 +50,7 @@ bool SwapchainRenderTarget::PresentBackbuffer(VkSemaphore *wait_semaphores,const
|
|||||||
present_info.pWaitSemaphores =wait_semaphores;
|
present_info.pWaitSemaphores =wait_semaphores;
|
||||||
present_info.pImageIndices =¤t_frame;
|
present_info.pImageIndices =¤t_frame;
|
||||||
|
|
||||||
VkResult result=vkQueuePresentKHR(queue,&present_info);
|
VkResult result=queue->Present(&present_info);
|
||||||
|
|
||||||
if (!((result == VK_SUCCESS) || (result == VK_SUBOPTIMAL_KHR)))
|
if (!((result == VK_SUCCESS) || (result == VK_SUBOPTIMAL_KHR)))
|
||||||
{
|
{
|
||||||
@ -80,11 +73,11 @@ bool SwapchainRenderTarget::PresentBackbuffer()
|
|||||||
|
|
||||||
bool SwapchainRenderTarget::Submit(VkCommandBuffer cb)
|
bool SwapchainRenderTarget::Submit(VkCommandBuffer cb)
|
||||||
{
|
{
|
||||||
return GPUQueue::Submit(cb,present_complete_semaphore,render_complete_semaphore);
|
return queue->Submit(cb,present_complete_semaphore,render_complete_semaphore);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SwapchainRenderTarget::Submit(VkCommandBuffer cb,GPUSemaphore *pce)
|
bool SwapchainRenderTarget::Submit(VkCommandBuffer cb,GPUSemaphore *pce)
|
||||||
{
|
{
|
||||||
return GPUQueue::Submit(cb,pce,render_complete_semaphore);
|
return queue->Submit(cb,pce,render_complete_semaphore);
|
||||||
}
|
}
|
||||||
VK_NAMESPACE_END
|
VK_NAMESPACE_END
|
||||||
|
Loading…
x
Reference in New Issue
Block a user