增加主Framebuffer,主RenderPass设计

This commit is contained in:
hyzboy 2019-04-23 00:02:59 +08:00
parent 8e77e09d77
commit 63a5aeaebe
5 changed files with 34 additions and 31 deletions

View File

@ -5,6 +5,7 @@
#include"VKCommandBuffer.h" #include"VKCommandBuffer.h"
//#include"VKDescriptorSet.h" //#include"VKDescriptorSet.h"
#include"VKRenderPass.h" #include"VKRenderPass.h"
#include"VKFramebuffer.h"
#include"VKFence.h" #include"VKFence.h"
#include"VKSemaphore.h" #include"VKSemaphore.h"
@ -74,9 +75,22 @@ Device::Device(DeviceAttribute *da)
present.pWaitSemaphores = nullptr; present.pWaitSemaphores = nullptr;
present.waitSemaphoreCount = 0; present.waitSemaphoreCount = 0;
present.pResults = nullptr; 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;i<sc_count;i++)
main_fb.Add(vulkan::CreateFramebuffer(this,main_rp,attr->sc_image_views[i],attr->depth.view));
}
} }
Device::~Device() Device::~Device()
{ {
main_fb.Clear();
delete main_rp;
delete image_acquired_semaphore; delete image_acquired_semaphore;
delete draw_fence; delete draw_fence;

View File

@ -5,6 +5,7 @@
#include"VK.h" #include"VK.h"
#include"Window.h" #include"Window.h"
#include"VKDeviceAttribute.h" #include"VKDeviceAttribute.h"
#include"VKFramebuffer.h"
VK_NAMESPACE_BEGIN VK_NAMESPACE_BEGIN
struct PhysicalDevice; struct PhysicalDevice;
@ -23,6 +24,9 @@ class Device
Semaphore *image_acquired_semaphore; Semaphore *image_acquired_semaphore;
Fence *draw_fence; Fence *draw_fence;
RenderPass *main_rp;
ObjectList<Framebuffer> main_fb;
uint32_t current_frame; uint32_t current_frame;
@ -54,6 +58,9 @@ public:
const uint32_t GetCurrentFrameIndices () {return current_frame;} const uint32_t GetCurrentFrameIndices () {return current_frame;}
RenderPass * GetRenderPass () {return main_rp;}
Framebuffer * GetFramebuffer (int index) {return main_fb[index];}
public: public:
Buffer * CreateBuffer(VkBufferUsageFlags buf_usage,VkDeviceSize size,VkSharingMode sharing_mode=VK_SHARING_MODE_EXCLUSIVE); Buffer * CreateBuffer(VkBufferUsageFlags buf_usage,VkDeviceSize size,VkSharingMode sharing_mode=VK_SHARING_MODE_EXCLUSIVE);

View File

@ -10,7 +10,7 @@ Pipeline::~Pipeline()
vkDestroyPipeline(device,pipeline,nullptr); vkDestroyPipeline(device,pipeline,nullptr);
} }
PipelineCreater::PipelineCreater(Device *dev) PipelineCreater::PipelineCreater(Device *dev,RenderPass *rp)
{ {
device=dev->GetDevice(); device=dev->GetDevice();
extent=dev->GetExtent(); extent=dev->GetExtent();
@ -19,6 +19,14 @@ PipelineCreater::PipelineCreater(Device *dev)
hgl_zero(pipelineInfo); hgl_zero(pipelineInfo);
pipelineInfo.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; 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.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
vis_create_info.pNext = nullptr; vis_create_info.pNext = nullptr;
@ -189,16 +197,6 @@ bool PipelineCreater::Set(VkPipelineLayout pl)
return(true); 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() Pipeline *PipelineCreater::Create()
{ {
VkPipeline graphicsPipeline; VkPipeline graphicsPipeline;

View File

@ -55,14 +55,13 @@ private:
public: public:
PipelineCreater(Device *dev); PipelineCreater(Device *dev,RenderPass *rp=nullptr);
~PipelineCreater()=default; ~PipelineCreater()=default;
bool Set(const Shader *); bool Set(const Shader *);
bool Set(const VertexInput *); bool Set(const VertexInput *);
bool Set(const VkPrimitiveTopology,bool=false); bool Set(const VkPrimitiveTopology,bool=false);
bool Set(VkPipelineLayout pl); 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 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;} void SetDepthRange( float min_depth,float max_depth){viewport.minDepth=min_depth;viewport.maxDepth=max_depth;}

View File

@ -156,8 +156,6 @@ int main(int,char **)
std::cout<<"auto select physical device: "<<render_device->GetDeviceName()<<std::endl; std::cout<<"auto select physical device: "<<render_device->GetDeviceName()<<std::endl;
} }
vulkan::CommandBuffer *cmd_buf=device->CreateCommandBuffer();
//vulkan::Buffer *ubo=device->CreateUBO(1024); //vulkan::Buffer *ubo=device->CreateUBO(1024);
//uint8_t *p=ubo->Map(); //uint8_t *p=ubo->Map();
@ -183,15 +181,6 @@ int main(int,char **)
vulkan::ImageView *color_iv=device->GetColorImageView(0); vulkan::ImageView *color_iv=device->GetColorImageView(0);
vulkan::ImageView *depth_iv=device->GetDepthImageView(); vulkan::ImageView *depth_iv=device->GetDepthImageView();
vulkan::RenderPass *rp=device->CreateRenderPass(color_iv->GetFormat(),depth_iv->GetFormat());
for(int i=0;i<image_count;i++)
{
color_iv=device->GetColorImageView(i);
fb[i]=vulkan::CreateFramebuffer(device,rp,color_iv,depth_iv);
}
vulkan::PipelineCreater pc(device); vulkan::PipelineCreater pc(device);
vulkan::DescriptorSetLayoutCreater dslc(device); vulkan::DescriptorSetLayoutCreater dslc(device);
@ -202,7 +191,6 @@ int main(int,char **)
pc.Set(vi); pc.Set(vi);
pc.Set(PRIM_TRIANGLES); pc.Set(PRIM_TRIANGLES);
pc.Set(*pl); pc.Set(*pl);
pc.Set(*rp);
vulkan::Pipeline *pipeline=pc.Create(); vulkan::Pipeline *pipeline=pc.Create();
@ -211,7 +199,9 @@ int main(int,char **)
device->AcquireNextImage(); 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(pipeline);
cmd_buf->Bind(pl); cmd_buf->Bind(pl);
cmd_buf->Bind(vi); cmd_buf->Bind(vi);
@ -227,17 +217,12 @@ int main(int,char **)
delete vertex_buffer; delete vertex_buffer;
delete color_buffer; delete color_buffer;
for(int i=0;i<image_count;i++)
delete fb[i];
delete[] fb;
delete pipeline; delete pipeline;
delete pl; delete pl;
delete dsl; delete dsl;
delete sem; delete sem;
delete rp;
delete vi; delete vi;
// delete ubo; // delete ubo;