diff --git a/example/Vulkan/VKCommandBuffer.h b/example/Vulkan/VKCommandBuffer.h index 8149fbb4..46620635 100644 --- a/example/Vulkan/VKCommandBuffer.h +++ b/example/Vulkan/VKCommandBuffer.h @@ -23,6 +23,8 @@ public: CommandBuffer(VkDevice dev,VkCommandPool cp,VkCommandBuffer cb); ~CommandBuffer(); + operator VkCommandBuffer(){return cmd_buf;} + void SetRenderArea(const VkRect2D &ra){render_area=ra;} void SetClearColor(float r,float g,float b,float a=1.0f) { diff --git a/example/Vulkan/VKDevice.cpp b/example/Vulkan/VKDevice.cpp index 56193ac0..2f3ea391 100644 --- a/example/Vulkan/VKDevice.cpp +++ b/example/Vulkan/VKDevice.cpp @@ -62,6 +62,14 @@ Device::Device(DeviceAttribute *da) attr=da; current_framebuffer=0; image_acquired_semaphore=this->CreateSem(); + + present.sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR; + present.pNext = nullptr; + present.swapchainCount = 1; + present.pSwapchains = &attr->swap_chain; + present.pWaitSemaphores = nullptr; + present.waitSemaphoreCount = 0; + present.pResults = nullptr; } Device::~Device() { @@ -225,4 +233,47 @@ bool Device::AcquireNextImage() { return(vkAcquireNextImageKHR(attr->device,attr->swap_chain,UINT64_MAX,*image_acquired_semaphore,VK_NULL_HANDLE,¤t_framebuffer)==VK_SUCCESS); } + +bool Device::QueueSubmit(CommandBuffer *buf,Fence *fence) +{ + if(!buf||!fence) + return(false); + + VkPipelineStageFlags pipe_stage_flags = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT; + VkSubmitInfo submit_info[1] = {}; + + VkSemaphore sem=*image_acquired_semaphore; + VkCommandBuffer cmd_bufs=*buf; + + submit_info[0].pNext = nullptr; + submit_info[0].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; + submit_info[0].waitSemaphoreCount = 1; + submit_info[0].pWaitSemaphores = &sem; + submit_info[0].pWaitDstStageMask = &pipe_stage_flags; + submit_info[0].commandBufferCount = 1; + submit_info[0].pCommandBuffers = &cmd_bufs; + submit_info[0].signalSemaphoreCount = 0; + submit_info[0].pSignalSemaphores = nullptr; + + return(vkQueueSubmit(attr->graphics_queue, 1, submit_info, *fence)==VK_SUCCESS); +} + +bool Device::Wait(Fence *f,bool wait_all,uint64_t time_out) +{ + VkResult res; + VkFence fence=*f; + + do { + res = vkWaitForFences(attr->device, 1, &fence, wait_all, time_out); + } while (res == VK_TIMEOUT); + + return(true); +} + +bool Device::QueuePresent() +{ + present.pImageIndices = ¤t_framebuffer; + + return(vkQueuePresentKHR(attr->present_queue, &present)==VK_SUCCESS); +} VK_NAMESPACE_END diff --git a/example/Vulkan/VKDevice.h b/example/Vulkan/VKDevice.h index 1dc40ad7..76fef9bc 100644 --- a/example/Vulkan/VKDevice.h +++ b/example/Vulkan/VKDevice.h @@ -22,6 +22,8 @@ class Device Semaphore *image_acquired_semaphore; uint32_t current_framebuffer; + VkPresentInfoKHR present; + private: friend Device *CreateRenderDevice(VkInstance,const PhysicalDevice *,Window *); @@ -68,6 +70,12 @@ public: Semaphore *CreateSem(); bool AcquireNextImage(); + + bool QueueSubmit(CommandBuffer *,Fence *); + + bool Wait(Fence *,bool wait_all=VK_TRUE,uint64_t time_out=HGL_NANO_SEC_PER_SEC*0.1); + + bool QueuePresent(); };//class Device VK_NAMESPACE_END #endif//HGL_GRAPH_RENDER_SURFACE_INCLUDE diff --git a/example/Vulkan/VKFence.h b/example/Vulkan/VKFence.h index e9960056..a5028517 100644 --- a/example/Vulkan/VKFence.h +++ b/example/Vulkan/VKFence.h @@ -21,6 +21,8 @@ private: public: ~Fence(); + + operator VkFence(){return fence;} };//class Fence VK_NAMESPACE_END #endif//HGL_VULKAN_GRAPH_FENCE_INCLUDE