mirror of
https://github.com/doitsujin/dxvk.git
synced 2025-01-30 11:52:11 +01:00
[vulkan] Acquire next image immediately after presentation
vkAcquireNextImageKHR is a blocking call, so doing this immediately after presentation may reduce the amount of time that passes between the application requesing presentation and presentation actually happening on the Vulkan device. Idea based on PR #2075.
This commit is contained in:
parent
0b88d0deab
commit
0fe8f2e40c
@ -46,17 +46,18 @@ namespace dxvk::vk {
|
|||||||
VkResult Presenter::acquireNextImage(PresenterSync& sync, uint32_t& index) {
|
VkResult Presenter::acquireNextImage(PresenterSync& sync, uint32_t& index) {
|
||||||
sync = m_semaphores.at(m_frameIndex);
|
sync = m_semaphores.at(m_frameIndex);
|
||||||
|
|
||||||
VkResult status = m_vkd->vkAcquireNextImageKHR(
|
// Don't acquire more than one image at a time
|
||||||
m_vkd->device(), m_swapchain,
|
if (m_acquireStatus == VK_NOT_READY) {
|
||||||
std::numeric_limits<uint64_t>::max(),
|
m_acquireStatus = m_vkd->vkAcquireNextImageKHR(m_vkd->device(),
|
||||||
sync.acquire, VK_NULL_HANDLE, &m_imageIndex);
|
m_swapchain, std::numeric_limits<uint64_t>::max(),
|
||||||
|
sync.acquire, VK_NULL_HANDLE, &m_imageIndex);
|
||||||
|
}
|
||||||
|
|
||||||
if (status != VK_SUCCESS
|
if (m_acquireStatus != VK_SUCCESS && m_acquireStatus != VK_SUBOPTIMAL_KHR)
|
||||||
&& status != VK_SUBOPTIMAL_KHR)
|
return m_acquireStatus;
|
||||||
return status;
|
|
||||||
|
|
||||||
index = m_imageIndex;
|
index = m_imageIndex;
|
||||||
return status;
|
return m_acquireStatus;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -73,10 +74,22 @@ namespace dxvk::vk {
|
|||||||
info.pImageIndices = &m_imageIndex;
|
info.pImageIndices = &m_imageIndex;
|
||||||
info.pResults = nullptr;
|
info.pResults = nullptr;
|
||||||
|
|
||||||
|
VkResult status = m_vkd->vkQueuePresentKHR(m_device.queue, &info);
|
||||||
|
|
||||||
|
if (status != VK_SUCCESS && status != VK_SUBOPTIMAL_KHR)
|
||||||
|
return status;
|
||||||
|
|
||||||
|
// Try to acquire next image already, in order to hide
|
||||||
|
// potential delays from the application thread.
|
||||||
m_frameIndex += 1;
|
m_frameIndex += 1;
|
||||||
m_frameIndex %= m_semaphores.size();
|
m_frameIndex %= m_semaphores.size();
|
||||||
|
|
||||||
return m_vkd->vkQueuePresentKHR(m_device.queue, &info);
|
sync = m_semaphores.at(m_frameIndex);
|
||||||
|
|
||||||
|
m_acquireStatus = m_vkd->vkAcquireNextImageKHR(m_vkd->device(),
|
||||||
|
m_swapchain, std::numeric_limits<uint64_t>::max(),
|
||||||
|
sync.acquire, VK_NULL_HANDLE, &m_imageIndex);
|
||||||
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -220,6 +233,7 @@ namespace dxvk::vk {
|
|||||||
// Invalidate indices
|
// Invalidate indices
|
||||||
m_imageIndex = 0;
|
m_imageIndex = 0;
|
||||||
m_frameIndex = 0;
|
m_frameIndex = 0;
|
||||||
|
m_acquireStatus = VK_NOT_READY;
|
||||||
return VK_SUCCESS;
|
return VK_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -182,6 +182,8 @@ namespace dxvk::vk {
|
|||||||
uint32_t m_imageIndex = 0;
|
uint32_t m_imageIndex = 0;
|
||||||
uint32_t m_frameIndex = 0;
|
uint32_t m_frameIndex = 0;
|
||||||
|
|
||||||
|
VkResult m_acquireStatus = VK_NOT_READY;
|
||||||
|
|
||||||
VkResult getSupportedFormats(
|
VkResult getSupportedFormats(
|
||||||
std::vector<VkSurfaceFormatKHR>& formats,
|
std::vector<VkSurfaceFormatKHR>& formats,
|
||||||
const PresenterDesc& desc);
|
const PresenterDesc& desc);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user