Add tests for external sharing not dependant on semaphores. (#1648)

* Add tests for external sharing not dependant on semaphores.

Additional external sharing tests that use fences instead of semaphores.

Signed-off-by: Paweł Jastrzębski <p.k.jastrzebski@gmail.com>

* Fix clang-format

Signed-off-by: Paweł Jastrzębski <p.k.jastrzebski@gmail.com>

* Apply changes for review.

Apply changes for review:
- Make VkFence + clFinish a synchronization option to existing tests
instead of creating a separate test that uses fence.

Signed-off-by: Paweł Jastrzębski <p.k.jastrzebski@gmail.com>

* Fix build break.

Signed-off-by: Paweł Jastrzębski <p.k.jastrzebski@gmail.com>

* Fix resource release conditions.

Signed-off-by: Paweł Jastrzębski <p.k.jastrzebski@gmail.com>

* Fix fence usage.

Fixed following fence issues:
- Add missing link to command buffer
- Add fence reset before wait

Signed-off-by: Paweł Jastrzębski <p.k.jastrzebski@gmail.com>

* Add Vulkan wrapper for fence.

Signed-off-by: Paweł Jastrzębski <p.k.jastrzebski@gmail.com>

* Rework fence reset.

Signed-off-by: Paweł Jastrzębski <p.k.jastrzebski@gmail.com>

* Change synchronisation mechanisms.

Changes made:
- wait for fence with clFinish
- queue submit with wait for fence

Signed-off-by: Paweł Jastrzębski <p.k.jastrzebski@gmail.com>

* Replace clFinish with vkWaitForFences.

Replaced clFinish with vkWaitForFences in Vulkan exectution context.

Signed-off-by: Paweł Jastrzębski <p.k.jastrzebski@gmail.com>

* Replace remaining clFinish with vkWaitForFences.

Replaced remaining clFinish with vkWaitForFences in Vulkan exectution context.

Signed-off-by: Paweł Jastrzębski <p.k.jastrzebski@gmail.com>

* Fix review comments for synchoronisation simplification.

Signed-off-by: Paweł Jastrzębski <p.k.jastrzebski@gmail.com>

* Fix review comments for synchoronisation simplification for remaining tests.

Signed-off-by: Paweł Jastrzębski <p.k.jastrzebski@gmail.com>

* Fix condition check.

Signed-off-by: Paweł Jastrzębski <p.k.jastrzebski@gmail.com>

---------

Signed-off-by: Paweł Jastrzębski <p.k.jastrzebski@gmail.com>
This commit is contained in:
Paweł Jastrzębski
2023-07-11 17:55:37 +02:00
committed by GitHub
parent 2686b9e2c1
commit 1ab4b26821
4 changed files with 338 additions and 77 deletions

View File

@@ -604,6 +604,37 @@ VulkanQueue &VulkanDevice::getQueue(const VulkanQueueFamily &queueFamily,
VulkanDevice::operator VkDevice() const { return m_vkDevice; }
////////////////////////////////
// VulkanFence implementation //
////////////////////////////////
VulkanFence::VulkanFence(const VulkanDevice &vkDevice)
{
device = vkDevice;
VkFenceCreateInfo fenceInfo{};
fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
fenceInfo.pNext = nullptr;
fenceInfo.flags = 0;
VkResult vkStatus = vkCreateFence(device, &fenceInfo, nullptr, &fence);
if (vkStatus != VK_SUCCESS)
{
throw std::runtime_error("Error: Failed create fence.");
}
}
VulkanFence::~VulkanFence() { vkDestroyFence(device, fence, nullptr); }
void VulkanFence::reset() { vkResetFences(device, 1, &fence); }
void VulkanFence::wait()
{
vkWaitForFences(device, 1, &fence, VK_TRUE, UINT64_MAX);
}
////////////////////////////////
// VulkanQueue implementation //
////////////////////////////////
@@ -615,6 +646,22 @@ VulkanQueue::VulkanQueue(VkQueue vkQueue): m_vkQueue(vkQueue) {}
VulkanQueue::~VulkanQueue() {}
void VulkanQueue::submit(const VulkanCommandBuffer &commandBuffer,
const std::shared_ptr<VulkanFence> &vkFence)
{
VulkanCommandBufferList commandBufferList;
commandBufferList.add(commandBuffer);
VkSubmitInfo vkSubmitInfo = {};
vkSubmitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
vkSubmitInfo.pNext = NULL;
vkSubmitInfo.waitSemaphoreCount = (uint32_t)0;
vkSubmitInfo.commandBufferCount = (uint32_t)commandBufferList.size();
vkSubmitInfo.pCommandBuffers = commandBufferList();
vkQueueSubmit(m_vkQueue, 1, &vkSubmitInfo, vkFence->fence);
}
void VulkanQueue::submit(const VulkanSemaphoreList &waitSemaphoreList,
const VulkanCommandBufferList &commandBufferList,
const VulkanSemaphoreList &signalSemaphoreList)

View File

@@ -21,6 +21,7 @@
#include "vulkan_wrapper_types.hpp"
#include "vulkan_list_map.hpp"
#include "vulkan_api_list.hpp"
#include <memory>
class VulkanInstance {
friend const VulkanInstance &getVulkanInstance();
@@ -145,6 +146,20 @@ public:
operator VkDevice() const;
};
class VulkanFence {
friend class VulkanQueue;
protected:
VkFence fence;
VkDevice device;
public:
VulkanFence(const VulkanDevice &device);
virtual ~VulkanFence();
void reset();
void wait();
};
class VulkanQueue {
friend class VulkanDevice;
@@ -157,6 +172,8 @@ protected:
public:
const VulkanQueueFamily &getQueueFamily();
void submit(const VulkanCommandBuffer &commandBuffer,
const std::shared_ptr<VulkanFence> &fence);
void submit(const VulkanSemaphoreList &waitSemaphoreList,
const VulkanCommandBufferList &commandBufferList,
const VulkanSemaphoreList &signalSemaphoreList);
@@ -569,7 +586,6 @@ public:
operator VkSemaphore() const;
};
#define VK_FUNC_DECL(name) extern "C" PFN_##name _##name;
VK_FUNC_LIST
#if defined(_WIN32) || defined(_WIN64)