From 58b0ae84b56996304b6ad373e4f6cff2cf6bdd41 Mon Sep 17 00:00:00 2001 From: ReinUsesLisp Date: Thu, 10 Sep 2020 03:43:30 -0300 Subject: renderer_vulkan: Make unconditional use of VK_KHR_timeline_semaphore This reworks how host<->device synchronization works on the Vulkan backend. Instead of "protecting" resources with a fence and signalling these as free when the fence is known to be signalled by the host GPU, use timeline semaphores. Vulkan timeline semaphores allow use to work on a subset of D3D12 fences. As far as we are concerned, timeline semaphores are a value set by the host or the device that can be waited by either of them. Taking advantange of this, we can have a monolithically increasing atomic value for each submission to the graphics queue. Instead of protecting resources with a fence, we simply store the current logical tick (the atomic value stored in CPU memory). When we want to know if a resource is free, it can be compared to the current GPU tick. This greatly simplifies resource management code and the free status of resources should have less false negatives. To workaround bugs in validation layers, when these are attached there's a thread waiting for timeline semaphores. --- src/video_core/renderer_vulkan/vk_query_cache.h | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) (limited to 'src/video_core/renderer_vulkan/vk_query_cache.h') diff --git a/src/video_core/renderer_vulkan/vk_query_cache.h b/src/video_core/renderer_vulkan/vk_query_cache.h index 9be996e55..2e57fb75d 100644 --- a/src/video_core/renderer_vulkan/vk_query_cache.h +++ b/src/video_core/renderer_vulkan/vk_query_cache.h @@ -11,7 +11,7 @@ #include "common/common_types.h" #include "video_core/query_cache.h" -#include "video_core/renderer_vulkan/vk_resource_manager.h" +#include "video_core/renderer_vulkan/vk_resource_pool.h" #include "video_core/renderer_vulkan/wrapper.h" namespace VideoCore { @@ -28,14 +28,12 @@ class VKScheduler; using CounterStream = VideoCommon::CounterStreamBase; -class QueryPool final : public VKFencedPool { +class QueryPool final : public ResourcePool { public: - explicit QueryPool(); + explicit QueryPool(const VKDevice& device, VKScheduler& scheduler, VideoCore::QueryType type); ~QueryPool() override; - void Initialize(const VKDevice& device, VideoCore::QueryType type); - - std::pair Commit(VKFence& fence); + std::pair Commit(); void Reserve(std::pair query); @@ -45,16 +43,15 @@ protected: private: static constexpr std::size_t GROW_STEP = 512; - const VKDevice* device = nullptr; - VideoCore::QueryType type = {}; + const VKDevice& device; + const VideoCore::QueryType type; std::vector pools; std::vector usage; }; class VKQueryCache final - : public VideoCommon::QueryCacheBase { + : public VideoCommon::QueryCacheBase { public: explicit VKQueryCache(VideoCore::RasterizerInterface& rasterizer, Tegra::Engines::Maxwell3D& maxwell3d, Tegra::MemoryManager& gpu_memory, @@ -76,6 +73,7 @@ public: private: const VKDevice& device; VKScheduler& scheduler; + std::array query_pools; }; class HostCounter final : public VideoCommon::HostCounterBase { @@ -92,7 +90,7 @@ private: VKQueryCache& cache; const VideoCore::QueryType type; const std::pair query; - const u64 ticks; + const u64 tick; }; class CachedQuery : public VideoCommon::CachedQueryBase { -- cgit v1.2.3