add new create function of Framebuffer

This commit is contained in:
hyzboy 2020-10-17 14:20:49 +08:00
parent 9b6ea20cca
commit 8fc19e802d
6 changed files with 136 additions and 90 deletions

2
CMCore

@ -1 +1 @@
Subproject commit 0c045fb8b1ce2588876c433fbd72e457bd23d2df
Subproject commit 1f1d1b80350a40bfeaf50ab6cf8c6be8a613c374

View File

@ -236,7 +236,7 @@ public:
int AcquireNextImage()
{
return sc_render_target->AcquireNextImage(present_complete_semaphore);
return sc_render_target->AcquireNextImage(*present_complete_semaphore);
}
virtual void SubmitDraw(int index)
@ -244,7 +244,7 @@ public:
VkCommandBuffer cb=*cmd_buf[index];
sc_render_target->Submit(cb,present_complete_semaphore,render_complete_semaphore);
sc_render_target->PresentBackbuffer(render_complete_semaphore);
sc_render_target->PresentBackbuffer(*render_complete_semaphore);
sc_render_target->Wait();
}

View File

@ -266,7 +266,7 @@ public: //Command Buffer 相关
public: //FrameBuffer相关
Framebuffer *CreateFramebuffer(RenderPass *rp,ImageView **color_list,const uint color_count,ImageView *depth);
Framebuffer *CreateFramebuffer(RenderPass *,List<ImageView *> &color,ImageView *depth);
// Framebuffer *CreateFramebuffer(RenderPass *,List<ImageView *> &color,ImageView *depth);
Framebuffer *CreateFramebuffer(RenderPass *,ImageView *color,ImageView *depth);
Framebuffer *CreateFramebuffer(RenderPass *,ImageView *);
@ -274,25 +274,26 @@ public:
bool SubmitTexture (const VkCommandBuffer *cmd_bufs,const uint32_t count=1); ///<提交纹理处理到队列
RenderTarget *CreateRenderTarget(Framebuffer *);
RenderTarget *CreateRenderTarget( const uint,const uint,const List<VkFormat> &,
const VkImageLayout color_final_layout=VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
const VkImageLayout depth_final_layout=VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
RenderTarget *CreateRenderTarget( const uint,const uint,const VkFormat,const VkImageLayout final_layout);
RenderTarget *CreateRenderTarget( const uint,const uint,
const VkFormat color_format,
const VkFormat depth_format,
const VkImageLayout color_final_layout=VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
const VkImageLayout depth_final_layout=VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
RenderTarget *CreateRenderTarget( Framebuffer *,const uint32_t fence_count=1);
RenderTarget *CreateRenderTarget( const uint,const uint,
const List<VkFormat> &color_format_list,
const VkFormat depth_format,
const VkImageLayout color_final_layout=VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
const VkImageLayout depth_final_layout=VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
const VkImageLayout depth_final_layout=VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
const uint32_t fence_count=1);
RenderTarget *CreateRenderTarget( const uint,const uint,
const VkFormat color_format,
const VkFormat depth_format,
const VkImageLayout color_final_layout=VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
const VkImageLayout depth_final_layout=VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
const uint32_t fence_count=1);
RenderTarget *CreateRenderTarget( const uint,const uint,const VkFormat,const VkImageLayout final_layout,const uint32_t fence_count=1);
public:
Pipeline *CreatePipeline(const InlinePipeline &,const Material *,const RenderTarget *);
Pipeline *CreatePipeline( PipelineData *, const Material *,const RenderTarget *);

View File

@ -2,33 +2,11 @@
#define HGL_GRAPH_VULKAN_RENDER_TARGET_INCLUDE
#include<hgl/graph/vulkan/VK.h>
#include<hgl/graph/vulkan/VKFence.h>
#include<hgl/graph/vulkan/VKRenderPass.h>
#include<hgl/graph/vulkan/VKFramebuffer.h>
#include<hgl/graph/vulkan/VKSwapchain.h>
#include<hgl/graph/vulkan/VKSubmitQueue.h>
VK_NAMESPACE_BEGIN
class SubmitQueue
{
protected:
Device *device;
VkQueue queue;
uint32_t current_fence;
ObjectList<Fence> fence_list;
SubmitInfo submit_info;
public:
SubmitQueue(Device *dev,VkQueue q,const uint32_t fence_count=1);
virtual ~SubmitQueue();
bool Wait(const bool wait_wall=true,const uint64_t time_out=HGL_NANO_SEC_PER_SEC);
bool Submit(const VkCommandBuffer &cmd_buf,vulkan::Semaphore *wait_sem,vulkan::Semaphore *complete_sem);
bool Submit(const VkCommandBuffer *cmd_buf,const uint32_t count,vulkan::Semaphore *wait_sem,vulkan::Semaphore *complete_sem);
};//class SumbitQueue
/**
*
*/
@ -42,11 +20,17 @@ protected:
CommandBuffer *command_buffer;
protected:
ObjectList<Texture2D> color_texture;
Texture2D *depth_texture;
protected:
friend class Device;
RenderTarget(Device *dev,Framebuffer *_fb,CommandBuffer *_cb,const uint32_t fence_count=1);
RenderTarget(Device *dev,Framebuffer *_fb,CommandBuffer *_cb,Texture2D **color_texture_list,const uint32_t color_count,Texture2D *depth_texture,const uint32_t fence_count=1);
public:
@ -57,6 +41,9 @@ public:
virtual const VkRenderPass GetRenderPass ()const {return fb->GetRenderPass();}
virtual const uint32_t GetColorCount ()const {return fb->GetColorCount();}
virtual const VkFramebuffer GetFramebuffer ()const {return fb->GetFramebuffer();}
virtual Texture2D * GetColorTexture (const int index=0){return color_texture[index];}
virtual Texture2D * GetDepthTexture (){return depth_texture;}
};//class RenderTarget
/**
@ -80,14 +67,17 @@ public:
SwapchainRenderTarget(Device *dev,Swapchain *sc);
~SwapchainRenderTarget();
const VkRenderPass GetRenderPass()const override{return *main_rp;}
const VkFramebuffer GetFramebuffer()const override{return render_frame[current_frame]->GetFramebuffer();}
VkFramebuffer GetFramebuffer(const uint32_t index){return render_frame[index]->GetFramebuffer();}
const VkRenderPass GetRenderPass ()const override {return *main_rp;}
const VkFramebuffer GetFramebuffer ()const override {return render_frame[current_frame]->GetFramebuffer();}
VkFramebuffer GetFramebuffer (const uint32_t index) {return render_frame[index]->GetFramebuffer();}
const uint32_t GetColorCount()const override{return 1;}
const uint32_t GetImageCount()const{return swap_chain_count;}
const uint32_t GetColorCount ()const override {return 1;}
const uint32_t GetImageCount ()const {return swap_chain_count;}
const uint32_t GetCurrentFrameIndices()const{return current_frame;}
const uint32_t GetCurrentFrameIndices()const{return current_frame;}
virtual Texture2D * GetColorTexture(const int index=0) override{return swapchain->GetColorTexture(index);}
virtual Texture2D * GetDepthTexture() override{return swapchain->GetDepthTexture();}
public:
@ -95,13 +85,18 @@ public:
*
* @param present_complete_semaphore
*/
int AcquireNextImage(vulkan::Semaphore *present_complete_semaphore);
int AcquireNextImage(VkSemaphore present_complete_semaphore);
/**
*
* @param render_complete_semaphore
*/
bool PresentBackbuffer(vulkan::Semaphore *render_complete_semaphore);
bool PresentBackbuffer(VkSemaphore *render_complete_semaphore,const uint32_t count);
bool PresentBackbuffer(VkSemaphore render_complete_semaphore)
{
return PresentBackbuffer(&render_complete_semaphore,1);
}
};//class SwapchainRenderTarget:public RenderTarget
VK_NAMESPACE_END
#endif//HGL_GRAPH_VULKAN_RENDER_TARGET_INCLUDE

View File

@ -1,13 +1,33 @@
#include<hgl/graph/vulkan/VKDevice.h>
VK_NAMESPACE_BEGIN
VkFramebuffer CreateVulkanFramebuffer(VkDevice device,RenderPass *rp,const VkExtent2D &extent,VkImageView *attachments,const uint attachmentCount)
{
FramebufferCreateInfo fb_info;
fb_info.renderPass = *rp;
fb_info.attachmentCount = attachmentCount;
fb_info.pAttachments = attachments;
fb_info.width = extent.width;
fb_info.height = extent.height;
fb_info.layers = 1;
VkFramebuffer fb;
if(vkCreateFramebuffer(device,&fb_info,nullptr,&fb)!=VK_SUCCESS)
return(nullptr);
return fb;
}
Framebuffer *Device::CreateFramebuffer(RenderPass *rp,ImageView **color_list,const uint color_count,ImageView *depth)
{
{
uint att_count=color_count;
if(depth)++att_count;
VkImageView *attachments=new VkImageView[att_count];
AutoDeleteArray<VkImageView> attachments=new VkImageView[att_count];
VkImageView *ap=attachments;
if(color_count)
{
@ -15,6 +35,7 @@ Framebuffer *Device::CreateFramebuffer(RenderPass *rp,ImageView **color_list,con
const VkFormat *cf=cf_list.GetData();
ImageView **iv=color_list;
for(uint i=0;i<color_count;i++)
{
if(*cf!=(*iv)->GetFormat())
@ -38,35 +59,28 @@ Framebuffer *Device::CreateFramebuffer(RenderPass *rp,ImageView **color_list,con
attachments[color_count]=*depth;
}
const VkExtent3D extent=depth->GetExtent();
VkExtent2D extent;
extent.width=depth->GetExtent().width;
extent.height=depth->GetExtent().height;
FramebufferCreateInfo *fb_info=new FramebufferCreateInfo;
VkFramebuffer fbo=CreateVulkanFramebuffer(GetDevice(),rp,extent,attachments,att_count);
fb_info->renderPass = *rp;
fb_info->attachmentCount = att_count;
fb_info->pAttachments = attachments;
fb_info->width = extent.width;
fb_info->height = extent.height;
fb_info->layers = 1;
VkFramebuffer fb;
if(vkCreateFramebuffer(GetDevice(),fb_info,nullptr,&fb)!=VK_SUCCESS)
if(!fbo)
return(nullptr);
return(new Framebuffer(GetDevice(),fb,fb_info,depth));
}
Framebuffer *Device::CreateFramebuffer(RenderPass *rp,List<ImageView *> &color,ImageView *depth)
{
if(!rp)return(nullptr);
if(rp->GetColorFormat().GetCount()!=color.GetCount())return(nullptr);
if(color.GetCount()==0&&!depth)return(nullptr);
return CreateFramebuffer(rp,color.GetData(),color.GetCount(),depth);
return(new Framebuffer(GetDevice(),fbo,extent,*rp,color_count,depth));
}
//
//Framebuffer *Device::CreateFramebuffer(RenderPass *rp,List<ImageView *> &color,ImageView *depth)
//{
// if(!rp)return(nullptr);
//
// if(rp->GetColorFormat().GetCount()!=color.GetCount())return(nullptr);
//
// if(color.GetCount()==0&&!depth)return(nullptr);
//
// return CreateFramebuffer(rp,color.GetData(),color.GetCount(),depth);
//}
Framebuffer *Device::CreateFramebuffer(RenderPass *rp,ImageView *color,ImageView *depth)
{

View File

@ -1,25 +1,33 @@
#include<hgl/graph/vulkan/VKDevice.h>
VK_NAMESPACE_BEGIN
RenderTarget *Device::CreateRenderTarget(Framebuffer *fb)
RenderTarget *Device::CreateRenderTarget(Framebuffer *fb,const uint32_t fence_count)
{
CommandBuffer *cb=CreateCommandBuffer(fb->GetExtent(),fb->GetAttachmentCount());
return(new RenderTarget(this,fb,cb));
return(new RenderTarget(this,fb,cb,fence_count));
}
RenderTarget *Device::CreateRenderTarget( const uint w,const uint h,
const List<VkFormat> &color_format_list,
const VkFormat depth_format,
const VkImageLayout color_layout,
const VkImageLayout depth_layout)
const VkImageLayout depth_layout,
const uint32_t fence_count)
{
if(w<=0||h<=0)return(nullptr);
RenderPass *rp=CreateRenderPass(color_format_list,depth_format,color_layout,depth_layout); //Renderpass内部会验证格式所以不需要自己处理
ObjectList<Texture2D> color_texture_list;
List<ImageView *> color_texture_image_view_list;
if(!rp)return(nullptr);
const uint32_t color_count=color_format_list.GetCount();
AutoDeleteObjectArray<Texture2D> color_texture_list(color_count);
AutoDeleteArray<ImageView *> color_iv_list=new ImageView *[color_count]; //iv只是从Texture2D中取出来的无需一个个delete
Texture2D **tp=color_texture_list;
ImageView **iv=color_iv_list;
for(const VkFormat &fmt:color_format_list)
{
@ -31,29 +39,37 @@ RenderTarget *Device::CreateRenderTarget( const uint w,const uint h,
return(nullptr);
}
color_texture_list.Add(color_texture);
color_texture_image_view_list.Add(color_texture->GetImageView());
*tp++=color_texture;
*iv++=color_texture->GetImageView();
}
Texture2D *depth_texture=(depth_format!=FMT_UNDEFINED)?CreateAttachmentTextureDepth(depth_format,w,h):nullptr;
Framebuffer *fb=CreateFramebuffer(rp,color_texture_image_view_list,depth_texture->GetImageView());
Framebuffer *fb=CreateFramebuffer(rp,color_iv_list,color_count,depth_texture?depth_texture->GetImageView():nullptr);
if(!fb)
if(fb)
{
SAFE_CLEAR(depth_texture)
delete rp;
return nullptr;
CommandBuffer *cb=CreateCommandBuffer(fb->GetExtent(),fb->GetAttachmentCount());
if(cb)
{
color_texture_list.DiscardObject();
return(new RenderTarget(this,fb,cb,color_texture_list,color_count,depth_texture,fence_count));
}
}
return(CreateRenderTarget(fb));
SAFE_CLEAR(depth_texture);
delete rp;
return nullptr;
}
RenderTarget *Device::CreateRenderTarget( const uint w,const uint h,
const VkFormat color_format,
const VkFormat depth_format,
const VkImageLayout color_layout,
const VkImageLayout depth_layout)
const VkImageLayout depth_layout,
const uint32_t fence_count)
{
if(w<=0||h<=0)return(nullptr);
@ -61,6 +77,26 @@ RenderTarget *Device::CreateRenderTarget( const uint w,const uint h,
color_format_list.Add(color_format);
return CreateRenderTarget(w,h,color_format_list,depth_format,color_layout,depth_layout);
return CreateRenderTarget(w,h,color_format_list,depth_format,color_layout,depth_layout,fence_count);
}
RenderTarget *Device::CreateRenderTarget(const uint w,const uint h,const VkFormat format,const VkImageLayout final_layout,const uint32_t fence_count)
{
if(w<=0||h<=0)return(nullptr);
if(format==FMT_UNDEFINED)return(nullptr);
List<VkFormat> color_format_list;
if(IsDepthFormat(format))
{
return CreateRenderTarget(w,h,color_format_list,format,VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,final_layout,fence_count);
}
else
{
color_format_list.Add(format);
return CreateRenderTarget(w,h,color_format_list,FMT_UNDEFINED,final_layout,VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,fence_count);
}
}
VK_NAMESPACE_END