2020-10-21 12:39:22 +08:00
|
|
|
|
#include<hgl/graph/VKQueue.h>
|
2020-10-21 11:43:18 +08:00
|
|
|
|
#include<hgl/graph/VKDevice.h>
|
|
|
|
|
#include<hgl/graph/VKSemaphore.h>
|
2020-10-17 14:16:52 +08:00
|
|
|
|
|
|
|
|
|
VK_NAMESPACE_BEGIN
|
|
|
|
|
namespace
|
|
|
|
|
{
|
|
|
|
|
const VkPipelineStageFlags pipe_stage_flags=VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
|
|
|
|
|
}//namespace
|
|
|
|
|
|
2020-10-21 12:39:22 +08:00
|
|
|
|
GPUQueue::GPUQueue(GPUDevice *dev,VkQueue q,const uint32_t fence_count)
|
2020-10-17 14:16:52 +08:00
|
|
|
|
{
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-21 12:39:22 +08:00
|
|
|
|
GPUQueue::~GPUQueue()
|
2020-10-17 14:16:52 +08:00
|
|
|
|
{
|
|
|
|
|
fence_list.Clear();
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-21 12:39:22 +08:00
|
|
|
|
bool GPUQueue::WaitQueue()
|
2020-10-17 14:16:52 +08:00
|
|
|
|
{
|
2020-10-17 22:12:16 +08:00
|
|
|
|
VkResult result=vkQueueWaitIdle(queue);
|
2020-10-17 14:16:52 +08:00
|
|
|
|
|
2020-10-17 22:12:16 +08:00
|
|
|
|
if(result!=VK_SUCCESS)
|
|
|
|
|
return(false);
|
|
|
|
|
|
|
|
|
|
return(true);
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-21 12:39:22 +08:00
|
|
|
|
bool GPUQueue::WaitFence(const bool wait_all,uint64_t time_out)
|
2020-10-17 22:12:16 +08:00
|
|
|
|
{
|
2020-10-17 14:16:52 +08:00
|
|
|
|
VkResult result;
|
2020-10-17 22:12:16 +08:00
|
|
|
|
VkFence fence=*fence_list[current_fence];
|
2020-10-17 14:16:52 +08:00
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-21 12:39:22 +08:00
|
|
|
|
bool GPUQueue::Submit(const VkCommandBuffer *cmd_buf,const uint32_t cb_count,vulkan::GPUSemaphore *wait_sem,vulkan::GPUSemaphore *complete_sem)
|
2020-10-17 14:16:52 +08:00
|
|
|
|
{
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-21 12:39:22 +08:00
|
|
|
|
bool GPUQueue::Submit(const VkCommandBuffer &cmd_buf,vulkan::GPUSemaphore *wait_sem,vulkan::GPUSemaphore *complete_sem)
|
2020-10-17 14:16:52 +08:00
|
|
|
|
{
|
|
|
|
|
return Submit(&cmd_buf,1,wait_sem,complete_sem);
|
|
|
|
|
}
|
|
|
|
|
VK_NAMESPACE_END
|