diff options
author | ReinUsesLisp <reinuseslisp@airmail.cc> | 2020-09-10 08:43:30 +0200 |
---|---|---|
committer | ReinUsesLisp <reinuseslisp@airmail.cc> | 2020-09-19 06:46:37 +0200 |
commit | 58b0ae84b56996304b6ad373e4f6cff2cf6bdd41 (patch) | |
tree | 9b7c3e28fa7445c78304902efe660356c59cad57 /src/video_core/renderer_vulkan/vk_master_semaphore.h | |
parent | Merge pull request #4663 from ReinUsesLisp/wswitch (diff) | |
download | yuzu-58b0ae84b56996304b6ad373e4f6cff2cf6bdd41.tar yuzu-58b0ae84b56996304b6ad373e4f6cff2cf6bdd41.tar.gz yuzu-58b0ae84b56996304b6ad373e4f6cff2cf6bdd41.tar.bz2 yuzu-58b0ae84b56996304b6ad373e4f6cff2cf6bdd41.tar.lz yuzu-58b0ae84b56996304b6ad373e4f6cff2cf6bdd41.tar.xz yuzu-58b0ae84b56996304b6ad373e4f6cff2cf6bdd41.tar.zst yuzu-58b0ae84b56996304b6ad373e4f6cff2cf6bdd41.zip |
Diffstat (limited to '')
-rw-r--r-- | src/video_core/renderer_vulkan/vk_master_semaphore.h | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/src/video_core/renderer_vulkan/vk_master_semaphore.h b/src/video_core/renderer_vulkan/vk_master_semaphore.h new file mode 100644 index 000000000..0e93706d7 --- /dev/null +++ b/src/video_core/renderer_vulkan/vk_master_semaphore.h @@ -0,0 +1,70 @@ +// Copyright 2020 yuzu Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#pragma once + +#include <atomic> +#include <thread> + +#include "common/common_types.h" +#include "video_core/renderer_vulkan/wrapper.h" + +namespace Vulkan { + +class VKDevice; + +class MasterSemaphore { +public: + explicit MasterSemaphore(const VKDevice& device); + ~MasterSemaphore(); + + /// Returns the current logical tick. + [[nodiscard]] u64 CurrentTick() const noexcept { + return current_tick; + } + + /// Returns the timeline semaphore handle. + [[nodiscard]] VkSemaphore Handle() const noexcept { + return *semaphore; + } + + /// Returns true when a tick has been hit by the GPU. + [[nodiscard]] bool IsFree(u64 tick) { + return gpu_tick >= tick; + } + + /// Advance to the logical tick. + void NextTick() noexcept { + ++current_tick; + } + + /// Refresh the known GPU tick + void Refresh() { + gpu_tick = semaphore.GetCounter(); + } + + /// Waits for a tick to be hit on the GPU + void Wait(u64 tick) { + // No need to wait if the GPU is ahead of the tick + if (IsFree(tick)) { + return; + } + // Update the GPU tick and try again + Refresh(); + if (IsFree(tick)) { + return; + } + // If none of the above is hit, fallback to a regular wait + semaphore.Wait(tick); + } + +private: + vk::Semaphore semaphore; ///< Timeline semaphore. + std::atomic<u64> gpu_tick{0}; ///< Current known GPU tick. + std::atomic<u64> current_tick{1}; ///< Current logical tick. + std::atomic<bool> shutdown{false}; ///< True when the object is being destroyed. + std::thread debug_thread; ///< Debug thread to workaround validation layer bugs. +}; + +} // namespace Vulkan |