VKDevice建立独立的texture提交专用fence,以避免和绘图用冲突
This commit is contained in:
parent
476a60b99e
commit
5c913dd792
@ -81,7 +81,7 @@ public:
|
|||||||
|
|
||||||
void Submit(const VkCommandBuffer cmd_buf)
|
void Submit(const VkCommandBuffer cmd_buf)
|
||||||
{
|
{
|
||||||
device->QueueSubmit(&cmd_buf);
|
device->SubmitDraw(&cmd_buf);
|
||||||
device->Wait();
|
device->Wait();
|
||||||
device->QueuePresent();
|
device->QueuePresent();
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,9 @@ class Device
|
|||||||
DeviceAttribute *attr;
|
DeviceAttribute *attr;
|
||||||
|
|
||||||
Semaphore *image_acquired_semaphore;
|
Semaphore *image_acquired_semaphore;
|
||||||
Fence *draw_fence;
|
Fence *draw_fence,*texture_fence;
|
||||||
|
|
||||||
|
VkSubmitInfo texture_submitInfo;
|
||||||
|
|
||||||
RenderPass *main_rp;
|
RenderPass *main_rp;
|
||||||
ObjectList<Framebuffer> main_fb;
|
ObjectList<Framebuffer> main_fb;
|
||||||
@ -103,7 +105,8 @@ public: //Command Buffer 相关
|
|||||||
public: //提交相关
|
public: //提交相关
|
||||||
|
|
||||||
bool AcquireNextImage ();
|
bool AcquireNextImage ();
|
||||||
bool QueueSubmit (const VkCommandBuffer *,const uint32_t count=1);
|
bool SubmitDraw (const VkCommandBuffer *,const uint32_t count=1);
|
||||||
|
bool SubmitTexture (const VkCommandBuffer *cmd_bufs,const uint32_t count=1);
|
||||||
bool Wait (bool wait_all=VK_TRUE,uint64_t time_out=HGL_NANO_SEC_PER_SEC*0.1);
|
bool Wait (bool wait_all=VK_TRUE,uint64_t time_out=HGL_NANO_SEC_PER_SEC*0.1);
|
||||||
bool QueuePresent ();
|
bool QueuePresent ();
|
||||||
};//class Device
|
};//class Device
|
||||||
|
@ -21,6 +21,10 @@ Device::Device(DeviceAttribute *da)
|
|||||||
|
|
||||||
image_acquired_semaphore=this->CreateSem();
|
image_acquired_semaphore=this->CreateSem();
|
||||||
draw_fence=this->CreateFence();
|
draw_fence=this->CreateFence();
|
||||||
|
texture_fence=this->CreateFence();
|
||||||
|
|
||||||
|
hgl_zero(texture_submitInfo);
|
||||||
|
texture_submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
|
||||||
|
|
||||||
present.sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR;
|
present.sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR;
|
||||||
present.pNext = nullptr;
|
present.pNext = nullptr;
|
||||||
@ -42,6 +46,7 @@ Device::~Device()
|
|||||||
delete main_rp;
|
delete main_rp;
|
||||||
|
|
||||||
delete image_acquired_semaphore;
|
delete image_acquired_semaphore;
|
||||||
|
delete texture_fence;
|
||||||
delete draw_fence;
|
delete draw_fence;
|
||||||
|
|
||||||
delete attr;
|
delete attr;
|
||||||
@ -217,9 +222,9 @@ bool Device::AcquireNextImage()
|
|||||||
return(vkAcquireNextImageKHR(attr->device,attr->swap_chain,UINT64_MAX,*image_acquired_semaphore,VK_NULL_HANDLE,¤t_frame)==VK_SUCCESS);
|
return(vkAcquireNextImageKHR(attr->device,attr->swap_chain,UINT64_MAX,*image_acquired_semaphore,VK_NULL_HANDLE,¤t_frame)==VK_SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Device::QueueSubmit(const VkCommandBuffer *cmd_bufs,const uint32_t count)
|
bool Device::SubmitDraw(const VkCommandBuffer *cmd_bufs,const uint32_t count)
|
||||||
{
|
{
|
||||||
if(!cmd_bufs)
|
if(!cmd_bufs||count<=0)
|
||||||
return(false);
|
return(false);
|
||||||
|
|
||||||
VkPipelineStageFlags pipe_stage_flags = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
|
VkPipelineStageFlags pipe_stage_flags = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
#include<hgl/graph/vulkan/VKSampler.h>
|
#include<hgl/graph/vulkan/VKSampler.h>
|
||||||
#include<hgl/graph/vulkan/VKDevice.h>
|
#include<hgl/graph/vulkan/VKDevice.h>
|
||||||
#include<hgl/graph/vulkan/VKPhysicalDevice.h>
|
#include<hgl/graph/vulkan/VKPhysicalDevice.h>
|
||||||
|
#include<hgl/graph/vulkan/VKFence.h>
|
||||||
#include<hgl/graph/vulkan/VKBuffer.h>
|
#include<hgl/graph/vulkan/VKBuffer.h>
|
||||||
#include<hgl/graph/vulkan/VKCommandBuffer.h>
|
#include<hgl/graph/vulkan/VKCommandBuffer.h>
|
||||||
VK_NAMESPACE_BEGIN
|
VK_NAMESPACE_BEGIN
|
||||||
@ -59,7 +60,7 @@ Texture2D *Device::CreateTexture2D(const VkFormat video_format,void *data,uint32
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
#define VK_CHECK_RESULT(func) if(func!=VK_SUCCESS){delete tex_data;return(nullptr);}
|
#define VK_CHECK_RESULT(func) if(func!=VK_SUCCESS){delete tex_data;delete buf;return(nullptr);}
|
||||||
|
|
||||||
Buffer *buf=CreateBuffer(VK_BUFFER_USAGE_TRANSFER_SRC_BIT,size,data);
|
Buffer *buf=CreateBuffer(VK_BUFFER_USAGE_TRANSFER_SRC_BIT,size,data);
|
||||||
|
|
||||||
@ -152,8 +153,9 @@ Texture2D *Device::CreateTexture2D(const VkFormat video_format,void *data,uint32
|
|||||||
1, &imageMemoryBarrier);
|
1, &imageMemoryBarrier);
|
||||||
|
|
||||||
cmd_buf->End();
|
cmd_buf->End();
|
||||||
QueueSubmit(*cmd_buf);
|
|
||||||
Wait();
|
SubmitTexture(*cmd_buf);
|
||||||
|
|
||||||
delete buf;
|
delete buf;
|
||||||
|
|
||||||
tex_data->image_view=CreateImageView2D(attr->device,video_format,VK_IMAGE_ASPECT_COLOR_BIT,tex_data->image);
|
tex_data->image_view=CreateImageView2D(attr->device,video_format,VK_IMAGE_ASPECT_COLOR_BIT,tex_data->image);
|
||||||
@ -164,6 +166,22 @@ Texture2D *Device::CreateTexture2D(const VkFormat video_format,void *data,uint32
|
|||||||
return(new Texture2D(width,height,attr->device,tex_data));
|
return(new Texture2D(width,height,attr->device,tex_data));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Device::SubmitTexture(const VkCommandBuffer *cmd_bufs,const uint32_t count)
|
||||||
|
{
|
||||||
|
if(!cmd_bufs||count<=0)
|
||||||
|
return(false);
|
||||||
|
|
||||||
|
texture_submitInfo.commandBufferCount = count;
|
||||||
|
texture_submitInfo.pCommandBuffers = cmd_bufs;
|
||||||
|
|
||||||
|
VkFence fence=*texture_fence;
|
||||||
|
|
||||||
|
if(vkQueueSubmit(attr->graphics_queue, 1, &texture_submitInfo, fence))return(false);
|
||||||
|
if(vkWaitForFences(attr->device, 1, &fence, VK_TRUE, HGL_NANO_SEC_PER_SEC*0.1)!=VK_SUCCESS)return(false);
|
||||||
|
|
||||||
|
return(true);
|
||||||
|
}
|
||||||
|
|
||||||
Sampler *Device::CreateSampler(VkSamplerCreateInfo *sci)
|
Sampler *Device::CreateSampler(VkSamplerCreateInfo *sci)
|
||||||
{
|
{
|
||||||
if(!sci)return(nullptr);
|
if(!sci)return(nullptr);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user