create VKSubmitQueue.h/.cpp
This commit is contained in:
parent
924df77e1f
commit
bfa7cf50e1
29
inc/hgl/graph/vulkan/VKSubmitQueue.h
Normal file
29
inc/hgl/graph/vulkan/VKSubmitQueue.h
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
#ifndef HGL_GRAPH_VULKAN_SUBMIT_QUEUE_INCLUDE
|
||||||
|
#define HGL_GRAPH_VULKAN_SUBMIT_QUEUE_INCLUDE
|
||||||
|
|
||||||
|
#include<hgl/graph/vulkan/VK.h>
|
||||||
|
#include<hgl/graph/vulkan/VKFence.h>
|
||||||
|
VK_NAMESPACE_BEGIN
|
||||||
|
class SubmitQueue
|
||||||
|
{
|
||||||
|
protected:
|
||||||
|
|
||||||
|
Device *device;
|
||||||
|
VkQueue queue;
|
||||||
|
|
||||||
|
uint32_t current_fence;
|
||||||
|
ObjectList<Fence> fence_list;
|
||||||
|
|
||||||
|
SubmitInfo submit_info;
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
SubmitQueue(Device *dev,VkQueue q,const uint32_t fence_count=1);
|
||||||
|
virtual ~SubmitQueue();
|
||||||
|
|
||||||
|
bool Wait(const bool wait_wall=true,const uint64_t time_out=HGL_NANO_SEC_PER_SEC);
|
||||||
|
bool Submit(const VkCommandBuffer &cmd_buf,vulkan::Semaphore *wait_sem,vulkan::Semaphore *complete_sem);
|
||||||
|
bool Submit(const VkCommandBuffer *cmd_buf,const uint32_t count,vulkan::Semaphore *wait_sem,vulkan::Semaphore *complete_sem);
|
||||||
|
};//class SumbitQueue
|
||||||
|
VK_NAMESPACE_END
|
||||||
|
#endif//HGL_GRAPH_VULKAN_SUBMIT_QUEUE_INCLUDE
|
@ -1,7 +1,6 @@
|
|||||||
#include<hgl/graph/vulkan/VKRenderTarget.h>
|
#include<hgl/graph/vulkan/VKRenderTarget.h>
|
||||||
#include<hgl/graph/vulkan/VKDevice.h>
|
#include<hgl/graph/vulkan/VKDevice.h>
|
||||||
#include<hgl/graph/vulkan/VKSwapchain.h>
|
#include<hgl/graph/vulkan/VKSwapchain.h>
|
||||||
#include<hgl/graph/vulkan/VKSemaphore.h>
|
|
||||||
#include<hgl/graph/vulkan/VKCommandBuffer.h>
|
#include<hgl/graph/vulkan/VKCommandBuffer.h>
|
||||||
|
|
||||||
VK_NAMESPACE_BEGIN
|
VK_NAMESPACE_BEGIN
|
||||||
@ -10,95 +9,28 @@ namespace
|
|||||||
const VkPipelineStageFlags pipe_stage_flags=VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
|
const VkPipelineStageFlags pipe_stage_flags=VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
|
||||||
}//namespace
|
}//namespace
|
||||||
|
|
||||||
SubmitQueue::SubmitQueue(Device *dev,VkQueue q,const uint32_t fence_count)
|
|
||||||
{
|
|
||||||
device=dev;
|
|
||||||
queue=q;
|
|
||||||
|
|
||||||
for(uint32_t i=0;i<fence_count;i++)
|
|
||||||
fence_list.Add(device->CreateFence(false));
|
|
||||||
|
|
||||||
current_fence=0;
|
|
||||||
|
|
||||||
submit_info.pWaitDstStageMask = &pipe_stage_flags;
|
|
||||||
}
|
|
||||||
|
|
||||||
SubmitQueue::~SubmitQueue()
|
|
||||||
{
|
|
||||||
fence_list.Clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool SubmitQueue::Wait(const bool wait_all,uint64_t time_out)
|
|
||||||
{
|
|
||||||
VkFence fence=*fence_list[current_fence];
|
|
||||||
|
|
||||||
VkResult result;
|
|
||||||
|
|
||||||
result=vkWaitForFences(device->GetDevice(),1,&fence,wait_all,time_out);
|
|
||||||
result=vkResetFences(device->GetDevice(),1,&fence);
|
|
||||||
|
|
||||||
if(++current_fence==fence_list.GetCount())
|
|
||||||
current_fence=0;
|
|
||||||
|
|
||||||
return(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool SubmitQueue::Submit(const VkCommandBuffer *cmd_buf,const uint32_t cb_count,vulkan::Semaphore *wait_sem,vulkan::Semaphore *complete_sem)
|
|
||||||
{
|
|
||||||
VkSemaphore ws;
|
|
||||||
VkSemaphore cs;
|
|
||||||
|
|
||||||
if(wait_sem)
|
|
||||||
{
|
|
||||||
ws=*wait_sem;
|
|
||||||
|
|
||||||
submit_info.waitSemaphoreCount =1;
|
|
||||||
submit_info.pWaitSemaphores =&ws;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
submit_info.waitSemaphoreCount =0;
|
|
||||||
submit_info.pWaitSemaphores =nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(complete_sem)
|
|
||||||
{
|
|
||||||
cs=*complete_sem;
|
|
||||||
|
|
||||||
submit_info.signalSemaphoreCount=1;
|
|
||||||
submit_info.pSignalSemaphores =&cs;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
submit_info.signalSemaphoreCount=0;
|
|
||||||
submit_info.pSignalSemaphores =nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
submit_info.commandBufferCount =cb_count;
|
|
||||||
submit_info.pCommandBuffers =cmd_buf;
|
|
||||||
|
|
||||||
VkFence fence=*fence_list[current_fence];
|
|
||||||
|
|
||||||
VkResult result=vkQueueSubmit(queue,1,&submit_info,fence);
|
|
||||||
|
|
||||||
//不在这里立即等待fence完成,是因为有可能queue submit需要久一点工作时间,我们这个时间可以去干别的。等在AcquireNextImage时再去等待fence,而且是另一帧的fence。这样有利于异步处理
|
|
||||||
|
|
||||||
return(result==VK_SUCCESS);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool SubmitQueue::Submit(const VkCommandBuffer &cmd_buf,vulkan::Semaphore *wait_sem,vulkan::Semaphore *complete_sem)
|
|
||||||
{
|
|
||||||
return Submit(&cmd_buf,1,wait_sem,complete_sem);
|
|
||||||
}
|
|
||||||
|
|
||||||
RenderTarget::RenderTarget(Device *dev,Framebuffer *_fb,CommandBuffer *_cb,const uint32_t fence_count):SubmitQueue(dev,dev->GetGraphicsQueue(),fence_count)
|
RenderTarget::RenderTarget(Device *dev,Framebuffer *_fb,CommandBuffer *_cb,const uint32_t fence_count):SubmitQueue(dev,dev->GetGraphicsQueue(),fence_count)
|
||||||
{
|
{
|
||||||
fb=_fb;
|
fb=_fb;
|
||||||
command_buffer=_cb;
|
command_buffer=_cb;
|
||||||
|
|
||||||
|
depth_texture=nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
RenderTarget::RenderTarget(Device *dev,Framebuffer *_fb,CommandBuffer *_cb,Texture2D **ctl,const uint32_t cc,Texture2D *dt,const uint32_t fence_count):SubmitQueue(dev,dev->GetGraphicsQueue(),fence_count)
|
||||||
|
{
|
||||||
|
fb=_fb;
|
||||||
|
command_buffer=_cb;
|
||||||
|
|
||||||
|
color_texture.Add(ctl,cc);
|
||||||
|
depth_texture=dt;
|
||||||
}
|
}
|
||||||
|
|
||||||
RenderTarget::~RenderTarget()
|
RenderTarget::~RenderTarget()
|
||||||
{
|
{
|
||||||
|
SAFE_CLEAR(depth_texture);
|
||||||
|
color_texture.Clear();
|
||||||
|
|
||||||
SAFE_CLEAR(command_buffer);
|
SAFE_CLEAR(command_buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -138,22 +70,18 @@ SwapchainRenderTarget::~SwapchainRenderTarget()
|
|||||||
delete main_rp;
|
delete main_rp;
|
||||||
}
|
}
|
||||||
|
|
||||||
int SwapchainRenderTarget::AcquireNextImage(vulkan::Semaphore *present_complete_semaphore)
|
int SwapchainRenderTarget::AcquireNextImage(VkSemaphore present_complete_semaphore)
|
||||||
{
|
{
|
||||||
VkSemaphore sem=*present_complete_semaphore;
|
if(vkAcquireNextImageKHR(device->GetDevice(),vk_swapchain,UINT64_MAX,present_complete_semaphore,VK_NULL_HANDLE,¤t_frame)==VK_SUCCESS)
|
||||||
|
|
||||||
if(vkAcquireNextImageKHR(device->GetDevice(),vk_swapchain,UINT64_MAX,sem,VK_NULL_HANDLE,¤t_frame)==VK_SUCCESS)
|
|
||||||
return current_frame;
|
return current_frame;
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SwapchainRenderTarget::PresentBackbuffer(vulkan::Semaphore *render_complete_semaphore)
|
bool SwapchainRenderTarget::PresentBackbuffer(VkSemaphore *render_complete_semaphore,const uint32_t count)
|
||||||
{
|
{
|
||||||
VkSemaphore sem=*render_complete_semaphore;
|
present_info.waitSemaphoreCount =count;
|
||||||
|
present_info.pWaitSemaphores =render_complete_semaphore;
|
||||||
present_info.waitSemaphoreCount =1;
|
|
||||||
present_info.pWaitSemaphores =&sem;
|
|
||||||
present_info.pImageIndices =¤t_frame;
|
present_info.pImageIndices =¤t_frame;
|
||||||
|
|
||||||
VkResult result=vkQueuePresentKHR(queue,&present_info);
|
VkResult result=vkQueuePresentKHR(queue,&present_info);
|
||||||
|
91
src/RenderDevice/Vulkan/VKSubmitQueue.cpp
Normal file
91
src/RenderDevice/Vulkan/VKSubmitQueue.cpp
Normal file
@ -0,0 +1,91 @@
|
|||||||
|
#include<hgl/graph/vulkan/VKSubmitQueue.h>
|
||||||
|
#include<hgl/graph/vulkan/VKDevice.h>
|
||||||
|
#include<hgl/graph/vulkan/VKSemaphore.h>
|
||||||
|
|
||||||
|
VK_NAMESPACE_BEGIN
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
const VkPipelineStageFlags pipe_stage_flags=VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
|
||||||
|
}//namespace
|
||||||
|
|
||||||
|
SubmitQueue::SubmitQueue(Device *dev,VkQueue q,const uint32_t fence_count)
|
||||||
|
{
|
||||||
|
device=dev;
|
||||||
|
queue=q;
|
||||||
|
|
||||||
|
for(uint32_t i=0;i<fence_count;i++)
|
||||||
|
fence_list.Add(device->CreateFence(false));
|
||||||
|
|
||||||
|
current_fence=0;
|
||||||
|
|
||||||
|
submit_info.pWaitDstStageMask = &pipe_stage_flags;
|
||||||
|
}
|
||||||
|
|
||||||
|
SubmitQueue::~SubmitQueue()
|
||||||
|
{
|
||||||
|
fence_list.Clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool SubmitQueue::Wait(const bool wait_all,uint64_t time_out)
|
||||||
|
{
|
||||||
|
VkFence fence=*fence_list[current_fence];
|
||||||
|
|
||||||
|
VkResult result;
|
||||||
|
|
||||||
|
result=vkWaitForFences(device->GetDevice(),1,&fence,wait_all,time_out);
|
||||||
|
result=vkResetFences(device->GetDevice(),1,&fence);
|
||||||
|
|
||||||
|
if(++current_fence==fence_list.GetCount())
|
||||||
|
current_fence=0;
|
||||||
|
|
||||||
|
return(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool SubmitQueue::Submit(const VkCommandBuffer *cmd_buf,const uint32_t cb_count,vulkan::Semaphore *wait_sem,vulkan::Semaphore *complete_sem)
|
||||||
|
{
|
||||||
|
VkSemaphore ws;
|
||||||
|
VkSemaphore cs;
|
||||||
|
|
||||||
|
if(wait_sem)
|
||||||
|
{
|
||||||
|
ws=*wait_sem;
|
||||||
|
|
||||||
|
submit_info.waitSemaphoreCount =1;
|
||||||
|
submit_info.pWaitSemaphores =&ws;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
submit_info.waitSemaphoreCount =0;
|
||||||
|
submit_info.pWaitSemaphores =nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(complete_sem)
|
||||||
|
{
|
||||||
|
cs=*complete_sem;
|
||||||
|
|
||||||
|
submit_info.signalSemaphoreCount=1;
|
||||||
|
submit_info.pSignalSemaphores =&cs;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
submit_info.signalSemaphoreCount=0;
|
||||||
|
submit_info.pSignalSemaphores =nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
submit_info.commandBufferCount =cb_count;
|
||||||
|
submit_info.pCommandBuffers =cmd_buf;
|
||||||
|
|
||||||
|
VkFence fence=*fence_list[current_fence];
|
||||||
|
|
||||||
|
VkResult result=vkQueueSubmit(queue,1,&submit_info,fence);
|
||||||
|
|
||||||
|
//不在这里立即等待fence完成,是因为有可能queue submit需要久一点工作时间,我们这个时间可以去干别的。等在AcquireNextImage时再去等待fence,而且是另一帧的fence。这样有利于异步处理
|
||||||
|
|
||||||
|
return(result==VK_SUCCESS);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool SubmitQueue::Submit(const VkCommandBuffer &cmd_buf,vulkan::Semaphore *wait_sem,vulkan::Semaphore *complete_sem)
|
||||||
|
{
|
||||||
|
return Submit(&cmd_buf,1,wait_sem,complete_sem);
|
||||||
|
}
|
||||||
|
VK_NAMESPACE_END
|
Loading…
x
Reference in New Issue
Block a user