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