合并Device中的纹理提交定义Fence/VkSubmitInfo,改为使用SubmitQueue。和RenderTarget共用代码
This commit is contained in:
parent
f87747f7b3
commit
396363d303
@ -223,14 +223,7 @@ public:
|
|||||||
|
|
||||||
int AcquireNextImage()
|
int AcquireNextImage()
|
||||||
{
|
{
|
||||||
if(sc_render_target->Wait())
|
return sc_render_target->AcquireNextImage(present_complete_semaphore);
|
||||||
{
|
|
||||||
int cur=sc_render_target->AcquireNextImage(present_complete_semaphore);
|
|
||||||
|
|
||||||
return cur;
|
|
||||||
}
|
|
||||||
|
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SubmitDraw(int index)
|
void SubmitDraw(int index)
|
||||||
@ -239,6 +232,7 @@ public:
|
|||||||
|
|
||||||
sc_render_target->Submit(cb,present_complete_semaphore,render_complete_semaphore);
|
sc_render_target->Submit(cb,present_complete_semaphore,render_complete_semaphore);
|
||||||
sc_render_target->PresentBackbuffer(render_complete_semaphore);
|
sc_render_target->PresentBackbuffer(render_complete_semaphore);
|
||||||
|
sc_render_target->Wait();
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void Draw()
|
virtual void Draw()
|
||||||
|
@ -16,9 +16,7 @@ class Device
|
|||||||
{
|
{
|
||||||
DeviceAttribute *attr;
|
DeviceAttribute *attr;
|
||||||
|
|
||||||
Fence *texture_fence;
|
SubmitQueue *textureSQ;
|
||||||
|
|
||||||
VkSubmitInfo texture_submit_info;
|
|
||||||
CommandBuffer *texture_cmd_buf;
|
CommandBuffer *texture_cmd_buf;
|
||||||
|
|
||||||
Swapchain *swapchain;
|
Swapchain *swapchain;
|
||||||
|
@ -25,7 +25,8 @@ public:
|
|||||||
virtual ~SubmitQueue();
|
virtual ~SubmitQueue();
|
||||||
|
|
||||||
bool Wait(const bool wait_wall=true,const uint64 time_out=HGL_NANO_SEC_PER_SEC);
|
bool Wait(const bool wait_wall=true,const uint64 time_out=HGL_NANO_SEC_PER_SEC);
|
||||||
bool Submit(VkCommandBuffer &cmd_buf,vulkan::Semaphore *wait_sem,vulkan::Semaphore *complete_sem);
|
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
|
};//class SumbitQueue
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -17,11 +17,7 @@ Device::Device(DeviceAttribute *da)
|
|||||||
{
|
{
|
||||||
attr=da;
|
attr=da;
|
||||||
|
|
||||||
texture_fence=this->CreateFence(false);
|
textureSQ=nullptr;
|
||||||
|
|
||||||
hgl_zero(texture_submit_info);
|
|
||||||
texture_submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
|
|
||||||
|
|
||||||
texture_cmd_buf=nullptr;
|
texture_cmd_buf=nullptr;
|
||||||
|
|
||||||
swapchain=nullptr;
|
swapchain=nullptr;
|
||||||
@ -34,8 +30,8 @@ Device::~Device()
|
|||||||
SAFE_CLEAR(swapchainRT);
|
SAFE_CLEAR(swapchainRT);
|
||||||
SAFE_CLEAR(swapchain);
|
SAFE_CLEAR(swapchain);
|
||||||
|
|
||||||
delete texture_cmd_buf;
|
SAFE_CLEAR(textureSQ);
|
||||||
delete texture_fence;
|
SAFE_CLEAR(texture_cmd_buf);
|
||||||
|
|
||||||
delete attr;
|
delete attr;
|
||||||
}
|
}
|
||||||
@ -45,11 +41,13 @@ bool Device::Resize(const VkExtent2D &extent)
|
|||||||
SAFE_CLEAR(swapchainRT);
|
SAFE_CLEAR(swapchainRT);
|
||||||
SAFE_CLEAR(swapchain);
|
SAFE_CLEAR(swapchain);
|
||||||
|
|
||||||
swapchain=CreateSwapchain(attr,extent);
|
SAFE_CLEAR(textureSQ);
|
||||||
|
SAFE_CLEAR(texture_cmd_buf);
|
||||||
if(texture_cmd_buf)delete texture_cmd_buf;
|
|
||||||
|
|
||||||
texture_cmd_buf=CreateCommandBuffer(swapchain->GetExtent(),0);
|
swapchain=CreateSwapchain(attr,extent);
|
||||||
|
|
||||||
|
texture_cmd_buf=CreateCommandBuffer(extent,0);
|
||||||
|
textureSQ=new SubmitQueue(this,attr->graphics_queue,1);
|
||||||
|
|
||||||
swapchainRT=new SwapchainRenderTarget(this,swapchain);
|
swapchainRT=new SwapchainRenderTarget(this,swapchain);
|
||||||
|
|
||||||
|
@ -156,14 +156,8 @@ bool Device::SubmitTexture(const VkCommandBuffer *cmd_bufs,const uint32_t count)
|
|||||||
if(!cmd_bufs||count<=0)
|
if(!cmd_bufs||count<=0)
|
||||||
return(false);
|
return(false);
|
||||||
|
|
||||||
texture_submit_info.commandBufferCount = count;
|
textureSQ->Submit(cmd_bufs,count,nullptr,nullptr);
|
||||||
texture_submit_info.pCommandBuffers = cmd_bufs;
|
textureSQ->Wait();
|
||||||
|
|
||||||
VkFence fence=*texture_fence;
|
|
||||||
|
|
||||||
if(vkQueueSubmit(attr->graphics_queue, 1, &texture_submit_info, fence))return(false);
|
|
||||||
if(vkWaitForFences(attr->device, 1, &fence, VK_TRUE, HGL_NANO_SEC_PER_SEC*0.1)!=VK_SUCCESS)return(false);
|
|
||||||
vkResetFences(attr->device,1,&fence);
|
|
||||||
|
|
||||||
return(true);
|
return(true);
|
||||||
}
|
}
|
||||||
|
@ -15,17 +15,13 @@ SubmitQueue::SubmitQueue(Device *dev,VkQueue q,const uint32_t fence_count)
|
|||||||
queue=q;
|
queue=q;
|
||||||
|
|
||||||
for(uint32_t i=0;i<fence_count;i++)
|
for(uint32_t i=0;i<fence_count;i++)
|
||||||
fence_list.Add(device->CreateFence(true));
|
fence_list.Add(device->CreateFence(false));
|
||||||
|
|
||||||
current_fence=0;
|
current_fence=0;
|
||||||
|
|
||||||
submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
|
submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
|
||||||
submit_info.pNext = nullptr;
|
submit_info.pNext = nullptr;
|
||||||
//submit_info.waitSemaphoreCount = 1;
|
|
||||||
//submit_info.pWaitSemaphores = *present_complete_semaphore;
|
|
||||||
submit_info.pWaitDstStageMask = &pipe_stage_flags;
|
submit_info.pWaitDstStageMask = &pipe_stage_flags;
|
||||||
//submit_info.signalSemaphoreCount = 1;
|
|
||||||
//submit_info.pSignalSemaphores = *render_complete_semaphore;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SubmitQueue::~SubmitQueue()
|
SubmitQueue::~SubmitQueue()
|
||||||
@ -42,32 +38,59 @@ bool SubmitQueue::Wait(const bool wait_all,uint64_t time_out)
|
|||||||
result=vkWaitForFences(device->GetDevice(),1,&fence,wait_all,time_out);
|
result=vkWaitForFences(device->GetDevice(),1,&fence,wait_all,time_out);
|
||||||
result=vkResetFences(device->GetDevice(),1,&fence);
|
result=vkResetFences(device->GetDevice(),1,&fence);
|
||||||
|
|
||||||
|
if(++current_fence==fence_list.GetCount())
|
||||||
|
current_fence=0;
|
||||||
|
|
||||||
return(true);
|
return(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SubmitQueue::Submit(VkCommandBuffer &cmd_buf,vulkan::Semaphore *wait_sem,vulkan::Semaphore *complete_sem)
|
bool SubmitQueue::Submit(const VkCommandBuffer *cmd_buf,const uint32_t cb_count,vulkan::Semaphore *wait_sem,vulkan::Semaphore *complete_sem)
|
||||||
{
|
{
|
||||||
VkSemaphore ws=*wait_sem;
|
VkSemaphore ws;
|
||||||
VkSemaphore cs=*complete_sem;
|
VkSemaphore cs;
|
||||||
|
|
||||||
submit_info.waitSemaphoreCount =1;
|
if(wait_sem)
|
||||||
submit_info.pWaitSemaphores =&ws;
|
{
|
||||||
submit_info.commandBufferCount =1;
|
ws=*wait_sem;
|
||||||
submit_info.pCommandBuffers =&cmd_buf;
|
|
||||||
submit_info.signalSemaphoreCount=1;
|
submit_info.waitSemaphoreCount =1;
|
||||||
submit_info.pSignalSemaphores =&cs;
|
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];
|
VkFence fence=*fence_list[current_fence];
|
||||||
|
|
||||||
VkResult result=vkQueueSubmit(queue,1,&submit_info,fence);
|
VkResult result=vkQueueSubmit(queue,1,&submit_info,fence);
|
||||||
|
|
||||||
if(++current_fence==fence_list.GetCount())
|
|
||||||
current_fence=0;
|
|
||||||
|
|
||||||
//不在这里立即等待fence完成,是因为有可能queue submit需要久一点工作时间,我们这个时间可以去干别的。等在AcquireNextImage时再去等待fence,而且是另一帧的fence。这样有利于异步处理
|
//不在这里立即等待fence完成,是因为有可能queue submit需要久一点工作时间,我们这个时间可以去干别的。等在AcquireNextImage时再去等待fence,而且是另一帧的fence。这样有利于异步处理
|
||||||
|
|
||||||
return(result==VK_SUCCESS);
|
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,const uint32_t fence_count):SubmitQueue(dev,dev->GetGraphicsQueue(),fence_count)
|
RenderTarget::RenderTarget(Device *dev,Framebuffer *_fb,const uint32_t fence_count):SubmitQueue(dev,dev->GetGraphicsQueue(),fence_count)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user