From 14af383238b66b50b37ea64a59ec5da646443813 Mon Sep 17 00:00:00 2001 From: Billy Laws Date: Fri, 21 Oct 2022 21:58:52 +0100 Subject: [PATCH] Only allow submitting `swapchainImageCount` images for host present at a time Prevents situations where nothing would otherwise be waiting on the GPU and since presentation no longer blocks too many images would be submitted for presentation. --- app/src/main/cpp/skyline/gpu/presentation_engine.cpp | 10 ++++++++-- app/src/main/cpp/skyline/gpu/presentation_engine.h | 5 +++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/app/src/main/cpp/skyline/gpu/presentation_engine.cpp b/app/src/main/cpp/skyline/gpu/presentation_engine.cpp index d222d134..77d7cf43 100644 --- a/app/src/main/cpp/skyline/gpu/presentation_engine.cpp +++ b/app/src/main/cpp/skyline/gpu/presentation_engine.cpp @@ -121,8 +121,12 @@ namespace skyline::gpu { throw exception("Setting the buffer transform to '{}' failed with {}", ToString(frame.transform), result); windowTransform = frame.transform; - auto &acquireSemaphore{acquireSemaphores[acquireSemaphoreIndex]}; - acquireSemaphoreIndex = (acquireSemaphoreIndex + 1) % swapchainImageCount; + auto &acquireSemaphore{acquireSemaphores[frameIndex]}; + auto &frameFence{frameFences[frameIndex]}; + if (frameFence) + frameFence->Wait(); + + frameIndex = (frameIndex + 1) % swapchainImageCount; std::pair nextImage; while (nextImage = vkSwapchain->acquireNextImage(std::numeric_limits::max(), *acquireSemaphore, {}), nextImage.first != vk::Result::eSuccess) [[unlikely]] { @@ -142,6 +146,8 @@ namespace skyline::gpu { .layerCount = 1, }); + frameFence = nextImageTexture->cycle; + auto getMonotonicNsNow{[]() -> i64 { timespec time; if (clock_gettime(CLOCK_MONOTONIC, &time)) diff --git a/app/src/main/cpp/skyline/gpu/presentation_engine.h b/app/src/main/cpp/skyline/gpu/presentation_engine.h index 21581b4b..e0529e78 100644 --- a/app/src/main/cpp/skyline/gpu/presentation_engine.h +++ b/app/src/main/cpp/skyline/gpu/presentation_engine.h @@ -41,8 +41,9 @@ namespace skyline::gpu { static constexpr size_t MaxSwapchainImageCount{6}; //!< The maximum amount of swapchain textures, this affects the amount of images that can be in the swapchain std::array, MaxSwapchainImageCount> images; //!< All the swapchain textures in the same order as supplied by the host swapchain std::array presentSemaphores; //!< Array of semaphores used to signal that swapchain images are ready to be completed, indexed by Vulkan swapchain index - std::array acquireSemaphores; //!< Array of semaphores used to wait on the GPU for swapchain images to be acquired, indexed by `acquireSemaphoreIndex` - size_t acquireSemaphoreIndex{}; //!< The index of the next semaphore to be used for acquiring swapchain images + std::array acquireSemaphores; //!< Array of semaphores used to wait on the GPU for swapchain images to be acquired, indexed by `frameIndex` + std::array, MaxSwapchainImageCount> frameFences{}; //!< Array of fences used to wait on the GPU for copying of swapchain images to be completed, indexed by `frameIndex` + size_t frameIndex{}; //!< The index of the next semaphore/fence to be used for acquiring swapchain images size_t swapchainImageCount{}; //!< The number of images in the current swapchain i64 frameTimestamp{}; //!< The timestamp of the last frame being shown in nanoseconds