[vulkan] Add frame rate limiter to Vulkan presenter

This commit is contained in:
Philip Rebohle 2021-06-10 21:53:08 +02:00 committed by Philip Rebohle
parent a16c861358
commit b537f19a3c
2 changed files with 36 additions and 0 deletions

View File

@ -89,6 +89,11 @@ namespace dxvk::vk {
m_acquireStatus = m_vkd->vkAcquireNextImageKHR(m_vkd->device(),
m_swapchain, std::numeric_limits<uint64_t>::max(),
sync.acquire, VK_NULL_HANDLE, &m_imageIndex);
bool vsync = m_info.presentMode == VK_PRESENT_MODE_FIFO_KHR
|| m_info.presentMode == VK_PRESENT_MODE_FIFO_RELAXED_KHR;
m_fpsLimiter.delay(vsync);
return status;
}
@ -238,6 +243,16 @@ namespace dxvk::vk {
}
void Presenter::setFrameRateLimit(double frameRate) {
m_fpsLimiter.setTargetFrameRate(frameRate);
}
void Presenter::setFrameRateLimiterRefreshRate(double refreshRate) {
m_fpsLimiter.setDisplayRefreshRate(refreshRate);
}
VkResult Presenter::getSupportedFormats(std::vector<VkSurfaceFormatKHR>& formats, const PresenterDesc& desc) {
uint32_t numFormats = 0;

View File

@ -5,6 +5,7 @@
#include "../util/log/log.h"
#include "../util/util_error.h"
#include "../util/util_fps_limiter.h"
#include "../util/util_math.h"
#include "../util/util_string.h"
@ -152,6 +153,24 @@ namespace dxvk::vk {
VkResult recreateSwapChain(
const PresenterDesc& desc);
/**
* \brief Changes maximum frame rate
*
* \param [in] frameRate Target frame rate. Set
* to 0 in order to disable the limiter.
*/
void setFrameRateLimit(double frameRate);
/**
* \brief Notifies frame rate limiter about the display refresh rate
*
* Used to dynamically disable the frame rate limiter in case
* vertical synchronization is used and the target frame rate
* roughly equals the display's refresh rate.
* \param [in] refresnRate Current refresh rate
*/
void setFrameRateLimiterRefreshRate(double refreshRate);
/**
* \brief Checks whether a Vulkan swap chain exists
*
@ -184,6 +203,8 @@ namespace dxvk::vk {
VkResult m_acquireStatus = VK_NOT_READY;
FpsLimiter m_fpsLimiter;
VkResult getSupportedFormats(
std::vector<VkSurfaceFormatKHR>& formats,
const PresenterDesc& desc);