From 63a5aeaebe9027e3905e84bbcf0ea835e4873fe0 Mon Sep 17 00:00:00 2001 From: hyzboy Date: Tue, 23 Apr 2019 00:02:59 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=B8=BBFramebuffer,?= =?UTF-8?q?=E4=B8=BBRenderPass=E8=AE=BE=E8=AE=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- example/Vulkan/VKDevice.cpp | 14 ++++++++++++++ example/Vulkan/VKDevice.h | 7 +++++++ example/Vulkan/VKPipeline.cpp | 20 +++++++++----------- example/Vulkan/VKPipeline.h | 3 +-- example/Vulkan/main.cpp | 21 +++------------------ 5 files changed, 34 insertions(+), 31 deletions(-) diff --git a/example/Vulkan/VKDevice.cpp b/example/Vulkan/VKDevice.cpp index 4d9e0845..cac23073 100644 --- a/example/Vulkan/VKDevice.cpp +++ b/example/Vulkan/VKDevice.cpp @@ -5,6 +5,7 @@ #include"VKCommandBuffer.h" //#include"VKDescriptorSet.h" #include"VKRenderPass.h" +#include"VKFramebuffer.h" #include"VKFence.h" #include"VKSemaphore.h" @@ -74,9 +75,22 @@ Device::Device(DeviceAttribute *da) present.pWaitSemaphores = nullptr; present.waitSemaphoreCount = 0; present.pResults = nullptr; + + { + const int sc_count=attr->sc_image_views.GetCount(); + + main_rp=CreateRenderPass(attr->sc_image_views[0]->GetFormat(),attr->depth.view->GetFormat()); + + for(int i=0;isc_image_views[i],attr->depth.view)); + } } Device::~Device() { + main_fb.Clear(); + + delete main_rp; + delete image_acquired_semaphore; delete draw_fence; diff --git a/example/Vulkan/VKDevice.h b/example/Vulkan/VKDevice.h index 244d50ee..d9d86eb3 100644 --- a/example/Vulkan/VKDevice.h +++ b/example/Vulkan/VKDevice.h @@ -5,6 +5,7 @@ #include"VK.h" #include"Window.h" #include"VKDeviceAttribute.h" +#include"VKFramebuffer.h" VK_NAMESPACE_BEGIN struct PhysicalDevice; @@ -23,6 +24,9 @@ class Device Semaphore *image_acquired_semaphore; Fence *draw_fence; + + RenderPass *main_rp; + ObjectList main_fb; uint32_t current_frame; @@ -54,6 +58,9 @@ public: const uint32_t GetCurrentFrameIndices () {return current_frame;} + RenderPass * GetRenderPass () {return main_rp;} + Framebuffer * GetFramebuffer (int index) {return main_fb[index];} + public: Buffer * CreateBuffer(VkBufferUsageFlags buf_usage,VkDeviceSize size,VkSharingMode sharing_mode=VK_SHARING_MODE_EXCLUSIVE); diff --git a/example/Vulkan/VKPipeline.cpp b/example/Vulkan/VKPipeline.cpp index ea36b254..2271864a 100644 --- a/example/Vulkan/VKPipeline.cpp +++ b/example/Vulkan/VKPipeline.cpp @@ -10,7 +10,7 @@ Pipeline::~Pipeline() vkDestroyPipeline(device,pipeline,nullptr); } -PipelineCreater::PipelineCreater(Device *dev) +PipelineCreater::PipelineCreater(Device *dev,RenderPass *rp) { device=dev->GetDevice(); extent=dev->GetExtent(); @@ -19,6 +19,14 @@ PipelineCreater::PipelineCreater(Device *dev) hgl_zero(pipelineInfo); pipelineInfo.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; + { + if(!rp) + rp=dev->GetRenderPass(); + + pipelineInfo.renderPass = *rp; + pipelineInfo.subpass = 0; + } + { vis_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO; vis_create_info.pNext = nullptr; @@ -189,16 +197,6 @@ bool PipelineCreater::Set(VkPipelineLayout pl) return(true); } -bool PipelineCreater::Set(VkRenderPass rp,uint32_t subpass) -{ - if(!rp)return(false); - - pipelineInfo.renderPass = rp; - pipelineInfo.subpass = subpass; - - return(true); -} - Pipeline *PipelineCreater::Create() { VkPipeline graphicsPipeline; diff --git a/example/Vulkan/VKPipeline.h b/example/Vulkan/VKPipeline.h index 40a9dd88..19ae789f 100644 --- a/example/Vulkan/VKPipeline.h +++ b/example/Vulkan/VKPipeline.h @@ -55,14 +55,13 @@ private: public: - PipelineCreater(Device *dev); + PipelineCreater(Device *dev,RenderPass *rp=nullptr); ~PipelineCreater()=default; bool Set(const Shader *); bool Set(const VertexInput *); bool Set(const VkPrimitiveTopology,bool=false); bool Set(VkPipelineLayout pl); - bool Set(VkRenderPass,uint32_t subpass=0); void SetViewport( float x,float y,float w,float h){viewport.x=x;viewport.y=y;viewport.width=w;viewport.height=h;} void SetDepthRange( float min_depth,float max_depth){viewport.minDepth=min_depth;viewport.maxDepth=max_depth;} diff --git a/example/Vulkan/main.cpp b/example/Vulkan/main.cpp index 0441cff6..ed334fc8 100644 --- a/example/Vulkan/main.cpp +++ b/example/Vulkan/main.cpp @@ -156,8 +156,6 @@ int main(int,char **) std::cout<<"auto select physical device: "<GetDeviceName()<CreateCommandBuffer(); - //vulkan::Buffer *ubo=device->CreateUBO(1024); //uint8_t *p=ubo->Map(); @@ -183,15 +181,6 @@ int main(int,char **) vulkan::ImageView *color_iv=device->GetColorImageView(0); vulkan::ImageView *depth_iv=device->GetDepthImageView(); - vulkan::RenderPass *rp=device->CreateRenderPass(color_iv->GetFormat(),depth_iv->GetFormat()); - - for(int i=0;iGetColorImageView(i); - - fb[i]=vulkan::CreateFramebuffer(device,rp,color_iv,depth_iv); - } - vulkan::PipelineCreater pc(device); vulkan::DescriptorSetLayoutCreater dslc(device); @@ -202,7 +191,6 @@ int main(int,char **) pc.Set(vi); pc.Set(PRIM_TRIANGLES); pc.Set(*pl); - pc.Set(*rp); vulkan::Pipeline *pipeline=pc.Create(); @@ -211,7 +199,9 @@ int main(int,char **) device->AcquireNextImage(); - cmd_buf->Begin(rp,fb[0]); + vulkan::CommandBuffer *cmd_buf=device->CreateCommandBuffer(); + + cmd_buf->Begin(device->GetRenderPass(),device->GetFramebuffer(0)); cmd_buf->Bind(pipeline); cmd_buf->Bind(pl); cmd_buf->Bind(vi); @@ -227,17 +217,12 @@ int main(int,char **) delete vertex_buffer; delete color_buffer; - for(int i=0;i