diff options
| author | 2019-02-14 13:06:05 -0300 | |
|---|---|---|
| committer | 2019-02-14 18:44:26 -0300 | |
| commit | aa0b6babdad588d176fc67784f9905709845aa07 (patch) | |
| tree | d8be258cecf13218af5283ef2fd8e04eab7fbc76 /src | |
| parent | vk_resource_manager: Implement VKFence (diff) | |
| download | yuzu-aa0b6babdad588d176fc67784f9905709845aa07.tar.gz yuzu-aa0b6babdad588d176fc67784f9905709845aa07.tar.xz yuzu-aa0b6babdad588d176fc67784f9905709845aa07.zip | |
vk_resource_manager: Implement VKFenceWatch
A fence watch is used to keep track of the usage of a fence and protect
a resource or set of resources without having to inherit from their
handlers.
Diffstat (limited to 'src')
| -rw-r--r-- | src/video_core/renderer_vulkan/vk_resource_manager.cpp | 38 | ||||
| -rw-r--r-- | src/video_core/renderer_vulkan/vk_resource_manager.h | 30 |
2 files changed, 68 insertions, 0 deletions
diff --git a/src/video_core/renderer_vulkan/vk_resource_manager.cpp b/src/video_core/renderer_vulkan/vk_resource_manager.cpp index 1875bcf54..2e9c6ef34 100644 --- a/src/video_core/renderer_vulkan/vk_resource_manager.cpp +++ b/src/video_core/renderer_vulkan/vk_resource_manager.cpp | |||
| @@ -3,6 +3,7 @@ | |||
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #include <algorithm> | 5 | #include <algorithm> |
| 6 | #include "common/assert.h" | ||
| 6 | #include "video_core/renderer_vulkan/declarations.h" | 7 | #include "video_core/renderer_vulkan/declarations.h" |
| 7 | #include "video_core/renderer_vulkan/vk_device.h" | 8 | #include "video_core/renderer_vulkan/vk_device.h" |
| 8 | #include "video_core/renderer_vulkan/vk_resource_manager.h" | 9 | #include "video_core/renderer_vulkan/vk_resource_manager.h" |
| @@ -79,4 +80,41 @@ void VKFence::Unprotect(const VKResource* resource) { | |||
| 79 | } | 80 | } |
| 80 | } | 81 | } |
| 81 | 82 | ||
| 83 | VKFenceWatch::VKFenceWatch() = default; | ||
| 84 | |||
| 85 | VKFenceWatch::~VKFenceWatch() { | ||
| 86 | if (fence) { | ||
| 87 | fence->Unprotect(this); | ||
| 88 | } | ||
| 89 | } | ||
| 90 | |||
| 91 | void VKFenceWatch::Wait() { | ||
| 92 | if (!fence) { | ||
| 93 | return; | ||
| 94 | } | ||
| 95 | fence->Wait(); | ||
| 96 | fence->Unprotect(this); | ||
| 97 | fence = nullptr; | ||
| 98 | } | ||
| 99 | |||
| 100 | void VKFenceWatch::Watch(VKFence& new_fence) { | ||
| 101 | Wait(); | ||
| 102 | fence = &new_fence; | ||
| 103 | fence->Protect(this); | ||
| 104 | } | ||
| 105 | |||
| 106 | bool VKFenceWatch::TryWatch(VKFence& new_fence) { | ||
| 107 | if (fence) { | ||
| 108 | return false; | ||
| 109 | } | ||
| 110 | fence = &new_fence; | ||
| 111 | fence->Protect(this); | ||
| 112 | return true; | ||
| 113 | } | ||
| 114 | |||
| 115 | void VKFenceWatch::OnFenceRemoval(VKFence* signaling_fence) { | ||
| 116 | ASSERT_MSG(signaling_fence == fence, "Removing the wrong fence"); | ||
| 117 | fence = nullptr; | ||
| 118 | } | ||
| 119 | |||
| 82 | } // namespace Vulkan | 120 | } // namespace Vulkan |
diff --git a/src/video_core/renderer_vulkan/vk_resource_manager.h b/src/video_core/renderer_vulkan/vk_resource_manager.h index aa52007c8..5345ba46e 100644 --- a/src/video_core/renderer_vulkan/vk_resource_manager.h +++ b/src/video_core/renderer_vulkan/vk_resource_manager.h | |||
| @@ -86,4 +86,34 @@ private: | |||
| 86 | bool is_used = false; ///< The fence has been commited but it has not been checked to be free. | 86 | bool is_used = false; ///< The fence has been commited but it has not been checked to be free. |
| 87 | }; | 87 | }; |
| 88 | 88 | ||
| 89 | /** | ||
| 90 | * A fence watch is used to keep track of the usage of a fence and protect a resource or set of | ||
| 91 | * resources without having to inherit VKResource from their handlers. | ||
| 92 | */ | ||
| 93 | class VKFenceWatch final : public VKResource { | ||
| 94 | public: | ||
| 95 | explicit VKFenceWatch(); | ||
| 96 | ~VKFenceWatch(); | ||
| 97 | |||
| 98 | /// Waits for the fence to be released. | ||
| 99 | void Wait(); | ||
| 100 | |||
| 101 | /** | ||
| 102 | * Waits for a previous fence and watches a new one. | ||
| 103 | * @param new_fence New fence to wait to. | ||
| 104 | */ | ||
| 105 | void Watch(VKFence& new_fence); | ||
| 106 | |||
| 107 | /** | ||
| 108 | * Checks if it's currently being watched and starts watching it if it's available. | ||
| 109 | * @returns True if a watch has started, false if it's being watched. | ||
| 110 | */ | ||
| 111 | bool TryWatch(VKFence& new_fence); | ||
| 112 | |||
| 113 | void OnFenceRemoval(VKFence* signaling_fence) override; | ||
| 114 | |||
| 115 | private: | ||
| 116 | VKFence* fence{}; ///< Fence watching this resource. nullptr when the watch is free. | ||
| 117 | }; | ||
| 118 | |||
| 89 | } // namespace Vulkan | 119 | } // namespace Vulkan |