diff --git a/inc/hgl/graph/vulkan/VKDevice.h b/inc/hgl/graph/vulkan/VKDevice.h index cd4adb69..7ff8a98f 100644 --- a/inc/hgl/graph/vulkan/VKDevice.h +++ b/inc/hgl/graph/vulkan/VKDevice.h @@ -250,6 +250,11 @@ public: //Command Buffer 相关 const VkImageLayout color_final_layout=VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, const VkImageLayout depth_final_layout=VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL); + RenderPass * CreateRenderPass( const List &color_format, + const VkFormat depth_format, + const VkImageLayout color_final_layout=VK_IMAGE_LAYOUT_PRESENT_SRC_KHR, + const VkImageLayout depth_final_layout=VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL); + RenderPass * CreateRenderPass( const VkFormat color_format, const VkFormat depth_format, const VkImageLayout color_final_layout=VK_IMAGE_LAYOUT_PRESENT_SRC_KHR, @@ -258,10 +263,17 @@ public: //Command Buffer 相关 Fence * CreateFence(bool); vulkan::Semaphore * CreateSem(); +public: //FrameBuffer相关 + + Framebuffer *CreateFramebuffer(RenderPass *rp,ImageView **color_list,const uint color_count,ImageView *depth); + Framebuffer *CreateFramebuffer(RenderPass *,List &color,ImageView *depth); + Framebuffer *CreateFramebuffer(RenderPass *,ImageView *color,ImageView *depth); + Framebuffer *CreateFramebuffer(RenderPass *,ImageView *); + public: bool SubmitTexture (const VkCommandBuffer *cmd_bufs,const uint32_t count=1); ///<提交纹理处理到队列 - + RenderTarget *CreateRenderTarget(Framebuffer *); RenderTarget *CreateRenderTarget( const uint,const uint,const List &, @@ -284,7 +296,7 @@ public: TileFont *CreateTileFont(FontSource *fs,int limit_count=-1); ///<创建一个Tile字体 };//class Device -void CreateSubpassDependency(VkSubpassDependency *); +//void CreateSubpassDependency(VkSubpassDependency *); void CreateSubpassDependency(List &dependency,const uint32_t count); void CreateAttachmentReference(VkAttachmentReference *ref_list,uint start,uint count,VkImageLayout layout); @@ -297,7 +309,7 @@ inline void CreateInputAttachmentReference(VkAttachmentReference *ref_list, uint bool CreateColorAttachment( List &ref_list,List &desc_list,const List &color_format,const VkImageLayout color_final_layout=VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL); bool CreateDepthAttachment( List &ref_list,List &desc_list,const VkFormat &depth_format,const VkImageLayout depth_final_layout=VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL); -bool CreateAttachment( List &color_output_desc_list, +bool CreateAttachmentDescription( List &color_output_desc_list, const List &color_format, const VkFormat depth_format, const VkImageLayout color_final_layout=VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, diff --git a/inc/hgl/graph/vulkan/VKFramebuffer.h b/inc/hgl/graph/vulkan/VKFramebuffer.h index e280ddc9..be4aca5a 100644 --- a/inc/hgl/graph/vulkan/VKFramebuffer.h +++ b/inc/hgl/graph/vulkan/VKFramebuffer.h @@ -18,7 +18,7 @@ class Framebuffer private: - friend Framebuffer *CreateFramebuffer(VkDevice dev,RenderPass *rp,ImageView **color_list,const uint color_count,ImageView *depth); + friend class Device; Framebuffer(VkDevice dev,VkFramebuffer fb,VkFramebufferCreateInfo *fb_create_info,bool depth); @@ -38,9 +38,5 @@ public: Texture2D * GetColorTexture (const int index=0){return color_texture[index];} Texture2D * GetDepthTexture (){return depth_texture;} };//class Framebuffer - -Framebuffer *CreateFramebuffer(VkDevice,RenderPass *,List &color,ImageView *depth); -Framebuffer *CreateFramebuffer(VkDevice,RenderPass *,ImageView *color,ImageView *depth); -Framebuffer *CreateFramebuffer(VkDevice,RenderPass *,ImageView *); VK_NAMESPACE_END #endif//HGL_GRAPH_VULKAN_FRAMEBUFFER_INCLUDE diff --git a/src/RenderDevice/Vulkan/VKDeviceFramebuffer.cpp b/src/RenderDevice/Vulkan/VKDeviceFramebuffer.cpp new file mode 100644 index 00000000..bf4bdff5 --- /dev/null +++ b/src/RenderDevice/Vulkan/VKDeviceFramebuffer.cpp @@ -0,0 +1,92 @@ +#include + +VK_NAMESPACE_BEGIN +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]; + + if(color_count) + { + const List &cf_list=rp->GetColorFormat(); + + const VkFormat *cf=cf_list.GetData(); + ImageView **iv=color_list; + for(uint i=0;iGetFormat()) + return(nullptr); + + attachments[i]=**iv; + + ++cf; + ++iv; + } + } + + if(depth) + { + if(rp->GetDepthFormat()!=depth->GetFormat()) + { + delete[] attachments; + return(nullptr); + } + + attachments[color_count]=*depth; + } + + const VkExtent3D extent=depth->GetExtent(); + + FramebufferCreateInfo *fb_info=new FramebufferCreateInfo; + + 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) + return(nullptr); + + return(new Framebuffer(GetDevice(),fb,fb_info,depth)); +} + +Framebuffer *Device::CreateFramebuffer(RenderPass *rp,List &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) +{ + if(!rp)return(nullptr); + if(!color&&!depth)return(nullptr); + + return CreateFramebuffer(rp,&color,1,depth); +} + +Framebuffer *Device::CreateFramebuffer(RenderPass *rp,ImageView *iv) +{ + if(!rp)return(nullptr); + if(!iv)return(nullptr); + + if(iv->hasColor()) + return CreateFramebuffer(rp,&iv,1,nullptr); + else + if(iv->hasDepth()) + return CreateFramebuffer(rp,nullptr,0,iv); + else + return nullptr; +} +VK_NAMESPACE_END \ No newline at end of file diff --git a/src/RenderDevice/Vulkan/VKFramebuffer.cpp b/src/RenderDevice/Vulkan/VKFramebuffer.cpp index d492c4d8..299feb44 100644 --- a/src/RenderDevice/Vulkan/VKFramebuffer.cpp +++ b/src/RenderDevice/Vulkan/VKFramebuffer.cpp @@ -32,96 +32,4 @@ Framebuffer::~Framebuffer() vkDestroyFramebuffer(device,frame_buffer,nullptr); } - -Framebuffer *CreateFramebuffer(VkDevice dev,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]; - - if(color_count) - { - const List &cf_list=rp->GetColorFormat(); - - const VkFormat *cf=cf_list.GetData(); - ImageView **iv=color_list; - for(uint i=0;iGetFormat()) - return(nullptr); - - attachments[i]=**iv; - - ++cf; - ++iv; - } - } - - if(depth) - { - if(rp->GetDepthFormat()!=depth->GetFormat()) - { - delete[] attachments; - return(nullptr); - } - - attachments[color_count]=*depth; - } - - const VkExtent3D extent=depth->GetExtent(); - - FramebufferCreateInfo *fb_info=new FramebufferCreateInfo; - - 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(dev,fb_info,nullptr,&fb)!=VK_SUCCESS) - return(nullptr); - - return(new Framebuffer(dev,fb,fb_info,depth)); -} - -Framebuffer *CreateFramebuffer(VkDevice dev,RenderPass *rp,List &color,ImageView *depth) -{ - if(!dev)return(nullptr); - if(!rp)return(nullptr); - - if(rp->GetColorFormat().GetCount()!=color.GetCount())return(nullptr); - - if(color.GetCount()==0&&!depth)return(nullptr); - - return CreateFramebuffer(dev,rp,color.GetData(),color.GetCount(),depth); -} - -Framebuffer *CreateFramebuffer(VkDevice dev,RenderPass *rp,ImageView *color,ImageView *depth) -{ - if(!dev)return(nullptr); - if(!rp)return(nullptr); - if(!color&&!depth)return(nullptr); - - return CreateFramebuffer(dev,rp,&color,1,depth); -} - -Framebuffer *CreateFramebuffer(VkDevice dev,RenderPass *rp,ImageView *iv) -{ - if(!dev)return(nullptr); - if(!rp)return(nullptr); - if(!iv)return(nullptr); - - if(iv->hasColor()) - return CreateFramebuffer(dev,rp,&iv,1,nullptr); - else - if(iv->hasDepth()) - return CreateFramebuffer(dev,rp,nullptr,0,iv); - else - return nullptr; -} VK_NAMESPACE_END