VKDevice内义RenderFrame,将frame_buffer,present_complete_semaphore,render_complete_semaphore,draw_fence等成对分配
This commit is contained in:
parent
5bad17d281
commit
6c8cf14abe
@ -195,20 +195,17 @@ private:
|
|||||||
device->AcquireNextImage();
|
device->AcquireNextImage();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Submit(const VkCommandBuffer cmd_buf)
|
|
||||||
{
|
|
||||||
device->SubmitDraw(&cmd_buf);
|
|
||||||
device->Wait();
|
|
||||||
device->QueuePresent();
|
|
||||||
}
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
virtual void Draw()
|
virtual void Draw()
|
||||||
{
|
{
|
||||||
const vulkan::CommandBuffer *cb=cmd_buf[device->GetCurrentFrameIndices()];
|
uint32_t index=device->GetCurrentFrameIndices();
|
||||||
|
|
||||||
Submit(*cb);
|
VkCommandBuffer cb=*cmd_buf[index];
|
||||||
|
|
||||||
|
device->SubmitDraw(&cb);
|
||||||
|
device->Wait(&index);
|
||||||
|
device->QueuePresent();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Run()
|
bool Run()
|
||||||
|
@ -8,6 +8,8 @@
|
|||||||
#include<hgl/graph/vulkan/VK.h>
|
#include<hgl/graph/vulkan/VK.h>
|
||||||
#include<hgl/graph/vulkan/VKDeviceAttribute.h>
|
#include<hgl/graph/vulkan/VKDeviceAttribute.h>
|
||||||
#include<hgl/graph/vulkan/VKFramebuffer.h>
|
#include<hgl/graph/vulkan/VKFramebuffer.h>
|
||||||
|
#include<hgl/graph/vulkan/VKFence.h>
|
||||||
|
#include<hgl/graph/vulkan/VKSemaphore.h>
|
||||||
#include<hgl/graph/VertexBufferCreater.h>
|
#include<hgl/graph/VertexBufferCreater.h>
|
||||||
|
|
||||||
VK_NAMESPACE_BEGIN
|
VK_NAMESPACE_BEGIN
|
||||||
@ -15,16 +17,38 @@ class Device
|
|||||||
{
|
{
|
||||||
DeviceAttribute *attr;
|
DeviceAttribute *attr;
|
||||||
|
|
||||||
Semaphore *image_acquired_semaphore;
|
struct RenderFrame
|
||||||
Fence *draw_fence,*texture_fence;
|
{
|
||||||
|
Framebuffer *frame_buffer=nullptr;
|
||||||
|
|
||||||
|
Semaphore *present_complete_semaphore=nullptr,
|
||||||
|
*render_complete_semaphore=nullptr;
|
||||||
|
|
||||||
|
Fence *draw_fence=nullptr;
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
~RenderFrame()
|
||||||
|
{
|
||||||
|
SAFE_CLEAR(frame_buffer);
|
||||||
|
|
||||||
|
SAFE_CLEAR(present_complete_semaphore);
|
||||||
|
SAFE_CLEAR(render_complete_semaphore);
|
||||||
|
SAFE_CLEAR(draw_fence);
|
||||||
|
}
|
||||||
|
};//struct RenderFrame
|
||||||
|
|
||||||
|
void Create(RenderFrame *);
|
||||||
|
|
||||||
|
Fence *texture_fence;
|
||||||
|
|
||||||
VkSubmitInfo texture_submitInfo;
|
VkSubmitInfo texture_submitInfo;
|
||||||
CommandBuffer *texture_cmd_buf;
|
CommandBuffer *texture_cmd_buf;
|
||||||
|
|
||||||
RenderPass *main_rp;
|
RenderPass *main_rp;
|
||||||
ObjectList<Framebuffer> main_fb;
|
|
||||||
|
|
||||||
uint32_t current_frame;
|
uint32_t current_frame;
|
||||||
|
ObjectList<RenderFrame> render_frame;
|
||||||
|
|
||||||
VkPresentInfoKHR present;
|
VkPresentInfoKHR present;
|
||||||
|
|
||||||
@ -59,9 +83,9 @@ public:
|
|||||||
ImageView *GetDepthImageView () {return attr->depth.view;}
|
ImageView *GetDepthImageView () {return attr->depth.view;}
|
||||||
|
|
||||||
RenderPass * GetRenderPass () {return main_rp;}
|
RenderPass * GetRenderPass () {return main_rp;}
|
||||||
Framebuffer * GetFramebuffer (int index) {return main_fb[index];}
|
Framebuffer * GetFramebuffer (int index) {return render_frame[index]->frame_buffer;}
|
||||||
const uint32_t GetCurrentFrameIndices () {return current_frame;}
|
const uint32_t GetCurrentFrameIndices () {return current_frame;}
|
||||||
Framebuffer * GetCurrentFramebuffer () {return main_fb[current_frame];}
|
Framebuffer * GetCurrentFramebuffer () {return render_frame[current_frame]->frame_buffer;}
|
||||||
|
|
||||||
bool Resize (uint,uint);
|
bool Resize (uint,uint);
|
||||||
|
|
||||||
|
@ -5,8 +5,6 @@
|
|||||||
//#include<hgl/graph/vulkan/VKDescriptorSet.h>
|
//#include<hgl/graph/vulkan/VKDescriptorSet.h>
|
||||||
#include<hgl/graph/vulkan/VKRenderPass.h>
|
#include<hgl/graph/vulkan/VKRenderPass.h>
|
||||||
#include<hgl/graph/vulkan/VKFramebuffer.h>
|
#include<hgl/graph/vulkan/VKFramebuffer.h>
|
||||||
#include<hgl/graph/vulkan/VKFence.h>
|
|
||||||
#include<hgl/graph/vulkan/VKSemaphore.h>
|
|
||||||
#include<hgl/graph/vulkan/VKShaderModuleManage.h>
|
#include<hgl/graph/vulkan/VKShaderModuleManage.h>
|
||||||
#include<hgl/graph/vulkan/VKDescriptorSets.h>
|
#include<hgl/graph/vulkan/VKDescriptorSets.h>
|
||||||
|
|
||||||
@ -19,8 +17,6 @@ Device::Device(DeviceAttribute *da)
|
|||||||
|
|
||||||
current_frame=0;
|
current_frame=0;
|
||||||
|
|
||||||
image_acquired_semaphore=this->CreateSem();
|
|
||||||
draw_fence=this->CreateFence();
|
|
||||||
texture_fence=this->CreateFence();
|
texture_fence=this->CreateFence();
|
||||||
|
|
||||||
hgl_zero(texture_submitInfo);
|
hgl_zero(texture_submitInfo);
|
||||||
@ -33,22 +29,19 @@ Device::Device(DeviceAttribute *da)
|
|||||||
|
|
||||||
Device::~Device()
|
Device::~Device()
|
||||||
{
|
{
|
||||||
main_fb.Clear();
|
render_frame.Clear();
|
||||||
|
|
||||||
delete main_rp;
|
delete main_rp;
|
||||||
|
|
||||||
delete image_acquired_semaphore;
|
|
||||||
|
|
||||||
delete texture_cmd_buf;
|
delete texture_cmd_buf;
|
||||||
delete texture_fence;
|
delete texture_fence;
|
||||||
delete draw_fence;
|
|
||||||
|
|
||||||
delete attr;
|
delete attr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Device::RecreateDevice()
|
void Device::RecreateDevice()
|
||||||
{
|
{
|
||||||
main_fb.Clear();
|
render_frame.Clear();
|
||||||
if(main_rp)delete main_rp;
|
if(main_rp)delete main_rp;
|
||||||
if(texture_cmd_buf)delete texture_cmd_buf;
|
if(texture_cmd_buf)delete texture_cmd_buf;
|
||||||
|
|
||||||
@ -56,15 +49,23 @@ void Device::RecreateDevice()
|
|||||||
present.pNext = nullptr;
|
present.pNext = nullptr;
|
||||||
present.swapchainCount = 1;
|
present.swapchainCount = 1;
|
||||||
present.pSwapchains = &attr->swap_chain;
|
present.pSwapchains = &attr->swap_chain;
|
||||||
present.pWaitSemaphores = nullptr;
|
|
||||||
present.waitSemaphoreCount = 0;
|
|
||||||
present.pResults = nullptr;
|
present.pResults = nullptr;
|
||||||
|
|
||||||
main_rp=CreateRenderPass(attr->sc_image_views[0]->GetFormat(),attr->depth.view->GetFormat());
|
main_rp=CreateRenderPass(attr->sc_image_views[0]->GetFormat(),attr->depth.view->GetFormat());
|
||||||
|
|
||||||
const int sc_count=attr->sc_image_views.GetCount();
|
const int sc_count=attr->sc_image_views.GetCount();
|
||||||
|
|
||||||
for(int i=0;i<sc_count;i++)
|
for(int i=0;i<sc_count;i++)
|
||||||
main_fb.Add(vulkan::CreateFramebuffer(this,main_rp,attr->sc_image_views[i],attr->depth.view));
|
{
|
||||||
|
RenderFrame *rf=new RenderFrame;
|
||||||
|
|
||||||
|
rf->frame_buffer =vulkan::CreateFramebuffer(this,main_rp,attr->sc_image_views[i],attr->depth.view);
|
||||||
|
rf->present_complete_semaphore =this->CreateSem();
|
||||||
|
rf->render_complete_semaphore =this->CreateSem();
|
||||||
|
rf->draw_fence =this->CreateFence();
|
||||||
|
|
||||||
|
render_frame.Add(rf);
|
||||||
|
}
|
||||||
|
|
||||||
texture_cmd_buf=CreateCommandBuffer();
|
texture_cmd_buf=CreateCommandBuffer();
|
||||||
}
|
}
|
||||||
@ -226,7 +227,9 @@ ShaderModuleManage *Device::CreateShaderModuleManage()
|
|||||||
|
|
||||||
bool Device::AcquireNextImage()
|
bool Device::AcquireNextImage()
|
||||||
{
|
{
|
||||||
return(vkAcquireNextImageKHR(attr->device,attr->swap_chain,UINT64_MAX,*image_acquired_semaphore,VK_NULL_HANDLE,¤t_frame)==VK_SUCCESS);
|
VkSemaphore present_complete_semaphore=*(render_frame[current_frame]->present_complete_semaphore);
|
||||||
|
|
||||||
|
return(vkAcquireNextImageKHR(attr->device,attr->swap_chain,UINT64_MAX,present_complete_semaphore,VK_NULL_HANDLE,¤t_frame)==VK_SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Device::SubmitDraw(const VkCommandBuffer *cmd_bufs,const uint32_t count)
|
bool Device::SubmitDraw(const VkCommandBuffer *cmd_bufs,const uint32_t count)
|
||||||
@ -237,26 +240,31 @@ bool Device::SubmitDraw(const VkCommandBuffer *cmd_bufs,const uint32_t count)
|
|||||||
VkPipelineStageFlags pipe_stage_flags = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
|
VkPipelineStageFlags pipe_stage_flags = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
|
||||||
VkSubmitInfo submit_info = {};
|
VkSubmitInfo submit_info = {};
|
||||||
|
|
||||||
VkSemaphore wait_sem=*image_acquired_semaphore;
|
RenderFrame *rf=render_frame[current_frame];
|
||||||
|
|
||||||
|
VkSemaphore present_sem=*(rf->present_complete_semaphore);
|
||||||
|
VkSemaphore complete_sem=*(rf->render_complete_semaphore);
|
||||||
|
|
||||||
submit_info.pNext = nullptr;
|
submit_info.pNext = nullptr;
|
||||||
submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
|
submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
|
||||||
submit_info.waitSemaphoreCount = 1;
|
submit_info.waitSemaphoreCount = 1;
|
||||||
submit_info.pWaitSemaphores = &wait_sem;
|
submit_info.pWaitSemaphores = &present_sem;
|
||||||
submit_info.pWaitDstStageMask = &pipe_stage_flags;
|
submit_info.pWaitDstStageMask = &pipe_stage_flags;
|
||||||
submit_info.commandBufferCount = count;
|
submit_info.commandBufferCount = count;
|
||||||
submit_info.pCommandBuffers = cmd_bufs;
|
submit_info.pCommandBuffers = cmd_bufs;
|
||||||
submit_info.signalSemaphoreCount = 0;
|
submit_info.signalSemaphoreCount = 1;
|
||||||
submit_info.pSignalSemaphores = nullptr;
|
submit_info.pSignalSemaphores = &complete_sem;
|
||||||
|
|
||||||
return(vkQueueSubmit(attr->graphics_queue, 1, &submit_info, *draw_fence)==VK_SUCCESS);
|
VkFence fence=*(rf->draw_fence);
|
||||||
|
|
||||||
|
return(vkQueueSubmit(attr->graphics_queue,1,&submit_info,fence)==VK_SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Device::Wait(bool wait_all,uint64_t time_out)
|
bool Device::Wait(bool wait_all,uint64_t time_out)
|
||||||
{
|
{
|
||||||
VkFence fence=*draw_fence;
|
VkFence fence=*(render_frame[current_frame]->draw_fence);
|
||||||
|
|
||||||
vkWaitForFences(attr->device, 1, &fence, wait_all, time_out);
|
while(vkWaitForFences(attr->device,1,&fence,wait_all,time_out)==VK_TIMEOUT){}
|
||||||
vkResetFences(attr->device,1,&fence);
|
vkResetFences(attr->device,1,&fence);
|
||||||
|
|
||||||
return(true);
|
return(true);
|
||||||
@ -264,9 +272,11 @@ bool Device::Wait(bool wait_all,uint64_t time_out)
|
|||||||
|
|
||||||
bool Device::QueuePresent()
|
bool Device::QueuePresent()
|
||||||
{
|
{
|
||||||
|
VkSemaphore render_complete_semaphore=*(render_frame[current_frame]->render_complete_semaphore);
|
||||||
|
|
||||||
present.pImageIndices = ¤t_frame;
|
present.pImageIndices = ¤t_frame;
|
||||||
present.waitSemaphoreCount = 0;
|
present.waitSemaphoreCount = 1;
|
||||||
present.pWaitSemaphores = nullptr;
|
present.pWaitSemaphores = &render_complete_semaphore;
|
||||||
|
|
||||||
return(vkQueuePresentKHR(attr->present_queue, &present)==VK_SUCCESS);
|
return(vkQueuePresentKHR(attr->present_queue, &present)==VK_SUCCESS);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user