diff options
author | ReinUsesLisp <reinuseslisp@airmail.cc> | 2019-02-14 16:57:56 +0100 |
---|---|---|
committer | ReinUsesLisp <reinuseslisp@airmail.cc> | 2019-02-14 22:44:26 +0100 |
commit | 25c2fe1c6b7b2ff7164fad0d915fb178d6d68770 (patch) | |
tree | 3381c9c0407e53b98292b785e3c34d65031e58aa /src/video_core/renderer_vulkan/vk_resource_manager.h | |
parent | vk_resource_manager: Add VKResource interface (diff) | |
download | yuzu-25c2fe1c6b7b2ff7164fad0d915fb178d6d68770.tar yuzu-25c2fe1c6b7b2ff7164fad0d915fb178d6d68770.tar.gz yuzu-25c2fe1c6b7b2ff7164fad0d915fb178d6d68770.tar.bz2 yuzu-25c2fe1c6b7b2ff7164fad0d915fb178d6d68770.tar.lz yuzu-25c2fe1c6b7b2ff7164fad0d915fb178d6d68770.tar.xz yuzu-25c2fe1c6b7b2ff7164fad0d915fb178d6d68770.tar.zst yuzu-25c2fe1c6b7b2ff7164fad0d915fb178d6d68770.zip |
Diffstat (limited to '')
-rw-r--r-- | src/video_core/renderer_vulkan/vk_resource_manager.h | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/src/video_core/renderer_vulkan/vk_resource_manager.h b/src/video_core/renderer_vulkan/vk_resource_manager.h index 21a53abcd..aa52007c8 100644 --- a/src/video_core/renderer_vulkan/vk_resource_manager.h +++ b/src/video_core/renderer_vulkan/vk_resource_manager.h @@ -4,11 +4,14 @@ #pragma once +#include <vector> #include "video_core/renderer_vulkan/declarations.h" namespace Vulkan { +class VKDevice; class VKFence; +class VKResourceManager; /// Interface for a Vulkan resource class VKResource { @@ -23,4 +26,64 @@ public: virtual void OnFenceRemoval(VKFence* signaling_fence) = 0; }; +/** + * Fences take ownership of objects, protecting them from GPU-side or driver-side concurrent access. + * They must be commited from the resource manager. Their usage flow is: commit the fence from the + * resource manager, protect resources with it and use them, send the fence to an execution queue + * and Wait for it if needed and then call Release. Used resources will automatically be signaled + * when they are free to be reused. + * @brief Protects resources for concurrent usage and signals its release. + */ +class VKFence { + friend class VKResourceManager; + +public: + explicit VKFence(const VKDevice& device, UniqueFence handle); + ~VKFence(); + + /** + * Waits for the fence to be signaled. + * @warning You must have ownership of the fence and it has to be previously sent to a queue to + * call this function. + */ + void Wait(); + + /** + * Releases ownership of the fence. Pass after it has been sent to an execution queue. + * Unmanaged usage of the fence after the call will result in undefined behavior because it may + * be being used for something else. + */ + void Release(); + + /// Protects a resource with this fence. + void Protect(VKResource* resource); + + /// Removes protection for a resource. + void Unprotect(const VKResource* resource); + + /// Retreives the fence. + operator vk::Fence() const { + return *handle; + } + +private: + /// Take ownership of the fence. + void Commit(); + + /** + * Updates the fence status. + * @warning Waiting for the owner might soft lock the execution. + * @param gpu_wait Wait for the fence to be signaled by the driver. + * @param owner_wait Wait for the owner to signal its freedom. + * @returns True if the fence is free. Waiting for gpu and owner will always return true. + */ + bool Tick(bool gpu_wait, bool owner_wait); + + const VKDevice& device; ///< Device handler + UniqueFence handle; ///< Vulkan fence + std::vector<VKResource*> protected_resources; ///< List of resources protected by this fence + bool is_owned = false; ///< The fence has been commited but not released yet. + bool is_used = false; ///< The fence has been commited but it has not been checked to be free. +}; + } // namespace Vulkan |