From e2b9983add6ea541269994ab8270156bf50a279a Mon Sep 17 00:00:00 2001 From: hyzboy Date: Mon, 26 Oct 2020 22:16:38 +0800 Subject: [PATCH] optimized BuildCommandBuffer of VulkanAppFramework --- example/common/VulkanAppFramework.h | 54 ++++++++++++---------------- inc/hgl/graph/VKCommandBuffer.h | 2 +- src/RenderDevice/VKCommandBuffer.cpp | 8 ++--- src/RenderDevice/VKRenderTarget.cpp | 2 +- 4 files changed, 28 insertions(+), 38 deletions(-) diff --git a/example/common/VulkanAppFramework.h b/example/common/VulkanAppFramework.h index dea7cd88..742dd569 100644 --- a/example/common/VulkanAppFramework.h +++ b/example/common/VulkanAppFramework.h @@ -141,6 +141,11 @@ public: virtual void MouseMove(){} virtual void MouseWheel(int,int,uint){} + void SetClearColor(COLOR cc) + { + clear_color.Use(cc,1.0); + } + void OnResize(int w,int h) { if(w>0&&h>0) @@ -168,46 +173,16 @@ public: } } - void BuildCommandBuffer(RenderTarget *rt,RenderableInstance *ri) - { - if(!rt||!ri) - return; - - GPUCmdBuffer *cb=rt->GetCommandBuffer(); - const IndexBuffer *ib=ri->GetIndexBuffer(); - - cb->Begin(); - cb->BindFramebuffer(rt); - cb->BindPipeline(ri->GetPipeline()); - cb->BindDescriptorSets(ri->GetDescriptorSets()); - cb->BindVAB(ri); - - if (ib) - cb->DrawIndexed(ib->GetCount()); - else - cb->Draw(ri->GetDrawCount()); - - cb->EndRenderPass(); - cb->End(); - } - - void SetClearColor(COLOR cc) - { - clear_color.Use(cc,1.0); - } - - bool BuildCommandBuffer(uint32_t index,RenderableInstance *ri) + bool BuildCommandBuffer(GPUCmdBuffer *cb,VkRenderPass rp,VkFramebuffer fb,RenderableInstance *ri) { if(!ri)return(false); const IndexBuffer *ib=ri->GetIndexBuffer(); - GPUCmdBuffer *cb=cmd_buf[index]; - cb->SetClearColor(0,clear_color.r,clear_color.g,clear_color.b); cb->Begin(); - cb->BindFramebuffer(sc_render_target->GetRenderPass(),sc_render_target->GetFramebuffer(index)); + cb->BindFramebuffer(rp,fb); cb->BindPipeline(ri->GetPipeline()); cb->BindDescriptorSets(ri->GetDescriptorSets()); cb->BindVAB(ri); @@ -223,6 +198,21 @@ public: return(true); } + void BuildCommandBuffer(RenderTarget *rt,RenderableInstance *ri) + { + if(!rt||!ri) + return; + + BuildCommandBuffer(rt->GetCommandBuffer(),rt->GetRenderPass(),rt->GetFramebuffer(),ri); + } + + bool BuildCommandBuffer(uint32_t index,RenderableInstance *ri) + { + if(!ri)return(false); + + return BuildCommandBuffer(cmd_buf[index],sc_render_target->GetRenderPass(),sc_render_target->GetFramebuffer(index),ri); + } + bool BuildCommandBuffer(RenderableInstance *ri) { if(!ri)return(false); diff --git a/inc/hgl/graph/VKCommandBuffer.h b/inc/hgl/graph/VKCommandBuffer.h index d6c89ce7..838805c2 100644 --- a/inc/hgl/graph/VKCommandBuffer.h +++ b/inc/hgl/graph/VKCommandBuffer.h @@ -67,7 +67,7 @@ public: template void BlitImage (ARGS...args){vkCmdBlitImage (cmd_buf,args...);} bool BindFramebuffer(VkRenderPass rp,VkFramebuffer fb); - bool BindFramebuffer(Framebuffer *); +// bool BindFramebuffer(Framebuffer *); bool BindFramebuffer(RenderTarget *); bool BindPipeline(Pipeline *p) diff --git a/src/RenderDevice/VKCommandBuffer.cpp b/src/RenderDevice/VKCommandBuffer.cpp index 3c3cc8d5..860f6c2f 100644 --- a/src/RenderDevice/VKCommandBuffer.cpp +++ b/src/RenderDevice/VKCommandBuffer.cpp @@ -93,10 +93,10 @@ bool GPUCmdBuffer::BindFramebuffer(VkRenderPass rp,VkFramebuffer fb) return(true); } -bool GPUCmdBuffer::BindFramebuffer(Framebuffer *fbo) -{ - return BindFramebuffer(fbo->GetRenderPass(),fbo->GetFramebuffer()); -} +//bool GPUCmdBuffer::BindFramebuffer(Framebuffer *fbo) +//{ +// return BindFramebuffer(fbo->GetRenderPass(),fbo->GetFramebuffer()); +//} bool GPUCmdBuffer::BindFramebuffer(RenderTarget *rt) { diff --git a/src/RenderDevice/VKRenderTarget.cpp b/src/RenderDevice/VKRenderTarget.cpp index 799c9ed7..6cdd0089 100644 --- a/src/RenderDevice/VKRenderTarget.cpp +++ b/src/RenderDevice/VKRenderTarget.cpp @@ -33,7 +33,7 @@ RenderTarget::RenderTarget(GPUDevice *dev,RenderPass *_rp,Framebuffer *_fb,GPUCm if(color_count>0) { color_textures=new Texture2D *[color_count]; - hgl_cpy(color_textures,ctl,color_count); + hgl_cpy(color_textures,ctl,color_count); extent.width=color_textures[0]->GetWidth(); extent.height=color_textures[0]->GetHeight();