From 389efebf2e26c9bc1e7f84c669c12bd63fa825ec Mon Sep 17 00:00:00 2001 From: HuYingzhuo Date: Fri, 19 Apr 2019 19:58:01 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9EVKFence=E5=88=9B=E5=BB=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- example/Vulkan/VKDevice.cpp | 16 ++++++++++++++++ example/Vulkan/VKDevice.h | 3 +++ example/Vulkan/VKFence.cpp | 7 +++++++ example/Vulkan/VKFence.h | 26 ++++++++++++++++++++++++++ example/Vulkan/main.cpp | 4 ++++ 5 files changed, 56 insertions(+) create mode 100644 example/Vulkan/VKFence.cpp create mode 100644 example/Vulkan/VKFence.h diff --git a/example/Vulkan/VKDevice.cpp b/example/Vulkan/VKDevice.cpp index e1e84139..db39a2e0 100644 --- a/example/Vulkan/VKDevice.cpp +++ b/example/Vulkan/VKDevice.cpp @@ -4,6 +4,7 @@ #include"VKCommandBuffer.h" //#include"VKDescriptorSet.h" #include"VKRenderPass.h" +#include"VKFence.h" VK_NAMESPACE_BEGIN @@ -182,4 +183,19 @@ RenderPass *Device::CreateRenderPass() return(new RenderPass(attr->device,render_pass)); } + +Fence *Device::CreateFence() +{ + VkFenceCreateInfo fenceInfo; + fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; + fenceInfo.pNext = nullptr; + fenceInfo.flags = 0; + + VkFence drawFence; + + if(vkCreateFence(attr->device, &fenceInfo, nullptr, &drawFence)!=VK_SUCCESS) + return(nullptr); + + return(new Fence(attr->device,drawFence)); +} VK_NAMESPACE_END diff --git a/example/Vulkan/VKDevice.h b/example/Vulkan/VKDevice.h index fff6f0a1..2d335d13 100644 --- a/example/Vulkan/VKDevice.h +++ b/example/Vulkan/VKDevice.h @@ -12,6 +12,7 @@ class Buffer; class VertexBuffer; class CommandBuffer; class RenderPass; +class Fence; class Device { @@ -60,6 +61,8 @@ public: // DescriptorSet * CreateDescSet(int); RenderPass *CreateRenderPass(); + + Fence *CreateFence(); };//class Device VK_NAMESPACE_END #endif//HGL_GRAPH_RENDER_SURFACE_INCLUDE diff --git a/example/Vulkan/VKFence.cpp b/example/Vulkan/VKFence.cpp new file mode 100644 index 00000000..c1e3f53f --- /dev/null +++ b/example/Vulkan/VKFence.cpp @@ -0,0 +1,7 @@ +#include"VKFence.h" +VK_NAMESPACE_BEGIN +Fence::~Fence() +{ + vkDestroyFence(device,fence,nullptr); +} +VK_NAMESPACE_END diff --git a/example/Vulkan/VKFence.h b/example/Vulkan/VKFence.h new file mode 100644 index 00000000..e9960056 --- /dev/null +++ b/example/Vulkan/VKFence.h @@ -0,0 +1,26 @@ +#ifndef HGL_VULKAN_GRAPH_FENCE_INCLUDE +#define HGL_VULKAN_GRAPH_FENCE_INCLUDE + +#include"VK.h" +VK_NAMESPACE_BEGIN +class Fence +{ + VkDevice device; + VkFence fence; + +private: + + friend class Device; + + Fence(VkDevice d,VkFence f) + { + device=d; + fence=f; + } + +public: + + ~Fence(); +};//class Fence +VK_NAMESPACE_END +#endif//HGL_VULKAN_GRAPH_FENCE_INCLUDE diff --git a/example/Vulkan/main.cpp b/example/Vulkan/main.cpp index ecb1160a..a720db49 100644 --- a/example/Vulkan/main.cpp +++ b/example/Vulkan/main.cpp @@ -10,6 +10,7 @@ #include"VKPipelineLayout.h" #include"VKPipeline.h" #include"VKCommandBuffer.h" +#include"VKFence.h" #include #include @@ -120,6 +121,8 @@ int main(int,char **) if(!shader) return -3; + vulkan::Fence *fence=device->CreateFence(); + vulkan::VertexInput vi; vulkan::PipelineCreater pc(device); vulkan::RenderPass *rp=device->CreateRenderPass(); @@ -141,6 +144,7 @@ int main(int,char **) delete pipeline; } + delete fence; delete rp; delete ubo;