summaryrefslogtreecommitdiffstats
path: root/src/video_core/renderer_vulkan/vk_present_manager.h
diff options
context:
space:
mode:
authorGPUCode <geoster3d@gmail.com>2023-03-19 16:23:24 +0100
committerGPUCode <geoster3d@gmail.com>2023-05-01 22:13:24 +0200
commit2ad9acf795fcb9f0f01ed85e1b4f1accd9c3965d (patch)
tree58c66b4f690b4ca069229ed46df7140f6dd6b0e7 /src/video_core/renderer_vulkan/vk_present_manager.h
parentMerge pull request #10084 from FernandoS27/yuzu-goes-broom-broom (diff)
downloadyuzu-2ad9acf795fcb9f0f01ed85e1b4f1accd9c3965d.tar
yuzu-2ad9acf795fcb9f0f01ed85e1b4f1accd9c3965d.tar.gz
yuzu-2ad9acf795fcb9f0f01ed85e1b4f1accd9c3965d.tar.bz2
yuzu-2ad9acf795fcb9f0f01ed85e1b4f1accd9c3965d.tar.lz
yuzu-2ad9acf795fcb9f0f01ed85e1b4f1accd9c3965d.tar.xz
yuzu-2ad9acf795fcb9f0f01ed85e1b4f1accd9c3965d.tar.zst
yuzu-2ad9acf795fcb9f0f01ed85e1b4f1accd9c3965d.zip
Diffstat (limited to 'src/video_core/renderer_vulkan/vk_present_manager.h')
-rw-r--r--src/video_core/renderer_vulkan/vk_present_manager.h82
1 files changed, 82 insertions, 0 deletions
diff --git a/src/video_core/renderer_vulkan/vk_present_manager.h b/src/video_core/renderer_vulkan/vk_present_manager.h
new file mode 100644
index 000000000..f5d9fc96d
--- /dev/null
+++ b/src/video_core/renderer_vulkan/vk_present_manager.h
@@ -0,0 +1,82 @@
+// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
+// SPDX-License-Identifier: GPL-2.0-or-later
+
+#pragma once
+
+#include <condition_variable>
+#include <mutex>
+#include <queue>
+
+#include "common/common_types.h"
+#include "common/polyfill_thread.h"
+#include "video_core/vulkan_common/vulkan_memory_allocator.h"
+#include "video_core/vulkan_common/vulkan_wrapper.h"
+
+namespace Core::Frontend {
+class EmuWindow;
+} // namespace Core::Frontend
+
+namespace Vulkan {
+
+class Device;
+class Scheduler;
+class Swapchain;
+
+struct Frame {
+ u32 width;
+ u32 height;
+ bool is_srgb;
+ vk::Image image;
+ vk::ImageView image_view;
+ vk::Framebuffer framebuffer;
+ MemoryCommit image_commit;
+ vk::CommandBuffer cmdbuf;
+ vk::Semaphore render_ready;
+ vk::Fence present_done;
+};
+
+class PresentManager {
+public:
+ PresentManager(Core::Frontend::EmuWindow& render_window, const Device& device,
+ MemoryAllocator& memory_allocator, Scheduler& scheduler, Swapchain& swapchain);
+ ~PresentManager();
+
+ /// Returns the last used presentation frame
+ Frame* GetRenderFrame();
+
+ /// Pushes a frame for presentation
+ void PushFrame(Frame* frame);
+
+ /// Recreates the present frame to match the provided parameters
+ void RecreateFrame(Frame* frame, u32 width, u32 height, bool is_srgb,
+ VkFormat image_view_format, VkRenderPass rd);
+
+ /// Waits for the present thread to finish presenting all queued frames.
+ void WaitPresent();
+
+private:
+ void PresentThread(std::stop_token token);
+
+ void CopyToSwapchain(Frame* frame);
+
+private:
+ Core::Frontend::EmuWindow& render_window;
+ const Device& device;
+ MemoryAllocator& memory_allocator;
+ Scheduler& scheduler;
+ Swapchain& swapchain;
+ vk::CommandPool cmdpool;
+ std::vector<Frame> frames;
+ std::queue<Frame*> present_queue;
+ std::queue<Frame*> free_queue;
+ std::condition_variable_any frame_cv;
+ std::condition_variable free_cv;
+ std::mutex swapchain_mutex;
+ std::mutex queue_mutex;
+ std::mutex free_mutex;
+ std::jthread present_thread;
+ bool blit_supported{};
+ std::size_t image_count;
+};
+
+} // namespace Vulkan