From d23abfade0e7c11a1e2ce325edb8af21d84bdd3d Mon Sep 17 00:00:00 2001 From: hyzboy Date: Tue, 16 Jul 2019 20:22:29 +0800 Subject: [PATCH] =?UTF-8?q?PipelineCreater=E4=BC=A0=E9=80=92=E5=8F=82?= =?UTF-8?q?=E6=95=B0=E5=88=86=E5=BC=80Renderpass+extent=EF=BC=8C=E6=94=B9?= =?UTF-8?q?=E4=B8=BA=E4=BC=A0=E4=B8=80=E4=B8=AARenderTarget?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- example/Vulkan/Atomsphere.cpp | 2 +- example/Vulkan/Deferred.cpp | 2 +- example/Vulkan/Geometry2D.cpp | 2 +- example/Vulkan/Geometry3D.cpp | 2 +- example/Vulkan/InlineGeometryScene.cpp | 2 +- example/Vulkan/LoadModel.cpp | 2 +- example/Vulkan/SceneTree.cpp | 2 +- example/Vulkan/indices_rect.cpp | 2 +- example/Vulkan/main.cpp | 4 ++-- example/Vulkan/texture_rect.cpp | 2 +- inc/hgl/graph/vulkan/VKCommandBuffer.h | 2 +- inc/hgl/graph/vulkan/VKFramebuffer.h | 4 ++-- inc/hgl/graph/vulkan/VKPipeline.h | 4 ++-- inc/hgl/graph/vulkan/VKRenderTarget.h | 16 ++++++++++------ src/RenderDevice/Vulkan/VKCommandBuffer.cpp | 6 +++--- src/RenderDevice/Vulkan/VKPipeline.cpp | 16 +++++++++------- src/SceneGraph/InlineGeometry.cpp | 2 +- 17 files changed, 39 insertions(+), 33 deletions(-) diff --git a/example/Vulkan/Atomsphere.cpp b/example/Vulkan/Atomsphere.cpp index 0b2693c8..83287144 100644 --- a/example/Vulkan/Atomsphere.cpp +++ b/example/Vulkan/Atomsphere.cpp @@ -88,7 +88,7 @@ private: bool InitPipeline() { AutoDelete - pipeline_creater=new vulkan::PipelineCreater(device,material,sc_render_target->GetRenderPass(),sc_render_target->GetExtent()); + pipeline_creater=new vulkan::PipelineCreater(device,material,sc_render_target); pipeline_creater->SetDepthTest(true); pipeline_creater->SetDepthWrite(true); pipeline_creater->SetCullMode(VK_CULL_MODE_NONE); diff --git a/example/Vulkan/Deferred.cpp b/example/Vulkan/Deferred.cpp index 373c5af2..b72deeb2 100644 --- a/example/Vulkan/Deferred.cpp +++ b/example/Vulkan/Deferred.cpp @@ -251,7 +251,7 @@ private: bool InitCompositionPipeline(SubpassParam *sp) { - AutoDelete pipeline_creater=new vulkan::PipelineCreater(device,sp->material,sc_render_target->GetRenderPass(),sc_render_target->GetExtent()); + AutoDelete pipeline_creater=new vulkan::PipelineCreater(device,sp->material,sc_render_target); pipeline_creater->SetDepthTest(false); pipeline_creater->SetDepthWrite(false); pipeline_creater->SetCullMode(VK_CULL_MODE_NONE); diff --git a/example/Vulkan/Geometry2D.cpp b/example/Vulkan/Geometry2D.cpp index 657120f6..597d6841 100644 --- a/example/Vulkan/Geometry2D.cpp +++ b/example/Vulkan/Geometry2D.cpp @@ -115,7 +115,7 @@ private: bool InitPipeline() { AutoDelete - pipeline_creater=new vulkan::PipelineCreater(device,material,sc_render_target->GetRenderPass(),sc_render_target->GetExtent()); + pipeline_creater=new vulkan::PipelineCreater(device,material,sc_render_target); pipeline_creater->CloseCullFace(); pipeline_creater->Set(PRIM_TRIANGLE_FAN); diff --git a/example/Vulkan/Geometry3D.cpp b/example/Vulkan/Geometry3D.cpp index ec7b9e99..db2520eb 100644 --- a/example/Vulkan/Geometry3D.cpp +++ b/example/Vulkan/Geometry3D.cpp @@ -58,7 +58,7 @@ private: bool InitPipeline(MDP *mdp,const VkPrimitiveTopology primitive) { AutoDelete - pipeline_creater=new vulkan::PipelineCreater(device,mdp->material,sc_render_target->GetRenderPass(),sc_render_target->GetExtent()); + pipeline_creater=new vulkan::PipelineCreater(device,mdp->material,sc_render_target); pipeline_creater->CloseCullFace(); pipeline_creater->Set(primitive); diff --git a/example/Vulkan/InlineGeometryScene.cpp b/example/Vulkan/InlineGeometryScene.cpp index 9c39f426..32a2acf6 100644 --- a/example/Vulkan/InlineGeometryScene.cpp +++ b/example/Vulkan/InlineGeometryScene.cpp @@ -137,7 +137,7 @@ private: bool InitPipeline() { AutoDelete - pipeline_creater=new vulkan::PipelineCreater(device,material,sc_render_target->GetRenderPass(),sc_render_target->GetExtent()); + pipeline_creater=new vulkan::PipelineCreater(device,material,sc_render_target); pipeline_creater->Set(PRIM_LINES); pipeline_line=pipeline_creater->Create(); diff --git a/example/Vulkan/LoadModel.cpp b/example/Vulkan/LoadModel.cpp index 09d9e8c4..8e4d7222 100644 --- a/example/Vulkan/LoadModel.cpp +++ b/example/Vulkan/LoadModel.cpp @@ -163,7 +163,7 @@ private: bool InitPipeline() { AutoDelete - pipeline_creater=new vulkan::PipelineCreater(device,material,sc_render_target->GetRenderPass(),sc_render_target->GetExtent()); + pipeline_creater=new vulkan::PipelineCreater(device,material,sc_render_target); pipeline_creater->SetDepthTest(false); pipeline_creater->SetDepthWrite(false); pipeline_creater->SetPolygonMode(VK_POLYGON_MODE_LINE); diff --git a/example/Vulkan/SceneTree.cpp b/example/Vulkan/SceneTree.cpp index 27489585..20bcd807 100644 --- a/example/Vulkan/SceneTree.cpp +++ b/example/Vulkan/SceneTree.cpp @@ -75,7 +75,7 @@ private: bool InitPipeline() { AutoDelete - pipeline_creater=new vulkan::PipelineCreater(device,material,sc_render_target->GetRenderPass(),sc_render_target->GetExtent()); + pipeline_creater=new vulkan::PipelineCreater(device,material,sc_render_target); pipeline_creater->SetDepthTest(true); pipeline_creater->SetDepthWrite(true); pipeline_creater->CloseCullFace(); diff --git a/example/Vulkan/indices_rect.cpp b/example/Vulkan/indices_rect.cpp index b0b38c2a..d656a16a 100644 --- a/example/Vulkan/indices_rect.cpp +++ b/example/Vulkan/indices_rect.cpp @@ -104,7 +104,7 @@ private: bool InitPipeline() { AutoDelete - pipeline_creater=new vulkan::PipelineCreater(device,material,sc_render_target->GetRenderPass(),sc_render_target->GetExtent()); + pipeline_creater=new vulkan::PipelineCreater(device,material,sc_render_target); pipeline_creater->CloseCullFace(); pipeline_creater->Set(PRIM_TRIANGLES); diff --git a/example/Vulkan/main.cpp b/example/Vulkan/main.cpp index fe530fe5..92a9b006 100644 --- a/example/Vulkan/main.cpp +++ b/example/Vulkan/main.cpp @@ -108,7 +108,7 @@ private: { AutoDelete - pipeline_creater=new vulkan::PipelineCreater(device,material,sc_render_target->GetRenderPass(),sc_render_target->GetExtent()); + pipeline_creater=new vulkan::PipelineCreater(device,material,sc_render_target); pipeline_creater->CloseCullFace(); pipeline_creater->Set(PRIM_TRIANGLES); @@ -119,7 +119,7 @@ private: void *data; uint size=filesystem::LoadFileToMemory(PIPELINE_FILENAME,(void **)&data); - AutoDelete pipeline_creater=new vulkan::PipelineCreater(device,material,sc_render_target->GetRenderPass(),sc_render_target->GetExtent(),(uchar *)data,size); + AutoDelete pipeline_creater=new vulkan::PipelineCreater(device,material,sc_render_target,(uchar *)data,size); pipeline=pipeline_creater->Create(); } diff --git a/example/Vulkan/texture_rect.cpp b/example/Vulkan/texture_rect.cpp index 30165b88..8de08a7c 100644 --- a/example/Vulkan/texture_rect.cpp +++ b/example/Vulkan/texture_rect.cpp @@ -149,7 +149,7 @@ private: bool InitPipeline() { AutoDelete - pipeline_creater=new vulkan::PipelineCreater(device,material,sc_render_target->GetRenderPass(),sc_render_target->GetExtent()); + pipeline_creater=new vulkan::PipelineCreater(device,material,sc_render_target); pipeline_creater->CloseCullFace(); pipeline_creater->Set(PRIM_TRIANGLES); diff --git a/inc/hgl/graph/vulkan/VKCommandBuffer.h b/inc/hgl/graph/vulkan/VKCommandBuffer.h index 4cb0bae4..e54d390e 100644 --- a/inc/hgl/graph/vulkan/VKCommandBuffer.h +++ b/inc/hgl/graph/vulkan/VKCommandBuffer.h @@ -91,7 +91,7 @@ public: vkCmdCopyImageToBuffer(cmd_buf,srcImage,srcImageLayout,dstBuffer,regionCount,pRegions); } - bool BeginRenderPass(RenderPass *rp,Framebuffer *fb); + bool BeginRenderPass(VkRenderPass rp,VkFramebuffer fb); bool Bind(Pipeline *p) { diff --git a/inc/hgl/graph/vulkan/VKFramebuffer.h b/inc/hgl/graph/vulkan/VKFramebuffer.h index cc7e151c..dacf25d4 100644 --- a/inc/hgl/graph/vulkan/VKFramebuffer.h +++ b/inc/hgl/graph/vulkan/VKFramebuffer.h @@ -37,8 +37,8 @@ public: ~Framebuffer(); - VkFramebuffer GetFramebuffer (){return frame_buffer;} - VkRenderPass GetRenderPass (){return fb_info->renderPass;} + const VkFramebuffer GetFramebuffer ()const{return frame_buffer;} + const VkRenderPass GetRenderPass ()const{return fb_info->renderPass;} const VkExtent2D & GetExtent ()const{return extent;} diff --git a/inc/hgl/graph/vulkan/VKPipeline.h b/inc/hgl/graph/vulkan/VKPipeline.h index 5c985d10..4162e687 100644 --- a/inc/hgl/graph/vulkan/VKPipeline.h +++ b/inc/hgl/graph/vulkan/VKPipeline.h @@ -67,8 +67,8 @@ class PipelineCreater public: - PipelineCreater(Device *dev,const Material *,RenderPass *rp,const VkExtent2D &); - PipelineCreater(Device *dev,const Material *,RenderPass *rp,const VkExtent2D &,uchar *,uint); + PipelineCreater(Device *dev,const Material *,const RenderTarget *); + PipelineCreater(Device *dev,const Material *,const RenderTarget *,uchar *,uint); ~PipelineCreater()=default; bool Set(const VkPrimitiveTopology,bool=false); diff --git a/inc/hgl/graph/vulkan/VKRenderTarget.h b/inc/hgl/graph/vulkan/VKRenderTarget.h index b8cc5bfb..27e0ca44 100644 --- a/inc/hgl/graph/vulkan/VKRenderTarget.h +++ b/inc/hgl/graph/vulkan/VKRenderTarget.h @@ -35,6 +35,8 @@ class RenderTarget:public SubmitQueue protected: Framebuffer *fb; + + VkExtent2D extent; protected: @@ -46,6 +48,9 @@ public: virtual ~RenderTarget()=default; + const VkExtent2D & GetExtent()const{return extent;} + virtual const VkRenderPass GetRenderPass()const{return fb->GetRenderPass();} + virtual const uint32_t GetColorCount()const{return fb->GetColorCount();} };//class RenderTarget /** @@ -60,7 +65,6 @@ class SwapchainRenderTarget:public RenderTarget RenderPass *main_rp=nullptr; uint32_t swap_chain_count; - VkExtent2D extent; uint32_t current_frame; ObjectList render_frame; @@ -70,13 +74,13 @@ public: SwapchainRenderTarget(Device *dev,Swapchain *sc); ~SwapchainRenderTarget(); - const uint32_t GetImageCount()const{return swap_chain_count;} - const VkExtent2D & GetExtent()const{return extent;} + const VkRenderPass GetRenderPass()const override{return *main_rp;} + VkFramebuffer GetFramebuffer(const uint32_t index){return render_frame[index]->GetFramebuffer();} - RenderPass * GetRenderPass(){return main_rp;} - Framebuffer * GetFramebuffer(const uint32_t index){return render_frame[index];} + 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;} public: diff --git a/src/RenderDevice/Vulkan/VKCommandBuffer.cpp b/src/RenderDevice/Vulkan/VKCommandBuffer.cpp index b2bfd6d3..d81ef39c 100644 --- a/src/RenderDevice/Vulkan/VKCommandBuffer.cpp +++ b/src/RenderDevice/Vulkan/VKCommandBuffer.cpp @@ -57,14 +57,14 @@ bool CommandBuffer::Begin() return(true); } -bool CommandBuffer::BeginRenderPass(RenderPass *rp,Framebuffer *fb) +bool CommandBuffer::BeginRenderPass(VkRenderPass rp,VkFramebuffer fb) { VkRenderPassBeginInfo rp_begin; rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO; rp_begin.pNext = nullptr; - rp_begin.renderPass = *rp; - rp_begin.framebuffer = fb->GetFramebuffer(); + rp_begin.renderPass = rp; + rp_begin.framebuffer = fb; rp_begin.renderArea = render_area; rp_begin.clearValueCount = cv_count; rp_begin.pClearValues = clear_values; diff --git a/src/RenderDevice/Vulkan/VKPipeline.cpp b/src/RenderDevice/Vulkan/VKPipeline.cpp index 52720e5e..342f1bea 100644 --- a/src/RenderDevice/Vulkan/VKPipeline.cpp +++ b/src/RenderDevice/Vulkan/VKPipeline.cpp @@ -2,6 +2,8 @@ #include #include #include +#include +#include VK_NAMESPACE_BEGIN Pipeline::~Pipeline() @@ -65,10 +67,10 @@ void PipelineCreater::InitDynamicState() //为什么一定要把ext放在这里,因为如果不放在这里,总是会让人遗忘它的重要性 -PipelineCreater::PipelineCreater(Device *dev,const Material *material,RenderPass *rp,const VkExtent2D &ext) +PipelineCreater::PipelineCreater(Device *dev,const Material *material,const RenderTarget *rt) { device=dev->GetDevice(); - extent=ext; + extent=rt->GetExtent(); cache=dev->GetPipelineCache(); //未来这里需要增加是否有vs/fs的检测 @@ -146,7 +148,7 @@ PipelineCreater::PipelineCreater(Device *dev,const Material *material,RenderPass cba.srcAlphaBlendFactor = VK_BLEND_FACTOR_ZERO; cba.dstAlphaBlendFactor = VK_BLEND_FACTOR_ZERO; - colorBlendAttachments.Add(cba,rp->GetColorCount()); //这个需要和subpass中的color attachment数量相等,所以添加多份 + colorBlendAttachments.Add(cba,rt->GetColorCount()); //这个需要和subpass中的color attachment数量相等,所以添加多份 alpha_blend=false; @@ -168,7 +170,7 @@ PipelineCreater::PipelineCreater(Device *dev,const Material *material,RenderPass pipelineInfo.layout = material->GetPipelineLayout(); { - pipelineInfo.renderPass = *rp; + pipelineInfo.renderPass = rt->GetRenderPass(); pipelineInfo.subpass = 0; //subpass由于还不知道有什么用,所以暂时写0,待知道功用后,需改进 } @@ -178,12 +180,12 @@ PipelineCreater::PipelineCreater(Device *dev,const Material *material,RenderPass } } -PipelineCreater::PipelineCreater(Device *dev,const Material *material,RenderPass *rp,const VkExtent2D &ext,uchar *data,uint size) +PipelineCreater::PipelineCreater(Device *dev,const Material *material,const RenderTarget *rt,uchar *data,uint size) { LoadFromMemory(data,size); device=dev->GetDevice(); - extent=ext; + extent=rt->GetExtent(); cache=dev->GetPipelineCache(); InitVertexInputState(material); @@ -202,7 +204,7 @@ PipelineCreater::PipelineCreater(Device *dev,const Material *material,RenderPass pipelineInfo.layout = material->GetPipelineLayout(); { - pipelineInfo.renderPass = *rp; + pipelineInfo.renderPass = rt->GetRenderPass(); pipelineInfo.subpass = 0; //subpass由于还不知道有什么用,所以暂时写0,待知道功用后,需改进 } diff --git a/src/SceneGraph/InlineGeometry.cpp b/src/SceneGraph/InlineGeometry.cpp index 992c5db0..8617d4ec 100644 --- a/src/SceneGraph/InlineGeometry.cpp +++ b/src/SceneGraph/InlineGeometry.cpp @@ -1241,7 +1241,7 @@ namespace hgl else { const float *sp=points; - float *vp=gc.GetVertexPointer(); + float *vp=(float *)(vertex->Get()); for(uint i=0;i<8;i++) {