增加主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"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;i<sc_count;i++)
main_fb.Add(vulkan::CreateFramebuffer(this,main_rp,attr->sc_image_views[i],attr->depth.view));
}
}
Device::~Device()
{
main_fb.Clear();
delete main_rp;
delete image_acquired_semaphore;
delete draw_fence;

View File

@ -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<Framebuffer> 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);

View File

@ -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;

View File

@ -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;}

View File

@ -156,8 +156,6 @@ int main(int,char **)
std::cout<<"auto select physical device: "<<render_device->GetDeviceName()<<std::endl;
}
vulkan::CommandBuffer *cmd_buf=device->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;i<image_count;i++)
{
color_iv=device->GetColorImageView(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<image_count;i++)
delete fb[i];
delete[] fb;
delete pipeline;
delete pl;
delete dsl;
delete sem;
delete rp;
delete vi;
// delete ubo;